From 3d7d4719c9378715535dd19b42abc12240b5f8dc Mon Sep 17 00:00:00 2001 From: LiPing Date: Tue, 6 Aug 2024 12:07:27 +0800 Subject: [PATCH] update themeId Signed-off-by: LiPing --- frameworks/resmgr/include/theme_pack_manager.h | 5 ++--- frameworks/resmgr/src/resource_manager_impl.cpp | 9 +-------- frameworks/resmgr/src/theme_pack_manager.cpp | 14 +++++++------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/frameworks/resmgr/include/theme_pack_manager.h b/frameworks/resmgr/include/theme_pack_manager.h index 5705c2b..1cc166e 100644 --- a/frameworks/resmgr/include/theme_pack_manager.h +++ b/frameworks/resmgr/include/theme_pack_manager.h @@ -113,9 +113,7 @@ public: const std::string ReplaceUserIdInPath(const std::string &originalPath, int32_t userId); - uint32_t GetThemeId() const; - - void SetThemeId(uint32_t themeId); + bool UpdateThemeId(uint32_t newThemeId); private: ThemePackManager(); std::string themeFlag; @@ -141,6 +139,7 @@ private: std::vector GetRootDir(const std::string &strCurrentDir); Lock lockSkin_; Lock lockIcon_; + Lock lockThemeId_; uint32_t themeId_; }; } // namespace Resource diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index a0aaf77..c2529cf 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -1149,14 +1149,7 @@ RState ResourceManagerImpl::UpdateFakeLocaleFlag(ResConfig &resConfig) RState ResourceManagerImpl::UpdateResConfig(ResConfig &resConfig, bool isUpdateTheme) { auto themePackManager = ThemePackManager::GetThemePackManager(); - uint32_t lastId = themePackManager->GetThemeId(); - uint32_t currentId = resConfig.GetThemeId(); - bool isThemeIdChanged = (currentId != 0 && (lastId != currentId)); - if (isThemeIdChanged) { - RESMGR_HILOGI(RESMGR_TAG, "update theme, lastId = %{public}d, currentId = %{public}d", lastId, currentId); - themePackManager->SetThemeId(resConfig.GetThemeId()); - } - if (isUpdateTheme || isThemeIdChanged) { + if (themePackManager->UpdateThemeId(resConfig.GetThemeId())) { RESMGR_HILOGD(RESMGR_TAG, "The theme enabled"); themePackManager->LoadThemeRes(bundleInfo.first, bundleInfo.second, userId); } diff --git a/frameworks/resmgr/src/theme_pack_manager.cpp b/frameworks/resmgr/src/theme_pack_manager.cpp index b975646..06d73c8 100644 --- a/frameworks/resmgr/src/theme_pack_manager.cpp +++ b/frameworks/resmgr/src/theme_pack_manager.cpp @@ -370,14 +370,14 @@ const std::string ThemePackManager::FindThemeIconResource(const std::pairthemeId_ = themeId; -} - -uint32_t ThemePackManager::GetThemeId() const -{ - return this->themeId_; + AutoMutex mutex(this->lockThemeId_); + if (newThemeId != 0 && newThemeId != themeId_) { + themeId_ = newThemeId; + return true; + } + return false; } } // namespace Resource } // namespace Global -- Gitee