diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index fcba9b766bfa1a53d43fb804ee01bb344e9fc43a..a2abd48e84cf2c9a1c2d6a9a9da8dc0a3946022b 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -531,7 +531,7 @@ private: int32_t taskPriority, const std::vector &tasks, int32_t userId); bool InnerMultiProcessBundleInstall( - const std::unordered_map> &needInstallMap, + const std::unordered_map, bool>> &needInstallMap, Constants::AppType appType); void ProcessCheckAppDataDir(); @@ -652,7 +652,7 @@ private: void CheckALLResourceInfo(); void InnerProcessAllDynamicIconInfoWhenOta(); void InnerProcessAllThemeAndDynamicIconInfoWhenOta( - const std::unordered_map> &needInstallMap); + const std::unordered_map, bool>> &needInstallMap); // Used to add bundle resource Info that does not exist in rdb when OTA. void static ProcessBundleResourceInfo(); // scan all bundle data group info @@ -661,7 +661,8 @@ private: void SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo); void SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo, const int32_t errorCode); void ProcessAppTmpPath(); - void UpdatePreinstallDB(const std::unordered_map> &needInstallMap); + void UpdatePreinstallDB( + const std::unordered_map, bool>> &needInstallMap); void UpdatePreinstallDBForNotUpdatedBundle(const std::string &bundleName, const std::unordered_map &innerBundleInfos); void InnerProcessRebootUninstallWrongBundle(); diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index a552aeb0a94e7c3cb38a9fbdeb171daf7164ed1f..27e30cac764d8e9ccf4de5bbf5aa48e986e0814f 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -2131,7 +2131,7 @@ void BMSEventHandler::InnerProcessRebootBundleInstall( return; } - std::unordered_map> needInstallMap; + std::unordered_map, bool>> needInstallMap; for (auto &scanPathIter : scanPathList) { LOG_NOFUNC_I(BMS_TAG_DEFAULT, "reboot scan bundle path: %{public}s ", scanPathIter.c_str()); bool removable = IsPreInstallRemovable(scanPathIter); @@ -2284,7 +2284,13 @@ void BMSEventHandler::InnerProcessRebootBundleInstall( (void)BMSEventHandler::OTAInstallSystemBundleNeedCheckUser(filePaths, bundleName, appType, removable); continue; } - needInstallMap[bundleName] = std::make_pair(scanPathIter, removable); + auto iter = needInstallMap.find(bundleName); + if (iter == needInstallMap.end()) { + std::vector filePaths = {scanPathIter}; + needInstallMap[bundleName] = std::make_pair(filePaths, removable); + } else { + iter->second.first.emplace_back(scanPathIter); + } } if (!InnerMultiProcessBundleInstall(needInstallMap, appType)) { LOG_E(BMS_TAG_DEFAULT, "multi install failed"); @@ -2352,7 +2358,7 @@ bool BMSEventHandler::HotPatchAppProcessing(const std::string &bundleName, uint3 } bool BMSEventHandler::InnerMultiProcessBundleInstall( - const std::unordered_map> &needInstallMap, + const std::unordered_map, bool>> &needInstallMap, Constants::AppType appType) { if (needInstallMap.empty()) { @@ -2380,7 +2386,16 @@ bool BMSEventHandler::InnerMultiProcessBundleInstall( std::string bundleName = iter->first; std::pair pair = iter->second; auto task = [bundleName, pair, taskTotalNum, appType, &taskEndNum, &bundlePromise]() { - std::vector filePaths = {pair.first}; + std::vector filePaths = pair.first; + if (filePaths.size() > 1) { + // If the bundle exists in different directories, the real hap file path needs to be obtained + std::vector realHapPaths; + for (const auto &path : filePaths) { + std::vector hapFilePathVec = {path}; + (void)BundleUtil::CheckFilePath(hapFilePathVec, realHapPaths); + } + filePaths = realHapPaths.empty() ? filePaths : realHapPaths; + } (void)BMSEventHandler::OTAInstallSystemBundleNeedCheckUser(filePaths, bundleName, appType, pair.second); taskEndNum++; if (bundlePromise && taskEndNum >= taskTotalNum) { @@ -4443,7 +4458,7 @@ void BMSEventHandler::SendBundleUpdateFailedEvent(const BundleInfo &bundleInfo, } void BMSEventHandler::UpdatePreinstallDB( - const std::unordered_map> &needInstallMap) + const std::unordered_map, bool>> &needInstallMap) { for (const auto &existInfo : loadExistData_) { std::string bundleName = existInfo.first; @@ -4879,7 +4894,7 @@ void BMSEventHandler::InnerProcessAllDynamicIconInfoWhenOta() } void BMSEventHandler::InnerProcessAllThemeAndDynamicIconInfoWhenOta( - const std::unordered_map> &needInstallMap) + const std::unordered_map, bool>> &needInstallMap) { // process dynamic info InnerProcessAllDynamicIconInfoWhenOta(); 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 e4e288e3ff19d080b8f5b9573aa228f94fdb3560..882192be93343d4c4db60aa35bfb7fcd766dfc43 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 @@ -660,7 +660,7 @@ void BMSEventHandler::CheckALLResourceInfo() {} void BMSEventHandler::InnerProcessAllDynamicIconInfoWhenOta() {} void BMSEventHandler::InnerProcessAllThemeAndDynamicIconInfoWhenOta( - const std::unordered_map> &needInstallMap) {} + const std::unordered_map, bool>> &needInstallMap) {} void BMSEventHandler::ProcessBundleResourceInfo() {} 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 1f6c00442a6d30df0fa3c0cbd16575597d1c30ef..f65741f14fdf2b362c8b56293e0b9d29646ed115 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 @@ -1353,10 +1353,31 @@ HWTEST_F(BmsEventHandlerTest, InnerMultiProcessBundleInstall_0100, Function | Sm std::shared_ptr handler = std::make_shared(); EXPECT_NE(handler, nullptr); if (handler) { - std::unordered_map> needInstallMap; + std::unordered_map, bool>> needInstallMap; bool ret = handler->InnerMultiProcessBundleInstall(needInstallMap, Constants::AppType::SYSTEM_APP); EXPECT_TRUE(ret); - needInstallMap["testName"] = std::make_pair("notExist", true); + std::vector filePaths = {"notExist"}; + needInstallMap["testName"] = std::make_pair(filePaths, true); + ret = handler->InnerMultiProcessBundleInstall(needInstallMap, Constants::AppType::SYSTEM_APP); + EXPECT_TRUE(ret); + } +} + +/** + * @tc.number: InnerMultiProcessBundleInstall_0200 + * @tc.name: InnerMultiProcessBundleInstall + * @tc.desc: test InnerMultiProcessBundleInstall + */ +HWTEST_F(BmsEventHandlerTest, InnerMultiProcessBundleInstall_0200, Function | SmallTest | Level0) +{ + std::shared_ptr handler = std::make_shared(); + EXPECT_NE(handler, nullptr); + if (handler) { + std::unordered_map, bool>> needInstallMap; + bool ret = handler->InnerMultiProcessBundleInstall(needInstallMap, Constants::AppType::SYSTEM_APP); + EXPECT_TRUE(ret); + std::vector filePaths = {"notExist", "notExist2"}; + needInstallMap["testName"] = std::make_pair(filePaths, true); ret = handler->InnerMultiProcessBundleInstall(needInstallMap, Constants::AppType::SYSTEM_APP); EXPECT_TRUE(ret); }