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 "extension_ability_info.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 bool GetExtensionAbilityResourceInfo(const std::string &bundleName, 67 const ExtensionAbilityType extensionAbilityType, const uint32_t flags, 68 std::vector<LauncherAbilityResourceInfo> &extensionAbilityResourceInfo, const int32_t appIndex = 0); 69 70 bool GetAllExtensionAbilityResourceInfo(const std::string &bundleName, const uint32_t flags, 71 std::vector<LauncherAbilityResourceInfo> &extensionAbilityResourceInfo, const int32_t appIndex = 0); 72 73 private: 74 bool ConvertToBundleResourceInfo( 75 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 76 const uint32_t flags, 77 BundleResourceInfo &bundleResourceInfo); 78 79 bool ConvertToLauncherAbilityResourceInfo( 80 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 81 const uint32_t flags, 82 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 83 84 bool ConvertToExtensionAbilityResourceInfo( 85 const std::shared_ptr<NativeRdb::ResultSet> &absSharedResultSet, 86 const uint32_t flags, 87 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 88 89 void ParseKey(const std::string &key, 90 LauncherAbilityResourceInfo &launcherAbilityResourceInfo); 91 92 void ParseKey(const std::string &key, 93 BundleResourceInfo &bundleResourceInfo); 94 95 std::shared_ptr<RdbDataManager> rdbDataManager_; 96 97 #define CHECK_RDB_RESULT_RETURN_IF_FAIL(errcode, errmsg) \ 98 do { \ 99 if ((errcode) != NativeRdb::E_OK) { \ 100 APP_LOGE(errmsg, errcode); \ 101 return false; \ 102 } \ 103 } while (0) 104 }; 105 } // AppExecFwk 106 } // OHOS 107 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_RDB_H 108