diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index 46239f952..02290c28b 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -631,6 +631,7 @@ private: void UpdatePreinstallDBForNotUpdatedBundle(const std::string &bundleName, const std::unordered_map &innerBundleInfos); void InnerProcessRebootUninstallWrongBundle(); + bool InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo); void ProcessCheckAppEl1Dir(); void static ProcessCheckAppEl1DirTask(); void CleanAllBundleShaderCache() const; diff --git a/services/bundlemgr/include/bundle_service_constants.h b/services/bundlemgr/include/bundle_service_constants.h index b92e37aaa..fb1d45732 100644 --- a/services/bundlemgr/include/bundle_service_constants.h +++ b/services/bundlemgr/include/bundle_service_constants.h @@ -181,6 +181,14 @@ const std::set ALLOW_MULTI_ICON_BUNDLE = { "com.ohos.contacts" }; constexpr const char* CALLER_NAME_BMS = "bms"; +// allow singleton change +const std::set SINGLETON_WHITE_LIST = { + "com.ohos.formrenderservice", + "com.ohos.sceneboard", + "com.ohos.callui", + "com.ohos.mms", + "com.ohos.FusionSearch" +}; } // namespace ServiceConstants } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 3217fb237..c330d1f3b 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -104,14 +104,6 @@ constexpr const char* BMS_ACTIVATION_LOCK = "persist.bms.activation-lock"; constexpr const char* BMS_TRUE = "true"; constexpr const char* BMS_FALSE = "false"; constexpr int8_t BMS_ACTIVATION_LOCK_VAL_LEN = 20; - -const std::set SINGLETON_WHITE_LIST = { - "com.ohos.formrenderservice", - "com.ohos.sceneboard", - "com.ohos.callui", - "com.ohos.mms", - "com.ohos.FusionSearch" -}; constexpr const char* DATA_EXTENSION_PATH = "/extension/"; const char* INSTALL_SOURCE_PREINSTALL = "pre-installed"; const char* INSTALL_SOURCE_UNKNOWN = "unknown"; @@ -2156,7 +2148,7 @@ ErrCode BaseBundleInstaller::ProcessBundleInstallStatus(InnerBundleInfo &info, i bool BaseBundleInstaller::AllowSingletonChange(const std::string &bundleName) { - return SINGLETON_WHITE_LIST.find(bundleName) != SINGLETON_WHITE_LIST.end(); + return ServiceConstants::SINGLETON_WHITE_LIST.find(bundleName) != ServiceConstants::SINGLETON_WHITE_LIST.end(); } ErrCode BaseBundleInstaller::ProcessBundleUpdateStatus( diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index fa171a161..cf5a6c625 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -3924,20 +3924,64 @@ void BMSEventHandler::ProcessRebootQuickFixUnInstallAndRecover(const std::string void BMSEventHandler::InnerProcessRebootUninstallWrongBundle() { + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "dataMgr is null"); + return; + } + for (const auto &bundleName : ServiceConstants::SINGLETON_WHITE_LIST) { + InnerBundleInfo bundleInfo; + if (!dataMgr->FetchInnerBundleInfo(bundleName, bundleInfo)) { + LOG_W(BMS_TAG_DEFAULT, "-n %{public}s is not exist", bundleName.c_str()); + continue; + } + InnerCheckSingletonBundleUserInfo(bundleInfo); + } +} + +bool BMSEventHandler::InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo) +{ + const auto bundleUserInfos = bundleInfo.GetInnerBundleUserInfos(); + if (bundleUserInfos.size() <= 1) { + return true; + } + std::set userIds; + for (const auto &item : bundleUserInfos) { + userIds.insert(item.second.bundleUserInfo.userId); + } + if (userIds.find(Constants::DEFAULT_USERID) == userIds.end()) { + return true; + } + const std::string bundleName = bundleInfo.GetBundleName(); + LOG_I(BMS_TAG_DEFAULT, "-n %{public}s is exist different user info", bundleName.c_str()); InstallParam installParam; installParam.userId = Constants::DEFAULT_USERID; installParam.SetKillProcess(false); installParam.needSendEvent = false; - std::vector wrongBundleNameList; - wrongBundleNameList.emplace_back(Constants::SCENE_BOARD_BUNDLE_NAME); - - for (const auto &bundle : wrongBundleNameList) { + if (!bundleInfo.IsSingleton()) { + LOG_I(BMS_TAG_DEFAULT, "-n %{public}s delete 0 userInfo", bundleName.c_str()); SystemBundleInstaller installer; - if (!installer.UninstallSystemBundle(bundle, installParam)) { - LOG_W(BMS_TAG_DEFAULT, "OTA uninstall bundle %{public}s userId %{public}d error", bundle.c_str(), + if (!installer.UninstallSystemBundle(bundleName, installParam)) { + LOG_W(BMS_TAG_DEFAULT, "OTA uninstall bundle %{public}s userId %{public}d error", bundleName.c_str(), installParam.userId); + return false; + } + return true; + } + for (const auto &userId : userIds) { + if (userId == Constants::DEFAULT_USERID) { + continue; + } + LOG_I(BMS_TAG_DEFAULT, "-n %{public}s delete %{public}d userInfo", bundleName.c_str(), userId); + installParam.userId = userId; + SystemBundleInstaller installer; + if (!installer.UninstallSystemBundle(bundleName, installParam)) { + LOG_W(BMS_TAG_DEFAULT, "OTA uninstall bundle %{public}s userId %{public}d error", bundleName.c_str(), + installParam.userId); + return false; } } + return true; } void BMSEventHandler::ProcessCheckAppEl1Dir() 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 dd6a064d5..7e5a62ecf 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 @@ -707,6 +707,11 @@ void BMSEventHandler::CheckALLResourceInfo() {} void BMSEventHandler::ProcessBundleResourceInfo() {} +bool InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo) +{ + return true; +} + bool BMSEventHandler::IsHapPathExist(const BundleInfo &bundleInfo) { return true; diff --git a/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_test.cpp b/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_test.cpp index 88f7a06e6..ca6c51eea 100644 --- a/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_test.cpp +++ b/services/bundlemgr/test/unittest/bms_event_handler_test/bms_event_handler_test.cpp @@ -1404,4 +1404,39 @@ HWTEST_F(BmsEventHandlerTest, InnerMultiProcessBundleInstall_0100, Function | Sm EXPECT_TRUE(ret); } } + +/** + * @tc.number: InnerCheckSingletonBundleUserInfo_0100 + * @tc.name: InnerCheckSingletonBundleUserInfo + * @tc.desc: test InnerCheckSingletonBundleUserInfo + */ +HWTEST_F(BmsEventHandlerTest, InnerCheckSingletonBundleUserInfo_0100, Function | SmallTest | Level0) +{ + std::shared_ptr handler = std::make_shared(); + EXPECT_NE(handler, nullptr); + if (handler) { + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleName = "InnerCheckSingletonBundleUserInfo"; + bool ret = handler->InnerCheckSingletonBundleUserInfo(innerBundleInfo); + EXPECT_TRUE(ret); + InnerBundleUserInfo userInfo; + userInfo.bundleUserInfo.userId = 100; + innerBundleInfo.innerBundleUserInfos_["_100"] = userInfo; + + userInfo.bundleUserInfo.userId = 101; + innerBundleInfo.innerBundleUserInfos_["_101"] = userInfo; + + ret = handler->InnerCheckSingletonBundleUserInfo(innerBundleInfo); + EXPECT_TRUE(ret); + + userInfo.bundleUserInfo.userId = 0; + innerBundleInfo.innerBundleUserInfos_["_0"] = userInfo; + ret = handler->InnerCheckSingletonBundleUserInfo(innerBundleInfo); + EXPECT_FALSE(ret); + + innerBundleInfo.SetSingleton(true); + ret = handler->InnerCheckSingletonBundleUserInfo(innerBundleInfo); + EXPECT_FALSE(ret); + } +} } // OHOS \ No newline at end of file