From 9e42a92b4accacf91fd4eb1ed575eb548e55b493 Mon Sep 17 00:00:00 2001 From: renjh5496 Date: Fri, 1 May 2026 14:44:11 +0800 Subject: [PATCH] support dms intent Co-Authored-By: ya Signed-off-by: renjh5496 --- .../src/ani_common_execute_param.cpp | 9 + .../@ohos.app.ability.insightIntentDriver.ets | 1 + .../napi_common/napi_common_execute_param.cpp | 10 + .../ability_business_error.cpp | 8 + .../distributed_client.cpp | 1 + .../include/ability_manager_errors.h | 6 + .../include/ability_manager_interface.h | 7 +- .../insight_intent_execute_param.h | 7 + .../insight_intent_execute_result.h | 2 + .../ability_business_error.h | 4 + .../include/ability_manager_proxy.h | 7 +- .../include/ability_manager_service.h | 19 +- .../extract_insight_intent_profile.h | 11 + .../insight_intent_execute_manager.h | 19 +- .../include/remote_intent_result_callback.h | 2 +- services/abilitymgr/libabilityms.map | 3 +- .../abilitymgr/src/ability_manager_proxy.cpp | 7 +- .../src/ability_manager_service.cpp | 239 ++++++++++++------ .../abilitymgr/src/ability_manager_stub.cpp | 4 +- .../insight_intent_execute_manager.cpp | 86 +++++-- .../insight_intent_execute_param.cpp | 3 + .../insight_intent_execute_result.cpp | 105 ++++++++ .../src/remote_intent_result_callback.cpp | 15 ++ .../common/include/permission_constants.h | 1 + .../common/include/permission_verification.h | 1 + .../common/src/permission_verification.cpp | 3 +- .../mock_serviceability_manager_service.cpp | 3 +- .../AMS/mock_serviceability_manager_service.h | 2 +- .../include/mock_ability_manager_service.h | 4 +- .../mock_ability_delegator_stub.cpp | 6 +- .../mock_ability_delegator_stub.h | 8 +- .../AMS/mock_ability_manager_service.h | 4 +- .../AMS/mock_serviceability_manager_service.h | 4 +- .../mock_iabilitymanager.h | 2 +- .../mock/include/mock_ability_mgr_service.h | 4 +- .../ability_manager_stub_mock_second_test.h | 2 +- .../ability_manager_stub_mock_test.h | 2 +- .../include/ability_manager_stub_mock_test.h | 2 +- .../ability_manager_stub_mock.h | 4 +- .../ability_manager_stub_mock.h | 4 +- .../ability_manager_stub_mock.h | 4 +- .../ability_manager_stub_mock.h | 4 +- .../ability_manager_stub_mock.h | 4 +- .../ability_manager_stub_mock.h | 4 +- .../BUILD.gn | 2 + .../BUILD.gn | 2 + .../BUILD.gn | 2 + .../ability_manager_stub_impl_mock.h | 4 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_mock.h | 4 +- .../BUILD.gn | 2 + .../BUILD.gn | 1 + .../ability_manager_stub_mock.h | 4 +- .../start_remote_ability_test/BUILD.gn | 70 +++++ .../mock_remote_intent_result_callback.cpp | 34 +++ .../mock_remote_intent_result_callback.h | 38 +++ .../start_remote_ability_test.cpp | 231 +++++++++++++++++ .../mock_ability_manager_service.h | 4 +- tools/test/mock/mock_ability_manager_stub.h | 2 +- 59 files changed, 885 insertions(+), 164 deletions(-) create mode 100644 test/unittest/start_remote_ability_test/BUILD.gn create mode 100644 test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.cpp create mode 100644 test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.h create mode 100644 test/unittest/start_remote_ability_test/start_remote_ability_test.cpp diff --git a/frameworks/ets/ani/ani_common/src/ani_common_execute_param.cpp b/frameworks/ets/ani/ani_common/src/ani_common_execute_param.cpp index f220abb8e6..a2edbde7ef 100644 --- a/frameworks/ets/ani/ani_common/src/ani_common_execute_param.cpp +++ b/frameworks/ets/ani/ani_common/src/ani_common_execute_param.cpp @@ -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"); diff --git a/frameworks/ets/ets/@ohos.app.ability.insightIntentDriver.ets b/frameworks/ets/ets/@ohos.app.ability.insightIntentDriver.ets index 7d79aeb887..6dd79b0fb5 100644 --- a/frameworks/ets/ets/@ohos.app.ability.insightIntentDriver.ets +++ b/frameworks/ets/ets/@ohos.app.ability.insightIntentDriver.ets @@ -34,6 +34,7 @@ export default namespace insightIntentDriver { uris?: Array; flags?: int; userId?: int; + deviceId?: string; } export interface InsightIntentInfoFilter { diff --git a/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp index f237c4c5b3..6d1a543a24 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_execute_param.cpp @@ -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) { diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index cde6a479be..75d8e6df9c 100644 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -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 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 INNER_TO_JS_ERROR_CODE_MAP { @@ -404,6 +410,8 @@ static std::unordered_map 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}, }; } diff --git a/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp index f463324ecf..a4d579ab7c 100644 --- a/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp +++ b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp @@ -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); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 1a5417774c..95dd203afa 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -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. */ diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 5b987197d3..30fd5c0546 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1221,7 +1221,7 @@ public: */ virtual int StartAbilityByCall(const Want &want, const sptr &connect, const sptr &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. @@ -1237,8 +1237,9 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr &connect, - const sptr &callerToken, int32_t accountId, std::string &errMsg, bool isSilent = false, - bool promotePriority = false, bool isVisible = false) + const sptr &callerToken, int32_t accountId, std::string &errMsg, + bool isSilent = false, bool promotePriority = false, + bool isVisible = false, uint64_t specifiedFullTokenId = 0) { return 0; }; diff --git a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_param.h b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_param.h index 1110ca11a9..b9040f6bcf 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_param.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_param.h @@ -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 queryParams_; + + // distributed intent params + std::string deviceId_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_result.h b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_result.h index 56fcd10216..aef5895c60 100644 --- a/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_result.h +++ b/interfaces/inner_api/ability_manager/include/insight_intent/insight_intent_execute_result.h @@ -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 result); }; diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 86b93349d0..a9a5704756 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -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 diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 7f632be092..4de104e4a5 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -927,8 +927,8 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int StartAbilityByCall(const Want &want, const sptr &connect, - const sptr &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, - bool isSilent = false, bool promotePriority = false, bool isVisible = false) override; + const sptr &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 &connect, const sptr &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. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 93130fbca4..937b682015 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -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 &connect, - const sptr &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, - bool isSilent = false, bool promotePriority = false, bool isVisible = false) override; + const sptr &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 &connect, const sptr &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 &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 &callerToken, - const InsightIntentExecuteParam ¶m, int32_t userId = DEFAULT_INVAL_VALUE); + int32_t StartAbilityByCallWithInsightIntent(const Want &want, + const sptr &callerToken, const InsightIntentExecuteParam ¶m, + 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; @@ -3551,6 +3554,10 @@ private: void HandleRecoveryRecipient(const std::shared_ptr& abilityRecord, const sptr& token); int32_t SetAppRecoveryFlag(const sptr& token, int flag) override; + int32_t ExecuteIntentCommon(const sptr &callerToken, + const std::shared_ptr ¶m, const std::string &callerBundleName, + const AbilityRuntime::ExecuteIntentCommonOptions &infos); + #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE std::shared_ptr bgtaskObserver_; #endif diff --git a/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h b/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h index 2f27551cb9..173497af8b 100644 --- a/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h +++ b/services/abilitymgr/include/insight_intent/extract_insight_intent_profile.h @@ -223,6 +223,17 @@ struct ExtractInsightIntentProfileInfoVec { std::vector 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); diff --git a/services/abilitymgr/include/insight_intent/insight_intent_execute_manager.h b/services/abilitymgr/include/insight_intent/insight_intent_execute_manager.h index 88fedb8bbd..bc85a120f7 100644 --- a/services/abilitymgr/include/insight_intent/insight_intent_execute_manager.h +++ b/services/abilitymgr/include/insight_intent/insight_intent_execute_manager.h @@ -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 &callerToken, const std::shared_ptr ¶m, 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 intentExemptionDeadlineTime_; int32_t AddRecord(uint64_t key, const sptr &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 ¶m, 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 CheckEntityQueryable( const AbilityRuntime::ExtractInsightIntentInfo& intentInfo, const std::string& className, const AppExecFwk::InsightIntentQueryEntityParam& queryParams); diff --git a/services/abilitymgr/include/remote_intent_result_callback.h b/services/abilitymgr/include/remote_intent_result_callback.h index b4eae4a35f..c432e73b3d 100644 --- a/services/abilitymgr/include/remote_intent_result_callback.h +++ b/services/abilitymgr/include/remote_intent_result_callback.h @@ -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 diff --git a/services/abilitymgr/libabilityms.map b/services/abilitymgr/libabilityms.map index 7e0ae12754..83f5ae409f 100644 --- a/services/abilitymgr/libabilityms.map +++ b/services/abilitymgr/libabilityms.map @@ -39,7 +39,8 @@ *ApplicationAnrListener*; *AppMgrUtil*; *AppScheduler*; - *AtomicServiceStatusCallback*; + *AtomicServiceStatusCallback*; + *RemoteIntentResultCallback*; *BackgroundTaskObserver*; *MainElementUtils*; *CallContainer*; diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index a0e3f93b23..c3ba08ee53 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -4037,16 +4037,17 @@ int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId, } int AbilityManagerProxy::StartAbilityByCall(const Want &want, const sptr &connect, - const sptr &callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible) + const sptr &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 &connect, const sptr &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()); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f23f8fd7bf..dd19c5957c 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -92,6 +92,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" @@ -292,7 +293,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) { @@ -759,8 +762,8 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr &conne } int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr &connect, - const sptr &callerToken, int32_t accountId, bool isSilent, bool promotePriority, - bool isVisible) + const sptr &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 &connect, const sptr &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; @@ -9924,6 +9931,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) { @@ -12399,7 +12407,9 @@ int AbilityManagerService::CheckCallServiceExtensionPermission(const AbilityRequ verificationInfo.visible = abilityRequest.abilityInfo.visible; verificationInfo.withContinuousTask = IsBackgroundTaskUid(IPCSkeleton::GetCallingUid()); verificationInfo.isBackgroundCall = false; - verificationInfo.specifyTokenId = static_cast(abilityRequest.specifyTokenId); + verificationInfo.specifyTokenId = (abilityRequest.specifiedFullTokenId != 0) ? + static_cast(abilityRequest.specifiedFullTokenId) : + static_cast(abilityRequest.specifyTokenId); if (isParamStartAbilityEnable_) { bool stopContinuousTaskFlag = ShouldPreventStartAbility(abilityRequest); if (stopContinuousTaskFlag) { @@ -12846,6 +12856,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(abilityRequest.specifiedFullTokenId); + if (IsCallFromBackground(abilityRequest, verificationInfo.isBackgroundCall, false) != ERR_OK) { return ERR_INVALID_VALUE; } @@ -14004,6 +14016,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(param); uint64_t key = requestCode; @@ -14019,7 +14034,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 &callerToken, + const std::shared_ptr ¶m, 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::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::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::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 &callerToken, @@ -14029,6 +14129,7 @@ int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr(param); - int32_t ret = DelayedSingleton::GetInstance()->CheckAndUpdateParam(key, callerToken, - paramPtr, callerBundlename, ignoreAbilityName); + + int32_t ret = DelayedSingleton::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::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 callback = new (std::nothrow) AAFwk::RemoteIntentResultCallback(); + DistributedClient dmsClient; + if (dmsClient.StartRemoteIntent(want, callerInfo, callback) != ERR_OK) { + TAG_LOGE(AAFwkTag::INTENT, "StartRemoteIntent failed"); + DelayedSingleton::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::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 callerToken, @@ -14204,7 +14287,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); @@ -14220,7 +14304,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) { @@ -14237,7 +14322,8 @@ int32_t AbilityManagerService::StartExtensionAbilityWithInsightIntent(const Want } int32_t AbilityManagerService::StartAbilityByCallWithInsightIntent(const Want &want, - const sptr &callerToken, const InsightIntentExecuteParam ¶m, int32_t userId) + const sptr &callerToken, + const InsightIntentExecuteParam ¶m, int32_t userId, uint64_t specifiedFullTokenId) { TAG_LOGI(AAFwkTag::INTENT, "called"); sptr connect = sptr::MakeSptr(); @@ -14255,6 +14341,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"); @@ -14268,7 +14355,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::GetInstance()->SetIntentExemptionInfo( @@ -14330,9 +14418,10 @@ int32_t AbilityManagerService::ExecuteInsightIntentDone(const sptrGrantUriPermission(result.uris, result.flags, callerBundleName, initiatorTokenId); } #endif // SUPPORT_UPMS - + int32_t callerUid = IPCSkeleton::GetCallingUid(); + uint32_t accessToken = IPCSkeleton::GetCallingTokenID(); ret = DelayedSingleton::GetInstance()->ExecuteIntentDone( - intentId, result.innerErr, result); + intentId, result.innerErr, result, callerUid, accessToken); FreezeUtil::GetInstance().AddLifecycleEvent(token, "ExecuteInsightIntentDone end"); return ret; } diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index e0dcf379f1..5c6e3780b1 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -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; } diff --git a/services/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp b/services/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp index 2be1270f16..a831fcfeae 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_execute_manager.cpp @@ -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 &callerToken, const std::shared_ptr ¶m, 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 &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 lock(mutex_); intentId = ++intentIdCount_; @@ -254,6 +259,9 @@ int32_t InsightIntentExecuteManager::AddRecord(uint64_t key, const sptrcallerToken = callerToken; record->bundleName = bundleName; record->callerBundleName = callerBundleName; + record->isDistributed = isDistributed; + record->deviceId = deviceId; + record->requestCode = requestCode; if (callerToken != nullptr) { record->deathRecipient = sptr::MakeSptr(intentId); callerToken->AddDeathRecipient(record->deathRecipient); @@ -265,7 +273,6 @@ int32_t InsightIntentExecuteManager::AddRecord(uint64_t key, const sptr 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 remoteCallback = iface_cast(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 remoteCallback = + iface_cast(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 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; diff --git a/services/abilitymgr/src/insight_intent/insight_intent_execute_param.cpp b/services/abilitymgr/src/insight_intent/insight_intent_execute_param.cpp index b6195fdd87..90128e22f6 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_execute_param.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_execute_param.cpp @@ -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(queryParams); return true; diff --git a/services/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp b/services/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp index e7f0f0a445..c54ce5ae5b 100644 --- a/services/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp +++ b/services/abilitymgr/src/insight_intent/insight_intent_execute_result.cpp @@ -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(); + } + if (jsonObject.contains(KEY_CODE) && jsonObject.at(KEY_CODE).is_number_integer()) { + code = jsonObject.at(KEY_CODE).get(); + } + if (jsonObject.contains(KEY_FLAGS) && jsonObject.at(KEY_FLAGS).is_number_integer()) { + flags = jsonObject.at(KEY_FLAGS).get(); + } + if (jsonObject.contains(KEY_IS_DECORATOR) && jsonObject.at(KEY_IS_DECORATOR).is_boolean()) { + isDecorator = jsonObject.at(KEY_IS_DECORATOR).get(); + } + 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(); + } + if (jsonObject.contains(KEY_IS_QUERY_ENTITY) && jsonObject.at(KEY_IS_QUERY_ENTITY).is_boolean()) { + isQueryEntity = jsonObject.at(KEY_IS_QUERY_ENTITY).get(); + } + + 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()); + } + } + } + + if (jsonObject.contains(KEY_RESULT)) { + const auto &resultJson = jsonObject.at(KEY_RESULT); + if (resultJson.is_object()) { + result = std::make_shared(); + 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(); + 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 result) { return true; diff --git a/services/abilitymgr/src/remote_intent_result_callback.cpp b/services/abilitymgr/src/remote_intent_result_callback.cpp index 3a940e2cf4..060fb988a6 100644 --- a/services/abilitymgr/src/remote_intent_result_callback.cpp +++ b/services/abilitymgr/src/remote_intent_result_callback.cpp @@ -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::GetInstance()->ExecuteIntentDone( + requestCode, resultCode, errorResult); + } else { + AppExecFwk::InsightIntentExecuteResult result; + result.FromJsonString(resultMsg); + DelayedSingleton::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::GetInstance()->ExecuteIntentDone( + requestCode, ERR_INTENT_DEVICE_DISCONNECTED, errorResult); } } // namespace AAFwk } // namespace OHOS diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index bec171e736..9b2d1a4f65 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -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 diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index be29363537..dc8d710993 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -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; diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 2d860096ed..c2358a4f96 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -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; } diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp index eb730c2610..4c0f7f3602 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp @@ -53,7 +53,8 @@ int MockServiceAbilityManagerService::StartAbilityAsCaller( } int MockServiceAbilityManagerService::StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible) + const sptr& callerToken, int32_t accountId, + bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId) { GTEST_LOG_(INFO) << "MockServiceAbilityManagerService::StartAbilityByCall begain"; if (!connect) { diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index bccaf67438..539417e40c 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -68,7 +68,7 @@ public: int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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& token, int resultCode = -1, const Want* resultWant = nullptr) override; diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index 90b8810259..e908c62696 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -147,8 +147,8 @@ public: MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetWantSenderInfo, int(const sptr& target, std::shared_ptr& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD5(StartAbilityAsCaller, int(const Want& want, const sptr& callerToken, sptr asCallerSourceToken, int32_t userId, int requestCode)); diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index ec4a7f70be..dd177b397a 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -100,7 +100,8 @@ int MockAbilityDelegatorStub::UnRegisterMissionListener(const std::string& devic } int MockAbilityDelegatorStub::StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible) + const sptr& 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& connect, - const sptr& callerToken, int32_t accountId, bool isSilent, bool promotePriority, bool isVisible) + const sptr& callerToken, int32_t accountId, + bool isSilent, bool promotePriority, bool isVisible, uint64_t specifiedFullTokenId) { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 1e171bd8b7..14dafff36f 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -138,8 +138,8 @@ public: int UnRegisterMissionListener(const std::string& deviceId, const sptr& listener) override; int StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, - bool isSilent = false, bool promotePriority = false, bool isVisible = false) override; + const sptr& 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& token, const sptr& callStub) override; int ReleaseCall(const sptr& connect, @@ -324,8 +324,8 @@ public: int UnRegisterMissionListener(const std::string& deviceId, const sptr& listener) override; int StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, - bool isSilent = false, bool promotePriority = false, bool isVisible = false) override; + const sptr& 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& token, const sptr& callStub) override; virtual int32_t GetForegroundUIAbilities(std::vector &list) diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index aa2299e44e..f2de92b45f 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -162,8 +162,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr &callStub, sptr &token)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 76a3429f07..7576bd9641 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -166,8 +166,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h index 45a46e142e..e2eb6b558f 100644 --- a/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h +++ b/test/moduletest/ability_manager_client_test/mock_iabilitymanager.h @@ -289,7 +289,7 @@ public: } int StartAbilityByCall(const Want &want, const sptr &connect, const sptr &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; } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index f43bb72ef4..718c3d21fa 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -117,8 +117,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h index 0ec4fe4ba2..7818099927 100644 --- a/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h +++ b/test/unittest/ability_manager_client_branch_second_test/ability_manager_stub_mock_second_test.h @@ -355,7 +355,7 @@ public: int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 9788f1af5c..4684461b23 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -374,7 +374,7 @@ public: int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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; } diff --git a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h index a29afdeb2d..d45b3627d8 100644 --- a/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_third_test/mock/include/ability_manager_stub_mock_test.h @@ -326,7 +326,7 @@ public: int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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; } diff --git a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h index 367f62a7ce..69154cf688 100644 --- a/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fifth_test/ability_manager_stub_mock.h @@ -359,8 +359,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h index 57bcd80350..c1b023956d 100644 --- a/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_fourth_test/ability_manager_stub_mock.h @@ -359,8 +359,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h index f4e46129ca..98010ea59c 100644 --- a/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_second_test/ability_manager_stub_mock.h @@ -359,8 +359,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h index f4e46129ca..98010ea59c 100644 --- a/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_sixth_test/ability_manager_stub_mock.h @@ -359,8 +359,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index e8621e5a21..d95025962d 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -378,8 +378,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h index 2073831935..74041b680a 100644 --- a/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_third_test/ability_manager_stub_mock.h @@ -327,8 +327,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t& missionId, const sptr& shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr& token, const int32_t& resultCode, const int32_t& uniqueId, WantParams& wantParam)); diff --git a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn index d6c2c61861..46b11e465c 100644 --- a/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_fourteenth_test/BUILD.gn @@ -169,6 +169,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", diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 1d3b4a65bd..7b43c56281 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -177,6 +177,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", diff --git a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn index f2ba7edc97..6e0a4a1444 100644 --- a/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn +++ b/test/unittest/ability_manager_service_thirteenth_test/BUILD.gn @@ -170,6 +170,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", diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index c7ccbf8da2..5b3b957011 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -70,8 +70,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); MOCK_METHOD4(ShareDataDone, int32_t(const sptr &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)); diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 5bc2b00ec5..c0f75540c1 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -360,7 +360,7 @@ public: int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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; } diff --git a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h index 3d63747e52..3281cd8331 100644 --- a/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/app_service_extension_context_test/ability_manager_stub_mock.h @@ -330,8 +330,8 @@ public: } int StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false, - bool promotePriority = false, bool isVisible = false) override + const sptr& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false, + bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override { return 0; } diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn index bcca7ee3c3..16e344071b 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_second_test/BUILD.gn @@ -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 = [ diff --git a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn index 401cf3b2c7..602374f1f7 100644 --- a/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn +++ b/test/unittest/insight_intent/insight_intent_execute_manager_test/BUILD.gn @@ -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", diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index e416d3f124..ed36eee02f 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -330,8 +330,8 @@ public: } int StartAbilityByCall(const Want& want, const sptr& connect, - const sptr& callerToken, int32_t userId = DEFAULT_INVAL_VALUE, bool isSilent = false, - bool promotePriority = false, bool isVisible = false) override + const sptr& callerToken, int32_t accountId = DEFAULT_INVAL_VALUE, bool isSilent = false, + bool promotePriority = false, bool isVisible = false, uint64_t specifiedFullTokenId = 0) override { return 0; } diff --git a/test/unittest/start_remote_ability_test/BUILD.gn b/test/unittest/start_remote_ability_test/BUILD.gn new file mode 100644 index 0000000000..63560f3368 --- /dev/null +++ b/test/unittest/start_remote_ability_test/BUILD.gn @@ -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" ] +} diff --git a/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.cpp b/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.cpp new file mode 100644 index 0000000000..dbb9ddd738 --- /dev/null +++ b/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.cpp @@ -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 diff --git a/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.h b/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.h new file mode 100644 index 0000000000..93b496a725 --- /dev/null +++ b/test/unittest/start_remote_ability_test/mock_remote_intent_result_callback.h @@ -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 +#include "iremote_stub.h" +#include "remote_intent_result_callback_interface.h" + +namespace OHOS { +namespace AAFwk { +class RemoteIntentResultCallback : public IRemoteStub { +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 diff --git a/test/unittest/start_remote_ability_test/start_remote_ability_test.cpp b/test/unittest/start_remote_ability_test/start_remote_ability_test.cpp new file mode 100644 index 0000000000..3ff3c0c70b --- /dev/null +++ b/test/unittest/start_remote_ability_test/start_remote_ability_test.cpp @@ -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 +#include +#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::Want want; + OHOS::AAFwk::IntentCallerInfo callerInfo; + callerInfo.callerUid = 100; + callerInfo.requestCode = 1; + callerInfo.accessToken = 200; + callerInfo.specifyTokenId = 300; + sptr 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::Want want; + OHOS::AAFwk::IntentCallerInfo callerInfo; + sptr 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::Want want; + OHOS::AAFwk::IntentCallerInfo callerInfo; + callerInfo.callerUid = 100; + callerInfo.requestCode = 1; + callerInfo.accessToken = 200; + callerInfo.specifyTokenId = 300; + sptr 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::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::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::Want want; + AppExecFwk::ElementName element("deviceId", "com.test.bundle", "MainAbility"); + want.SetElement(element); + OHOS::AAFwk::IntentCallerInfo callerInfo; + callerInfo.callerUid = 100; + callerInfo.accessToken = 1000; + sptr 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::Want want; + OHOS::AAFwk::IntentCallerInfo callerInfo; + callerInfo.callerUid = 0; + callerInfo.requestCode = 0; + callerInfo.accessToken = 0; + callerInfo.specifyTokenId = 0; + sptr 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::Want want; + OHOS::AAFwk::IntentCallerInfo callerInfo; + callerInfo.callerUid = -1; + callerInfo.requestCode = -1; + sptr 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"; +} diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 33de221af2..de795606b3 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -148,8 +148,8 @@ public: MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); - MOCK_METHOD7(StartAbilityByCall, - int(const Want&, const sptr&, const sptr&, int32_t, bool, bool, bool)); + MOCK_METHOD8(StartAbilityByCall, int(const Want&, const sptr&, + const sptr&, int32_t, bool, bool, bool, uint64_t)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr &callStub, sptr &token)); MOCK_METHOD2(AcquireShareData, int32_t(const int32_t &missionId, const sptr &shareData)); diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 70a762afad..b1179f1637 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -190,7 +190,7 @@ public: virtual int StartAbilityByCall(const Want& want, const sptr& connect, const sptr& 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; }