mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
链接跳转管控
Signed-off-by: donglin <donglin9@huawei.com> Change-Id: I835304597ea713b61e352c11312ffe410cd0da27
This commit is contained in:
+3
-1
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "parcel.h"
|
||||
#include "want.h"
|
||||
#include "ability_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace EcologicalRuleMgrService {
|
||||
@@ -69,10 +70,11 @@ struct AbilityCallerInfo : public Parcelable {
|
||||
std::string targetAppDistType = "";
|
||||
std::string targetLinkFeature = "";
|
||||
int32_t targetLinkType = LINK_TYPE_INVALID;
|
||||
int32_t callerAbilityType = 0L;
|
||||
AppExecFwk::AbilityType callerAbilityType = AppExecFwk::AbilityType::UNKNOWN;
|
||||
int32_t embedded = 0;
|
||||
std::string callerAppProvisionType;
|
||||
std::string targetAppProvisionType;
|
||||
AppExecFwk::ExtensionAbilityType callerExtensionAbilityType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId);
|
||||
void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId,
|
||||
const sptr<IRemoteObject> &callerToken = nullptr);
|
||||
void InitErmsCallerInfo(Want &want, ErmsCallerInfo &callerInfo) const;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
||||
@@ -30,6 +30,7 @@ struct StartAbilityInfo {
|
||||
AppExecFwk::AbilityInfo &abilityInfo);
|
||||
static std::shared_ptr<StartAbilityInfo> CreateStartAbilityInfo(const Want &want, int32_t userId,
|
||||
int32_t appIndex);
|
||||
static std::shared_ptr<StartAbilityInfo> CreateCallerAbilityInfo(const sptr<IRemoteObject> &callerToken);
|
||||
|
||||
static std::shared_ptr<StartAbilityInfo> CreateStartExtensionInfo(const Want &want, int32_t userId,
|
||||
int32_t appIndex);
|
||||
@@ -48,15 +49,18 @@ struct StartAbilityUtils {
|
||||
static int32_t GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken);
|
||||
static bool GetApplicationInfo(const std::string &bundleName, int32_t userId,
|
||||
AppExecFwk::ApplicationInfo &appInfo);
|
||||
static bool GetCallerAbilityInfo(const sptr<IRemoteObject> &callerToken,
|
||||
AppExecFwk::AbilityInfo &abilityInfo);
|
||||
static thread_local std::shared_ptr<StartAbilityInfo> startAbilityInfo;
|
||||
|
||||
static thread_local std::shared_ptr<StartAbilityInfo> callerAbilityInfo;
|
||||
static thread_local bool skipCrowTest;
|
||||
static thread_local bool skipStartOther;
|
||||
static thread_local bool skipErms;
|
||||
};
|
||||
|
||||
struct StartAbilityInfoWrap {
|
||||
StartAbilityInfoWrap(const Want &want, int32_t validUserId, int32_t appIndex, bool isExtension = false);
|
||||
StartAbilityInfoWrap(const Want &want, int32_t validUserId, int32_t appIndex,
|
||||
const sptr<IRemoteObject> &callerToken, bool isExtension = false);
|
||||
~StartAbilityInfoWrap();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -877,7 +877,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
|
||||
int32_t validUserId = oriValidUserId;
|
||||
|
||||
StartAbilityInfoWrap threadLocalInfo(want, validUserId,
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken));
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), callerToken);
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(),
|
||||
true, nullptr);
|
||||
auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
|
||||
@@ -1160,7 +1160,7 @@ int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSett
|
||||
int32_t oriValidUserId = GetValidUserId(userId);
|
||||
int32_t validUserId = oriValidUserId;
|
||||
StartAbilityInfoWrap threadLocalInfo(want, validUserId,
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken));
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), callerToken);
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(),
|
||||
true, nullptr);
|
||||
result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
|
||||
@@ -1425,7 +1425,7 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St
|
||||
int32_t oriValidUserId = GetValidUserId(userId);
|
||||
int32_t validUserId = oriValidUserId;
|
||||
StartAbilityInfoWrap threadLocalInfo(want, validUserId,
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken));
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), callerToken);
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(),
|
||||
true, nullptr);
|
||||
auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
|
||||
@@ -1819,7 +1819,7 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo)
|
||||
|
||||
auto requestCode = sessionInfo->requestCode;
|
||||
StartAbilityInfoWrap threadLocalInfo(sessionInfo->want, currentUserId,
|
||||
StartAbilityUtils::GetAppIndex(sessionInfo->want, sessionInfo->callerToken));
|
||||
StartAbilityUtils::GetAppIndex(sessionInfo->want, sessionInfo->callerToken), sessionInfo->callerToken);
|
||||
if (sessionInfo->want.GetBoolParam(IS_CALL_BY_SCB, true)) {
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "interceptorExecuter_ called.");
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(sessionInfo->want, requestCode,
|
||||
@@ -2388,7 +2388,7 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp
|
||||
|
||||
int32_t validUserId = GetValidUserId(userId);
|
||||
StartAbilityInfoWrap threadLocalInfo(want, validUserId,
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), true);
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), callerToken, true);
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), false, nullptr);
|
||||
result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
|
||||
interceptorExecuter_->DoProcess(interceptorParam);
|
||||
@@ -6428,7 +6428,7 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr<IAbil
|
||||
|
||||
AbilityUtil::RemoveWantKey(const_cast<Want &>(want));
|
||||
StartAbilityInfoWrap threadLocalInfo(want, GetUserId(),
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken));
|
||||
StartAbilityUtils::GetAppIndex(want, callerToken), callerToken);
|
||||
AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, 0, GetUserId(), true, nullptr);
|
||||
auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE :
|
||||
interceptorExecuter_->DoProcess(interceptorParam);
|
||||
|
||||
+12
-7
@@ -125,15 +125,12 @@ AbilityCallerInfo *AbilityCallerInfo::Unmarshalling(Parcel &in)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!in.ReadInt32(info->callerAbilityType)) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "read callerAbilityType failed");
|
||||
delete info;
|
||||
return nullptr;
|
||||
}
|
||||
info->callerAbilityType = static_cast<AppExecFwk::AbilityType>(in.ReadInt32());
|
||||
|
||||
info->embedded = in.ReadInt32();
|
||||
info->callerAppProvisionType = in.ReadString();
|
||||
info->targetAppProvisionType = in.ReadString();
|
||||
info->callerExtensionAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(in.ReadInt32());
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -157,6 +154,11 @@ bool AbilityCallerInfo::Marshalling(Parcel &parcel) const
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAppProvisionType failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(callerExtensionAbilityType))) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerExtensionAbilityType failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -207,10 +209,11 @@ bool AbilityCallerInfo::DoMarshallingOne(Parcel &parcel) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(callerAbilityType)) {
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(callerAbilityType))) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerAbilityType failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -220,7 +223,9 @@ std::string AbilityCallerInfo::ToString() const
|
||||
",pid:" + std::to_string(pid) + ",callerAppType:" + std::to_string(callerAppType) +
|
||||
",targetAppType:" + std::to_string(targetAppType) + ",callerModelType:" + std::to_string(callerModelType) +
|
||||
",targetAppDistType:" + targetAppDistType + ",targetLinkFeature:" + targetLinkFeature + ",targetLinkType:" +
|
||||
std::to_string(targetLinkType) + ",callerAbilityType:" + std::to_string(callerAbilityType) + ",embedded:" +
|
||||
std::to_string(targetLinkType) + ",callerAbilityType:" +
|
||||
std::to_string(static_cast<int32_t>(callerAbilityType)) + ",callerExtensionAbilityType:" +
|
||||
std::to_string(static_cast<int32_t>(callerExtensionAbilityType)) + ",embedded:" +
|
||||
std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType + ",targetAppProvisionType:" +
|
||||
targetAppProvisionType + "}";
|
||||
return str;
|
||||
|
||||
@@ -54,7 +54,7 @@ ErrCode EcologicalRuleInterceptor::DoProcess(AbilityInterceptorParam param)
|
||||
}
|
||||
AAFwk::Want newWant = param.want;
|
||||
newWant.RemoveAllFd();
|
||||
GetEcologicalCallerInfo(newWant, callerInfo, param.userId);
|
||||
GetEcologicalCallerInfo(newWant, callerInfo, param.userId, param.callerToken);
|
||||
std::string supportErms = OHOS::system::GetParameter(ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE, "true");
|
||||
if (supportErms == "false") {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Abilityms not support Erms between applications.");
|
||||
@@ -128,30 +128,39 @@ bool EcologicalRuleInterceptor::DoProcess(Want &want, int32_t userId)
|
||||
return rule.isAllow;
|
||||
}
|
||||
|
||||
void EcologicalRuleInterceptor::GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId)
|
||||
void EcologicalRuleInterceptor::GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId,
|
||||
const sptr<IRemoteObject> &callerToken)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
InitErmsCallerInfo(const_cast<Want &>(want), callerInfo);
|
||||
|
||||
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
|
||||
if (bundleMgrHelper == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "The bundleMgrHelper is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string callerBundleName;
|
||||
ErrCode err = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callerInfo.uid, callerBundleName));
|
||||
if (err != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Get callerBundleName failed,uid: %{public}d.", callerInfo.uid);
|
||||
return;
|
||||
}
|
||||
AppExecFwk::ApplicationInfo callerAppInfo;
|
||||
bool getCallerResult = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(callerBundleName,
|
||||
AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, callerAppInfo));
|
||||
if (!getCallerResult) {
|
||||
TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "Get callerAppInfo failed.");
|
||||
return;
|
||||
AppExecFwk::AbilityInfo callerAbilityInfo;
|
||||
if (StartAbilityUtils::GetCallerAbilityInfo(callerToken, callerAbilityInfo)) {
|
||||
callerAppInfo = callerAbilityInfo.applicationInfo;
|
||||
callerInfo.callerAbilityType = callerAbilityInfo.type;
|
||||
callerInfo.callerExtensionAbilityType = callerAbilityInfo.extensionAbilityType;
|
||||
} else {
|
||||
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
|
||||
if (bundleMgrHelper == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "The bundleMgrHelper is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string callerBundleName;
|
||||
ErrCode err = IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callerInfo.uid, callerBundleName));
|
||||
if (err != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Get callerBundleName failed,uid: %{public}d.", callerInfo.uid);
|
||||
return;
|
||||
}
|
||||
bool getCallerResult = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(callerBundleName,
|
||||
AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, callerAppInfo));
|
||||
if (!getCallerResult) {
|
||||
TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "Get callerAppInfo failed.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
callerInfo.callerAppProvisionType = callerAppInfo.appProvisionType;
|
||||
if (callerAppInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE) {
|
||||
TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "the caller type is atomic service");
|
||||
|
||||
@@ -31,6 +31,7 @@ constexpr const char* SCREENSHOT_BUNDLE_NAME = "com.huawei.ohos.screenshot";
|
||||
constexpr const char* SCREENSHOT_ABILITY_NAME = "com.huawei.ohos.screenshot.ServiceExtAbility";
|
||||
}
|
||||
thread_local std::shared_ptr<StartAbilityInfo> StartAbilityUtils::startAbilityInfo;
|
||||
thread_local std::shared_ptr<StartAbilityInfo> StartAbilityUtils::callerAbilityInfo;
|
||||
thread_local bool StartAbilityUtils::skipCrowTest = false;
|
||||
thread_local bool StartAbilityUtils::skipStartOther = false;
|
||||
thread_local bool StartAbilityUtils::skipErms = false;
|
||||
@@ -66,8 +67,26 @@ bool StartAbilityUtils::GetApplicationInfo(const std::string &bundleName, int32_
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StartAbilityUtils::GetCallerAbilityInfo(const sptr<IRemoteObject> &callerToken,
|
||||
AppExecFwk::AbilityInfo &abilityInfo)
|
||||
{
|
||||
if (StartAbilityUtils::callerAbilityInfo) {
|
||||
abilityInfo = StartAbilityUtils::callerAbilityInfo->abilityInfo;
|
||||
} else {
|
||||
if (callerToken == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
|
||||
if (abilityRecord == nullptr) {
|
||||
return false;
|
||||
}
|
||||
abilityInfo = abilityRecord->GetAbilityInfo();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StartAbilityInfoWrap::StartAbilityInfoWrap(const Want &want, int32_t validUserId, int32_t appIndex,
|
||||
bool isExtension)
|
||||
const sptr<IRemoteObject> &callerToken, bool isExtension)
|
||||
{
|
||||
if (StartAbilityUtils::startAbilityInfo != nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "startAbilityInfo has been created");
|
||||
@@ -91,11 +110,17 @@ StartAbilityInfoWrap::StartAbilityInfoWrap(const Want &want, int32_t validUserId
|
||||
StartAbilityUtils::skipCrowTest = true;
|
||||
StartAbilityUtils::skipStartOther = true;
|
||||
}
|
||||
|
||||
if (StartAbilityUtils::callerAbilityInfo != nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "callerAbilityInfo has been created");
|
||||
}
|
||||
StartAbilityUtils::callerAbilityInfo = StartAbilityInfo::CreateCallerAbilityInfo(callerToken);
|
||||
}
|
||||
|
||||
StartAbilityInfoWrap::~StartAbilityInfoWrap()
|
||||
{
|
||||
StartAbilityUtils::startAbilityInfo.reset();
|
||||
StartAbilityUtils::callerAbilityInfo.reset();
|
||||
StartAbilityUtils::skipCrowTest = false;
|
||||
StartAbilityUtils::skipStartOther = false;
|
||||
StartAbilityUtils::skipErms = false;
|
||||
@@ -220,5 +245,22 @@ std::shared_ptr<StartAbilityInfo> StartAbilityInfo::CreateStartExtensionInfo(con
|
||||
|
||||
return abilityInfo;
|
||||
}
|
||||
|
||||
std::shared_ptr<StartAbilityInfo> StartAbilityInfo::CreateCallerAbilityInfo(const sptr<IRemoteObject> &callerToken)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (callerToken == nullptr) {
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "not call from context.");
|
||||
return nullptr;
|
||||
}
|
||||
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
|
||||
if (abilityRecord == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "can not find abilityRecord");
|
||||
return nullptr;
|
||||
}
|
||||
auto request = std::make_shared<StartAbilityInfo>();
|
||||
request->abilityInfo = abilityRecord->GetAbilityInfo();
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user