1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #define MLOG_TAG "scan_demo" 16 17 #include <iostream> 18 #include <unistd.h> 19 #include "accesstoken_kit.h" 20 #include "datashare_helper.h" 21 #include "get_self_permissions.h" 22 #include "iservice_registry.h" 23 #include "ringtone_log.h" 24 #include "ringtone_db_const.h" 25 #include "nativetoken_kit.h" 26 #include "token_setproc.h" 27 #include "ringtone_asset.h" 28 #include "ringtone_fetch_result.h" 29 30 using namespace std; 31 using namespace OHOS; 32 using namespace OHOS::Media; 33 using namespace OHOS::DataShare; 34 35 namespace OHOS { 36 namespace Media { 37 namespace { 38 constexpr int STORAGE_MANAGER_MANAGER_ID = 5003; 39 } // namespace 40 } // namespace Media 41 } // namespace OHOS 42 CreateDataShareHelper(int32_t systemAbilityId)43static shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper(int32_t systemAbilityId) 44 { 45 RINGTONE_INFO_LOG("CreateDataShareHelper::CreateFileExtHelper "); 46 auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 47 if (saManager == nullptr) { 48 RINGTONE_INFO_LOG("CreateFileExtHelper Get system ability mgr failed."); 49 return nullptr; 50 } 51 auto remoteObj = saManager->GetSystemAbility(systemAbilityId); 52 if (remoteObj == nullptr) { 53 RINGTONE_INFO_LOG("CreateDataShareHelper GetSystemAbility Service Failed."); 54 return nullptr; 55 } 56 return DataShare::DataShareHelper::Creator(remoteObj, RINGTONE_URI); 57 } 58 59 /* 60 * Feature: RingtoneScanner 61 * Function: Strat scanner 62 * SubFunction: NA 63 * FunctionPoints: NA 64 * EnvConditions: NA 65 */ main()66int32_t main() 67 { 68 vector<string> perms; 69 perms.push_back("ohos.permission.WRITE_RINGTONE"); 70 71 uint64_t tokenId = 0; 72 RingtonePermissionUtilsUnitTest::SetAccessTokenPermission("RingtoneScan", perms, tokenId); 73 if (tokenId == 0) { 74 RINGTONE_ERR_LOG("Set Access Token Permisson Failed."); 75 return -1; 76 } 77 78 auto ringtoneDataShareHelper = CreateDataShareHelper(STORAGE_MANAGER_MANAGER_ID); 79 if (ringtoneDataShareHelper == nullptr) { 80 RINGTONE_ERR_LOG("ringtoneDataShareHelper fail"); 81 return -1; 82 } 83 84 return 0; 85 } 86