From 36256376b4b02a330a5fb5260c28e65bb739e4ae Mon Sep 17 00:00:00 2001 From: daiyujia Date: Thu, 11 Sep 2025 15:34:54 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:#ICXJFB=20Description:[6.0]=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DUpdateBundleForSelf=E5=8F=AF=E4=BB=A5=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=85=B6=E4=BB=96=E5=BA=94=E7=94=A8=20Sig:bundleManag?= =?UTF-8?q?er=20Feature=20or=20Bugfix:Bugfix=20Binary=20Source:No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: daiyujia Change-Id: Ia6f9ce1dfa1951e7be929bd6e80db7e001ec6c61 --- .../bundlemgr/src/base_bundle_installer.cpp | 11 ++++++-- services/bundlemgr/src/pre_bundle_profile.cpp | 2 +- .../bms_bundle_install_checker_test.cpp | 26 +++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 2d83c03167..9b79935cf4 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -4581,6 +4581,9 @@ ErrCode BaseBundleInstaller::CheckProxyDatas( ErrCode BaseBundleInstaller::CheckMDMUpdateBundleForSelf(const InstallParam &installParam, InnerBundleInfo &oldInfo, const std::unordered_map &newInfos, bool isAppExist) { + if (!InitDataMgr()) { + return ERR_APPEXECFWK_NULL_PTR; + } if (!installParam.isSelfUpdate) { return ERR_OK; } @@ -4599,10 +4602,14 @@ ErrCode BaseBundleInstaller::CheckMDMUpdateBundleForSelf(const InstallParam &ins LOG_E(BMS_TAG_INSTALLER, "not mdm app"); return ERR_APPEXECFWK_INSTALL_SELF_UPDATE_NOT_MDM; } - std::string bundleName = oldInfo.GetBundleName(); + std::string bundleName; + if (!dataMgr_->GetBundleNameForUid(sysEventInfo_.callingUid, bundleName)) { + bundleName = Constants::EMPTY_STRING; + } for (const auto &info : newInfos) { if (bundleName != info.second.GetBundleName()) { - LOG_E(BMS_TAG_INSTALLER, "bundleName %{public}s not same", info.second.GetBundleName().c_str()); + LOG_E(BMS_TAG_INSTALLER, "callingBundleName %{public}s bundleName %{public}s not same", + bundleName.c_str(), info.second.GetBundleName().c_str()); return ERR_APPEXECFWK_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME; } } diff --git a/services/bundlemgr/src/pre_bundle_profile.cpp b/services/bundlemgr/src/pre_bundle_profile.cpp index 0ffaa15073..b505fbe495 100644 --- a/services/bundlemgr/src/pre_bundle_profile.cpp +++ b/services/bundlemgr/src/pre_bundle_profile.cpp @@ -534,6 +534,7 @@ void PreBundleProfile::ProcessOnDemandList(std::set &scanAppInfos, { for (auto iter = scanAppInfos.begin(); iter != scanAppInfos.end();) { if (iter->onDemandInstall) { + APP_LOGI("%{public}s is onDemandInstall", iter->bundleDir.c_str()); PreScanInfo preScanInfo; preScanInfo.removable = iter->removable; preScanInfo.isDataPreloadHap = iter->isDataPreloadHap; @@ -543,7 +544,6 @@ void PreBundleProfile::ProcessOnDemandList(std::set &scanAppInfos, preScanInfo.onDemandInstall = iter->onDemandInstall; scanDemandInfos.insert(preScanInfo); iter = scanAppInfos.erase(iter); - APP_LOGI("%{public}s is onDemandInstall", iter->bundleDir.c_str()); } else { ++iter; } diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp index 481b4358ba..184d2bf56b 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_checker_test.cpp @@ -1956,6 +1956,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckProxyPermissionLevel_0003, Function | HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0001, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = false; std::unordered_map infos; @@ -1972,6 +1973,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0001, Function HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0002, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = true; std::unordered_map infos; @@ -1988,6 +1990,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0002, Function HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0003, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = true; std::unordered_map infos; @@ -2006,6 +2009,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0003, Function HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0004, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = true; std::unordered_map infos; @@ -2024,6 +2028,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0004, Function HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0005, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = true; std::unordered_map infos; @@ -2034,7 +2039,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0005, Function innerBundleInfo.SetAppDistributionType(Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE_MDM); infos.emplace(BUNDLE_NAME, innerBundleInfo); auto ret = baseBundleInstaller.CheckMDMUpdateBundleForSelf(param, innerBundleInfo, infos, true); - EXPECT_EQ(ret, ERR_OK); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME); } /** @@ -2045,6 +2050,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0005, Function HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0006, Function | SmallTest | Level0) { BaseBundleInstaller baseBundleInstaller; + baseBundleInstaller.dataMgr_ = std::make_shared(); InstallParam param; param.isSelfUpdate = true; std::unordered_map infos; @@ -2055,7 +2061,7 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0006, Function innerBundleInfo.SetAppDistributionType(Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE_MDM); InnerBundleInfo innerBundleInfo2; ApplicationInfo applicationInfo2; - applicationInfo.bundleName = "wrong_name"; + applicationInfo2.bundleName = "wrong_name"; innerBundleInfo2.SetBaseApplicationInfo(applicationInfo2); infos.emplace(BUNDLE_NAME, innerBundleInfo2); @@ -2063,6 +2069,22 @@ HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0006, Function EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_SELF_UPDATE_BUNDLENAME_NOT_SAME); } +/** + * @tc.number: CheckMDMUpdateBundleForSelf_0007 + * @tc.name: test the start function of CheckMDMUpdateBundleForSelf + * @tc.desc: 1. test CheckMDMUpdateBundleForSelf +*/ +HWTEST_F(BmsBundleInstallCheckerTest, CheckMDMUpdateBundleForSelf_0007, Function | SmallTest | Level0) +{ + BaseBundleInstaller baseBundleInstaller; + InstallParam param; + param.isSelfUpdate = false; + std::unordered_map infos; + InnerBundleInfo innerBundleInfo; + auto ret = baseBundleInstaller.CheckMDMUpdateBundleForSelf(param, innerBundleInfo, infos, true); + EXPECT_EQ(ret, ERR_APPEXECFWK_NULL_PTR); +} + /** * @tc.number: VaildEnterpriseInstallPermission_0001 * @tc.name: test the start function of VaildEnterpriseInstallPermission -- Gitee