diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index be2962b7d..e976b8ed9 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -1495,7 +1495,8 @@ public: return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } - virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state) + virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state, + bool isNeedSendNotify = true) { return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; } diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h index 64c43459e..acb2f59d0 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h @@ -1045,7 +1045,8 @@ public: * @param state Indicates whether the specified application can be uninstalled. * @return Returns ERR_OK if this function is successfully called; returns other ErrCode otherwise. */ - virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state) override; + virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state, + bool isNeedSendNotify = true) override; /** * @brief Query the AbilityInfo by continueType. diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index 47c5cb827..a7bbc650f 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -3817,7 +3817,8 @@ ErrCode BundleMgrHost::HandleSwitchUninstallState(MessageParcel &data, MessagePa HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); std::string bundleName = data.ReadString(); bool state = data.ReadBool(); - ErrCode ret = SwitchUninstallState(bundleName, state); + bool isNeedSendNotify = data.ReadBool(); + ErrCode ret = SwitchUninstallState(bundleName, state, isNeedSendNotify); if (!reply.WriteInt32(ret)) { APP_LOGE("write failed"); return ERR_APPEXECFWK_PARCEL_ERROR; diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp index 948de58fa..eef4dbbf9 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp @@ -4904,7 +4904,8 @@ ErrCode BundleMgrProxy::GetAllPreinstalledApplicationInfos( BundleMgrInterfaceCode::GET_PREINSTALLED_APPLICATION_INFO, data, preinstalledApplicationInfos); } -ErrCode BundleMgrProxy::SwitchUninstallState(const std::string &bundleName, const bool &state) +ErrCode BundleMgrProxy::SwitchUninstallState(const std::string &bundleName, const bool &state, + bool isNeedSendNotify) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); MessageParcel data; @@ -4920,7 +4921,10 @@ ErrCode BundleMgrProxy::SwitchUninstallState(const std::string &bundleName, cons APP_LOGE("write state failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } - + if (!data.WriteBool(isNeedSendNotify)) { + APP_LOGE("write isNeedSendNotify failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } MessageParcel reply; if (!SendTransactCmd(BundleMgrInterfaceCode::SWITCH_UNINSTALL_STATE, data, reply)) { APP_LOGE("SendTransactCmd failed"); diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 1df159b5e..c54f8112f 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -937,7 +937,7 @@ public: std::vector &bundleInfos, int32_t userId); ErrCode GetDeveloperIds(const std::string &appDistributionType, std::vector &developerIdList, int32_t userId); - ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state); + ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state, const bool isNeedSendNotify); ErrCode AddCloneBundle(const std::string &bundleName, const InnerBundleCloneInfo &attr); ErrCode RemoveCloneBundle(const std::string &bundleName, const int32_t userId, int32_t appIndex); diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 2452c28f2..edf248390 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -979,7 +979,8 @@ public: virtual ErrCode GetDeveloperIds(const std::string &appDistributionType, std::vector &developerIdList, int32_t userId) override; - virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state) override; + virtual ErrCode SwitchUninstallState(const std::string &bundleName, const bool &state, + bool isNeedSendNotify) override; virtual ErrCode QueryAbilityInfoByContinueType(const std::string &bundleName, const std::string &continueType, AbilityInfo &abilityInfo, int32_t userId = Constants::UNSPECIFIED_USERID) override; diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index d4592aa57..e984c8c88 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -2209,6 +2209,8 @@ public: bool IsTsanEnabled() const; bool GetUninstallState() const; void SetUninstallState(const bool &uninstallState); + bool IsNeedSendNotify() const; + void SetNeedSendNotify(const bool needStatus); void UpdateMultiAppMode(const InnerBundleInfo &newInfo); void UpdateReleaseType(const InnerBundleInfo &newInfo); ErrCode AddCloneBundle(const InnerBundleCloneInfo &attr); @@ -2319,6 +2321,9 @@ private: // use to control uninstalling bool uninstallState_ = true; + + // need to send a notification when uninstallState_ change + bool isNeedSendNotify_ = false; }; void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 310b0bfc2..445de1d04 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -1912,7 +1912,7 @@ void BundleDataMgr::GetMatchLauncherAbilityInfos(const Want& want, APP_LOGD("bundleName %{public}s exist mainAbility", info.GetBundleName().c_str()); info.GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, responseUserId, mainAbilityInfo.applicationInfo); - if (mainAbilityInfo.applicationInfo.removable) { + if (mainAbilityInfo.applicationInfo.removable && info.IsNeedSendNotify()) { mainAbilityInfo.applicationInfo.removable = info.GetUninstallState(); } mainAbilityInfo.installTime = installTime; @@ -8009,7 +8009,8 @@ ErrCode BundleDataMgr::GetDeveloperIds(const std::string &appDistributionType, return ERR_OK; } -ErrCode BundleDataMgr::SwitchUninstallState(const std::string &bundleName, const bool &state) +ErrCode BundleDataMgr::SwitchUninstallState(const std::string &bundleName, const bool &state, + const bool isNeedSendNotify) { std::unique_lock lock(bundleInfoMutex_); auto infoItem = bundleInfos_.find(bundleName); @@ -8026,6 +8027,7 @@ ErrCode BundleDataMgr::SwitchUninstallState(const std::string &bundleName, const return ERR_OK; } innerBundleInfo.SetUninstallState(state); + innerBundleInfo.SetNeedSendNotify(isNeedSendNotify); if (!dataStorage_->SaveStorageBundleInfo(innerBundleInfo)) { APP_LOGW("update storage failed bundle:%{public}s", bundleName.c_str()); return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index ece7ec7a2..3830cef7a 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -4062,7 +4062,8 @@ ErrCode BundleMgrHostImpl::GetDeveloperIds(const std::string &appDistributionTyp return dataMgr->GetDeveloperIds(appDistributionType, developerIdList, userId); } -ErrCode BundleMgrHostImpl::SwitchUninstallState(const std::string &bundleName, const bool &state) +ErrCode BundleMgrHostImpl::SwitchUninstallState(const std::string &bundleName, const bool &state, + bool isNeedSendNotify) { APP_LOGD("start SwitchUninstallState, bundleName : %{public}s, state : %{public}d", bundleName.c_str(), state); if (!BundlePermissionMgr::IsSystemApp()) { @@ -4080,11 +4081,15 @@ ErrCode BundleMgrHostImpl::SwitchUninstallState(const std::string &bundleName, c APP_LOGE("DataMgr is nullptr"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } - auto resCode = dataMgr->SwitchUninstallState(bundleName, state); + auto resCode = dataMgr->SwitchUninstallState(bundleName, state, isNeedSendNotify); if (resCode != ERR_OK) { APP_LOGE("set status fail"); return resCode; } + if (!isNeedSendNotify) { + APP_LOGI("no need notify %{public}s", bundleName.c_str()); + return resCode; + } InnerBundleInfo innerBundleInfo; bool isSuccess = dataMgr->FetchInnerBundleInfo(bundleName, innerBundleInfo); if (!isSuccess) { diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index fdee230fd..ef5a36464 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -4283,6 +4283,16 @@ void InnerBundleInfo::SetUninstallState(const bool &uninstallState) uninstallState_ = uninstallState; } +bool InnerBundleInfo::IsNeedSendNotify() const +{ + return isNeedSendNotify_; +} + +void InnerBundleInfo::SetNeedSendNotify(const bool needStatus) +{ + isNeedSendNotify_ = needStatus; +} + std::vector InnerBundleInfo::GetAllExtensionDirsInSpecifiedModule(const std::string &moduleName) const { std::vector dirVec; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index 645a73404..21bfc7100 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -9740,7 +9740,7 @@ HWTEST_F(BmsBundleKitServiceTest, SwitchUninstallState_0100, Function | SmallTes { auto hostImpl = std::make_unique(); ASSERT_NE(hostImpl, nullptr); - ErrCode ret = hostImpl->SwitchUninstallState(BUNDLE_NAME_DEMO, true); + ErrCode ret = hostImpl->SwitchUninstallState(BUNDLE_NAME_DEMO, true, false); EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST); } @@ -13152,7 +13152,7 @@ HWTEST_F(BmsBundleKitServiceTest, SwitchUninstallState_0001, Function | SmallTes { auto dataMgr = GetBundleDataMgr(); EXPECT_NE(dataMgr, nullptr); - ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, false); + ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, false, false); EXPECT_EQ(res, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST); } @@ -13169,7 +13169,7 @@ HWTEST_F(BmsBundleKitServiceTest, SwitchUninstallState_0002, Function | SmallTes InnerBundleInfo info; info.SetRemovable(false); dataMgr->bundleInfos_.emplace(BUNDLE_NAME_UNINSTALL_STATE, info); - ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, true); + ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, true, false); EXPECT_EQ(res, ERR_BUNDLE_MANAGER_BUNDLE_CAN_NOT_BE_UNINSTALLED); dataMgr->bundleInfos_.erase(BUNDLE_NAME_UNINSTALL_STATE); } @@ -13187,7 +13187,7 @@ HWTEST_F(BmsBundleKitServiceTest, SwitchUninstallState_0003, Function | SmallTes InnerBundleInfo info; dataMgr->bundleInfos_.emplace(BUNDLE_NAME_UNINSTALL_STATE, info); EXPECT_TRUE(info.uninstallState_); - ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, true); + ErrCode res = dataMgr->SwitchUninstallState(BUNDLE_NAME_UNINSTALL_STATE, true, false); EXPECT_EQ(res, ERR_OK); EXPECT_TRUE(info.uninstallState_); dataMgr->bundleInfos_.erase(BUNDLE_NAME_UNINSTALL_STATE);