mirror of
https://github.com/openharmony/multimedia_ringtone_library.git
synced 2026-07-01 03:23:19 -04:00
add ringtone_data_extension
Signed-off-by: caochuan <caochuan@huawei.com>
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -67,10 +67,44 @@
|
||||
<filteritem type="filepath" name="src/test/.*" desc="Test files"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
|
||||
<filteritem type="filepath" name="src/main/java/ohos/oat/analysis/headermatcher/.*"
|
||||
desc="License matcher rules, not license header"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/build-profile.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/hvigorfile.js"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/module.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/build-profile.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/hvigorfile.js"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/TestAbility/pages/index.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/main/ets/pages/index.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/test/Ability.test.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/test/List.test.ets"
|
||||
desc="Ringtone library file"/>
|
||||
</filefilter>
|
||||
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/build-profile.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/hvigorfile.js"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/module.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/build-profile.json5"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/hvigorfile.js"
|
||||
desc="Ringtone library file, and this file does not support comments"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/TestAbility/pages/index.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/main/ets/pages/index.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/test/Ability.test.ets"
|
||||
desc="Ringtone library file"/>
|
||||
<filteritem type="filepath" name="frameworks/ringtone_extension_hap/RingtoneLibraryExt/entry/src/ohosTest/ets/test/List.test.ets"
|
||||
desc="Ringtone library file"/>
|
||||
</filefilter>
|
||||
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
|
||||
</filefilter>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
# Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/ringtone_library/ringtone_library.gni")
|
||||
|
||||
ohos_hap("ringtone_extension_hap") {
|
||||
hap_profile = "RingtoneLibraryExt/entry/src/main/module.json"
|
||||
deps = [
|
||||
":RingtoneLibStage_js_assets",
|
||||
":RingtoneLibStage_resources",
|
||||
]
|
||||
certificate_profile = "${RINGTONE_EXT_HAP_PATH}/signature/ringtonelibrary.p7b"
|
||||
shared_libraries = [ "${RINGTONE_SERVICES_PATH}:ringtone_data_extension" ]
|
||||
hap_name = "Ringtone_Library_Ext"
|
||||
part_name = "prebuilt_hap"
|
||||
subsystem_name = "applications"
|
||||
module_install_dir = "app/com.ohos.ringtonelibrary.RingtoneLibraryData"
|
||||
}
|
||||
|
||||
ohos_js_assets("RingtoneLibStage_js_assets") {
|
||||
hap_profile = "RingtoneLibraryExt/entry/src/main/module.json"
|
||||
ets2abc = true
|
||||
source_dir = "RingtoneLibraryExt/entry/src/main/ets"
|
||||
}
|
||||
|
||||
ohos_app_scope("RingtoneLibStage_app_profile") {
|
||||
app_profile = "RingtoneLibraryExt/AppScope/app.json"
|
||||
sources = [ "RingtoneLibraryExt/AppScope/resources" ]
|
||||
}
|
||||
|
||||
ohos_resources("RingtoneLibStage_resources") {
|
||||
hap_profile = "RingtoneLibraryExt/entry/src/main/module.json"
|
||||
deps = [ ":RingtoneLibStage_app_profile" ]
|
||||
sources = [ "RingtoneLibraryExt/entry/src/main/resources" ]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/local.properties
|
||||
/.idea
|
||||
**/build
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.ringtonelibrary.ringtonelibrarydata",
|
||||
"vendor": "huawei",
|
||||
"versionCode": 10000000,
|
||||
"versionName": "1.0.0.0",
|
||||
"minAPIVersion": 12,
|
||||
"targetAPIVersion": 12,
|
||||
"KeepAlive": false,
|
||||
"removable": false,
|
||||
"singleton": false,
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"generateBuildHash": true,
|
||||
"distributedNotificationEnabled": true
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "RingtoneLibraryExt"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"app": {
|
||||
"compileSdkVersion": 12,
|
||||
"compatibleSdkVersion": 12,
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/node_modules
|
||||
/.preview
|
||||
/build
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"apiType": 'stageMode',
|
||||
"buildOption": {
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"license":"ISC",
|
||||
"devDependencies":{},
|
||||
"name":"entry",
|
||||
"ohos":{
|
||||
"org":"huawei",
|
||||
"directoryLevel":"module",
|
||||
"buildTool":"hvigor"
|
||||
},
|
||||
"description":"example description",
|
||||
"repository":{},
|
||||
"version":"1.0.0",
|
||||
"dependencies":{}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityStage from '@ohos.app.ability.AbilityStage';
|
||||
|
||||
export default class MyAbilityStage extends AbilityStage {
|
||||
onCreate(): void {
|
||||
console.log('[Ringtone] MyAbilityStage onCreate');
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Extension from '@ohos.application.DataShareExtensionAbility';
|
||||
|
||||
export default class DataShareExtAbility extends Extension {
|
||||
private rdbStore_;
|
||||
|
||||
onCreate(want): void {
|
||||
console.log('[RingtoneDataShare] <<Provider>> DataShareExtAbility onCreate, want:' + want.abilityName);
|
||||
}
|
||||
|
||||
getFileTypes(uri: string, mimeTypeFilter: string): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [getFileTypes] enter');
|
||||
}
|
||||
|
||||
insert(uri, value, callback): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [insert] enter');
|
||||
}
|
||||
|
||||
update(uri, value, predicates, callback): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [update] enter');
|
||||
}
|
||||
|
||||
delete(uri, predicates, callback): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [delete] enter');
|
||||
}
|
||||
|
||||
query(uri, columns, predicates, callback): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [query] enter');
|
||||
}
|
||||
|
||||
getType(uri: string): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [getType] enter');
|
||||
}
|
||||
|
||||
batchInsert(uri: string, valueBuckets, callback): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [batchInsert] enter');
|
||||
}
|
||||
|
||||
normalizeUri(uri: string): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [normalizeUri] enter');
|
||||
}
|
||||
|
||||
denormalizeUri(uri: string): void {
|
||||
console.info('[RingtoneDataShare] <<Provider>> [denormalizeUri] enter');
|
||||
}
|
||||
};
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.app.ability.UIAbility';
|
||||
|
||||
export default class MainAbility extends Ability {
|
||||
onCreate(want, launchParam): void {
|
||||
console.log('[Ringtone] MainAbility onCreate');
|
||||
globalThis.abilityWant = want;
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
console.log('[Ringtone] MainAbility onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
console.log('[Ringtone] MainAbility onWindowStageCreate');
|
||||
windowStage.setUIContent(this.context, 'pages/index', null);
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
console.log('[Ringtone] MainAbility onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
console.log('[Ringtone] MainAbility onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
console.log('[Ringtone] MainAbility onBackground');
|
||||
}
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State message: string = 'Hello World'
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"srcEntrance": "./ets/Application/AbilityStage.ts",
|
||||
"description": "$string:entry_desc",
|
||||
"mainElement": "MainAbility",
|
||||
"deviceTypes": [
|
||||
"default",
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"uiSyntax": "ets",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "MainAbility",
|
||||
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:app_name",
|
||||
"visible": false
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"srcEntrance": "./ets/DataShareExtAbility/DataShareExtAbility.ts",
|
||||
"name": "DataShareExtAbility",
|
||||
"icon": "$media:icon",
|
||||
"srcLanguage": "ets",
|
||||
"description": "$string:DataShareExtAbility_desc",
|
||||
"type": "dataShare",
|
||||
"uri": "datashare://ringtone",
|
||||
"visible": true
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.PERMISSION_USED_STATS",
|
||||
"reason": "$string:permission_used_stats",
|
||||
"usedScene": {
|
||||
"abilities": [
|
||||
"DataShareExtAbility"
|
||||
],
|
||||
"when": "inuse"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.PROXY_AUTHORIZATION_URI",
|
||||
"reason": "$string:permission_proxy_authorization_uri",
|
||||
"usedScene": {
|
||||
"abilities": [
|
||||
"DataShareExtAbility"
|
||||
],
|
||||
"when": "inuse"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED",
|
||||
"reason": "$string:permission_get_bundle_info_privileged",
|
||||
"usedScene": {
|
||||
"abilities": [
|
||||
"DataShareExtAbility"
|
||||
],
|
||||
"when": "inuse"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "DataShareExtAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "permission_used_stats",
|
||||
"value": "Allow the application to access the permission usage records"
|
||||
},
|
||||
{
|
||||
"name": "permission_proxy_authorization_uri",
|
||||
"value": "Allow the application proxy to grant URIs"
|
||||
},
|
||||
{
|
||||
"name": "permission_get_bundle_info_privileged",
|
||||
"value": "Allows querying of the app's basic information and other sensitive information"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/index"
|
||||
]
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.app.ability.UIAbility';
|
||||
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
|
||||
import { Hypium } from 'hypium/index';
|
||||
import testsuite from '../test/List.test';
|
||||
|
||||
export default class TestAbility extends Ability {
|
||||
onCreate(want, launchParam): void {
|
||||
console.log('TestAbility onCreate');
|
||||
let abilityDelegator;
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
let abilityDelegatorArguments;
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
|
||||
console.info('start run testcase!!!');
|
||||
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
console.log('TestAbility onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage): void {
|
||||
console.log('TestAbility onWindowStageCreate');
|
||||
windowStage.setUIContent(this.context, 'TestAbility/pages/index', null);
|
||||
|
||||
globalThis.abilityContext = this.context;
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
console.log('TestAbility onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
console.log('TestAbility onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
console.log('TestAbility onBackground');
|
||||
}
|
||||
};
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import router from '@ohos.router';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
aboutToAppear() {
|
||||
console.info('TestAbility index aboutToAppear')
|
||||
}
|
||||
@State message: string = 'Hello World'
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Text(this.message)
|
||||
.fontSize(50)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
Button() {
|
||||
Text('next page')
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
}.type(ButtonType.Capsule)
|
||||
.margin({
|
||||
top: 20
|
||||
})
|
||||
.backgroundColor('#0D9FFB')
|
||||
.width('35%')
|
||||
.height('5%')
|
||||
.onClick(()=>{
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
.height('100%')
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import TestRunner from '@ohos.application.testRunner';
|
||||
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
|
||||
|
||||
let abilityDelegator = undefined;
|
||||
let abilityDelegatorArguments = undefined;
|
||||
|
||||
function translateParamsToString(parameters): string {
|
||||
const keySet = new Set([
|
||||
'-s class', '-s notClass', '-s suite', '-s it',
|
||||
'-s level', '-s testType', '-s size', '-s timeout'
|
||||
])
|
||||
let targetParams = '';
|
||||
for (const key in parameters) {
|
||||
if (keySet.has(key)) {
|
||||
targetParams = `${targetParams} ${key} ${parameters[key]}`;
|
||||
}
|
||||
}
|
||||
return targetParams.trim();
|
||||
}
|
||||
|
||||
async function onAbilityCreateCallback(): Promise<void> {
|
||||
console.log('onAbilityCreateCallback');
|
||||
}
|
||||
|
||||
async function addAbilityMonitorCallback(err): Promise<void> {
|
||||
console.info('addAbilityMonitorCallback : ' + JSON.stringify(err));
|
||||
}
|
||||
|
||||
export default class OpenHarmonyTestRunner implements TestRunner {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
onPrepare(): void {
|
||||
console.info('OpenHarmonyTestRunner OnPrepare ');
|
||||
}
|
||||
|
||||
async onRun(): Promise<void> {
|
||||
console.log('OpenHarmonyTestRunner onRun run');
|
||||
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
|
||||
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
let testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility';
|
||||
let lMonitor = {
|
||||
abilityName: testAbilityName,
|
||||
onAbilityCreate: onAbilityCreateCallback,
|
||||
};
|
||||
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback);
|
||||
let cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName;
|
||||
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters);
|
||||
console.info('cmd : ' + cmd);
|
||||
abilityDelegator.executeShellCommand(cmd,
|
||||
(err, d) => {
|
||||
console.info('executeShellCommand : err : ' + JSON.stringify(err));
|
||||
console.info('executeShellCommand : data : ' + d.stdResult);
|
||||
console.info('executeShellCommand : data : ' + d.exitCode);
|
||||
});
|
||||
console.info('OpenHarmonyTestRunner onRun end');
|
||||
}
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index'
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', function () {
|
||||
it('assertContain',0, function () {
|
||||
console.info("it begin")
|
||||
let a = 'abc'
|
||||
let b = 'b'
|
||||
expect(a).assertContain(b)
|
||||
expect(a).assertEqual(a)
|
||||
})
|
||||
})
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import abilityTest from './Ability.test'
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
|
||||
"description": "$string:entry_test_desc",
|
||||
"mainElement": "TestAbility",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:test_pages",
|
||||
"uiSyntax": "ets",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "TestAbility",
|
||||
"srcEntrance": "./ets/TestAbility/TestAbility.ts",
|
||||
"description": "$string:TestAbility_desc",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:TestAbility_label",
|
||||
"visible": true,
|
||||
"skills": [
|
||||
{
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
],
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_test_desc",
|
||||
"value": "i am an entry for tv"
|
||||
},
|
||||
{
|
||||
"name": "TestAbility_desc",
|
||||
"value": "the tv entry test ability"
|
||||
},
|
||||
{
|
||||
"name": "TestAbility_label",
|
||||
"value": "tvBase"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"TestAbility/pages/index"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
module.exports = require('@ohos/hvigor-ohos-plugin').appTasks
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"license":"ISC",
|
||||
"devDependencies":{},
|
||||
"name":"ringtonelibrarydata",
|
||||
"ohos":{
|
||||
"org":"huawei",
|
||||
"directoryLevel":"project",
|
||||
"buildTool":"hvigor"
|
||||
},
|
||||
"description":"example description",
|
||||
"repository":{},
|
||||
"version":"1.0.0",
|
||||
"dependencies":{
|
||||
"@ohos/hvigor-ohos-plugin":"1.0.6",
|
||||
"hypium":"^1.0.0",
|
||||
"@ohos/hvigor":"1.0.6"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################################################
|
||||
# below is the format of defining event #
|
||||
#####################################################
|
||||
#domain: domain name. [Only one domain name can be defined at the top]
|
||||
#
|
||||
#author: the author name who defined this event.
|
||||
#date: the date when this event was defined, format is YYYY-MM-DD.
|
||||
#logged: source file which refer to this event.
|
||||
#usage: the usage of this event.
|
||||
#//Define event name and event properties.
|
||||
#@EVENT_NAME: the event definition part begin.
|
||||
# // __BASE is used for defining the basic info of the event.
|
||||
# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR.
|
||||
# // "level" optional values are: CRITICAL, MINOR.
|
||||
# // "tag" set tags with may used by subscriber of this event, multiple tags divided by space.
|
||||
# // "desc" full description of this event.
|
||||
# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}.
|
||||
# // follow the __BASE block, each line defines a parameter of this event.
|
||||
# // "type" optional values are: INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING.
|
||||
# // "arrsize" of the parameter is an array, set a non-zero value.
|
||||
# // "desc" full description of this parameter.
|
||||
|
||||
# DESCRIPTION contains userid,request type.
|
||||
# REASON contains errno num, and failed interface.
|
||||
|
||||
domain: RINGTONELIBRARY
|
||||
|
||||
RINGTONELIB_DFX_MESSAGE:
|
||||
__BASE: { type: STATISTIC, level: MINOR, desc: preset and custom ringtone number }
|
||||
DATE: { type: STRING, desc: report date }
|
||||
PRESET_NUM: { type: INT32, desc: preset ringtone number }
|
||||
CUSTOM_NUM: { type: INT32, desc: custom ringtone number }
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_RINGTONE_BUNDLE_MANAGER_H
|
||||
#define OHOS_RINGTONE_BUNDLE_MANAGER_H
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class RingtoneBundleManager {
|
||||
public:
|
||||
RingtoneBundleManager() = default;
|
||||
~RingtoneBundleManager() = default;
|
||||
static std::shared_ptr<RingtoneBundleManager> GetInstance();
|
||||
std::string GetClientBundleName();
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
void GetBundleNameByUid(const int32_t uid, std::string &bundleName);
|
||||
|
||||
// BundleMessage is the pair of bundleName and whether bundle is system app
|
||||
std::list<std::pair<int32_t, std::string>> cacheList_;
|
||||
std::unordered_map<int32_t, std::list<std::pair<int32_t, std::string>>::iterator> cacheMap_;
|
||||
std::mutex uninstallMutex_;
|
||||
|
||||
static std::mutex mutex_;
|
||||
static std::shared_ptr<RingtoneBundleManager> instance_;
|
||||
};
|
||||
} // RingtoneBundleManager
|
||||
} // OHOS
|
||||
#endif // OHOS_RINGTONE_BUNDLE_MANAGER_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_COLUMN_DATA_COMMAND_H
|
||||
#define RINGTONE_COLUMN_DATA_COMMAND_H
|
||||
|
||||
#include "abs_rdb_predicates.h"
|
||||
#include "datashare_predicates.h"
|
||||
#include "ringtone_db_const.h"
|
||||
#include "uri.h"
|
||||
#include "values_bucket.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
enum class EXPORT RingtoneOperationType : uint32_t {
|
||||
UNKNOWN_TYPE = 0,
|
||||
OPEN,
|
||||
INSERT,
|
||||
DELETE,
|
||||
UPDATE,
|
||||
QUERY,
|
||||
SCAN,
|
||||
};
|
||||
|
||||
class RingtoneDataCommand {
|
||||
public:
|
||||
EXPORT explicit RingtoneDataCommand(const Uri &uri, const std::string &table, const RingtoneOperationType type);
|
||||
EXPORT RingtoneDataCommand() = delete;
|
||||
EXPORT ~RingtoneDataCommand();
|
||||
EXPORT RingtoneDataCommand(const RingtoneDataCommand &) = delete;
|
||||
EXPORT RingtoneDataCommand &operator=(const RingtoneDataCommand &) = delete;
|
||||
EXPORT RingtoneDataCommand(RingtoneDataCommand &&) = delete;
|
||||
EXPORT RingtoneDataCommand &operator=(RingtoneDataCommand &&) = delete;
|
||||
|
||||
const Uri &GetUri() const;
|
||||
const std::string &GetTableName();
|
||||
NativeRdb::ValuesBucket &GetValueBucket();
|
||||
EXPORT NativeRdb::AbsRdbPredicates *GetAbsRdbPredicates();
|
||||
const std::string &GetBundleName();
|
||||
const std::string &GetResult();
|
||||
|
||||
EXPORT void SetDataSharePred(const DataShare::DataSharePredicates &pred);
|
||||
EXPORT void SetValueBucket(const NativeRdb::ValuesBucket &value);
|
||||
void SetBundleName(const std::string &bundleName);
|
||||
void SetResult(const std::string &result);
|
||||
RingtoneOperationType GetOprnType() const;
|
||||
private:
|
||||
static int32_t GetToneIdFromUri(Uri &uri);
|
||||
|
||||
Uri uri_ {""};
|
||||
std::string tableName_;
|
||||
RingtoneOperationType oprnType_ {RingtoneOperationType::UNKNOWN_TYPE};
|
||||
int32_t toneId_;
|
||||
NativeRdb::ValuesBucket insertValue_;
|
||||
std::unique_ptr<NativeRdb::AbsRdbPredicates> absRdbPredicates_;
|
||||
std::unique_ptr<const DataShare::DataSharePredicates> datasharePred_;
|
||||
std::string bundleName_;
|
||||
std::string result_;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // RINGTONE_COLUMN_DATA_COMMAND_H
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_COLUMN_DATA_MANAGER_H
|
||||
#define RINGTONE_COLUMN_DATA_MANAGER_H
|
||||
|
||||
#include "datashare_values_bucket.h"
|
||||
#include "rdb_utils.h"
|
||||
#include "ringtone_asset.h"
|
||||
#include "ringtone_data_command.h"
|
||||
#include "ringtone_datashare_extension.h"
|
||||
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class RingtoneDataShareExtension;
|
||||
}
|
||||
namespace Media {
|
||||
using OHOS::AbilityRuntime::RingtoneDataShareExtension;
|
||||
class RingtoneDataManager {
|
||||
public:
|
||||
EXPORT RingtoneDataManager();
|
||||
EXPORT ~RingtoneDataManager();
|
||||
EXPORT static std::shared_ptr<RingtoneDataManager> GetInstance();
|
||||
|
||||
EXPORT int32_t Insert(RingtoneDataCommand &cmd, const DataShare::DataShareValuesBucket &value);
|
||||
EXPORT int32_t Delete(RingtoneDataCommand &cmd, const DataShare::DataSharePredicates &predicates);
|
||||
EXPORT int32_t Update(RingtoneDataCommand &cmd, const DataShare::DataShareValuesBucket &value,
|
||||
const DataShare::DataSharePredicates &predicates);
|
||||
EXPORT std::shared_ptr<DataShare::ResultSetBridge> Query(RingtoneDataCommand &cmd,
|
||||
const std::vector<std::string> &columns, const DataShare::DataSharePredicates &predicates, int &errCode);
|
||||
EXPORT int32_t OpenFile(RingtoneDataCommand &cmd, const std::string &mode);
|
||||
|
||||
EXPORT int32_t Init(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
|
||||
EXPORT void ClearRingtoneDataMgr();
|
||||
EXPORT void SetOwner(const std::shared_ptr<RingtoneDataShareExtension> &datashareExtension);
|
||||
EXPORT std::shared_ptr<RingtoneDataShareExtension> GetOwner();
|
||||
private:
|
||||
std::string GetIdFromUri(Uri &uri);
|
||||
std::shared_ptr<RingtoneAsset> GetRingtoneAssetFromId(const std::string &id);
|
||||
int32_t DeleteFileFromResultSet(std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
std::shared_mutex mgrSharedMutex_;
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context_ = nullptr;
|
||||
static std::mutex mutex_;
|
||||
static std::shared_ptr<RingtoneDataManager> instance_;
|
||||
std::atomic<int> refCnt_ {0};
|
||||
std::shared_ptr<RingtoneDataShareExtension> extension_ = nullptr;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // RINGTONE_COLUMN_DATA_MANAGER_H
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_RINGTONE_COLUMN_DATASHARE_EXT_ABILITY_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_RINGTONE_COLUMN_DATASHARE_EXT_ABILITY_H
|
||||
|
||||
#include "datashare_ext_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace DataShare;
|
||||
/**
|
||||
* @brief Basic datashare extension ability components.
|
||||
*/
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
class RingtoneDataShareExtension : public DataShareExtAbility {
|
||||
public:
|
||||
EXPORT RingtoneDataShareExtension(Runtime &runtime);
|
||||
EXPORT virtual ~RingtoneDataShareExtension() override;
|
||||
|
||||
/**
|
||||
* @brief Create RingtoneDataShareExtension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The RingtoneDataShareExtension instance.
|
||||
*/
|
||||
EXPORT static RingtoneDataShareExtension *Create(const std::unique_ptr<Runtime> &runtime);
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
EXPORT void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this datashare extension ability is started. You must override this function if you want to
|
||||
* perform some initialization operations during extension startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an extension.
|
||||
* @param Want Indicates the {@link Want} structure containing startup information about the extension.
|
||||
*/
|
||||
EXPORT void OnStart(const AAFwk::Want &want) override;
|
||||
|
||||
EXPORT void OnStop() override;
|
||||
|
||||
/**
|
||||
* @brief Called when this datashare extension ability is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the datashare
|
||||
* extension.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected datashare extension ability.
|
||||
*/
|
||||
EXPORT sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
|
||||
/**
|
||||
* @brief Inserts a single data record into the database.
|
||||
*
|
||||
* @param uri Indicates the path of the data to operate.
|
||||
* @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
|
||||
*
|
||||
* @return Returns the index of the inserted data record.
|
||||
*/
|
||||
EXPORT int Insert(const Uri &uri, const DataShareValuesBucket &value) override;
|
||||
|
||||
/**
|
||||
* @brief Deletes one or more data records from the database.
|
||||
*
|
||||
* @param uri Indicates the path of the data to operate.
|
||||
* @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
|
||||
*
|
||||
* @return Returns the number of data records deleted.
|
||||
*/
|
||||
EXPORT int Delete(const Uri &uri, const DataSharePredicates &predicates) override;
|
||||
|
||||
/**
|
||||
* @brief Updates data records in the database.
|
||||
*
|
||||
* @param uri Indicates the path of data to update.
|
||||
* @param value Indicates the data to update. This parameter can be null.
|
||||
* @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
|
||||
*
|
||||
* @return Returns the number of data records updated.
|
||||
*/
|
||||
EXPORT int Update(const Uri &uri, const DataSharePredicates &predicates,
|
||||
const DataShareValuesBucket &value) override;
|
||||
|
||||
/**
|
||||
* @brief query one or more data records from the database.
|
||||
*
|
||||
* @param uri Indicates the path of data to query.
|
||||
* @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
|
||||
* @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
|
||||
* @param businessError Indicates errorcode and message.
|
||||
|
||||
* @return Returns the query result.
|
||||
*/
|
||||
EXPORT std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
|
||||
std::vector<std::string> &columns, DatashareBusinessError &businessError) override;
|
||||
|
||||
/**
|
||||
* @brief Opens a file in a specified remote path.
|
||||
*
|
||||
* @param uri Indicates the path of the file to open.
|
||||
* @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
|
||||
* (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
|
||||
* "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
|
||||
* or "rwt" for read and write access that truncates any existing file.
|
||||
*
|
||||
* @return Returns the file descriptor.
|
||||
*/
|
||||
EXPORT int OpenFile(const Uri &uri, const std::string &mode) override;
|
||||
private:
|
||||
static void DumpDataShareValueBucket(const std::vector<std::string> &tabFields, const DataShareValuesBucket &value);
|
||||
Runtime &runtime_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_RINGTONE_COLUMN_DATASHARE_EXT_ABILITY_H
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_COLUMN_DATASHARE_STUB_IMPL_H
|
||||
#define RINGTONE_COLUMN_DATASHARE_STUB_IMPL_H
|
||||
|
||||
#include "datashare_stub.h"
|
||||
#include "ringtone_datashare_extension.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DataShare {
|
||||
using DataShare::RingtoneDataShareExtension;
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
class EXPORT RingtoneDataShareStubImpl : public DataShareStub {
|
||||
public:
|
||||
EXPORT explicit RingtoneDataShareStubImpl(const std::shared_ptr<RingtoneDataShareExtension>& extension,
|
||||
napi_env env) : extension_(extension) {}
|
||||
|
||||
EXPORT virtual ~RingtoneDataShareStubImpl() {}
|
||||
|
||||
EXPORT std::vector<std::string> GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter) override;
|
||||
|
||||
EXPORT int OpenFile(const Uri &uri, const std::string &mode) override;
|
||||
|
||||
EXPORT int Insert(const Uri &uri, const DataShareValuesBucket &value) override;
|
||||
|
||||
EXPORT int InsertExt(const Uri &uri, const DataShareValuesBucket &value, std::string &result) override;
|
||||
|
||||
EXPORT int Update(const Uri &uri, const DataSharePredicates &predicates,
|
||||
const DataShareValuesBucket &value) override;
|
||||
|
||||
EXPORT int Delete(const Uri &uri, const DataSharePredicates &predicates) override;
|
||||
|
||||
EXPORT std::shared_ptr<DataShareResultSet> Query(const Uri &uri, const DataSharePredicates &predicates,
|
||||
std::vector<std::string> &columns, DatashareBusinessError &businessError) override;
|
||||
|
||||
EXPORT int OpenRawFile(const Uri &uri, const std::string &mode) override;
|
||||
|
||||
EXPORT std::string GetType(const Uri &uri) override;
|
||||
|
||||
EXPORT int BatchInsert(const Uri &uri, const std::vector<DataShareValuesBucket> &values) override;
|
||||
|
||||
EXPORT bool RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
|
||||
|
||||
EXPORT bool UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver) override;
|
||||
|
||||
EXPORT bool NotifyChange(const Uri &uri) override;
|
||||
|
||||
EXPORT Uri NormalizeUri(const Uri &uri) override;
|
||||
|
||||
EXPORT Uri DenormalizeUri(const Uri &uri) override;
|
||||
|
||||
private:
|
||||
EXPORT std::shared_ptr<RingtoneDataShareExtension> GetOwner();
|
||||
|
||||
private:
|
||||
std::shared_ptr<RingtoneDataShareExtension> extension_;
|
||||
};
|
||||
} // namespace Media_DataShare
|
||||
} // namespace OHOS
|
||||
#endif // RINGTONE_COLUMN_DATASHARE_STUB_IMPL_H
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_RDBSTORE_H
|
||||
#define RINGTONE_RDBSTORE_H
|
||||
|
||||
#include "ringtone_unistore.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
|
||||
class RingtoneDataCallBack;
|
||||
|
||||
class RingtoneRdbStore final : public RingtoneUnistore {
|
||||
public:
|
||||
EXPORT static RingtoneUnistore *GetInstance(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context =
|
||||
nullptr);
|
||||
EXPORT virtual ~RingtoneRdbStore();
|
||||
|
||||
EXPORT virtual int32_t Init() override;
|
||||
EXPORT virtual void Stop() override;
|
||||
|
||||
EXPORT virtual int32_t Insert(RingtoneDataCommand &cmd, int64_t &rowId) override;
|
||||
EXPORT virtual int32_t Delete(RingtoneDataCommand &cmd, int32_t &deletedRows) override;
|
||||
EXPORT virtual int32_t Update(RingtoneDataCommand &cmd, int32_t &changedRows) override;
|
||||
EXPORT std::shared_ptr<NativeRdb::ResultSet> Query(RingtoneDataCommand &cmd,
|
||||
const std::vector<std::string> &columns) override;
|
||||
|
||||
EXPORT int32_t ExecuteSql(const std::string &sql) override;
|
||||
EXPORT std::shared_ptr<NativeRdb::ResultSet> QuerySql(const std::string &sql,
|
||||
const std::vector<std::string> &selectionArgs = std::vector<std::string>()) override;
|
||||
EXPORT std::shared_ptr<NativeRdb::RdbStore> GetRaw() override;
|
||||
private:
|
||||
explicit RingtoneRdbStore(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
|
||||
|
||||
std::string bundleName_ {BUNDLE_NAME};
|
||||
NativeRdb::RdbStoreConfig config_ {""};
|
||||
static std::shared_ptr<NativeRdb::RdbStore> rdbStore_;
|
||||
};
|
||||
|
||||
class RingtoneDataCallBack : public NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override;
|
||||
int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override;
|
||||
private:
|
||||
static int32_t InitSql(NativeRdb::RdbStore &store);
|
||||
static int32_t PrepareDir();
|
||||
static int32_t CreatePreloadFolder(const std::string &path);
|
||||
static int32_t MkdirRecursive(const std::string &path, size_t start);
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // RINGTONE_RDBSTORE_H
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef RINGTONE_SUBSCRIBER_H
|
||||
#define RINGTONE_SUBSCRIBER_H
|
||||
|
||||
#include "common_event_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
class EXPORT RingtoneSubscriber : public EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
EXPORT RingtoneSubscriber() = default;
|
||||
EXPORT explicit RingtoneSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo);
|
||||
EXPORT static bool Subscribe(void);
|
||||
EXPORT virtual ~RingtoneSubscriber() = default;
|
||||
|
||||
EXPORT virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override;
|
||||
|
||||
private:
|
||||
static const std::vector<std::string> events_;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // RINGTONE_SUBSCRIBER_H
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_UNISTORE_H
|
||||
#define RINGTONE_UNISTORE_H
|
||||
|
||||
#include "ability_context.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "ringtone_data_command.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
class RingtoneUnistore {
|
||||
public:
|
||||
EXPORT RingtoneUnistore() = default;
|
||||
EXPORT virtual ~RingtoneUnistore() = default;
|
||||
|
||||
EXPORT virtual int32_t Init() = 0;
|
||||
EXPORT virtual void Stop() = 0;
|
||||
|
||||
EXPORT virtual int32_t Insert(RingtoneDataCommand &cmd, int64_t &rowId) = 0;
|
||||
EXPORT virtual int32_t Delete(RingtoneDataCommand &cmd, int32_t &rowId) = 0;
|
||||
EXPORT virtual int32_t Update(RingtoneDataCommand &cmd, int32_t &rowId) = 0;
|
||||
EXPORT virtual std::shared_ptr<NativeRdb::ResultSet> Query(RingtoneDataCommand &cmd,
|
||||
const std::vector<std::string> &columns)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EXPORT virtual int32_t ExecuteSql(const std::string &sql)
|
||||
{
|
||||
return NativeRdb::E_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
EXPORT virtual std::shared_ptr<NativeRdb::ResultSet> QuerySql(const std::string &sql,
|
||||
const std::vector<std::string> &selectionArgs = std::vector<std::string>())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
EXPORT virtual std::shared_ptr<NativeRdb::RdbStore> GetRaw() = 0;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // RINGTONE_UNISTORE_H
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define MLOG_TAG "RingtoneBundleManager"
|
||||
|
||||
#include "ringtone_bundle_manager.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
#include "permission_utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
const int CAPACITY = 50;
|
||||
shared_ptr<RingtoneBundleManager> RingtoneBundleManager::instance_ = nullptr;
|
||||
mutex RingtoneBundleManager::mutex_;
|
||||
shared_ptr<RingtoneBundleManager> RingtoneBundleManager::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = make_shared<RingtoneBundleManager>();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void RingtoneBundleManager::GetBundleNameByUid(const int32_t uid, string &bundleName)
|
||||
{
|
||||
RingtonePermissionUtils::GetClientBundle(uid, bundleName);
|
||||
if (bundleName.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = cacheMap_.find(uid);
|
||||
if (it != cacheMap_.end()) {
|
||||
cacheList_.erase(it->second);
|
||||
}
|
||||
cacheList_.push_front(make_pair(uid, bundleName));
|
||||
cacheMap_[uid] = cacheList_.begin();
|
||||
if (cacheMap_.size() > CAPACITY) {
|
||||
int32_t deleteKey = cacheList_.back().first;
|
||||
cacheMap_.erase(deleteKey);
|
||||
cacheList_.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
string RingtoneBundleManager::GetClientBundleName()
|
||||
{
|
||||
lock_guard<mutex> lock(uninstallMutex_);
|
||||
int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
auto iter = cacheMap_.find(uid);
|
||||
if (iter == cacheMap_.end()) {
|
||||
string bundleName;
|
||||
GetBundleNameByUid(uid, bundleName);
|
||||
return bundleName;
|
||||
}
|
||||
cacheList_.splice(cacheList_.begin(), cacheList_, iter->second);
|
||||
return iter->second->second;
|
||||
}
|
||||
|
||||
void RingtoneBundleManager::Clear()
|
||||
{
|
||||
lock_guard<mutex> lock(uninstallMutex_);
|
||||
cacheList_.clear();
|
||||
cacheMap_.clear();
|
||||
}
|
||||
} // Ringtone
|
||||
} // OHOS
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ringtone_data_command.h"
|
||||
|
||||
#include "ringtone_errno.h"
|
||||
#include "ringtone_log.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::NativeRdb;
|
||||
using namespace OHOS::DataShare;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
RingtoneDataCommand::RingtoneDataCommand(const Uri &uri, const string &table, const RingtoneOperationType type)
|
||||
: uri_(uri), tableName_(table), oprnType_(type), toneId_(-1)
|
||||
{
|
||||
toneId_ = GetToneIdFromUri(uri_);
|
||||
}
|
||||
|
||||
RingtoneDataCommand::~RingtoneDataCommand() {}
|
||||
|
||||
// set functions
|
||||
void RingtoneDataCommand::SetDataSharePred(const DataShare::DataSharePredicates &pred)
|
||||
{
|
||||
datasharePred_ = make_unique<const DataSharePredicates>(pred);
|
||||
}
|
||||
|
||||
void RingtoneDataCommand::SetValueBucket(const NativeRdb::ValuesBucket &value)
|
||||
{
|
||||
insertValue_ = value;
|
||||
}
|
||||
|
||||
void RingtoneDataCommand::SetBundleName(const string &bundleName)
|
||||
{
|
||||
bundleName_ = bundleName;
|
||||
}
|
||||
|
||||
void RingtoneDataCommand::SetResult(const string &result)
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
|
||||
// get functions
|
||||
ValuesBucket &RingtoneDataCommand::GetValueBucket()
|
||||
{
|
||||
return insertValue_;
|
||||
}
|
||||
|
||||
AbsRdbPredicates *RingtoneDataCommand::GetAbsRdbPredicates()
|
||||
{
|
||||
if (absRdbPredicates_ == nullptr) {
|
||||
absRdbPredicates_ = make_unique<AbsRdbPredicates>(tableName_);
|
||||
}
|
||||
return absRdbPredicates_.get();
|
||||
}
|
||||
|
||||
const string &RingtoneDataCommand::GetTableName()
|
||||
{
|
||||
return tableName_;
|
||||
}
|
||||
|
||||
const Uri &RingtoneDataCommand::GetUri() const
|
||||
{
|
||||
return uri_;
|
||||
}
|
||||
|
||||
const string &RingtoneDataCommand::GetBundleName()
|
||||
{
|
||||
return bundleName_;
|
||||
}
|
||||
|
||||
const string &RingtoneDataCommand::GetResult()
|
||||
{
|
||||
return result_;
|
||||
}
|
||||
|
||||
static bool IsNumber(const string &str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
RINGTONE_ERR_LOG("IsNumber input is empty ");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (char const &c : str) {
|
||||
if (isdigit(c) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCommand::GetToneIdFromUri(Uri &uri)
|
||||
{
|
||||
string uriStr = uri.ToString();
|
||||
if (uriStr.empty()) {
|
||||
return E_INVALID_URI;
|
||||
}
|
||||
|
||||
auto toneId = uriStr.substr(RINGTONE_PATH_URI.size(), uriStr.size());
|
||||
if (IsNumber(toneId)) {
|
||||
RINGTONE_INFO_LOG("Get toneId=%{public}s from Uri", toneId.c_str());
|
||||
return stoi(toneId);
|
||||
}
|
||||
|
||||
return E_INVALID_URI;
|
||||
}
|
||||
|
||||
RingtoneOperationType RingtoneDataCommand::GetOprnType() const
|
||||
{
|
||||
return oprnType_;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define MLOG_TAG "DataManager"
|
||||
|
||||
#include "ringtone_data_manager.h"
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "rdb_utils.h"
|
||||
#include "ringtone_fetch_result.h"
|
||||
#include "ringtone_file_utils.h"
|
||||
#include "ringtone_log.h"
|
||||
#include "ringtone_mimetype_utils.h"
|
||||
#include "ringtone_rdbstore.h"
|
||||
#include "ringtone_scanner_manager.h"
|
||||
#include "ringtone_tracer.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
using namespace OHOS::NativeRdb;
|
||||
using namespace OHOS::DataShare;
|
||||
using namespace OHOS::RdbDataShareAdapter;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
shared_ptr<RingtoneDataManager> RingtoneDataManager::instance_ = nullptr;
|
||||
mutex RingtoneDataManager::mutex_;
|
||||
RingtoneUnistore *g_uniStore_ = nullptr;
|
||||
|
||||
RingtoneDataManager::RingtoneDataManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
RingtoneDataManager::~RingtoneDataManager(void)
|
||||
{
|
||||
}
|
||||
|
||||
shared_ptr<RingtoneDataManager> RingtoneDataManager::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = make_shared<RingtoneDataManager>();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::Init(const shared_ptr<OHOS::AbilityRuntime::Context> &context)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
lock_guard<shared_mutex> lock(mgrSharedMutex_);
|
||||
|
||||
if (refCnt_.load() > 0) {
|
||||
RINGTONE_DEBUG_LOG("already initialized");
|
||||
refCnt_++;
|
||||
return E_OK;
|
||||
}
|
||||
context_ = context;
|
||||
if (g_uniStore_ == nullptr) {
|
||||
g_uniStore_ = RingtoneRdbStore::GetInstance(context_);
|
||||
if (g_uniStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("RingtoneDataManager is not initialized");
|
||||
return E_DB_FAIL;
|
||||
}
|
||||
}
|
||||
RingtoneMimeTypeUtils::InitMimeTypeMap();
|
||||
refCnt_++;
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::Insert(RingtoneDataCommand &cmd, const DataShareValuesBucket &dataShareValue)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
RINGTONE_ERR_LOG("RingtoneDataManager is not initialized");
|
||||
return E_FAIL;
|
||||
}
|
||||
if (g_uniStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdb store is not initialized");
|
||||
return E_DB_FAIL;
|
||||
}
|
||||
|
||||
ValuesBucket value = RdbUtils::ToValuesBucket(dataShareValue);
|
||||
if (value.IsEmpty()) {
|
||||
RINGTONE_ERR_LOG("RingtoneDataManager Insert: Input parameter is invalid");
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
cmd.SetValueBucket(value);
|
||||
|
||||
int64_t outRowId = E_HAS_DB_ERROR;
|
||||
auto retRdb = g_uniStore_->Insert(cmd, outRowId);
|
||||
if (retRdb != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("Insert operation failed. Result %{public}d.", retRdb);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
auto asset = GetRingtoneAssetFromId(to_string(outRowId));
|
||||
if (asset == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to get RingtoneAsset");
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
|
||||
auto ret = RingtoneFileUtils::CreateFile(asset->GetPath());
|
||||
if (ret != E_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return static_cast<int32_t>(outRowId);
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::DeleteFileFromResultSet(std::shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
auto count = 0;
|
||||
auto ret = resultSet->GetRowCount(count);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("get rdbstore failed");
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
if (count == 0) {
|
||||
RINGTONE_ERR_LOG("have no files to delete");
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
shared_ptr<RingtoneFetchResult<RingtoneAsset>> fetchResult = make_shared<RingtoneFetchResult<RingtoneAsset>>();
|
||||
if (fetchResult == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to obtain fetch file result");
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < count; i++) {
|
||||
auto asset = fetchResult->GetObjectFromRdb(resultSet, i);
|
||||
RingtoneFileUtils::DeleteFile(asset->GetPath());
|
||||
}
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::Delete(RingtoneDataCommand &cmd, const DataSharePredicates &predicates)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
RINGTONE_DEBUG_LOG("RingtoneDataManager is not initialized");
|
||||
return E_FAIL;
|
||||
}
|
||||
if (g_uniStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdb store is not initialized");
|
||||
return E_DB_FAIL;
|
||||
}
|
||||
|
||||
string uriString = cmd.GetUri().ToString();
|
||||
if (uriString.find(RINGTONE_URI) == string::npos) {
|
||||
RINGTONE_ERR_LOG("Not Data ability Uri");
|
||||
return E_INVALID_URI;
|
||||
}
|
||||
|
||||
NativeRdb::RdbPredicates rdbPredicate = RdbUtils::ToPredicates(predicates, cmd.GetTableName());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereClause(rdbPredicate.GetWhereClause());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereArgs(rdbPredicate.GetWhereArgs());
|
||||
|
||||
vector<string> columns = {RINGTONE_COLUMN_TONE_ID, RINGTONE_COLUMN_DATA};
|
||||
auto absResultSet = g_uniStore_->Query(cmd, columns);
|
||||
|
||||
DeleteFileFromResultSet(absResultSet);
|
||||
|
||||
int32_t deletedRows = E_HAS_DB_ERROR;
|
||||
int32_t ret = g_uniStore_->Delete(cmd, deletedRows);
|
||||
if (ret != NativeRdb::E_OK || deletedRows <= 0) {
|
||||
RINGTONE_ERR_LOG("Delete operation failed. Result %{public}d.", ret);
|
||||
deletedRows = E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return deletedRows;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::Update(RingtoneDataCommand &cmd, const DataShareValuesBucket &dataShareValue,
|
||||
const DataSharePredicates &predicates)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
RINGTONE_DEBUG_LOG("RingtoneDataManager is not initialized");
|
||||
return E_FAIL;
|
||||
}
|
||||
if (g_uniStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdb store is not initialized");
|
||||
return E_DB_FAIL;
|
||||
}
|
||||
|
||||
ValuesBucket value = RdbUtils::ToValuesBucket(dataShareValue);
|
||||
if (value.IsEmpty()) {
|
||||
RINGTONE_ERR_LOG("RingtoneDataManager Update:Input parameter is invalid");
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
|
||||
cmd.SetValueBucket(value);
|
||||
cmd.SetDataSharePred(predicates);
|
||||
NativeRdb::RdbPredicates rdbPredicate = RdbUtils::ToPredicates(predicates, cmd.GetTableName());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereClause(rdbPredicate.GetWhereClause());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereArgs(rdbPredicate.GetWhereArgs());
|
||||
|
||||
int32_t updatedRows = E_HAS_DB_ERROR;
|
||||
int32_t result = g_uniStore_->Update(cmd, updatedRows);
|
||||
if (result != NativeRdb::E_OK || updatedRows <= 0) {
|
||||
RINGTONE_ERR_LOG("Update operation failed. Result %{public}d. Updated %{public}d", result, updatedRows);
|
||||
updatedRows = E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return updatedRows;
|
||||
}
|
||||
|
||||
shared_ptr<ResultSetBridge> RingtoneDataManager::Query(RingtoneDataCommand &cmd,
|
||||
const vector<string> &columns, const DataSharePredicates &predicates, int &errCode)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
RINGTONE_DEBUG_LOG("RingtoneDataManager is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
if (g_uniStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdb store is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RingtoneDataManager::Query");
|
||||
cmd.SetDataSharePred(predicates);
|
||||
NativeRdb::RdbPredicates rdbPredicate = RdbUtils::ToPredicates(predicates, cmd.GetTableName());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereClause(rdbPredicate.GetWhereClause());
|
||||
cmd.GetAbsRdbPredicates()->SetWhereArgs(rdbPredicate.GetWhereArgs());
|
||||
cmd.GetAbsRdbPredicates()->SetOrder(rdbPredicate.GetOrder());
|
||||
|
||||
auto absResultSet = g_uniStore_->Query(cmd, columns);
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return RdbUtils::ToResultSetBridge(absResultSet);
|
||||
}
|
||||
|
||||
static bool IsNumber(const string &str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
RINGTONE_ERR_LOG("IsNumber input is empty ");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (char const &c : str) {
|
||||
if (isdigit(c) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataManager::OpenFile(RingtoneDataCommand &cmd, const string &mode)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RingtoneDataManager::OpenFile");
|
||||
string toneId = GetIdFromUri(const_cast<Uri &>(cmd.GetUri()));
|
||||
auto asset = GetRingtoneAssetFromId(toneId);
|
||||
if (asset == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to get RingtoneAsset");
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
|
||||
string absFilePath;
|
||||
if (!PathToRealPath(asset->GetPath(), absFilePath)) {
|
||||
RINGTONE_ERR_LOG("Failed to get real path: %{private}s", asset->GetPath().c_str());
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
RINGTONE_DEBUG_LOG("end");
|
||||
return RingtoneFileUtils::OpenFile(absFilePath, mode);
|
||||
}
|
||||
|
||||
void RingtoneDataManager::SetOwner(const shared_ptr<RingtoneDataShareExtension> &datashareExternsion)
|
||||
{
|
||||
extension_ = datashareExternsion;
|
||||
}
|
||||
|
||||
shared_ptr<RingtoneDataShareExtension> RingtoneDataManager::GetOwner()
|
||||
{
|
||||
return extension_;
|
||||
}
|
||||
|
||||
string RingtoneDataManager::GetIdFromUri(Uri &uri)
|
||||
{
|
||||
vector<string> segments;
|
||||
uri.GetPathSegments(segments);
|
||||
const int uriSegmentsCount = 3;
|
||||
const int toneIdSegmentNumber = 2;
|
||||
if (segments.size() != uriSegmentsCount || segments[1] != RINGTONE_URI_PATH ||
|
||||
!IsNumber(segments[toneIdSegmentNumber])) {
|
||||
return {};
|
||||
}
|
||||
return segments[toneIdSegmentNumber];
|
||||
}
|
||||
|
||||
shared_ptr<RingtoneAsset> RingtoneDataManager::GetRingtoneAssetFromId(const string &id)
|
||||
{
|
||||
if ((id.empty()) || (!IsNumber(id)) || (stoi(id) == -1)) {
|
||||
RINGTONE_ERR_LOG("Id for the path is incorrect: %{private}s", id.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
Uri uri("");
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::QUERY);
|
||||
cmd.GetAbsRdbPredicates()->EqualTo(RINGTONE_COLUMN_TONE_ID, id);
|
||||
|
||||
auto resultSet = g_uniStore_->Query(cmd, {RINGTONE_COLUMN_TONE_ID, RINGTONE_COLUMN_DATA});
|
||||
if (resultSet == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to obtain file asset from database");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<RingtoneFetchResult<RingtoneAsset>> fetchResult = make_shared<RingtoneFetchResult<RingtoneAsset>>();
|
||||
if (fetchResult == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to obtain fetch file result");
|
||||
return nullptr;
|
||||
}
|
||||
return fetchResult->GetObjectFromRdb(resultSet, 0);
|
||||
}
|
||||
|
||||
void RingtoneDataManager::ClearRingtoneDataMgr()
|
||||
{
|
||||
lock_guard<shared_mutex> lock(mgrSharedMutex_);
|
||||
|
||||
refCnt_--;
|
||||
if (refCnt_.load() > 0) {
|
||||
RINGTONE_DEBUG_LOG("still other extension exist");
|
||||
return;
|
||||
}
|
||||
|
||||
extension_ = nullptr;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "ringtone_Extension"
|
||||
|
||||
#include "ringtone_datashare_extension.h"
|
||||
|
||||
#include "app_mgr_client.h"
|
||||
#include "datashare_ext_ability_context.h"
|
||||
#include "dfx_manager.h"
|
||||
#include "parameter.h"
|
||||
#include "permission_utils.h"
|
||||
#include "ringtone_data_manager.h"
|
||||
#include "ringtone_datashare_stub_impl.h"
|
||||
#include "ringtone_log.h"
|
||||
#include "ringtone_scanner_manager.h"
|
||||
#include "runtime.h"
|
||||
#include "singleton.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
using namespace OHOS::NativeRdb;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::DataShare;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
const char RINGTONE_PARAMETER_SCANNER_COMPLETED_KEY[] = "ringtone.scanner.completed";
|
||||
const char RINGTONE_PARAMETER_SCANNER_COMPLETED_TRUE[] = "1";
|
||||
const char RINGTONE_PARAMETER_SCANNER_COMPLETED_FALSE[] = "0";
|
||||
const int32_t SYSPARA_SIZE = 64;
|
||||
|
||||
RingtoneDataShareExtension *RingtoneDataShareExtension::Create(const unique_ptr<Runtime> &runtime)
|
||||
{
|
||||
return new RingtoneDataShareExtension(static_cast<Runtime&>(*runtime));
|
||||
}
|
||||
|
||||
RingtoneDataShareExtension::RingtoneDataShareExtension(Runtime &runtime) : DataShareExtAbility(), runtime_(runtime) {}
|
||||
|
||||
RingtoneDataShareExtension::~RingtoneDataShareExtension()
|
||||
{
|
||||
}
|
||||
|
||||
void RingtoneDataShareExtension::Init(const shared_ptr<AbilityLocalRecord> &record,
|
||||
const shared_ptr<OHOSApplication> &application, shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
if ((record == nullptr) || (application == nullptr) || (handler == nullptr) || (token == nullptr)) {
|
||||
RINGTONE_ERR_LOG("RingtoneDataShareExtension::init failed, some object is nullptr");
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf();
|
||||
return;
|
||||
}
|
||||
DataShareExtAbility::Init(record, application, handler, token);
|
||||
}
|
||||
|
||||
void RingtoneDataShareExtension::OnStart(const AAFwk::Want &want)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
Extension::OnStart(want);
|
||||
auto context = AbilityRuntime::Context::GetApplicationContext();
|
||||
if (context == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to get context");
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf();
|
||||
return;
|
||||
}
|
||||
RINGTONE_INFO_LOG("runtime language %{public}d", runtime_.GetLanguage());
|
||||
auto dataManager = RingtoneDataManager::GetInstance();
|
||||
if (dataManager == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to get dataManager");
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf();
|
||||
return;
|
||||
}
|
||||
int32_t ret = dataManager->Init(context);
|
||||
if (ret != E_OK) {
|
||||
RINGTONE_ERR_LOG("Failed to init RingtoneData Mgr");
|
||||
DelayedSingleton<AppExecFwk::AppMgrClient>::GetInstance()->KillApplicationSelf();
|
||||
return;
|
||||
}
|
||||
dataManager->SetOwner(static_pointer_cast<RingtoneDataShareExtension>(shared_from_this()));
|
||||
auto dfxMgr = DfxManager::GetInstance();
|
||||
dfxMgr->Init(context);
|
||||
|
||||
// ringtone scan
|
||||
char scanCompletedValue[SYSPARA_SIZE] = {0};
|
||||
GetParameter(RINGTONE_PARAMETER_SCANNER_COMPLETED_KEY, RINGTONE_PARAMETER_SCANNER_COMPLETED_FALSE,
|
||||
scanCompletedValue, SYSPARA_SIZE);
|
||||
int isCompleted = atoi(scanCompletedValue);
|
||||
if (!isCompleted) {
|
||||
RingtoneScannerManager::GetInstance()->Start(false);
|
||||
SetParameter(RINGTONE_PARAMETER_SCANNER_COMPLETED_KEY, RINGTONE_PARAMETER_SCANNER_COMPLETED_TRUE);
|
||||
}
|
||||
RINGTONE_INFO_LOG("end.");
|
||||
}
|
||||
|
||||
void RingtoneDataShareExtension::OnStop()
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
auto scannerManager = RingtoneScannerManager::GetInstance();
|
||||
if (scannerManager != nullptr) {
|
||||
scannerManager->Stop();
|
||||
}
|
||||
RingtoneDataManager::GetInstance()->ClearRingtoneDataMgr();
|
||||
RINGTONE_INFO_LOG("end.");
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> RingtoneDataShareExtension::OnConnect(const AAFwk::Want &want)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
Extension::OnConnect(want);
|
||||
sptr<RingtoneDataShareStubImpl> remoteObject = new (nothrow) RingtoneDataShareStubImpl(
|
||||
static_pointer_cast<RingtoneDataShareExtension>(shared_from_this()),
|
||||
nullptr);
|
||||
if (remoteObject == nullptr) {
|
||||
RINGTONE_ERR_LOG("No memory allocated for DataShareStubImpl");
|
||||
return nullptr;
|
||||
}
|
||||
RINGTONE_INFO_LOG("end.");
|
||||
return remoteObject->AsObject();
|
||||
}
|
||||
|
||||
static int32_t CheckRingtonePerm(RingtoneDataCommand &cmd, bool isWrite)
|
||||
{
|
||||
auto err = E_SUCCESS;
|
||||
if (isWrite) {
|
||||
err = (RingtonePermissionUtils::CheckCallerPermission(PERM_WRITE_RINGTONE) ? E_SUCCESS : E_PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int32_t UriValidCheck(const Uri &uri)
|
||||
{
|
||||
string uriStr = uri.ToString();
|
||||
if (uriStr.compare(0, RINGTONE_PATH_URI.size(), RINGTONE_PATH_URI)) {
|
||||
RINGTONE_ERR_LOG("error: invalid uri!");
|
||||
return E_INVALID_URI;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
static const std::vector<string> g_ringToneTableFields = {
|
||||
{ RINGTONE_COLUMN_TONE_ID },
|
||||
{ RINGTONE_COLUMN_DATA },
|
||||
{ RINGTONE_COLUMN_SIZE },
|
||||
{ RINGTONE_COLUMN_DISPLAY_NAME },
|
||||
{ RINGTONE_COLUMN_TITLE },
|
||||
{ RINGTONE_COLUMN_MEDIA_TYPE },
|
||||
{ RINGTONE_COLUMN_TONE_TYPE },
|
||||
{ RINGTONE_COLUMN_MIME_TYPE },
|
||||
{ RINGTONE_COLUMN_SOURCE_TYPE },
|
||||
{ RINGTONE_COLUMN_DATE_ADDED },
|
||||
{ RINGTONE_COLUMN_DATE_MODIFIED },
|
||||
{ RINGTONE_COLUMN_DATE_TAKEN },
|
||||
{ RINGTONE_COLUMN_DURATION },
|
||||
{ RINGTONE_COLUMN_SHOT_TONE_TYPE },
|
||||
{ RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE },
|
||||
{ RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE },
|
||||
{ RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE },
|
||||
{ RINGTONE_COLUMN_RING_TONE_TYPE },
|
||||
{ RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE },
|
||||
{ RINGTONE_COLUMN_ALARM_TONE_TYPE },
|
||||
{ RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE },
|
||||
};
|
||||
|
||||
void RingtoneDataShareExtension::DumpDataShareValueBucket(const std::vector<string> &tabFields,
|
||||
const DataShareValuesBucket &value)
|
||||
{
|
||||
bool isValid = false;
|
||||
for (auto tab : tabFields) {
|
||||
auto valueObject = value.Get(tab, isValid);
|
||||
if (!isValid) {
|
||||
RINGTONE_INFO_LOG("not set field: %{public}s", tab.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (std::get_if<std::vector<uint8_t>>(&(valueObject.value))) {
|
||||
auto value = static_cast<std::vector<uint8_t>>(valueObject);
|
||||
RINGTONE_INFO_LOG("field: %{public}s, value=%{public}s",
|
||||
tab.c_str(), value.data());
|
||||
} else if (std::get_if<int64_t>(&(valueObject.value))) {
|
||||
auto value = static_cast<int64_t>(valueObject);
|
||||
RINGTONE_INFO_LOG("field: %{public}s, value=%{public}lld",
|
||||
tab.c_str(), value);
|
||||
} else if (std::get_if<std::string>(&(valueObject.value))) {
|
||||
auto value = static_cast<std::string>(valueObject);
|
||||
RINGTONE_INFO_LOG("field: %{public}s, value=%{public}s",
|
||||
tab.c_str(), value.c_str());
|
||||
} else if (std::get_if<bool>(&(valueObject.value))) {
|
||||
auto value = static_cast<bool>(valueObject);
|
||||
RINGTONE_INFO_LOG("field: %{public}s, value=%{public}d",
|
||||
tab.c_str(), value);
|
||||
} else if (std::get_if<double>(&(valueObject.value))) {
|
||||
auto value = static_cast<double>(valueObject);
|
||||
RINGTONE_INFO_LOG("field: %{public}s, value=%{public}lf",
|
||||
tab.c_str(), value);
|
||||
} else {
|
||||
RINGTONE_INFO_LOG("unkown field: %{public}s type", tab.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RingtoneDataShareExtension::Insert(const Uri &uri, const DataShareValuesBucket &value)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry, uri=%{public}s", uri.ToString().c_str());
|
||||
|
||||
DumpDataShareValueBucket(g_ringToneTableFields, value);
|
||||
|
||||
int err = UriValidCheck(uri);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::INSERT);
|
||||
err = CheckRingtonePerm(cmd, true);
|
||||
if (err < 0) {
|
||||
RINGTONE_ERR_LOG("Check Insert-permission failed, errCode: %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
auto ret = RingtoneDataManager::GetInstance()->Insert(cmd, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareExtension::Update(const Uri &uri, const DataSharePredicates &predicates,
|
||||
const DataShareValuesBucket &value)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry, uri=%{public}s", uri.ToString().c_str());
|
||||
RINGTONE_DEBUG_LOG("WhereClause=%{public}s", predicates.GetWhereClause().c_str());
|
||||
|
||||
int err = UriValidCheck(uri);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::UPDATE);
|
||||
err = CheckRingtonePerm(cmd, false);
|
||||
if (err < 0) {
|
||||
RINGTONE_ERR_LOG("Check Update-permission failed, errCode: %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return RingtoneDataManager::GetInstance()->Update(cmd, value, predicates);
|
||||
}
|
||||
|
||||
int RingtoneDataShareExtension::Delete(const Uri &uri, const DataSharePredicates &predicates)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry, uri=%{public}s", uri.ToString().c_str());
|
||||
|
||||
int err = UriValidCheck(uri);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::DELETE);
|
||||
err = CheckRingtonePerm(cmd, true);
|
||||
if (err < 0) {
|
||||
RINGTONE_ERR_LOG("Check Delete-permission failed, errCode: %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return RingtoneDataManager::GetInstance()->Delete(cmd, predicates);
|
||||
}
|
||||
|
||||
shared_ptr<DataShareResultSet> RingtoneDataShareExtension::Query(const Uri &uri,
|
||||
const DataSharePredicates &predicates, vector<string> &columns, DatashareBusinessError &businessError)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry, uri=%{public}s", uri.ToString().c_str());
|
||||
int err = UriValidCheck(uri);
|
||||
if (err != E_OK) {
|
||||
return nullptr;
|
||||
}
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::QUERY);
|
||||
err = CheckRingtonePerm(cmd, false);
|
||||
if (err < 0) {
|
||||
businessError.SetCode(err);
|
||||
RINGTONE_ERR_LOG("Check Query-permission failed, errCode: %{public}d", err);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int errCode = businessError.GetCode();
|
||||
auto queryResultSet = RingtoneDataManager::GetInstance()->Query(cmd, columns, predicates, errCode);
|
||||
businessError.SetCode(to_string(errCode));
|
||||
if (queryResultSet == nullptr) {
|
||||
RINGTONE_ERR_LOG("queryResultSet is nullptr! errCode: %{public}d", errCode);
|
||||
return nullptr;
|
||||
}
|
||||
shared_ptr<DataShareResultSet> resultSet = make_shared<DataShareResultSet>(queryResultSet);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
int RingtoneDataShareExtension::OpenFile(const Uri &uri, const string &mode)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry, uri=%{public}s, mode=%{public}s",
|
||||
uri.ToString().c_str(), mode.c_str());
|
||||
|
||||
int err = UriValidCheck(uri);
|
||||
if (err != E_OK) {
|
||||
return err;
|
||||
}
|
||||
RingtoneDataCommand cmd(uri, RINGTONE_TABLE, RingtoneOperationType::OPEN);
|
||||
|
||||
string unifyMode = mode;
|
||||
transform(unifyMode.begin(), unifyMode.end(), unifyMode.begin(), ::tolower);
|
||||
|
||||
err = CheckRingtonePerm(cmd, true);
|
||||
if (err == E_PERMISSION_DENIED) {
|
||||
RINGTONE_ERR_LOG("OpenFile denied, errCode: %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
return RingtoneDataManager::GetInstance()->OpenFile(cmd, unifyMode);
|
||||
}
|
||||
|
||||
static DataShare::DataShareExtAbility *RingtoneDataShareCreator(const unique_ptr<Runtime> &runtime)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("entry");
|
||||
return RingtoneDataShareExtension::Create(runtime);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) void RegisterDataShareCreator()
|
||||
{
|
||||
RINGTONE_ERR_LOG("entry");
|
||||
DataShare::DataShareExtAbility::SetCreator(RingtoneDataShareCreator);
|
||||
|
||||
RINGTONE_ERR_LOG("End");
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "Extension"
|
||||
|
||||
#include "ringtone_datashare_stub_impl.h"
|
||||
|
||||
#include "ringtone_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DataShare {
|
||||
std::shared_ptr<RingtoneDataShareExtension> RingtoneDataShareStubImpl::GetOwner()
|
||||
{
|
||||
return extension_;
|
||||
}
|
||||
|
||||
std::vector<std::string> RingtoneDataShareStubImpl::GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
std::vector<std::string> ret;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->GetFileTypes(uri, mimeTypeFilter);
|
||||
RINGTONE_INFO_LOG("end successfully.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::OpenFile(const Uri &uri, const std::string &mode)
|
||||
{
|
||||
int ret = -1;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->OpenFile(uri, mode);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::OpenRawFile(const Uri &uri, const std::string &mode)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
int ret = -1;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->OpenRawFile(uri, mode);
|
||||
RINGTONE_INFO_LOG("end successfully. ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::Insert(const Uri &uri, const DataShareValuesBucket &value)
|
||||
{
|
||||
int ret = 0;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->Insert(uri, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::InsertExt(const Uri &uri, const DataShareValuesBucket &value, std::string &result)
|
||||
{
|
||||
int ret = 0;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->InsertExt(uri, value, result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::Update(const Uri &uri, const DataSharePredicates &predicates,
|
||||
const DataShareValuesBucket &value)
|
||||
{
|
||||
int ret = 0;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->Update(uri, predicates, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::Delete(const Uri &uri, const DataSharePredicates &predicates)
|
||||
{
|
||||
int ret = 0;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->Delete(uri, predicates);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<DataShareResultSet> RingtoneDataShareStubImpl::Query(const Uri &uri,
|
||||
const DataSharePredicates &predicates, std::vector<std::string> &columns, DatashareBusinessError &businessError)
|
||||
{
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return nullptr;
|
||||
}
|
||||
return extension->Query(uri, predicates, columns, businessError);
|
||||
}
|
||||
|
||||
std::string RingtoneDataShareStubImpl::GetType(const Uri &uri)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
std::string ret = "";
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->GetType(uri);
|
||||
RINGTONE_INFO_LOG("end successfully.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RingtoneDataShareStubImpl::BatchInsert(const Uri &uri, const std::vector<DataShareValuesBucket> &values)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
int ret = 0;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->BatchInsert(uri, values);
|
||||
RINGTONE_INFO_LOG("end successfully.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RingtoneDataShareStubImpl::RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
bool ret = false;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->RegisterObserver(uri, dataObserver);
|
||||
RINGTONE_INFO_LOG("end successfully. ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RingtoneDataShareStubImpl::UnregisterObserver(const Uri &uri,
|
||||
const sptr<AAFwk::IDataAbilityObserver> &dataObserver)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
bool ret = false;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->UnregisterObserver(uri, dataObserver);
|
||||
RINGTONE_INFO_LOG("end successfully. ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RingtoneDataShareStubImpl::NotifyChange(const Uri &uri)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
bool ret = false;
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return ret;
|
||||
}
|
||||
ret = extension->NotifyChange(uri);
|
||||
RINGTONE_INFO_LOG("end successfully. ret: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Uri RingtoneDataShareStubImpl::NormalizeUri(const Uri &uri)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
Uri urivalue("");
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return urivalue;
|
||||
}
|
||||
urivalue = extension->NormalizeUri(uri);
|
||||
RINGTONE_INFO_LOG("end successfully.");
|
||||
return urivalue;
|
||||
}
|
||||
|
||||
Uri RingtoneDataShareStubImpl::DenormalizeUri(const Uri &uri)
|
||||
{
|
||||
RINGTONE_INFO_LOG("begin.");
|
||||
Uri urivalue("");
|
||||
auto client = sptr<RingtoneDataShareStubImpl>(this);
|
||||
auto extension = client->GetOwner();
|
||||
if (extension == nullptr) {
|
||||
RINGTONE_ERR_LOG("end failed.");
|
||||
return urivalue;
|
||||
}
|
||||
urivalue = extension->DenormalizeUri(uri);
|
||||
RINGTONE_INFO_LOG("end successfully.");
|
||||
return urivalue;
|
||||
}
|
||||
} // namespace DataShare
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "RdbStore"
|
||||
|
||||
#include "ringtone_rdbstore.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "rdb_sql_utils.h"
|
||||
#include "ringtone_errno.h"
|
||||
#include "ringtone_log.h"
|
||||
#include "ringtone_tracer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::NativeRdb;
|
||||
namespace OHOS::Media {
|
||||
static const mode_t MODE_RWX_USR_GRP = 02771;
|
||||
const std::string CREATE_RINGTONE_TABLE = "CREATE TABLE IF NOT EXISTS " + RINGTONE_TABLE + "(" +
|
||||
RINGTONE_COLUMN_TONE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||
RINGTONE_COLUMN_DATA + " TEXT , " +
|
||||
RINGTONE_COLUMN_SIZE + " BIGINT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_DISPLAY_NAME + " TEXT , " +
|
||||
RINGTONE_COLUMN_TITLE + " TEXT , " +
|
||||
RINGTONE_COLUMN_MEDIA_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_TONE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_MIME_TYPE + " TEXT , " +
|
||||
RINGTONE_COLUMN_SOURCE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_DATE_ADDED + " BIGINT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_DATE_MODIFIED + " BIGINT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_DATE_TAKEN + " BIGINT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_DURATION + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_SHOT_TONE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_RING_TONE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_ALARM_TONE_TYPE + " INT DEFAULT 0, " +
|
||||
RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE + " INT DEFAULT 0 " + ")";
|
||||
|
||||
shared_ptr<NativeRdb::RdbStore> RingtoneRdbStore::rdbStore_;
|
||||
|
||||
static const vector<string> g_initSqls = {
|
||||
CREATE_RINGTONE_TABLE,
|
||||
};
|
||||
|
||||
int32_t RingtoneDataCallBack::MkdirRecursive(const string &path, size_t start)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start pos %{public}zu", start);
|
||||
size_t end = path.find("/", start + 1);
|
||||
|
||||
string subDir = "";
|
||||
if (end == std::string::npos) {
|
||||
if (start + 1 == path.size()) {
|
||||
RINGTONE_DEBUG_LOG("path size=%d", path.size());
|
||||
} else {
|
||||
subDir = path.substr(start + 1, path.size() - start - 1);
|
||||
}
|
||||
} else {
|
||||
subDir = path.substr(start + 1, end - start - 1);
|
||||
}
|
||||
|
||||
if (subDir.size() == 0) {
|
||||
return NativeRdb::E_OK;
|
||||
} else {
|
||||
string real = path.substr(0, start + subDir.size() + 1);
|
||||
mode_t mask = umask(0);
|
||||
int result = mkdir(real.c_str(), MODE_RWX_USR_GRP);
|
||||
if (result == 0) {
|
||||
RINGTONE_INFO_LOG("mkdir %{public}s successfully", real.c_str());
|
||||
} else {
|
||||
RINGTONE_INFO_LOG("mkdir %{public}s failed, errno is %{public}d", real.c_str(), errno);
|
||||
}
|
||||
umask(mask);
|
||||
}
|
||||
if (end == std::string::npos) {
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
return MkdirRecursive(path, end);
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCallBack::CreatePreloadFolder(const string &path)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("start");
|
||||
if (access(path.c_str(), F_OK) == 0) {
|
||||
RINGTONE_INFO_LOG("dir is existing");
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
auto start = path.find(RINGTONE_CUSTOMIZED_BASE_PATH);
|
||||
if (start == string::npos) {
|
||||
RINGTONE_ERR_LOG("base dir is wrong");
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
|
||||
return MkdirRecursive(path, start + RINGTONE_CUSTOMIZED_BASE_PATH.size());
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCallBack::PrepareDir()
|
||||
{
|
||||
static const vector<string> userPreloadDirs = {
|
||||
{ RINGTONE_CUSTOMIZED_ALARM }, { RINGTONE_CUSTOMIZED_RINGTONE }, { RINGTONE_CUSTOMIZED_NOTIFICATIONS }
|
||||
};
|
||||
|
||||
for (const auto &dir: userPreloadDirs) {
|
||||
if (CreatePreloadFolder(dir) != NativeRdb::E_OK) {
|
||||
RINGTONE_INFO_LOG("scan failed on dir %{public}s", dir.c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCallBack::InitSql(RdbStore &store)
|
||||
{
|
||||
for (const string &sqlStr : g_initSqls) {
|
||||
if (store.ExecuteSql(sqlStr) != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("Failed to execute sql");
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
}
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCallBack::OnCreate(RdbStore &store)
|
||||
{
|
||||
if (InitSql(store) != NativeRdb::E_OK) {
|
||||
RINGTONE_DEBUG_LOG("error");
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
|
||||
if (PrepareDir() != NativeRdb::E_OK) {
|
||||
RINGTONE_DEBUG_LOG("Prepare dir error");
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
int32_t RingtoneDataCallBack::OnUpgrade(RdbStore &store, int32_t oldVersion, int32_t newVersion)
|
||||
{
|
||||
RINGTONE_DEBUG_LOG("OnUpgrade old:%d, new:%d", oldVersion, newVersion);
|
||||
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
RingtoneUnistore *RingtoneRdbStore::GetInstance(const std::shared_ptr<OHOS::AbilityRuntime::Context> &context)
|
||||
{
|
||||
static RingtoneRdbStore *instance = nullptr;
|
||||
if (instance == nullptr && context == nullptr) {
|
||||
RINGTONE_ERR_LOG("RingtoneRdbStore is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
if (instance == nullptr) {
|
||||
instance = new RingtoneRdbStore(context);
|
||||
if (instance->Init() != 0) {
|
||||
RINGTONE_ERR_LOG("init RingtoneRdbStore failed");
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
RingtoneRdbStore::RingtoneRdbStore(const shared_ptr<OHOS::AbilityRuntime::Context> &context)
|
||||
{
|
||||
if (context == nullptr) {
|
||||
RINGTONE_ERR_LOG("Failed to get context");
|
||||
return;
|
||||
}
|
||||
string databaseDir = context->GetDatabaseDir();
|
||||
string name = RINGTONE_COLUMN_DATA_ABILITY_DB_NAME;
|
||||
int32_t errCode = 0;
|
||||
string realPath = RdbSqlUtils::GetDefaultDatabasePath(databaseDir, name, errCode);
|
||||
config_.SetName(move(name));
|
||||
config_.SetPath(move(realPath));
|
||||
config_.SetBundleName(context->GetBundleName());
|
||||
config_.SetArea(context->GetArea());
|
||||
config_.SetSecurityLevel(SecurityLevel::S3);
|
||||
}
|
||||
|
||||
int32_t RingtoneRdbStore::Init()
|
||||
{
|
||||
RINGTONE_INFO_LOG("Init rdb store");
|
||||
if (rdbStore_ != nullptr) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t errCode = 0;
|
||||
RingtoneDataCallBack rdbDataCallBack;
|
||||
rdbStore_ = RdbHelper::GetRdbStore(config_, RINGTONE_RDB_VERSION, rdbDataCallBack, errCode);
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("GetRdbStore is failed , errCode=%{public}d", errCode);
|
||||
return E_ERR;
|
||||
}
|
||||
RINGTONE_INFO_LOG("SUCCESS");
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
RingtoneRdbStore::~RingtoneRdbStore() = default;
|
||||
|
||||
void RingtoneRdbStore::Stop()
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
rdbStore_ = nullptr;
|
||||
}
|
||||
|
||||
int32_t RingtoneRdbStore::Insert(RingtoneDataCommand &cmd, int64_t &rowId)
|
||||
{
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RingtoneRdbStore::Insert");
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("Pointer rdbStore_ is nullptr. Maybe it didn't init successfully.");
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
int32_t ret = rdbStore_->Insert(rowId, cmd.GetTableName(), cmd.GetValueBucket());
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("rdbStore_->Insert failed, ret = %{public}d", ret);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
RINGTONE_DEBUG_LOG("rdbStore_->Insert end, rowId = %d, ret = %{public}d", (int)rowId, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t RingtoneRdbStore::Delete(RingtoneDataCommand &cmd, int32_t &deletedRows)
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("Pointer rdbStore_ is nullptr. Maybe it didn't init successfully.");
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RdbStore->DeleteByCmd");
|
||||
|
||||
auto predicates = cmd.GetAbsRdbPredicates();
|
||||
int32_t ret = rdbStore_->Delete(deletedRows, cmd.GetTableName(), predicates->GetWhereClause(),
|
||||
predicates->GetWhereArgs());
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("rdbStore_->Delete failed, ret = %{public}d", ret);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t RingtoneRdbStore::Update(RingtoneDataCommand &cmd, int32_t &changedRows)
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdbStore_ is nullptr");
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RdbStore->UpdateByCmd");
|
||||
int32_t ret = rdbStore_->Update(changedRows, cmd.GetTableName(), cmd.GetValueBucket(),
|
||||
cmd.GetAbsRdbPredicates()->GetWhereClause(), cmd.GetAbsRdbPredicates()->GetWhereArgs());
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("rdbStore_->Update failed, ret = %{public}d", ret);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::ResultSet> RingtoneRdbStore::Query(RingtoneDataCommand &cmd,
|
||||
const vector<string> &columns)
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rdbStore_ is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RdbStore->QueryByCmd");
|
||||
|
||||
auto resultSet = rdbStore_->Query(*cmd.GetAbsRdbPredicates(), columns);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
int32_t RingtoneRdbStore::ExecuteSql(const string &sql)
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("Pointer rdbStore_ is nullptr. Maybe it didn't init successfully.");
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RdbStore->ExecuteSql");
|
||||
int32_t ret = rdbStore_->ExecuteSql(sql);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
RINGTONE_ERR_LOG("rdbStore_->ExecuteSql failed, ret = %{public}d", ret);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::ResultSet> RingtoneRdbStore::QuerySql(const string &sql, const vector<string> &selectionArgs)
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("Pointer rdbStore_ is nullptr. Maybe it didn't init successfully.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RingtoneTracer tracer;
|
||||
tracer.Start("RdbStore->QuerySql");
|
||||
auto resultSet = rdbStore_->QuerySql(sql, selectionArgs);
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::RdbStore> RingtoneRdbStore::GetRaw()
|
||||
{
|
||||
return rdbStore_;
|
||||
}
|
||||
} // namespace OHOS::Media
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "Subscribe"
|
||||
|
||||
#include "ringtone_subscriber.h"
|
||||
|
||||
#include "common_event_support.h"
|
||||
#include "ringtone_log.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
const std::vector<std::string> RingtoneSubscriber::events_ = {
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING,
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING,
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF,
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON,
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED,
|
||||
EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED
|
||||
};
|
||||
|
||||
RingtoneSubscriber::RingtoneSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo)
|
||||
: EventFwk::CommonEventSubscriber(subscriberInfo)
|
||||
{
|
||||
}
|
||||
|
||||
bool RingtoneSubscriber::Subscribe(void)
|
||||
{
|
||||
EventFwk::MatchingSkills matchingSkills;
|
||||
for (auto event : events_) {
|
||||
matchingSkills.AddEvent(event);
|
||||
}
|
||||
EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
|
||||
|
||||
std::shared_ptr<RingtoneSubscriber> subscriber = std::make_shared<RingtoneSubscriber>(subscribeInfo);
|
||||
return EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
}
|
||||
|
||||
void RingtoneSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData)
|
||||
{
|
||||
const AAFwk::Want &want = eventData.GetWant();
|
||||
std::string action = want.GetAction();
|
||||
RINGTONE_INFO_LOG("OnReceiveEvent action:%{public}s.", action.c_str());
|
||||
if (action.compare(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) == 0) {
|
||||
RINGTONE_INFO_LOG("recieve boot complete event.");
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,80 @@
|
||||
# Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/ringtone_library/ringtone_library.gni")
|
||||
|
||||
config("ringtone_helper_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("ringtone_data_helper") {
|
||||
install_enable = true
|
||||
|
||||
include_dirs = [
|
||||
"${RINGTONE_SCANNER_PATH}/include",
|
||||
"${RINGTONE_BACKUP_PATH}/include",
|
||||
"${RINGTONE_EXTENSION_PATH}/include",
|
||||
"${RINGTONE_DFX_PATH}/include",
|
||||
"${RINGTONE_SERVICES_PATH}/utils/include",
|
||||
"${RINGTONE_INTERFACES_PATH}/inner_api/native",
|
||||
"${RINGTONE_HELPER_PATH}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/ringtone_asset.cpp",
|
||||
"src/ringtone_fetch_result.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":ringtone_helper_public_config" ]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-unused-but-set-variable",
|
||||
"-fdata-sections",
|
||||
"-ffunction-sections",
|
||||
"-Os",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-Os" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"app_file_service:sandbox_helper_native",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"data_share:datashare_common",
|
||||
"data_share:datashare_consumer",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"kv_store:distributeddata_inner",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
|
||||
if (!ringtone_link_opt) {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
stack_protector_ret = true
|
||||
}
|
||||
}
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "ringtone_library"
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_ASSET_H
|
||||
#define RINGTONE_ASSET_H
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
|
||||
class RingtoneAsset {
|
||||
public:
|
||||
EXPORT RingtoneAsset();
|
||||
EXPORT virtual ~RingtoneAsset() = default;
|
||||
|
||||
EXPORT int32_t GetId() const;
|
||||
EXPORT void SetId(int32_t id);
|
||||
|
||||
EXPORT int64_t GetSize() const;
|
||||
EXPORT void SetSize(int64_t size);
|
||||
|
||||
EXPORT const std::string &GetPath() const;
|
||||
EXPORT void SetPath(const std::string &path);
|
||||
|
||||
EXPORT const std::string &GetDisplayName() const;
|
||||
EXPORT void SetDisplayName(const std::string &displayName);
|
||||
|
||||
EXPORT const std::string &GetTitle() const;
|
||||
EXPORT void SetTitle(const std::string &title);
|
||||
|
||||
EXPORT const std::string &GetMimeType() const;
|
||||
EXPORT void SetMimeType(const std::string &mimeType);
|
||||
|
||||
EXPORT int32_t GetSourceType() const;
|
||||
EXPORT void SetSourceType(int32_t type);
|
||||
|
||||
EXPORT int64_t GetDateAdded() const;
|
||||
EXPORT void SetDateAdded(int64_t dateAdded);
|
||||
|
||||
EXPORT int64_t GetDateModified() const;
|
||||
EXPORT void SetDateModified(int64_t dateModified);
|
||||
|
||||
EXPORT int64_t GetDateTaken() const;
|
||||
EXPORT void SetDateTaken(int64_t dateTaken);
|
||||
|
||||
EXPORT int32_t GetDuration() const;
|
||||
EXPORT void SetDuration(int32_t duration);
|
||||
|
||||
EXPORT int32_t GetShottoneType() const;
|
||||
EXPORT void SetShottoneType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetShottoneSourceType() const;
|
||||
EXPORT void SetShottoneSourceType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetNotificationtoneType() const;
|
||||
EXPORT void SetNotificationtoneType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetNotificationtoneSourceType() const;
|
||||
EXPORT void SetNotificationtoneSourceType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetRingtoneType() const;
|
||||
EXPORT void SetRingtoneType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetRingtoneSourceType() const;
|
||||
EXPORT void SetRingtoneSourceType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetAlarmtoneType() const;
|
||||
EXPORT void SetAlarmtoneType(int32_t type);
|
||||
|
||||
EXPORT int32_t GetAlarmtoneSourceType() const;
|
||||
EXPORT void SetAlarmtoneSourceType(int32_t type);
|
||||
|
||||
EXPORT void SetOpenStatus(int32_t fd, int32_t openStatus);
|
||||
EXPORT void RemoveOpenStatus(int32_t fd);
|
||||
EXPORT int32_t GetOpenStatus(int32_t fd);
|
||||
|
||||
EXPORT std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string, double>> &GetMemberMap();
|
||||
EXPORT std::variant<int32_t, int64_t, std::string, double> &GetMemberValue(const std::string &name);
|
||||
|
||||
private:
|
||||
const std::string &GetStrMember(const std::string &name) const;
|
||||
int32_t GetInt32Member(const std::string &name) const;
|
||||
int64_t GetInt64Member(const std::string &name) const;
|
||||
|
||||
std::unordered_map<std::string, std::variant<int32_t, int64_t, std::string, double>> member_;
|
||||
std::mutex openStatusMapMutex_;
|
||||
std::shared_ptr<std::unordered_map<int32_t, int32_t>> openStatusMap_;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // RINGTONE_ASSET_H
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RINGTONE_FETCH_RESULT_H
|
||||
#define RINGTONE_FETCH_RESULT_H
|
||||
|
||||
#include "abs_shared_result_set.h"
|
||||
#include "datashare_result_set.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "ringtone_asset.h"
|
||||
#include "ringtone_db_const.h"
|
||||
#include "ringtone_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#define EXPORT __attribute__ ((visibility ("default")))
|
||||
/**
|
||||
* @brief Class for returning the data cursor to application.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
template <class T>
|
||||
class RingtoneFetchResult {
|
||||
public:
|
||||
EXPORT explicit RingtoneFetchResult(const std::shared_ptr<DataShare::DataShareResultSet> &resultset);
|
||||
EXPORT RingtoneFetchResult();
|
||||
EXPORT virtual ~RingtoneFetchResult();
|
||||
|
||||
EXPORT void Close();
|
||||
EXPORT int32_t GetCount();
|
||||
EXPORT bool IsAtLastRow();
|
||||
|
||||
EXPORT std::shared_ptr<DataShare::DataShareResultSet> &GetDataShareResultSet();
|
||||
|
||||
EXPORT std::unique_ptr<T> GetObjectAtPosition(int32_t index);
|
||||
EXPORT std::unique_ptr<T> GetFirstObject();
|
||||
EXPORT std::unique_ptr<T> GetObjectFromRdb(std::shared_ptr<NativeRdb::ResultSet> &resultSet, int idx);
|
||||
EXPORT std::unique_ptr<T> GetNextObject();
|
||||
EXPORT std::unique_ptr<T> GetLastObject();
|
||||
EXPORT std::unique_ptr<T> GetObject();
|
||||
|
||||
private:
|
||||
EXPORT std::unique_ptr<T> GetObject(std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
EXPORT std::variant<int32_t, int64_t, std::string, double> GetRowValFromColumn(std::string columnName,
|
||||
ResultSetDataType dataType, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
std::variant<int32_t, int64_t, std::string, double> GetValByIndex(int32_t index, ResultSetDataType dataType,
|
||||
std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
|
||||
void SetRingtoneAsset(RingtoneAsset *asset, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
|
||||
void GetObjectFromResultSet(RingtoneAsset *asset, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
|
||||
std::shared_ptr<DataShare::DataShareResultSet> resultset_ = nullptr;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INTERFACES_INNERKITS_NATIVE_INCLUDE_FETCH_RESULT_H
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "RingtoneAsset"
|
||||
|
||||
#include "ringtone_asset.h"
|
||||
|
||||
#include "ringtone_db_const.h"
|
||||
#include "ringtone_errno.h"
|
||||
#include "ringtone_log.h"
|
||||
#include "ringtone_type.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
RingtoneAsset::RingtoneAsset()
|
||||
{
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetId() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_TONE_ID);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetId(int32_t id)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_TONE_ID] = id;
|
||||
}
|
||||
|
||||
int64_t RingtoneAsset::GetSize() const
|
||||
{
|
||||
return GetInt64Member(RINGTONE_COLUMN_SIZE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetSize(int64_t size)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_SIZE] = size;
|
||||
}
|
||||
|
||||
const string &RingtoneAsset::GetPath() const
|
||||
{
|
||||
return GetStrMember(RINGTONE_COLUMN_DATA);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetPath(const string &path)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DATA] = path;
|
||||
}
|
||||
|
||||
const string &RingtoneAsset::GetDisplayName() const
|
||||
{
|
||||
return GetStrMember(RINGTONE_COLUMN_DISPLAY_NAME);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetDisplayName(const string &displayName)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DISPLAY_NAME] = displayName;
|
||||
}
|
||||
|
||||
const string &RingtoneAsset::GetTitle() const
|
||||
{
|
||||
return GetStrMember(RINGTONE_COLUMN_TITLE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetTitle(const string &title)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_TITLE] = title;
|
||||
}
|
||||
|
||||
const string &RingtoneAsset::GetMimeType() const
|
||||
{
|
||||
return GetStrMember(RINGTONE_COLUMN_MIME_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetMimeType(const string &mimeType)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_MIME_TYPE] = mimeType;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetSourceType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_SOURCE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetSourceType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_SOURCE_TYPE] = type;
|
||||
}
|
||||
|
||||
int64_t RingtoneAsset::GetDateAdded() const
|
||||
{
|
||||
return GetInt64Member(RINGTONE_COLUMN_DATE_ADDED);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetDateAdded(int64_t dateAdded)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DATE_ADDED] = dateAdded;
|
||||
}
|
||||
|
||||
int64_t RingtoneAsset::GetDateModified() const
|
||||
{
|
||||
return GetInt64Member(RINGTONE_COLUMN_DATE_MODIFIED);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetDateModified(int64_t dateModified)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DATE_MODIFIED] = dateModified;
|
||||
}
|
||||
|
||||
|
||||
int64_t RingtoneAsset::GetDateTaken() const
|
||||
{
|
||||
return GetInt64Member(RINGTONE_COLUMN_DATE_TAKEN);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetDateTaken(int64_t dataTaken)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DATE_TAKEN] = dataTaken;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetDuration() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_DURATION);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetDuration(int32_t duration)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_DURATION] = duration;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetShottoneType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_SHOT_TONE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetShottoneType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_SHOT_TONE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetShottoneSourceType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetShottoneSourceType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetNotificationtoneType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetNotificationtoneType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetNotificationtoneSourceType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetNotificationtoneSourceType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetRingtoneType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_RING_TONE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetRingtoneType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_RING_TONE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetRingtoneSourceType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetRingtoneSourceType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetAlarmtoneType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_ALARM_TONE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetAlarmtoneType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_ALARM_TONE_TYPE] = type;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetAlarmtoneSourceType() const
|
||||
{
|
||||
return GetInt32Member(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE);
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetAlarmtoneSourceType(int32_t type)
|
||||
{
|
||||
member_[RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE] = type;
|
||||
}
|
||||
|
||||
void RingtoneAsset::SetOpenStatus(int32_t fd, int32_t openStatus)
|
||||
{
|
||||
lock_guard<mutex> lock(openStatusMapMutex_);
|
||||
if (openStatusMap_ == nullptr) {
|
||||
openStatusMap_ = make_shared<unordered_map<int32_t, int32_t>>();
|
||||
}
|
||||
openStatusMap_->insert({fd, openStatus});
|
||||
}
|
||||
|
||||
void RingtoneAsset::RemoveOpenStatus(int32_t fd)
|
||||
{
|
||||
lock_guard<mutex> lock(openStatusMapMutex_);
|
||||
if (openStatusMap_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
openStatusMap_->erase(fd);
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetOpenStatus(int32_t fd)
|
||||
{
|
||||
lock_guard<mutex> lock(openStatusMapMutex_);
|
||||
if (openStatusMap_ == nullptr) {
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
if (openStatusMap_->find(fd) != openStatusMap_->end()) {
|
||||
return openStatusMap_->at(fd);
|
||||
} else {
|
||||
RINGTONE_ERR_LOG("can not find this fd: [%{public}d]", fd);
|
||||
return E_INVALID_VALUES;
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<string, variant<int32_t, int64_t, string, double>> &RingtoneAsset::GetMemberMap()
|
||||
{
|
||||
return member_;
|
||||
}
|
||||
|
||||
variant<int32_t, int64_t, string, double> &RingtoneAsset::GetMemberValue(const string &name)
|
||||
{
|
||||
return member_[name];
|
||||
}
|
||||
|
||||
const string &RingtoneAsset::GetStrMember(const string &name) const
|
||||
{
|
||||
return (member_.count(name) > 0) ? get<string>(member_.at(name)) : DEFAULT_STR;
|
||||
}
|
||||
|
||||
int32_t RingtoneAsset::GetInt32Member(const string &name) const
|
||||
{
|
||||
return (member_.count(name) > 0) ? get<int32_t>(member_.at(name)) : DEFAULT_INT32;
|
||||
}
|
||||
|
||||
int64_t RingtoneAsset::GetInt64Member(const string &name) const
|
||||
{
|
||||
return (member_.count(name) > 0) ? get<int64_t>(member_.at(name)) : DEFAULT_INT64;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "RingtoneFetchResult"
|
||||
|
||||
#include "ringtone_fetch_result.h"
|
||||
|
||||
#include "ringtone_log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using ResultTypeMap = unordered_map<string, ResultSetDataType>;
|
||||
|
||||
static const ResultTypeMap &GetResultTypeMap()
|
||||
{
|
||||
static const ResultTypeMap RESULT_TYPE_MAP = {
|
||||
{ RINGTONE_COLUMN_TONE_ID, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_DATA, TYPE_STRING },
|
||||
{ RINGTONE_COLUMN_SIZE, TYPE_INT64 },
|
||||
{ RINGTONE_COLUMN_DISPLAY_NAME, TYPE_STRING },
|
||||
{ RINGTONE_COLUMN_TITLE, TYPE_STRING },
|
||||
{ RINGTONE_COLUMN_MEDIA_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_TONE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_MIME_TYPE, TYPE_STRING },
|
||||
{ RINGTONE_COLUMN_SOURCE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_DATE_ADDED, TYPE_INT64 },
|
||||
{ RINGTONE_COLUMN_DATE_MODIFIED, TYPE_INT64 },
|
||||
{ RINGTONE_COLUMN_DATE_TAKEN, TYPE_INT64 },
|
||||
{ RINGTONE_COLUMN_DURATION, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_SHOT_TONE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_RING_TONE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_ALARM_TONE_TYPE, TYPE_INT32 },
|
||||
{ RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE, TYPE_INT32 },
|
||||
};
|
||||
return RESULT_TYPE_MAP;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
RingtoneFetchResult<T>::RingtoneFetchResult(const shared_ptr<DataShare::DataShareResultSet> &resultset)
|
||||
{
|
||||
resultset_ = resultset;
|
||||
GetCount();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
// empty constructor napi
|
||||
RingtoneFetchResult<T>::RingtoneFetchResult() : resultset_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
RingtoneFetchResult<T>::~RingtoneFetchResult()
|
||||
{
|
||||
resultset_.reset();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void RingtoneFetchResult<T>::Close()
|
||||
{
|
||||
if (resultset_ != nullptr) {
|
||||
resultset_->Close();
|
||||
resultset_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int32_t RingtoneFetchResult<T>::GetCount()
|
||||
{
|
||||
int32_t count = 0;
|
||||
if (resultset_ == nullptr || resultset_->GetRowCount(count) != NativeRdb::E_OK) {
|
||||
return 0;
|
||||
}
|
||||
return count < 0 ? 0 : count;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
shared_ptr<DataShare::DataShareResultSet> &RingtoneFetchResult<T>::GetDataShareResultSet()
|
||||
{
|
||||
return resultset_;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetObjectAtPosition(int32_t index)
|
||||
{
|
||||
if (resultset_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("rs is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t count = GetCount();
|
||||
if ((index < 0) || (index > (count - 1))) {
|
||||
RINGTONE_ERR_LOG("index not proper");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (resultset_->GoToRow(index) != 0) {
|
||||
RINGTONE_ERR_LOG("failed to go to row at index pos");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetObject();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetFirstObject()
|
||||
{
|
||||
if ((resultset_ == nullptr) || (resultset_->GoToFirstRow() != 0)) {
|
||||
RINGTONE_DEBUG_LOG("resultset is null|first row failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetObject();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetNextObject()
|
||||
{
|
||||
if ((resultset_ == nullptr) || (resultset_->GoToNextRow() != 0)) {
|
||||
RINGTONE_DEBUG_LOG("resultset is null|go to next row failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetObject();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetLastObject()
|
||||
{
|
||||
if ((resultset_ == nullptr) || (resultset_->GoToLastRow() != 0)) {
|
||||
RINGTONE_ERR_LOG("resultset is null|go to last row failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetObject();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool RingtoneFetchResult<T>::IsAtLastRow()
|
||||
{
|
||||
if (resultset_ == nullptr) {
|
||||
RINGTONE_ERR_LOG("resultset null");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool retVal = false;
|
||||
resultset_->IsAtLastRow(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
variant<int32_t, int64_t, string, double> ReturnDefaultOnError(string errMsg, ResultSetDataType dataType)
|
||||
{
|
||||
if (dataType == TYPE_STRING) {
|
||||
return "";
|
||||
} else if (dataType == TYPE_INT64) {
|
||||
return static_cast<int64_t>(0);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
variant<int32_t, int64_t, string, double> RingtoneFetchResult<T>::GetRowValFromColumn(string columnName,
|
||||
ResultSetDataType dataType, shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
if ((resultset_ == nullptr) && (resultSet == nullptr)) {
|
||||
return ReturnDefaultOnError("Resultset is null", dataType);
|
||||
}
|
||||
int index;
|
||||
int status;
|
||||
if (resultSet) {
|
||||
status = resultSet->GetColumnIndex(columnName, index);
|
||||
} else {
|
||||
status = resultset_->GetColumnIndex(columnName, index);
|
||||
}
|
||||
if (status != NativeRdb::E_OK) {
|
||||
return ReturnDefaultOnError("failed to obtain the index", dataType);
|
||||
}
|
||||
return GetValByIndex(index, dataType, resultSet);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
variant<int32_t, int64_t, string, double> RingtoneFetchResult<T>::GetValByIndex(int32_t index,
|
||||
ResultSetDataType dataType, shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
if ((resultset_ == nullptr) && (resultSet == nullptr)) {
|
||||
return ReturnDefaultOnError("Resultset is null", dataType);
|
||||
}
|
||||
variant<int32_t, int64_t, string, double> cellValue;
|
||||
int integerVal = 0;
|
||||
string stringVal = "";
|
||||
int64_t longVal = 0;
|
||||
int status;
|
||||
double doubleVal = 0.0;
|
||||
switch (dataType) {
|
||||
case TYPE_STRING:
|
||||
if (resultSet) {
|
||||
status = resultSet->GetString(index, stringVal);
|
||||
} else {
|
||||
status = resultset_->GetString(index, stringVal);
|
||||
}
|
||||
cellValue = move(stringVal);
|
||||
break;
|
||||
case TYPE_INT32:
|
||||
if (resultSet) {
|
||||
status = resultSet->GetInt(index, integerVal);
|
||||
} else {
|
||||
status = resultset_->GetInt(index, integerVal);
|
||||
}
|
||||
cellValue = integerVal;
|
||||
break;
|
||||
case TYPE_INT64:
|
||||
if (resultSet) {
|
||||
status = resultSet->GetLong(index, longVal);
|
||||
} else {
|
||||
status = resultset_->GetLong(index, longVal);
|
||||
}
|
||||
cellValue = longVal;
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if (resultSet) {
|
||||
status = resultSet->GetDouble(index, doubleVal);
|
||||
} else {
|
||||
status = resultset_->GetDouble(index, doubleVal);
|
||||
}
|
||||
cellValue = doubleVal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void RingtoneFetchResult<T>::SetRingtoneAsset(RingtoneAsset *asset, shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
if ((resultset_ == nullptr) && (resultSet == nullptr)) {
|
||||
RINGTONE_ERR_LOG("SetRingtoneAsset fail, result is nullptr");
|
||||
return;
|
||||
}
|
||||
vector<string> columnNames;
|
||||
if (resultSet != nullptr) {
|
||||
resultSet->GetAllColumnNames(columnNames);
|
||||
} else {
|
||||
resultset_->GetAllColumnNames(columnNames);
|
||||
}
|
||||
int32_t index = -1;
|
||||
auto &map = asset->GetMemberMap();
|
||||
for (const auto &name : columnNames) {
|
||||
index++;
|
||||
if (GetResultTypeMap().count(name) == 0) {
|
||||
continue;
|
||||
}
|
||||
auto memberType = GetResultTypeMap().at(name);
|
||||
map.emplace(move(name), move(GetValByIndex(index, memberType, resultSet)));
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void RingtoneFetchResult<T>::GetObjectFromResultSet(RingtoneAsset *asset, shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
SetRingtoneAsset(asset, resultSet);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetObject(shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
unique_ptr<T> asset = make_unique<T>();
|
||||
GetObjectFromResultSet(asset.get(), resultSet);
|
||||
return asset;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetObject()
|
||||
{
|
||||
shared_ptr<NativeRdb::ResultSet> resultSet = nullptr;
|
||||
return GetObject(resultSet);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
unique_ptr<T> RingtoneFetchResult<T>::GetObjectFromRdb(shared_ptr<NativeRdb::ResultSet> &resultSet, int idx)
|
||||
{
|
||||
if ((resultSet == nullptr) || (resultSet->GoToFirstRow() != 0) || (resultSet->GoTo(idx))) {
|
||||
RINGTONE_ERR_LOG("resultset is null|first row failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return GetObject(resultSet);
|
||||
}
|
||||
|
||||
template class RingtoneFetchResult<RingtoneAsset>;
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user