!7110 设置卸载状态新增参数

Merge pull request !7110 from jiangminsen/master001
This commit is contained in:
openharmony_ci 2024-09-28 10:35:38 +00:00 committed by Gitee
commit 7d511e36d9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 45 additions and 15 deletions

View File

@ -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;
}

View File

@ -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.

View File

@ -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;

View File

@ -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");

View File

@ -937,7 +937,7 @@ public:
std::vector<BundleInfo> &bundleInfos, int32_t userId);
ErrCode GetDeveloperIds(const std::string &appDistributionType,
std::vector<std::string> &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);

View File

@ -979,7 +979,8 @@ public:
virtual ErrCode GetDeveloperIds(const std::string &appDistributionType,
std::vector<std::string> &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;

View File

@ -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);

View File

@ -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<std::shared_mutex> 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;

View File

@ -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) {

View File

@ -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<std::string> InnerBundleInfo::GetAllExtensionDirsInSpecifiedModule(const std::string &moduleName) const
{
std::vector<std::string> dirVec;

View File

@ -9740,7 +9740,7 @@ HWTEST_F(BmsBundleKitServiceTest, SwitchUninstallState_0100, Function | SmallTes
{
auto hostImpl = std::make_unique<BundleMgrHostImpl>();
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);