From d7ca89cd9c8f54e111ae306afaf8af44a661e1f9 Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Sat, 6 Sep 2025 15:26:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E9=94=81=E4=BC=98=E5=85=88=E5=88=9B?= =?UTF-8?q?=E5=BB=BAota=E6=96=B0=E5=A2=9E=E5=BA=94=E7=94=A8=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- services/bundlemgr/include/bundle_data_mgr.h | 5 +++++ services/bundlemgr/src/bundle_data_mgr.cpp | 18 +++++++++++++++ .../src/bundle_mgr_service_event_handler.cpp | 2 ++ .../src/user_unlocked_event_subscriber.cpp | 7 ++++++ .../bms_data_mgr_test/bms_data_mgr_test.cpp | 22 ++++++++++++++++++- 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index f473cfd14d..ed0a4b394f 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1189,6 +1189,9 @@ public: ErrCode GetTestRunner(const std::string &bundleName, const std::string &moduleName, ModuleTestRunner &testRunner); ErrCode ImplicitQueryAbilityInfosWithDefault(const Want &want, int32_t flags, int32_t userId, std::vector &abilityInfos, AbilityInfo &defaultAbilityInfo, bool &findDefaultApp); + void AddOtaNewInstallBundleName(const std::string &bundleName); + std::set GetOtaNewInstallBundleNames(); + void ClearOtaNewInstallBundleNames(); private: /** @@ -1420,6 +1423,7 @@ private: mutable ffrt::shared_mutex bundleIdMapMutex_; mutable ffrt::shared_mutex callbackMutex_; mutable ffrt::shared_mutex bundleMutex_; + mutable ffrt::shared_mutex otaNewInstallMutex_; std::shared_ptr dataStorage_; std::shared_ptr preInstallDataStorage_; std::shared_ptr bundleStateStorage_; @@ -1453,6 +1457,7 @@ private: std::set appServiceHspBundleName_; // using for plugin event callback std::vector> pluginCallbackList_; + std::set otaNewInstallBundleNames_; static bool HasAppLinkingFlag(uint32_t flags); }; diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 7d0cb071f6..45c58e6ec7 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -11028,6 +11028,24 @@ void BundleDataMgr::NotifyPluginEventCallback(const EventFwk::CommonEventData &e APP_LOGI("end"); } +void BundleDataMgr::AddOtaNewInstallBundleName(const std::string &bundleName) +{ + std::lock_guard lock(otaNewInstallMutex_); + otaNewInstallBundleNames_.insert(bundleName); +} + +std::set BundleDataMgr::GetOtaNewInstallBundleNames() +{ + std::lock_guard lock(otaNewInstallMutex_); + return otaNewInstallBundleNames_; +} + +void BundleDataMgr::ClearOtaNewInstallBundleNames() +{ + std::lock_guard lock(otaNewInstallMutex_); + otaNewInstallBundleNames_.clear(); +} + ErrCode BundleDataMgr::GetAllDynamicIconInfo(const int32_t userId, std::vector &dynamicIconInfos) { APP_LOGI("start userId %{public}d", userId); diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index a552aeb0a9..5ff5d32a36 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -2159,6 +2159,8 @@ void BMSEventHandler::InnerProcessRebootBundleInstall( if (!OTAInstallSystemBundle(filePaths, appType, removable)) { LOG_E(BMS_TAG_DEFAULT, "OTA Install new bundle(%{public}s) error", bundleName.c_str()); SavePreInstallException(scanPathIter); + } else { + dataMgr->AddOtaNewInstallBundleName(bundleName); } continue; } diff --git a/services/bundlemgr/src/user_unlocked_event_subscriber.cpp b/services/bundlemgr/src/user_unlocked_event_subscriber.cpp index e364a452e0..b0660ff30e 100644 --- a/services/bundlemgr/src/user_unlocked_event_subscriber.cpp +++ b/services/bundlemgr/src/user_unlocked_event_subscriber.cpp @@ -249,6 +249,13 @@ void UpdateAppDataMgr::UpdateAppDataDirSelinuxLabel(int32_t userId) return; } + std::set otaNewInstallBundleNames = dataMgr->GetOtaNewInstallBundleNames(); + dataMgr->ClearOtaNewInstallBundleNames(); + std::stable_partition(bundleInfos.begin(), bundleInfos.end(), + [&otaNewInstallBundleNames](const BundleInfo &info) { + return otaNewInstallBundleNames.find(info.name) != otaNewInstallBundleNames.end(); + }); + ReturnIfNewTask(ProcessUpdateAppDataDir, tempTaskNum, userId, bundleInfos, ServiceConstants::BUNDLE_EL[1]); #ifdef CHECK_ELDIR_ENABLED ReturnIfNewTask(ProcessUpdateAppDataDir, tempTaskNum, userId, bundleInfos, ServiceConstants::DIR_EL3); diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp index a4f58c4796..f3a0e14bfc 100644 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp @@ -6548,4 +6548,24 @@ HWTEST_F(BmsDataMgrTest, SetBundleUserInfoRemovable_0001, TestSize.Level1) bundleDataMgr.GetInnerBundleUserInfoByUserId(bundleName, userId, getUserInfo); EXPECT_FALSE(getUserInfo.isRemovable); } -} // OHOS \ No newline at end of file + +/** + * @tc.number: OtaNewInstallBundleName_0001 + * @tc.name: OtaNewInstallBundleName + * @tc.desc: test OtaNewInstallBundleName + */ +HWTEST_F(BmsDataMgrTest, OtaNewInstallBundleName_0001, Function | MediumTest | Level1) +{ + BundleDataMgr bundleDataMgr; + EXPECT_EQ(bundleDataMgr.otaNewInstallBundleNames_.size(), 0); + bundleDataMgr.AddOtaNewInstallBundleName(BUNDLE_NAME); + EXPECT_EQ(bundleDataMgr.otaNewInstallBundleNames_.size(), 1); + + std::set otaNewInstallBundleNames = bundleDataMgr.GetOtaNewInstallBundleNames(); + EXPECT_EQ(otaNewInstallBundleNames.size(), 1); + EXPECT_EQ(bundleDataMgr.otaNewInstallBundleNames_.size(), 1); + + bundleDataMgr.ClearOtaNewInstallBundleNames(); + EXPECT_EQ(bundleDataMgr.otaNewInstallBundleNames_.size(), 0); +} +} // OHOS -- Gitee