From 2f5f235f8f0da9875b408d83c40f962e007ad5cd Mon Sep 17 00:00:00 2001 From: wang19954 Date: Thu, 7 Aug 2025 10:54:51 +0800 Subject: [PATCH 1/3] IssueNo:#ICRQXV Description:optim bundle resource Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- services/bundlemgr/appexecfwk_bundlemgr.gni | 2 + .../bundlemgr/include/base_bundle_installer.h | 1 - services/bundlemgr/include/bundle_data_mgr.h | 2 + .../bundle_mgr_service_event_handler.h | 3 + .../bundle_resource_constants.h | 6 +- .../bundle_resource_icon_rdb.h | 93 + .../bundle_resource/bundle_resource_manager.h | 116 +- .../bundle_resource/bundle_resource_parser.h | 10 +- .../bundle_resource/bundle_resource_process.h | 9 +- .../bundle_resource_theme_process.h | 45 + .../include/bundle_resource/resource_info.h | 10 +- .../include/bundle_resource_helper.h | 27 +- .../bundlemgr/src/base_bundle_installer.cpp | 44 +- services/bundlemgr/src/bundle_data_mgr.cpp | 20 + .../src/bundle_mgr_service_event_handler.cpp | 36 +- .../src/bundle_multiuser_installer.cpp | 3 +- .../bundle_resource_callback.cpp | 28 +- .../bundle_resource_drawable.cpp | 25 - .../bundle_resource_event_subscriber.cpp | 2 +- .../bundle_resource_icon_rdb.cpp | 425 +++++ .../bundle_resource_manager.cpp | 1547 ++++++++++------- .../bundle_resource_parser.cpp | 154 +- .../bundle_resource_process.cpp | 69 +- .../bundle_resource_theme_process.cpp | 93 + .../bundlemgr/src/bundle_resource_helper.cpp | 83 +- .../src/clone/bundle_clone_installer.cpp | 10 +- .../extend_resource_manager_host_impl.cpp | 39 +- .../bms_bundle_installer_test.cpp | 18 - .../bms_bundle_resource_test.cpp | 1302 +------------- .../bmsbundleresourcehelpersecond_fuzzer.cpp | 12 +- .../bmsbundleresourcemanager_fuzzer.cpp | 63 +- .../bmsbundleresourcehelper_fuzzer.cpp | 7 +- .../bundleresmgr_fuzzer.cpp | 22 +- .../bundleresparser_fuzzer.cpp | 1 - 34 files changed, 1936 insertions(+), 2391 deletions(-) create mode 100644 services/bundlemgr/include/bundle_resource/bundle_resource_icon_rdb.h create mode 100644 services/bundlemgr/include/bundle_resource/bundle_resource_theme_process.h create mode 100644 services/bundlemgr/src/bundle_resource/bundle_resource_icon_rdb.cpp create mode 100644 services/bundlemgr/src/bundle_resource/bundle_resource_theme_process.cpp diff --git a/services/bundlemgr/appexecfwk_bundlemgr.gni b/services/bundlemgr/appexecfwk_bundlemgr.gni index 6b22092d70..ce2589af14 100644 --- a/services/bundlemgr/appexecfwk_bundlemgr.gni +++ b/services/bundlemgr/appexecfwk_bundlemgr.gni @@ -246,6 +246,7 @@ bundle_resource = [ "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_drawable.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_event_subscriber.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_host_impl.cpp", + "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_icon_rdb.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_image_info.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_observer.cpp", @@ -254,6 +255,7 @@ bundle_resource = [ "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_process.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_rdb.cpp", "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_register.cpp", + "${services_path}/bundlemgr/src/bundle_resource/bundle_resource_theme_process.cpp", "${services_path}/bundlemgr/src/bundle_resource/resource_info.cpp", ] diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 523f8bd1dd..4655355be4 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -822,7 +822,6 @@ private: bool AddAppGalleryHapToTempPath(const bool isPreInstallApp, const std::unordered_map &infos); bool DeleteAppGalleryHapFromTempPath(); - void ProcessAddResourceInfo(const InstallParam &installParam, const std::string &bundleName, int32_t userId); bool GetTempBundleInfo(InnerBundleInfo &info) const; bool InitTempBundleFromCache(InnerBundleInfo &info, bool &isAppExist, std::string bundleName = ""); ErrCode UpdateAppEncryptedStatus(const std::string &bundleName, bool isExisted, int32_t appIndex); diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index ee7bc02f50..610c06d200 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -798,6 +798,8 @@ public: void CreateAppInstallDir(int32_t userId); void RemoveAppInstallDir(int32_t userId); bool IsObtainAbilityInfo(const Want &want, int32_t userId, AbilityInfo &abilityInfo); + ErrCode GetExtendResourceInfo(const std::string &bundleName, const std::string &moduleName, + ExtendResourceInfo &extendResourceInfos); /** * @brief Sets whether to enable isRemovable based on given bundle name, module name and isEnable. diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index b110e4db45..349f98d520 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -58,6 +58,7 @@ enum OTAFlag : uint32_t { DELETE_DEPRECATED_ARK_PATHS = 0x00008000, CHECK_EXTENSION_ABILITY = 0x00010000, PROCESS_DYNAMIC_ICON = 0x00020000, + PROCESS_THEME_AND_DYNAMIC_ICON = 0x00040000, }; enum class ScanResultCode : uint8_t { @@ -648,6 +649,8 @@ private: bool UpdateModuleByHash(const BundleInfo &oldBundleInfo, const InnerBundleInfo &newInfo) const; void CheckALLResourceInfo(); void InnerProcessAllDynamicIconInfoWhenOta(); + void InnerProcessAllThemeAndDynamicIconInfoWhenOta( + const std::unordered_map> &needInstallMap); // Used to add bundle resource Info that does not exist in rdb when OTA. void static ProcessBundleResourceInfo(); // scan all bundle data group info diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_constants.h b/services/bundlemgr/include/bundle_resource/bundle_resource_constants.h index 67d3e6289a..6c307f9da6 100644 --- a/services/bundlemgr/include/bundle_resource/bundle_resource_constants.h +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_constants.h @@ -27,18 +27,22 @@ constexpr const char* BUNDLE_RESOURCE_RDB_STORAGE_PATH = "/data/storage/bundle_r constexpr const char* BUNDLE_RESOURCE_RDB_NAME = "/bundleResource.db"; // resource table name constexpr const char* BUNDLE_RESOURCE_RDB_TABLE_NAME = "bundleResource"; +constexpr const char* BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME = "bundleIconResource"; constexpr const char* SEPARATOR = "/"; +constexpr const char* UNDER_LINE = "_"; constexpr const char* EXTENSION_ABILITY_SEPARATOR = "+"; // bundle resource rdb table key constexpr const char* NAME = "NAME"; constexpr const char* UPDATE_TIME = "UPDATE_TIME"; +constexpr const char* USER_ID = "USER_ID"; +constexpr const char* ICON_TYPE = "ICON_TYPE"; constexpr const char* LABEL = "LABEL"; constexpr const char* ICON = "ICON"; constexpr const char* SYSTEM_STATE = "SYSTEM_STATE"; constexpr const char* FOREGROUND = "FOREGROUND"; constexpr const char* BACKGROUND = "BACKGROUND"; constexpr const char* USER_FILE_NAME = "/userFile.json"; -constexpr const char* USER_ID = "user"; +constexpr const char* USER = "user"; constexpr const char* THEME = "theme"; constexpr const char* LANGUAGE = "language"; constexpr const char* THEME_ID = "themeId"; diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_icon_rdb.h b/services/bundlemgr/include/bundle_resource/bundle_resource_icon_rdb.h new file mode 100644 index 0000000000..50c7190e11 --- /dev/null +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_icon_rdb.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H +#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H + +#include +#include +#include + +#include "bundle_resource_info.h" +#include "launcher_ability_resource_info.h" +#include "rdb_data_manager.h" +#include "resource_info.h" + +namespace OHOS { +namespace AppExecFwk { +class BundleResourceIconRdb : public std::enable_shared_from_this { +public: + BundleResourceIconRdb(); + ~BundleResourceIconRdb(); + // add resource info to resource rdb + bool AddResourceIconInfo(const int32_t userId, const IconResourceType type, + const ResourceInfo &resourceInfo); + + bool AddResourceIconInfos(const int32_t userId, const IconResourceType type, + const std::vector &resourceInfos); + + bool DeleteResourceIconInfo(const std::string &bundleName, const int32_t userId, + const int32_t appIndex = 0, const IconResourceType type = IconResourceType::UNKNOWN); + + bool DeleteResourceIconInfos(const std::string &bundleName, const int32_t userId, + const IconResourceType type = IconResourceType::UNKNOWN); + + bool DeleteResourceIconInfos(const std::string &bundleName, + const IconResourceType type = IconResourceType::UNKNOWN); + + bool GetAllResourceIconName(const int32_t userId, std::set &resourceNames, + const IconResourceType type = IconResourceType::UNKNOWN); + + bool GetResourceIconInfos(const std::string &bundleName, const int32_t userId, + const int32_t appIndex, const uint32_t resourceFlag, + std::vector &launcherAbilityResourceInfos, + const IconResourceType type = IconResourceType::UNKNOWN); + + bool GetAllResourceIconInfo(const int32_t userId, const uint32_t resourceFlag, + std::vector &launcherAbilityResourceInfos); + + void SetIsOnlineTheme(const int32_t userId, bool isOnlineTheme); + + bool GetIsOnlineTheme(const int32_t userId); + +private: + void ParseNameToResourceName(const std::string &name, std::string &resourceName); + + bool ConvertToLauncherAbilityResourceInfo( + const std::shared_ptr &absSharedResultSet, const uint32_t resourceFlag, + LauncherAbilityResourceInfo &launcherAbilityResourceInfo, IconResourceType &iconType); + + void ParseKey(const std::string &key, + LauncherAbilityResourceInfo &launcherAbilityResourceInfo); + + void InnerProcessResourceIconInfos(const LauncherAbilityResourceInfo &resourceInfo, + const IconResourceType type, const int32_t userId, + std::vector &launcherAbilityResourceInfos); + + std::shared_ptr rdbDataManager_; + mutable ffrt::shared_mutex isOnlineThemeMutex_; + std::unordered_map isOnlineThemeMap_; + +#define CHECK_RDB_RESULT_RETURN_IF_FAIL(errcode, errmsg) \ + do { \ + if ((errcode) != NativeRdb::E_OK) { \ + APP_LOGE(errmsg, errcode); \ + return false; \ + } \ + } while (0) +}; +} // AppExecFwk +} // OHOS +#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_ICON_RDB_H diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_manager.h b/services/bundlemgr/include/bundle_resource/bundle_resource_manager.h index c80387202e..3aaa0ec141 100644 --- a/services/bundlemgr/include/bundle_resource/bundle_resource_manager.h +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_manager.h @@ -24,6 +24,7 @@ #include "ability_info.h" #include "bundle_constants.h" #include "bundle_resource_change_type.h" +#include "bundle_resource_icon_rdb.h" #include "bundle_resource_rdb.h" #include "bundle_system_state.h" #include "inner_bundle_info.h" @@ -45,27 +46,10 @@ public: * delete resource info */ bool DeleteResourceInfo(const std::string &key); - /** - * add all resource info in system, used when system configuration changed, like: - * language, colorMode, theme, and so on - */ - bool AddAllResourceInfo(const int32_t userId, const uint32_t type, - const int32_t oldUserId = Constants::INVALID_USERID); /** * delete all resource info */ bool DeleteAllResourceInfo(); - /** - * add bundle resource info by bundleName, used when bundle state changed, like: - * enable or disable - */ - bool AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId); - /** - * add launcher ability resource info by abilityName, used when ability state changed, like: - * enable or disable - */ - bool AddResourceInfoByAbility(const std::string &bundleName, const std::string &moduleName, - const std::string &abilityName, const int32_t userId); bool GetAllResourceName(std::vector &keyNames); @@ -87,46 +71,51 @@ public: bool FilterLauncherAbilityResourceInfoWithFlag(const uint32_t flags, const std::string &bundleName, std::vector &launcherAbilityResourceInfos); - bool SaveResourceInfos(std::vector &resourceInfos); - void GetTargetBundleName(const std::string &bundleName, std::string &targetBundleName); - bool UpdateBundleIcon(const std::string &bundleName, ResourceInfo &resourceInfo); - - bool AddCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex, - const int32_t userId = Constants::UNSPECIFIED_USERID); - - bool DeleteCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex); - bool DeleteNotExistResourceInfo(); - bool AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId, const int32_t appIndex); - bool GetExtensionAbilityResourceInfo(const std::string &bundleName, const ExtensionAbilityType extensionAbilityType, const uint32_t flags, std::vector &extensionAbilityResourceInfo, const int32_t appIndex = 0); - bool GetResourceInfoForRequestUser(const std::string &bundleName, const int32_t userId, const uint32_t flags, - const int32_t appIndex, std::vector &launcherAbilityResourceInfo); - - bool ConvertLauncherAbilityResourceInfo(const ResourceInfo &resourceInfo, const uint32_t flags, - LauncherAbilityResourceInfo &launcherAbilityResourceInfo); + bool AddResourceInfoByBundleNameWhenInstall(const std::string &bundleName, const int32_t userId, + const bool isBundleFirstInstall = true); -private: - bool AddResourceInfo(const int32_t userId, ResourceInfo &resourceInfo); + bool AddResourceInfoByBundleNameWhenUpdate(const std::string &bundleName, const int32_t userId); - bool AddResourceInfos(const int32_t userId, std::vector &resourceInfos); + bool AddResourceInfoByBundleNameWhenCreateUser(const std::string &bundleName, const int32_t userId); - bool AddResourceInfosByMap(std::map> &resourceInfosMap, - const uint32_t tempTaskNumber, const uint32_t type, const int32_t userId, const int32_t oldUserId); + bool DeleteBundleResourceInfo(const std::string &bundleName, const int32_t userId, const bool isExistInOtherUser); - void InnerProcessResourceInfoByResourceUpdateType( - std::map> &resourceInfosMap, const uint32_t type, - const int32_t userId, const int32_t oldUserId); + bool AddDynamicIconResource( + const std::string &bundleName, const int32_t userId, const int32_t appIndex, ResourceInfo &resourceInfo); - void ProcessResourceInfoWhenParseFailed(ResourceInfo &resourceInfo); + bool DeleteDynamicIconResource(const std::string &bundleName, const int32_t userId, const int32_t appIndex); + + bool AddAllResourceInfo(const int32_t userId, const uint32_t type); + + bool AddResourceInfosWhenSystemThemeChanged( + std::map> &resourceInfosMap, + const int32_t userId, const uint32_t tempTaskNumber); + + bool AddResourceInfosWhenSystemLanguageChanged( + std::map> &resourceInfosMap, + const int32_t userId, const uint32_t tempTaskNumber); - void ProcessResourceInfo(const std::vector &resourceInfos, ResourceInfo &resourceInfo); + bool AddCloneBundleResourceInfoWhenInstall(const std::string &bundleName, const int32_t userId, + const int32_t appIndex, const bool isExistInOtherUser); + + bool DeleteCloneBundleResourceInfoWhenUninstall(const std::string &bundleName, const int32_t userId, + const int32_t appIndex, const bool isExistInOtherUser); + + void SetIsOnlineThemeWhenBoot(); + + // for ota, need process all user + bool ProcessThemeAndDynamicIconWhenOta(const std::set &updateBundleNames); + +private: + void ProcessResourceInfoWhenParseFailed(ResourceInfo &resourceInfo); void GetDefaultIcon(ResourceInfo &resourceInfo); @@ -138,50 +127,47 @@ private: std::map> &resourceInfosMap); void InnerProcessResourceInfoBySystemThemeChanged( - std::map> &resourceInfosMap, - const int32_t userId); - - void InnerProcessResourceInfoByUserIdChanged( - std::map> &resourceInfosMap, - const int32_t userId, const int32_t oldUserId); + std::map> &resourceInfosMap, const int32_t userId); void DeleteNotExistResourceInfo(const std::map> &resourceInfosMap, const std::vector &existResourceNames); - bool InnerProcessWhetherThemeExist(const std::string &bundleName, const int32_t userId); - bool GetBundleResourceInfoForCloneBundle(const std::string &bundleName, - const int32_t appIndex, std::vector &resourceInfos); - - bool UpdateCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex, const uint32_t type); + const int32_t appIndex, const uint32_t type, std::vector &resourceInfos); - bool UpdateCloneBundleResourceInfo(const std::string &bundleName, const int32_t userId, - const int32_t appIndex, const uint32_t type); + bool ProcessCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex); void DeleteNotExistResourceInfo(const std::string &bundleName, const int32_t appIndex, const std::vector &resourceInfos); void ProcessResourceInfoNoNeedToParseOtherIcon(std::vector &resourceInfos); - bool ProcessUpdateCloneBundleResourceInfo(const std::string &bundleName); + bool ProcessCloneBundleResourceInfoWhenSystemThemeChanged( + const std::string &bundleName, const int32_t userId, const int32_t appIndex); - void BundleResourceConvertToResourceInfo(const BundleResourceInfo &bundleResourceInfo, ResourceInfo &resourceInfo); + bool ProcessCloneBundleResourceInfoWhenSystemLanguageChanged( + const std::string &bundleName, const int32_t userId, const int32_t appIndex); - void LauncherAbilityResourceConvertToResourceInfo( - const LauncherAbilityResourceInfo &launcherAbilityResourceInfo, ResourceInfo &resourceInfo); + void DeleteNotExistThemeResource(const std::map> &resourceInfosMap, + const std::set &oldResourceNames, const int32_t userId); - void PrepareSysRes(); + bool IsNeedProcessResourceIconInfo(const uint32_t resourceFlags); - bool CheckAllAddResourceInfo(const int32_t userId); + bool InnerProcessThemeIconWhenOta(const std::string &bundleName, const std::set userIds); - void FilterResourceInfoWhenSystemThemeChanged( - std::map> &resourceInfosMap, - const int32_t userId); + bool InnerProcessDynamicIconWhenOta(const std::string &bundleName); + + int32_t GetUserId(); + + void SetIsOnlineTheme(const int32_t userId); + + void PrepareSysRes(); std::atomic isInterrupted_ = false; std::atomic_uint currentTaskNum_ = 0; std::mutex mutex_; std::shared_ptr bundleResourceRdb_; + std::shared_ptr bundleResourceIconRdb_; std::shared_ptr delayedTaskMgr_ = nullptr; static std::mutex g_sysResMutex; static std::shared_ptr g_resMgr; diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h b/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h index 7cd2223abe..dddba70696 100644 --- a/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_parser.h @@ -41,6 +41,10 @@ public: // parse clone bundle resource info bool ParserCloneResourceInfo(const int32_t appIndex, std::vector &resourceInfos); + bool ParseResourceInfosNoTheme(const int32_t userId, std::vector &resourceInfos); + + bool ParseIconResourceInfosWithTheme(const int32_t userId, std::vector &resourceInfos); + private: // for defaultIconPath is empty, icon and label exist in same hap. bool ParseResourceInfoWithSameHap(const int32_t userId, ResourceInfo &resourceInfo); @@ -49,7 +53,7 @@ private: bool ParseLabelResourceByPath(const std::string &hapPath, const uint32_t labelId, std::string &label); bool ParseResourceInfoByResourceManager(const std::shared_ptr resourceManager, - ResourceInfo &resourceInfo); + ResourceInfo &resourceInfo, bool usingThemeResource = true); // parse label resource by resourceManager bool ParseLabelResourceByResourceManager(const std::shared_ptr resourceManager, @@ -57,7 +61,7 @@ private: // parse foreground/background/mask icons resource by resourceManager bool ParseIconResourceByResourceManager(const std::shared_ptr resourceManager, - ResourceInfo &resourceInfo); + ResourceInfo &resourceInfo, bool usingThemeResource = true); bool ParseForegroundAndBackgroundResource( const std::shared_ptr resourceManager, @@ -69,8 +73,6 @@ private: const uint32_t iconId, const int32_t density, std::vector &data); bool IsNeedToParseResourceInfo(const ResourceInfo &newResourceInfo, const ResourceInfo &oldResourceInfo); - - void ProcessSpecialBundleResource(const int32_t userId, std::vector &resourceInfos); }; } // AppExecFwk } // OHOS diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_process.h b/services/bundlemgr/include/bundle_resource/bundle_resource_process.h index c15352c8e6..eca9fbb165 100644 --- a/services/bundlemgr/include/bundle_resource/bundle_resource_process.h +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_process.h @@ -31,7 +31,8 @@ class BundleResourceProcess { public: // get LauncherAbilityResourceInfo and BundleResourceInfo by bundleName static bool GetResourceInfoByBundleName(const std::string &bundleName, const int32_t userId, - std::vector &resourceInfo, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); + std::vector &resourceInfo, const int32_t appIndex = Constants::DEFAULT_APP_INDEX, + bool needParseDynamic = true); // get LauncherAbilityResourceInfo by abilityName static bool GetLauncherResourceInfoByAbilityName(const std::string &bundleName, const std::string &moduleName, const std::string &abilityName, const int32_t userId, @@ -55,6 +56,9 @@ public: static bool CheckThemeType(const std::string &bundleName, const int32_t userId, bool &isOnlineTheme); + static bool GetDynamicIconResourceInfo(const std::string &bundleName, + const std::string &dynamicModuleName, ResourceInfo &resourceInfo); + private: // used for show in settings static bool GetBundleResourceInfo(const InnerBundleInfo &innerBundleInfo, const int32_t userId, @@ -75,7 +79,8 @@ private: static ResourceInfo ConvertToExtensionAbilityResourceInfo(const ExtensionAbilityInfo &info); static bool InnerGetResourceInfo(const InnerBundleInfo &innerBundleInfo, const int32_t userId, - std::vector &resourceInfos, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); + std::vector &resourceInfos, const int32_t appIndex = Constants::DEFAULT_APP_INDEX, + bool needParseDynamic = true); static bool OnGetResourceInfo(const InnerBundleInfo &innerBundleInfo, const int32_t userId, std::vector &resourceInfos); diff --git a/services/bundlemgr/include/bundle_resource/bundle_resource_theme_process.h b/services/bundlemgr/include/bundle_resource/bundle_resource_theme_process.h new file mode 100644 index 0000000000..4ebb8ba53f --- /dev/null +++ b/services/bundlemgr/include/bundle_resource/bundle_resource_theme_process.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_THEME_PROCESS_H +#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_THEME_PROCESS_H + +#include + +#include "bundle_resource_info.h" +#include "launcher_ability_resource_info.h" + +namespace OHOS { +namespace AppExecFwk { +class BundleResourceThemeProcess : public std::enable_shared_from_this { +public: + BundleResourceThemeProcess() {}; + ~BundleResourceThemeProcess() {}; + + static bool IsBundleThemeExist(const std::string &bundleName, const int32_t userId); + + static bool IsAbilityThemeExist(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, const int32_t userId); + + static bool IsThemeExistInFlagA(const std::string &bundleName, const int32_t userId); + + static bool IsThemeExistInFlagB(const std::string &bundleName, const int32_t userId); + + static void ProcessSpecialBundleResource(const std::vector &resourceIconInfos, + BundleResourceInfo &bundleResourceInfo); +}; +} // AppExecFwk +} // OHOS +#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_THEME_PROCESS_H diff --git a/services/bundlemgr/include/bundle_resource/resource_info.h b/services/bundlemgr/include/bundle_resource/resource_info.h index 39639c9c8e..d8063cdd0b 100644 --- a/services/bundlemgr/include/bundle_resource/resource_info.h +++ b/services/bundlemgr/include/bundle_resource/resource_info.h @@ -23,6 +23,12 @@ #include "launcher_ability_resource_info.h" namespace OHOS { namespace AppExecFwk { +enum class IconResourceType { + UNKNOWN = 0, + THEME_ICON = 1, + DYNAMIC_ICON = 2 +}; + class ResourceInfo { public: ResourceInfo(); @@ -47,10 +53,6 @@ public: // for app clone int32_t appIndex_ = 0; int32_t extensionAbilityType_ = -1; - // for dynamic icon - bool hasDynamicIcon_ = false; - // for theme icon - bool hasThemeIcon_ = false; // key std::string bundleName_; std::string moduleName_; diff --git a/services/bundlemgr/include/bundle_resource_helper.h b/services/bundlemgr/include/bundle_resource_helper.h index ced2f09867..56525181bc 100644 --- a/services/bundlemgr/include/bundle_resource_helper.h +++ b/services/bundlemgr/include/bundle_resource_helper.h @@ -26,6 +26,12 @@ namespace OHOS { namespace AppExecFwk { +enum class ADD_RESOURCE_TYPE { + INSTALL_BUNDLE = 1, + UPDATE_BUNDLE = 2, + CREATE_USER = 3 +}; + class BundleResourceHelper { public: // parse system config and init BundleSystemState, like language and colorMode @@ -38,30 +44,29 @@ public: static void RegisterCommonEventSubscriber(); static void AddResourceInfoByBundleName(const std::string &bundleName, - const int32_t userId); + const int32_t userId, const ADD_RESOURCE_TYPE type, const bool isBundleFirstInstall = true); - static bool DeleteResourceInfo(const std::string &key, const int32_t userId = Constants::UNSPECIFIED_USERID); + static bool DeleteBundleResourceInfo(const std::string &bundleName, + const int32_t userId, const bool isExistInOtherUser); static bool DeleteAllResourceInfo(); - static void SetApplicationEnabled(const std::string &bundleName, bool enabled, const int32_t userId, - int32_t appIndex = 0); - - static void SetAbilityEnabled(const std::string &bundleName, const std::string &moduleName, - const std::string &abilityName, bool enabled, const int32_t userId, int32_t appIndex = 0); - static void GetAllBundleResourceName(std::vector &resourceNames); static std::string ParseBundleName(const std::string &keyName); + static void SetIsOnlineThemeWhenBoot(); + static void SetOverlayEnabled(const std::string &bundleName, const std::string &moduleName, bool isEnabled, int32_t userId); static bool AddCloneBundleResourceInfo(const std::string &bundleName, - const int32_t appIndex, const int32_t userId = Constants::UNSPECIFIED_USERID); + const int32_t userId, const int32_t appIndex, const bool isExistInOtherUser); + + static bool DeleteCloneBundleResourceInfo(const std::string &bundleName, const int32_t userId, + const int32_t appIndex, const bool isExistInOtherUser); - static bool DeleteCloneBundleResourceInfo(const std::string &bundleName, const int32_t appIndex, - const int32_t userId = Constants::UNSPECIFIED_USERID); + static bool ProcessThemeAndDynamicIconWhenOta(const std::set updateBundleNames); static void DeleteNotExistResourceInfo(); diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index be98542e1c..e0a3497b10 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1540,7 +1540,9 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector ProcessArkStartupCache(ceateArk, cacheInfo.GetModuleSize(), userId_); } ProcessUpdateShortcut(); - ProcessAddResourceInfo(installParam, bundleName_, userId_); + BundleResourceHelper::AddResourceInfoByBundleName(bundleName_, userId_, + (isAppExist_ && hasInstalledInUser_) ? ADD_RESOURCE_TYPE::UPDATE_BUNDLE : ADD_RESOURCE_TYPE::INSTALL_BUNDLE, + !isAppExist_); if (!ProcessExtProfile(installParam)) { LOG_W(BMS_TAG_INSTALLER, "ProcessExtProfile failed"); } @@ -1831,6 +1833,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( "DeleteShortcutVisibleInfo failed, bundleName: %{public}s, userId: %{public}d, appIndex: 0", bundleName.c_str(), userId_); } + BundleResourceHelper::DeleteBundleResourceInfo(bundleName, userId_, true); return ERR_OK; } dataMgr_->DisableBundle(bundleName); @@ -1915,7 +1918,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( } DeleteEncryptedStatus(bundleName, uid); - BundleResourceHelper::DeleteResourceInfo(bundleName, userId_); + BundleResourceHelper::DeleteBundleResourceInfo(bundleName, userId_, false); DeleteRouterInfo(bundleName); // remove profile from code signature RemoveProfileFromCodeSign(bundleName); @@ -2128,6 +2131,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( DeleteRouterInfo(bundleName); SaveUninstallBundleInfo(bundleName, installParam.isKeepData, uninstallBundleInfo); UninstallDebugAppSandbox(bundleName, uid, oldInfo); + BundleResourceHelper::DeleteBundleResourceInfo(bundleName, userId_, false); return ERR_OK; } auto removeRes = RemoveBundleUserData(oldInfo, installParam.isKeepData); @@ -2139,6 +2143,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( if (!PatchDataMgr::GetInstance().DeleteInnerPatchInfo(bundleName)) { LOG_E(BMS_TAG_INSTALLER, "DeleteInnerPatchInfo failed, bundleName: %{public}s", bundleName.c_str()); } + BundleResourceHelper::DeleteBundleResourceInfo(bundleName, userId_, true); return ERR_OK; } @@ -2322,6 +2327,8 @@ ErrCode BaseBundleInstaller::InnerProcessInstallByPreInstallInfo( preInstallBundleInfo.DeleteForceUnisntalledUser(userId_); dataMgr_->SavePreInstallBundleInfo(bundleName, preInstallBundleInfo); } + // process resource + BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId_, ADD_RESOURCE_TYPE::CREATE_USER); return ERR_OK; } } @@ -7007,7 +7014,7 @@ ErrCode BaseBundleInstaller::RollbackHmpCommonInfo(const std::string &bundleName oldInfo.GetBundleName().c_str()); } DeleteRouterInfo(oldInfo.GetBundleName()); - BundleResourceHelper::DeleteResourceInfo(oldInfo.GetBundleName()); + BundleResourceHelper::DeleteBundleResourceInfo(oldInfo.GetBundleName(), userId_, false); RemoveProfileFromCodeSign(oldInfo.GetBundleName()); ClearDomainVerifyStatus(oldInfo.GetAppIdentifier(), oldInfo.GetBundleName()); return ERR_OK; @@ -7343,37 +7350,6 @@ bool BaseBundleInstaller::DeleteAppGalleryHapFromTempPath() return true; } -void BaseBundleInstaller::ProcessAddResourceInfo(const InstallParam &installParam, - const std::string &bundleName, int32_t userId) -{ - // if bundle not exist, need to add resource - if (!isAppExist_) { - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId); - return; - } - // if user id is 0, 1, or 100, need to add resource - if ((userId == Constants::DEFAULT_USERID) || (userId == Constants::U1) || - (userId == Constants::START_USERID)) { - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId); - return; - } - // For multiple users, it is necessary to check whether the userId is equal to the current active userId. - // When OTA, the default user is obtained. - int32_t currentUserId = AccountHelper::GetCurrentActiveUserIdWithRetry(installParam.isOTA || otaInstall_); - if (currentUserId == Constants::INVALID_USERID) { - LOG_W(BMS_TAG_INSTALLER, "current user %{public}d is invalid", currentUserId); - if ((installParam.isOTA || otaInstall_) && userId != Constants::START_USERID && - dataMgr_->HasUserInstallInBundle(bundleName, Constants::START_USERID)) { - return; - } - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId); - return; - } - if (userId == currentUserId) { - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId); - } -} - void BaseBundleInstaller::CheckPreBundle(const std::unordered_map &newInfos, const InstallParam &installParam, bool isRecover) { diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index abdc0648b5..2a08728916 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -2729,6 +2729,26 @@ bool BundleDataMgr::RemoveExtResources(const std::string &bundleName, return true; } +ErrCode BundleDataMgr::GetExtendResourceInfo( + const std::string &bundleName, const std::string &moduleName, + ExtendResourceInfo &extendResourceInfo) +{ + std::shared_lock lock(bundleInfoMutex_); + auto infoItem = bundleInfos_.find(bundleName); + if (infoItem == bundleInfos_.end()) { + APP_LOGE("can not find bundle %{public}s", bundleName.c_str()); + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; + } + auto extendResourceInfos = infoItem->second.GetExtendResourceInfos(); + auto iter = extendResourceInfos.find(moduleName); + if (iter == extendResourceInfos.end()) { + APP_LOGE("can not find module %{public}s", moduleName.c_str()); + return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; + } + extendResourceInfo = iter->second; + return ERR_OK; +} + bool BundleDataMgr::UpateCurDynamicIconModule( const std::string &bundleName, const std::string &moduleName, const int32_t userId, const int32_t appIndex) { diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index 396a69fcba..fbd0f25548 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -306,6 +306,8 @@ void BMSEventHandler::AfterBmsStart() } #endif DelayedSingleton::GetInstance()->CheckAllUser(); + // process is online theme + BundleResourceHelper::SetIsOnlineThemeWhenBoot(); CreateAppInstallDir(); SetAllInstallFlag(); HandleSceneBoard(); @@ -366,6 +368,7 @@ void BMSEventHandler::BundleBootStartEvent() UpdateOtaFlag(OTAFlag::CHECK_INSTALL_SOURCE); UpdateOtaFlag(OTAFlag::DELETE_DEPRECATED_ARK_PATHS); UpdateOtaFlag(OTAFlag::PROCESS_DYNAMIC_ICON); + UpdateOtaFlag(OTAFlag::PROCESS_THEME_AND_DYNAMIC_ICON); (void)SaveBmsSystemTimeForShortcut(); UpdateOtaFlag(OTAFlag::CHECK_EXTENSION_ABILITY); (void)SaveUpdatePermissionsFlag(); @@ -1283,7 +1286,6 @@ void BMSEventHandler::ProcessRebootBundle() ProcessCheckRecoverableApplicationInfo(); ProcessCheckInstallSource(); ProcessCheckAppExtensionAbility(); - InnerProcessAllDynamicIconInfoWhenOta(); // Driver update may cause shader cache invalidity and need to be cleared CleanAllBundleShaderCache(); CleanAllBundleEl1ShaderCacheLocal(); @@ -2233,6 +2235,8 @@ void BMSEventHandler::InnerProcessRebootBundleInstall( LOG_E(BMS_TAG_DEFAULT, "multi install failed"); } UpdatePreinstallDB(needInstallMap); + // process bundle theme and dynamic resource + InnerProcessAllThemeAndDynamicIconInfoWhenOta(needInstallMap); } bool BMSEventHandler::CheckIsBundleUpdatedByHapPath(const BundleInfo &bundleInfo) @@ -2614,7 +2618,7 @@ void BMSEventHandler::InnerProcessCheckAppExtensionAbility() for (const auto &bundleName : bundleNames) { LOG_NOFUNC_I(BMS_TAG_DEFAULT, "-n %{public}s add resource when ota", bundleName.c_str()); - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId); + BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId, ADD_RESOURCE_TYPE::UPDATE_BUNDLE); } } @@ -4357,7 +4361,8 @@ void BMSEventHandler::ProcessBundleResourceInfo() for (const auto &bundleName : needAddResourceBundles) { LOG_NOFUNC_I(BMS_TAG_DEFAULT, "-n %{public}s add resource when reboot", bundleName.c_str()); - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, Constants::START_USERID); + BundleResourceHelper::AddResourceInfoByBundleName(bundleName, Constants::START_USERID, + ADD_RESOURCE_TYPE::INSTALL_BUNDLE); } LOG_I(BMS_TAG_DEFAULT, "ProcessBundleResourceInfo end"); } @@ -4829,6 +4834,31 @@ void BMSEventHandler::InnerProcessAllDynamicIconInfoWhenOta() UpdateOtaFlag(OTAFlag::PROCESS_DYNAMIC_ICON); } +void BMSEventHandler::InnerProcessAllThemeAndDynamicIconInfoWhenOta( + const std::unordered_map> &needInstallMap) +{ + // process dynamic info + InnerProcessAllDynamicIconInfoWhenOta(); + // process theme and dynamic icon + bool checkThemeDynamicIcon = false; + CheckOtaFlag(OTAFlag::PROCESS_THEME_AND_DYNAMIC_ICON, checkThemeDynamicIcon); + if (checkThemeDynamicIcon) { + LOG_I(BMS_TAG_DEFAULT, "No need to process theme and dynamic due to has checked"); + return; + } + LOG_I(BMS_TAG_DEFAULT, "process theme and dynamic start"); + std::set bundleNames; + for (const auto &item : needInstallMap) { + bundleNames.insert(item.first); + } + if (!BundleResourceHelper::ProcessThemeAndDynamicIconWhenOta(bundleNames)) { + LOG_E(BMS_TAG_DEFAULT, "process theme and dynamic failed"); + return; + } + UpdateOtaFlag(OTAFlag::PROCESS_THEME_AND_DYNAMIC_ICON); + LOG_I(BMS_TAG_DEFAULT, "process theme and dynamic end"); +} + void BMSEventHandler::InnerProcessBootCheckOnDemandBundle() { for (const auto &preScanInfo : onDemandInstallList_) { diff --git a/services/bundlemgr/src/bundle_multiuser_installer.cpp b/services/bundlemgr/src/bundle_multiuser_installer.cpp index fd7aa2e99d..e70af3e6a3 100644 --- a/services/bundlemgr/src/bundle_multiuser_installer.cpp +++ b/services/bundlemgr/src/bundle_multiuser_installer.cpp @@ -195,7 +195,8 @@ ErrCode BundleMultiUserInstaller::ProcessBundleInstall(const std::string &bundle if (!dataMgr_->AddInnerBundleUserInfo(bundleName, newUserInfo)) { return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; } - + // add new user bundle info + BundleResourceHelper::AddResourceInfoByBundleName(bundleName, userId, ADD_RESOURCE_TYPE::CREATE_USER); CreateEl5Dir(info, userId, uid); CreateDataGroupDir(bundleName, userId); diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_callback.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_callback.cpp index 5cffa1e63d..0697467e8b 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_callback.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_callback.cpp @@ -29,25 +29,7 @@ namespace OHOS { namespace AppExecFwk { bool BundleResourceCallback::OnUserIdSwitched(const int32_t oldUserId, const int32_t userId, const uint32_t type) { - APP_LOGI("start, oldUserId:%{public}d to newUserId:%{public}d", oldUserId, userId); - if (userId != Constants::START_USERID) { - int32_t currentUserId = AccountHelper::GetCurrentActiveUserId(); - if (currentUserId != userId) { - APP_LOGE("userId:%{public}d current:%{public}d not same", userId, currentUserId); - return false; - } - } - auto manager = DelayedSingleton::GetInstance(); - if (manager == nullptr) { - APP_LOGE("switch userId %{public}d failed", userId); - return false; - } - SetUserId(userId); - if (!manager->AddAllResourceInfo(userId, type, oldUserId)) { - APP_LOGE("AddAllResourceInfo userId : %{public}d failed", userId); - return false; - } - APP_LOGI("end, oldUserId:%{public}d to newUserId:%{public}d", oldUserId, userId); + APP_LOGI("start, oldUserId:%{public}d to newUserId:%{public}d no need to process", oldUserId, userId); return true; } @@ -161,11 +143,7 @@ bool BundleResourceCallback::OnOverlayStatusChanged( manager->GetTargetBundleName(bundleName, targetBundleName); APP_LOGI("bundleName:%{public}s, targetBundleName:%{public}s overlay changed", bundleName.c_str(), targetBundleName.c_str()); - if (!manager->DeleteResourceInfo(targetBundleName)) { - APP_LOGW("delete resource failed %{public}s", targetBundleName.c_str()); - } - - if (!manager->AddResourceInfoByBundleName(targetBundleName, userId)) { + if (!manager->AddResourceInfoByBundleNameWhenUpdate(targetBundleName, userId)) { APP_LOGE("add resource failed %{public}s", targetBundleName.c_str()); return false; } @@ -223,7 +201,7 @@ void BundleResourceCallback::SetUserId(const int32_t userId) APP_LOGE("open user file failed, errno:%{public}d", errno); return; } - jsonBuf[BundleResourceConstants::USER_ID] = userId; + jsonBuf[BundleResourceConstants::USER] = userId; out << jsonBuf.dump(); out.close(); } diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_drawable.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_drawable.cpp index fa59359c59..fe7d2079ce 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_drawable.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_drawable.cpp @@ -25,26 +25,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { -// bundle name -constexpr const char* COM_OHOS_CONTACTS = "com.ohos.contacts"; -constexpr const char* IS_SUPPORT_TELEPHONY_VOICE = "const.telephony.voice.capable"; -constexpr int8_t THRESHOLD_VAL_LEN = 10; - -bool IsSupportTelephonyVoice() -{ - char retValue[THRESHOLD_VAL_LEN] = {"true"}; - int32_t ret = GetParameter(IS_SUPPORT_TELEPHONY_VOICE, "true", retValue, THRESHOLD_VAL_LEN); - if (ret <= 0) { - LOG_W(BMS_TAG_DEFAULT, "GetParameter const.telephony.voice.capable failed"); - return true; - } - if (std::strcmp(retValue, "false") == 0) { - return false; - } - return true; -} -} bool BundleResourceDrawable::GetIconResourceByTheme( const uint32_t iconId, @@ -57,11 +37,6 @@ bool BundleResourceDrawable::GetIconResourceByTheme( LOG_E(BMS_TAG_DEFAULT, "resourceManager is nullptr"); return false; } - if ((resourceInfo.GetKey() == COM_OHOS_CONTACTS) && IsSupportTelephonyVoice()) { - // contacts app.json use hap resource - LOG_I(BMS_TAG_DEFAULT, "bundleName:%{public}s parse no theme icon", resourceInfo.bundleName_.c_str()); - return GetIconResourceByHap(iconId, density, resourceManager, resourceInfo); - } BundleResourceImageInfo info; OHOS::Ace::Napi::DrawableDescriptor::DrawableType drawableType; std::string themeMask = resourceManager->GetThemeMask(); diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_event_subscriber.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_event_subscriber.cpp index 95a4ca64b9..fc9da47d0c 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_event_subscriber.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_event_subscriber.cpp @@ -81,7 +81,7 @@ bool BundleResourceEventSubscriber::CheckUserSwitchWhenReboot(const int32_t user const auto &jsonBufEnd = jsonBuf.end(); int32_t parseResult = ERR_OK; int32_t lastUserId = 0; - GetValueIfFindKey(jsonBuf, jsonBufEnd, BundleResourceConstants::USER_ID, lastUserId, + GetValueIfFindKey(jsonBuf, jsonBufEnd, BundleResourceConstants::USER, lastUserId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY); if ((parseResult == ERR_OK) && (lastUserId != userId)) { // The user before reboot and the current user do not match, need add resources. diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_icon_rdb.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_icon_rdb.cpp new file mode 100644 index 0000000000..982a4cdde3 --- /dev/null +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_icon_rdb.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_resource_icon_rdb.h" + +#include "app_log_wrapper.h" +#include "bundle_resource_constants.h" +#include "bundle_util.h" +#include "hitrace_meter.h" +#include "scope_guard.h" +#include "string_ex.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr const char* SYSTEM_RESOURCES_APP = "ohos.global.systemres"; +constexpr int32_t INDEX_NAME = 0; +constexpr int32_t INDEX_USERID = 1; +constexpr int32_t INDEX_ICON_TYPE = 2; +constexpr int32_t INDEX_ICON = 3; +constexpr int32_t INDEX_FOREGROUND = 4; +constexpr int32_t INDEX_BACKGROUND = 5; +} + +BundleResourceIconRdb::BundleResourceIconRdb() +{ + APP_LOGI_NOFUNC("BundleResourceRdb create"); + BmsRdbConfig bmsRdbConfig; + bmsRdbConfig.dbName = BundleResourceConstants::BUNDLE_RESOURCE_RDB_NAME; + bmsRdbConfig.dbPath = BundleResourceConstants::BUNDLE_RESOURCE_RDB_PATH; + bmsRdbConfig.tableName = BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME; + bmsRdbConfig.createTableSql = std::string( + "CREATE TABLE IF NOT EXISTS " + + std::string(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME) + + "(NAME TEXT NOT NULL, USER_ID INTEGER, ICON_TYPE INTEGER, ICON TEXT, " + + "FOREGROUND BLOB, BACKGROUND BLOB, PRIMARY KEY (NAME, USER_ID, ICON_TYPE));"); + rdbDataManager_ = std::make_shared(bmsRdbConfig); + rdbDataManager_->CreateTable(); +} + +BundleResourceIconRdb::~BundleResourceIconRdb() +{ +} + +bool BundleResourceIconRdb::AddResourceIconInfo(const int32_t userId, const IconResourceType type, + const ResourceInfo &resourceInfo) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (resourceInfo.bundleName_.empty()) { + APP_LOGE("failed, bundleName is empty"); + return false; + } + APP_LOGD("insert resource key:%{public}s", resourceInfo.GetKey().c_str()); + NativeRdb::ValuesBucket valuesBucket; + valuesBucket.PutString(BundleResourceConstants::NAME, resourceInfo.GetKey()); + valuesBucket.PutInt(BundleResourceConstants::USER_ID, userId); + valuesBucket.PutInt(BundleResourceConstants::ICON_TYPE, static_cast(type)); + valuesBucket.PutString(BundleResourceConstants::ICON, resourceInfo.icon_); + // used for layered icons + valuesBucket.PutBlob(BundleResourceConstants::FOREGROUND, resourceInfo.foreground_); + valuesBucket.PutBlob(BundleResourceConstants::BACKGROUND, resourceInfo.background_); + APP_LOGD("key:%{public}s foreground: %{public}zu, background: %{public}zu", resourceInfo.GetKey().c_str(), + resourceInfo.foreground_.size(), resourceInfo.background_.size()); + + return rdbDataManager_->InsertData(valuesBucket); +} + +bool BundleResourceIconRdb::AddResourceIconInfos(const int32_t userId, const IconResourceType type, + const std::vector &resourceInfos) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (resourceInfos.empty()) { + APP_LOGE("failed, resourceInfos is empty"); + return false; + } + if (resourceInfos.size() == 1) { + return AddResourceIconInfo(userId, type, resourceInfos[0]); + } + bool ret = true; + std::vector valuesBuckets; + for (const auto &info : resourceInfos) { + if (info.bundleName_.empty()) { + APP_LOGE("failed, bundleName is empty"); + ret = false; + continue; + } + NativeRdb::ValuesBucket valuesBucket; + valuesBucket.PutString(BundleResourceConstants::NAME, info.GetKey()); + valuesBucket.PutInt(BundleResourceConstants::USER_ID, userId); + valuesBucket.PutInt(BundleResourceConstants::ICON_TYPE, static_cast(type)); + valuesBucket.PutString(BundleResourceConstants::ICON, info.icon_); + // used for layered icons + valuesBucket.PutBlob(BundleResourceConstants::FOREGROUND, info.foreground_); + valuesBucket.PutBlob(BundleResourceConstants::BACKGROUND, info.background_); + APP_LOGD("key:%{public}s foreground: %{public}zu, background: %{public}zu", info.GetKey().c_str(), + info.foreground_.size(), info.background_.size()); + valuesBuckets.emplace_back(valuesBucket); + } + int64_t insertNum = 0; + bool insertRet = rdbDataManager_->BatchInsert(insertNum, valuesBuckets); + if (!insertRet) { + APP_LOGE("BatchInsert failed"); + return false; + } + if (valuesBuckets.size() != static_cast(insertNum)) { + APP_LOGE("BatchInsert size not expected"); + return false; + } + return ret; +} + +bool BundleResourceIconRdb::DeleteResourceIconInfo(const std::string &bundleName, + const int32_t userId, const int32_t appIndex, const IconResourceType type) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (bundleName.empty()) { + APP_LOGE("failed, bundleName is empty"); + return false; + } + APP_LOGD("need delete resource info, -n %{public}s, -u %{public}d, -i %{public}d, -t %{public}d", + bundleName.c_str(), userId, appIndex, static_cast(type)); + std::string key = bundleName; + if (appIndex > 0) { + key = std::to_string(appIndex) + BundleResourceConstants::UNDER_LINE + bundleName; + } + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + // need delete both bundle resource and launcher ability resource + absRdbPredicates.BeginsWith(BundleResourceConstants::NAME, key); + absRdbPredicates.EqualTo(BundleResourceConstants::USER_ID, userId); + if (type != IconResourceType::UNKNOWN) { + absRdbPredicates.EqualTo(BundleResourceConstants::ICON_TYPE, static_cast(type)); + } + if (!rdbDataManager_->DeleteData(absRdbPredicates)) { + APP_LOGW("delete key:%{public}s failed", key.c_str()); + return false; + } + return true; +} + +bool BundleResourceIconRdb::DeleteResourceIconInfos(const std::string &bundleName, + const int32_t userId, const IconResourceType type) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (bundleName.empty()) { + APP_LOGE("failed, bundleName is empty"); + return false; + } + APP_LOGD("need delete resource info, -n %{public}s, -u %{public}d, -t %{public}d", + bundleName.c_str(), userId, static_cast(type)); + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + // need delete both bundle resource and launcher ability resource + absRdbPredicates.Contains(BundleResourceConstants::NAME, bundleName); + absRdbPredicates.EqualTo(BundleResourceConstants::USER_ID, userId); + if (type != IconResourceType::UNKNOWN) { + absRdbPredicates.EqualTo(BundleResourceConstants::ICON_TYPE, static_cast(type)); + } + if (!rdbDataManager_->DeleteData(absRdbPredicates)) { + APP_LOGW("delete bundleName:%{public}s failed", bundleName.c_str()); + return false; + } + return true; +} + +bool BundleResourceIconRdb::DeleteResourceIconInfos(const std::string &bundleName, const IconResourceType type) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (bundleName.empty()) { + APP_LOGE("failed, bundleName is empty"); + return false; + } + APP_LOGD("need delete resource info, -n %{public}s, -t %{public}d", + bundleName.c_str(), static_cast(type)); + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + // need delete both bundle resource and launcher ability resource + absRdbPredicates.Contains(BundleResourceConstants::NAME, bundleName); + if (type != IconResourceType::UNKNOWN) { + absRdbPredicates.EqualTo(BundleResourceConstants::ICON_TYPE, static_cast(type)); + } + if (!rdbDataManager_->DeleteData(absRdbPredicates)) { + APP_LOGW("delete bundleName:%{public}s failed", bundleName.c_str()); + return false; + } + return true; +} + +bool BundleResourceIconRdb::GetAllResourceIconName(const int32_t userId, std::set &resourceNames, + const IconResourceType type) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + absRdbPredicates.EqualTo(BundleResourceConstants::USER_ID, userId); + if (type != IconResourceType::UNKNOWN) { + absRdbPredicates.EqualTo(BundleResourceConstants::ICON_TYPE, static_cast(type)); + } + auto absSharedResultSet = rdbDataManager_->QueryByStep(absRdbPredicates); + if (absSharedResultSet == nullptr) { + APP_LOGE("QueryByStep failed"); + return false; + } + ScopeGuard stateGuard([absSharedResultSet] { absSharedResultSet->Close(); }); + + auto ret = absSharedResultSet->GoToFirstRow(); + if (ret != NativeRdb::E_OK) { + APP_LOGE("GoToFirstRow failed, ret %{public}d", ret); + return false; + } + do { + std::string name; + std::string resourceName; + ret = absSharedResultSet->GetString(BundleResourceConstants::INDEX_NAME, name); + if (ret != NativeRdb::E_OK) { + APP_LOGE("GetString name failed, ret %{public}d", ret); + return false; + } + ParseNameToResourceName(name, resourceName); + resourceNames.insert(resourceName); + } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); + APP_LOGI_NOFUNC("end"); + return true; +} + +void BundleResourceIconRdb::ParseNameToResourceName(const std::string &name, std::string &resourceName) +{ + resourceName = name; + // clone bundle no need to add + auto pos = name.find_first_of(BundleResourceConstants::UNDER_LINE); + if (pos != std::string::npos) { + int32_t appIndex = 0; + if (!OHOS::StrToInt(name.substr(0, pos), appIndex)) { + return; + } + resourceName = name.substr(pos + 1); + } +} + +bool BundleResourceIconRdb::GetResourceIconInfos(const std::string &bundleName, + const int32_t userId, const int32_t appIndex, const uint32_t resourceFlag, + std::vector &launcherAbilityResourceInfos, + const IconResourceType type) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + APP_LOGI_NOFUNC("icon rdb get resource icon start -n %{public}s -i %{public}d", bundleName.c_str(), appIndex); + if (bundleName.empty()) { + APP_LOGE("bundleName is empty"); + return false; + } + ResourceInfo resourceInfo; + resourceInfo.bundleName_ = bundleName; + resourceInfo.appIndex_ = appIndex; + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + absRdbPredicates.BeginsWith(BundleResourceConstants::NAME, resourceInfo.GetKey()); + absRdbPredicates.EqualTo(BundleResourceConstants::USER_ID, userId); + if (type != IconResourceType::UNKNOWN) { + absRdbPredicates.EqualTo(BundleResourceConstants::ICON_TYPE, static_cast(type)); + } + + auto absSharedResultSet = rdbDataManager_->QueryByStep(absRdbPredicates); + if (absSharedResultSet == nullptr) { + APP_LOGE("QueryByStep failed bundleName %{public}s failed", bundleName.c_str()); + return false; + } + ScopeGuard stateGuard([absSharedResultSet] { absSharedResultSet->Close(); }); + auto ret = absSharedResultSet->GoToFirstRow(); + if (ret != NativeRdb::E_OK) { + APP_LOGD("bundleName %{public}s GoToFirstRow failed, ret %{public}d", bundleName.c_str(), ret); + return false; + } + + do { + LauncherAbilityResourceInfo resourceInfo; + IconResourceType type; + if (ConvertToLauncherAbilityResourceInfo(absSharedResultSet, resourceFlag, resourceInfo, type)) { + InnerProcessResourceIconInfos(resourceInfo, type, userId, launcherAbilityResourceInfos); + } + } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); + + APP_LOGI_NOFUNC("icon rdb get resource icon end -n %{public}s -i %{public}d", bundleName.c_str(), appIndex); + return !launcherAbilityResourceInfos.empty(); +} + +bool BundleResourceIconRdb::GetAllResourceIconInfo(const int32_t userId, const uint32_t resourceFlag, + std::vector &launcherAbilityResourceInfos) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + APP_LOGI("start get all launcher resource"); + NativeRdb::AbsRdbPredicates absRdbPredicates(BundleResourceConstants::BUNDLE_ICON_RESOURCE_RDB_TABLE_NAME); + absRdbPredicates.EqualTo(BundleResourceConstants::USER_ID, userId); + auto absSharedResultSet = rdbDataManager_->QueryByStep(absRdbPredicates); + if (absSharedResultSet == nullptr) { + APP_LOGE("absSharedResultSet nullptr"); + return false; + } + + ScopeGuard stateGuard([absSharedResultSet] { absSharedResultSet->Close(); }); + auto ret = absSharedResultSet->GoToFirstRow(); + if (ret != NativeRdb::E_OK) { + APP_LOGE("GoToFirstRow failed, ret %{public}d", ret); + return false; + } + + do { + LauncherAbilityResourceInfo resourceInfo; + IconResourceType type; + if (ConvertToLauncherAbilityResourceInfo(absSharedResultSet, resourceFlag, resourceInfo, type)) { + InnerProcessResourceIconInfos(resourceInfo, type, userId, launcherAbilityResourceInfos); + } + } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); + + APP_LOGI_NOFUNC("end get all launcher resource"); + return !launcherAbilityResourceInfos.empty(); +} + +bool BundleResourceIconRdb::ConvertToLauncherAbilityResourceInfo( + const std::shared_ptr &absSharedResultSet, + const uint32_t resourceFlag, + LauncherAbilityResourceInfo &launcherAbilityResourceInfo, + IconResourceType &iconType) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (absSharedResultSet == nullptr) { + APP_LOGE("absSharedResultSet is nullptr"); + return false; + } + std::string key; + auto ret = absSharedResultSet->GetString(INDEX_NAME, key); + CHECK_RDB_RESULT_RETURN_IF_FAIL(ret, "GetString name failed, ret: %{public}d"); + ParseKey(key, launcherAbilityResourceInfo); + + bool getIcon = ((resourceFlag & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON)) == + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON)) || + ((resourceFlag & static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL)) == + static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL)); + if (getIcon) { + ret = absSharedResultSet->GetString(INDEX_ICON, launcherAbilityResourceInfo.icon); + CHECK_RDB_RESULT_RETURN_IF_FAIL(ret, "GetString label icon, ret: %{public}d"); + } + + bool getDrawable = (resourceFlag & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR)) + == static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR); + if (getDrawable) { + ret = absSharedResultSet->GetBlob(INDEX_FOREGROUND, launcherAbilityResourceInfo.foreground); + CHECK_RDB_RESULT_RETURN_IF_FAIL(ret, "GetBlob foreground, ret: %{public}d"); + + ret = absSharedResultSet->GetBlob(INDEX_BACKGROUND, launcherAbilityResourceInfo.background); + CHECK_RDB_RESULT_RETURN_IF_FAIL(ret, "GetBlob background, ret: %{public}d"); + } + int32_t type = 0; + ret = absSharedResultSet->GetInt(INDEX_ICON_TYPE, type); + CHECK_RDB_RESULT_RETURN_IF_FAIL(ret, "GetBlob background, ret: %{public}d"); + iconType = static_cast(type); + + return true; +} + +void BundleResourceIconRdb::ParseKey(const std::string &key, + LauncherAbilityResourceInfo &launcherAbilityResourceInfo) +{ + ResourceInfo info; + info.ParseKey(key); + launcherAbilityResourceInfo.bundleName = info.bundleName_; + launcherAbilityResourceInfo.moduleName = info.moduleName_; + launcherAbilityResourceInfo.abilityName = info.abilityName_; + launcherAbilityResourceInfo.appIndex = info.appIndex_; +} + +bool BundleResourceIconRdb::GetIsOnlineTheme(const int32_t userId) +{ + std::shared_lock lock(isOnlineThemeMutex_); + auto iter = isOnlineThemeMap_.find(userId); + if (iter == isOnlineThemeMap_.end()) { + return false; + } + return iter->second; +} + +void BundleResourceIconRdb::SetIsOnlineTheme(const int32_t userId, bool isOnlineTheme) +{ + std::unique_lock lock(isOnlineThemeMutex_); + isOnlineThemeMap_[userId] = isOnlineTheme; +} + +void BundleResourceIconRdb::InnerProcessResourceIconInfos(const LauncherAbilityResourceInfo &resourceInfo, + const IconResourceType type, const int32_t userId, + std::vector &launcherAbilityResourceInfos) +{ + if (!resourceInfo.abilityName.empty() && GetIsOnlineTheme(userId)) { + launcherAbilityResourceInfos.push_back(resourceInfo); + return; + } + auto iter = std::find_if(launcherAbilityResourceInfos.begin(), launcherAbilityResourceInfos.end(), + [resourceInfo](const LauncherAbilityResourceInfo info) { + return (resourceInfo.bundleName == info.bundleName) && (resourceInfo.appIndex == info.appIndex); + }); + // not exist + if (iter == launcherAbilityResourceInfos.end()) { + launcherAbilityResourceInfos.push_back(resourceInfo); + return; + } + // if exist, need to process theme or dynamic icon + if (((type == IconResourceType::THEME_ICON) && GetIsOnlineTheme(userId)) || + ((type == IconResourceType::DYNAMIC_ICON) && !GetIsOnlineTheme(userId))) { + for (auto iter = launcherAbilityResourceInfos.begin(); iter != launcherAbilityResourceInfos.end();) { + if ((iter->bundleName == resourceInfo.bundleName) && (iter->appIndex == resourceInfo.appIndex)) { + iter = launcherAbilityResourceInfos.erase(iter); + } else { + ++iter; + } + } + launcherAbilityResourceInfos.push_back(resourceInfo); + } +} +} // AppExecFwk +} // OHOS diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp index 0625344cae..984e2898b2 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp @@ -15,11 +15,14 @@ #include "bundle_resource_manager.h" +#include "account_helper.h" #include "bms_extension_client.h" #include "bundle_common_event_mgr.h" +#include "bundle_permission_mgr.h" #include "bundle_util.h" #include "bundle_resource_parser.h" #include "bundle_resource_process.h" +#include "bundle_resource_theme_process.h" #include "bundle_mgr_service.h" #include "directory_ex.h" #include "event_report.h" @@ -35,14 +38,10 @@ constexpr const char* THREAD_POOL_NAME = "BundleResourceThreadPool"; constexpr int8_t CHECK_INTERVAL = 30; // 30ms constexpr const char* FOUNDATION_PROCESS_NAME = "foundation"; constexpr int8_t SCENE_ID_UPDATE_RESOURCE = 1 << 1; -constexpr const char* SYSTEM_THEME_PATH = "/data/service/el1/public/themes/"; -constexpr const char* THEME_ICONS_A = "/a/app/icons/"; -constexpr const char* THEME_ICONS_B = "/b/app/icons/"; constexpr const char* INNER_UNDER_LINE = "_"; -constexpr const char* THEME_ICONS_A_FLAG = "/a/app/flag"; -constexpr const char* THEME_ICONS_B_FLAG = "/b/app/flag"; constexpr const char* TASK_NAME = "ReleaseResourceTask"; constexpr uint64_t DELAY_TIME_MILLI_SECONDS = 3 * 60 * 1000; // 3mins +constexpr const char* CONTACTS_BUNDLE_NAME = "com.ohos.contacts"; using Want = OHOS::AAFwk::Want; } std::mutex BundleResourceManager::g_sysResMutex; @@ -51,6 +50,7 @@ std::shared_ptr BundleResourceManager::g_resM BundleResourceManager::BundleResourceManager() { bundleResourceRdb_ = std::make_shared(); + bundleResourceIconRdb_ = std::make_shared(); delayedTaskMgr_ = std::make_shared(TASK_NAME, DELAY_TIME_MILLI_SECONDS); } @@ -58,67 +58,6 @@ BundleResourceManager::~BundleResourceManager() { } -bool BundleResourceManager::AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId) -{ - APP_LOGD("start, bundleName:%{public}s", bundleName.c_str()); - std::vector resourceInfos; - if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos)) { - APP_LOGE("bundleName %{public}s GetResourceInfoByBundleName failed", bundleName.c_str()); - return false; - } - DeleteNotExistResourceInfo(bundleName, 0, resourceInfos); - PrepareSysRes(); - - if (!AddResourceInfos(userId, resourceInfos)) { - APP_LOGE("error, bundleName:%{public}s", bundleName.c_str()); - return false; - } - if (!resourceInfos.empty() && !resourceInfos[0].appIndexes_.empty()) { - for (const int32_t appIndex : resourceInfos[0].appIndexes_) { - DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); - // trigger parse dynamic icon - if (!AddCloneBundleResourceInfo(resourceInfos[0].bundleName_, appIndex, userId)) { - APP_LOGW("-n %{public}s -i %{public}d add clone resource failed", bundleName.c_str(), appIndex); - } - } - } - APP_LOGD("success, bundleName:%{public}s", bundleName.c_str()); - return true; -} - -bool BundleResourceManager::AddResourceInfoByBundleName( - const std::string &bundleName, const int32_t userId, const int32_t appIndex) -{ - APP_LOGD("start bundleName%{public}s userId %{public}d appIndex %{public}d", bundleName.c_str(), userId, appIndex); - std::vector resourceInfos; - if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos, appIndex) || - resourceInfos.empty()) { - APP_LOGE("get resource bundleName %{public}s userId %{public}d appIndex %{public}d failed", - bundleName.c_str(), userId, appIndex); - return false; - } - DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); - PrepareSysRes(); - // need to parse label and icon - BundleResourceParser parser; - if (!parser.ParseResourceInfos(userId, resourceInfos)) { - APP_LOGW_NOFUNC("key:%{public}s Parse failed, need to modify label and icon", - resourceInfos[0].GetKey().c_str()); - ProcessResourceInfoWhenParseFailed(resourceInfos[0]); - } - if (appIndex != 0) { - for (auto &info : resourceInfos) { - info.label_ = info.label_.empty() ? info.label_ : (info.label_ + std::to_string(appIndex)); - info.appIndex_ = appIndex; - } - // process clone bundle - if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { - APP_LOGW_NOFUNC("key:%{public}s Parse clone failed may loss badge", resourceInfos[0].GetKey().c_str()); - } - } - return bundleResourceRdb_->AddResourceInfos(resourceInfos); -} - void BundleResourceManager::DeleteNotExistResourceInfo( const std::string &bundleName, const int32_t appIndex, const std::vector &resourceInfos) { @@ -138,136 +77,11 @@ void BundleResourceManager::DeleteNotExistResourceInfo( } } -bool BundleResourceManager::AddResourceInfoByAbility(const std::string &bundleName, const std::string &moduleName, - const std::string &abilityName, const int32_t userId) -{ - APP_LOGD("start, bundleName:%{public}s", bundleName.c_str()); - ResourceInfo resourceInfo; - if (!BundleResourceProcess::GetLauncherResourceInfoByAbilityName(bundleName, moduleName, abilityName, - userId, resourceInfo)) { - APP_LOGE("bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s failed", - bundleName.c_str(), moduleName.c_str(), abilityName.c_str()); - return false; - } - PrepareSysRes(); - if (!AddResourceInfo(userId, resourceInfo)) { - APP_LOGE("error, bundleName %{public}s, moduleName %{public}s, abilityName %{public}s failed", - bundleName.c_str(), moduleName.c_str(), abilityName.c_str()); - return false; - } - APP_LOGD("success, bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s failed", - bundleName.c_str(), moduleName.c_str(), abilityName.c_str()); - return true; -} - -bool BundleResourceManager::AddAllResourceInfo(const int32_t userId, const uint32_t type, const int32_t oldUserId) -{ - EventReport::SendCpuSceneEvent(FOUNDATION_PROCESS_NAME, SCENE_ID_UPDATE_RESOURCE); - ++currentTaskNum_; - uint32_t tempTaskNum = currentTaskNum_; - std::lock_guard guard(mutex_); - APP_LOGI("bundle resource hold mutex"); - std::map> resourceInfosMap; - if (!BundleResourceProcess::GetAllResourceInfo(userId, resourceInfosMap)) { - APP_LOGE("GetAllResourceInfo failed userId %{public}d", userId); - return false; - } - if (tempTaskNum != currentTaskNum_) { - APP_LOGI("need stop current task, new first"); - isInterrupted_ = true; - return false; - } - PrepareSysRes(); - if (!AddResourceInfosByMap(resourceInfosMap, tempTaskNum, type, userId, oldUserId)) { - APP_LOGE("add all resource info failed, userId:%{public}d", userId); - return false; - } - // process clone bundle resource info - for (const auto &item : resourceInfosMap) { - if (!item.second.empty() && !item.second[0].appIndexes_.empty()) { - APP_LOGI("start process bundle:%{public}s clone resource info", item.first.c_str()); - for (const int32_t appIndex : item.second[0].appIndexes_) { - UpdateCloneBundleResourceInfo(item.first, userId, appIndex, type); - } - } - } - SendBundleResourcesChangedEvent(userId, type); - isInterrupted_ = false; - std::string systemState; - if (bundleResourceRdb_->GetCurrentSystemState(systemState)) { - APP_LOGI_NOFUNC("current resource rdb system state:%{public}s", systemState.c_str()); - } - APP_LOGI_NOFUNC("add all resource end"); - return true; -} - bool BundleResourceManager::DeleteAllResourceInfo() { return bundleResourceRdb_->DeleteAllResourceInfo(); } -bool BundleResourceManager::AddResourceInfo(const int32_t userId, ResourceInfo &resourceInfo) -{ - // need to parse label and icon - BundleResourceParser parser; - if (!parser.ParseResourceInfo(userId, resourceInfo)) { - APP_LOGW("key %{public}s ParseResourceInfo failed", resourceInfo.GetKey().c_str()); - BundleResourceInfo bundleResourceInfo; - if (GetBundleResourceInfo(resourceInfo.bundleName_, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL), bundleResourceInfo)) { - // default ability label and icon - resourceInfo.label_ = resourceInfo.label_.empty() ? bundleResourceInfo.label : resourceInfo.label_; - resourceInfo.icon_ = resourceInfo.icon_.empty() ? bundleResourceInfo.icon : resourceInfo.icon_; - resourceInfo.foreground_ = resourceInfo.foreground_.empty() ? bundleResourceInfo.foreground : - resourceInfo.foreground_; - resourceInfo.background_ = resourceInfo.background_.empty() ? bundleResourceInfo.background : - resourceInfo.background_; - } - ProcessResourceInfoWhenParseFailed(resourceInfo); - } - return bundleResourceRdb_->AddResourceInfo(resourceInfo); -} - -bool BundleResourceManager::AddResourceInfos(const int32_t userId, std::vector &resourceInfos) -{ - if (resourceInfos.empty()) { - APP_LOGE("resourceInfos is empty"); - return false; - } - // need to parse label and icon - BundleResourceParser parser; - if (!parser.ParseResourceInfos(userId, resourceInfos)) { - APP_LOGW_NOFUNC("key:%{public}s Parse failed, need to modify label and icon", - resourceInfos[0].GetKey().c_str()); - ProcessResourceInfoWhenParseFailed(resourceInfos[0]); - } - return bundleResourceRdb_->AddResourceInfos(resourceInfos); -} - -void BundleResourceManager::InnerProcessResourceInfoByResourceUpdateType( - std::map> &resourceInfosMap, - const uint32_t type, const int32_t userId, const int32_t oldUserId) -{ - APP_LOGI("current resource update, code:%{public}u", type); - switch (type) { - case static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE) : { - InnerProcessResourceInfoBySystemLanguageChanged(resourceInfosMap); - break; - } - case static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE) : { - InnerProcessResourceInfoBySystemThemeChanged(resourceInfosMap, userId); - break; - } - case static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE) : { - InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, userId, oldUserId); - break; - } - default: { - break; - } - } -} - void BundleResourceManager::InnerProcessResourceInfoBySystemLanguageChanged( std::map> &resourceInfosMap) { @@ -278,93 +92,6 @@ void BundleResourceManager::InnerProcessResourceInfoBySystemLanguageChanged( } } -void BundleResourceManager::InnerProcessResourceInfoBySystemThemeChanged( - std::map> &resourceInfosMap, - const int32_t userId) -{ - // There are two scenarios need to add all resource: - // 1. The icons dir is empty. - // 2. Previous theme change is interrupted. - if (!CheckAllAddResourceInfo(userId) && !isInterrupted_) { - FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, userId); - } - // process labelNeedParse_ - for (auto iter = resourceInfosMap.begin(); iter != resourceInfosMap.end(); ++iter) { - ProcessResourceInfoNoNeedToParseOtherIcon(iter->second); - } -} - -void BundleResourceManager::FilterResourceInfoWhenSystemThemeChanged( - std::map> &resourceInfosMap, - const int32_t userId) -{ - bool isThemeFlagExistA = BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + - THEME_ICONS_A_FLAG); - // judge whether the bundle theme exists - for (auto iter = resourceInfosMap.begin(); iter != resourceInfosMap.end();) { - bool isThemeExistInA = BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + - THEME_ICONS_A + iter->first); - bool isThemeExistInB = BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + - THEME_ICONS_B + iter->first); - if (!isThemeExistInA && !isThemeExistInB) { - iter = resourceInfosMap.erase(iter); - continue; - } - if ((isThemeFlagExistA && isThemeExistInA) || (!isThemeFlagExistA && isThemeExistInB)) { - for (auto &resource : iter->second) { - resource.hasThemeIcon_ = true; - } - } - ++iter; - } -} - -bool BundleResourceManager::CheckAllAddResourceInfo(const int32_t userId) -{ - if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A_FLAG) && - (!BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B) || - OHOS::IsEmptyFolder(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B))) { - return true; - } - if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B_FLAG) && - (!BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A) || - OHOS::IsEmptyFolder(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A))) { - return true; - } - return false; -} - -void BundleResourceManager::InnerProcessResourceInfoByUserIdChanged( - std::map> &resourceInfosMap, - const int32_t userId, const int32_t oldUserId) -{ - APP_LOGI("start process switch oldUserId:%{public}d to userId:%{public}d", oldUserId, userId); - for (auto iter = resourceInfosMap.begin(); iter != resourceInfosMap.end();) { - // first, check oldUserId whether exist theme, if exist then need parse again - bool isOldUserExistTheme = InnerProcessWhetherThemeExist(iter->first, oldUserId); - bool isNewUserExistTheme = InnerProcessWhetherThemeExist(iter->first, userId); - if (!isOldUserExistTheme && !isNewUserExistTheme && iter->second[0].appIndexes_.empty()) { - APP_LOGD("bundleName:%{public}s not exist theme", iter->first.c_str()); - // exist dynamic icon - if (!iter->second[0].hasDynamicIcon_) { - iter = resourceInfosMap.erase(iter); - continue; - } - } - APP_LOGI("bundleName:%{public}s oldUser:%{public}d or newUser:%{public}d exist theme", - iter->first.c_str(), oldUserId, userId); - if (isNewUserExistTheme) { - ProcessResourceInfoNoNeedToParseOtherIcon(iter->second); - } else { - for (auto &resource : iter->second) { - resource.labelNeedParse_ = false; - resource.label_ = Constants::EMPTY_STRING; - } - } - ++iter; - } -} - void BundleResourceManager::DeleteNotExistResourceInfo( const std::map> &resourceInfosMap, const std::vector &existResourceNames) @@ -394,79 +121,6 @@ void BundleResourceManager::DeleteNotExistResourceInfo( } } -bool BundleResourceManager::InnerProcessWhetherThemeExist(const std::string &bundleName, const int32_t userId) -{ - if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A_FLAG)) { - return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A + bundleName); - } - return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B + bundleName); -} - -bool BundleResourceManager::AddResourceInfosByMap( - std::map> &resourceInfosMap, - const uint32_t tempTaskNumber, - const uint32_t type, - const int32_t userId, - const int32_t oldUserId) -{ - if (resourceInfosMap.empty()) { - APP_LOGE("resourceInfosMap is empty"); - return false; - } - InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, type, userId, oldUserId); - if (resourceInfosMap.empty()) { - APP_LOGI("resourceInfosMap is empty, no need to parse"); - return true; - } - std::shared_ptr threadPool = std::make_shared(THREAD_POOL_NAME); - threadPool->Start(MAX_TASK_NUMBER); - threadPool->SetMaxTaskNum(MAX_TASK_NUMBER); - - for (const auto &item : resourceInfosMap) { - if (tempTaskNumber != currentTaskNum_) { - APP_LOGI("need stop current task, new first"); - isInterrupted_ = true; - threadPool->Stop(); - return false; - } - std::string bundleName = item.first; - auto task = [userId, bundleName, &resourceInfosMap, this]() { - if (resourceInfosMap.find(bundleName) == resourceInfosMap.end()) { - APP_LOGE("bundleName %{public}s not exist", bundleName.c_str()); - return; - } - std::vector resourceInfos = resourceInfosMap[bundleName]; - BundleResourceParser parser; - parser.ParseResourceInfos(userId, resourceInfos); - bundleResourceRdb_->UpdateResourceForSystemStateChanged(resourceInfos); - }; - threadPool->AddTask(task); - } - while (threadPool->GetCurTaskNum() > 0) { - std::this_thread::sleep_for(std::chrono::milliseconds(CHECK_INTERVAL)); - } - threadPool->Stop(); - APP_LOGI("all task end resource size %{public}zu", resourceInfosMap.size()); - return true; -} - -void BundleResourceManager::ProcessResourceInfo( - const std::vector &resourceInfos, ResourceInfo &resourceInfo) -{ - if (resourceInfo.label_.empty()) { - resourceInfo.label_ = resourceInfo.bundleName_; - } - if (resourceInfo.icon_.empty()) { - if (!resourceInfos.empty() && !resourceInfos[0].icon_.empty()) { - resourceInfo.icon_ = resourceInfos[0].icon_; - resourceInfo.foreground_ = resourceInfos[0].foreground_; - resourceInfo.background_ = resourceInfos[0].background_; - } else { - ProcessResourceInfoWhenParseFailed(resourceInfo); - } - } -} - bool BundleResourceManager::DeleteResourceInfo(const std::string &key) { return bundleResourceRdb_->DeleteResourceInfo(key); @@ -485,6 +139,27 @@ bool BundleResourceManager::GetBundleResourceInfo(const std::string &bundleName, uint32_t resourceFlags = CheckResourceFlags(flags); if (bundleResourceRdb_->GetBundleResourceInfo(bundleName, resourceFlags, bundleResourceInfo, appIndex)) { APP_LOGD("success, bundleName:%{public}s", bundleName.c_str()); + if (IsNeedProcessResourceIconInfo(resourceFlags)) { + int32_t userId = GetUserId(); + std::vector resourceIconInfos; + if (!bundleResourceIconRdb_->GetResourceIconInfos(bundleName, userId, appIndex, resourceFlags, + resourceIconInfos) || resourceIconInfos.empty()) { + return true; + } + if (bundleName == CONTACTS_BUNDLE_NAME) { + BundleResourceThemeProcess::ProcessSpecialBundleResource(resourceIconInfos, bundleResourceInfo); + return true; + } + auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [bundleName, appIndex](const auto resourceIconInfo) { + return ((resourceIconInfo.bundleName == bundleName) && + (resourceIconInfo.appIndex == appIndex)); }); + if (iter != resourceIconInfos.end()) { + bundleResourceInfo.icon = iter->icon; + bundleResourceInfo.foreground = iter->foreground; + bundleResourceInfo.background = iter->background; + } + } return true; } auto bmsExtensionClient = std::make_shared(); @@ -502,27 +177,35 @@ bool BundleResourceManager::GetLauncherAbilityResourceInfo(const std::string &bu { APP_LOGD("start, bundleName:%{public}s", bundleName.c_str()); uint32_t resourceFlags = CheckResourceFlags(flags); - - int32_t requestUserId = BundleUtil::GetUserIdByCallingUid(); - int32_t activeUserId = AccountHelper::GetCurrentActiveUserId(); - if (activeUserId == Constants::INVALID_USERID) { - APP_LOGW("activeUserId is invalid"); - activeUserId = requestUserId; - } - - bool isResourceInfoFetched = false; - if (requestUserId != activeUserId) { - APP_LOGI_NOFUNC("requestUserId %{public}d is not equal to activeUserId %{public}d", - requestUserId, activeUserId); - isResourceInfoFetched = GetResourceInfoForRequestUser(bundleName, requestUserId, - resourceFlags, appIndex, launcherAbilityResourceInfo); - } else { - isResourceInfoFetched = bundleResourceRdb_->GetLauncherAbilityResourceInfo(bundleName, resourceFlags, - launcherAbilityResourceInfo, appIndex); - } - - if (isResourceInfoFetched) { - APP_LOGD("success, bundleName:%{public}s", bundleName.c_str()); + if (bundleResourceRdb_->GetLauncherAbilityResourceInfo(bundleName, resourceFlags, + launcherAbilityResourceInfo, appIndex)) { + if (IsNeedProcessResourceIconInfo(resourceFlags)) { + int32_t userId = GetUserId(); + std::vector resourceIconInfos; + if (!bundleResourceIconRdb_->GetResourceIconInfos(bundleName, userId, 0, resourceFlags, resourceIconInfos) + || resourceIconInfos.empty()) { + return true; + } + for (auto &resource : launcherAbilityResourceInfo) { + auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [resource](const auto resourceIconInfo) { + return ((resource.bundleName == resourceIconInfo.bundleName) && + (resource.moduleName == resourceIconInfo.moduleName) && + (resource.abilityName == resourceIconInfo.abilityName) && + (resource.appIndex == resourceIconInfo.appIndex)); }); + if (iter == resourceIconInfos.end()) { + iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [resource](const auto resourceIconInfo) { + return ((resource.bundleName == resourceIconInfo.bundleName) && + (resource.appIndex == resourceIconInfo.appIndex)); }); + } + if (iter != resourceIconInfos.end()) { + resource.icon = iter->icon; + resource.foreground = iter->foreground; + resource.background = iter->background; + } + } + } return true; } auto bmsExtensionClient = std::make_shared(); @@ -536,96 +219,38 @@ bool BundleResourceManager::GetLauncherAbilityResourceInfo(const std::string &bu return false; } -bool BundleResourceManager::GetResourceInfoForRequestUser( - const std::string &bundleName, - const int32_t userId, - const uint32_t flags, - const int32_t appIndex, - std::vector &launcherAbilityResourceInfos) -{ - std::vector resourceInfos; - if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos, appIndex)) { - APP_LOGE("-n %{public}s -i %{public}d GetResourceInfoByBundleName failed", - bundleName.c_str(), appIndex); - return false; - } - if (resourceInfos.empty()) { - APP_LOGE("resourceInfos is empty"); - return false; - } - BundleResourceParser parser; - if (!parser.ParseResourceInfos(userId, resourceInfos)) { - APP_LOGW_NOFUNC("key:%{public}s Parse failed, need to modify label and icon", - resourceInfos[0].GetKey().c_str()); - ProcessResourceInfoWhenParseFailed(resourceInfos[0]); - } - if (appIndex != 0) { - auto it = std::find(resourceInfos[0].appIndexes_.begin(), resourceInfos[0].appIndexes_.end(), appIndex); - if (it == resourceInfos[0].appIndexes_.end()) { - APP_LOGE("appIndex not exist in resourceInfos"); - return false; - } - if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { - APP_LOGE("-n %{public}s -i %{public}d parse clone resource failed", bundleName.c_str(), appIndex); - } - } - for (auto &resourceInfo : resourceInfos) { - if (resourceInfo.icon_.empty()) { - APP_LOGW("resourceInfo icon is empty"); - resourceInfo.icon_ = resourceInfos[0].icon_; - resourceInfo.foreground_ = resourceInfos[0].foreground_; - resourceInfo.background_ = resourceInfos[0].background_; - } - if (resourceInfo.label_.empty()) { - APP_LOGW("resourceInfo label is empty"); - resourceInfo.label_ = resourceInfos[0].label_; - } - LauncherAbilityResourceInfo launcherAbilityResourceInfo; - if (ConvertLauncherAbilityResourceInfo(resourceInfo, flags, launcherAbilityResourceInfo)) { - launcherAbilityResourceInfos.push_back(launcherAbilityResourceInfo); - } - } - return true; -} - -bool BundleResourceManager::ConvertLauncherAbilityResourceInfo(const ResourceInfo &resourceInfo, const uint32_t flags, - LauncherAbilityResourceInfo &launcherAbilityResourceInfo) -{ - if (resourceInfo.moduleName_.empty() || resourceInfo.abilityName_.empty()) { - APP_LOGW("moduleName or abilityName is empty."); - return false; - } - launcherAbilityResourceInfo.bundleName = resourceInfo.bundleName_; - launcherAbilityResourceInfo.moduleName = resourceInfo.moduleName_; - launcherAbilityResourceInfo.abilityName = resourceInfo.abilityName_; - launcherAbilityResourceInfo.appIndex = resourceInfo.appIndex_; - bool getAll = (flags & static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL)) == - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); - bool getLabel = (flags & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL)) == - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL); - if (getAll || getLabel) { - launcherAbilityResourceInfo.label = resourceInfo.label_; - } - bool getIcon = (flags & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON)) == - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON); - if (getAll || getIcon) { - launcherAbilityResourceInfo.icon = resourceInfo.icon_; - } - bool getDrawable = (flags & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR)) == - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR); - if (getDrawable) { - launcherAbilityResourceInfo.foreground = resourceInfo.foreground_; - launcherAbilityResourceInfo.background = resourceInfo.background_; - } - return true; -} - bool BundleResourceManager::GetAllBundleResourceInfo(const uint32_t flags, std::vector &bundleResourceInfos) { APP_LOGD("start"); uint32_t resourceFlags = CheckResourceFlags(flags); - return bundleResourceRdb_->GetAllBundleResourceInfo(resourceFlags, bundleResourceInfos); + if (bundleResourceRdb_->GetAllBundleResourceInfo(resourceFlags, bundleResourceInfos)) { + if (IsNeedProcessResourceIconInfo(resourceFlags)) { + int32_t userId = GetUserId(); + std::vector resourceIconInfos; + if (!bundleResourceIconRdb_->GetAllResourceIconInfo(userId, resourceFlags, resourceIconInfos) || + resourceIconInfos.empty()) { + return true; + } + for (auto &resource : bundleResourceInfos) { + if (resource.bundleName == CONTACTS_BUNDLE_NAME) { + BundleResourceThemeProcess::ProcessSpecialBundleResource(resourceIconInfos, resource); + continue; + } + auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [resource](const auto resourceIconInfo) { + return ((resource.bundleName == resourceIconInfo.bundleName) && + (resource.appIndex == resourceIconInfo.appIndex)); }); + if (iter != resourceIconInfos.end()) { + resource.icon = iter->icon; + resource.foreground = iter->foreground; + resource.background = iter->background; + } + } + } + return true; + } + return false; } bool BundleResourceManager::GetAllLauncherAbilityResourceInfo(const uint32_t flags, @@ -633,7 +258,37 @@ bool BundleResourceManager::GetAllLauncherAbilityResourceInfo(const uint32_t fla { APP_LOGD("start"); uint32_t resourceFlags = CheckResourceFlags(flags); - return bundleResourceRdb_->GetAllLauncherAbilityResourceInfo(resourceFlags, launcherAbilityResourceInfos); + if (bundleResourceRdb_->GetAllLauncherAbilityResourceInfo(resourceFlags, launcherAbilityResourceInfos)) { + if (IsNeedProcessResourceIconInfo(resourceFlags)) { + int32_t userId = GetUserId(); + std::vector resourceIconInfos; + if (!bundleResourceIconRdb_->GetAllResourceIconInfo(userId, resourceFlags, resourceIconInfos) || + resourceIconInfos.empty()) { + return true; + } + for (auto &resource : launcherAbilityResourceInfos) { + auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [resource](const auto resourceIconInfo) { + return ((resource.bundleName == resourceIconInfo.bundleName) && + (resource.moduleName == resourceIconInfo.moduleName) && + (resource.abilityName == resourceIconInfo.abilityName) && + (resource.appIndex == resourceIconInfo.appIndex)); }); + if (iter == resourceIconInfos.end()) { + iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), + [resource](const auto resourceIconInfo) { + return ((resource.bundleName == resourceIconInfo.bundleName) && + (resource.appIndex == resourceIconInfo.appIndex)); }); + } + if (iter != resourceIconInfos.end()) { + resource.icon = iter->icon; + resource.foreground = iter->foreground; + resource.background = iter->background; + } + } + } + return true; + } + return false; } bool BundleResourceManager::FilterLauncherAbilityResourceInfoWithFlag(const uint32_t flags, @@ -732,15 +387,6 @@ void BundleResourceManager::ProcessResourceInfoWhenParseFailed(ResourceInfo &res } } -bool BundleResourceManager::SaveResourceInfos(std::vector &resourceInfos) -{ - if (resourceInfos.empty()) { - APP_LOGE("resourceInfos is empty"); - return false; - } - return bundleResourceRdb_->AddResourceInfos(resourceInfos); -} - void BundleResourceManager::GetDefaultIcon(ResourceInfo &resourceInfo) { BundleResourceInfo bundleResourceInfo; @@ -769,107 +415,21 @@ void BundleResourceManager::GetTargetBundleName(const std::string &bundleName, s BundleResourceProcess::GetTargetBundleName(bundleName, targetBundleName); } -bool BundleResourceManager::UpdateBundleIcon(const std::string &bundleName, ResourceInfo &resourceInfo) -{ - int32_t appIndex = resourceInfo.appIndex_; - APP_LOGI("bundleName:%{public}s appIndex %{public}d update icon", bundleName.c_str(), appIndex); - if (appIndex == Constants::UNSPECIFIED_USERID) { - resourceInfo.appIndex_ = 0; - } - std::vector resourceInfos; - BundleResourceInfo bundleResourceInfo; - if (!GetBundleResourceInfo(bundleName, - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), bundleResourceInfo)) { - APP_LOGW("bundle %{public}s index %{public}d get resource failed", bundleName.c_str(), resourceInfo.appIndex_); - } else { - BundleResourceConvertToResourceInfo(bundleResourceInfo, resourceInfo); - resourceInfos.emplace_back(resourceInfo); - } - - std::vector launcherAbilityResourceInfos; - if (!GetLauncherAbilityResourceInfo(bundleName, - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), launcherAbilityResourceInfos)) { - APP_LOGW("bundle %{public}s index %{public}d get resource failed", bundleName.c_str(), resourceInfo.appIndex_); - } else { - for (const auto &launcherAbilityResourceInfo : launcherAbilityResourceInfos) { - LauncherAbilityResourceConvertToResourceInfo(launcherAbilityResourceInfo, resourceInfo); - resourceInfos.emplace_back(resourceInfo); - } - } - if (resourceInfos.empty()) { - APP_LOGW("%{public}s no default icon, need build new", bundleName.c_str()); - resourceInfo.bundleName_ = bundleName; - resourceInfo.label_ = bundleName; - resourceInfos.emplace_back(resourceInfo); - } - - APP_LOGI("bundle %{public}s size %{public}zu index %{public}d", bundleName.c_str(), resourceInfos.size(), appIndex); - if (resourceInfo.appIndex_ != 0) { - // need to process base icon and badge icon - BundleResourceParser parser; - if (!parser.ParserCloneResourceInfo(resourceInfo.appIndex_, resourceInfos)) { - APP_LOGW("%{public}s appIndex:%{public}d parse clone resource failed", bundleName.c_str(), appIndex); - } - } - if (!SaveResourceInfos(resourceInfos)) { - APP_LOGE("save %{public}s resource info failed", bundleName.c_str()); - return false; - } - if (appIndex == Constants::UNSPECIFIED_USERID) { - return ProcessUpdateCloneBundleResourceInfo(bundleName); - } - return true; -} - -bool BundleResourceManager::AddCloneBundleResourceInfo( - const std::string &bundleName, const int32_t appIndex, const int32_t userId) +bool BundleResourceManager::GetBundleResourceInfoForCloneBundle(const std::string &bundleName, + const int32_t appIndex, const uint32_t type, std::vector &resourceInfos) { - APP_LOGD("start add clone bundle resource info, bundleName:%{public}s appIndex:%{public}d", - bundleName.c_str(), appIndex); - if (userId != Constants::UNSPECIFIED_USERID) { - return UpdateCloneBundleResourceInfo(bundleName, userId, appIndex, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)); - } - // 1. get main bundle resource info - std::vector resourceInfos; - if (!GetBundleResourceInfoForCloneBundle(bundleName, appIndex, resourceInfos)) { - APP_LOGE("add clone resource failed %{public}s appIndex:%{public}d", - bundleName.c_str(), appIndex); - return false; + uint32_t flags = 0; + if ((type & static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) == + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) { + flags |= static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR) | + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON); } - // 2. need to process base icon and badge icon - // BundleResourceParser - BundleResourceParser parser; - if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { - APP_LOGE("%{public}s appIndex:%{public}d parse clone resource failed", bundleName.c_str(), appIndex); - } - // 3. save clone bundle resource info - if (!bundleResourceRdb_->AddResourceInfos(resourceInfos)) { - APP_LOGE("add resource failed %{public}s appIndex:%{public}d", bundleName.c_str(), appIndex); - return false; + if ((type & static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)) == + static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)) { + flags |= static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL); } - APP_LOGD("end, add clone bundle resource succeed"); - return true; -} - -bool BundleResourceManager::DeleteCloneBundleResourceInfo(const std::string &bundleName, - const int32_t appIndex) -{ - APP_LOGD("start delete clone bundle resource info, bundleName:%{public}s appIndex:%{public}d", - bundleName.c_str(), appIndex); - ResourceInfo info; - info.bundleName_ = bundleName; - info.appIndex_ = appIndex; - return bundleResourceRdb_->DeleteResourceInfo(info.GetKey()); -} - -bool BundleResourceManager::GetBundleResourceInfoForCloneBundle(const std::string &bundleName, - const int32_t appIndex, std::vector &resourceInfos) -{ // 1. get main bundle resource info BundleResourceInfo bundleResourceInfo; - uint32_t flags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR); if (!bundleResourceRdb_->GetBundleResourceInfo(bundleName, flags, bundleResourceInfo)) { APP_LOGE("get resource failed %{public}s appIndex:%{public}d", bundleName.c_str(), appIndex); return false; @@ -904,91 +464,6 @@ bool BundleResourceManager::GetBundleResourceInfoForCloneBundle(const std::strin return true; } -bool BundleResourceManager::UpdateCloneBundleResourceInfo( - const std::string &bundleName, - const int32_t appIndex, - const uint32_t type) -{ - APP_LOGD("start update clone bundle resource info, bundleName:%{public}s appIndex:%{public}d", - bundleName.c_str(), appIndex); - // 1. get main bundle resource info - std::vector resourceInfos; - if (!GetBundleResourceInfoForCloneBundle(bundleName, appIndex, resourceInfos)) { - APP_LOGE("add clone bundle resource failed, bundleName:%{public}s appIndex:%{public}d", - bundleName.c_str(), appIndex); - return false; - } - // 2. need to process base icon and badge icon when userId or theme changed - if (((type & static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) == - static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) || - ((type & static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)) == - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE))) { - BundleResourceParser parser; - if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { - APP_LOGE("bundleName:%{public}s appIndex:%{public}d parse clone resource failed", - bundleName.c_str(), appIndex); - } - } else { - for (auto &resourceInfo : resourceInfos) { - resourceInfo.icon_ = Constants::EMPTY_STRING; - } - } - // 3. save clone bundle resource info - if (!bundleResourceRdb_->UpdateResourceForSystemStateChanged(resourceInfos)) { - APP_LOGE("add resource failed, bundleName:%{public}s appIndex:%{public}d", bundleName.c_str(), appIndex); - return false; - } - APP_LOGD("end, add clone bundle resource succeed"); - return true; -} - -bool BundleResourceManager::UpdateCloneBundleResourceInfo(const std::string &bundleName, const int32_t userId, - const int32_t appIndex, const uint32_t type) -{ - if (appIndex <= 0) { - APP_LOGW("-n %{public}s -i %{public}d invalid", bundleName.c_str(), appIndex); - return false; - } - // check theme - bool isOnlineTheme = false; - if (BundleResourceProcess::CheckThemeType(bundleName, userId, isOnlineTheme) && isOnlineTheme) { - return UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - } - // Need to consider dynamic icons when user switching - if (((type & static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)) != - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE))) { - return UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - } - // check dynamic - std::string mainDynamicIcon = BundleResourceProcess::GetCurDynamicIconModule(bundleName, userId, 0); - std::string dynamicIcon = BundleResourceProcess::GetCurDynamicIconModule(bundleName, userId, appIndex); - if (mainDynamicIcon == dynamicIcon) { - return UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - } else if (!dynamicIcon.empty()) { - // need to parse dynamic icon - ExtendResourceInfo extendResourceInfo; - if (!BundleResourceProcess::GetExtendResourceInfo(bundleName, dynamicIcon, extendResourceInfo)) { - APP_LOGW("-n %{public}s -m %{public}s is not exist", bundleName.c_str(), dynamicIcon.c_str()); - return UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - } - ResourceInfo resourceInfo; - resourceInfo.bundleName_ = bundleName; - resourceInfo.iconId_ = extendResourceInfo.iconId; - resourceInfo.appIndex_ = appIndex; - BundleResourceParser bundleResourceParser; - if (!bundleResourceParser.ParseIconResourceByPath(extendResourceInfo.filePath, - extendResourceInfo.iconId, resourceInfo) || resourceInfo.icon_.empty()) { - APP_LOGW("-n %{public}s -m %{public}s parse resource by path failed", - bundleName.c_str(), dynamicIcon.c_str()); - return UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - } - return UpdateBundleIcon(bundleName, resourceInfo); - } else { - // need to parse hap icon - return AddResourceInfoByBundleName(bundleName, userId, appIndex); - } -} - bool BundleResourceManager::DeleteNotExistResourceInfo() { APP_LOGD("start delete not exist resource"); @@ -1043,45 +518,769 @@ void BundleResourceManager::PrepareSysRes() delayedTaskMgr_->ScheduleDelayedTask(task); } -bool BundleResourceManager::ProcessUpdateCloneBundleResourceInfo(const std::string &bundleName) +bool BundleResourceManager::AddResourceInfoByBundleNameWhenInstall( + const std::string &bundleName, const int32_t userId, const bool isBundleFirstInstall) +{ + // 1. get all resourceInfos by bundleName + std::vector resourceInfos; + if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos, 0, false)) { + APP_LOGE("get resource by -n %{public}s -u %{public}d failed", bundleName.c_str(), userId); + return false; + } + // not first install need delete resource + if (!isBundleFirstInstall) { + DeleteNotExistResourceInfo(bundleName, 0, resourceInfos); + } + PrepareSysRes(); + // 2. parse icon and label resource with hap files + BundleResourceParser parser; + if (!parser.ParseResourceInfosNoTheme(userId, resourceInfos)) { + APP_LOGW_NOFUNC("-n %{public}s Parse failed, need to modify label and icon", bundleName.c_str()); + ProcessResourceInfoWhenParseFailed(resourceInfos[0]); + } + // 3. add original resource information to bundleResourceRdb + bool ret = bundleResourceRdb_->AddResourceInfos(resourceInfos); + if (!ret) { + APP_LOGE("add resource failed when install -n %{public}s -u %{public}d", bundleName.c_str(), userId); + } + // 4. if isBundleFirstInstall false, need to process clone bundle resource + if (!isBundleFirstInstall && !resourceInfos.empty() && !resourceInfos[0].appIndexes_.empty()) { + for (const int32_t appIndex : resourceInfos[0].appIndexes_) { + DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); + // update clone bundle, label and icon + if (!ProcessCloneBundleResourceInfo(resourceInfos[0].bundleName_, appIndex)) { + APP_LOGW("-n %{public}s -i %{public}d add clone resource failed", bundleName.c_str(), appIndex); + } + } + } + // 5. if theme not exist, then return + if (!BundleResourceThemeProcess::IsBundleThemeExist(bundleName, userId)) { + return ret; + } + std::vector themeResourceInfos; + themeResourceInfos.emplace_back(resourceInfos[0]); + // 5. traverse all resourceInfo to determine if ability theme exist + for (const auto &resource : resourceInfos) { + if (BundleResourceThemeProcess::IsAbilityThemeExist(resource.bundleName_, resource.moduleName_, + resource.abilityName_, userId)) { + themeResourceInfos.emplace_back(resource); + } + } + // clear icon data + for (auto resource : themeResourceInfos) { + resource.icon_ = ""; + resource.foreground_.clear(); + resource.background_.clear(); + } + // 6. parse resource with theme + if (!parser.ParseIconResourceInfosWithTheme(userId, themeResourceInfos)) { + APP_LOGE("parse theme resource failed -n %{public}s -u %{public}d", bundleName.c_str(), userId); + return false; + } + // 7. add theme resource to bundleResourceIconRdb + if (!bundleResourceIconRdb_->AddResourceIconInfos(userId, IconResourceType::THEME_ICON, themeResourceInfos)) { + APP_LOGE("add theme resource failed -n %{public}s -u %{public}d", bundleName.c_str(), userId); + return false; + } + return ret; +} + +bool BundleResourceManager::AddResourceInfoByBundleNameWhenUpdate( + const std::string &bundleName, const int32_t userId) +{ + // 1. get all resource + std::vector resourceInfos; + if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos, 0, false) || + resourceInfos.empty()) { + APP_LOGE("get resource bundleName %{public}s userId %{public}d failed", + bundleName.c_str(), userId); + return false; + } + // 2. delete ability resource when update, module or ability may changed + DeleteNotExistResourceInfo(bundleName, 0, resourceInfos); + PrepareSysRes(); + // 3. parse icon and label resource with hap files + BundleResourceParser parser; + if (!parser.ParseResourceInfosNoTheme(userId, resourceInfos)) { + APP_LOGW_NOFUNC("key:%{public}s Parse failed, need to modify label and icon", + resourceInfos[0].GetKey().c_str()); + ProcessResourceInfoWhenParseFailed(resourceInfos[0]); + } + // 4. add original resource information to bundleResourceRdb + bool ret = bundleResourceRdb_->AddResourceInfos(resourceInfos); + if (!ret) { + APP_LOGE("add resource failed when update -n %{public}s -u %{public}d", bundleName.c_str(), userId); + } + /** + * 5. no need to consider theme and dynamic icon when bundle update, + * need to update clone bundle resource (original resource information) in bundleResourceRdb + */ + if (!resourceInfos.empty() && !resourceInfos[0].appIndexes_.empty()) { + for (const int32_t appIndex : resourceInfos[0].appIndexes_) { + DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); + // 6. update clone bundle, label and icon + if (!ProcessCloneBundleResourceInfo(resourceInfos[0].bundleName_, appIndex)) { + APP_LOGW("-n %{public}s -i %{public}d add clone resource failed", bundleName.c_str(), appIndex); + } + } + } + return ret; +} + +bool BundleResourceManager::ProcessCloneBundleResourceInfo( + const std::string &bundleName, const int32_t appIndex) +{ + APP_LOGD("start update clone bundle resource info, bundleName:%{public}s appIndex:%{public}d", + bundleName.c_str(), appIndex); + uint32_t type = static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE) | + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE); + // 1. get main bundle resource info + std::vector resourceInfos; + if (!GetBundleResourceInfoForCloneBundle(bundleName, appIndex, type, resourceInfos)) { + APP_LOGE("add clone bundle resource failed, bundleName:%{public}s appIndex:%{public}d", + bundleName.c_str(), appIndex); + return false; + } + // 2. need to process base icon and badge icon + BundleResourceParser parser; + if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { + APP_LOGE("bundleName:%{public}s appIndex:%{public}d parse clone resource failed", + bundleName.c_str(), appIndex); + } + // 3. add clone bundle resource info + if (!bundleResourceRdb_->AddResourceInfos(resourceInfos)) { + APP_LOGE("add resource failed, bundleName:%{public}s appIndex:%{public}d", bundleName.c_str(), appIndex); + return false; + } + APP_LOGD("end, add clone bundle resource succeed"); + return true; +} + +bool BundleResourceManager::AddResourceInfoByBundleNameWhenCreateUser( + const std::string &bundleName, const int32_t userId) +{ + // 1. if theme not exist, then return + if (!BundleResourceThemeProcess::IsBundleThemeExist(bundleName, userId)) { + return true; + } + // 2. get all resource + std::vector resourceInfos; + if (!BundleResourceProcess::GetResourceInfoByBundleName(bundleName, userId, resourceInfos, 0, false) || + resourceInfos.empty()) { + APP_LOGE("get all resource failed when create user -n %{public}s -u %{public}d", + bundleName.c_str(), userId); + return false; + } + std::vector themeResourceInfos; + themeResourceInfos.emplace_back(resourceInfos[0]); + // 3. traverse all resourceInfo to determine if ability theme exist + for (const auto &resource : resourceInfos) { + if (BundleResourceThemeProcess::IsAbilityThemeExist(resource.bundleName_, resource.moduleName_, + resource.abilityName_, userId)) { + themeResourceInfos.emplace_back(resource); + } + } + // 4. parse theme icon, no need to add hapPath + BundleResourceParser parser; + if (!parser.ParseIconResourceInfosWithTheme(userId, themeResourceInfos)) { + APP_LOGE("parse theme icon failed when create user -n %{public}s -u %{public}d", bundleName.c_str(), userId); + return false; + } + // 5. add theme icon to bundleResourceIconRdb + if (!bundleResourceIconRdb_->AddResourceIconInfos(userId, IconResourceType::THEME_ICON, themeResourceInfos)) { + APP_LOGE("add theme icon failed when create user -n %{public}s -u %{public}d", bundleName.c_str(), userId); + return false; + } + // 6. process bundle clone resource + if (!resourceInfos.empty() && !resourceInfos[0].appIndexes_.empty()) { + for (const int32_t appIndex : resourceInfos[0].appIndexes_) { + // update clone bundle icon resource + (void)ProcessCloneBundleResourceInfoWhenSystemThemeChanged(bundleName, userId, appIndex); + } + } + return true; +} + +bool BundleResourceManager::DeleteBundleResourceInfo( + const std::string &bundleName, + const int32_t userId, + const bool isExistInOtherUser) +{ + /** + * Delete bundle resource when uninstall, but bundle still exists in other users. + * if isExistInOtherUser false, need to delete resource in bundleResourceIconRdb and bundleResourceRdb. + * if isExistInOtherUser true, Only need to delete resource in bundleResourceIconRdb. + */ + bool ret = true; + if (!isExistInOtherUser) { + ret = bundleResourceRdb_->DeleteResourceInfo(bundleName); + if (!ret) { + APP_LOGE("delete -n %{public}s -u %{public}d in bundleResourceRdb failed", bundleName.c_str(), userId); + } + } + + if (!bundleResourceIconRdb_->DeleteResourceIconInfos(bundleName, userId)) { + APP_LOGE("delete -n %{public}s -u %{public}d in bundleResourceIconRdb failed", bundleName.c_str(), userId); + return false; + } + return ret; +} + +bool BundleResourceManager::AddDynamicIconResource( + const std::string &bundleName, const int32_t userId, const int32_t appIndex, ResourceInfo &resourceInfo) { + // only need to process bundleResourceIconRdb + resourceInfo.bundleName_ = bundleName; + resourceInfo.appIndex_ = appIndex; + if (userId != Constants::UNSPECIFIED_USERID) { + if (!bundleResourceIconRdb_->AddResourceIconInfo(userId, IconResourceType::DYNAMIC_ICON, resourceInfo)) { + APP_LOGE("add dynamic icon failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + return true; + } + // if userId == -2, process all user and clone bundle + std::shared_ptr dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return false; + } bool ret = true; - auto appIndexes = BundleResourceProcess::GetAppIndexByBundleName(bundleName); - for (const auto appIndex : appIndexes) { - if (!AddCloneBundleResourceInfo(bundleName, appIndex)) { - APP_LOGE("add %{public}s %{public}d clone resource info failed", bundleName.c_str(), appIndex); - ret = false; + auto userIds = dataMgr->GetUserIds(bundleName); + for (const auto &user : userIds) { + resourceInfo.appIndex_ = 0; + ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, resourceInfo); + auto appIndexes = dataMgr->GetCloneAppIndexes(bundleName, user); + for (const auto &index : appIndexes) { + resourceInfo.appIndex_ = index; + ret &= bundleResourceIconRdb_->AddResourceIconInfo(user, IconResourceType::DYNAMIC_ICON, resourceInfo); } } + if (!ret) { + APP_LOGE("add all user dynamic icon failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + } return ret; } -void BundleResourceManager::BundleResourceConvertToResourceInfo( - const BundleResourceInfo &bundleResourceInfo, ResourceInfo &resourceInfo) +bool BundleResourceManager::DeleteDynamicIconResource( + const std::string &bundleName, const int32_t userId, const int32_t appIndex) +{ + if (userId != Constants::UNSPECIFIED_USERID) { + if (!bundleResourceIconRdb_->DeleteResourceIconInfo(bundleName, userId, appIndex, + IconResourceType::DYNAMIC_ICON)) { + APP_LOGE("delete dynamic icon failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + return true; + } + // if userId is -2, need delete all userId and appIndex dynamic icon + if (!bundleResourceIconRdb_->DeleteResourceIconInfos(bundleName, IconResourceType::DYNAMIC_ICON)) { + APP_LOGE("delete all user dynamic icon failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + return true; +} + +bool BundleResourceManager::AddAllResourceInfo( + const int32_t userId, const uint32_t type) { - // no need to process icon, use dynamic icon - resourceInfo.bundleName_ = bundleResourceInfo.bundleName; - resourceInfo.moduleName_ = Constants::EMPTY_STRING; - resourceInfo.abilityName_ = Constants::EMPTY_STRING; - if (bundleResourceInfo.appIndex == resourceInfo.appIndex_) { - resourceInfo.label_ = bundleResourceInfo.label; - } else { - resourceInfo.label_ = bundleResourceInfo.label + std::to_string(resourceInfo.appIndex_); + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + EventReport::SendCpuSceneEvent(FOUNDATION_PROCESS_NAME, SCENE_ID_UPDATE_RESOURCE); + ++currentTaskNum_; + uint32_t tempTaskNum = currentTaskNum_; + std::lock_guard guard(mutex_); + APP_LOGI("bundle resource hold mutex"); + std::map> resourceInfosMap; + if (!BundleResourceProcess::GetAllResourceInfo(userId, resourceInfosMap)) { + APP_LOGE("GetAllResourceInfo failed userId %{public}d", userId); + return false; } + PrepareSysRes(); + if ((type & static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) == + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)) { + if (!AddResourceInfosWhenSystemThemeChanged(resourceInfosMap, userId, tempTaskNum)) { + APP_LOGE("add resource failed when theme changed -u %{public}d", userId); + return false; + } + } + if ((type & static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)) == + static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)) { + if (!AddResourceInfosWhenSystemLanguageChanged(resourceInfosMap, userId, tempTaskNum)) { + APP_LOGE("add resource failed when language changed -u %{public}d", userId); + return false; + } + } + SendBundleResourcesChangedEvent(userId, type); + APP_LOGI_NOFUNC("add all resource end"); + return true; } -void BundleResourceManager::LauncherAbilityResourceConvertToResourceInfo( - const LauncherAbilityResourceInfo &launcherAbilityResourceInfo, ResourceInfo &resourceInfo) +bool BundleResourceManager::AddResourceInfosWhenSystemLanguageChanged( + std::map> &resourceInfosMap, + const int32_t userId, const uint32_t tempTaskNumber) { - // no need to process icon, use dynamic icon - resourceInfo.bundleName_ = launcherAbilityResourceInfo.bundleName; - resourceInfo.abilityName_ = launcherAbilityResourceInfo.abilityName; - resourceInfo.moduleName_ = launcherAbilityResourceInfo.moduleName; - if (launcherAbilityResourceInfo.appIndex == resourceInfo.appIndex_) { - resourceInfo.label_ = launcherAbilityResourceInfo.label; - } else { - resourceInfo.label_ = launcherAbilityResourceInfo.label + std::to_string(resourceInfo.appIndex_); + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (resourceInfosMap.empty()) { + APP_LOGE("resourceInfosMap is empty"); + return false; } + InnerProcessResourceInfoBySystemLanguageChanged(resourceInfosMap); + std::shared_ptr threadPool = std::make_shared(THREAD_POOL_NAME); + threadPool->Start(MAX_TASK_NUMBER); + threadPool->SetMaxTaskNum(MAX_TASK_NUMBER); + for (const auto &item : resourceInfosMap) { + if (tempTaskNumber != currentTaskNum_) { + APP_LOGI("need stop current task, new first"); + threadPool->Stop(); + return false; + } + std::string bundleName = item.first; + auto task = [userId, bundleName, &resourceInfosMap, this]() { + if (resourceInfosMap.find(bundleName) == resourceInfosMap.end()) { + APP_LOGE("bundleName %{public}s not exist", bundleName.c_str()); + return; + } + std::vector resourceInfos = resourceInfosMap[bundleName]; + BundleResourceParser parser; + parser.ParseResourceInfos(userId, resourceInfos); + bundleResourceRdb_->UpdateResourceForSystemStateChanged(resourceInfos); + }; + threadPool->AddTask(task); + } + while (threadPool->GetCurTaskNum() > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(CHECK_INTERVAL)); + } + threadPool->Stop(); + // process clone bundle resource info, only flash label + for (const auto &item : resourceInfosMap) { + if (!item.second.empty() && !item.second[0].appIndexes_.empty()) { + APP_LOGI("start process bundle:%{public}s clone resource info", item.first.c_str()); + for (const int32_t appIndex : item.second[0].appIndexes_) { + ProcessCloneBundleResourceInfoWhenSystemLanguageChanged(item.first, userId, appIndex); + } + } + } + APP_LOGI("all task end resource size %{public}zu when language changed", resourceInfosMap.size()); + return true; +} + +bool BundleResourceManager::ProcessCloneBundleResourceInfoWhenSystemLanguageChanged( + const std::string &bundleName, + const int32_t userId, + const int32_t appIndex) +{ + if (appIndex <= 0) { + APP_LOGE("prase clone bundle failed -n %{public}s -u %{public}d -a %{public}d", bundleName.c_str(), + userId, appIndex); + return false; + } + std::vector resourceInfos; + if (!GetBundleResourceInfoForCloneBundle(bundleName, appIndex, + static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), resourceInfos)) { + APP_LOGE("get clone bundle resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + // update clone bundle label resource + if (!bundleResourceRdb_->UpdateResourceForSystemStateChanged(resourceInfos)) { + APP_LOGE("update clone resource failed -n %{public}s -u %{public}d -a %{public}d", bundleName.c_str(), + userId, appIndex); + return false; + } + return true; +} + +void BundleResourceManager::DeleteNotExistThemeResource( + const std::map> &resourceInfosMap, + const std::set &oldResourceNames, + const int32_t userId) +{ + if (oldResourceNames.empty()) { + return; + } + std::set newBundleNames; + for (const auto &item : resourceInfosMap) { + for (const auto &resource : item.second) { + newBundleNames.insert(resource.GetKey()); + } + } + for (const auto &name : oldResourceNames) { + if (newBundleNames.find(name) == newBundleNames.end()) { + // delete key bundleName and type, need delete clone bundle + (void)bundleResourceIconRdb_->DeleteResourceIconInfos(name, userId, IconResourceType::THEME_ICON); + } + } +} + +bool BundleResourceManager::AddResourceInfosWhenSystemThemeChanged( + std::map> &resourceInfosMap, + const int32_t userId, const uint32_t tempTaskNumber) +{ + HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + if (resourceInfosMap.empty()) { + APP_LOGE("resourceInfosMap is empty"); + return false; + } + // 1. used to delete no exist in current theme bundle resource + std::set oldResourceNames; + if (!bundleResourceIconRdb_->GetAllResourceIconName(userId, oldResourceNames, IconResourceType::THEME_ICON)) { + APP_LOGW("get old bundle names failed"); + } + // 2. judge whether the bundle theme exists + InnerProcessResourceInfoBySystemThemeChanged(resourceInfosMap, userId); + std::shared_ptr threadPool = std::make_shared(THREAD_POOL_NAME); + threadPool->Start(MAX_TASK_NUMBER); + threadPool->SetMaxTaskNum(MAX_TASK_NUMBER); + for (const auto &item : resourceInfosMap) { + if (tempTaskNumber != currentTaskNum_) { + APP_LOGI("need stop current task, new first"); + threadPool->Stop(); + return false; + } + std::string bundleName = item.first; + auto task = [userId, bundleName, &resourceInfosMap, this]() { + if (resourceInfosMap.find(bundleName) == resourceInfosMap.end()) { + APP_LOGE("bundleName %{public}s not exist", bundleName.c_str()); + return; + } + std::vector resourceInfos = resourceInfosMap[bundleName]; + BundleResourceParser parser; + parser.ParseIconResourceInfosWithTheme(userId, resourceInfos); + (void)bundleResourceIconRdb_->AddResourceIconInfos(userId, IconResourceType::THEME_ICON, resourceInfos); + }; + threadPool->AddTask(task); + } + while (threadPool->GetCurTaskNum() > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(CHECK_INTERVAL)); + } + threadPool->Stop(); + // process clone bundle resource info + for (const auto &item : resourceInfosMap) { + if (!item.second.empty() && !item.second[0].appIndexes_.empty()) { + APP_LOGI("start process bundle:%{public}s clone resource info", item.first.c_str()); + for (const int32_t appIndex : item.second[0].appIndexes_) { + (void)ProcessCloneBundleResourceInfoWhenSystemThemeChanged(item.first, userId, appIndex); + } + } + } + DeleteNotExistThemeResource(resourceInfosMap, oldResourceNames, userId); + // set is online theme + SetIsOnlineTheme(userId); + APP_LOGI("all task end resource size %{public}zu when theme changed", resourceInfosMap.size()); + return true; +} + +bool BundleResourceManager::ProcessCloneBundleResourceInfoWhenSystemThemeChanged( + const std::string &bundleName, + const int32_t userId, + const int32_t appIndex) +{ + // 1. query main bundle resource in bundleResourceIconRdb + std::vector launcherAbilityResourceInfos; + if (!bundleResourceIconRdb_->GetResourceIconInfos(bundleName, userId, 0, + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON) | + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), + launcherAbilityResourceInfos, IconResourceType::THEME_ICON)) { + APP_LOGE("get resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + std::vector resourceInfos; + for (auto &info : launcherAbilityResourceInfos) { + info.appIndex = appIndex; + ResourceInfo bundleResource; + bundleResource.ConvertFromLauncherAbilityResourceInfo(info); + resourceInfos.emplace_back(bundleResource); + } + // 2. process icon with badge + BundleResourceParser parser; + if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { + APP_LOGE("parse clone resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + } + // 3. save clone bundle resource info to bundleResourceIconRdb + if (!bundleResourceIconRdb_->AddResourceIconInfos(userId, IconResourceType::THEME_ICON, resourceInfos)) { + APP_LOGE("add resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + return true; +} + +void BundleResourceManager::InnerProcessResourceInfoBySystemThemeChanged( + std::map> &resourceInfosMap, + const int32_t userId) +{ + for (auto iter = resourceInfosMap.begin(); iter != resourceInfosMap.end();) { + if (iter->second.empty() || !BundleResourceThemeProcess::IsBundleThemeExist(iter->first, userId)) { + iter = resourceInfosMap.erase(iter); + continue; + } + std::vector themeResourceInfos; + themeResourceInfos.emplace_back(iter->second[0]); + for (const auto &resource : iter->second) { + if (BundleResourceThemeProcess::IsAbilityThemeExist(resource.bundleName_, resource.moduleName_, + resource.abilityName_, userId)) { + themeResourceInfos.emplace_back(resource); + } + } + iter->second = themeResourceInfos; + ++iter; + } + for (auto iter = resourceInfosMap.begin(); iter != resourceInfosMap.end(); ++iter) { + ProcessResourceInfoNoNeedToParseOtherIcon(iter->second); + } +} + +bool BundleResourceManager::AddCloneBundleResourceInfoWhenInstall( + const std::string &bundleName, + const int32_t userId, + const int32_t appIndex, + const bool isExistInOtherUser) +{ + /** + * Need to distinguish whether bundle and appIndex exist in other users. + * if not exist, need to process both bundleResourceRdb and bundleResourceIconRdb; + * if exist, only need to process bundleResourceIconRdb. + */ + bool ret = true; + if (!isExistInOtherUser) { + // 1. process clone resource icon and label in bundleResourceRdb, icon with badge, label with appIndex + ret = ProcessCloneBundleResourceInfo(bundleName, appIndex); + if (!ret) { + APP_LOGE("-n %{public}s -u %{public}d -a %{public}d process clone resource failed", + bundleName.c_str(), userId, appIndex); + } + } + // 2. if theme not exist, then return + if (!BundleResourceThemeProcess::IsBundleThemeExist(bundleName, userId)) { + return ret; + } + // 3. process clone resource icon in bundleResourceIconRdb + std::vector launcherAbilityResourceInfos; + if (!bundleResourceIconRdb_->GetResourceIconInfos(bundleName, userId, 0, + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON) | + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), + launcherAbilityResourceInfos, IconResourceType::THEME_ICON)) { + APP_LOGE("get resource failed -n %{public}s -u %{public}d -a %{public}d", + bundleName.c_str(), userId, appIndex); + return false; + } + // 4. process icon with badge + std::vector resourceInfos; + for (auto &info : launcherAbilityResourceInfos) { + info.appIndex = appIndex; + ResourceInfo bundleResource; + bundleResource.ConvertFromLauncherAbilityResourceInfo(info); + resourceInfos.emplace_back(bundleResource); + } + BundleResourceParser parser; + if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { + APP_LOGE("-n %{public}s -u %{public}d -a %{public}d parse clone resource failed", + bundleName.c_str(), userId, appIndex); + } + // 5. add theme icon to bundleResourceIconRdb + if (!bundleResourceIconRdb_->AddResourceIconInfos(userId, IconResourceType::THEME_ICON, resourceInfos)) { + APP_LOGE("-n %{public}s -u %{public}d -a %{public}d add clone resource failed", + bundleName.c_str(), userId, appIndex); + return false; + } + return ret; +} + +bool BundleResourceManager::DeleteCloneBundleResourceInfoWhenUninstall( + const std::string &bundleName, + const int32_t userId, + const int32_t appIndex, + const bool isExistInOtherUser) +{ + /** + * Need to distinguish whether bundle and appIndex exist in other users. + * if not exist, need to delete both bundleResourceRdb and bundleResourceIconRdb; + * if exist, only need to delete bundleResourceIconRdb. + */ + bool ret = true; + if (!isExistInOtherUser) { + ResourceInfo resourceInfo; + resourceInfo.bundleName_ = bundleName; + resourceInfo.appIndex_ = appIndex; + ret = bundleResourceRdb_->DeleteResourceInfo(resourceInfo.GetKey()); + if (!ret) { + APP_LOGE("-n %{public}s -u %{public}d -a %{public}d delete resource failed", + bundleName.c_str(), userId, appIndex); + } + } + if (!bundleResourceIconRdb_->DeleteResourceIconInfo(bundleName, userId, appIndex)) { + APP_LOGE("-n %{public}s -u %{public}d -a %{public}d delete resource failed", + bundleName.c_str(), userId, appIndex); + return false; + } + return ret; +} + +bool BundleResourceManager::IsNeedProcessResourceIconInfo(const uint32_t resourceFlags) +{ + if (((resourceFlags & static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL)) == + static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL)) || + ((resourceFlags & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON)) == + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON)) || + ((resourceFlags & static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR)) == + static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR))) { + return true; + } + return false; +} + +int32_t BundleResourceManager::GetUserId() +{ + int32_t userId = BundleUtil::GetUserIdByCallingUid(); + if (userId == Constants::DEFAULT_USERID) { + // check is sa call + if (BundlePermissionMgr::IsNativeTokenType()) { + userId = AccountHelper::GetCurrentActiveUserId(); + } + } + if (userId < Constants::DEFAULT_USERID) { + APP_LOGE("userId %{public}d is invalid", userId); + } + return userId; +} + +void BundleResourceManager::SetIsOnlineThemeWhenBoot() +{ + APP_LOGI("set online theme when boot start"); + // 1. get all user + std::shared_ptr dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return; + } + auto userIds = dataMgr->GetAllUser(); + // 2. parse json file + for (const auto &userId : userIds) { + SetIsOnlineTheme(userId); + } + APP_LOGI("set online theme when boot end"); +} + +void BundleResourceManager::SetIsOnlineTheme(const int32_t userId) +{ + bool isOnlineTheme = false; + if (!BundleResourceProcess::CheckThemeType("", userId, isOnlineTheme)) { + APP_LOGE("userId %{public}d check online theme failed", userId); + } + APP_LOGI("userId %{public}d isOnlineTheme %{public}d", userId, isOnlineTheme); + bundleResourceIconRdb_->SetIsOnlineTheme(userId, isOnlineTheme); +} + +bool BundleResourceManager::InnerProcessThemeIconWhenOta( + const std::string &bundleName, const std::set userIds) +{ + // 1. theme whether exist in all user, no need to process + std::vector existThemeUserIds; + for (const auto user : userIds) { + if (BundleResourceThemeProcess::IsBundleThemeExist(bundleName, user)) { + existThemeUserIds.push_back(user); + } + } + if (existThemeUserIds.empty()) { + return true; + } + std::shared_ptr dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return false; + } + // 2. only process bundle resource rdb, like bundle update + bool isUpdated = false; + for (const auto userId : existThemeUserIds) { + // bundle whether installed in user + bool isInstalled = false; + if ((dataMgr->IsBundleInstalled(bundleName, userId, 0, isInstalled) != ERR_OK) || !isInstalled) { + continue; + } + if (!isUpdated) { + (void)AddResourceInfoByBundleNameWhenUpdate(bundleName, existThemeUserIds[0]); + isUpdated = true; + } + (void)AddResourceInfoByBundleNameWhenCreateUser(bundleName, userId); + } + return true; +} + +bool BundleResourceManager::InnerProcessDynamicIconWhenOta(const std::string &bundleName) +{ + std::shared_ptr dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return false; + } + // 1. check dynamic icon info, if not exist then return + std::vector dynamicIconInfos; + if (dataMgr->GetDynamicIconInfo(bundleName, dynamicIconInfos) != ERR_OK) { + APP_LOGE("get dynamic icon failed -n %{public}s", bundleName.c_str()); + return false; + } + if (dynamicIconInfos.empty()) { + return true; + } + // 2. need parse dynamic icon, add to bundle resource icon rdb + std::set userIds; + for (const auto &dynamicIcon : dynamicIconInfos) { + userIds.insert(dynamicIcon.userId); + ResourceInfo resourceInfo; + resourceInfo.bundleName_ = dynamicIcon.bundleName; + resourceInfo.appIndex_ = dynamicIcon.appIndex; + if (!BundleResourceProcess::GetDynamicIconResourceInfo(dynamicIcon.bundleName, dynamicIcon.moduleName, + resourceInfo)) { + APP_LOGE("get dynamic icon failed -n %{public}s", bundleName.c_str()); + continue; + } + // add bundle resource icon rdb + if (!AddDynamicIconResource(bundleName, dynamicIcon.userId, dynamicIcon.appIndex, resourceInfo)) { + APP_LOGE("add dynamic icon failed -n %{public}s", bundleName.c_str()); + } + } + // 3. update bundle resource rdb + for (const auto userId : userIds) { + if (BundleResourceThemeProcess::IsBundleThemeExist(bundleName, userId)) { + if (AddResourceInfoByBundleNameWhenUpdate(bundleName, userId)) { + APP_LOGE("add resource icon failed -n %{public}s -u %{public}d", bundleName.c_str(), userId); + } + break; + } + } + return true; +} + +bool BundleResourceManager::ProcessThemeAndDynamicIconWhenOta( + const std::set &updateBundleNames) +{ + APP_LOGI("ProcessThemeAndDynamicIconWhenOta start"); + std::shared_ptr dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return false; + } + PrepareSysRes(); + auto userIds = dataMgr->GetAllUser(); + // 1. get all bundle names + std::vector allBundleNames = dataMgr->GetAllBundleName(); + for (const auto &bundleName : allBundleNames) { + // dynamic icon need all process + InnerProcessDynamicIconWhenOta(bundleName); + // theme icon already process when bundle update + if (std::find(updateBundleNames.begin(), updateBundleNames.end(), bundleName) != updateBundleNames.end()) { + continue; + } + InnerProcessThemeIconWhenOta(bundleName, userIds); + } + APP_LOGI("ProcessThemeAndDynamicIconWhenOta end"); + return true; } } // AppExecFwk } // OHOS diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp index 2f5edad13b..9e41166443 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_parser.cpp @@ -39,17 +39,6 @@ constexpr char CHAR_COLON = ':'; constexpr const char* OHOS_CLONE_APP_BADGE_RESOURCE = "clone_app_badge_"; constexpr int8_t BADGE_SIZE = 62; #endif -constexpr const char* COM_OHOS_CONTACTS_ENTRY_ABILITY = "com.ohos.contacts.EntryAbility"; -constexpr const char* COM_OHOS_CONTACTS_ENTRY = "entry"; -constexpr const char* SYSTEM_THEME_PATH = "/data/service/el1/public/themes/"; -constexpr const char* ENTRY_ABILITY_THEME_ICONS_A = - "/a/app/icons/com.ohos.contacts/entry/com.ohos.contacts.EntryAbility"; -constexpr const char* ENTRY_ABILITY_THEME_ICONS_B = - "/b/app/icons/com.ohos.contacts/entry/com.ohos.contacts.EntryAbility"; -constexpr const char* THEME_ICONS_A_FLAG = "/a/app/flag"; -constexpr const char* THEME_ICONS_B_FLAG = "/b/app/flag"; -constexpr const char* COM_OHOS_CONTACTS = "com.ohos.contacts"; - struct LayeredImage { std::string foreground; std::string background; @@ -152,13 +141,9 @@ bool BundleResourceParser::ParseResourceInfos(const int32_t userId, std::vector< std::shared_ptr(Global::Resource::CreateResourceManager( resourceInfos[index].bundleName_, resourceInfos[index].moduleName_, resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, *resConfig, 0, userId)); - if (resourceInfos[index].hasThemeIcon_) { - (void)BundleResourceConfiguration::InitResourceGlobalConfig(resourceManager); - } else { - (void)BundleResourceConfiguration::InitResourceGlobalConfig( - resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, resourceManager, - resourceInfos[index].iconNeedParse_, resourceInfos[index].labelNeedParse_); - } + (void)BundleResourceConfiguration::InitResourceGlobalConfig( + resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, resourceManager, + resourceInfos[index].iconNeedParse_, resourceInfos[index].labelNeedParse_); resourceManagerMap[resourceInfos[index].moduleName_] = resourceManager; } @@ -166,7 +151,6 @@ bool BundleResourceParser::ParseResourceInfos(const int32_t userId, std::vector< APP_LOGW_NOFUNC("ParseResourceInfo fail key:%{public}s", resourceInfos[index].GetKey().c_str()); } } - ProcessSpecialBundleResource(userId, resourceInfos); if ((resourceInfos[0].labelNeedParse_ && resourceInfos[0].label_.empty()) || (resourceInfos[0].iconNeedParse_ && resourceInfos[0].icon_.empty())) { APP_LOGE_NOFUNC("ParseResourceInfos fail -n %{public}s -m %{public}s", @@ -283,7 +267,7 @@ bool BundleResourceParser::ParseIconResourceByPath(const std::string &hapPath, c bool BundleResourceParser::ParseResourceInfoByResourceManager( const std::shared_ptr resourceManager, - ResourceInfo &resourceInfo) + ResourceInfo &resourceInfo, bool usingThemeResource) { if (resourceManager == nullptr) { APP_LOGE("resourceManager is nullptr"); @@ -296,7 +280,8 @@ bool BundleResourceParser::ParseResourceInfoByResourceManager( ans = false; } - if (resourceInfo.iconNeedParse_ && !ParseIconResourceByResourceManager(resourceManager, resourceInfo)) { + if (resourceInfo.iconNeedParse_ && !ParseIconResourceByResourceManager(resourceManager, resourceInfo, + usingThemeResource)) { APP_LOGE_NOFUNC("ParseIconResource fail key %{public}s", resourceInfo.GetKey().c_str()); ans = false; } @@ -327,7 +312,7 @@ bool BundleResourceParser::ParseLabelResourceByResourceManager( bool BundleResourceParser::ParseIconResourceByResourceManager( const std::shared_ptr resourceManager, - ResourceInfo &resourceInfo) + ResourceInfo &resourceInfo, bool usingThemeResource) { if (resourceManager == nullptr) { APP_LOGE("resourceManager is nullptr"); @@ -337,13 +322,15 @@ bool BundleResourceParser::ParseIconResourceByResourceManager( APP_LOGE_NOFUNC("iconId is 0 or less than 0"); return false; } - // Firstly, check if the bundle theme resource exists, density 0 - BundleResourceDrawable drawable; - if (drawable.GetIconResourceByTheme(resourceInfo.iconId_, 0, resourceManager, resourceInfo) && - !resourceInfo.foreground_.empty()) { - return true; + if (usingThemeResource) { + // Firstly, check if the bundle theme resource exists, density 0 + BundleResourceDrawable drawable; + if (drawable.GetIconResourceByTheme(resourceInfo.iconId_, 0, resourceManager, resourceInfo) && + !resourceInfo.foreground_.empty()) { + return true; + } + APP_LOGI_NOFUNC("%{public}s not exist theme", resourceInfo.GetKey().c_str()); } - APP_LOGI_NOFUNC("%{public}s not exist theme", resourceInfo.GetKey().c_str()); // parse json std::string type; size_t len; @@ -365,6 +352,7 @@ bool BundleResourceParser::ParseIconResourceByResourceManager( return bundleResourceImageInfo.ConvertToBase64(std::move(jsonBuf), len, resourceInfo.icon_); } APP_LOGI_NOFUNC("%{public}s icon is not png, parse by drawable descriptor", resourceInfo.GetKey().c_str()); + BundleResourceDrawable drawable; if (!drawable.GetIconResourceByHap(resourceInfo.iconId_, 0, resourceManager, resourceInfo)) { APP_LOGE("key:%{public}s parse failed with hap iconId:%{public}d", resourceInfo.GetKey().c_str(), resourceInfo.iconId_); @@ -518,39 +506,99 @@ bool BundleResourceParser::ParserCloneResourceInfo( #endif } -void BundleResourceParser::ProcessSpecialBundleResource(const int32_t userId, std::vector &resourceInfos) +bool BundleResourceParser::ParseResourceInfosNoTheme( + const int32_t userId, std::vector &resourceInfos) { + APP_LOGD("start"); if (resourceInfos.empty()) { - APP_LOGW("resourceInfos empty"); - return; - } - if ((resourceInfos[0].GetKey() == COM_OHOS_CONTACTS)) { - bool isContactsEntryAbilityExistTheme = false; - if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A_FLAG) && - BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + ENTRY_ABILITY_THEME_ICONS_A)) { - isContactsEntryAbilityExistTheme = true; + APP_LOGE("resourceInfos is empty"); + return false; + } + // same module need parse together + std::map> resourceManagerMap; + size_t size = resourceInfos.size(); + for (size_t index = 0; index < size; ++index) { + if (!resourceInfos[index].iconNeedParse_ && !resourceInfos[index].labelNeedParse_) { + APP_LOGI("%{public}s no need parse", resourceInfos[index].bundleName_.c_str()); + continue; } - if (!isContactsEntryAbilityExistTheme && - BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B_FLAG) && - BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + ENTRY_ABILITY_THEME_ICONS_B)) { - isContactsEntryAbilityExistTheme = true; + if ((index > 0) && !IsNeedToParseResourceInfo(resourceInfos[index], resourceInfos[0])) { + continue; + } + auto resourceManager = resourceManagerMap[resourceInfos[index].moduleName_]; + if (resourceManager == nullptr) { + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + if (resConfig == nullptr) { + APP_LOGE("resConfig is nullptr"); + continue; + } + resourceManager = + std::shared_ptr(Global::Resource::CreateResourceManager( + resourceInfos[index].bundleName_, resourceInfos[index].moduleName_, + resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, *resConfig, 0, userId)); + resourceManagerMap[resourceInfos[index].moduleName_] = resourceManager; + if (!BundleResourceConfiguration::InitResourceGlobalConfig( + resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, resourceManager, + resourceInfos[index].iconNeedParse_, resourceInfos[index].labelNeedParse_)) { + APP_LOGW("InitResourceGlobalConfig failed, key:%{public}s", resourceInfos[index].GetKey().c_str()); + } } - if (!isContactsEntryAbilityExistTheme) { - APP_LOGI("%{public}s not exist entry ability theme", resourceInfos[0].GetKey().c_str()); - return; + + if (!ParseResourceInfoByResourceManager(resourceManager, resourceInfos[index], false)) { + APP_LOGW_NOFUNC("ParseResourceInfo fail key:%{public}s", resourceInfos[index].GetKey().c_str()); } - for (const auto &resourceInfo : resourceInfos) { - if ((resourceInfo.moduleName_ == COM_OHOS_CONTACTS_ENTRY) && - (resourceInfo.abilityName_ == COM_OHOS_CONTACTS_ENTRY_ABILITY) && - !resourceInfo.icon_.empty()) { - APP_LOGI("%{public}s exist entry ability theme", resourceInfos[0].GetKey().c_str()); - resourceInfos[0].icon_ = resourceInfo.icon_; - resourceInfos[0].foreground_ = resourceInfo.foreground_; - resourceInfos[0].background_ = resourceInfo.background_; - return; + } + if ((resourceInfos[0].labelNeedParse_ && resourceInfos[0].label_.empty()) || + (resourceInfos[0].iconNeedParse_ && resourceInfos[0].icon_.empty())) { + APP_LOGE_NOFUNC("ParseResourceInfos fail -n %{public}s -m %{public}s", + resourceInfos[0].bundleName_.c_str(), resourceInfos[0].moduleName_.c_str()); + return false; + } + APP_LOGD("end"); + return true; +} + +bool BundleResourceParser::ParseIconResourceInfosWithTheme( + const int32_t userId, std::vector &resourceInfos) +{ + APP_LOGD("start"); + if (resourceInfos.empty()) { + APP_LOGE("resourceInfos is empty"); + return false; + } + // same module need parse together + std::map> resourceManagerMap; + size_t size = resourceInfos.size(); + for (size_t index = 0; index < size; ++index) { + auto resourceManager = resourceManagerMap[resourceInfos[index].moduleName_]; + if (resourceManager == nullptr) { + std::unique_ptr resConfig(Global::Resource::CreateResConfig()); + if (resConfig == nullptr) { + APP_LOGE("resConfig is nullptr"); + continue; + } + resourceManager = + std::shared_ptr(Global::Resource::CreateResourceManager( + resourceInfos[index].bundleName_, resourceInfos[index].moduleName_, + resourceInfos[index].hapPath_, resourceInfos[index].overlayHapPaths_, *resConfig, 0, userId)); + resourceManagerMap[resourceInfos[index].moduleName_] = resourceManager; + // no add path when theme exist + if (!BundleResourceConfiguration::InitResourceGlobalConfig(resourceManager)) { + APP_LOGW("InitResourceGlobalConfig failed, key:%{public}s", resourceInfos[index].GetKey().c_str()); } } + + if (!ParseIconResourceByResourceManager(resourceManager, resourceInfos[index])) { + APP_LOGW_NOFUNC("ParseResourceInfo fail key:%{public}s", resourceInfos[index].GetKey().c_str()); + } + } + if (resourceInfos[0].icon_.empty()) { + APP_LOGE_NOFUNC("ParseResourceInfos fail -n %{public}s -m %{public}s", + resourceInfos[0].bundleName_.c_str(), resourceInfos[0].moduleName_.c_str()); + return false; } + APP_LOGD("end"); + return true; } } // AppExecFwk } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp index 643b767ecc..3072913637 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp @@ -96,7 +96,8 @@ bool BundleResourceProcess::GetResourceInfoByBundleName( const std::string &bundleName, const int32_t userId, std::vector &resourceInfo, - const int32_t appIndex) + const int32_t appIndex, + bool needParseDynamic) { APP_LOGD("start, bundleName:%{public}s", bundleName.c_str()); auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); @@ -114,7 +115,7 @@ bool BundleResourceProcess::GetResourceInfoByBundleName( return false; } - return InnerGetResourceInfo(innerBundleInfo, userId, resourceInfo, appIndex); + return InnerGetResourceInfo(innerBundleInfo, userId, resourceInfo, appIndex, needParseDynamic); } bool BundleResourceProcess::GetLauncherResourceInfoByAbilityName( @@ -245,38 +246,51 @@ bool BundleResourceProcess::GetDynamicIcon( return true; } +bool BundleResourceProcess::GetDynamicIconResourceInfo(const std::string &bundleName, + const std::string &dynamicModuleName, ResourceInfo &resourceInfo) +{ + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is nullptr"); + return false; + } + ExtendResourceInfo extendResourceInfo; + if (dataMgr->GetExtendResourceInfo(bundleName, dynamicModuleName, extendResourceInfo) != ERR_OK) { + APP_LOGE("GetExtendResourceInfo failed -n %{public}s -m %{public}s", + bundleName.c_str(), dynamicModuleName.c_str()); + return false; + } + BundleResourceParser parser; + if (!parser.ParseIconResourceByPath(extendResourceInfo.filePath, extendResourceInfo.iconId, resourceInfo)) { + APP_LOGE("-n %{public}s parse dynamicIcon failed, iconId:%{public}d", + bundleName.c_str(), extendResourceInfo.iconId); + return false; + } + return true; +} + bool BundleResourceProcess::InnerGetResourceInfo( const InnerBundleInfo &innerBundleInfo, const int32_t userId, std::vector &resourceInfos, - const int32_t appIndex) + const int32_t appIndex, + bool needParseDynamic) { - ResourceInfo dynamicResourceInfo; - dynamicResourceInfo.bundleName_ = innerBundleInfo.GetBundleName(); - dynamicResourceInfo.appIndex_ = appIndex; - bool hasDynamicIcon = GetDynamicIcon(innerBundleInfo, userId, dynamicResourceInfo); if (!OnGetResourceInfo(innerBundleInfo, userId, resourceInfos)) { - if (!hasDynamicIcon) { - APP_LOGW("bundleName: %{public}s get bundle resource failed", - innerBundleInfo.GetBundleName().c_str()); - return false; - } - - APP_LOGI("%{public}s no default icon, build new", innerBundleInfo.GetBundleName().c_str()); - ResourceInfo defaultResourceInfo; - defaultResourceInfo.bundleName_ = innerBundleInfo.GetBundleName(); - defaultResourceInfo.labelNeedParse_ = false; - defaultResourceInfo.iconNeedParse_ = false; - defaultResourceInfo.icon_ = dynamicResourceInfo.icon_; - defaultResourceInfo.foreground_ = dynamicResourceInfo.foreground_; - defaultResourceInfo.background_ = dynamicResourceInfo.background_; - resourceInfos.emplace_back(defaultResourceInfo); - } - - if (hasDynamicIcon) { - APP_LOGI("-n %{public}s -u %{public}d -i %{public}d has dynamicIcon", innerBundleInfo.GetBundleName().c_str(), + APP_LOGE("-n %{public}s -u %{public}d -i %{public}d no resource", innerBundleInfo.GetBundleName().c_str(), userId, appIndex); - ChangeDynamicIcon(resourceInfos, dynamicResourceInfo); + return false; + } + if (needParseDynamic) { + ResourceInfo dynamicResourceInfo; + dynamicResourceInfo.bundleName_ = innerBundleInfo.GetBundleName(); + dynamicResourceInfo.appIndex_ = appIndex; + bool hasDynamicIcon = GetDynamicIcon(innerBundleInfo, userId, dynamicResourceInfo); + if (hasDynamicIcon) { + APP_LOGI("-n %{public}s -u %{public}d -i %{public}d has dynamicIcon", + innerBundleInfo.GetBundleName().c_str(), userId, appIndex); + ChangeDynamicIcon(resourceInfos, dynamicResourceInfo); + } } // for clone bundle std::set appIndexes = innerBundleInfo.GetCloneBundleAppIndexes(); @@ -348,7 +362,6 @@ ResourceInfo BundleResourceProcess::ConvertToBundleResourceInfo(const InnerBundl } resourceInfo.moduleName_ = moduleName; resourceInfo.abilityName_ = std::string(); - resourceInfo.hasDynamicIcon_ = innerBundleInfo.IsDynamicIconModuleExist(); return resourceInfo; } diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_theme_process.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_theme_process.cpp new file mode 100644 index 0000000000..4e8c7acddc --- /dev/null +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_theme_process.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bundle_resource_theme_process.h" + +#include "app_log_wrapper.h" +#include "bundle_util.h" +#include "directory_ex.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr const char* SYSTEM_THEME_PATH = "/data/service/el1/public/themes/"; +constexpr const char* THEME_ICONS_A = "/a/app/icons/"; +constexpr const char* THEME_ICONS_B = "/b/app/icons/"; +constexpr const char* THEME_ICONS_A_FLAG = "/a/app/flag"; +constexpr const char* THEME_ICONS_B_FLAG = "/b/app/flag"; +constexpr const char* THEME_ICONS_CHAR = "/"; +constexpr const char* COM_OHOS_CONTACTS_ENTRY_ABILITY = "com.ohos.contacts.EntryAbility"; +constexpr const char* COM_OHOS_CONTACTS_ENTRY = "entry"; +constexpr const char* COM_OHOS_CONTACTS = "com.ohos.contacts"; +} + +bool BundleResourceThemeProcess::IsBundleThemeExist( + const std::string &bundleName, + const int32_t userId) +{ + if (bundleName.empty()) { + return false; + } + if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A_FLAG)) { + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A + bundleName); + } + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B + bundleName); +} + +bool BundleResourceThemeProcess::IsAbilityThemeExist( + const std::string &bundleName, + const std::string &moduleName, + const std::string &abilityName, + const int32_t userId) +{ + if (bundleName.empty() || moduleName.empty() || abilityName.empty()) { + return false; + } + if (BundleUtil::IsExistFileNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A_FLAG)) { + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A + bundleName + + THEME_ICONS_CHAR + moduleName + THEME_ICONS_CHAR + abilityName); + } + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B + bundleName + + THEME_ICONS_CHAR + moduleName + THEME_ICONS_CHAR + abilityName); +} + +bool BundleResourceThemeProcess::IsThemeExistInFlagA(const std::string &bundleName, const int32_t userId) +{ + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_A + bundleName); +} + +bool BundleResourceThemeProcess::IsThemeExistInFlagB(const std::string &bundleName, const int32_t userId) +{ + return BundleUtil::IsExistDirNoLog(SYSTEM_THEME_PATH + std::to_string(userId) + THEME_ICONS_B + bundleName); +} + +void BundleResourceThemeProcess::ProcessSpecialBundleResource( + const std::vector &resourceIconInfos, + BundleResourceInfo &bundleResourceInfo) +{ + // contact icon is same with COM_OHOS_CONTACTS_ENTRY_ABILITY icon, if theme not exist, use hap resource + for (const auto &item : resourceIconInfos) { + if ((item.bundleName == bundleResourceInfo.bundleName) && + (item.moduleName == COM_OHOS_CONTACTS_ENTRY) && + (item.abilityName == COM_OHOS_CONTACTS_ENTRY_ABILITY)) { + // process com.ohos.contacts icon + bundleResourceInfo.icon = item.icon; + bundleResourceInfo.foreground = item.foreground; + bundleResourceInfo.background = item.background; + } + } +} +} // AppExecFwk +} // OHOS diff --git a/services/bundlemgr/src/bundle_resource_helper.cpp b/services/bundlemgr/src/bundle_resource_helper.cpp index 1c40b8bdfb..28c15dab1a 100644 --- a/services/bundlemgr/src/bundle_resource_helper.cpp +++ b/services/bundlemgr/src/bundle_resource_helper.cpp @@ -57,35 +57,57 @@ void BundleResourceHelper::RegisterCommonEventSubscriber() } void BundleResourceHelper::AddResourceInfoByBundleName(const std::string &bundleName, - const int32_t userId) + const int32_t userId, const ADD_RESOURCE_TYPE type, const bool isBundleFirstInstall) { #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE - APP_LOGI_NOFUNC("-n %{public}s -u %{public}d add resource start", bundleName.c_str(), userId); + APP_LOGI_NOFUNC("-n %{public}s -u %{public}d type %{public}d add resource start", bundleName.c_str(), userId, + static_cast(type)); auto manager = DelayedSingleton::GetInstance(); if (manager == nullptr) { APP_LOGE("failed, manager is nullptr"); return; } - // add new resource info - if (!manager->AddResourceInfoByBundleName(bundleName, userId)) { - APP_LOGW("failed, bundleName:%{public}s", bundleName.c_str()); + switch (type){ + case ADD_RESOURCE_TYPE::INSTALL_BUNDLE : { + // add new resource info + if (!manager->AddResourceInfoByBundleNameWhenInstall(bundleName, userId, isBundleFirstInstall)) { + APP_LOGW("add failed, bundleName:%{public}s", bundleName.c_str()); + } + break; + } + case ADD_RESOURCE_TYPE::UPDATE_BUNDLE : { + if (!manager->AddResourceInfoByBundleNameWhenUpdate(bundleName, userId)) { + APP_LOGW("update failed, bundleName:%{public}s", bundleName.c_str()); + } + break; + } + case ADD_RESOURCE_TYPE::CREATE_USER : { + if (!manager->AddResourceInfoByBundleNameWhenCreateUser(bundleName, userId)) { + APP_LOGW("update failed, bundleName:%{public}s", bundleName.c_str()); + } + break; + } + default: + break; } - APP_LOGI_NOFUNC("-n %{public}s -u %{public}d add resource end", bundleName.c_str(), userId); + APP_LOGI_NOFUNC("-n %{public}s -u %{public}d type %{public}d add resource end", bundleName.c_str(), userId, + static_cast(type)); #endif } -bool BundleResourceHelper::DeleteResourceInfo(const std::string &key, const int32_t userId) +bool BundleResourceHelper::DeleteBundleResourceInfo( + const std::string &bundleName, const int32_t userId, const bool isExistInOtherUser) { #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE - APP_LOGI("start delete key %{public}s userId:%{public}d", key.c_str(), userId); + APP_LOGI("start delete resource -n %{public}s -u %{public}d", bundleName.c_str(), userId); auto manager = DelayedSingleton::GetInstance(); if (manager == nullptr) { APP_LOGE("failed, manager is nullptr"); return false; } - if (!manager->DeleteResourceInfo(key)) { - APP_LOGE("failed, key:%{public}s", key.c_str()); + if (!manager->DeleteBundleResourceInfo(bundleName, userId, isExistInOtherUser)) { + APP_LOGE("delete resource failed -n %{public}s -u %{public}d", bundleName.c_str(), userId); return false; } @@ -151,7 +173,7 @@ bool BundleResourceHelper::DeleteAllResourceInfo() } bool BundleResourceHelper::AddCloneBundleResourceInfo(const std::string &bundleName, - const int32_t appIndex, const int32_t userId) + const int32_t userId, const int32_t appIndex, const bool isExistInOtherUser) { #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE APP_LOGI("start add clone bundle:%{public}s appIndex:%{public}d userId:%{public}d", @@ -161,7 +183,7 @@ bool BundleResourceHelper::AddCloneBundleResourceInfo(const std::string &bundleN APP_LOGE("failed, manager is nullptr"); return false; } - if (!manager->AddCloneBundleResourceInfo(bundleName, appIndex, userId)) { + if (!manager->AddCloneBundleResourceInfoWhenInstall(bundleName, userId, appIndex, isExistInOtherUser)) { APP_LOGE("add clone bundle resource failed, bundleName:%{public}s, appIndex:%{public}d", bundleName.c_str(), appIndex); return false; @@ -176,7 +198,7 @@ bool BundleResourceHelper::AddCloneBundleResourceInfo(const std::string &bundleN } bool BundleResourceHelper::DeleteCloneBundleResourceInfo(const std::string &bundleName, - const int32_t appIndex, const int32_t userId) + const int32_t userId, const int32_t appIndex, const bool isExistInOtherUser) { #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE APP_LOGI("start delete clone bundle:%{public}s appIndex:%{public}d userId:%{public}d", @@ -187,7 +209,7 @@ bool BundleResourceHelper::DeleteCloneBundleResourceInfo(const std::string &bund return false; } - if (!manager->DeleteCloneBundleResourceInfo(bundleName, appIndex)) { + if (!manager->DeleteCloneBundleResourceInfoWhenUninstall(bundleName, userId, appIndex, isExistInOtherUser)) { APP_LOGE("failed, key:%{public}s appIndex:%{public}d", bundleName.c_str(), appIndex); return false; } @@ -215,6 +237,27 @@ void BundleResourceHelper::DeleteNotExistResourceInfo() #endif } +bool BundleResourceHelper::ProcessThemeAndDynamicIconWhenOta(const std::set updateBundleNames) +{ +#ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE + APP_LOGI("ProcessThemeAndDynamicIconWhenOta start"); + auto manager = DelayedSingleton::GetInstance(); + if (manager == nullptr) { + APP_LOGE("failed, manager is nullptr"); + return false; + } + + if (!manager->ProcessThemeAndDynamicIconWhenOta(updateBundleNames)) { + APP_LOGE("ProcessThemeAndDynamicIconWhenOta failed"); + return false; + } + APP_LOGI("ProcessThemeAndDynamicIconWhenOta end"); + return true; +#else + return false; +#endif +} + bool BundleResourceHelper::GetBundleResourceInfo(const std::string &bundleName, const uint32_t flags, BundleResourceInfo &bundleResourceInfo, int32_t appIndex) { @@ -304,5 +347,17 @@ void BundleResourceHelper::ProcessBundleResourceChange() return; #endif } + +void BundleResourceHelper::SetIsOnlineThemeWhenBoot() +{ +#ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE + auto manager = DelayedSingleton::GetInstance(); + if (manager == nullptr) { + APP_LOGE("failed, manager is nullptr"); + return; + } + manager->SetIsOnlineThemeWhenBoot(); +#endif +} } // AppExecFwk } // OHOS diff --git a/services/bundlemgr/src/clone/bundle_clone_installer.cpp b/services/bundlemgr/src/clone/bundle_clone_installer.cpp index 6f399b32fe..ad57861f95 100644 --- a/services/bundlemgr/src/clone/bundle_clone_installer.cpp +++ b/services/bundlemgr/src/clone/bundle_clone_installer.cpp @@ -267,9 +267,8 @@ ErrCode BundleCloneInstaller::ProcessCloneBundleInstall(const std::string &bundl { auto appIndexes = info.GetCloneBundleAppIndexes(); // appIndex not exist, need parse - if (appIndexes.find(appIndex) == appIndexes.end()) { - BundleResourceHelper::AddCloneBundleResourceInfo(bundleName, appIndex, userId); - } + BundleResourceHelper::AddCloneBundleResourceInfo(bundleName, userId, appIndex, + appIndexes.find(appIndex) != appIndexes.end()); } // total to commit, avoid rollback @@ -344,9 +343,8 @@ ErrCode BundleCloneInstaller::ProcessCloneBundleUninstall(const std::string &bun InnerBundleInfo info; if (dataMgr_->FetchInnerBundleInfo(bundleName, info)) { auto appIndexes = info.GetCloneBundleAppIndexes(); - if (appIndexes.find(appIndex) == appIndexes.end()) { - BundleResourceHelper::DeleteCloneBundleResourceInfo(bundleName, appIndex, userId); - } + BundleResourceHelper::DeleteCloneBundleResourceInfo(bundleName, userId, appIndex, + appIndexes.find(appIndex) != appIndexes.end()); } } #ifdef BUNDLE_FRAMEWORK_APP_CONTROL diff --git a/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp b/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp index 8d02353eda..1986d8fabd 100644 --- a/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp +++ b/services/bundlemgr/src/extend_resource/extend_resource_manager_host_impl.cpp @@ -506,18 +506,7 @@ bool ExtendResourceManagerHostImpl::ParseBundleResource( ResourceInfo info; info.bundleName_ = bundleName; info.iconId_ = extendResourceInfo.iconId; - if ((userId == Constants::UNSPECIFIED_USERID) && (appIndex == Constants::DEFAULT_APP_INDEX)) { - // process all appIndex - info.appIndex_ = Constants::UNSPECIFIED_USERID; - } else { - // process one appIndex - info.appIndex_ = appIndex; - if (!IsNeedUpdateBundleResourceInfo(bundleName, userId)) { - APP_LOGI("bundle %{public}s userId %{public}d no need to update bundle resource", - bundleName.c_str(), userId); - return true; - } - } + info.appIndex_ = appIndex; BundleResourceParser bundleResourceParser; if (!bundleResourceParser.ParseIconResourceByPath(extendResourceInfo.filePath, extendResourceInfo.iconId, info)) { @@ -533,7 +522,7 @@ bool ExtendResourceManagerHostImpl::ParseBundleResource( APP_LOGE("failed, manager is nullptr"); return false; } - if (!manager->UpdateBundleIcon(bundleName, info)) { + if (!manager->AddDynamicIconResource(bundleName, userId, appIndex, info)) { APP_LOGE("UpdateBundleIcon failed, bundleName:%{public}s", bundleName.c_str()); return false; } @@ -621,9 +610,7 @@ ErrCode ExtendResourceManagerHostImpl::DisableDynamicIcon(const std::string &bun } SaveCurDynamicIcon(bundleName, "", userId, appIndex); - if (CheckWhetherDynamicIconNeedProcess(bundleName, userId)) { - (void)ResetBundleResourceIcon(bundleName, userId, appIndex); - } + (void)ResetBundleResourceIcon(bundleName, userId, appIndex); SendBroadcast(bundleName, false, userId, appIndex); return ERR_OK; } @@ -639,25 +626,7 @@ bool ExtendResourceManagerHostImpl::ResetBundleResourceIcon(const std::string &b APP_LOGE("failed, manager is nullptr"); return false; } - if ((userId == Constants::UNSPECIFIED_USERID) && (appIndex == Constants::DEFAULT_APP_INDEX)) { - // Reset default icon - int32_t currentUserId = AccountHelper::GetCurrentActiveUserId(); - if ((currentUserId <= 0)) { - currentUserId = Constants::START_USERID; - } - if (!manager->AddResourceInfoByBundleName(bundleName, currentUserId)) { - APP_LOGE("No default icon, bundleName:%{public}s", bundleName.c_str()); - return false; - } - return true; - } - if (!IsNeedUpdateBundleResourceInfo(bundleName, userId)) { - APP_LOGI("%{public}s userId %{public}d appIndex %{public}d no need to process", bundleName.c_str(), - userId, appIndex); - return true; - } - - if (!manager->AddResourceInfoByBundleName(bundleName, userId, appIndex)) { + if (!manager->DeleteDynamicIconResource(bundleName, userId, appIndex)) { APP_LOGE("%{public}s userId %{public}d appIndex %{public}d add resource failed", bundleName.c_str(), userId, appIndex); return false; diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index f22c7ce01d..d14d876022 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -12162,24 +12162,6 @@ HWTEST_F(BmsBundleInstallerTest, GetAllPreInstallBundleInfos_0100, Function | Me EXPECT_TRUE(ret); } -/** - * @tc.number: ProcessAddResourceInfo_0010 - * @tc.name: test ProcessAddResourceInfo - * @tc.desc: 1.Test the ProcessAddResourceInfo of BaseBundleInstaller -*/ -HWTEST_F(BmsBundleInstallerTest, ProcessAddResourceInfo_0010, Function | SmallTest | Level0) -{ - BaseBundleInstaller installer; - installer.isAppExist_ = true; - std::string testBudnleName = "com.example.u1Enable"; - InstallParam installParam; - installer.ProcessAddResourceInfo(installParam, testBudnleName, 1); - bool res = BundleResourceHelper::DeleteResourceInfo(testBudnleName, 1); - EXPECT_FALSE(res); - res = BundleResourceHelper::DeleteResourceInfo(testBudnleName, -1); - EXPECT_FALSE(res); -} - /** * @tc.number: ProcessExtProfile_0010 * @tc.name: test ProcessExtProfile diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index 3d2c8ceb1f..6fea458713 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -511,90 +511,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0012, Function | SmallTest EXPECT_FALSE(ans); } -/** - * @tc.number: BmsBundleResourceTest_0013 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByBundleName, bundle not exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0013, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - // bundle not exist - bool ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, USERID); - EXPECT_FALSE(ans); -} - -/** - * @tc.number: BmsBundleResourceTest_0014 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByBundleName, bundle exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0014, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - // bundle exist, userId not exist - bool ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, 200); - EXPECT_FALSE(ans); - - // bundle exist, userId exist - ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, USERID); - EXPECT_TRUE(ans); - - // delete key - ans = manager->DeleteResourceInfo(BUNDLE_NAME); - EXPECT_TRUE(ans); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0015 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByAbility, bundle exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0015, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - // bundle not exist - bool ans = manager->AddResourceInfoByAbility(BUNDLE_NAME, MODULE_NAME, ABILITY_NAME, USERID); - EXPECT_FALSE(ans); - - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - // bundle exist, moduleName or abilityName not exist - ans = manager->AddResourceInfoByAbility(BUNDLE_NAME, "xxx", "yyy", USERID); - EXPECT_FALSE(ans); - - // bundle moduleName exist, abilityName not exist - ans = manager->AddResourceInfoByAbility(BUNDLE_NAME, MODULE_NAME, "yyy", USERID); - EXPECT_FALSE(ans); - - // bundle moduleName exist, abilityName exist - ans = manager->AddResourceInfoByAbility(BUNDLE_NAME, MODULE_NAME, ABILITY_NAME, USERID); - EXPECT_TRUE(ans); - - // delete key - ans = manager->DeleteResourceInfo(BUNDLE_NAME); - EXPECT_TRUE(ans); - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: BmsBundleResourceTest_0016 * Function: BundleResourceManager @@ -2411,70 +2327,6 @@ HWTEST_F(BmsBundleResourceTest, ProcessBundleResourceInfo_0001, Function | Small EXPECT_EQ(unInstallResult, ERR_OK); } -/** - * @tc.number: ProcessResourceInfo_0001 - * @tc.name: test the start function of ProcessResourceInfo - * @tc.desc: 1. test ProcessResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, ProcessResourceInfo_0001, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::vector resourceInfos; - ResourceInfo info; - info.label_ = "xxx"; - info.icon_ = "yyy"; - manager->ProcessResourceInfo(resourceInfos, info); - EXPECT_FALSE(info.label_.empty()); - EXPECT_FALSE(info.icon_.empty()); - - info.label_ = ""; - info.icon_ = ""; - info.bundleName_ = "aaa"; - manager->ProcessResourceInfo(resourceInfos, info); - EXPECT_FALSE(info.label_.empty()); - EXPECT_FALSE(info.icon_.empty()); - - resourceInfos.emplace_back(info); - info.icon_ = ""; - manager->ProcessResourceInfo(resourceInfos, info); - EXPECT_FALSE(info.label_.empty()); - EXPECT_FALSE(info.icon_.empty()); - } -} - -/** - * @tc.number: AddResourceInfos_0001 - * @tc.name: test the start function of AddResourceInfos - * @tc.desc: 1. test AddResourceInfos - */ -HWTEST_F(BmsBundleResourceTest, AddResourceInfos_0001, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_NO_ICON); - EXPECT_EQ(installResult, ERR_OK); - - std::vector resourceInfos; - bool ans = BundleResourceProcess::GetResourceInfoByBundleName(BUNDLE_NAME_NO_ICON, USERID, resourceInfos); - EXPECT_TRUE(ans); - EXPECT_FALSE(resourceInfos.empty()); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - bool ret = manager->AddResourceInfosByMap(resourceInfosMap, 0, 0, USERID, USERID); - EXPECT_FALSE(ret); - resourceInfosMap[BUNDLE_NAME_NO_ICON] = resourceInfos; - ret = manager->AddResourceInfosByMap(resourceInfosMap, manager->currentTaskNum_, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), USERID, USERID); - EXPECT_TRUE(ret); - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME_NO_ICON); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: BmsBundleResourceTest_0105 * Function: BundleResourceManager @@ -3178,269 +3030,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0130, Function | SmallTest EXPECT_EQ(unInstallResult, ERR_OK); } -/** - * @tc.number: BmsBundleResourceTest_0140 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test UpdateBundleIcon - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0140, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME; - info.label_ = BUNDLE_NAME; - bool ret = manager->UpdateBundleIcon(BUNDLE_NAME, info); - EXPECT_TRUE(ret); - - BundleResourceInfo bundleResourceInfo; - ret = manager->GetBundleResourceInfo(BUNDLE_NAME, 1, bundleResourceInfo); - EXPECT_TRUE(ret); - EXPECT_EQ(info.bundleName_, bundleResourceInfo.bundleName); - EXPECT_EQ(info.label_, bundleResourceInfo.label); - EXPECT_TRUE(bundleResourceInfo.icon.empty()); - - ret = manager->DeleteResourceInfo(BUNDLE_NAME); - EXPECT_TRUE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0141 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test UpdateBundleIcon - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0141, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - BundleResourceInfo oldBundleResourceInfo; - bool ret = manager->GetBundleResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - oldBundleResourceInfo); - EXPECT_TRUE(ret); - EXPECT_EQ(oldBundleResourceInfo.bundleName, BUNDLE_NAME); - - ResourceInfo resourceInfo; - resourceInfo.appIndex_ = Constants::UNSPECIFIED_USERID; - resourceInfo.icon_ = "icon"; - resourceInfo.foreground_.push_back(1); - resourceInfo.background_.push_back(1); - ret = manager->UpdateBundleIcon(BUNDLE_NAME, resourceInfo); - EXPECT_TRUE(ret); - - BundleResourceInfo newBundleResourceInfo; - ret = manager->GetBundleResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - newBundleResourceInfo); - EXPECT_TRUE(ret); - EXPECT_EQ(newBundleResourceInfo.bundleName, oldBundleResourceInfo.bundleName); - EXPECT_EQ(newBundleResourceInfo.label, oldBundleResourceInfo.label); - EXPECT_EQ(newBundleResourceInfo.icon, resourceInfo.icon_); - EXPECT_EQ(newBundleResourceInfo.foreground.size(), resourceInfo.foreground_.size()); - EXPECT_FALSE(newBundleResourceInfo.foreground.empty()); - if (!newBundleResourceInfo.foreground.empty() && !resourceInfo.foreground_.empty()) { - EXPECT_EQ(newBundleResourceInfo.foreground[0], resourceInfo.foreground_[0]); - } - EXPECT_EQ(newBundleResourceInfo.background.size(), resourceInfo.background_.size()); - EXPECT_FALSE(newBundleResourceInfo.background.empty()); - if (!newBundleResourceInfo.background.empty() && !resourceInfo.background_.empty()) { - EXPECT_EQ(newBundleResourceInfo.background[0], resourceInfo.background_[0]); - } - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0142 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test UpdateBundleIcon - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0142, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::vector oldLauncherAbilityResourceInfos; - bool ret = manager->GetLauncherAbilityResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - oldLauncherAbilityResourceInfos); - EXPECT_TRUE(ret); - EXPECT_FALSE(oldLauncherAbilityResourceInfos.empty()); - - ResourceInfo resourceInfo; - resourceInfo.icon_ = "icon"; - resourceInfo.foreground_.push_back(1); - resourceInfo.background_.push_back(1); - ret = manager->UpdateBundleIcon(BUNDLE_NAME, resourceInfo); - EXPECT_TRUE(ret); - - std::vector newLauncherAbilityResourceInfos; - int32_t currentUserId = AccountHelper::GetCurrentActiveUserId(); - setuid(currentUserId * Constants::BASE_USER_RANGE); - ret = manager->GetLauncherAbilityResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - newLauncherAbilityResourceInfos); - setuid(Constants::ROOT_UID); - EXPECT_TRUE(ret); - EXPECT_FALSE(newLauncherAbilityResourceInfos.empty()); - if (!newLauncherAbilityResourceInfos.empty() && !oldLauncherAbilityResourceInfos.empty()) { - EXPECT_EQ(newLauncherAbilityResourceInfos[0].bundleName, oldLauncherAbilityResourceInfos[0].bundleName); - EXPECT_EQ(newLauncherAbilityResourceInfos[0].moduleName, oldLauncherAbilityResourceInfos[0].moduleName); - EXPECT_EQ(newLauncherAbilityResourceInfos[0].abilityName, oldLauncherAbilityResourceInfos[0].abilityName); - EXPECT_EQ(newLauncherAbilityResourceInfos[0].label, oldLauncherAbilityResourceInfos[0].label); - EXPECT_EQ(newLauncherAbilityResourceInfos[0].icon, resourceInfo.icon_); - EXPECT_EQ(newLauncherAbilityResourceInfos[0].foreground.size(), resourceInfo.foreground_.size()); - EXPECT_FALSE(newLauncherAbilityResourceInfos[0].foreground.empty()); - if (!newLauncherAbilityResourceInfos[0].foreground.empty() && !resourceInfo.foreground_.empty()) { - EXPECT_EQ(newLauncherAbilityResourceInfos[0].foreground[0], resourceInfo.foreground_[0]); - } - EXPECT_EQ(newLauncherAbilityResourceInfos[0].background.size(), resourceInfo.background_.size()); - EXPECT_FALSE(newLauncherAbilityResourceInfos[0].background.empty()); - if (!newLauncherAbilityResourceInfos[0].background.empty() && !resourceInfo.background_.empty()) { - EXPECT_EQ(newLauncherAbilityResourceInfos[0].background[0], resourceInfo.background_[0]); - } - } - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0143 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddCloneBundleResourceInfo, bundleName not exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0143, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ret = manager->AddCloneBundleResourceInfo(BUNDLE_NAME, 1); - EXPECT_FALSE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0144 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddCloneBundleResourceInfo, bundleName exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0144, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - BundleResourceInfo bundleResourceInfo; - bool ret = manager->GetBundleResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - bundleResourceInfo); - EXPECT_TRUE(ret); - // add clone bundle resource - int32_t appIndex = 1; - ret = manager->AddCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - BundleResourceInfo cloneBundleResourceInfo; - ret = manager->GetBundleResourceInfo(BUNDLE_NAME, static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - cloneBundleResourceInfo, appIndex); - EXPECT_TRUE(ret); - EXPECT_EQ(cloneBundleResourceInfo.bundleName, bundleResourceInfo.bundleName); - EXPECT_EQ(cloneBundleResourceInfo.appIndex, appIndex); - EXPECT_EQ(cloneBundleResourceInfo.label, bundleResourceInfo.label + std::to_string(appIndex)); - EXPECT_FALSE(cloneBundleResourceInfo.icon.empty()); - EXPECT_FALSE(cloneBundleResourceInfo.foreground.empty()); - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0145 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddCloneBundleResourceInfo, bundleName exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0145, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::vector launcherAbilityResourceInfos; - bool ret = manager->GetLauncherAbilityResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - launcherAbilityResourceInfos); - EXPECT_TRUE(ret); - // add clone bundle resource - int32_t appIndex = 1; - ret = manager->AddCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - - int32_t currentUserId = AccountHelper::GetCurrentActiveUserId(); - setuid(currentUserId * Constants::BASE_USER_RANGE); - std::vector cloneLauncherAbilityResourceInfos; - ret = manager->GetLauncherAbilityResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - cloneLauncherAbilityResourceInfos, appIndex); - setuid(Constants::ROOT_UID); - EXPECT_TRUE(ret); - EXPECT_EQ(launcherAbilityResourceInfos.size(), cloneLauncherAbilityResourceInfos.size()); - if (!launcherAbilityResourceInfos.empty() && !cloneLauncherAbilityResourceInfos.empty()) { - EXPECT_EQ(cloneLauncherAbilityResourceInfos[0].bundleName, launcherAbilityResourceInfos[0].bundleName); - EXPECT_EQ(cloneLauncherAbilityResourceInfos[0].moduleName, launcherAbilityResourceInfos[0].moduleName); - EXPECT_EQ(cloneLauncherAbilityResourceInfos[0].abilityName, launcherAbilityResourceInfos[0].abilityName); - EXPECT_EQ(cloneLauncherAbilityResourceInfos[0].label, - launcherAbilityResourceInfos[0].label + std::to_string(appIndex)); - EXPECT_EQ(cloneLauncherAbilityResourceInfos[0].appIndex, appIndex); - EXPECT_FALSE(cloneLauncherAbilityResourceInfos[0].icon.empty()); - EXPECT_FALSE(cloneLauncherAbilityResourceInfos[0].foreground.empty()); - } - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: BmsBundleResourceTest_0146 * Function: BundleResourceManager @@ -3515,7 +3104,7 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0175, Function | SmallTest auto manager = DelayedSingleton::GetInstance(); EXPECT_NE(manager, nullptr); if (manager != nullptr) { - ret = manager->AddAllResourceInfo(USERID, 0, 0); + ret = manager->AddAllResourceInfo(USERID, 0); EXPECT_TRUE(ret); } } @@ -3770,132 +3359,13 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0160, Function | SmallTest } /** - * @tc.number: BmsBundleResourceTest_0161 - * Function: InnerProcessWhetherThemeExist - * @tc.name: test user change - * @tc.desc: 1. system running normally - * 2. test InnerProcessWhetherThemeExist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0161, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ret = manager->InnerProcessWhetherThemeExist(BUNDLE_NAME, 0); - EXPECT_FALSE(ret); - ret = manager->InnerProcessWhetherThemeExist(BUNDLE_NAME, 100); - EXPECT_FALSE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0162 - * Function: DeleteNotExistResourceInfo - * @tc.name: test user change + * @tc.number: BmsBundleResourceTest_0166 + * Function: AddResourceInfoByAbility + * @tc.name: test * @tc.desc: 1. system running normally - * 2. test DeleteNotExistResourceInfo + * 2. test AddResourceInfoByAbility */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0162, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - ResourceInfo resourceInfo; - resourceInfo.bundleName_ = "notExist"; - std::vector resourceInfos; - resourceInfos.emplace_back(resourceInfo); - resourceInfo.appIndex_ = 1; - resourceInfos.emplace_back(resourceInfo); - resourceInfo.bundleName_ = "bundleName"; - resourceInfo.appIndex_ = 0; - resourceInfos.emplace_back(resourceInfo); - resourceInfo.appIndex_ = 1; - resourceInfos.emplace_back(resourceInfo); - resourceInfo.appIndex_ = 2; - resourceInfos.emplace_back(resourceInfo); - bool ret = manager->SaveResourceInfos(resourceInfos); - EXPECT_TRUE(ret); - std::vector existResourceNames; - existResourceNames.emplace_back("notExist"); - existResourceNames.emplace_back("1_notExist"); - existResourceNames.emplace_back("bundleName"); - existResourceNames.emplace_back("1_bundleName"); - existResourceNames.emplace_back("2_bundleName"); - std::map> resourceInfosMap; - ResourceInfo info; - info.appIndexes_.emplace_back(1); - resourceInfosMap["bundleName"].emplace_back(info); - manager->DeleteNotExistResourceInfo(resourceInfosMap, existResourceNames); - BundleResourceInfo bundleResourceInfo; - ret = manager->GetBundleResourceInfo("bundleName", - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), bundleResourceInfo); - EXPECT_TRUE(ret); - ret = manager->GetBundleResourceInfo("bundleName", - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), bundleResourceInfo, 1); - EXPECT_TRUE(ret); - ret = manager->GetBundleResourceInfo("bundleName", - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), bundleResourceInfo, 2); - EXPECT_FALSE(ret); - ret = manager->GetBundleResourceInfo("notExist", - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL), bundleResourceInfo); - EXPECT_FALSE(ret); - manager->DeleteResourceInfo("bundleName"); - manager->DeleteResourceInfo("1_bundleName"); - manager->DeleteResourceInfo("2_bundleName"); - manager->DeleteResourceInfo("notExist"); - manager->DeleteResourceInfo("1_notExist"); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0163 - * Function: AddCloneBundleResourceInfo - * @tc.name: test AddCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0163, Function | SmallTest | Level0) -{ - int32_t appIndex = 1; - bool ret = BundleResourceHelper::AddCloneBundleResourceInfo(BUNDLE_NAME, false, USERID); - EXPECT_FALSE(ret); -} - -/** - * @tc.number: BmsBundleResourceTest_0164 - * Function: DeleteCloneBundleResourceInfo - * @tc.name: test DeleteCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0164, Function | SmallTest | Level0) -{ - int32_t appIndex = 1; - bool ret = BundleResourceHelper::DeleteCloneBundleResourceInfo(BUNDLE_NAME, false, USERID); - EXPECT_TRUE(ret); -} - -/** - * @tc.number: BmsBundleResourceTest_0165 - * Function: AddResourceInfoByBundleName - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByBundleName - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0165, Function | SmallTest | Level0) -{ - std::shared_ptr bundleResourceHostImpl = std::make_shared(); - ASSERT_NE(bundleResourceHostImpl, nullptr); - auto ret = bundleResourceHostImpl->AddResourceInfoByBundleName("", USERID); - EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INVALID_PARAMETER); - ret = bundleResourceHostImpl->AddResourceInfoByBundleName(BUNDLE_NAME, USERID); - EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_INTERNAL_ERROR); -} - -/** - * @tc.number: BmsBundleResourceTest_0166 - * Function: AddResourceInfoByAbility - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByAbility - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0166, Function | SmallTest | Level0) +HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0166, Function | SmallTest | Level0) { std::shared_ptr bundleResourceHostImpl = std::make_shared(); ASSERT_NE(bundleResourceHostImpl, nullptr); @@ -3984,37 +3454,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0170, Function | SmallTest EXPECT_NE(subscriberPtr, nullptr); } -/** - * @tc.number: BmsBundleResourceTest_0171 - * Function: UpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0171, Function | SmallTest | Level0) -{ - ResourceInfo resourceInfo; - std::string bundleName = "bundleName/moduleName/abilityName"; - int32_t appIndex = 1; - uint32_t type = static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE); - resourceInfo.bundleName_ = bundleName; - resourceInfo.icon_ = "data:image/png"; - resourceInfo.foreground_.push_back(1); - resourceInfo.label_ = "xxxx"; - - auto manager = DelayedSingleton::GetInstance(); - ASSERT_NE(manager, nullptr); - bool ret = manager->bundleResourceRdb_->AddResourceInfo(resourceInfo); - EXPECT_TRUE(ret); - ret = manager->UpdateCloneBundleResourceInfo(bundleName, appIndex, 0); - EXPECT_FALSE(ret); - ret = manager->UpdateCloneBundleResourceInfo(bundleName, appIndex, type); - EXPECT_FALSE(ret); - // delete key - ret = manager->DeleteResourceInfo(resourceInfo.GetKey()); - EXPECT_TRUE(ret); -} - /** * @tc.number: BmsBundleResourceTest_0172 * Function: ProcessResourceInfoNoNeedToParseOtherIcon @@ -4053,23 +3492,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0173, Function | SmallTest EXPECT_TRUE(ret); } -/** - * @tc.number: BmsBundleResourceTest_0174 - * Function: DeleteResourceInfo - * @tc.name: test DeleteResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0174, Function | SmallTest | Level0) -{ - BundleResourceHelper::BundleSystemStateInit(); - BundleResourceHelper::RegisterConfigurationObserver(); - BundleResourceHelper::RegisterCommonEventSubscriber(); - BundleResourceHelper::AddResourceInfoByBundleName(BUNDLE_NAME, 100); - - std::string key; - bool ret = BundleResourceHelper::DeleteResourceInfo(key); - EXPECT_FALSE(ret); -} - /** * @tc.number: BmsBundleResourceTest_0176 * Function: DeleteResourceInfo @@ -4124,32 +3546,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0186, Function | SmallTest EXPECT_FALSE(ret); } -/** - * @tc.number: BmsBundleResourceTest_0187 - * Function: GetIconResourceByTheme - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test GetIconResourceByTheme - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0187, Function | SmallTest | Level0) -{ - BundleResourceParser parse; - std::vector resourceInfos; - parse.ProcessSpecialBundleResource(100, resourceInfos); - EXPECT_TRUE(resourceInfos.empty()); - ResourceInfo resourceInfo; - resourceInfo.icon_ = "1"; - resourceInfos.emplace_back(resourceInfo); - parse.ProcessSpecialBundleResource(100, resourceInfos); - EXPECT_EQ(resourceInfos[0].icon_, resourceInfo.icon_); - - resourceInfos.clear(); - resourceInfo.bundleName_ = "com.ohos.contacts"; - resourceInfos.emplace_back(resourceInfo); - parse.ProcessSpecialBundleResource(100, resourceInfos); - EXPECT_EQ(resourceInfos[0].icon_, resourceInfo.icon_); -} - /** * @tc.number: BmsBundleResourceTest_0188 * Function: ChangeDynamicIcon @@ -4221,104 +3617,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0191, Function | SmallTest } } -/** - * @tc.number: BmsBundleResourceTest_0192 - * Function: ProcessUpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test ProcessUpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0192, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ret = manager->ProcessUpdateCloneBundleResourceInfo(BUNDLE_NAME_NOT_EXIST); - EXPECT_TRUE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0193 - * Function: ProcessUpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test ProcessUpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0193, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); - InnerBundleCloneInfo cloneInfo; - cloneInfo.appIndex = 1; - InnerBundleUserInfo userInfo; - userInfo.cloneInfos["1"] = cloneInfo; - InnerBundleInfo bundleInfo; - bundleInfo.innerBundleUserInfos_["100"] = userInfo; - savedDataMgr->bundleInfos_[BUNDLE_NAME_NOT_EXIST] = bundleInfo; - - bool ret = manager->ProcessUpdateCloneBundleResourceInfo(BUNDLE_NAME_NOT_EXIST); - EXPECT_FALSE(ret); - - auto iter = savedDataMgr->bundleInfos_.find(BUNDLE_NAME_NOT_EXIST); - if (iter != savedDataMgr->bundleInfos_.end()) { - savedDataMgr->bundleInfos_.erase(iter); - } - } -} - -/** - * @tc.number: BmsBundleResourceTest_0194 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByBundleName, bundle not exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0194, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, USERID, APP_INDEX); - EXPECT_FALSE(ans); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0195 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddResourceInfoByBundleName, bundle exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0195, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - // bundle exist, userId exist, appIndex = 0 - bool ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, USERID, 0); - EXPECT_TRUE(ans); - - // bundle exist, userId exist, appIndex = 1 - ans = manager->AddResourceInfoByBundleName(BUNDLE_NAME, USERID, APP_INDEX); - EXPECT_TRUE(ans); - - // delete key - ans = manager->DeleteResourceInfo(BUNDLE_NAME); - EXPECT_TRUE(ans); - - ans = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, APP_INDEX); - EXPECT_TRUE(ans); - } - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: BmsBundleResourceTest_0196 * Function: BundleResourceManager @@ -4452,169 +3750,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0200, Function | SmallTest EXPECT_FALSE(ret); } -/** - * @tc.number: BmsBundleResourceTest_0201 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddCloneBundleResourceInfo, bundleName not exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0201, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - // add clone bundle resource - int32_t appIndex = 1; - bool ret = manager->AddCloneBundleResourceInfo(BUNDLE_NAME, appIndex, USERID); - EXPECT_FALSE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0202 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test AddCloneBundleResourceInfo, bundleName exist - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0202, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - BundleResourceInfo bundleResourceInfo; - bool ret = manager->GetBundleResourceInfo(BUNDLE_NAME, - static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - bundleResourceInfo); - EXPECT_TRUE(ret); - // add clone bundle resource - int32_t appIndex = 1; - ret = manager->AddCloneBundleResourceInfo(BUNDLE_NAME, appIndex, USERID); - EXPECT_TRUE(ret); - BundleResourceInfo cloneBundleResourceInfo; - ret = manager->GetBundleResourceInfo(BUNDLE_NAME, static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR), - cloneBundleResourceInfo, appIndex); - EXPECT_TRUE(ret); - EXPECT_EQ(cloneBundleResourceInfo.bundleName, bundleResourceInfo.bundleName); - EXPECT_EQ(cloneBundleResourceInfo.appIndex, appIndex); - EXPECT_EQ(cloneBundleResourceInfo.label, bundleResourceInfo.label + std::to_string(appIndex)); - EXPECT_FALSE(cloneBundleResourceInfo.icon.empty()); - EXPECT_FALSE(cloneBundleResourceInfo.foreground.empty()); - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0203 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0203, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, USERID, 0, 0); - EXPECT_FALSE(ret); - - ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); - EXPECT_FALSE(ret); - - ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)); - EXPECT_FALSE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0204 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0204, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - int32_t appIndex = 1; - bool ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, USERID, appIndex, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)); - EXPECT_TRUE(ret); - - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, appIndex); - EXPECT_TRUE(ret); - } - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0205 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test BundleResourceConvertToResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0205, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - BundleResourceInfo bundleResourceInfo; - bundleResourceInfo.label = "label"; - ResourceInfo resourceInfo; - manager->BundleResourceConvertToResourceInfo(bundleResourceInfo, resourceInfo); - EXPECT_EQ(bundleResourceInfo.label, resourceInfo.label_); - - ResourceInfo resourceInfo2; - resourceInfo2.appIndex_ = 1; - manager->BundleResourceConvertToResourceInfo(bundleResourceInfo, resourceInfo2); - EXPECT_NE(bundleResourceInfo.label, resourceInfo2.label_); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0206 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test LauncherAbilityResourceConvertToResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0206, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - LauncherAbilityResourceInfo launcherAbilityResourceInfo; - launcherAbilityResourceInfo.label = "label"; - ResourceInfo resourceInfo; - manager->LauncherAbilityResourceConvertToResourceInfo(launcherAbilityResourceInfo, resourceInfo); - EXPECT_EQ(launcherAbilityResourceInfo.label, resourceInfo.label_); - - ResourceInfo resourceInfo2; - resourceInfo2.appIndex_ = 1; - manager->LauncherAbilityResourceConvertToResourceInfo(launcherAbilityResourceInfo, resourceInfo2); - EXPECT_NE(launcherAbilityResourceInfo.label, resourceInfo2.label_); - } -} - /** * @tc.number: BmsBundleResourceTest_0207 * Function: BundleResourceManager @@ -5289,29 +4424,6 @@ HWTEST_F(BmsBundleResourceTest, ProcessForegroundIcon_0010, Function | SmallTest EXPECT_FALSE(ret); } -/** - * @tc.number: ParseResourceInfos_0010 - * Function: BundleResourceParser - * @tc.name: test BundleResourceParser - * @tc.desc: 1. system running normally - * 2. test ParseResourceInfos - */ -HWTEST_F(BmsBundleResourceTest, ParseResourceInfos_0010, Function | SmallTest | Level0) -{ - ResourceInfo resourceInfo; - resourceInfo.bundleName_ = BUNDLE_NAME; - resourceInfo.label_ = BUNDLE_NAME; - resourceInfo.labelId_ = 0; - resourceInfo.iconId_ = 0; - resourceInfo.hasThemeIcon_ = true; - std::vector resourceInfos; - resourceInfos.push_back(resourceInfo); - - BundleResourceParser parser; - bool ans = parser.ParseResourceInfos(USERID, resourceInfos); - EXPECT_FALSE(ans); -} - /** * @tc.number: IsOnlineTheme_0010 * Function: IsOnlineTheme @@ -5593,279 +4705,6 @@ HWTEST_F(BmsBundleResourceTest, CheckThemeType_0080, Function | SmallTest | Leve OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); } -/** - * @tc.number: FilterResourceInfoWhenSystemThemeChanged_0010 - * Function: FilterResourceInfoWhenSystemThemeChanged - * @tc.name: test system theme change - * @tc.desc: 1. system running normally - * 2. test FilterResourceInfoWhenSystemThemeChanged - */ -HWTEST_F(BmsBundleResourceTest, FilterResourceInfoWhenSystemThemeChanged_0010, Function | SmallTest | Level0) -{ - // flag exist in A, icons exist in A and B - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); - std::ofstream file; - file.open(THEME_A_FLAG_BUNDLE_NAME, ios::out); - file << "" << endl; - file.close(); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME_NOT_EXIST; - resourceInfosMap[BUNDLE_NAME_NOT_EXIST].emplace_back(info); - // theme not exist - manager->FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); - EXPECT_TRUE(resourceInfosMap.empty()); - } - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); -} - -/** - * @tc.number: FilterResourceInfoWhenSystemThemeChanged_0020 - * Function: FilterResourceInfoWhenSystemThemeChanged - * @tc.name: test system theme change - * @tc.desc: 1. system running normally - * 2. test FilterResourceInfoWhenSystemThemeChanged - */ -HWTEST_F(BmsBundleResourceTest, FilterResourceInfoWhenSystemThemeChanged_0020, Function | SmallTest | Level0) -{ - // flag exist in A, icons exist in A and B - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); - std::ofstream file; - file.open(THEME_A_FLAG_BUNDLE_NAME, ios::out); - file << "" << endl; - file.close(); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME; - resourceInfosMap[BUNDLE_NAME].emplace_back(info); - ResourceInfo info2; - info2.bundleName_ = BUNDLE_NAME_NOT_EXIST; - resourceInfosMap[BUNDLE_NAME_NOT_EXIST].emplace_back(info2); - manager->FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); - EXPECT_EQ(resourceInfosMap.size(), 1); - if (resourceInfosMap.find(BUNDLE_NAME) != resourceInfosMap.end()) { - EXPECT_TRUE(resourceInfosMap[BUNDLE_NAME][0].hasThemeIcon_); - } - } - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); -} - -/** - * @tc.number: FilterResourceInfoWhenSystemThemeChanged_0030 - * Function: FilterResourceInfoWhenSystemThemeChanged - * @tc.name: test system theme change - * @tc.desc: 1. system running normally - * 2. test FilterResourceInfoWhenSystemThemeChanged - */ -HWTEST_F(BmsBundleResourceTest, FilterResourceInfoWhenSystemThemeChanged_0030, Function | SmallTest | Level0) -{ - // flag exist in B, icons exist in A and B - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME; - resourceInfosMap[BUNDLE_NAME].emplace_back(info); - ResourceInfo info2; - info2.bundleName_ = BUNDLE_NAME_NOT_EXIST; - resourceInfosMap[BUNDLE_NAME_NOT_EXIST].emplace_back(info2); - manager->FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); - EXPECT_EQ(resourceInfosMap.size(), 1); - if (resourceInfosMap.find(BUNDLE_NAME) != resourceInfosMap.end()) { - EXPECT_TRUE(resourceInfosMap[BUNDLE_NAME][0].hasThemeIcon_); - } - } - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); -} - -/** - * @tc.number: FilterResourceInfoWhenSystemThemeChanged_0040 - * Function: FilterResourceInfoWhenSystemThemeChanged - * @tc.name: test system theme change - * @tc.desc: 1. system running normally - * 2. test FilterResourceInfoWhenSystemThemeChanged - */ -HWTEST_F(BmsBundleResourceTest, FilterResourceInfoWhenSystemThemeChanged_0040, Function | SmallTest | Level0) -{ - // flag exist in A, icons exist in B - OHOS::ForceCreateDirectory(THEME_A_ICON_JSON_BUNDLE_NAME); - OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); - std::ofstream file; - file.open(THEME_A_FLAG_BUNDLE_NAME, ios::out); - file << "" << endl; - file.close(); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME; - resourceInfosMap[BUNDLE_NAME].emplace_back(info); - ResourceInfo info2; - info2.bundleName_ = BUNDLE_NAME_NOT_EXIST; - resourceInfosMap[BUNDLE_NAME_NOT_EXIST].emplace_back(info2); - manager->FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); - EXPECT_EQ(resourceInfosMap.size(), 1); - if (resourceInfosMap.find(BUNDLE_NAME) != resourceInfosMap.end()) { - EXPECT_FALSE(resourceInfosMap[BUNDLE_NAME][0].hasThemeIcon_); - } - } - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); -} - -/** - * @tc.number: FilterResourceInfoWhenSystemThemeChanged_0050 - * Function: FilterResourceInfoWhenSystemThemeChanged - * @tc.name: test system theme change - * @tc.desc: 1. system running normally - * 2. test FilterResourceInfoWhenSystemThemeChanged - */ -HWTEST_F(BmsBundleResourceTest, FilterResourceInfoWhenSystemThemeChanged_0050, Function | SmallTest | Level0) -{ - // flag exist in B, icons exist in A and B - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - OHOS::ForceCreateDirectory(THEME_B_ICON_JSON_BUNDLE_NAME); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - ResourceInfo info; - info.bundleName_ = BUNDLE_NAME; - resourceInfosMap[BUNDLE_NAME].emplace_back(info); - ResourceInfo info2; - info2.bundleName_ = BUNDLE_NAME_NOT_EXIST; - resourceInfosMap[BUNDLE_NAME_NOT_EXIST].emplace_back(info2); - manager->FilterResourceInfoWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); - EXPECT_EQ(resourceInfosMap.size(), 1); - if (resourceInfosMap.find(BUNDLE_NAME) != resourceInfosMap.end()) { - EXPECT_FALSE(resourceInfosMap[BUNDLE_NAME][0].hasThemeIcon_); - } - } - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); -} - -/** - * @tc.number: UpdateCloneBundleResourceInfo_0010 - * Function: UpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, UpdateCloneBundleResourceInfo_0010, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - bool ret = manager->UpdateCloneBundleResourceInfo(THEME_TEST_BUNDLE_NAME, USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); - EXPECT_TRUE(ret); - ret = manager->DeleteCloneBundleResourceInfo(THEME_TEST_BUNDLE_NAME, 1); - EXPECT_TRUE(ret); - } -} - -/** - * @tc.number: UpdateCloneBundleResourceInfo_0020 - * Function: UpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, UpdateCloneBundleResourceInfo_0020, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - std::ofstream file; - file.open(THEME_A_FLAG_BUNDLE_NAME, ios::out); - file << "" << endl; - file.close(); - // description.json not exist - bool ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, THEME_TEST_USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); - EXPECT_TRUE(ret); - - // description.json exist - std::ofstream file2; - file2.open(THEME_A_ICON_JSON_BUNDLE_NAME, ios::out); - file2 << "{\"origin\":\"online\"}" << endl; - file2.close(); - - ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, THEME_TEST_USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); - EXPECT_TRUE(ret); - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, 1); - EXPECT_TRUE(ret); - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); - } - - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: UpdateCloneBundleResourceInfo_0030 - * Function: UpdateCloneBundleResourceInfo - * @tc.name: test - * @tc.desc: 1. system running normally - * 2. test UpdateCloneBundleResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, UpdateCloneBundleResourceInfo_0030, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - OHOS::ForceCreateDirectory(THEME_A_ICON_BUNDLE_NAME); - std::ofstream file; - file.open(THEME_A_FLAG_BUNDLE_NAME, ios::out); - file << "" << endl; - file.close(); - // description.json exist - std::ofstream file2; - file2.open(THEME_A_ICON_JSON_BUNDLE_NAME, ios::out); - file2 << "{\"origin\":\"preset\"}" << endl; - file2.close(); - bool ret = manager->UpdateCloneBundleResourceInfo(BUNDLE_NAME, THEME_TEST_USERID, 1, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); - EXPECT_TRUE(ret); - ret = manager->DeleteCloneBundleResourceInfo(BUNDLE_NAME, 1); - EXPECT_TRUE(ret); - - OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); - } - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - /** * @tc.number: GetDynamicIcon_0010 * Function: BundleResourceManager @@ -5915,39 +4754,6 @@ HWTEST_F(BmsBundleResourceTest, GetDynamicIcon_0010, Function | SmallTest | Leve OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); } -/** - * @tc.number: InnerProcessResourceInfoByUserIdChanged_0010 - * Function: BundleResourceManager - * @tc.name: test BundleResourceManager - * @tc.desc: 1. system running normally - * 2. test InnerProcessResourceInfoByUserIdChanged - */ -HWTEST_F(BmsBundleResourceTest, InnerProcessResourceInfoByUserIdChanged_0010, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - std::map> resourceInfosMap; - std::vector resourceInfos; - ResourceInfo resourceInfo; - resourceInfos.push_back(resourceInfo); - resourceInfosMap["bundleName"] = resourceInfos; - manager->InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, 100, 101); - EXPECT_TRUE(resourceInfosMap.empty()); - - resourceInfos.clear(); - resourceInfo.hasDynamicIcon_ = true; - resourceInfos.push_back(resourceInfo); - resourceInfosMap["bundleName"] = resourceInfos; - manager->InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, 100, 101); - EXPECT_FALSE(resourceInfosMap.empty()); - EXPECT_FALSE(resourceInfosMap["bundleName"].empty()); - if (!resourceInfosMap["bundleName"].empty()) { - EXPECT_TRUE(resourceInfosMap["bundleName"][0].hasDynamicIcon_); - } - } -} - /** * @tc.number: IsDynamicIconModuleExist_0010 * Function: BundleResourceManager @@ -6124,102 +4930,6 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0185, Function | SmallTest #endif } -/** - * @tc.number: BmsBundleResourceTest_0230 - * @tc.name: CheckAllAddResourceInfo - * @tc.desc: 1. test CheckAllAddResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0230, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - EXPECT_NE(manager, nullptr); - if (manager != nullptr) { - auto ret = manager->CheckAllAddResourceInfo(THEME_TEST_USERID); - EXPECT_FALSE(ret); - } -} - -/** - * @tc.number: BmsBundleResourceTest_0240 - * @tc.name: GetResourceInfoForRequestUser - * @tc.desc: 1. test GetResourceInfoForRequestUser - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0240, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - ASSERT_NE(manager, nullptr); - std::vector launcherAbilityResourceInfos; - int32_t userId = -1; - std::string bundleName = "bundleName"; - uint32_t flag = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); - - auto ret = manager->GetResourceInfoForRequestUser(bundleName, userId, flag, - 0, launcherAbilityResourceInfos); - EXPECT_FALSE(ret); -} - -/** - * @tc.number: BmsBundleResourceTest_0250 - * @tc.name: GetResourceInfoForRequestUser - * @tc.desc: 1. test GetResourceInfoForRequestUser - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0250, Function | SmallTest | Level0) -{ - ErrCode installResult = InstallBundle(HAP_FILE_PATH1); - EXPECT_EQ(installResult, ERR_OK); - - auto manager = DelayedSingleton::GetInstance(); - ASSERT_NE(manager, nullptr); - std::vector launcherAbilityResourceInfos; - std::string bundleName = "bundleName"; - uint32_t flag = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); - - auto ret = manager->GetResourceInfoForRequestUser(BUNDLE_NAME, USERID, flag, - 0, launcherAbilityResourceInfos); - EXPECT_TRUE(ret); - - ret = manager->GetResourceInfoForRequestUser(BUNDLE_NAME, USERID, flag, - 1, launcherAbilityResourceInfos); - EXPECT_FALSE(ret); - ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); - EXPECT_EQ(unInstallResult, ERR_OK); -} - -/** - * @tc.number: BmsBundleResourceTest_0251 - * @tc.name: ConvertLauncherAbilityResourceInfo - * @tc.desc: 1. test ConvertLauncherAbilityResourceInfo - */ -HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0251, Function | SmallTest | Level0) -{ - auto manager = DelayedSingleton::GetInstance(); - ASSERT_NE(manager, nullptr); - ResourceInfo resourceInfo; - uint32_t flags = 0; - LauncherAbilityResourceInfo launcherAbilityResourceInfo; - auto ret = manager->ConvertLauncherAbilityResourceInfo(resourceInfo, - flags, launcherAbilityResourceInfo); - EXPECT_FALSE(ret); - - resourceInfo.moduleName_ = "moduleName"; - resourceInfo.abilityName_ = "abilityName"; - ret = manager->ConvertLauncherAbilityResourceInfo(resourceInfo, - flags, launcherAbilityResourceInfo); - EXPECT_TRUE(ret); - - flags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR); - ret = manager->ConvertLauncherAbilityResourceInfo(resourceInfo, - flags, launcherAbilityResourceInfo); - EXPECT_TRUE(ret); - - flags = static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL) | - static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON); - ret = manager->ConvertLauncherAbilityResourceInfo(resourceInfo, - flags, launcherAbilityResourceInfo); - EXPECT_TRUE(ret); -} - /** * @tc.number: BmsBundleResourceTest_0252 * @tc.name: GetLauncherAbilityResourceInfo diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehelpersecond_fuzzer/bmsbundleresourcehelpersecond_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehelpersecond_fuzzer/bmsbundleresourcehelpersecond_fuzzer.cpp index aa219a0af1..bbc58ffee6 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehelpersecond_fuzzer/bmsbundleresourcehelpersecond_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehelpersecond_fuzzer/bmsbundleresourcehelpersecond_fuzzer.cpp @@ -43,10 +43,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) bundleresourcehelper->BundleSystemStateInit(); bundleresourcehelper->RegisterConfigurationObserver(); bundleresourcehelper->RegisterCommonEventSubscriber(); - bundleresourcehelper->AddResourceInfoByBundleName(bundleName, USERID); - bundleresourcehelper->AddResourceInfoByBundleName(bundleName, userId); - bundleresourcehelper->DeleteResourceInfo(key, userId); - bundleresourcehelper->DeleteResourceInfo(key, USERID); + bundleresourcehelper->AddResourceInfoByBundleName(bundleName, USERID, ADD_RESOURCE_TYPE::INSTALL_BUNDLE, true); + bundleresourcehelper->AddResourceInfoByBundleName(bundleName, userId, ADD_RESOURCE_TYPE::INSTALL_BUNDLE, true); bundleresourcehelper->DeleteAllResourceInfo(); std::vector resourceNames; bundleresourcehelper->GetAllBundleResourceName(resourceNames); @@ -54,10 +52,8 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); bundleresourcehelper->SetOverlayEnabled(bundleName, moduleName, true, userId); int32_t appIndex = fdp.ConsumeIntegral(); - bundleresourcehelper->AddCloneBundleResourceInfo(bundleName, appIndex, USERID); - bundleresourcehelper->AddCloneBundleResourceInfo(bundleName, appIndex, userId); - bundleresourcehelper->DeleteCloneBundleResourceInfo(bundleName, appIndex, USERID); - bundleresourcehelper->DeleteCloneBundleResourceInfo(bundleName, appIndex, userId); + bundleresourcehelper->DeleteCloneBundleResourceInfo(bundleName, USERID, appIndex, true); + bundleresourcehelper->DeleteCloneBundleResourceInfo(bundleName, userId, appIndex, false); bundleresourcehelper->DeleteNotExistResourceInfo(); uint32_t flags = fdp.ConsumeIntegral(); BundleResourceInfo bundleResourceInfo; diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcemanager_fuzzer/bmsbundleresourcemanager_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcemanager_fuzzer/bmsbundleresourcemanager_fuzzer.cpp index a7a47a05eb..c556942317 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcemanager_fuzzer/bmsbundleresourcemanager_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcemanager_fuzzer/bmsbundleresourcemanager_fuzzer.cpp @@ -39,11 +39,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); int32_t userId = GenerateRandomUser(fdp); - manager->AddResourceInfoByBundleName(bundleName, USERID); - manager->AddResourceInfoByBundleName(bundleName, userId); int32_t appIndex = fdp.ConsumeIntegral(); - manager->AddResourceInfoByBundleName(bundleName, userId, appIndex); - manager->AddResourceInfoByBundleName(bundleName, userId, 0); ResourceInfo resourceInfo; resourceInfo.bundleName_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); resourceInfo.label_ = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); @@ -61,46 +57,16 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) manager->DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - manager->AddResourceInfoByAbility(bundleName, MODULE_NAME, ABILITY_NAME, USERID); - manager->AddResourceInfoByAbility(bundleName, moduleName, abilityName, userId); - manager->AddAllResourceInfo(USERID, 0, 0); + manager->AddAllResourceInfo(USERID, 0); uint32_t type = fdp.ConsumeIntegral(); int32_t oldUserId = fdp.ConsumeIntegral(); - manager->AddAllResourceInfo(userId, type, oldUserId); - manager->AddResourceInfo(USERID, resourceInfo); - manager->AddResourceInfo(userId, resourceInfo); - manager->AddResourceInfos(userId, resourceInfos); - manager->AddResourceInfos(userId, resourceInfos2); - manager->InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), userId, oldUserId); - manager->InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, - static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), userId, oldUserId); - manager->InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE), userId, oldUserId); - manager->InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, type, userId, oldUserId); + manager->AddAllResourceInfo(userId, type); manager->InnerProcessResourceInfoBySystemLanguageChanged(resourceInfosMap); manager->InnerProcessResourceInfoBySystemThemeChanged(resourceInfosMap, userId); - manager->CheckAllAddResourceInfo(userId); - manager->CheckAllAddResourceInfo(oldUserId); - manager->InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, USERID, USERID); - manager->InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, userId, oldUserId); - manager->InnerProcessWhetherThemeExist(bundleName, userId); uint32_t tempTaskNumber = fdp.ConsumeIntegral(); - manager->AddResourceInfosByMap(resourceInfosMap, manager->currentTaskNum_, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), USERID, USERID); - manager->AddResourceInfosByMap(resourceInfosMap2, manager->currentTaskNum_, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), USERID, USERID); - manager->AddResourceInfosByMap(resourceInfosMap2, manager->currentTaskNum_, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), userId, userId); - manager->AddResourceInfosByMap(resourceInfosMap, manager->currentTaskNum_, type, userId, userId); - manager->AddResourceInfosByMap(resourceInfosMap, tempTaskNumber, type, userId, userId); - manager->ProcessResourceInfo(resourceInfos, resourceInfo); ResourceInfo resourceInfo2; resourceInfo2.label_ = ""; resourceInfo2.icon_ = ""; - manager->ProcessResourceInfo(resourceInfos, resourceInfo2); - manager->ProcessResourceInfo(resourceInfos2, resourceInfo); - manager->ProcessResourceInfo(resourceInfos2, resourceInfo2); manager->DeleteResourceInfo(bundleName); std::vector keyNames; manager->GetAllResourceName(keyNames); @@ -141,27 +107,13 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) manager->ProcessResourceInfoWhenParseFailed(resourceInfo2); manager->ProcessResourceInfoWhenParseFailed(resourceInfo3); manager->ProcessResourceInfoWhenParseFailed(resourceInfo4); - manager->SaveResourceInfos(resourceInfos); - manager->SaveResourceInfos(resourceInfos2); manager->GetDefaultIcon(resourceInfo); manager->SendBundleResourcesChangedEvent(userId, type); std::string targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); manager->GetTargetBundleName(bundleName, targetBundleName); - manager->UpdateBundleIcon(bundleName, resourceInfo); - manager->UpdateBundleIcon(bundleName, resourceInfo2); - manager->UpdateBundleIcon(bundleName, resourceInfo3); - manager->UpdateBundleIcon(bundleName, resourceInfo4); - manager->AddCloneBundleResourceInfo(bundleName, appIndex, Constants::UNSPECIFIED_USERID); - manager->AddCloneBundleResourceInfo(bundleName, appIndex, userId); - manager->DeleteCloneBundleResourceInfo(bundleName, appIndex); - manager->GetBundleResourceInfoForCloneBundle(bundleName, appIndex, resourceInfos); - manager->UpdateCloneBundleResourceInfo(bundleName, 1, - static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)); - manager->UpdateCloneBundleResourceInfo(bundleName, 1, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)); - manager->UpdateCloneBundleResourceInfo(bundleName, appIndex, - static_cast(BundleResourceChangeType::SYSTEM_USER_ID_CHANGE)); - manager->UpdateCloneBundleResourceInfo(bundleName, appIndex, type); + manager->GetBundleResourceInfoForCloneBundle(bundleName, appIndex, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), resourceInfos); + std::vector extensionAbilityResourceInfo; manager->GetExtensionAbilityResourceInfo(bundleName, ExtensionAbilityType::RECENT_PHOTO, flags, extensionAbilityResourceInfo, appIndex); @@ -170,19 +122,14 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) manager->DeleteAllResourceInfo(); manager->ProcessResourceInfoNoNeedToParseOtherIcon(resourceInfos); manager->PrepareSysRes(); - manager->ProcessUpdateCloneBundleResourceInfo(bundleName); BundleResourceInfo bundleResourceInfo; bundleResourceInfo.appIndex = Constants::UNSPECIFIED_USERID; BundleResourceInfo bundleResourceInfo2; bundleResourceInfo2.appIndex = fdp.ConsumeIntegral(); - manager->BundleResourceConvertToResourceInfo(bundleResourceInfo, resourceInfo); - manager->BundleResourceConvertToResourceInfo(bundleResourceInfo2, resourceInfo); LauncherAbilityResourceInfo launcherAbilityResourceInfo; launcherAbilityResourceInfo.appIndex = Constants::UNSPECIFIED_USERID; LauncherAbilityResourceInfo launcherAbilityResourceInfo2; launcherAbilityResourceInfo2.appIndex = fdp.ConsumeIntegral(); - manager->LauncherAbilityResourceConvertToResourceInfo(launcherAbilityResourceInfo, resourceInfo); - manager->LauncherAbilityResourceConvertToResourceInfo(launcherAbilityResourceInfo2, resourceInfo); manager->IsLauncherAbility(launcherAbilityResourceInfo, abilityInfos); return true; } diff --git a/test/fuzztest/fuzztest_others/bmsbundleresourcehelper_fuzzer/bmsbundleresourcehelper_fuzzer.cpp b/test/fuzztest/fuzztest_others/bmsbundleresourcehelper_fuzzer/bmsbundleresourcehelper_fuzzer.cpp index 25cab360b4..20845714d6 100644 --- a/test/fuzztest/fuzztest_others/bmsbundleresourcehelper_fuzzer/bmsbundleresourcehelper_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/bmsbundleresourcehelper_fuzzer/bmsbundleresourcehelper_fuzzer.cpp @@ -30,8 +30,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) BundleResourceHelper::RegisterConfigurationObserver(); BundleResourceHelper::RegisterCommonEventSubscriber(); std::string bundleName(data, size); - BundleResourceHelper::AddResourceInfoByBundleName(bundleName, USERID); - BundleResourceHelper::DeleteResourceInfo(bundleName); + BundleResourceHelper::AddResourceInfoByBundleName(bundleName, USERID, ADD_RESOURCE_TYPE::INSTALL_BUNDLE, true); BundleResourceHelper::DeleteAllResourceInfo(); std::vector resourceNames; BundleResourceHelper::GetAllBundleResourceName(resourceNames); @@ -39,8 +38,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::string moduleName(data, size); BundleResourceHelper::SetOverlayEnabled(bundleName, moduleName, true, USERID); int32_t appIndex = 0; - BundleResourceHelper::AddCloneBundleResourceInfo(bundleName, appIndex, USERID); - BundleResourceHelper::DeleteCloneBundleResourceInfo(bundleName, appIndex, USERID); + BundleResourceHelper::AddCloneBundleResourceInfo(bundleName, USERID, appIndex, true); + BundleResourceHelper::DeleteCloneBundleResourceInfo(bundleName, USERID, appIndex, false); BundleResourceHelper::DeleteNotExistResourceInfo(); return true; } diff --git a/test/fuzztest/fuzztest_others/bundleresmgr_fuzzer/bundleresmgr_fuzzer.cpp b/test/fuzztest/fuzztest_others/bundleresmgr_fuzzer/bundleresmgr_fuzzer.cpp index 5d026b118b..71b2e080dd 100644 --- a/test/fuzztest/fuzztest_others/bundleresmgr_fuzzer/bundleresmgr_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/bundleresmgr_fuzzer/bundleresmgr_fuzzer.cpp @@ -32,11 +32,9 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { auto manager = DelayedSingleton::GetInstance(); std::string bundleName(data, size); - manager->AddResourceInfoByBundleName(bundleName, USERID); manager->DeleteResourceInfo(bundleName); - manager->AddAllResourceInfo(USERID, 0, 0); + manager->AddAllResourceInfo(USERID, 0); manager->DeleteAllResourceInfo(); - manager->AddResourceInfoByAbility(bundleName, MODULE_NAME, ABILITY_NAME, USERID); std::vector keyNames; manager->GetAllResourceName(keyNames); BundleResourceInfo info; @@ -48,40 +46,26 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) manager->GetAllBundleResourceInfo(0, infos); manager->GetAllLauncherAbilityResourceInfo(0, launcherInfos); std::vector resourceInfos; - manager->SaveResourceInfos(resourceInfos); std::string targetBundleName(data, size); manager->GetTargetBundleName(bundleName, targetBundleName); ResourceInfo resourceInfo; resourceInfo.bundleName_ = bundleName; resourceInfo.label_ = bundleName; - manager->UpdateBundleIcon(bundleName, resourceInfo); int32_t appIndex = 1; - manager->AddCloneBundleResourceInfo(bundleName, appIndex); - manager->DeleteCloneBundleResourceInfo(bundleName, appIndex); manager->DeleteNotExistResourceInfo(); - manager->AddResourceInfo(USERID, resourceInfo); - manager->AddResourceInfos(USERID, resourceInfos); std::map> resourceInfosMap; resourceInfosMap[BUNDLE_NAME_NO_ICON] = resourceInfos; - manager->AddResourceInfosByMap(resourceInfosMap, manager->currentTaskNum_, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), USERID, USERID); - manager->InnerProcessResourceInfoByResourceUpdateType(resourceInfosMap, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), USERID, USERID); manager->ProcessResourceInfoWhenParseFailed(resourceInfo); - manager->ProcessResourceInfo(resourceInfos, resourceInfo); manager->GetDefaultIcon(resourceInfo); manager->CheckResourceFlags(static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); manager->SendBundleResourcesChangedEvent(USERID, static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); manager->InnerProcessResourceInfoBySystemLanguageChanged(resourceInfosMap); manager->InnerProcessResourceInfoBySystemThemeChanged(resourceInfosMap, USERID); - manager->InnerProcessResourceInfoByUserIdChanged(resourceInfosMap, USERID, USERID); std::vector existResourceNames; manager->DeleteNotExistResourceInfo(resourceInfosMap, existResourceNames); - manager->InnerProcessWhetherThemeExist(bundleName, USERID); - manager->GetBundleResourceInfoForCloneBundle(bundleName, appIndex, resourceInfos); - manager->UpdateCloneBundleResourceInfo(bundleName, appIndex, - static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)); + manager->GetBundleResourceInfoForCloneBundle(bundleName, appIndex, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), resourceInfos); manager->DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); manager->ProcessResourceInfoNoNeedToParseOtherIcon(resourceInfos); return true; diff --git a/test/fuzztest/fuzztest_others/bundleresparser_fuzzer/bundleresparser_fuzzer.cpp b/test/fuzztest/fuzztest_others/bundleresparser_fuzzer/bundleresparser_fuzzer.cpp index 8f2216cf11..a748308a65 100644 --- a/test/fuzztest/fuzztest_others/bundleresparser_fuzzer/bundleresparser_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/bundleresparser_fuzzer/bundleresparser_fuzzer.cpp @@ -75,7 +75,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) parser.GetMediaDataById(resourceManager, iconId, density, datas); ResourceInfo newResourceInfo; parser.IsNeedToParseResourceInfo(newResourceInfo, resourceInfo); - parser.ProcessSpecialBundleResource(USERID, resourceInfos); return true; } } -- Gitee From f82d02408a0540ddbb09c5087e4f3875f2d99d25 Mon Sep 17 00:00:00 2001 From: wang19954 Date: Fri, 8 Aug 2025 15:25:39 +0800 Subject: [PATCH 2/3] IssueNo:#ICRQXV Description:add test case Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../src/bundle_mgr_service_event_handler.cpp | 5 + .../bms_bundle_resource_test.cpp | 820 +++++++++++++++++- 2 files changed, 824 insertions(+), 1 deletion(-) diff --git a/services/bundlemgr/test/mock/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/test/mock/src/bundle_mgr_service_event_handler.cpp index db92d177d8..994cf7fa30 100755 --- a/services/bundlemgr/test/mock/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/test/mock/src/bundle_mgr_service_event_handler.cpp @@ -657,6 +657,11 @@ void BMSEventHandler::ProcessRebootQuickFixBundleInstall(const std::string& path void BMSEventHandler::CheckALLResourceInfo() {} +void BMSEventHandler::InnerProcessAllDynamicIconInfoWhenOta() {} + +void BMSEventHandler::InnerProcessAllThemeAndDynamicIconInfoWhenOta( + const std::unordered_map> &needInstallMap) {} + void BMSEventHandler::ProcessBundleResourceInfo() {} bool InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo) diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index 6fea458713..233f463ecb 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -1466,6 +1466,11 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0067, Function | SmallTest ans = parser.ParseIconResourceByResourceManager(resourceManager, info); // iconId not exist EXPECT_FALSE(ans); EXPECT_EQ(info.icon_, ""); + + info.iconId_ = 1; + ans = parser.ParseIconResourceByResourceManager(resourceManager, info, false); + EXPECT_FALSE(ans); + EXPECT_EQ(info.icon_, ""); } /** @@ -1613,7 +1618,7 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0073, Function | SmallTest { BundleResourceCallback callback; bool ans = callback.OnUserIdSwitched(100, 200); - EXPECT_FALSE(ans); + EXPECT_TRUE(ans); ans = callback.OnUserIdSwitched(200, 100); EXPECT_TRUE(ans); @@ -5046,4 +5051,817 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0255, Function | SmallTest callback.SetConfigInFile("", "", 0, 0, 0, userId); callback.DeleteConfigInFile(userId, 0); } + +/** + * @tc.number: GetExtendResourceInfo_0001 + * Function: GetExtendResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test GetExtendResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, GetExtendResourceInfo_0001, Function | SmallTest | Level0) +{ + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + ExtendResourceInfo resourceInfo; + ErrCode ret = savedDataMgr->GetExtendResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, resourceInfo); + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST); + + InnerBundleInfo bundleInfo; + savedDataMgr->bundleInfos_[BUNDLE_NAME_NOT_EXIST] = bundleInfo; + ret = savedDataMgr->GetExtendResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, resourceInfo); + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST); + + ExtendResourceInfo extendResourceInfo; + extendResourceInfo.iconId = 100; + bundleInfo.extendResourceInfos_[BUNDLE_NAME_NOT_EXIST] = extendResourceInfo; + savedDataMgr->bundleInfos_[BUNDLE_NAME_NOT_EXIST] = bundleInfo; + ret = savedDataMgr->GetExtendResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, resourceInfo); + EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(resourceInfo.iconId, extendResourceInfo.iconId); + + auto iter = savedDataMgr->bundleInfos_.find(BUNDLE_NAME_NOT_EXIST); + if (iter != savedDataMgr->bundleInfos_.end()) { + savedDataMgr->bundleInfos_.erase(iter); + } +} + +/** + * @tc.number: GetDynamicIconResourceInfo_0001 + * Function: GetDynamicIconResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test GetDynamicIconResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, GetDynamicIconResourceInfo_0001, Function | SmallTest | Level0) +{ + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + DelayedSingleton::GetInstance()->RegisterDataMgr(nullptr); + ResourceInfo resourceInfo; + bool ret = BundleResourceProcess::GetDynamicIconResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, + resourceInfo); + EXPECT_FALSE(ret); + DelayedSingleton::GetInstance()->RegisterDataMgr(savedDataMgr); + ret = BundleResourceProcess::GetDynamicIconResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, + resourceInfo); + EXPECT_FALSE(ret); + + ExtendResourceInfo extendResourceInfo; + extendResourceInfo.iconId = 100; + InnerBundleInfo bundleInfo; + bundleInfo.extendResourceInfos_[BUNDLE_NAME_NOT_EXIST] = extendResourceInfo; + savedDataMgr->bundleInfos_[BUNDLE_NAME_NOT_EXIST] = bundleInfo; + ret = BundleResourceProcess::GetDynamicIconResourceInfo(BUNDLE_NAME_NOT_EXIST, BUNDLE_NAME_NOT_EXIST, + resourceInfo); + EXPECT_FALSE(ret); + auto iter = savedDataMgr->bundleInfos_.find(BUNDLE_NAME_NOT_EXIST); + if (iter != savedDataMgr->bundleInfos_.end()) { + savedDataMgr->bundleInfos_.erase(iter); + } +} + +/** + * @tc.number: ParseResourceInfosNoTheme_0010 + * Function: ParseResourceInfosNoTheme + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ParseResourceInfosNoTheme + */ +HWTEST_F(BmsBundleResourceTest, ParseResourceInfosNoTheme_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + std::vector resourceInfos; + bool ans = BundleResourceProcess::GetResourceInfoByBundleName(BUNDLE_NAME, USERID, resourceInfos); + EXPECT_TRUE(ans); + EXPECT_FALSE(resourceInfos.empty()); + + if (!resourceInfos.empty()) { + BundleResourceParser parser; + resourceInfos[0].label_ = ""; + resourceInfos[0].icon_ = ""; + ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_TRUE(ans); + EXPECT_NE(resourceInfos[0].label_, ""); + EXPECT_NE(resourceInfos[0].icon_, ""); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: ParseResourceInfosNoTheme_0020 + * Function: ParseResourceInfosNoTheme + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ParseResourceInfosNoTheme + */ +HWTEST_F(BmsBundleResourceTest, ParseResourceInfosNoTheme_0020, Function | SmallTest | Level0) +{ + std::vector resourceInfos; + BundleResourceParser parser; + bool ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); + ResourceInfo resourceInfo; + resourceInfo.labelNeedParse_ = false; + resourceInfo.iconNeedParse_ = false; + resourceInfos.push_back(resourceInfo); + ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_TRUE(ans); + resourceInfo.labelNeedParse_ = true; + resourceInfos.clear(); + resourceInfos.push_back(resourceInfo); + ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); + resourceInfo.iconNeedParse_ = true; + resourceInfos.clear(); + resourceInfos.push_back(resourceInfo); + ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); + + resourceInfos.push_back(resourceInfo); + ans = parser.ParseResourceInfosNoTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); +} + +/** + * @tc.number: ParseResourceInfosWithTheme_0010 + * Function: ParseResourceInfosWithTheme + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ParseResourceInfosWithTheme + */ +HWTEST_F(BmsBundleResourceTest, ParseResourceInfosWithTheme_0010, Function | SmallTest | Level0) +{ + std::vector resourceInfos; + BundleResourceParser parser; + bool ans = parser.ParseIconResourceInfosWithTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); + + ResourceInfo resourceInfo; + resourceInfos.push_back(resourceInfo); + ans = parser.ParseIconResourceInfosWithTheme(USERID, resourceInfos); + EXPECT_FALSE(ans); +} + +/** + * @tc.number: InnerGetResourceInfo_0010 + * Function: InnerGetResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test InnerGetResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, InnerGetResourceInfo_0010, Function | SmallTest | Level0) +{ + InnerBundleInfo innerBundleInfo; + std::vector resourceInfos; + bool ret = BundleResourceProcess::InnerGetResourceInfo(innerBundleInfo, USERID, resourceInfos, 0, true); + EXPECT_FALSE(ret); + + innerBundleInfo.baseApplicationInfo_->bundleName = BUNDLE_NAME; + ret = BundleResourceProcess::InnerGetResourceInfo(innerBundleInfo, USERID, resourceInfos, 0, true); + EXPECT_TRUE(ret); + + std::vector resourceInfos2; + ret = BundleResourceProcess::InnerGetResourceInfo(innerBundleInfo, USERID, resourceInfos2, 0, false); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: GetBundleResourceInfoForCloneBundle_0010 + * Function: GetBundleResourceInfoForCloneBundle + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test GetBundleResourceInfoForCloneBundle + */ +HWTEST_F(BmsBundleResourceTest, GetBundleResourceInfoForCloneBundle_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::vector resourceInfos; + bool ans = manager->GetBundleResourceInfoForCloneBundle(BUNDLE_NAME_NOT_EXIST, 1, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), resourceInfos); + EXPECT_FALSE(ans); + ResourceInfo info; + info.bundleName_ = BUNDLE_NAME_NOT_EXIST; + info.label_ = "label"; + info.icon_ = "icon"; + BundleResourceRdb resourceRdb; + ans = resourceRdb.AddResourceInfo(info); + EXPECT_TRUE(ans); + std::vector resourceInfos2; + ans = manager->GetBundleResourceInfoForCloneBundle(BUNDLE_NAME_NOT_EXIST, 1, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), resourceInfos2); + EXPECT_TRUE(ans); + EXPECT_EQ(resourceInfos2.size(), 1); + + info.moduleName_ = BUNDLE_NAME_NOT_EXIST; + info.abilityName_ = BUNDLE_NAME_NOT_EXIST; + info.label_ = "label"; + info.icon_ = "icon"; + ans = resourceRdb.AddResourceInfo(info); + EXPECT_TRUE(ans); + std::vector resourceInfos3; + ans = manager->GetBundleResourceInfoForCloneBundle(BUNDLE_NAME_NOT_EXIST, 1, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE), resourceInfos3); + EXPECT_TRUE(ans); + EXPECT_EQ(resourceInfos3.size(), 2); + + ans = resourceRdb.DeleteResourceInfo(BUNDLE_NAME_NOT_EXIST); + EXPECT_TRUE(ans); + } +} + +/** + * @tc.number: AddResourceInfoByBundleNameWhenInstall_0010 + * Function: AddResourceInfoByBundleNameWhenInstall + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfoByBundleNameWhenInstall + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfoByBundleNameWhenInstall_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->AddResourceInfoByBundleNameWhenInstall(BUNDLE_NAME_NOT_EXIST, USERID, true); + EXPECT_FALSE(ret); + ret = manager->AddResourceInfoByBundleNameWhenInstall(BUNDLE_NAME, USERID, true); + EXPECT_TRUE(ret); + ret = manager->AddResourceInfoByBundleNameWhenInstall(BUNDLE_NAME, USERID, false); + EXPECT_TRUE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddResourceInfoByBundleNameWhenUpdate_0010 + * Function: AddResourceInfoByBundleNameWhenUpdate + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfoByBundleNameWhenUpdate + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfoByBundleNameWhenUpdate_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->AddResourceInfoByBundleNameWhenUpdate(BUNDLE_NAME_NOT_EXIST, USERID); + EXPECT_FALSE(ret); + ret = manager->AddResourceInfoByBundleNameWhenUpdate(BUNDLE_NAME, USERID); + EXPECT_TRUE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: ProcessCloneBundleResourceInfo_0010 + * Function: ProcessCloneBundleResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ProcessCloneBundleResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, ProcessCloneBundleResourceInfo_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->ProcessCloneBundleResourceInfo(BUNDLE_NAME_NOT_EXIST, 1); + EXPECT_FALSE(ret); + ret = manager->ProcessCloneBundleResourceInfo(BUNDLE_NAME, 1); + EXPECT_TRUE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddResourceInfoByBundleNameWhenCreateUser_0010 + * Function: AddResourceInfoByBundleNameWhenCreateUser + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfoByBundleNameWhenCreateUser + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfoByBundleNameWhenCreateUser_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->AddResourceInfoByBundleNameWhenCreateUser(BUNDLE_NAME_NOT_EXIST, 100); + EXPECT_TRUE(ret); + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + ret = manager->AddResourceInfoByBundleNameWhenCreateUser(BUNDLE_NAME, THEME_TEST_USERID); + EXPECT_FALSE(ret); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddResourceInfoByBundleNameWhenCreateUser_0020 + * Function: AddResourceInfoByBundleNameWhenCreateUser + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfoByBundleNameWhenCreateUser + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfoByBundleNameWhenCreateUser_0020, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + bool ret = manager->AddResourceInfoByBundleNameWhenCreateUser(BUNDLE_NAME, THEME_TEST_USERID); + EXPECT_FALSE(ret); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } +} + +/** + * @tc.number: DeleteBundleResourceInfo_0010 + * Function: DeleteBundleResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test DeleteBundleResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, DeleteBundleResourceInfo_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->DeleteBundleResourceInfo(BUNDLE_NAME_NOT_EXIST, USERID, false); + EXPECT_TRUE(ret); + ret = manager->DeleteBundleResourceInfo(BUNDLE_NAME_NOT_EXIST, USERID, true); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: AddDynamicIconResource_0010 + * Function: AddDynamicIconResource + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddDynamicIconResource + */ +HWTEST_F(BmsBundleResourceTest, AddDynamicIconResource_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + ResourceInfo resourceInfo; + bool ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 0, resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, USERID, 0); + EXPECT_TRUE(ret); + + ret = manager->AddDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0, resourceInfo); + EXPECT_TRUE(ret); + ret = manager->DeleteDynamicIconResource(BUNDLE_NAME_NOT_EXIST, Constants::UNSPECIFIED_USERID, 0); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: AddAllResourceInfo_0010 + * Function: AddAllResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddAllResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, AddAllResourceInfo_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->AddAllResourceInfo(THEME_TEST_USERID, 0); + EXPECT_FALSE(ret); + + ret = manager->AddAllResourceInfo(USERID, 0); + EXPECT_TRUE(ret); + + ret = manager->AddAllResourceInfo(USERID, + static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE)); + EXPECT_TRUE(ret); + + ret = manager->AddAllResourceInfo(USERID, + static_cast(BundleResourceChangeType::SYSTEM_THEME_CHANGE)); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: AddResourceInfosWhenSystemLanguageChanged_0010 + * Function: AddResourceInfosWhenSystemLanguageChanged + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfosWhenSystemLanguageChanged + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfosWhenSystemLanguageChanged_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::map> resourceInfosMap; + bool ret = manager->AddResourceInfosWhenSystemLanguageChanged(resourceInfosMap, USERID, 0); + EXPECT_FALSE(ret); + ResourceInfo resourceInfo; + resourceInfosMap[BUNDLE_NAME].push_back(resourceInfo); + manager->currentTaskNum_ = 100; + ret = manager->AddResourceInfosWhenSystemLanguageChanged(resourceInfosMap, USERID, 6000000); + EXPECT_FALSE(ret); + + ret = manager->AddResourceInfosWhenSystemLanguageChanged(resourceInfosMap, USERID, 100); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: ProcessCloneBundleResourceInfoWhenSystemLanguageChanged_0010 + * Function: ProcessCloneBundleResourceInfoWhenSystemLanguageChanged + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ProcessCloneBundleResourceInfoWhenSystemLanguageChanged + */ +HWTEST_F(BmsBundleResourceTest, ProcessCloneBundleResourceInfoWhenSystemLanguageChanged_0010, + Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->ProcessCloneBundleResourceInfoWhenSystemLanguageChanged(BUNDLE_NAME, USERID, 0); + EXPECT_FALSE(ret); + + ret = manager->ProcessCloneBundleResourceInfoWhenSystemLanguageChanged(BUNDLE_NAME_NOT_EXIST, USERID, 1); + EXPECT_FALSE(ret); + + ret = manager->ProcessCloneBundleResourceInfoWhenSystemLanguageChanged(BUNDLE_NAME, USERID, 1); + EXPECT_TRUE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddResourceInfosWhenSystemThemeChanged_0010 + * Function: AddResourceInfosWhenSystemThemeChanged + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfosWhenSystemThemeChanged + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfosWhenSystemThemeChanged_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::map> resourceInfosMap; + bool ret = manager->AddResourceInfosWhenSystemThemeChanged(resourceInfosMap, USERID, 0); + EXPECT_FALSE(ret); + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + ResourceInfo resourceInfo; + resourceInfosMap[BUNDLE_NAME].push_back(resourceInfo); + manager->currentTaskNum_ = 100; + ret = manager->AddResourceInfosWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID, 1000000); + EXPECT_FALSE(ret); + + ret = manager->AddResourceInfosWhenSystemThemeChanged(resourceInfosMap, THEME_TEST_USERID, 100); + EXPECT_TRUE(ret); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } +} + +/** + * @tc.number: ProcessCloneBundleResourceInfoWhenSystemThemeChanged_0010 + * Function: ProcessCloneBundleResourceInfoWhenSystemThemeChanged + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ProcessCloneBundleResourceInfoWhenSystemThemeChanged + */ +HWTEST_F(BmsBundleResourceTest, ProcessCloneBundleResourceInfoWhenSystemThemeChanged_0010, + Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->ProcessCloneBundleResourceInfoWhenSystemThemeChanged(BUNDLE_NAME_NOT_EXIST, USERID, 1); + EXPECT_FALSE(ret); + + ret = manager->ProcessCloneBundleResourceInfoWhenSystemThemeChanged(BUNDLE_NAME, USERID, 1); + EXPECT_FALSE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: InnerProcessResourceInfoBySystemThemeChanged_0010 + * Function: InnerProcessResourceInfoBySystemThemeChanged + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test InnerProcessResourceInfoBySystemThemeChanged + */ +HWTEST_F(BmsBundleResourceTest, InnerProcessResourceInfoBySystemThemeChanged_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::map> resourceInfosMap; + ResourceInfo resourceInfo; + resourceInfosMap[BUNDLE_NAME_NOT_EXIST].push_back(resourceInfo); + resourceInfosMap[BUNDLE_NAME].push_back(resourceInfo); + resourceInfosMap[MODULE_NAME].clear(); + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + manager->InnerProcessResourceInfoBySystemThemeChanged(resourceInfosMap, THEME_TEST_USERID); + EXPECT_EQ(resourceInfosMap.size(), 1); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } +} + +/** + * @tc.number: AddCloneBundleResourceInfoWhenInstall_0010 + * Function: AddCloneBundleResourceInfoWhenInstall + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddCloneBundleResourceInfoWhenInstall + */ +HWTEST_F(BmsBundleResourceTest, AddCloneBundleResourceInfoWhenInstall_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->AddCloneBundleResourceInfoWhenInstall(BUNDLE_NAME_NOT_EXIST, USERID, 1, false); + EXPECT_FALSE(ret); + ret = manager->AddCloneBundleResourceInfoWhenInstall(BUNDLE_NAME, USERID, 1, false); + EXPECT_TRUE(ret); + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + ret = manager->AddCloneBundleResourceInfoWhenInstall(BUNDLE_NAME, USERID, 2, false); + EXPECT_TRUE(ret); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: DeleteCloneBundleResourceInfoWhenUninstall_0010 + * Function: DeleteCloneBundleResourceInfoWhenUninstall + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test DeleteCloneBundleResourceInfoWhenUninstall + */ +HWTEST_F(BmsBundleResourceTest, DeleteCloneBundleResourceInfoWhenUninstall_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + bool ret = manager->DeleteCloneBundleResourceInfoWhenUninstall(BUNDLE_NAME_NOT_EXIST, USERID, 1, false); + EXPECT_TRUE(ret); + ret = manager->DeleteCloneBundleResourceInfoWhenUninstall(BUNDLE_NAME_NOT_EXIST, USERID, 1, true); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: IsNeedProcessResourceIconInfo_0010 + * Function: IsNeedProcessResourceIconInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test IsNeedProcessResourceIconInfo + */ +HWTEST_F(BmsBundleResourceTest, IsNeedProcessResourceIconInfo_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + uint32_t resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ALL); + bool ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_TRUE(ret); + + resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_LABEL); + ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_FALSE(ret); + + resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_ICON); + ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_TRUE(ret); + + resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_DRAWABLE_DESCRIPTOR); + ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_TRUE(ret); + + resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_WITH_SORTED_BY_LABEL); + ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_FALSE(ret); + + resourceFlags = static_cast(ResourceFlag::GET_RESOURCE_INFO_ONLY_WITH_MAIN_ABILITY); + ret = manager->IsNeedProcessResourceIconInfo(resourceFlags); + EXPECT_FALSE(ret); + } +} + +/** + * @tc.number: GetUserId_0010 + * Function: GetUserId + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test GetUserId + */ +HWTEST_F(BmsBundleResourceTest, GetUserId_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + auto userId = manager->GetUserId(); + EXPECT_EQ(userId, USERID); + } +} + +/** + * @tc.number: SetIsOnlineThemeWhenBoot_0020 + * Function: SetIsOnlineThemeWhenBoot + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test SetIsOnlineThemeWhenBoot + */ +HWTEST_F(BmsBundleResourceTest, SetIsOnlineThemeWhenBoot_0020, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + bundleMgrService_->RegisterDataMgr(nullptr); + manager->SetIsOnlineThemeWhenBoot(); + bundleMgrService_->RegisterDataMgr(savedDataMgr); + manager->SetIsOnlineThemeWhenBoot(); + bool ret = manager->bundleResourceIconRdb_->GetIsOnlineTheme(THEME_TEST_USERID); + EXPECT_FALSE(ret); + } +} + +/** + * @tc.number: InnerProcessThemeIconWhenOta_0010 + * Function: InnerProcessThemeIconWhenOta + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test InnerProcessThemeIconWhenOta + */ +HWTEST_F(BmsBundleResourceTest, InnerProcessThemeIconWhenOta_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::set userIds; + userIds.insert(USERID); + bool ret = manager->InnerProcessThemeIconWhenOta(BUNDLE_NAME, userIds); + EXPECT_TRUE(ret); + + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + bundleMgrService_->RegisterDataMgr(nullptr); + OHOS::ForceCreateDirectory(THEME_B_ICON_BUNDLE_NAME); + userIds.insert(THEME_TEST_USERID); + ret = manager->InnerProcessThemeIconWhenOta(BUNDLE_NAME, userIds); + EXPECT_FALSE(ret); + bundleMgrService_->RegisterDataMgr(savedDataMgr); + ret = manager->InnerProcessThemeIconWhenOta(BUNDLE_NAME, userIds); + EXPECT_TRUE(ret); + OHOS::ForceRemoveDirectory(THEME_BUNDLE_NAME_PATH); + } +} + +/** + * @tc.number: InnerProcessDynamicIconWhenOta_0010 + * Function: InnerProcessDynamicIconWhenOta + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test InnerProcessDynamicIconWhenOta + */ +HWTEST_F(BmsBundleResourceTest, InnerProcessDynamicIconWhenOta_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + bundleMgrService_->RegisterDataMgr(nullptr); + bool ret = manager->InnerProcessDynamicIconWhenOta(BUNDLE_NAME); + EXPECT_FALSE(ret); + bundleMgrService_->RegisterDataMgr(savedDataMgr); + + ret = manager->InnerProcessDynamicIconWhenOta(BUNDLE_NAME_NOT_EXIST); + EXPECT_FALSE(ret); + } + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: ProcessThemeAndDynamicIconWhenOta_0010 + * Function: ProcessThemeAndDynamicIconWhenOta + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test ProcessThemeAndDynamicIconWhenOta + */ +HWTEST_F(BmsBundleResourceTest, ProcessThemeAndDynamicIconWhenOta_0010, Function | SmallTest | Level0) +{ + auto manager = DelayedSingleton::GetInstance(); + EXPECT_NE(manager, nullptr); + if (manager != nullptr) { + std::set updateBundleNames; + auto savedDataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + bundleMgrService_->RegisterDataMgr(nullptr); + bool ret = manager->ProcessThemeAndDynamicIconWhenOta(updateBundleNames); + EXPECT_FALSE(ret); + bundleMgrService_->RegisterDataMgr(savedDataMgr); + + ret = manager->ProcessThemeAndDynamicIconWhenOta(updateBundleNames); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: AddResourceInfoByBundleName_0010 + * Function: AddResourceInfoByBundleName + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddResourceInfoByBundleName + */ +HWTEST_F(BmsBundleResourceTest, AddResourceInfoByBundleName_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + BundleResourceHelper::AddResourceInfoByBundleName(BUNDLE_NAME, USERID, ADD_RESOURCE_TYPE::INSTALL_BUNDLE); + bool ret = BundleResourceHelper::DeleteBundleResourceInfo(BUNDLE_NAME, USERID, true); + EXPECT_TRUE(ret); + + BundleResourceHelper::AddResourceInfoByBundleName(BUNDLE_NAME, USERID, ADD_RESOURCE_TYPE::UPDATE_BUNDLE); + ret = BundleResourceHelper::DeleteBundleResourceInfo(BUNDLE_NAME, USERID, true); + EXPECT_TRUE(ret); + + BundleResourceHelper::AddResourceInfoByBundleName(BUNDLE_NAME, USERID, ADD_RESOURCE_TYPE::CREATE_USER); + ret = BundleResourceHelper::DeleteBundleResourceInfo(BUNDLE_NAME, USERID, true); + EXPECT_TRUE(ret); + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} + +/** + * @tc.number: AddCloneBundleResourceInfo_0010 + * Function: AddCloneBundleResourceInfo + * @tc.name: test + * @tc.desc: 1. system running normally + * 2. test AddCloneBundleResourceInfo + */ +HWTEST_F(BmsBundleResourceTest, AddCloneBundleResourceInfo_0010, Function | SmallTest | Level0) +{ + ErrCode installResult = InstallBundle(HAP_FILE_PATH1); + EXPECT_EQ(installResult, ERR_OK); + + bool ret = BundleResourceHelper::AddCloneBundleResourceInfo(BUNDLE_NAME_NOT_EXIST, USERID, 1, false); + EXPECT_FALSE(ret); + + ret = BundleResourceHelper::AddCloneBundleResourceInfo(BUNDLE_NAME, USERID, 1, false); + EXPECT_TRUE(ret); + + ret = BundleResourceHelper::DeleteCloneBundleResourceInfo(BUNDLE_NAME, USERID, 1, false); + EXPECT_TRUE(ret); + + ErrCode unInstallResult = UnInstallBundle(BUNDLE_NAME); + EXPECT_EQ(unInstallResult, ERR_OK); +} } // OHOS -- Gitee From 69bdccb58274cd76f35f8ad13a0fe7dd62789d99 Mon Sep 17 00:00:00 2001 From: wang19954 Date: Fri, 8 Aug 2025 15:58:25 +0800 Subject: [PATCH 3/3] IssueNo:#ICRQXV Description:fix code check Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../bundle_resource_manager.cpp | 20 ++++++++++--------- .../bundlemgr/src/bundle_resource_helper.cpp | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp index 984e2898b2..a9e692fa9d 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_manager.cpp @@ -153,7 +153,8 @@ bool BundleResourceManager::GetBundleResourceInfo(const std::string &bundleName, auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), [bundleName, appIndex](const auto resourceIconInfo) { return ((resourceIconInfo.bundleName == bundleName) && - (resourceIconInfo.appIndex == appIndex)); }); + (resourceIconInfo.appIndex == appIndex)); + }); if (iter != resourceIconInfos.end()) { bundleResourceInfo.icon = iter->icon; bundleResourceInfo.foreground = iter->foreground; @@ -197,7 +198,8 @@ bool BundleResourceManager::GetLauncherAbilityResourceInfo(const std::string &bu iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), [resource](const auto resourceIconInfo) { return ((resource.bundleName == resourceIconInfo.bundleName) && - (resource.appIndex == resourceIconInfo.appIndex)); }); + (resource.appIndex == resourceIconInfo.appIndex)); + }); } if (iter != resourceIconInfos.end()) { resource.icon = iter->icon; @@ -240,7 +242,8 @@ bool BundleResourceManager::GetAllBundleResourceInfo(const uint32_t flags, auto iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), [resource](const auto resourceIconInfo) { return ((resource.bundleName == resourceIconInfo.bundleName) && - (resource.appIndex == resourceIconInfo.appIndex)); }); + (resource.appIndex == resourceIconInfo.appIndex)); + }); if (iter != resourceIconInfos.end()) { resource.icon = iter->icon; resource.foreground = iter->foreground; @@ -277,7 +280,8 @@ bool BundleResourceManager::GetAllLauncherAbilityResourceInfo(const uint32_t fla iter = std::find_if(resourceIconInfos.begin(), resourceIconInfos.end(), [resource](const auto resourceIconInfo) { return ((resource.bundleName == resourceIconInfo.bundleName) && - (resource.appIndex == resourceIconInfo.appIndex)); }); + (resource.appIndex == resourceIconInfo.appIndex)); + }); } if (iter != resourceIconInfos.end()) { resource.icon = iter->icon; @@ -548,9 +552,7 @@ bool BundleResourceManager::AddResourceInfoByBundleNameWhenInstall( for (const int32_t appIndex : resourceInfos[0].appIndexes_) { DeleteNotExistResourceInfo(bundleName, appIndex, resourceInfos); // update clone bundle, label and icon - if (!ProcessCloneBundleResourceInfo(resourceInfos[0].bundleName_, appIndex)) { - APP_LOGW("-n %{public}s -i %{public}d add clone resource failed", bundleName.c_str(), appIndex); - } + (void)ProcessCloneBundleResourceInfo(resourceInfos[0].bundleName_, appIndex); } } // 5. if theme not exist, then return @@ -645,7 +647,7 @@ bool BundleResourceManager::ProcessCloneBundleResourceInfo( BundleResourceParser parser; if (!parser.ParserCloneResourceInfo(appIndex, resourceInfos)) { APP_LOGE("bundleName:%{public}s appIndex:%{public}d parse clone resource failed", - bundleName.c_str(), appIndex); + bundleName.c_str(), appIndex); } // 3. add clone bundle resource info if (!bundleResourceRdb_->AddResourceInfos(resourceInfos)) { @@ -880,7 +882,7 @@ bool BundleResourceManager::ProcessCloneBundleResourceInfoWhenSystemLanguageChan } std::vector resourceInfos; if (!GetBundleResourceInfoForCloneBundle(bundleName, appIndex, - static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), resourceInfos)) { + static_cast(BundleResourceChangeType::SYSTEM_LANGUE_CHANGE), resourceInfos)) { APP_LOGE("get clone bundle resource failed -n %{public}s -u %{public}d -a %{public}d", bundleName.c_str(), userId, appIndex); return false; diff --git a/services/bundlemgr/src/bundle_resource_helper.cpp b/services/bundlemgr/src/bundle_resource_helper.cpp index 28c15dab1a..a4db6e868e 100644 --- a/services/bundlemgr/src/bundle_resource_helper.cpp +++ b/services/bundlemgr/src/bundle_resource_helper.cpp @@ -67,7 +67,7 @@ void BundleResourceHelper::AddResourceInfoByBundleName(const std::string &bundle APP_LOGE("failed, manager is nullptr"); return; } - switch (type){ + switch (type) { case ADD_RESOURCE_TYPE::INSTALL_BUNDLE : { // add new resource info if (!manager->AddResourceInfoByBundleNameWhenInstall(bundleName, userId, isBundleFirstInstall)) { -- Gitee