diff --git a/frameworks/resmgr/include/theme_pack_manager.h b/frameworks/resmgr/include/theme_pack_manager.h index 5705c2bb2f966a92f75de93960c4ddc641abe70e..1cc166eb3c53492be0749e4a60f85639ee993d3d 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 a0aaf776f743942e5adc3c89844ee097003d21a4..c2529cf598a5f40133208afcaddb51d8358f49f5 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 b975646cfe80765d31161b3752d1efdf49c07a5b..06d73c8d58f90d73bc9e61c9754b3654290628d9 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