!7467 【bug】singleton应用预期只会安装在0用户下

Merge pull request !7467 from wangtiantian/fix_singleton_bug
This commit is contained in:
openharmony_ci 2024-11-14 06:52:05 +00:00 committed by Gitee
commit b513526bc2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 100 additions and 15 deletions

View File

@ -631,6 +631,7 @@ private:
void UpdatePreinstallDBForNotUpdatedBundle(const std::string &bundleName,
const std::unordered_map<std::string, InnerBundleInfo> &innerBundleInfos);
void InnerProcessRebootUninstallWrongBundle();
bool InnerCheckSingletonBundleUserInfo(const InnerBundleInfo &bundleInfo);
void ProcessCheckAppEl1Dir();
void static ProcessCheckAppEl1DirTask();
void CleanAllBundleShaderCache() const;

View File

@ -181,6 +181,14 @@ const std::set<std::string> ALLOW_MULTI_ICON_BUNDLE = {
"com.ohos.contacts"
};
constexpr const char* CALLER_NAME_BMS = "bms";
// allow singleton change
const std::set<std::string> SINGLETON_WHITE_LIST = {
"com.ohos.formrenderservice",
"com.ohos.sceneboard",
"com.ohos.callui",
"com.ohos.mms",
"com.ohos.FusionSearch"
};
} // namespace ServiceConstants
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -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<std::string> 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(

View File

@ -3924,20 +3924,64 @@ void BMSEventHandler::ProcessRebootQuickFixUnInstallAndRecover(const std::string
void BMSEventHandler::InnerProcessRebootUninstallWrongBundle()
{
auto dataMgr = DelayedSingleton<BundleMgrService>::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<int32_t> 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<std::string> 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()

View File

@ -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;

View File

@ -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<BMSEventHandler> handler = std::make_shared<BMSEventHandler>();
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