1 /* 2 * Copyright (c) 2023 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 16 #ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_RDB_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_RDB_H 18 19 #include <vector> 20 21 #include "bundle_system_state.h" 22 #include "bundle_resource_info.h" 23 #include "launcher_ability_resource_info.h" 24 #include "rdb_data_manager.h" 25 #include "resource_info.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class BundleResourceRdb : public std::enable_shared_from_this<BundleResourceRdb> { 30 public: 31 BundleResourceRdb(); 32 ~BundleResourceRdb(); 33 // add resource info to resource rdb 34 bool AddResourceInfo(const ResourceInfo &resourceInfo); 35 36 bool DeleteResourceInfo(const std::string &key); 37 38 bool DeleteAllResourceInfo(); 39 40 bool AddResourceInfos(const std::vector<ResourceInfo> &resourceInfos); 41 42 bool GetAllResourceName(std::vector<std::string> &keyName); 43 44 bool GetResourceNameByBundleName(const std::string &bundleName, 45 const int32_t appIndex, 46 std::vector<std::string> &keyName); 47 48 bool GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags, 49 BundleResourceInfo &bundleResourceInfo, const int32_t appIndex = 0); 50 51 bool GetLauncherAbilityResourceInfo(const std::string &bundleName, const uint32_t flags, 52 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfo, const int32_t appIndex = 0); 53 54 bool GetAllBundleResourceInfo(const uint32_t flags, std::vector<BundleResourceInfo> &bundleResourceInfos); 55 56 bool GetAllLauncherAbilityResourceInfo(const uint32_t flags, 57 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 58 59 bool UpdateResourceForSystemStateChanged(const std::vector<ResourceInfo> &resourceInfos); 60 61 bool GetCurrentSystemState(std::string &systemState); 62 63 bool DeleteNotExistResourceInfo(); 64 65 private: 66 bool ConvertToBundleResourceInfo( 67 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 68 const uint32_t flags, 69 BundleResourceInfo &bundleResourceInfo); 70 71 bool ConvertToLauncherAbilityResourceInfo( 72 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 73 const uint32_t flags, 74 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 75 76 void ParseKey(const std::string &key, 77 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 78 79 void ParseKey(const std::string &key, 80 BundleResourceInfo &bundleResourceInfo); 81 82 void BackupRdb(); 83 84 std::shared_ptr<RdbDataManager> rdbDataManager_; 85 86 std::atomic_bool isBackingUp_ = false; 87 88 #define CHECK_RDB_RESULT_RETURN_IF_FAIL(errcode, errmsg) \ 89 do { \ 90 if ((errcode) != NativeRdb::E_OK) { \ 91 APP_LOGE(errmsg, errcode); \ 92 return false; \ 93 } \ 94 } while (0) 95 }; 96 } // AppExecFwk 97 } // OHOS 98 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_RDB_H 99