!19163 merge Supportdistributedintent_0430 into master

support dms intent

Created-by: renjh5496
Commit-by: renjh5496
Merged-by: openharmony_ci
Description: **IssueNo**:
https://gitcode.com/openharmony/ability_ability_runtime/issues/15116
**Description**:

**稳定性自检:**
| 自检项                                                       | 自检结果  |
| ------------------------------------------------------------ | -------- |
| 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发              |          |
| 成员变量进行赋值或创建需要排查并发                               |          |
| 谨慎在lambda表达式中使用引用捕获                                |          |
| 谨慎在未经拷贝的情况下使用外部传入的string、C字符串               |          |
| map\vector\list\set等stl模板类使用时需要排查并发                |          |
| 谨慎考虑加锁范围                                               |          |
| 在IPC通信中谨慎使用同步通信方式                                 |          |
| 禁止传递this指针至其他模块或线程(特别是eventhandler任务)        |          |
| 禁止将外部传入的裸指针在内部直接构造智能指针                      |          |
| 禁止多个独立创建的智能指针管理同一地址                           |          |
| 禁止在析构函数中抛异步任务                                      |          |
| 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁             |          |
| 禁止在对外接口中未经判空直接使用外部传入的指针                    |          |
| 禁止接口返回局部变量引用                                        |          |
| 禁止在信号函数中加锁                                            |          |
| 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作           |          |
| 禁止将同一个cpp编译在不同的so中                                 |          |

**安全编码自检:**
| 自检项                                                          | 自检结果 |
| -------------------------------------------------------------- | -------- |
| 裸指针避免通过隐式转换构造为sptr                                 |          |
| json对象在取值之前必须先判断类型,避免类型不匹配                   |          |
| 序列化时必须对传入的数组大小进行校验,避免出现超大数组              |          |
| 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型            |          |
| 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 |          |
| 指针变量、表示资源描述符的变量、bool变量必须赋初值                  |          |
| readParcelable获取的对象使用前需要判空                            |          |
| 分配和释放内存的函数需要成对出现                                   |          |
| 申请内存后异常退出前需要及时进行内存释放                            |          |
| 内存申请前必须对内存大小进行合法性校验                              |          |
| 内存分配后必须判断是否成功                                         |          |
| 禁止使用realloc、alloca函数                                       |          |
| 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰          |          |
| 禁止打印内存地址                                                  |          |
| 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0               |          |
| 禁止对有符号整数进行位操作符运算                                    |          |
| 禁止对指针进行逻辑或位运算                                         |          |
| 循环次数如果收外部数据控制,需要检验其合法性                         |          |
| 禁止使用内存操作类危险函数,需要使用安全函数                         |          |
| 谨慎使用不可重入函数                                               |          |
| 必须检查安全函数的返回值,并进行正确处理                             |          |
| 禁止仅通过TokenType类型判断绕过权限校验                             |          |

**TDD Result**:

**XTS Result**:

### 是否已执行L0用例
- [ ] 已验证
- [ ] 不涉及。如不涉及,请写明理由


See merge request: openharmony/ability_ability_runtime!19163
This commit is contained in:
openharmony_ci
2026-05-06 11:15:13 +08:00
59 changed files with 885 additions and 164 deletions
@@ -63,6 +63,15 @@ bool UnwrapExecuteParam(ani_env *env, ani_object param, AppExecFwk::InsightInten
}
executeParam.insightIntentName_ = insightIntentName;
if (IsExistsProperty(env, param, "deviceId")) {
std::string deviceId {""};
if (!GetStringProperty(env, param, "deviceId", deviceId)) {
TAG_LOGE(AAFwkTag::INTENT, "Wrong argument type deviceId");
return false;
}
executeParam.deviceId_ = deviceId;
}
ani_ref aniIntentParam = nullptr;
if (!GetRefProperty(env, param, "insightIntentParam", aniIntentParam)) {
TAG_LOGE(AAFwkTag::INTENT, "null aniIntentParam");
@@ -34,6 +34,7 @@ export default namespace insightIntentDriver {
uris?: Array<string>;
flags?: int;
userId?: int;
deviceId?: string;
}
export interface InsightIntentInfoFilter {
@@ -64,6 +64,16 @@ bool UnwrapExecuteParam(napi_env env, napi_value param, InsightIntentExecutePara
return false;
}
if (IsExistsByPropertyName(env, param, "deviceId")) {
TAG_LOGI(AAFwkTag::JSNAPI, "has deviceId");
std::string deviceId {""};
if (!UnwrapStringByPropertyName(env, param, "deviceId", deviceId)) {
TAG_LOGE(AAFwkTag::JSNAPI, "Wrong argument type deviceId");
return false;
}
executeParam.deviceId_ = deviceId;
}
napi_valuetype valueType = napi_undefined;
napi_typeof(env, napiIntentParam, &valueType);
if (valueType != napi_object) {
@@ -170,6 +170,10 @@ constexpr const char* ERROR_MSG_UIABILITY_IS_ALREADY_EXIST =
constexpr const char* ERROR_MSG_SELF_REDIRECTION_DISALLOWED =
"The UIAbility is prohibited from launching itself via App Linking.";
constexpr const char* ERROR_MSG_SEND_REQUEST_TO_SYSTEM_FAIL = "Failed to send request to system service.";
constexpr const char* ERROR_MSG_INTENT_CONNECTION_FAILED =
"Cross-device execution intent connection failed.";
constexpr const char* ERROR_MSG_INTENT_DEVICE_DISCONNECTED =
"Device disconnected during cross-device intent execution.";
// follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework
constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220;
@@ -284,6 +288,8 @@ static std::unordered_map<AbilityErrorCode, const char*> ERR_CODE_MAP = {
{ AbilityErrorCode::ERROR_CODE_UIABILITY_IS_ALREADY_EXIST, ERROR_MSG_UIABILITY_IS_ALREADY_EXIST },
{ AbilityErrorCode::ERROR_CODE_SELF_REDIRECTION_DISALLOWED, ERROR_MSG_SELF_REDIRECTION_DISALLOWED },
{ AbilityErrorCode::ERROR_CODE_SEND_REQUEST_TO_SYSTEM_FAIL, ERROR_MSG_SEND_REQUEST_TO_SYSTEM_FAIL },
{ AbilityErrorCode::ERROR_CODE_INTENT_CONNECTION_FAILED, ERROR_MSG_INTENT_CONNECTION_FAILED },
{ AbilityErrorCode::ERROR_CODE_INTENT_DEVICE_DISCONNECTED, ERROR_MSG_INTENT_DEVICE_DISCONNECTED }
};
static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP {
@@ -404,6 +410,8 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
{ERROR_UIABILITY_IS_ALREADY_EXIST, AbilityErrorCode::ERROR_CODE_UIABILITY_IS_ALREADY_EXIST},
{ERR_CODE_INVALID_ID, AbilityErrorCode::ERROR_CODE_INVALID_ID},
{ERR_SELF_REDIRECTION_DISALLOWED, AbilityErrorCode::ERROR_CODE_SELF_REDIRECTION_DISALLOWED },
{ERR_INTENT_CONNECTION_FAILED, AbilityErrorCode::ERROR_CODE_INTENT_CONNECTION_FAILED},
{ERR_INTENT_DEVICE_DISCONNECTED, AbilityErrorCode::ERROR_CODE_INTENT_DEVICE_DISCONNECTED},
};
}
@@ -585,6 +585,7 @@ int32_t DistributedClient::StartRemoteIntent(const OHOS::AAFwk::Want& want,
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Parcelable, &want);
PARCEL_WRITE_HELPER(data, String, want.GetElement().GetModuleName());
PARCEL_WRITE_HELPER(data, Int32, callerInfo.callerUid);
PARCEL_WRITE_HELPER(data, Uint64, callerInfo.requestCode);
PARCEL_WRITE_HELPER(data, Uint32, callerInfo.accessToken);
@@ -1144,6 +1144,12 @@ enum {
ERR_INVALID_DISTRIBUTION_TYPE = 2099414,
// Result (2099420) for Cross-device execution intent connection failed.
ERR_INTENT_CONNECTION_FAILED = 2099420,
// Result (2099421) for Device disconnected during cross-device intent execution.
ERR_INTENT_DEVICE_DISCONNECTED = 2099421,
/**
* Native error(3000000) for target bundle not exist.
*/
@@ -1226,7 +1226,7 @@ public:
*/
virtual int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) = 0;
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) = 0;
/**
* Start Ability, connect session with common ability.
@@ -1242,8 +1242,9 @@ public:
* @return Returns ERR_OK on success, others on failure.
*/
virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg, bool isSilent = false,
bool promotePriority = false, bool isVisible = false)
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg,
bool isSilent = false, bool promotePriority = false,
bool isVisible = false, uint64_t specifiedFullTokenId = 0)
{
return 0;
};
@@ -86,6 +86,10 @@ constexpr char INSIGHT_INTENT_DECORATOR_CLASS[] = "ohos.insightIntent.decoratorC
constexpr char INSIGHT_INTENT_QUERY_ENTITY_CLASS_NAME[] = "ohos.insightIntent.queryEntity.className";
constexpr char INSIGHT_INTENT_QUERY_TYPE[] = "ohos.insightIntent.queryEntity.queryType";
constexpr char INSIGHT_INTENT_QUERY_ENTITY_PARAM_PARAM[] = "ohos.insightIntent.queryEntity.param";
constexpr char INSIGHT_INTENT_PARAM_USER_ID[] = "ohos.insightIntent.param.userId";
constexpr char INSIGHT_INTENT_DISTRIBUTED_CALLBACK_KEY[] = "ohos.insightIntent.distributed.callbackKey";
constexpr char INSIGHT_INTENT_DISTRIBUTED_SRC_DEVICE_ID[] = "ohos.insightIntent.distributed.srcDeviceId";
constexpr char INSIGHT_INTENT_DISTRIBUTED_REQUEST_CODE[] = "ohos.insightIntent.distributed.requestCode";
constexpr int32_t INVALID_DISPLAY_ID = -1;
constexpr char METHOD_PARAM_SEPARATOR = '\x1f';
@@ -139,6 +143,9 @@ public:
std::string queryType_;
std::string queryEntityClassName_;
std::shared_ptr<WantParams> queryParams_;
// distributed intent params
std::string deviceId_;
};
} // namespace AppExecFwk
} // namespace OHOS
@@ -45,6 +45,8 @@ public:
bool ReadFromParcel(Parcel &parcel);
bool Marshalling(Parcel &parcel) const override;
static InsightIntentExecuteResult *Unmarshalling(Parcel &parcel);
void FromJsonString(const std::string &jsonStr);
std::string ToJsonString() const;
// Check result returned by intent executor
static bool CheckResult(std::shared_ptr<const WantParams> result);
};
@@ -316,6 +316,10 @@ enum class AbilityErrorCode {
ERROR_CODE_SELF_REDIRECTION_DISALLOWED = 16000136,
ERROR_CODE_INTENT_CONNECTION_FAILED = 16000137,
ERROR_CODE_INTENT_DEVICE_DISCONNECTED = 16000138,
ERROR_CODE_SEND_REQUEST_TO_SYSTEM_FAIL = 16000150,
// target bundle is not in u1
@@ -927,8 +927,8 @@ public:
* @return Returns ERR_OK on success, others on failure.
*/
virtual int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
/**
* Start Ability for prelauch.
@@ -953,7 +953,8 @@ public:
*/
virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
bool isSilent = false, bool promotePriority = false,
bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
/**
* CallRequestDone, after invoke callRequest, ability will call this interface to return callee.
@@ -83,6 +83,7 @@ namespace AbilityRuntime {
class IStatusBarDelegate;
struct ExtractInsightIntentGenericInfo;
struct LinkIntentParamMapping;
struct ExecuteIntentCommonOptions;
}
namespace Rosen {
class FocusChangeInfo;
@@ -1350,8 +1351,8 @@ public:
* @return Returns ERR_OK on success, others on failure.
*/
virtual int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
/**
* Start Ability, connect session with common ability.
@@ -1368,7 +1369,8 @@ public:
*/
virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
bool isSilent = false, bool promotePriority = false,
bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
/**
* Start Ability for prelauch.
@@ -2177,10 +2179,11 @@ public:
int32_t OnExecuteIntent(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord);
int32_t StartAbilityWithInsightIntent(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE,
int requestCode = DEFAULT_INVAL_VALUE);
int requestCode = DEFAULT_INVAL_VALUE, uint64_t specifiedFullTokenId = 0);
int32_t StartAbilityByCallWithInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
const InsightIntentExecuteParam &param, int32_t userId = DEFAULT_INVAL_VALUE);
int32_t StartAbilityByCallWithInsightIntent(const Want &want,
const sptr<IRemoteObject> &callerToken, const InsightIntentExecuteParam &param,
int32_t userId = DEFAULT_INVAL_VALUE, uint64_t specifiedFullTokenId = 0);
int32_t ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId,
uint64_t requestCode, uint64_t specifiedFullTokenId = 0) override;
@@ -3568,6 +3571,10 @@ private:
void HandleRecoveryRecipient(const std::shared_ptr<AbilityRecord>& abilityRecord,
const sptr<IRemoteObject>& token);
int32_t SetAppRecoveryFlag(const sptr<IRemoteObject>& token, int flag) override;
int32_t ExecuteIntentCommon(const sptr<IRemoteObject> &callerToken,
const std::shared_ptr<InsightIntentExecuteParam> &param, const std::string &callerBundleName,
const AbilityRuntime::ExecuteIntentCommonOptions &infos);
#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
std::shared_ptr<BackgroundTaskObserver> bgtaskObserver_;
#endif
@@ -223,6 +223,17 @@ struct ExtractInsightIntentProfileInfoVec {
std::vector<ExtractInsightIntentProfileInfo> insightIntents {};
};
struct ExecuteIntentCommonOptions {
bool ignoreAbilityName;
ExtractInsightIntentGenericInfo infos;
uint64_t key;
std::string srcDeviceId;
uint64_t requestCode;
uint64_t specifiedFullTokenId;
ExecuteIntentCommonOptions(bool ignoreAbilityName, const ExtractInsightIntentGenericInfo &infos,
uint64_t key): ignoreAbilityName(ignoreAbilityName), infos(infos), key(key){};
};
class ExtractInsightIntentProfile {
public:
static bool TransformTo(const std::string &profileStr, ExtractInsightIntentProfileInfoVec &infos);
@@ -43,6 +43,9 @@ struct InsightIntentExecuteRecord {
std::string bundleName;
std::string callerBundleName;
InsightIntentExecuteState state = InsightIntentExecuteState::UNKNOWN;
bool isDistributed = false;
std::string deviceId;
uint64_t requestCode = 0;
};
class InsightIntentExecuteConnection : public AbilityConnectionStub {
@@ -77,7 +80,8 @@ DECLARE_DELAYED_SINGLETON(InsightIntentExecuteManager)
public:
int32_t CheckAndUpdateParam(uint64_t key, const sptr<IRemoteObject> &callerToken,
const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param, std::string callerBundleName = "",
const bool ignoreAbilityName = false);
const bool ignoreAbilityName = false, bool isDistributed = false,
const std::string &srcDeviceId = "", uint64_t requestCode = 0, uint64_t specifiedFullTokenId = 0);
int32_t CheckAndUpdateWant(Want &want, AppExecFwk::ExecuteMode executeMode, int32_t userId,
std::string callerBundleName = "");
@@ -85,7 +89,10 @@ public:
int32_t RemoveExecuteIntent(uint64_t intentId);
int32_t ExecuteIntentDone(uint64_t intentId, int32_t resultCode,
const AppExecFwk::InsightIntentExecuteResult &result);
const AppExecFwk::InsightIntentExecuteResult &result, int32_t callerUid = 0, uint32_t accessToken = 0);
int32_t GetDistributedInfo(uint64_t intentId, std::string &srcDeviceId,
int32_t &requestCode, uint64_t &callbackKey) const;
int32_t RemoteDied(uint64_t intentId);
@@ -103,7 +110,7 @@ public:
bool CheckIntentIsExemption(int32_t uid);
static int32_t CheckCallerPermission();
static int32_t CheckCallerPermission(uint64_t specifiedFullTokenId = 0);
static int32_t CheckGetInsightIntenInfoPermission();
@@ -122,7 +129,8 @@ private:
std::map<int32_t, int64_t> intentExemptionDeadlineTime_;
int32_t AddRecord(uint64_t key, const sptr<IRemoteObject> &callerToken, const std::string &bundleName,
uint64_t &intentId, const std::string &callerBundleName);
uint64_t &intentId, const std::string &callerBundleName, bool isDistributed = false,
const std::string &deviceId = "", uint64_t requestCode = 0);
static int32_t IsValidCall(const Want &want);
@@ -139,7 +147,8 @@ private:
static int32_t UpdateEntryDecoratorParams(const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param,
AbilityRuntime::ExtractInsightIntentInfo &info, Want &want);
static int32_t UpdateEntryDecoratorParams(Want &want, AppExecFwk::ExecuteMode executeMode, int32_t userId);
static std::string GetMainElementName(const std::string &bundleName, const std::string &moduleName);
static std::string GetMainElementName(
const std::string &bundleName, const std::string &moduleName, int32_t userId = -1);
static std::shared_ptr<AbilityRuntime::InsightIntentEntityInfo> CheckEntityQueryable(
const AbilityRuntime::ExtractInsightIntentInfo& intentInfo, const std::string& className,
const AppExecFwk::InsightIntentQueryEntityParam& queryParams);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Copyright (c) 2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
+2 -1
View File
@@ -39,7 +39,8 @@
*ApplicationAnrListener*;
*AppMgrUtil*;
*AppScheduler*;
*AtomicServiceStatusCallback*;
*AtomicServiceStatusCallback*;
*RemoteIntentResultCallback*;
*BackgroundTaskObserver*;
*MainElementUtils*;
*CallContainer*;
@@ -4037,16 +4037,17 @@ int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId,
}
int AbilityManagerProxy::StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible)
const sptr<IRemoteObject> &callerToken, int32_t accountId,
bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
std::string errMsg;
return StartAbilityByCallWithErrMsg(want, connect, callerToken, accountId, errMsg, isSilent, promotePriority,
isVisible);
isVisible, specifiedFullTokenId);
}
int AbilityManagerProxy::StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg, bool isSilent,
bool promotePriority, bool isVisible)
bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
if (AppUtils::GetInstance().IsForbidStart()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
@@ -93,6 +93,7 @@
#include "rate_limiter.h"
#include "recovery_info_timer.h"
#include "recovery_param.h"
#include "remote_intent_result_callback.h"
#include "report_data_partition_usage_manager.h"
#include "res_sched_util.h"
#include "restart_app_manager.h"
@@ -293,7 +294,9 @@ constexpr const char* UI_EXTENSION_TARGET_USER_ID = "ohos.ability.params.uiExten
constexpr int32_t INSTALL_TYPE_UPGRADE = 2;
constexpr int64_t CLEAR_USER_LOCKED_BUNDLE_LIST_KEY_DELAY_TIME = 60 * 1000; // 60s
constexpr const char* VPN_PERMISSION_IF = "libnet_vpn_permission_if.z.so";
using RequestVpnPermission = int32_t(*)(int32_t, const std::string&, const std::string&,bool &);
constexpr const char* INTENT_USER_ID = "ohos.insightIntent.userId";
using RequestVpnPermission = int32_t (*)(int32_t, const std::string &, const std::string &, bool &);
void SendAbilityEvent(const EventName &eventName, HiSysEventEventType type, const EventInfo &eventInfo)
{
@@ -760,8 +763,8 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr<IRemoteObje
.requestCode = requestCode,
.userId = userId,
.specifiedFullTokenId = specifiedFullTokenId,
.removeInsightIntentFlag = true,
};
param.removeInsightIntentFlag = true;
return StartAbilityWithRemoveIntentFlag(param);
}
@@ -9838,18 +9841,22 @@ int AbilityManagerService::ReleaseRemoteAbility(const sptr<IRemoteObject> &conne
}
int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, bool isSilent, bool promotePriority,
bool isVisible)
const sptr<IRemoteObject> &callerToken, int32_t accountId,
bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
std::string errMsg;
return StartAbilityByCallWithErrMsg(want, connect, callerToken, accountId, errMsg, isSilent, promotePriority,
isVisible);
isVisible, specifiedFullTokenId);
}
int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg, bool isSilent,
bool promotePriority, bool isVisible)
bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
if (specifiedFullTokenId != 0 && IPCSkeleton::GetCallingUid() != DMS_UID) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "specifiedFullTokenId only support for DMS");
specifiedFullTokenId = 0;
}
if (AppUtils::GetInstance().IsForbidStart()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
return INNER_ERR;
@@ -9925,6 +9932,7 @@ int AbilityManagerService::StartAbilityByCallWithErrMsg(const Want &want, const
abilityRequest.callerToken = callerToken;
abilityRequest.want = want;
abilityRequest.connect = connect;
abilityRequest.specifiedFullTokenId = specifiedFullTokenId;
abilityRequest.promotePriority = PermissionVerification::GetInstance()->IsSACall() && promotePriority;
result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, oriValidUserId);
if (result != ERR_OK) {
@@ -12400,7 +12408,9 @@ int AbilityManagerService::CheckCallServiceExtensionPermission(const AbilityRequ
verificationInfo.visible = abilityRequest.abilityInfo.visible;
verificationInfo.withContinuousTask = IsBackgroundTaskUid(IPCSkeleton::GetCallingUid());
verificationInfo.isBackgroundCall = false;
verificationInfo.specifyTokenId = static_cast<uint32_t>(abilityRequest.specifyTokenId);
verificationInfo.specifyTokenId = (abilityRequest.specifiedFullTokenId != 0) ?
static_cast<uint32_t>(abilityRequest.specifiedFullTokenId) :
static_cast<uint32_t>(abilityRequest.specifyTokenId);
if (isParamStartAbilityEnable_) {
bool stopContinuousTaskFlag = ShouldPreventStartAbility(abilityRequest);
if (stopContinuousTaskFlag) {
@@ -12847,6 +12857,8 @@ int AbilityManagerService::CheckStartByCallPermission(const AbilityRequest &abil
verificationInfo.accessTokenId = abilityRequest.appInfo.accessTokenId;
verificationInfo.visible = abilityRequest.abilityInfo.visible;
verificationInfo.withContinuousTask = IsBackgroundTaskUid(IPCSkeleton::GetCallingUid());
verificationInfo.specifiedFullTokenId = static_cast<uint32_t>(abilityRequest.specifiedFullTokenId);
if (IsCallFromBackground(abilityRequest, verificationInfo.isBackgroundCall, false) != ERR_OK) {
return ERR_INVALID_VALUE;
}
@@ -14005,6 +14017,9 @@ int32_t AbilityManagerService::ExecuteIntentForDistributed(const Want &want, con
TAG_LOGE(AAFwkTag::INTENT, "GenerateFromWant failed, not a valid insight intent");
return ERR_INVALID_VALUE;
}
int32_t userId = want.GetIntParam(AbilityRuntime::INTENT_USER_ID, -1);
param.userId_ = userId;
auto paramCopy = std::make_shared<InsightIntentExecuteParam>(param);
uint64_t key = requestCode;
@@ -14020,7 +14035,92 @@ int32_t AbilityManagerService::ExecuteIntentForDistributed(const Want &want, con
(infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_PAGE) ||
(infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_FUNCTION);
return ERR_OK;
AbilityRuntime::ExecuteIntentCommonOptions options(ignoreAbilityName, infos, key);
options.srcDeviceId = srcDeviceId;
options.requestCode = requestCode;
options.specifiedFullTokenId = specifiedFullTokenId;
return ExecuteIntentCommon(nullptr, paramCopy, callerBundlename, options);
}
int32_t AbilityManagerService::ExecuteIntentCommon(const sptr<IRemoteObject> &callerToken,
const std::shared_ptr<InsightIntentExecuteParam> &param, const std::string &callerBundleName,
const AbilityRuntime::ExecuteIntentCommonOptions &options)
{
bool openLinkExecuteFlag = options.infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_LINK;
bool isDistributed = !options.srcDeviceId.empty();
int32_t ret = DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateParam(
options.key, callerToken, param, callerBundleName, options.ignoreAbilityName, isDistributed,
options.srcDeviceId, options.requestCode, options.specifiedFullTokenId);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "CheckAndUpdateParam failed: %{public}d", ret);
return ret;
}
TAG_LOGI(AAFwkTag::INTENT, "execute insight intent, bundleName: %{public}s, moduleName: %{public}s, "
"intentName: %{public}s, intentId:%{public}" PRIu64 ", openLinkExecuteFlag: %{public}d, "
"executeMode: %{public}d, userId: %{public}d, isDistributed: %{public}d",
param->bundleName_.c_str(), param->moduleName_.c_str(), param->insightIntentName_.c_str(),
param->insightIntentId_, openLinkExecuteFlag, param->executeMode_, param->userId_, isDistributed);
if (openLinkExecuteFlag) {
auto info = options.infos;
return IntentOpenLinkInner(param, info, param->userId_);
}
Want want;
ret = InsightIntentExecuteManager::GenerateWant(param, options.infos, want);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "GenerateWant failed: %{public}d", ret);
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->RemoveExecuteIntent(param->insightIntentId_);
return ret;
}
int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId();
EventInfo eventInfo = BuildEventInfo(want, callerUserId);
switch (param->executeMode_) {
case AppExecFwk::ExecuteMode::UI_ABILITY_FOREGROUND:
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode UI_ABILITY_FOREGROUND.");
ret = StartAbilityWithInsightIntent(
want, param->userId_, DEFAULT_INVAL_VALUE, options.specifiedFullTokenId);
if (ret != ERR_OK) {
eventInfo.errReason = "StartAbilityWithInsightIntent error";
SendIntentReport(eventInfo, ret, param->insightIntentName_);
}
break;
case AppExecFwk::ExecuteMode::UI_ABILITY_BACKGROUND: {
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode UI_ABILITY_BACKGROUND.");
ret = StartAbilityByCallWithInsightIntent(
want, callerToken, *param, param->userId_, options.specifiedFullTokenId);
if (ret != ERR_OK) {
eventInfo.errReason = "StartAbilityByCallWithInsightIntent error";
SendIntentReport(eventInfo, ret, param->insightIntentName_);
}
break;
}
case AppExecFwk::ExecuteMode::UI_EXTENSION_ABILITY:
TAG_LOGE(AAFwkTag::INTENT, "executeMode UI_EXTENSION_ABILITY not supported");
ret = ERR_INVALID_OPERATION;
break;
case AppExecFwk::ExecuteMode::SERVICE_EXTENSION_ABILITY:
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode SERVICE_EXTENSION_ABILITY.");
ret = StartExtensionAbilityWithInsightIntent(
want, AppExecFwk::ExtensionAbilityType::SERVICE, param->userId_);
if (ret != ERR_OK) {
eventInfo.errReason = "StartExtensionAbilityWithInsightIntent error";
SendIntentReport(eventInfo, ret, param->insightIntentName_);
}
break;
default:
TAG_LOGE(AAFwkTag::INTENT, "ExecuteMode invalid: %{public}d", param->executeMode_);
ret = ERR_INVALID_VALUE;
break;
}
if (ret != ERR_OK) {
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->RemoveExecuteIntent(param->insightIntentId_);
}
TAG_LOGI(AAFwkTag::INTENT, "ExecuteIntentCommon done, ret: %{public}d.", ret);
return ret;
}
int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr<IRemoteObject> &callerToken,
@@ -14030,6 +14130,7 @@ int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr<IRemoteObj
if (param.isServiceMatch_) {
return StartAbilityWithServiceMatch(param);
}
auto callerBundlename = InsightIntentGetcallerBundleName();
if (callerBundlename.empty()) {
TAG_LOGD(AAFwkTag::INTENT, "callerBundlename is null");
@@ -14050,74 +14151,56 @@ int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr<IRemoteObj
bool openLinkExecuteFlag = infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_LINK;
bool ignoreAbilityName = openLinkExecuteFlag ||
(infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_PAGE) ||
(infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_FUNCTION);
(infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_FUNCTION) ||
!param.deviceId_.empty();
auto paramPtr = std::make_shared<InsightIntentExecuteParam>(param);
int32_t ret = DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateParam(key, callerToken,
paramPtr, callerBundlename, ignoreAbilityName);
int32_t ret = DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->CheckAndUpdateParam(
key, callerToken, paramPtr, callerBundlename, ignoreAbilityName);
if (ret != ERR_OK) {
return ret;
}
TAG_LOGI(AAFwkTag::INTENT, "execute insight intent, bundleName: %{public}s, moduleName: %{public}s, "
"intentName: %{public}s, intentId:%{public}" PRIu64", openLinkExecuteFlag: %{public}d, executeMode: %{public}d, "
"userId: %{public}d",
param.bundleName_.c_str(), param.moduleName_.c_str(), param.insightIntentName_.c_str(), param.insightIntentId_,
openLinkExecuteFlag, param.executeMode_, param.userId_);
"intentName: %{public}s, intentId:%{public}" PRIu64 ", openLinkExecuteFlag: %{public}d, "
"executeMode: %{public}d, userId: %{public}d, deviceId: %{public}s",
param.bundleName_.c_str(), param.moduleName_.c_str(), param.insightIntentName_.c_str(),
paramPtr->insightIntentId_, openLinkExecuteFlag, param.executeMode_, param.userId_, param.deviceId_.c_str());
if (openLinkExecuteFlag) {
return IntentOpenLinkInner(paramPtr, infos, param.userId_);
}
if (!param.deviceId_.empty()) {
bool hasDistributedPermission = PermissionVerification::GetInstance()->VerifyCallingPermission(
PermissionConstants::PERMISSION_EXECUTE_DISTRIBUTED_INTENT);
if (!hasDistributedPermission) {
TAG_LOGE(AAFwkTag::INTENT, "distributed intent permission denied");
return CHECK_PERMISSION_FAILED;
}
Want want;
auto ret = InsightIntentExecuteManager::GenerateWant(paramPtr, infos, want);
auto element = want.GetElement();
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "GenerateWant failed: %{public}d", ret);
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->RemoveExecuteIntent(paramPtr->insightIntentId_);
return ret;
}
TAG_LOGI(AAFwkTag::INTENT, "GenerateWant success");
IntentCallerInfo callerInfo;
callerInfo.callerUid = IPCSkeleton::GetCallingUid();
callerInfo.requestCode = paramPtr->insightIntentId_;
callerInfo.accessToken = IPCSkeleton::GetCallingTokenID();
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
DistributedClient dmsClient;
if (dmsClient.StartRemoteIntent(want, callerInfo, callback) != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "StartRemoteIntent failed");
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->RemoveExecuteIntent(
paramPtr->insightIntentId_);
return ERR_INTENT_CONNECTION_FAILED;
}
return ERR_OK;
}
Want want;
ret = InsightIntentExecuteManager::GenerateWant(paramPtr, infos, want);
if (ret != ERR_OK) {
return ret;
}
int32_t callerUserId = AbilityRuntime::UserController::GetInstance().GetCallerUserId();
EventInfo eventInfo = BuildEventInfo(want, callerUserId);
switch (param.executeMode_) {
case AppExecFwk::ExecuteMode::UI_ABILITY_FOREGROUND:
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode UI_ABILITY_FOREGROUND.");
ret = StartAbilityWithInsightIntent(want, param.userId_);
if (ret != ERR_OK) {
eventInfo.errReason = "StartAbilityWithInsightIntent error";
SendIntentReport(eventInfo, ret, param.insightIntentName_);
}
break;
case AppExecFwk::ExecuteMode::UI_ABILITY_BACKGROUND: {
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode UI_ABILITY_BACKGROUND.");
ret = StartAbilityByCallWithInsightIntent(want, callerToken, param, param.userId_);
if (ret != ERR_OK) {
eventInfo.errReason = "StartAbilityByCallWithInsightIntent error";
SendIntentReport(eventInfo, ret, param.insightIntentName_);
}
break;
}
case AppExecFwk::ExecuteMode::UI_EXTENSION_ABILITY:
TAG_LOGE(AAFwkTag::INTENT, "executeMode UI_EXTENSION_ABILITY not supported");
ret = ERR_INVALID_OPERATION;
break;
case AppExecFwk::ExecuteMode::SERVICE_EXTENSION_ABILITY:
TAG_LOGI(AAFwkTag::INTENT, "ExecuteMode SERVICE_EXTENSION_ABILITY.");
ret = StartExtensionAbilityWithInsightIntent(want, AppExecFwk::ExtensionAbilityType::SERVICE, param.userId_);
if (ret != ERR_OK) {
eventInfo.errReason = "StartExtensionAbilityWithInsightIntent error";
SendIntentReport(eventInfo, ret, param.insightIntentName_);
}
break;
default:
TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid executeMode");
ret = ERR_INVALID_OPERATION;
break;
}
if (ret == START_ABILITY_WAITING) {
TAG_LOGI(AAFwkTag::INTENT, "Top ability is foregrounding. The intent will be queued for execution");
ret = ERR_OK;
}
if (ret != ERR_OK) {
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->RemoveExecuteIntent(paramPtr->insightIntentId_);
}
TAG_LOGI(AAFwkTag::INTENT, "ExecuteIntent done, ret: %{public}d.", ret);
return ret;
AbilityRuntime::ExecuteIntentCommonOptions options(ignoreAbilityName, infos, key);
return ExecuteIntentCommon(callerToken, paramPtr, callerBundlename, options);
}
ErrCode AbilityManagerService::QueryEntityInfo(uint64_t key, sptr<IRemoteObject> callerToken,
@@ -14205,7 +14288,8 @@ int32_t AbilityManagerService::OnExecuteIntent(AbilityRequest &abilityRequest,
return ERR_OK;
}
int32_t AbilityManagerService::StartAbilityWithInsightIntent(const Want &want, int32_t userId, int requestCode)
int32_t AbilityManagerService::StartAbilityWithInsightIntent(const Want &want, int32_t userId, int requestCode,
uint64_t specifiedFullTokenId)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
bool startWithAccount = want.GetBoolParam(START_ABILITY_TYPE, false);
@@ -14221,7 +14305,8 @@ int32_t AbilityManagerService::StartAbilityWithInsightIntent(const Want &want, i
StartAbilityWrapParam startAbilityWrapParam = {
.want = want,
.requestCode = requestCode,
.userId = userId
.userId = userId,
.specifiedFullTokenId = specifiedFullTokenId,
};
int32_t ret = StartAbilityWrap(startAbilityWrapParam);
if (ret != ERR_OK) {
@@ -14238,7 +14323,8 @@ int32_t AbilityManagerService::StartExtensionAbilityWithInsightIntent(const Want
}
int32_t AbilityManagerService::StartAbilityByCallWithInsightIntent(const Want &want,
const sptr<IRemoteObject> &callerToken, const InsightIntentExecuteParam &param, int32_t userId)
const sptr<IRemoteObject> &callerToken,
const InsightIntentExecuteParam &param, int32_t userId, uint64_t specifiedFullTokenId)
{
TAG_LOGI(AAFwkTag::INTENT, "called");
sptr<IAbilityConnection> connect = sptr<AbilityBackgroundConnection>::MakeSptr();
@@ -14256,6 +14342,7 @@ int32_t AbilityManagerService::StartAbilityByCallWithInsightIntent(const Want &w
abilityRequest.startSetting = nullptr;
abilityRequest.want = want;
abilityRequest.connect = connect;
abilityRequest.specifiedFullTokenId = specifiedFullTokenId;
int32_t result = GenerateAbilityRequest(want, -1, abilityRequest, callerToken, GetValidUserId(userId));
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "generate ability request error");
@@ -14269,7 +14356,8 @@ int32_t AbilityManagerService::StartAbilityByCallWithInsightIntent(const Want &w
UpdateCallerInfoUtil::GetInstance().UpdateCallerInfo(abilityRequest.want, callerToken);
result = OnExecuteIntent(abilityRequest, targetRecord);
} else {
result = StartAbilityByCall(want, connect, callerToken, oriValidUserId);
result = StartAbilityByCall(want, connect, callerToken, oriValidUserId,
false, false, false, specifiedFullTokenId);
}
ResSchedUtil::GetInstance().ReportAbilityIntentExemptionInfoToRSS(abilityRequest.uid, 0);
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->SetIntentExemptionInfo(
@@ -14331,9 +14419,10 @@ int32_t AbilityManagerService::ExecuteInsightIntentDone(const sptr<IRemoteObject
abilityRecord->GrantUriPermission(result.uris, result.flags, callerBundleName, initiatorTokenId);
}
#endif // SUPPORT_UPMS
int32_t callerUid = IPCSkeleton::GetCallingUid();
uint32_t accessToken = IPCSkeleton::GetCallingTokenID();
ret = DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->ExecuteIntentDone(
intentId, result.innerErr, result);
intentId, result.innerErr, result, callerUid, accessToken);
FreezeUtil::GetInstance().AddLifecycleEvent(token, "ExecuteInsightIntentDone end");
return ret;
}
@@ -346,8 +346,8 @@ int AbilityManagerStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel
return StartSelfUIAbilityInCurrentProcessInner(data, reply);
}
if (interfaceCode == AbilityManagerInterfaceCode::EXECUTE_INTENT_FOR_DISTRIBUTED) {
return ExecuteIntentForDistributedInner(data, reply);
}
return ExecuteIntentForDistributedInner(data, reply);
}
return ERR_CODE_NOT_EXIST;
}
@@ -21,6 +21,7 @@
#include "ability_config.h"
#include "ability_util.h"
#include "ability_manager_errors.h"
#include "distributed_ability_runtime/distributed_client.h"
#include "extract_insight_intent_profile.h"
#include "hilog_tag_wrapper.h"
#include "insight_intent_execute_callback_interface.h"
@@ -137,13 +138,14 @@ InsightIntentExecuteManager::~InsightIntentExecuteManager() = default;
int32_t InsightIntentExecuteManager::CheckAndUpdateParam(uint64_t key, const sptr<IRemoteObject> &callerToken,
const std::shared_ptr<AppExecFwk::InsightIntentExecuteParam> &param, std::string callerBundleName,
const bool ignoreAbilityName)
const bool ignoreAbilityName, bool isDistributed, const std::string &srcDeviceId, uint64_t requestCode,
uint64_t specifiedFullTokenId)
{
int32_t result = CheckCallerPermission();
int32_t result = CheckCallerPermission(specifiedFullTokenId);
if (result != ERR_OK && (param == nullptr || !param->isServiceMatch_)) {
return result;
}
if (callerToken == nullptr && (param == nullptr || !param->isServiceMatch_)) {
if ((!isDistributed && callerToken == nullptr) && (param == nullptr || !param->isServiceMatch_)) {
TAG_LOGE(AAFwkTag::INTENT, "null callerToken");
return ERR_INVALID_VALUE;
}
@@ -151,13 +153,15 @@ int32_t InsightIntentExecuteManager::CheckAndUpdateParam(uint64_t key, const spt
TAG_LOGE(AAFwkTag::INTENT, "null param");
return ERR_INVALID_VALUE;
}
if (param->bundleName_.empty() || param->moduleName_.empty() ||
(!ignoreAbilityName && param->abilityName_.empty()) || param->insightIntentName_.empty()) {
TAG_LOGE(AAFwkTag::INTENT, "invalid param");
return ERR_INVALID_VALUE;
}
uint64_t intentId = 0;
result = AddRecord(key, callerToken, param->bundleName_, intentId, callerBundleName);
result = AddRecord(key, callerToken, param->bundleName_,
intentId, callerBundleName, isDistributed, srcDeviceId, requestCode);
if (result != ERR_OK) {
return result;
}
@@ -244,7 +248,8 @@ int32_t InsightIntentExecuteManager::UpdateEntryDecoratorParams(Want &want, Exec
}
int32_t InsightIntentExecuteManager::AddRecord(uint64_t key, const sptr<IRemoteObject> &callerToken,
const std::string &bundleName, uint64_t &intentId, const std::string &callerBundleName)
const std::string &bundleName, uint64_t &intentId, const std::string &callerBundleName,
bool isDistributed, const std::string &deviceId, uint64_t requestCode)
{
std::lock_guard<ffrt::mutex> lock(mutex_);
intentId = ++intentIdCount_;
@@ -254,6 +259,9 @@ int32_t InsightIntentExecuteManager::AddRecord(uint64_t key, const sptr<IRemoteO
record->callerToken = callerToken;
record->bundleName = bundleName;
record->callerBundleName = callerBundleName;
record->isDistributed = isDistributed;
record->deviceId = deviceId;
record->requestCode = requestCode;
if (callerToken != nullptr) {
record->deathRecipient = sptr<InsightIntentExecuteRecipient>::MakeSptr(intentId);
callerToken->AddDeathRecipient(record->deathRecipient);
@@ -265,7 +273,6 @@ int32_t InsightIntentExecuteManager::AddRecord(uint64_t key, const sptr<IRemoteO
// save the latest INSIGHT_INTENT_EXECUTE_RECORDS_MAX_SIZE records
records_.erase(intentId - INSIGHT_INTENT_EXECUTE_RECORDS_MAX_SIZE);
}
TAG_LOGI(AAFwkTag::INTENT, "init done, records_ size: %{public}zu", records_.size());
return ERR_OK;
}
@@ -279,10 +286,10 @@ int32_t InsightIntentExecuteManager::RemoveExecuteIntent(uint64_t intentId)
}
int32_t InsightIntentExecuteManager::ExecuteIntentDone(uint64_t intentId, int32_t resultCode,
const AppExecFwk::InsightIntentExecuteResult &result)
const AppExecFwk::InsightIntentExecuteResult &result, int32_t callerUid, uint32_t accessToken)
{
TAG_LOGI(AAFwkTag::INTENT, "execute start, intentId: %{public}" PRIu64 ", records_ size: %{public}zu",
intentId, records_.size());
TAG_LOGI(AAFwkTag::INTENT, "execute start, intentId: %{public}" PRIu64 ", resultCode: %{public}d",
intentId, resultCode);
std::lock_guard<ffrt::mutex> lock(mutex_);
EventInfo eventInfo;
auto findResult = records_.find(intentId);
@@ -307,13 +314,31 @@ int32_t InsightIntentExecuteManager::ExecuteIntentDone(uint64_t intentId, int32_
return ERR_INVALID_OPERATION;
}
record->state = InsightIntentExecuteState::EXECUTE_DONE;
sptr<IInsightIntentExecuteCallback> remoteCallback = iface_cast<IInsightIntentExecuteCallback>(record->callerToken);
if (remoteCallback == nullptr) {
TAG_LOGE(AAFwkTag::INTENT, "intentExecuteCallback empty,"
" intentId: %{public}" PRIu64 ", records_ size: %{public}zu", intentId, records_.size());
return ERR_INVALID_VALUE;
if (record->isDistributed) {
std::string msg = result.ToJsonString();
Want want;
want.SetElementName(record->deviceId, record->bundleName, "", "");
IntentCallerInfo callerInfo;
callerInfo.callerUid = callerUid;
callerInfo.requestCode = record->requestCode;
callerInfo.accessToken = accessToken;
DistributedClient dmsClient;
int32_t ret = dmsClient.SendIntentResult(want, callerInfo, msg);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "SendIntentResult failed: %{public}d", ret);
}
} else {
sptr<IInsightIntentExecuteCallback> remoteCallback =
iface_cast<IInsightIntentExecuteCallback>(record->callerToken);
if (remoteCallback == nullptr) {
TAG_LOGE(AAFwkTag::INTENT, "intentExecuteCallback empty,"
" intentId: %{public}" PRIu64 ", records_ size: %{public}zu", intentId, records_.size());
return ERR_INVALID_VALUE;
}
remoteCallback->OnExecuteDone(record->key, resultCode, result);
}
remoteCallback->OnExecuteDone(record->key, resultCode, result);
if (record->callerToken != nullptr) {
record->callerToken->RemoveDeathRecipient(record->deathRecipient);
record->callerToken = nullptr;
@@ -404,7 +429,7 @@ int32_t InsightIntentExecuteManager::UpdateFuncDecoratorParams(
}
if (param->abilityName_.empty()) {
param->abilityName_ = GetMainElementName(param->bundleName_, param->moduleName_);
param->abilityName_ = GetMainElementName(param->bundleName_, param->moduleName_, param->userId_);
}
if (param->abilityName_.empty()) {
TAG_LOGE(AAFwkTag::INTENT, "ability name empty");
@@ -441,7 +466,7 @@ int32_t InsightIntentExecuteManager::UpdateFuncDecoratorParams(
}
std::string InsightIntentExecuteManager::GetMainElementName(const std::string &bundleName,
const std::string &moduleName)
const std::string &moduleName, int32_t userId)
{
auto bms = AbilityUtil::GetBundleManagerHelper();
if (bms == nullptr) {
@@ -449,7 +474,9 @@ std::string InsightIntentExecuteManager::GetMainElementName(const std::string &b
return "";
}
const int32_t userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE;
if (userId == DEFAULT_INVAL_VALUE) {
userId = IPCSkeleton::GetCallingUid() / AppExecFwk::Constants::BASE_USER_RANGE;
}
std::vector<AppExecFwk::AbilityInfo> abilityInfos;
if (IN_PROCESS_CALL(bms->GetLauncherAbilityInfoSync(bundleName, userId, abilityInfos)) != ERR_OK) {
TAG_LOGE(AAFwkTag::INTENT, "get launcher ability info failed");
@@ -618,7 +645,7 @@ int32_t InsightIntentExecuteManager::GenerateWant(
std::chrono::system_clock::now().time_since_epoch()).count());
want.SetParam(Want::PARAM_RESV_START_TIME, startTime);
want.AddFlags(Want::FLAG_INSTALL_ON_DEMAND);
} else if (decoratorInfo.decoratorType == "" && !param->isServiceMatch_) {
} else if (decoratorInfo.decoratorType == "" && !param->isServiceMatch_ && param->deviceId_.empty()) {
// decoratorType is empty indicate no decorator
TAG_LOGE(AAFwkTag::INTENT, "insight intent srcEntry invalid");
return ERR_INVALID_VALUE;
@@ -627,11 +654,19 @@ int32_t InsightIntentExecuteManager::GenerateWant(
want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_NAME, param->insightIntentName_);
want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_MODE, param->executeMode_);
want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_ID, std::to_string(param->insightIntentId_));
want.SetParam(INSIGHT_INTENT_PARAM_USER_ID, param->userId_);
if (param->displayId_ != INVALID_DISPLAY_ID) {
want.SetParam(Want::PARAM_RESV_DISPLAY_ID, param->displayId_);
TAG_LOGD(AAFwkTag::INTENT, "Generate want with displayId: %{public}d", param->displayId_);
}
if (!param->deviceId_.empty()) {
want.SetDeviceId(param->deviceId_);
}
if (!param->uris_.empty()) {
want.SetParam(INSIGHT_INTENT_EXECUTE_PARAM_URI, param->uris_);
}
auto intRet = AddWantUirsAndFlagsFromParam(param, want);
if (intRet != ERR_OK) {
return intRet;
@@ -662,16 +697,23 @@ int32_t InsightIntentExecuteManager::IsValidCall(const Want &want)
return ERR_OK;
}
int32_t InsightIntentExecuteManager::CheckCallerPermission()
int32_t InsightIntentExecuteManager::CheckCallerPermission(uint64_t specifiedFullTokenId)
{
bool isSystemAppCall = PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI();
TAG_LOGI(AAFwkTag::INTENT, "specifiedFullTokenId: %{public}" PRIu64, specifiedFullTokenId);
bool isSystemAppCall = false;
if (specifiedFullTokenId != 0) {
isSystemAppCall = PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPIByTokenId(
specifiedFullTokenId);
} else {
isSystemAppCall = PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI();
}
if (!isSystemAppCall) {
TAG_LOGE(AAFwkTag::INTENT, "system-api cannot use");
return ERR_NOT_SYSTEM_APP;
}
bool isCallingPerm = PermissionVerification::GetInstance()->VerifyCallingPermission(
EXECUTE_INSIGHT_INTENT_PERMISSION);
EXECUTE_INSIGHT_INTENT_PERMISSION, specifiedFullTokenId);
if (!isCallingPerm) {
TAG_LOGE(AAFwkTag::INTENT, "permission %{public}s verification failed", EXECUTE_INSIGHT_INTENT_PERMISSION);
return ERR_PERMISSION_DENIED;
@@ -160,6 +160,7 @@ bool InsightIntentExecuteParam::ReadFromParcel(Parcel &parcel)
navigationId_ = Str16ToStr8(parcel.ReadString16());
navDestinationName_ = Str16ToStr8(parcel.ReadString16());
isServiceMatch_ = parcel.ReadBool();
deviceId_ = Str16ToStr8(parcel.ReadString16());
return true;
}
@@ -200,6 +201,7 @@ bool InsightIntentExecuteParam::Marshalling(Parcel &parcel) const
parcel.WriteString16(Str8ToStr16(navigationId_));
parcel.WriteString16(Str8ToStr16(navDestinationName_));
parcel.WriteBool(isServiceMatch_);
parcel.WriteString16(Str8ToStr16(deviceId_));
return true;
}
@@ -266,6 +268,7 @@ bool InsightIntentExecuteParam::GenerateFromWant(const AAFwk::Want &want,
executeParam.navDestinationName_ = wantParams.GetStringParam(INSIGHT_INTENT_PAGE_PARAM_NAVDESTINATIONNAME);
executeParam.queryEntityClassName_ = wantParams.GetStringParam(INSIGHT_INTENT_QUERY_ENTITY_CLASS_NAME);
executeParam.queryType_ = wantParams.GetStringParam(INSIGHT_INTENT_QUERY_TYPE);
executeParam.userId_ = wantParams.GetIntParam(INSIGHT_INTENT_PARAM_USER_ID, -1);
auto queryParams = wantParams.GetWantParams(INSIGHT_INTENT_QUERY_ENTITY_PARAM_PARAM);
executeParam.queryParams_ = std::make_shared<WantParams>(queryParams);
return true;
@@ -15,9 +15,24 @@
#include "insight_intent_execute_result.h"
#include "nlohmann/json.hpp"
namespace OHOS {
namespace AppExecFwk {
using WantParams = OHOS::AAFwk::WantParams;
namespace {
constexpr const char *KEY_INNER_ERR = "innerErr";
constexpr const char *KEY_CODE = "code";
constexpr const char *KEY_FLAGS = "flags";
constexpr const char *KEY_RESULT = "result";
constexpr const char *KEY_URIS = "uris";
constexpr const char *KEY_IS_DECORATOR = "isDecorator";
constexpr const char *KEY_IS_NEED_DELAY_RESULT = "isNeedDelayResult";
constexpr const char *KEY_IS_QUERY_ENTITY = "isQueryEntity";
constexpr const char *KEY_QUERY_RESULTS = "queryResults";
} // namespace
bool InsightIntentExecuteResult::ReadFromParcel(Parcel &parcel)
{
innerErr = parcel.ReadInt32();
@@ -84,6 +99,96 @@ InsightIntentExecuteResult *InsightIntentExecuteResult::Unmarshalling(Parcel &pa
return res;
}
void InsightIntentExecuteResult::FromJsonString(const std::string &jsonStr)
{
nlohmann::json jsonObject = nlohmann::json::parse(jsonStr, nullptr, false);
if (jsonObject.is_discarded() || !jsonObject.is_object()) {
return;
}
if (jsonObject.contains(KEY_INNER_ERR) && jsonObject.at(KEY_INNER_ERR).is_number_integer()) {
innerErr = jsonObject.at(KEY_INNER_ERR).get<int32_t>();
}
if (jsonObject.contains(KEY_CODE) && jsonObject.at(KEY_CODE).is_number_integer()) {
code = jsonObject.at(KEY_CODE).get<int32_t>();
}
if (jsonObject.contains(KEY_FLAGS) && jsonObject.at(KEY_FLAGS).is_number_integer()) {
flags = jsonObject.at(KEY_FLAGS).get<int32_t>();
}
if (jsonObject.contains(KEY_IS_DECORATOR) && jsonObject.at(KEY_IS_DECORATOR).is_boolean()) {
isDecorator = jsonObject.at(KEY_IS_DECORATOR).get<bool>();
}
if (jsonObject.contains(KEY_IS_NEED_DELAY_RESULT) && jsonObject.at(KEY_IS_NEED_DELAY_RESULT).is_boolean()) {
isNeedDelayResult = jsonObject.at(KEY_IS_NEED_DELAY_RESULT).get<bool>();
}
if (jsonObject.contains(KEY_IS_QUERY_ENTITY) && jsonObject.at(KEY_IS_QUERY_ENTITY).is_boolean()) {
isQueryEntity = jsonObject.at(KEY_IS_QUERY_ENTITY).get<bool>();
}
if (jsonObject.contains(KEY_URIS) && jsonObject.at(KEY_URIS).is_array()) {
uris.clear();
for (const auto &item : jsonObject.at(KEY_URIS)) {
if (item.is_string()) {
uris.emplace_back(item.get<std::string>());
}
}
}
if (jsonObject.contains(KEY_RESULT)) {
const auto &resultJson = jsonObject.at(KEY_RESULT);
if (resultJson.is_object()) {
result = std::make_shared<WantParams>();
OHOS::AAFwk::from_json(resultJson, *result);
} else if (resultJson.is_null()) {
result = nullptr;
}
}
if (jsonObject.contains(KEY_QUERY_RESULTS) && jsonObject.at(KEY_QUERY_RESULTS).is_array()) {
queryResults.clear();
for (const auto &item : jsonObject.at(KEY_QUERY_RESULTS)) {
if (!item.is_object()) {
continue;
}
auto queryResult = std::make_shared<WantParams>();
OHOS::AAFwk::from_json(item, *queryResult);
queryResults.emplace_back(queryResult);
}
}
}
std::string InsightIntentExecuteResult::ToJsonString() const
{
nlohmann::json jsonObject;
jsonObject[KEY_INNER_ERR] = innerErr;
jsonObject[KEY_CODE] = code;
jsonObject[KEY_FLAGS] = flags;
jsonObject[KEY_URIS] = uris;
jsonObject[KEY_IS_DECORATOR] = isDecorator;
jsonObject[KEY_IS_NEED_DELAY_RESULT] = isNeedDelayResult;
jsonObject[KEY_IS_QUERY_ENTITY] = isQueryEntity;
if (result != nullptr) {
nlohmann::json resultJson;
OHOS::AAFwk::to_json(resultJson, *result);
jsonObject[KEY_RESULT] = resultJson;
} else {
jsonObject[KEY_RESULT] = nullptr;
}
nlohmann::json queryResultsJson = nlohmann::json::array();
for (const auto &item : queryResults) {
if (item == nullptr) {
continue;
}
nlohmann::json itemJson;
OHOS::AAFwk::to_json(itemJson, *item);
queryResultsJson.emplace_back(itemJson);
}
jsonObject[KEY_QUERY_RESULTS] = queryResultsJson;
return jsonObject.dump();
}
bool InsightIntentExecuteResult::CheckResult(std::shared_ptr<const WantParams> result)
{
return true;
@@ -26,12 +26,27 @@ void RemoteIntentResultCallback::OnIntentResult(uint64_t requestCode, int32_t re
{
TAG_LOGI(AAFwkTag::ABILITYMGR,
"OnIntentResult requestCode=%{public}" PRIu64 ", resultCode=%{public}d", requestCode, resultCode);
if (resultMsg.empty()) {
AppExecFwk::InsightIntentExecuteResult errorResult{};
errorResult.innerErr = AbilityRuntime::InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED;
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->ExecuteIntentDone(
requestCode, resultCode, errorResult);
} else {
AppExecFwk::InsightIntentExecuteResult result;
result.FromJsonString(resultMsg);
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->ExecuteIntentDone(
requestCode, resultCode, result);
}
}
void RemoteIntentResultCallback::OnLinkDisconnected(uint64_t requestCode, int32_t reason)
{
TAG_LOGI(AAFwkTag::ABILITYMGR,
"OnLinkDisconnected requestCode=%{public}" PRIu64 ", reason=%{public}d", requestCode, reason);
AppExecFwk::InsightIntentExecuteResult errorResult{};
errorResult.innerErr = AbilityRuntime::InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED;
DelayedSingleton<InsightIntentExecuteManager>::GetInstance()->ExecuteIntentDone(
requestCode, ERR_INTENT_DEVICE_DISCONNECTED, errorResult);
}
} // namespace AAFwk
} // namespace OHOS
@@ -88,6 +88,7 @@ constexpr const char* PERMISSION_GET_AGENT_CARD = "ohos.permission.GET_AGENT_CAR
constexpr const char* PERMISSION_MODIFY_AGENT_CARD = "ohos.permission.MODIFY_AGENT_CARD";
constexpr const char* PERMISSION_START_ABILITY_TO_PAGE = "ohos.permission.START_ABILITY_TO_PAGE";
constexpr const char* PERMISSION_CONTINUATION_NOTIFY = "ohos.permission.CONTINUATION_NOTIFY";
constexpr const char* PERMISSION_EXECUTE_DISTRIBUTED_INTENT = "ohos.permission.EXECUTE_DISTRIBUTED_INTENT";
} // namespace PermissionConstants
} // namespace AAFwk
} // namespace OHOS
@@ -28,6 +28,7 @@ struct VerificationInfo {
uint32_t accessTokenId = 0;
uint32_t specifyTokenId = 0;
int32_t apiTargetVersion = 0;
uint32_t specifiedFullTokenId = 0;
bool visible = false;
bool isBackgroundCall = true;
bool associatedWakeUp = false;
@@ -335,7 +335,8 @@ int PermissionVerification::CheckStartByCallPermission(const VerificationInfo &v
return CHECK_PERMISSION_FAILED;
}
// Different APP call, check permissions
if (!VerifyCallingPermission(PermissionConstants::PERMISSION_ABILITY_BACKGROUND_COMMUNICATION)) {
if (!VerifyCallingPermission(
PermissionConstants::PERMISSION_ABILITY_BACKGROUND_COMMUNICATION, verificationInfo.specifiedFullTokenId)) {
TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied");
return CHECK_PERMISSION_FAILED;
}
@@ -53,7 +53,8 @@ int MockServiceAbilityManagerService::StartAbilityAsCaller(
}
int MockServiceAbilityManagerService::StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible)
const sptr<IRemoteObject>& callerToken, int32_t accountId,
bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
GTEST_LOG_(INFO) << "MockServiceAbilityManagerService::StartAbilityByCall begain";
if (!connect) {
@@ -68,7 +68,7 @@ public:
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false);
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
int StartAbilityForPrelaunch(const Want &want, const int32_t frameNum);
int TerminateAbility(
const sptr<IRemoteObject>& token, int resultCode = -1, const Want* resultWant = nullptr) override;
@@ -147,8 +147,8 @@ public:
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD2(GetWantSenderInfo, int(const sptr<IWantSender>& target, std::shared_ptr<WantSenderInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD5(StartAbilityAsCaller, int(const Want& want, const sptr<IRemoteObject>& callerToken,
sptr<IRemoteObject> asCallerSourceToken, int32_t userId, int requestCode));
@@ -100,7 +100,8 @@ int MockAbilityDelegatorStub::UnRegisterMissionListener(const std::string& devic
}
int MockAbilityDelegatorStub::StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible)
const sptr<IRemoteObject>& callerToken, int32_t accountId,
bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
return 0;
}
@@ -300,7 +301,8 @@ int MockAbilityDelegatorStub2::UnRegisterMissionListener(const std::string& devi
}
int MockAbilityDelegatorStub2::StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible)
const sptr<IRemoteObject>& callerToken, int32_t accountId,
bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId)
{
return 0;
}
@@ -138,8 +138,8 @@ public:
int UnRegisterMissionListener(const std::string& deviceId,
const sptr<IRemoteMissionListener>& listener) override;
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
int StartAbilityForPrelaunch(const Want &want, const int32_t frameNum) override;
void CallRequestDone(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& callStub) override;
int ReleaseCall(const sptr<IAbilityConnection>& connect,
@@ -324,8 +324,8 @@ public:
int UnRegisterMissionListener(const std::string& deviceId,
const sptr<IRemoteMissionListener>& listener) override;
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE,
bool isSilent = false, bool promotePriority = false, bool isVisible = false) override;
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override;
int StartAbilityForPrelaunch(const Want &want, const int32_t frameNum) override;
void CallRequestDone(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& callStub) override;
virtual int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list)
@@ -162,8 +162,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token));
MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
@@ -166,8 +166,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -289,7 +289,7 @@ public:
}
int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -117,8 +117,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -355,7 +355,7 @@ public:
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -374,7 +374,7 @@ public:
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -326,7 +326,7 @@ public:
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -359,8 +359,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -359,8 +359,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -359,8 +359,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -359,8 +359,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -378,8 +378,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -327,8 +327,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t& missionId, const sptr<IAcquireShareDataCallback>& shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject>& token, const int32_t& resultCode,
const int32_t& uniqueId, WantParams& wantParam));
@@ -170,6 +170,8 @@ ohos_unittest("ability_manager_service_fourteenth_test") {
"${ability_runtime_services_path}/abilitymgr/src/rdb/parser_util.cpp",
"${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback_stub.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp",
"${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp",
@@ -178,6 +178,8 @@ ohos_unittest("ability_manager_service_second_test") {
"${ability_runtime_services_path}/abilitymgr/src/rdb/parser_util.cpp",
"${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback_stub.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp",
"${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp",
@@ -171,6 +171,8 @@ ohos_unittest("ability_manager_service_thirteenth_test") {
"${ability_runtime_services_path}/abilitymgr/src/rdb/parser_util.cpp",
"${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/recovery_info_timer.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback_stub.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_intent_result_callback.cpp",
"${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_proxy.cpp",
"${ability_runtime_services_path}/abilitymgr/src/report_data_partition_usage_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/resident_process/resident_process_manager.cpp",
@@ -70,8 +70,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
MOCK_METHOD4(ShareDataDone, int32_t(const sptr<IRemoteObject> &token,
const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam));
@@ -360,7 +360,7 @@ public:
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -330,8 +330,8 @@ public:
}
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -50,8 +50,10 @@ ohos_unittest("insight_intent_execute_manager_second_test") {
}
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
]
external_deps = [
@@ -42,6 +42,7 @@ ohos_unittest("insight_intent_execute_manager_test") {
}
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:perm_verification",
@@ -330,8 +330,8 @@ public:
}
int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false) override
const sptr<IRemoteObject>& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override
{
return 0;
}
@@ -0,0 +1,70 @@
# Copyright (c) 2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_unittest("start_remote_intent_test") {
module_out_path = "ability_runtime/ability_runtime/start_remote_intent_test"
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include",
]
sources = [
"${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp",
"mock_remote_intent_result_callback.cpp",
"start_remote_ability_test.cpp",
]
configs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config",
]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_connect_callback_stub",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:mission_info",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:abilitykit_utils",
"${ability_runtime_native_path}/appkit:app_context",
]
external_deps = [
"ability_base:extractortool",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"googletest:gtest_main",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"napi:ace_napi",
"resource_management:global_resmgr",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
external_deps += [
"form_fwk:fmskit_native",
"i18n:intl_util",
]
}
}
group("unittest") {
testonly = true
deps = [ ":start_remote_intent_test" ]
}
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mock_remote_intent_result_callback.h"
namespace OHOS {
namespace AAFwk {
int RemoteIntentResultCallback::onIntentResultCount = 0;
int RemoteIntentResultCallback::onLinkDisconnectedCount = 0;
void RemoteIntentResultCallback::OnIntentResult(
int32_t requestCode, int32_t resultCode, const std::string& resultMsg)
{
onIntentResultCount++;
}
void RemoteIntentResultCallback::OnLinkDisconnected(int32_t requestCode, int32_t reason)
{
onLinkDisconnectedCount++;
}
} // namespace AAFwk
} // namespace OHOS
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_MOCK_REMOTE_INTENT_RESULT_CALLBACK_H
#define OHOS_ABILITY_RUNTIME_MOCK_REMOTE_INTENT_RESULT_CALLBACK_H
#include <string>
#include "iremote_stub.h"
#include "remote_intent_result_callback_interface.h"
namespace OHOS {
namespace AAFwk {
class RemoteIntentResultCallback : public IRemoteStub<IRemoteIntentResultCallback> {
public:
RemoteIntentResultCallback() = default;
virtual ~RemoteIntentResultCallback() = default;
void OnIntentResult(int32_t requestCode, int32_t resultCode, const std::string& resultMsg) override;
void OnLinkDisconnected(int32_t requestCode, int32_t reason) override;
static int onIntentResultCount;
static int onLinkDisconnectedCount;
};
} // namespace AAFwk
} // namespace OHOS
#endif
@@ -0,0 +1,231 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <iremote_stub.h>
#define private public
#define protected public
#include "ability_manager_errors.h"
#include "dms_intent_caller_info.h"
#include "distributed_client.h"
#include "distributed_parcel_helper.h"
#include "iservice_registry.h"
#include "iremote_object.h"
#include "mock_ability_connect_callback.h"
#include "mock_remote_intent_result_callback.h"
#include "parcel.h"
#undef protected
#undef private
using namespace OHOS;
using namespace OHOS::AppExecFwk;
using namespace testing;
using namespace testing::ext;
class StartRemoteIntentTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void StartRemoteIntentTest::SetUpTestCase()
{}
void StartRemoteIntentTest::TearDownTestCase()
{}
void StartRemoteIntentTest::SetUp()
{}
void StartRemoteIntentTest::TearDown()
{}
/**
* @tc.number: StartRemoteIntent_0100
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test, return DMS_PERMISSION_DENIED.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0100, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0100 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = 100;
callerInfo.requestCode = 1;
callerInfo.accessToken = 200;
callerInfo.specifyTokenId = 300;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
if (client->GetDmsProxy() != nullptr) {
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
} else {
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
}
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0100 end";
}
/**
* @tc.number: StartRemoteIntent_0200
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test, return INVALID_PARAMETERS_ERR when samgr is nullptr.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0200, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0200 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr;
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0200 end";
}
/**
* @tc.number: StartRemoteIntent_0300
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with specifyTokenId, return INVALID_PARAMETERS_ERR when samgr is nullptr.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0300, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0300 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = 100;
callerInfo.requestCode = 1;
callerInfo.accessToken = 200;
callerInfo.specifyTokenId = 300;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr;
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0300 end";
}
/**
* @tc.number: StartRemoteIntent_0400
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with null callback, return DMS_PERMISSION_DENIED or INVALID_PARAMETERS_ERR.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0400, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0400 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = 0;
int32_t result = client->StartRemoteIntent(want, callerInfo, nullptr);
if (client->GetDmsProxy() != nullptr) {
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
} else {
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
}
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0400 end";
}
/**
* @tc.number: StartRemoteIntent_0500
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with null callback and samgr nullptr, return INVALID_PARAMETERS_ERR.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0500, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0500 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = nullptr;
int32_t result = client->StartRemoteIntent(want, callerInfo, nullptr);
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0500 end";
}
/**
* @tc.number: StartRemoteIntent_0600
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with Want containing ElementName, return DMS_PERMISSION_DENIED.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0600, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0600 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
AppExecFwk::ElementName element("deviceId", "com.test.bundle", "MainAbility");
want.SetElement(element);
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = 100;
callerInfo.accessToken = 1000;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
if (client->GetDmsProxy() != nullptr) {
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
} else {
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
}
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0600 end";
}
/**
* @tc.number: StartRemoteIntent_0700
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with zero IntentCallerInfo, return DMS_PERMISSION_DENIED.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0700, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0700 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = 0;
callerInfo.requestCode = 0;
callerInfo.accessToken = 0;
callerInfo.specifyTokenId = 0;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
if (client->GetDmsProxy() != nullptr) {
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
} else {
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
}
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0700 end";
}
/**
* @tc.number: StartRemoteIntent_0800
* @tc.name: StartRemoteIntent
* @tc.desc: StartRemoteIntent Test with negative callerUid, return DMS_PERMISSION_DENIED.
*/
HWTEST_F(StartRemoteIntentTest, StartRemoteIntent_0800, TestSize.Level3)
{
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0800 start";
auto client = std::make_shared<OHOS::AAFwk::DistributedClient>();
OHOS::AAFwk::Want want;
OHOS::AAFwk::IntentCallerInfo callerInfo;
callerInfo.callerUid = -1;
callerInfo.requestCode = -1;
sptr<IRemoteObject> callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback();
int32_t result = client->StartRemoteIntent(want, callerInfo, callback);
if (client->GetDmsProxy() != nullptr) {
EXPECT_EQ(result, OHOS::AAFwk::DMS_PERMISSION_DENIED);
} else {
EXPECT_EQ(result, OHOS::AAFwk::INVALID_PARAMETERS_ERR);
}
GTEST_LOG_(INFO) << "StartRemoteIntentTest StartRemoteIntent_0800 end";
}
@@ -148,8 +148,8 @@ public:
MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector<AbilityRunningInfo>& info));
MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector<ExtensionRunningInfo>& info));
MOCK_METHOD1(GetProcessRunningInfos, int(std::vector<AppExecFwk::RunningProcessInfo>& info));
MOCK_METHOD7(StartAbilityByCall,
int(const Want&, const sptr<IAbilityConnection>&, const sptr<IRemoteObject>&, int32_t, bool, bool, bool));
MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr<IAbilityConnection>&,
const sptr<IRemoteObject>&, int32_t, bool, bool, bool, uint64_t));
MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr<IRemoteObject>& token));
MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token));
MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData));
+1 -1
View File
@@ -190,7 +190,7 @@ public:
virtual int StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
const sptr<IRemoteObject>& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false,
bool promotePriority = false, bool isVisible = false)
bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0)
{
return 0;
}