diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 2d83c03167e5fec17cf4884593f690a5beafa84b..9b79935cf43d4420f7d9abbc706ae868fc5af4fc 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 0ffaa150730d2cf778d9dd4e558c0b6f7b799cdb..b505fbe495f40c6f0dd98c9e68144aa4930c655f 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 481b4358ba142afcd1abb1cffc714d546ddb8c8a..184d2bf56b76478d356c8d9d01bf5adc894e2a18 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