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 #include "single_delayed_task_mgr.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 class BundleResourceRdb : public std::enable_shared_from_this<BundleResourceRdb> { 31 public: 32 BundleResourceRdb(); 33 ~BundleResourceRdb(); 34 // add resource info to resource rdb 35 bool AddResourceInfo(const ResourceInfo &resourceInfo); 36 37 bool DeleteResourceInfo(const std::string &key); 38 39 bool DeleteAllResourceInfo(); 40 41 bool AddResourceInfos(const std::vector<ResourceInfo> &resourceInfos); 42 43 bool GetAllResourceName(std::vector<std::string> &keyName); 44 45 bool GetResourceNameByBundleName(const std::string &bundleName, 46 const int32_t appIndex, 47 std::vector<std::string> &keyName); 48 49 bool GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags, 50 BundleResourceInfo &bundleResourceInfo, const int32_t appIndex = 0); 51 52 bool GetLauncherAbilityResourceInfo(const std::string &bundleName, const uint32_t flags, 53 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfo, const int32_t appIndex = 0); 54 55 bool GetAllBundleResourceInfo(const uint32_t flags, std::vector<BundleResourceInfo> &bundleResourceInfos); 56 57 bool GetAllLauncherAbilityResourceInfo(const uint32_t flags, 58 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 59 60 bool UpdateResourceForSystemStateChanged(const std::vector<ResourceInfo> &resourceInfos); 61 62 bool GetCurrentSystemState(std::string &systemState); 63 64 bool DeleteNotExistResourceInfo(); 65 66 private: 67 bool ConvertToBundleResourceInfo( 68 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 69 const uint32_t flags, 70 BundleResourceInfo &bundleResourceInfo); 71 72 bool ConvertToLauncherAbilityResourceInfo( 73 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 74 const uint32_t flags, 75 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 76 77 void ParseKey(const std::string &key, 78 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 79 80 void ParseKey(const std::string &key, 81 BundleResourceInfo &bundleResourceInfo); 82 83 void BackupRdb(); 84 85 std::shared_ptr<RdbDataManager> rdbDataManager_; 86 std::shared_ptr<SingleDelayedTaskMgr> delayedTaskMgr_ = nullptr; 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