1 /* 2 * Copyright (c) 2023-2025 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 <map> 20 #include <mutex> 21 #include <string> 22 #include <vector> 23 24 #include "ability_info.h" 25 #include "bundle_constants.h" 26 #include "bundle_resource_change_type.h" 27 #include "bundle_resource_icon_rdb.h" 28 #include "bundle_resource_rdb.h" 29 #include "bundle_system_state.h" 30 #include "inner_bundle_info.h" 31 #include "launcher_ability_info.h" 32 #include "resource_info.h" 33 #include "resource_manager.h" 34 #include "singleton.h" 35 #include "single_delayed_task_mgr.h" 36 #include "want.h" 37 38 namespace OHOS { 39 namespace AppExecFwk { 40 class BundleResourceManager : public DelayedSingleton<BundleResourceManager> { 41 public: 42 BundleResourceManager(); 43 44 ~BundleResourceManager(); 45 /** 46 * delete resource info 47 */ 48 bool DeleteResourceInfo(const std::string &key); 49 /** 50 * delete all resource info 51 */ 52 bool DeleteAllResourceInfo(); 53 54 bool GetAllResourceName(std::vector<std::string> &keyNames); 55 56 bool GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags, 57 BundleResourceInfo &bundleResourceInfo, const int32_t appIndex = 0); 58 59 bool GetLauncherAbilityResourceInfo(const std::string &bundleName, const uint32_t flags, 60 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfo, const int32_t appIndex = 0); 61 62 bool GetAllBundleResourceInfo(const uint32_t flags, std::vector<BundleResourceInfo> &bundleResourceInfos); 63 64 bool GetAllLauncherAbilityResourceInfo(const uint32_t flags, 65 std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 66 67 bool IsLauncherAbility(const LauncherAbilityResourceInfo &resourceInfo, std::vector<AbilityInfo> &abilityInfos); 68 69 bool GetLauncherAbilityInfos(const std::string &bundleName, std::vector<AbilityInfo> &abilityInfos); 70 71 bool FilterLauncherAbilityResourceInfoWithFlag(const uint32_t flags, 72 const std::string &bundleName, std::vector<LauncherAbilityResourceInfo> &launcherAbilityResourceInfos); 73 74 void GetTargetBundleName(const std::string &bundleName, std::string &targetBundleName); 75 76 bool DeleteNotExistResourceInfo(); 77 78 bool GetExtensionAbilityResourceInfo(const std::string &bundleName, 79 const ExtensionAbilityType extensionAbilityType, const uint32_t flags, 80 std::vector<LauncherAbilityResourceInfo> &extensionAbilityResourceInfo, const int32_t appIndex = 0); 81 82 bool AddResourceInfoByBundleNameWhenInstall(const std::string &bundleName, const int32_t userId, 83 const bool isBundleFirstInstall = true); 84 85 bool AddResourceInfoByBundleNameWhenUpdate(const std::string &bundleName, const int32_t userId); 86 87 bool AddResourceInfoByBundleNameWhenCreateUser(const std::string &bundleName, const int32_t userId); 88 89 bool DeleteBundleResourceInfo(const std::string &bundleName, const int32_t userId, const bool isExistInOtherUser); 90 91 bool AddDynamicIconResource( 92 const std::string &bundleName, const int32_t userId, const int32_t appIndex, ResourceInfo &resourceInfo); 93 94 bool DeleteDynamicIconResource(const std::string &bundleName, const int32_t userId, const int32_t appIndex); 95 96 bool AddAllResourceInfo(const int32_t userId, const uint32_t type); 97 98 bool AddResourceInfosWhenSystemThemeChanged( 99 std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap, 100 const int32_t userId, const uint32_t tempTaskNumber); 101 102 bool AddResourceInfosWhenSystemLanguageChanged( 103 std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap, 104 const int32_t userId, const uint32_t tempTaskNumber); 105 106 bool AddCloneBundleResourceInfoWhenInstall(const std::string &bundleName, const int32_t userId, 107 const int32_t appIndex, const bool isExistInOtherUser); 108 109 bool DeleteCloneBundleResourceInfoWhenUninstall(const std::string &bundleName, const int32_t userId, 110 const int32_t appIndex, const bool isExistInOtherUser); 111 112 void SetIsOnlineThemeWhenBoot(); 113 114 // for ota, need process all user 115 bool ProcessThemeAndDynamicIconWhenOta(const std::set<std::string> &updateBundleNames); 116 117 private: 118 void ProcessResourceInfoWhenParseFailed(ResourceInfo &resourceInfo); 119 120 void GetDefaultIcon(ResourceInfo &resourceInfo); 121 122 uint32_t CheckResourceFlags(const uint32_t flags); 123 124 void SendBundleResourcesChangedEvent(const int32_t userId, const uint32_t type); 125 126 void InnerProcessResourceInfoBySystemLanguageChanged( 127 std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap); 128 129 void InnerProcessResourceInfoBySystemThemeChanged( 130 std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap, const int32_t userId); 131 132 void DeleteNotExistResourceInfo(const std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap, 133 const std::vector<std::string> &existResourceNames); 134 135 bool GetBundleResourceInfoForCloneBundle(const std::string &bundleName, 136 const int32_t appIndex, const uint32_t type, std::vector<ResourceInfo> &resourceInfos); 137 138 bool ProcessCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex); 139 140 void DeleteNotExistResourceInfo(const std::string &bundleName, 141 const int32_t appIndex, const std::vector<ResourceInfo> &resourceInfos); 142 143 void ProcessResourceInfoNoNeedToParseOtherIcon(std::vector<ResourceInfo> &resourceInfos); 144 145 bool ProcessCloneBundleResourceInfoWhenSystemThemeChanged( 146 const std::string &bundleName, const int32_t userId, const int32_t appIndex); 147 148 bool ProcessCloneBundleResourceInfoWhenSystemLanguageChanged( 149 const std::string &bundleName, const int32_t userId, const int32_t appIndex); 150 151 void DeleteNotExistThemeResource(const std::map<std::string, std::vector<ResourceInfo>> &resourceInfosMap, 152 const std::set<std::string> &oldResourceNames, const int32_t userId); 153 154 bool IsNeedProcessResourceIconInfo(const uint32_t resourceFlags); 155 156 bool InnerProcessThemeIconWhenOta(const std::string &bundleName, const std::set<int32_t> userIds, 157 const bool hasBundleUpdated = false); 158 159 bool InnerProcessDynamicIconWhenOta(const std::string &bundleName); 160 161 int32_t GetUserId(); 162 163 void SetIsOnlineTheme(const int32_t userId); 164 165 void PrepareSysRes(); 166 167 std::atomic<bool> isInterrupted_ = false; 168 std::atomic_uint currentTaskNum_ = 0; 169 std::mutex mutex_; 170 std::shared_ptr<BundleResourceRdb> bundleResourceRdb_; 171 std::shared_ptr<BundleResourceIconRdb> bundleResourceIconRdb_; 172 std::shared_ptr<SingleDelayedTaskMgr> delayedTaskMgr_ = nullptr; 173 static std::mutex g_sysResMutex; 174 static std::shared_ptr<Global::Resource::ResourceManager> g_resMgr; 175 }; 176 } // AppExecFwk 177 } // OHOS 178 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_MANAGER_H 179