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_MANAGER_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "bundle_resource_rdb.h" 23 #include "bundle_system_state.h" 24 #include "inner_bundle_info.h" 25 #include "resource_info.h" 26 #include "singleton.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 class BundleResourceManager : public DelayedSingleton<BundleResourceManager> { 31 public: 32 BundleResourceManager(); 33 34 ~BundleResourceManager(); 35 /** 36 * add bundle resource and launcher ability resource by innerBundleInfo, used when install hap 37 */ 38 bool AddResourceInfo(const InnerBundleInfo &innerBundleInfo, const int32_t userId, std::string hapPath = ""); 39 /** 40 * delete resource info 41 */ 42 bool DeleteResourceInfo(const std::string &key); 43 /** 44 * add all resource info in system, used when system configuration changed, like: 45 * language, colorMode, theme, and so on 46 */ 47 bool AddAllResourceInfo(const int32_t userId); 48 /** 49 * delete all resource info 50 */ 51 bool DeleteAllResourceInfo(); 52 /** 53 * add bundle resource info by bundleName, used when bundle state changed, like: 54 * enable or disable 55 */ 56 bool AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId); 57 /** 58 * add launcher ability resource info by abilityName, used when ability state changed, like: 59 * enable or disable 60 */ 61 bool AddResourceInfoByAbility(const std::string &bundleName, const std::string &moduleName, 62 const std::string &abilityName, const int32_t userId); 63 64 bool GetAllResourceName(std::vector<std::string> &keyNames); 65 /** 66 * add resource info by colorMode changed 67 */ 68 bool AddResourceInfoByColorModeChanged(const int32_t userId); 69 70 bool GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags, 71 BundleResourceInfo &bundleResourceInfo); 72 73 bool GetLauncherAbilityResourceInfo(const std::string &bundleName, const uint32_t flags, 74 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfo); 75 76 bool GetAllBundleResourceInfo(const uint32_t flags, std::vector<BundleResourceInfo> &bundleResourceInfos); 77 78 bool GetAllLauncherAbilityResourceInfo(const uint32_t flags, 79 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 80 81 private: 82 bool AddResourceInfo(ResourceInfo &resourceInfo); 83 84 bool AddResourceInfos(std::vector<ResourceInfo> &resourceInfos); 85 86 void ProcessResourceInfoWhenParseFailed(ResourceInfo &resourceInfo); 87 88 std::string GetDefaultIcon(); 89 90 uint32_t CheckResourceFlags(const uint32_t flags); 91 92 void SendBundleResourcesChangedEvent(int32_t userId); 93 94 std::shared_ptr<BundleResourceRdb> bundleResourceRdb_; 95 }; 96 } // AppExecFwk 97 } // OHOS 98 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_MANAGER_H 99