From 1acc90e1713643b5585e5de1bff6a1ed7b757ebe Mon Sep 17 00:00:00 2001 From: renjh5496 Date: Tue, 28 Apr 2026 11:21:34 +0800 Subject: [PATCH] provide dms interfaces Co-Authored-By: ya Signed-off-by: renjh5496 --- .../distributed_client.cpp | 45 ++++++++ .../include/ability_manager_client.h | 12 ++ .../include/ability_manager_interface.h | 15 +++ .../ability_manager_ipc_interface_code.h | 2 + .../include/dms_intent_caller_info.h | 31 +++++ .../remote_intent_result_callback_interface.h | 39 +++++++ .../remote_intent_result_callback_proxy.h | 43 +++++++ .../remote_intent_result_callback_stub.h | 42 +++++++ .../distributed_client.h | 10 +- services/abilitymgr/abilitymgr.gni | 5 + .../include/ability_manager_proxy.h | 12 ++ .../include/ability_manager_service.h | 2 + .../abilitymgr/include/ability_manager_stub.h | 1 + .../include/remote_intent_result_callback.h | 37 ++++++ .../abilitymgr/src/ability_manager_client.cpp | 9 ++ .../abilitymgr/src/ability_manager_proxy.cpp | 37 ++++++ .../src/ability_manager_service.cpp | 26 +++++ .../abilitymgr/src/ability_manager_stub.cpp | 28 +++++ .../src/remote_intent_result_callback.cpp | 37 ++++++ .../remote_intent_result_callback_proxy.cpp | 106 ++++++++++++++++++ .../remote_intent_result_callback_stub.cpp | 63 +++++++++++ 21 files changed, 601 insertions(+), 1 deletion(-) create mode 100644 interfaces/inner_api/ability_manager/include/dms_intent_caller_info.h create mode 100644 interfaces/inner_api/ability_manager/include/remote_intent_result_callback_interface.h create mode 100644 interfaces/inner_api/ability_manager/include/remote_intent_result_callback_proxy.h create mode 100644 interfaces/inner_api/ability_manager/include/remote_intent_result_callback_stub.h create mode 100644 services/abilitymgr/include/remote_intent_result_callback.h create mode 100644 services/abilitymgr/src/remote_intent_result_callback.cpp create mode 100644 services/abilitymgr/src/remote_intent_result_callback_proxy.cpp create mode 100644 services/abilitymgr/src/remote_intent_result_callback_stub.cpp 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 77335f0680..f463324ecf 100644 --- a/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp +++ b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp @@ -570,5 +570,50 @@ int32_t DistributedClient::OnCollaborateDone( PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast(NOTIFY_ON_COLLABORATE_DONE), data, reply); } + +int32_t DistributedClient::StartRemoteIntent(const OHOS::AAFwk::Want& want, + const OHOS::AAFwk::IntentCallerInfo& callerInfo, + const sptr& resultCallback) +{ + sptr remote = GetDmsProxy(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::DISTRIBUTED, "StartRemoteIntent null remote"); + return INVALID_PARAMETERS_ERR; + } + MessageParcel data; + if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + return ERR_FLATTEN_OBJECT; + } + PARCEL_WRITE_HELPER(data, Parcelable, &want); + PARCEL_WRITE_HELPER(data, Int32, callerInfo.callerUid); + PARCEL_WRITE_HELPER(data, Uint64, callerInfo.requestCode); + PARCEL_WRITE_HELPER(data, Uint32, callerInfo.accessToken); + PARCEL_WRITE_HELPER(data, Uint32, callerInfo.specifyTokenId); + PARCEL_WRITE_HELPER(data, RemoteObject, resultCallback); + MessageParcel reply; + PARCEL_TRANSACT_SYNC_RET_INT(remote, START_REMOTE_INTENT, data, reply); +} + +int32_t DistributedClient::SendIntentResult(const OHOS::AAFwk::Want& want, + const OHOS::AAFwk::IntentCallerInfo& callerInfo, const std::string& msg) +{ + sptr remote = GetDmsProxy(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::DISTRIBUTED, "SendIntentResult null remote"); + return INVALID_PARAMETERS_ERR; + } + MessageParcel data; + if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + return ERR_FLATTEN_OBJECT; + } + PARCEL_WRITE_HELPER(data, Parcelable, &want); + PARCEL_WRITE_HELPER(data, Int32, callerInfo.callerUid); + PARCEL_WRITE_HELPER(data, Uint64, callerInfo.requestCode); + PARCEL_WRITE_HELPER(data, Uint32, callerInfo.accessToken); + PARCEL_WRITE_HELPER(data, Uint32, callerInfo.specifyTokenId); + PARCEL_WRITE_HELPER(data, String, msg); + MessageParcel reply; + PARCEL_TRANSACT_SYNC_RET_INT(remote, SEND_INTENT_RESULT, data, reply); +} } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 77e976bd06..ffd0b61536 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1748,6 +1748,18 @@ public: ErrCode ExecuteIntent(uint64_t key, sptr callerToken, const InsightIntentExecuteParam ¶m); + /** + * @brief Execute intent for distributed scenario. + * + * @param want The want containing intent execution information. + * @param srcDeviceId The source device id. + * @param requestCode The Intent id. + * @param specifiedFullTokenId The caller token id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId = 0); + /** * @brief Query entity info. * @param key The key of intent executing client. 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 0118defd75..d5c8d07069 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -2015,6 +2015,21 @@ public: virtual int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, const InsightIntentExecuteParam ¶m) = 0; + /** + * @brief Execute intent for distributed scenario. + * + * @param want The want containing intent execution information. + * @param srcDeviceId The source device id. + * @param requestCode The Intent id. + * @param specifiedFullTokenId The caller token id. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId = 0) + { + return 0; + } + /** * @brief Check if ability controller can start. * @param want The want of ability to start. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index 9653626f86..577f2fa7e1 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -491,6 +491,8 @@ enum class AbilityManagerInterfaceCode { // ipc for request modal UIExtension with account REQUEST_MODAL_UI_EXTENSION_WITH_ACCOUNT = 1144, + EXECUTE_INTENT_FOR_DISTRIBUTED = 1145, + // ipc id 2001-3000 for tools // ipc id for dumping state (2001) DUMP_STATE = 2001, diff --git a/interfaces/inner_api/ability_manager/include/dms_intent_caller_info.h b/interfaces/inner_api/ability_manager/include/dms_intent_caller_info.h new file mode 100644 index 0000000000..222e6339d9 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/dms_intent_caller_info.h @@ -0,0 +1,31 @@ +/* + * 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 + * + * 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_DMS_INTENT_CALLER_INFO_H +#define OHOS_ABILITY_RUNTIME_DMS_INTENT_CALLER_INFO_H + +#include + +namespace OHOS { +namespace AAFwk { +struct IntentCallerInfo { + int32_t callerUid = 0; + uint64_t requestCode = 0; + uint32_t accessToken = 0; + uint32_t specifyTokenId = 0; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_DMS_INTENT_CALLER_INFO_H diff --git a/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_interface.h b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_interface.h new file mode 100644 index 0000000000..e4d4f7d2fa --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_interface.h @@ -0,0 +1,39 @@ +/* + * 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 + * + * 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_REMOTE_INTENT_RESULT_CALLBACK_INTERFACE_H +#define OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_INTERFACE_H + +#include +#include "iremote_broker.h" + +namespace OHOS { +namespace AAFwk { + +class IRemoteIntentResultCallback : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedschedule.IRemoteIntentResultCallback"); + enum { + ON_INTENT_RESULT = 1, + ON_LINK_DISCONNECTED = 2, + }; + + virtual void OnIntentResult(uint64_t requestCode, int32_t resultCode, const std::string& resultMsg) = 0; + virtual void OnLinkDisconnected(uint64_t requestCode, int32_t reason) = 0; +}; + +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_INTERFACE_H diff --git a/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_proxy.h b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_proxy.h new file mode 100644 index 0000000000..fa5b419626 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_proxy.h @@ -0,0 +1,43 @@ +/* + * 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 + * + * 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_REMOTE_INTENT_RESULT_CALLBACK_PROXY_H +#define OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_PROXY_H + +#include + +#include "iremote_broker.h" +#include "iremote_object.h" +#include "iremote_proxy.h" + +#include "remote_intent_result_callback_interface.h" + +namespace OHOS { +namespace AAFwk { +class RemoteIntentResultCallbackProxy : public IRemoteProxy { +public: + explicit RemoteIntentResultCallbackProxy(const sptr& impl); + + void OnIntentResult(uint64_t requestCode, int32_t resultCode, const std::string& resultMsg) override; + + void OnLinkDisconnected(uint64_t requestCode, int32_t reason) override; + +private: + int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + static inline BrokerDelegator delegator_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_PROXY_H diff --git a/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_stub.h b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_stub.h new file mode 100644 index 0000000000..16687cc8fa --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/remote_intent_result_callback_stub.h @@ -0,0 +1,42 @@ +/* + * 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 + * + * 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_REMOTE_INTENT_RESULT_CALLBACK_STUB_H +#define OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_STUB_H + +#include +#include +#include "nocopyable.h" + +#include "remote_intent_result_callback_interface.h" + +namespace OHOS { +namespace AAFwk { +class RemoteIntentResultCallbackStub : public IRemoteStub { +public: + RemoteIntentResultCallbackStub(); + virtual ~RemoteIntentResultCallbackStub() = default; + + int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(RemoteIntentResultCallbackStub); + int OnIntentResultInner(MessageParcel &data, MessageParcel &reply); + int OnLinkDisconnectedInner(MessageParcel &data, MessageParcel &reply); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_STUB_H diff --git a/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h b/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h index 82fb38de31..a6b34608a8 100644 --- a/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h +++ b/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h @@ -20,6 +20,7 @@ #include #include "dms_continueInfo.h" +#include "dms_intent_caller_info.h" #include "mission_info.h" #include "mission_snapshot.h" #include "want_params.h" @@ -63,6 +64,11 @@ public: int32_t SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state, int32_t callingUid); int32_t OnCollaborateDone( const std::string &collabToken, int32_t result, int32_t pid, int32_t uid, int32_t accessTokenId); + int32_t StartRemoteIntent(const OHOS::AAFwk::Want& want, + const OHOS::AAFwk::IntentCallerInfo& callerInfo, + const sptr& resultCallback); + int32_t SendIntentResult(const OHOS::AAFwk::Want& want, const OHOS::AAFwk::IntentCallerInfo& callerInfo, + const std::string& msg); enum { START_REMOTE_ABILITY = 1, CONNECT_REMOTE_ABILITY = 6, @@ -84,7 +90,9 @@ public: REGISTER_ON_LISTENER = 260, REGISTER_OFF_LISTENER = 261, SET_MISSION_CONTINUE_STATE = 300, - NOTIFY_ON_COLLABORATE_DONE = 334 + NOTIFY_ON_COLLABORATE_DONE = 334, + START_REMOTE_INTENT = 400, + SEND_INTENT_RESULT = 401 }; private: sptr GetDmsProxy(); diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index d4ffc1484d..6df7638307 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -116,6 +116,11 @@ abilityms_files = [ "src/free_install_manager.cpp", "src/free_install_observer_manager.cpp", + #remote_intent + "src/remote_intent_result_callback.cpp", + "src/remote_intent_result_callback_proxy.cpp", + "src/remote_intent_result_callback_stub.cpp", + #erms "src/query_erms_manager.cpp", "src/query_erms_observer_manager.cpp", diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index d8e18300de..91ef6e920f 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -1532,6 +1532,18 @@ public: int32_t ExecuteIntent(uint64_t key, const sptr &callerToken, const InsightIntentExecuteParam ¶m) override; + /** + * @brief Execute intent for distributed scenario. + * + * @param want The want containing intent execution information. + * @param srcDeviceId The source device id. + * @param requestCode The Intent id. + * @param specifiedFullTokenId The caller token id. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId = 0) override; + /** * @brief Query entity. * @param key The key of intent executing client. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index ac7a18a801..58ef5827b0 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2181,6 +2181,8 @@ public: int32_t StartAbilityByCallWithInsightIntent(const Want &want, const sptr &callerToken, const InsightIntentExecuteParam ¶m, int32_t userId = DEFAULT_INVAL_VALUE); + int32_t ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId = 0) override; /** * @brief Check if ability controller can start. diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index d1fba71811..772aee45ae 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -309,6 +309,7 @@ private: int32_t AttachAppDebugInner(MessageParcel &data, MessageParcel &reply); int32_t DetachAppDebugInner(MessageParcel &data, MessageParcel &reply); int32_t ExecuteIntentInner(MessageParcel &data, MessageParcel &reply); + int32_t ExecuteIntentForDistributedInner(MessageParcel &data, MessageParcel &reply); int32_t QueryEntityInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/remote_intent_result_callback.h b/services/abilitymgr/include/remote_intent_result_callback.h new file mode 100644 index 0000000000..b4eae4a35f --- /dev/null +++ b/services/abilitymgr/include/remote_intent_result_callback.h @@ -0,0 +1,37 @@ +/* + * 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_REMOTE_INTENT_RESULT_CALLBACK_H +#define OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_H + +#include +#include + +#include "remote_intent_result_callback_stub.h" + +namespace OHOS { +namespace AAFwk { +class RemoteIntentResultCallback : public RemoteIntentResultCallbackStub { +public: + RemoteIntentResultCallback() = default; + virtual ~RemoteIntentResultCallback() = default; + + void OnIntentResult(uint64_t requestCode, int32_t resultCode, const std::string& resultMsg) override; + + void OnLinkDisconnected(uint64_t requestCode, int32_t reason) override; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_REMOTE_INTENT_RESULT_CALLBACK_H diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index a076cfae5e..c7664b8fdf 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -2135,6 +2135,15 @@ ErrCode AbilityManagerClient::ExecuteIntent(uint64_t key, sptr ca return abms->ExecuteIntent(key, callerToken, param); } +ErrCode AbilityManagerClient::ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->ExecuteIntentForDistributed(want, srcDeviceId, requestCode, specifiedFullTokenId); +} + ErrCode AbilityManagerClient::QueryEntityInfo(uint64_t key, sptr callerToken, const InsightIntentQueryParam ¶m) { diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 4aadf86f71..1bd0300650 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -5770,6 +5770,43 @@ int32_t AbilityManagerProxy::ExecuteIntent(uint64_t key, const sptr callerToken, const InsightIntentQueryParam ¶m) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 47842db211..2775435aa4 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -13985,6 +13985,32 @@ int32_t AbilityManagerService::StartAbilityWithServiceMatch(const InsightIntentE } +int32_t AbilityManagerService::ExecuteIntentForDistributed(const Want &want, const std::string &srcDeviceId, + uint64_t requestCode, uint64_t specifiedFullTokenId) +{ + AppExecFwk::InsightIntentExecuteParam param; + if (!AppExecFwk::InsightIntentExecuteParam::GenerateFromWant(want, param)) { + TAG_LOGE(AAFwkTag::INTENT, "GenerateFromWant failed, not a valid insight intent"); + return ERR_INVALID_VALUE; + } + auto paramCopy = std::make_shared(param); + + uint64_t key = requestCode; + + auto callerBundlename = InsightIntentGetcallerBundleName(); + if (callerBundlename.empty()) { + TAG_LOGD(AAFwkTag::INTENT, "callerBundlename is null"); + } + + AbilityRuntime::ExtractInsightIntentGenericInfo infos = GetInsightIntentGenericInfo(*paramCopy); + bool openLinkExecuteFlag = infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_LINK; + bool ignoreAbilityName = openLinkExecuteFlag || + (infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_PAGE) || + (infos.decoratorType == AbilityRuntime::INSIGHT_INTENTS_DECORATOR_TYPE_FUNCTION); + + return ERR_OK; +} + int32_t AbilityManagerService::ExecuteIntent(uint64_t key, const sptr &callerToken, const InsightIntentExecuteParam ¶m) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 90c35bed1b..04dd7a241a 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -345,6 +345,9 @@ int AbilityManagerStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel if (interfaceCode == AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_IN_CURRENT_PROCESS) { return StartSelfUIAbilityInCurrentProcessInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::EXECUTE_INTENT_FOR_DISTRIBUTED) { + return ExecuteIntentForDistributedInner(data, reply); + } return ERR_CODE_NOT_EXIST; } @@ -4266,6 +4269,31 @@ int AbilityManagerStub::QueryEntityInner(MessageParcel &data, MessageParcel &rep return NO_ERROR; } +int32_t AbilityManagerStub::ExecuteIntentForDistributedInner(MessageParcel &data, MessageParcel &reply) +{ + std::unique_ptr want(data.ReadParcelable()); + if (want == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "want null"); + return ERR_INVALID_VALUE; + } + + std::string srcDeviceId = data.ReadString(); + if (srcDeviceId.empty()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "srcDeviceId empty"); + return ERR_INVALID_VALUE; + } + + uint64_t requestCode = data.ReadUint64(); + uint64_t specifiedFullTokenId = data.ReadUint64(); + + auto result = ExecuteIntentForDistributed(*want, srcDeviceId, requestCode, specifiedFullTokenId); + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write result fail"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::StartAbilityForResultAsCallerInner(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); diff --git a/services/abilitymgr/src/remote_intent_result_callback.cpp b/services/abilitymgr/src/remote_intent_result_callback.cpp new file mode 100644 index 0000000000..3a940e2cf4 --- /dev/null +++ b/services/abilitymgr/src/remote_intent_result_callback.cpp @@ -0,0 +1,37 @@ +/* + * 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 + * + * 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 "remote_intent_result_callback.h" +#include "insight_intent_execute_manager.h" +#include "insight_intent_execute_result.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AAFwk { +void RemoteIntentResultCallback::OnIntentResult(uint64_t requestCode, int32_t resultCode, + const std::string& resultMsg) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, + "OnIntentResult requestCode=%{public}" PRIu64 ", resultCode=%{public}d", requestCode, resultCode); +} + +void RemoteIntentResultCallback::OnLinkDisconnected(uint64_t requestCode, int32_t reason) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, + "OnLinkDisconnected requestCode=%{public}" PRIu64 ", reason=%{public}d", requestCode, reason); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/remote_intent_result_callback_proxy.cpp b/services/abilitymgr/src/remote_intent_result_callback_proxy.cpp new file mode 100644 index 0000000000..7bbc411c03 --- /dev/null +++ b/services/abilitymgr/src/remote_intent_result_callback_proxy.cpp @@ -0,0 +1,106 @@ +/* + * 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 + * + * 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 "remote_intent_result_callback_proxy.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AAFwk { +RemoteIntentResultCallbackProxy::RemoteIntentResultCallbackProxy(const sptr& impl) + : IRemoteProxy(impl) +{ +} + +void RemoteIntentResultCallbackProxy::OnIntentResult(uint64_t requestCode, int32_t resultCode, + const std::string& resultMsg) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(IRemoteIntentResultCallback::GetDescriptor())) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed"); + return; + } + + if (!data.WriteUint64(requestCode)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestCode failed"); + return; + } + + if (!data.WriteInt32(resultCode)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed"); + return; + } + + if (!data.WriteString(resultMsg)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultMsg failed"); + return; + } + + int32_t error = SendTransactCmd(IRemoteIntentResultCallback::ON_INTENT_RESULT, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "OnIntentResult fail, error: %{public}d", error); + return; + } +} + +void RemoteIntentResultCallbackProxy::OnLinkDisconnected(uint64_t requestCode, int32_t reason) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(IRemoteIntentResultCallback::GetDescriptor())) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed"); + return; + } + + if (!data.WriteUint64(requestCode)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestCode failed"); + return; + } + + if (!data.WriteInt32(reason)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write reason failed"); + return; + } + + int32_t error = SendTransactCmd(IRemoteIntentResultCallback::ON_LINK_DISCONNECTED, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "OnLinkDisconnected fail, error: %{public}d", error); + return; + } +} + +int32_t RemoteIntentResultCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + sptr remote = Remote(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote"); + return ERR_NULL_OBJECT; + } + + int32_t ret = remote->SendRequest(code, data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest failed, code: %{public}d, ret: %{public}d", code, ret); + return ret; + } + return NO_ERROR; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/src/remote_intent_result_callback_stub.cpp b/services/abilitymgr/src/remote_intent_result_callback_stub.cpp new file mode 100644 index 0000000000..f6efefe6ac --- /dev/null +++ b/services/abilitymgr/src/remote_intent_result_callback_stub.cpp @@ -0,0 +1,63 @@ +/* + * 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 + * + * 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 "remote_intent_result_callback_stub.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AAFwk { +RemoteIntentResultCallbackStub::RemoteIntentResultCallbackStub() {} + +int RemoteIntentResultCallbackStub::OnIntentResultInner(MessageParcel &data, MessageParcel &reply) +{ + auto requestCode = data.ReadUint64(); + auto resultCode = data.ReadInt32(); + std::string resultMsg = data.ReadString(); + OnIntentResult(requestCode, resultCode, resultMsg); + return NO_ERROR; +} + +int RemoteIntentResultCallbackStub::OnLinkDisconnectedInner(MessageParcel &data, MessageParcel &reply) +{ + auto requestCode = data.ReadUint64(); + auto reason = data.ReadInt32(); + OnLinkDisconnected(requestCode, reason); + return NO_ERROR; +} + +int RemoteIntentResultCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string descriptor = RemoteIntentResultCallbackStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "descriptor not equal to remote"); + return ERR_INVALID_STATE; + } + + switch (code) { + case IRemoteIntentResultCallback::ON_INTENT_RESULT: + return OnIntentResultInner(data, reply); + case IRemoteIntentResultCallback::ON_LINK_DISCONNECTED: + return OnLinkDisconnectedInner(data, reply); + default: + break; + } + + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} +} // namespace AAFwk +} // namespace OHOS