diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index f473cfd14d4c086c6f3d6e62bf14e3d394faf207..ed0a4b394fa7a8361a596db738d56e142db8786e 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 7d0cb071f604b3cc45f79d6dcbb0f5771bc7beb5..45c58e6ec7820079610ff03411e8c73aad072b43 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 a552aeb0a94e7c3cb38a9fbdeb171daf7164ed1f..5ff5d32a367d157c8ddd88b5b9eb486f96b79a4c 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 e364a452e096926175292b51968f9ddc4f20aa46..b0660ff30e96c6cb950d92723656236c9e3df4be 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 a4f58c4796fae64e4863a80b92578937af6711bb..f3a0e14bfcc843a47f5bba02cc27cb381beaef70 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