From 2ead56e74170d3b34c1b7c3517f25bdf92ba2fe5 Mon Sep 17 00:00:00 2001 From: wang19954 Date: Thu, 11 Sep 2025 16:59:44 +0800 Subject: [PATCH] IssueNo:#ICXKJP Description:fix ota bug Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../bundle_mgr_service_event_handler.h | 7 ++--- .../src/bundle_mgr_service_event_handler.cpp | 27 ++++++++++++++----- .../src/bundle_mgr_service_event_handler.cpp | 2 +- .../bms_event_handler_test.cpp | 25 +++++++++++++++-- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index 270dbcfe63..4edd846991 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -530,7 +530,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 a05d40006e..afd21949e7 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -2118,7 +2118,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); @@ -2260,7 +2260,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"); @@ -2322,7 +2328,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()) { @@ -2350,7 +2356,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) { @@ -4426,7 +4441,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; @@ -4863,7 +4878,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 994cf7fa30..83c101d9e7 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 718b7f849c..88cd663de7 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); } -- Gitee