IssueNo:#I5BOAL:补充拆分ConnectFreeInstall的判断和业务

Description:拆分ConnectFreeInstall的判断和业务
Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source: No

Signed-off-by: dy <dingyao5@huawei.com>
This commit is contained in:
dy
2022-06-14 10:05:53 +08:00
parent 310f4dc565
commit eb22cea2ad
5 changed files with 81 additions and 119 deletions
@@ -551,9 +551,7 @@ public:
int requestCode,
int callerUid = DEFAULT_INVAL_VALUE,
int32_t userId = DEFAULT_INVAL_VALUE);
bool IsStartFreeInstall(const Want &want);
int StartFreeInstall(const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId);
int CheckPermission(const std::string &bundleName, const std::string &permission);
void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag);
@@ -1015,9 +1013,6 @@ private:
bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri);
int StartFreeInstall(const Want &want, int32_t userId, int requestCode,
const sptr<IRemoteObject> &callerToken);
bool CheckIsFreeInstall(const Want &want);
bool CheckTargetBundleList(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken);
void HandleFreeInstallErrorCode(int &resultCode);
int NotifyDmsCallback(const Want &want, int resultCode);
@@ -137,6 +137,15 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi
return (int64_t)(t.tv_sec);
}
[[maybe_unused]] static bool IsStartFreeInstall(const Want &want)
{
auto flags = want.GetFlags();
if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) {
return true;
}
return false;
}
static sptr<AppExecFwk::IBundleMgr> GetBundleManager()
{
auto bundleObj =
@@ -83,28 +83,16 @@ public:
int32_t userId, int requestCode);
/**
* Check if the connect request is free install.
* Connect if the request is free install.
* @param want, the want of the ability to free install.
* @param userId, designation User ID.
* @param callerToken, caller ability token.
* @param localDeviceId, the device id of local.
* @return Returns ERR_OK on success, others on failure.
*/
int IsConnectFreeInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken,
int ConnectFreeInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken,
std::string& localDeviceId);
/**
* Check if the connect request is free install.
* @param want, the want of the ability to free install.
* @param userId, designation User ID.
* @param callerToken, caller ability token.
* @param requestCode, ability request code.
* @param isRemote, is remote ability to free install.
* @return Returns ERR_OK on success, others on failure.
*/
int StartFreeInstall(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken,
int requestCode, bool isRemote);
private:
std::weak_ptr<AbilityManagerService> server_;
struct FreeInstallInfo {
@@ -119,7 +107,6 @@ private:
std::vector<FreeInstallInfo> freeInstallList_;
std::vector<FreeInstallInfo> dmsFreeInstallCbs_;
bool CheckIsFreeInstall(const Want &want);
bool CheckTargetBundleList(const Want &want, int32_t userId, const sptr<IRemoteObject> &callerToken);
int HandleFreeInstallErrorCode(int resultCode);
int NotifyDmsCallback(const Want &want, int resultCode);
@@ -362,8 +362,9 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
if (callerToken != nullptr) {
if (CheckIfOperateRemote(want)) {
if (IsStartFreeInstall(want)) {
return StartFreeInstall(want, callerToken, requestCode, validUserId);
if (AbilityUtil::IsStartFreeInstall(want) && freeInstallManager_ != nullptr) {
return freeInstallManager_->FreeInstall(
want, validUserId, requestCode, callerToken, CheckIfOperateRemote(want));
}
if (requestCode == DEFAULT_REQUEST_CODE) {
HILOG_INFO("AbilityManagerService::StartAbility. try to StartRemoteAbility");
@@ -376,10 +377,11 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
return StartRemoteAbility(newWant, requestCode);
}
}
if (IsStartFreeInstall(want)) {
int ret = StartFreeInstall(want, callerToken, requestCode, validUserId);
if (AbilityUtil::IsStartFreeInstall(want) && freeInstallManager_ != nullptr) {
int ret = freeInstallManager_->FreeInstall(
want, validUserId, requestCode, callerToken, CheckIfOperateRemote(want));
if (ret != ERR_OK) {
HILOG_DEBUG("StartFreeInstall ret : %{public}d", ret);
HILOG_DEBUG("FreeInstall ret : %{public}d", ret);
return ret;
}
}
@@ -480,14 +482,15 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
int32_t oriValidUserId = GetValidUserId(userId);
int32_t validUserId = oriValidUserId;
if (IsStartFreeInstall(want)) {
if (CheckIfOperateRemote(want)) {
if (AbilityUtil::IsStartFreeInstall(want)) {
if (CheckIfOperateRemote(want) || freeInstallManager_ == nullptr) {
HILOG_ERROR("can not start remote free install");
return ERR_INVALID_VALUE;
}
int ret = StartFreeInstall(want, callerToken, requestCode, validUserId);
int ret = freeInstallManager_->FreeInstall(
want, validUserId, requestCode, callerToken, CheckIfOperateRemote(want));
if (ret != ERR_OK) {
HILOG_DEBUG("StartFreeInstall ret : %{public}d", ret);
HILOG_DEBUG("FreeInstall ret : %{public}d", ret);
return ret;
}
}
@@ -614,14 +617,15 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
int32_t oriValidUserId = GetValidUserId(userId);
int32_t validUserId = oriValidUserId;
if (IsStartFreeInstall(want)) {
if (CheckIfOperateRemote(want)) {
if (AbilityUtil::IsStartFreeInstall(want)) {
if (CheckIfOperateRemote(want) || freeInstallManager_ == nullptr) {
HILOG_ERROR("can not start remote free install");
return ERR_INVALID_VALUE;
}
int ret = StartFreeInstall(want, callerToken, requestCode, validUserId);
int ret = freeInstallManager_->FreeInstall(
want, validUserId, requestCode, callerToken, CheckIfOperateRemote(want));
if (ret != ERR_OK) {
HILOG_DEBUG("StartFreeInstall ret : %{public}d", ret);
HILOG_DEBUG("FreeInstall ret : %{public}d", ret);
return ret;
}
}
@@ -711,15 +715,6 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st
return ret;
}
bool AbilityManagerService::IsStartFreeInstall(const Want &want)
{
auto flags = want.GetFlags();
if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) {
return true;
}
return false;
}
bool AbilityManagerService::IsBackgroundTaskUid(const int uid)
{
#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
@@ -729,13 +724,6 @@ bool AbilityManagerService::IsBackgroundTaskUid(const int uid)
#endif
}
int AbilityManagerService::StartFreeInstall(
const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
{
HILOG_INFO("StartAbility with free install flags");
return freeInstallManager_->StartFreeInstall(want, userId, callerToken, requestCode, CheckIfOperateRemote(want));
}
int AbilityManagerService::CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest,
int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType)
{
@@ -1293,12 +1281,14 @@ int AbilityManagerService::ConnectAbility(
return ERR_INVALID_VALUE;
}
int result = freeInstallManager_->IsConnectFreeInstall(want, validUserId, callerToken, localDeviceId);
if (result != ERR_OK) {
eventInfo.errCode = result;
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
HiSysEventType::FAULT, eventInfo);
return result;
if (AbilityUtil::IsStartFreeInstall(want) && freeInstallManager_ != nullptr) {
int result = freeInstallManager_->ConnectFreeInstall(want, validUserId, callerToken, localDeviceId);
if (result != ERR_OK) {
eventInfo.errCode = result;
AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR,
HiSysEventType::FAULT, eventInfo);
return result;
}
}
Want abilityWant = want;
@@ -4672,6 +4662,10 @@ int AbilityManagerService::FreeInstallAbilityFromRemote(const Want &want, const
int32_t userId, int requestCode)
{
int32_t validUserId = GetValidUserId(userId);
if (freeInstallManager_ == nullptr) {
HILOG_ERROR("freeInstallManager_ is nullptr");
return ERR_INVALID_VALUE;
}
return freeInstallManager_->FreeInstallAbilityFromRemote(want, callback, validUserId, requestCode);
}
@@ -32,17 +32,6 @@ FreeInstallManager::FreeInstallManager(const std::weak_ptr<AbilityManagerService
{
}
bool FreeInstallManager::CheckIsFreeInstall(const Want &want)
{
HILOG_INFO("%{public}s", __func__);
auto flags = want.GetFlags();
if ((flags & Want::FLAG_INSTALL_ON_DEMAND) == Want::FLAG_INSTALL_ON_DEMAND) {
HILOG_INFO("StartAbility with free install flags");
return true;
}
return false;
}
bool FreeInstallManager::IsTopAbility(const sptr<IRemoteObject> &callerToken)
{
HILOG_INFO("%{public}s", __func__);
@@ -301,67 +290,55 @@ int FreeInstallManager::HandleFreeInstallErrorCode(int resultCode)
return itToApp->second;
}
int FreeInstallManager::IsConnectFreeInstall(const Want &want, int32_t userId,
int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId,
const sptr<IRemoteObject> &callerToken, std::string& localDeviceId)
{
if (CheckIsFreeInstall(want)) {
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
AppExecFwk::AbilityType type = abilityRecord->GetAbilityInfo().type;
if (type == AppExecFwk::AbilityType::PAGE) {
if (!IsTopAbility(callerToken)) {
return NOT_TOP_ABILITY;
}
}
std::string wantBundleName = want.GetElement().GetBundleName();
std::string wantAbilityName = want.GetElement().GetAbilityName();
std::string wantDeviceId = want.GetElement().GetDeviceID();
std::string wantModuleName = want.GetStringParam("moduleName");
if (!(localDeviceId == wantDeviceId || wantDeviceId.empty())) {
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. wantDeviceId error");
return ERR_INVALID_VALUE;
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (abilityRecord == nullptr) {
return ERR_INVALID_VALUE;
}
AppExecFwk::AbilityType type = abilityRecord->GetAbilityInfo().type;
if (type == AppExecFwk::AbilityType::PAGE) {
if (!IsTopAbility(callerToken)) {
return NOT_TOP_ABILITY;
}
}
std::string wantBundleName = want.GetElement().GetBundleName();
std::string wantAbilityName = want.GetElement().GetAbilityName();
std::string wantDeviceId = want.GetElement().GetDeviceID();
std::string wantModuleName = want.GetStringParam("moduleName");
if (!(localDeviceId == wantDeviceId || wantDeviceId.empty())) {
HILOG_ERROR("AbilityManagerService::ConnectFreeInstall. wantDeviceId error");
return ERR_INVALID_VALUE;
}
if (wantBundleName.empty() || wantAbilityName.empty()) {
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. wantBundleName or wantAbilityName is empty");
return ERR_INVALID_VALUE;
}
auto bms = AbilityUtil::GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED);
int callerUid = IPCSkeleton::GetCallingUid();
std::string LocalBundleName;
bms->GetBundleNameForUid(callerUid, LocalBundleName);
if (LocalBundleName != wantBundleName) {
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. wantBundleName is not local BundleName");
return ERR_INVALID_VALUE;
}
AppExecFwk::AbilityInfo abilityInfo;
if (!(bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId,
abilityInfo))) {
HILOG_INFO("AbilityManagerService::IsConnectFreeInstall. try to FreeInstall");
int result = FreeInstall(want, userId, DEFAULT_INVAL_VALUE, callerToken, false);
if (result) {
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. FreeInstall error");
return result;
}
HILOG_INFO("AbilityManagerService::IsConnectFreeInstall. FreeInstall success");
if (wantBundleName.empty() || wantAbilityName.empty()) {
HILOG_ERROR("AbilityManagerService::ConnectFreeInstall. wantBundleName or wantAbilityName is empty");
return ERR_INVALID_VALUE;
}
auto bms = AbilityUtil::GetBundleManager();
CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED);
int callerUid = IPCSkeleton::GetCallingUid();
std::string localBundleName;
bms->GetBundleNameForUid(callerUid, localBundleName);
if (localBundleName != wantBundleName) {
HILOG_ERROR("AbilityManagerService::ConnectFreeInstall. wantBundleName is not local BundleName");
return ERR_INVALID_VALUE;
}
AppExecFwk::AbilityInfo abilityInfo;
if (!(bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, userId,
abilityInfo))) {
HILOG_INFO("AbilityManagerService::ConnectFreeInstall. try to FreeInstall");
int result = FreeInstall(want, userId, DEFAULT_INVAL_VALUE, callerToken, false);
if (result) {
HILOG_ERROR("AbilityManagerService::ConnectFreeInstall. FreeInstall error");
return result;
}
HILOG_INFO("AbilityManagerService::ConnectFreeInstall. FreeInstall success");
}
return ERR_OK;
}
int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId,
const sptr<IRemoteObject> &callerToken, int requestCode, bool isRemote)
{
int result = FreeInstall(want, userId, DEFAULT_INVAL_VALUE, callerToken, isRemote);
if (result) {
HILOG_ERROR("AbilityManagerService::IsConnectFreeInstall. FreeInstall error");
return result;
}
return ERR_OK;
}
void FreeInstallManager::OnInstallFinished(int resultCode, const Want &want, int32_t userId)
{
HILOG_INFO("%{public}s resultCode = %{public}d", __func__, resultCode);