From 01a4580675e5640e2459647a3feb409079ebf5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Wed, 27 Aug 2025 17:03:09 +0800 Subject: [PATCH] add service bind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../device_manager_ipc_interface_code.h | 2 + common/include/dm_constants.h | 1 + .../ipc/model/ipc_unbind_service_target_req.h | 42 ++++++ common/src/dm_anonymous.cpp | 3 +- common/src/dm_constants.cpp | 1 + common/src/ipc/standard/ipc_model_codec.cpp | 2 + .../native_cpp/include/device_manager.h | 3 + .../native_cpp/include/device_manager_impl.h | 3 + .../native_cpp/include/dm_device_info.h | 11 +- .../include/i_dm_service_impl_ext.h | 1 + .../include/i_dm_service_impl_ext_resident.h | 1 + .../idevice_manager_service_listener.h | 1 + .../native_cpp/src/device_manager_impl.cpp | 58 ++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 56 ++++++++ .../include/authentication_v2/auth_manager.h | 1 + .../authentication_v2/dm_auth_context.h | 1 + .../dm_auth_message_processor.h | 6 + .../include/device_manager_service_impl.h | 4 + .../src/authentication_v2/auth_manager.cpp | 14 ++ .../dm_auth_message_processor.cpp | 129 ++++++++++++++++-- .../src/authentication_v2/dm_auth_state.cpp | 5 + .../src/device_manager_service_impl.cpp | 91 ++++++++++++ .../service/include/device_manager_service.h | 4 + .../include/device_manager_service_listener.h | 1 + .../include/idevice_manager_service_impl.h | 3 + .../service/src/device_manager_service.cpp | 52 +++++++ .../src/device_manager_service_listener.cpp | 9 ++ .../src/ipc/standard/ipc_cmd_parser.cpp | 30 ++++ 28 files changed, 522 insertions(+), 13 deletions(-) create mode 100644 common/include/ipc/model/ipc_unbind_service_target_req.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 418684851..7d0eb7802 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -122,6 +122,8 @@ enum DMIpcCmdInterfaceCode { CHECK_SINK_ACCESS_CONTROL, CHECK_SRC_SAME_ACCOUNT, CHECK_SINK_SAME_ACCOUNT, + BIND_SERVICE_TARGET, + UNBIND_SERVICE_TARGET, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 403201b60..4b471f46a 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -172,6 +172,7 @@ DM_EXPORT extern const char* APP_USER_DATA; DM_EXPORT extern const char* BUNDLE_INFO; DM_EXPORT extern const char* TITLE; DM_EXPORT extern const char* DM_BUSINESS_ID; +DM_EXPORT extern const char* PARAM_KEY_IS_SERVICE_BIND; // screen state enum ScreenState { diff --git a/common/include/ipc/model/ipc_unbind_service_target_req.h b/common/include/ipc/model/ipc_unbind_service_target_req.h new file mode 100644 index 000000000..7167da853 --- /dev/null +++ b/common/include/ipc/model/ipc_unbind_service_target_req.h @@ -0,0 +1,42 @@ +/* + * 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_DM_IPC_UNBIND_SERVICE_TARGET_REQ_H +#define OHOS_DM_IPC_UNBIND_SERVICE_TARGET_REQ_H + +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcUnBindServiceTargetReq : public IpcReq { + DECLARE_IPC_MODEL(IpcUnBindServiceTargetReq); + +public: + int64_t GetServiceId() const + { + return serviceId_; + } + + void SetServiceId(int64_t serviceId) + { + serviceId_ = serviceId; + } + +private: + int64_t serviceId_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_UNBIND_SERVICE_TARGET_REQ_H diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 43a0ecfed..b083472b1 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -225,7 +225,8 @@ void ParseMapFromJsonString(const std::string &jsonStr, std::map MAP_ERROR_CODE = { diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index 2e336c5fd..f42cf49c3 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -76,6 +76,7 @@ bool IpcModelCodec::EncodePeerTargetId(const PeerTargetId &targetId, MessageParc bRet = (bRet && parcel.WriteString(targetId.bleMac)); bRet = (bRet && parcel.WriteString(targetId.wifiIp)); bRet = (bRet && parcel.WriteUint16(targetId.wifiPort)); + bRet = (bRet && parcel.WriteInt64(targetId.serviceId)); return bRet; } @@ -86,6 +87,7 @@ void IpcModelCodec::DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targ targetId.bleMac = parcel.ReadString(); targetId.wifiIp = parcel.ReadString(); targetId.wifiPort = parcel.ReadUint16(); + targetId.serviceId = parcel.ReadInt64(); } bool IpcModelCodec::EncodeDmAccessCaller(const DmAccessCaller &caller, MessageParcel &parcel) diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index da0db3936..8645264b7 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -653,6 +653,9 @@ public: virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) = 0; + virtual int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + std::map &bindParam, std::shared_ptr callback) = 0; + virtual int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 863626aef..fdd7d9d47 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -439,6 +439,9 @@ public: virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; + virtual int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + std::map &bindParam, std::shared_ptr callback) override; + virtual int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) override; private: DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index b7704d94d..5a32cf527 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -292,11 +292,16 @@ typedef struct PeerTargetId { * wlan ip port. */ uint16_t wifiPort = 0; + /** + * service id. + */ + int64_t serviceId; bool operator==(const PeerTargetId &other) const { return (deviceId == other.deviceId) && (brMac == other.brMac) && - (bleMac == other.bleMac) && (wifiIp == other.wifiIp) && (wifiPort == other.wifiPort); + (bleMac == other.bleMac) && (wifiIp == other.wifiIp) && (wifiPort == other.wifiPort) && + (serviceId == other.serviceId); } bool operator<(const PeerTargetId &other) const @@ -306,7 +311,9 @@ typedef struct PeerTargetId { (deviceId == other.deviceId && brMac == other.brMac && bleMac < other.bleMac) || (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp < other.wifiIp) || (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp == other.wifiIp && - wifiPort < other.wifiPort); + wifiPort < other.wifiPort) || + (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp == other.wifiIp && + wifiPort == other.wifiPort && serviceId < other.serviceId); } } PeerTargetId; diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index cb4bb85bc..39fed79af 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -107,6 +107,7 @@ public: virtual void OnSessionClosed(const int32_t sessionId) = 0; virtual void OnBytesReceived(const int32_t sessionId, const std::string message) = 0; virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; + virtual int32_t OpenAuthSessionWithPara(const int64_t serviceId) = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index 4f738fc7c..d7cf5669b 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -113,6 +113,7 @@ public: virtual void HandleScreenLockEvent(bool isLock) = 0; virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; virtual void HandleUserSwitchEvent(int32_t currentUserId, int32_t beforeUserId) = 0; + virtual int32_t OpenAuthSessionWithPara(const int64_t serviceId) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index 336c5b631..919a7c86e 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -177,6 +177,7 @@ public: virtual std::string GetLocalDisplayDeviceName() = 0; virtual int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) = 0; + virtual int32_t OpenAuthSessionWithPara(int64_t serviceId) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index d07c6ff68..3ccebfe5d 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -66,6 +66,7 @@ #include "ipc_sync_callback_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_unbind_device_req.h" +#include "ipc_unbind_service_target_req.h" #include "ipc_unpublish_req.h" #include "securec.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -2998,5 +2999,62 @@ bool DeviceManagerImpl::CheckAclByIpcCode(const DmAccessCaller &caller, const Dm anonyLocalUdid_); return result; } + +int32_t DeviceManagerImpl::BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + std::map &bindParam, std::shared_ptr callback) +{ + if (pkgName.empty() || IsInvalidPeerTargetId(targetId)) { + LOGE("DeviceManagerImpl::BindServiceTarget failed: input pkgName or targetId is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("start"); + std::string bindParamStr = ConvertMapToJsonString(bindParam); + DeviceManagerNotify::GetInstance().RegisterBindCallback(pkgName, targetId, callback); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetPeerTargetId(targetId); + req->SetBindParam(bindParamStr); + int32_t ret = ipcClientProxy_->SendRequest(BIND_SERVICE_TARGET, req, rsp); + if (ret != DM_OK) { + LOGE("BindServiceTarget error: Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("BindServiceTarget error: Failed with ret %{public}d", ret); + return ret; + } + + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) +{ + if (pkgName.empty() || serviceId == 0) { + LOGE("UnbindServiceTarget failed: input pkgName or serviceId is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("Start, pkgName: %{public}s", pkgName.c_str()); + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetServiceId(serviceId); + int32_t ret = ipcClientProxy_->SendRequest(UNBIND_SERVICE_TARGET, req, rsp); + if (ret != DM_OK) { + LOGE("UnbindServiceTarget error: Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("UnbindServiceTarget error: Failed with ret %{public}d", ret); + return ret; + } + + LOGI("Completed"); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index a30e5493b..866a84919 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -67,6 +67,7 @@ #include "ipc_permission_req.h" #include "ipc_publish_req.h" #include "ipc_unbind_device_req.h" +#include "ipc_unbind_service_target_req.h" #include "ipc_unpublish_req.h" #include "ipc_unauthenticate_device_req.h" #include "securec.h" @@ -2217,5 +2218,60 @@ ON_IPC_READ_RESPONSE(CHECK_SINK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ { return ReadResponse(CHECK_SINK_SAME_ACCOUNT, reply, pBaseRsp); } + +ON_IPC_SET_REQUEST(BIND_SERVICE_TARGET, std::shared_ptr pBaseReq, MessageParcel &data) +{ + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + PeerTargetId targetId = pReq->GetPeerTargetId(); + std::string bindParam = pReq->GetBindParam(); + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!IpcModelCodec::EncodePeerTargetId(targetId, data)) { + LOGE("write peer target id failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteString(bindParam)) { + LOGE("write bind parameter string failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(BIND_SERVICE_TARGET, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(UNBIND_SERVICE_TARGET, std::shared_ptr pBaseReq, MessageParcel &data) +{ + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + int64_t serviceId = pReq->GetServiceId(); + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteInt64(serviceId)) { + LOGE("write service id failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNBIND_SERVICE_TARGET, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/authentication_v2/auth_manager.h b/services/implementation/include/authentication_v2/auth_manager.h index 02deef3fe..58f16d19a 100644 --- a/services/implementation/include/authentication_v2/auth_manager.h +++ b/services/implementation/include/authentication_v2/auth_manager.h @@ -154,6 +154,7 @@ private: void GetBindCallerInfo(); int32_t GetBindLevel(int32_t bindLevel); void GetIsNeedJoinLnnParam(const std::map &bindParam); + void ParseServiceInfo(const JsonObject &jsonObject); }; class AuthSrcManager : public AuthManager { diff --git a/services/implementation/include/authentication_v2/dm_auth_context.h b/services/implementation/include/authentication_v2/dm_auth_context.h index 4bb875565..95271a5ea 100644 --- a/services/implementation/include/authentication_v2/dm_auth_context.h +++ b/services/implementation/include/authentication_v2/dm_auth_context.h @@ -276,6 +276,7 @@ struct DmAuthContext { std::multimap proxy; // Multimap where the key is the accessor and the value is the accesssee bool isNeedJoinLnn{true}; bool IsProxyBind{false}; + bool isServiceBind{false}; bool IsCallingProxyAsSubject{true}; bool IsNeedSetProxy{false}; bool isNeedAuthenticate{true}; // apply for skip authenticate diff --git a/services/implementation/include/authentication_v2/dm_auth_message_processor.h b/services/implementation/include/authentication_v2/dm_auth_message_processor.h index 98144d108..78706f4a3 100644 --- a/services/implementation/include/authentication_v2/dm_auth_message_processor.h +++ b/services/implementation/include/authentication_v2/dm_auth_message_processor.h @@ -357,6 +357,12 @@ private: void ParseUltrasonicSide(const JsonObject &jsonObject, std::shared_ptr context); void ParseCert(const JsonObject &jsonObject, std::shared_ptr context); void ParseAccesserInfo(const JsonObject &jsonObject, std::shared_ptr context); + void ParseServiceNego(const JsonObject &jsonObject, std::shared_ptr context); + void ParseSyncServiceInfo(const JsonObject &jsonObject, std::shared_ptr context); + + int32_t SetSyncMsgJson(std::shared_ptr &context, const DmAccess &accessSide, + const DmAccessToSync &accessToSync, JsonObject &syncMsgJson); + std::string GetAccesseeServiceInfo(int64_t serviceId); std::shared_ptr cryptoMgr_ = nullptr; std::unordered_map createMessageFuncMap_; std::unordered_map paraseMessageFuncMap_; diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 60726df8f..55733d996 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -205,6 +205,9 @@ public: const DmAccessCallee &callee, const std::string &sinkUdid); void DeleteHoDevice(const std::string &peerUdid, const std::vector &foreGroundUserIds, const std::vector &backGroundUserIds); + int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam); + int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); private: int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); std::string GetUdidHashByNetworkId(const std::string &networkId); @@ -303,6 +306,7 @@ private: const std::string &deviceId, int32_t reason, uint64_t tokenId); void GetBundleName(const DMAclQuadInfo &info, std::set &pkgNameSet); void DeleteSessionKey(int32_t userId, const DistributedDeviceProfile::AccessControlProfile &profile); + int32_t DeleteAclExtraDataServiceId(int64_t serviceId); private: std::mutex authMgrMtx_; std::shared_ptr authMgr_; // Old protocol only diff --git a/services/implementation/src/authentication_v2/auth_manager.cpp b/services/implementation/src/authentication_v2/auth_manager.cpp index 09e29468b..334dd9a39 100644 --- a/services/implementation/src/authentication_v2/auth_manager.cpp +++ b/services/implementation/src/authentication_v2/auth_manager.cpp @@ -477,9 +477,19 @@ void AuthManager::ParseJsonObject(const JsonObject &jsonObject) } ParseHmlInfoInJsonObject(jsonObject); ParseProxyJsonObject(jsonObject); + ParseServiceInfo(jsonObject); return; } +void AuthManager::ParseServiceInfo(const JsonObject &jsonObject) +{ + if (context_ == nullptr || jsonObject.IsDiscarded() || !IsString(jsonObject, PARAM_KEY_IS_SERVICE_BIND) || + jsonObject[PARAM_KEY_IS_SERVICE_BIND].Get() != DM_VAL_TRUE) { + return; + } + context_->isServiceBind = true; +} + void AuthManager::ParseUltrasonicSide(const JsonObject &jsonObject) { if (jsonObject[TAG_ULTRASONIC_SIDE].IsString()) { @@ -580,6 +590,10 @@ void AuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, return; } ParseJsonObject(jsonObject); + if (context_->isServiceBind) { + context_->accessee.serviceId = std::stoll(deviceId); + context_->accesser.serviceId = std::stoll(deviceId); + } context_->accesser.accountId = MultipleUserConnector::GetOhosAccountIdByUserId(context_->accesser.userId); // compatible for old version diff --git a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp index 9d8cc425b..812776303 100644 --- a/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_message_processor.cpp @@ -105,6 +105,14 @@ const char* TAG_LANGUAGE = "language"; const char* TAG_ULTRASONIC_SIDE = "ultrasonicSide"; const char* TAG_REMAINING_FROZEN_TIME = "remainingFrozenTime"; const char* TAG_IS_SUPPORT_ULTRASONIC = "isSupportUltrasonic"; +const char* TAG_SERVICE_ID = "serviceId"; +const char* TAG_ACCESSEE_SERVICE_INFO = "accesseeServiceInfo"; +const char* TAG_REG_SERVICE_ID = "regServiceId"; +const char* TAG_DEVICE_ID = "deviceId"; +const char* TAG_PUBLISH_STATE = "publishState"; +const char* TAG_SERVICE_TYPE = "serviceType"; +const char* TAG_SERVICE_NAME = "serviceName"; +const char* TAG_SERVICE_DISPLAY_NAME = "serviceDisplayName"; constexpr const char* TAG_CUSTOM_DESCRIPTION = "CUSTOMDESC"; @@ -361,6 +369,7 @@ int32_t DmAuthMessageProcessor::PutAccessControlList(std::shared_ptrIsProxyBind || context->subjectProxyOnes.empty() || (context->IsCallingProxyAsSubject && !isAuthed)) { std::string isLnnAclFalse = std::string(ACL_IS_LNN_ACL_VAL_FALSE); extraData[ACL_IS_LNN_ACL_KEY] = isLnnAclFalse; + extraData[TAG_SERVICE_ID] = access.serviceId; profile.SetExtraData(extraData.Dump()); profile.SetBindLevel(access.bindLevel); SetTransmitAccessControlList(context, accesser, accessee); @@ -900,6 +910,8 @@ int32_t DmAuthMessageProcessor::CreateNegotiateMessage(std::shared_ptraccessee.displayId; jsonObject[TAG_PEER_PKG_NAME] = context->accessee.pkgName; jsonObject[TAG_HOST_PKGLABEL] = context->pkgLabel; + jsonObject[TAG_SERVICE_ID] = context->accessee.serviceId; + jsonObject[PARAM_KEY_IS_SERVICE_BIND] = context->isServiceBind; if (!context->businessId.empty()) { jsonObject[DM_BUSINESS_ID] = context->businessId; @@ -1202,9 +1214,53 @@ int32_t DmAuthMessageProcessor::ParseSyncMessage(std::shared_ptr } } ParseCert(jsonObject, context); + ParseSyncServiceInfo(jsonObject, context); return DM_OK; } +void DmAuthMessageProcessor::ParseSyncServiceInfo(const JsonObject &jsonObject, + std::shared_ptr context) +{ + std::string serviceInfoStr = ""; + if (IsString(jsonObject, TAG_ACCESSEE_SERVICE_INFO)) { + serviceInfoStr = jsonObject[TAG_ACCESSEE_SERVICE_INFO].Get(); + } + JsonObject json; + json.Parse(serviceInfoStr); + if (json.IsDiscarded()) { + return; + } + ServiceInfoProfile serviceInfoProfile; + if (IsInt32(json, TAG_REG_SERVICE_ID)) { + serviceInfoProfile.regServiceId = json[TAG_REG_SERVICE_ID].Get(); + } + if (IsString(json, TAG_DEVICE_ID)) { + serviceInfoProfile.deviceId = json[TAG_DEVICE_ID].Get(); + } + if (IsInt32(json, TAG_USER_ID)) { + serviceInfoProfile.userId = json[TAG_USER_ID].Get(); + } + if (IsInt64(json, TAG_TOKEN_ID)) { + serviceInfoProfile.tokenId = json[TAG_TOKEN_ID].Get(); + } + if (IsInt32(json, TAG_PUBLISH_STATE)) { + serviceInfoProfile.publishState = json[TAG_PUBLISH_STATE].Get(); + } + if (IsInt64(json, TAG_SERVICE_ID)) { + serviceInfoProfile.serviceId = json[TAG_SERVICE_ID].Get(); + } + if (IsString(json, TAG_SERVICE_TYPE)) { + serviceInfoProfile.serviceType = json[TAG_SERVICE_TYPE].Get(); + } + if (IsString(json, TAG_SERVICE_NAME)) { + serviceInfoProfile.serviceName = json[TAG_SERVICE_NAME].Get(); + } + if (IsString(json, TAG_SERVICE_DISPLAY_NAME)) { + serviceInfoProfile.serviceDisplayName = json[TAG_SERVICE_DISPLAY_NAME].Get(); + } + DeviceProfileConnector::GetInstance().PutServiceInfoProfile(serviceInfoProfile); +} + int32_t DmAuthMessageProcessor::ParseProxyAccessToSync(std::shared_ptr &context, JsonObject &jsonObject) { @@ -1411,10 +1467,26 @@ int32_t DmAuthMessageProcessor::ParseNegotiateMessage( ParseAccesserInfo(jsonObject, context); ParseUltrasonicSide(jsonObject, context); ParseProxyNegotiateMessage(jsonObject, context); + ParseServiceNego(jsonObject, context); context->authStateMachine->TransitionTo(std::make_shared()); return DM_OK; } +void DmAuthMessageProcessor::ParseServiceNego(const JsonObject &jsonObject, + std::shared_ptr context) +{ + context->isServiceBind = false; + if (IsBool(jsonObject, PARAM_KEY_IS_SERVICE_BIND)) { + context->isServiceBind = jsonObject[PARAM_KEY_IS_SERVICE_BIND].Get(); + } + if (!context->isServiceBind) { + return; + } + if (IsInt64(jsonObject, TAG_SERVICE_ID)) { + context->accessee.serviceId = jsonObject[TAG_SERVICE_ID].Get(); + } +} + void DmAuthMessageProcessor::ParseAccesserInfo(const JsonObject &jsonObject, std::shared_ptr context) { @@ -2002,6 +2074,27 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptrEncryptMessage(plainJson.Dump(), encSyncMsg); +} + +int32_t DmAuthMessageProcessor::SetSyncMsgJson(std::shared_ptr &context, const DmAccess &accessSide, + const DmAccessToSync &accessToSync, JsonObject &syncMsgJson) +{ syncMsgJson[TAG_TRANSMIT_SK_ID] = std::to_string(accessSide.transmitSessionKeyId); syncMsgJson[TAG_TRANSMIT_SK_TIMESTAMP] = accessSide.transmitSkTimeStamp; syncMsgJson[TAG_TRANSMIT_CREDENTIAL_ID] = accessSide.transmitCredentialId; @@ -2036,17 +2129,33 @@ int32_t DmAuthMessageProcessor::EncryptSyncMessage(std::shared_ptraccesser.isCommonFlag; syncMsgJson[TAG_DM_CERT_CHAIN] = context->accesser.cert; - CreateProxyAccessMessage(context, syncMsgJson); - std::string syncMsg = syncMsgJson.Dump(); - std::string compressMsg = CompressSyncMsg(syncMsg); - if (compressMsg.empty()) { - LOGE("DmAuthMessageProcessor::EncryptSyncMessage compress failed"); - return ERR_DM_FAILED; + if (context->isServiceBind) { + std::string serviceInfo = GetAccesseeServiceInfo(context->accessee.serviceId); + syncMsgJson[TAG_ACCESSEE_SERVICE_INFO] = serviceInfo; } - JsonObject plainJson; - plainJson[TAG_COMPRESS_ORI_LEN] = syncMsg.size(); - plainJson[TAG_COMPRESS] = Base64Encode(compressMsg); - return cryptoMgr_->EncryptMessage(plainJson.Dump(), encSyncMsg); + return DM_OK; +} + +std::string DmAuthMessageProcessor::GetAccesseeServiceInfo(int64_t serviceId) +{ + ServiceInfoProfile serviceInfoProfile; + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByServiceId(serviceId, + serviceInfoProfile); + if (ret != DM_OK) { + LOGE("GetAccesseeServiceInfo GetServiceInfoProfileByServiceId failed."); + return ""; + } + JsonObject json; + json[TAG_REG_SERVICE_ID] = serviceInfoProfile.regServiceId; + json[TAG_DEVICE_ID] = serviceInfoProfile.deviceId; + json[TAG_USER_ID] = serviceInfoProfile.userId; + json[TAG_TOKEN_ID] = serviceInfoProfile.tokenId; + json[TAG_PUBLISH_STATE] = serviceInfoProfile.publishState; + json[TAG_SERVICE_ID] = serviceInfoProfile.serviceId; + json[TAG_SERVICE_TYPE] = serviceInfoProfile.serviceType; + json[TAG_SERVICE_NAME] = serviceInfoProfile.serviceName; + json[TAG_SERVICE_DISPLAY_NAME] = serviceInfoProfile.serviceDisplayName; + return json.Dump(); } int32_t DmAuthMessageProcessor::CreateProxyAccessMessage(std::shared_ptr &context, diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index 5d5698a4d..f2ed043c9 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -986,6 +986,11 @@ void DmAuthState::JoinLnn(std::shared_ptr context) LOGI("The remote device is offline."); isForceJoin = true; } + if (context->isServiceBind) { + context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, + context->accessee.transmitSessionKeyId, isForceJoin); + return; + } if (context->connSessionType == CONN_SESSION_TYPE_HML) { context->softbusConnector->JoinLnnByHml(context->sessionId, context->accesser.transmitSessionKeyId, context->accessee.transmitSessionKeyId, isForceJoin); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index dea0e21e5..df16ebba8 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -20,6 +20,8 @@ #include #include +#include "distributed_device_profile_client.h" + #include "app_manager.h" #include "bundle_mgr_interface.h" #include "bundle_mgr_proxy.h" @@ -71,6 +73,7 @@ constexpr const char* BIND_CALLER_USERID = "bindCallerUserId"; const char* IS_NEED_JOIN_LNN = "IsNeedJoinLnn"; constexpr const char* NEED_JOIN_LNN = "0"; constexpr const char* NO_NEED_JOIN_LNN = "1"; +constexpr const char* TAG_SERVICE_ID = "serviceId"; // currently, we just support one bind session in one device at same time constexpr size_t MAX_NEW_PROC_SESSION_COUNT_TEMP = 1; const int32_t USLEEP_TIME_US_500000 = 500000; // 500ms @@ -1605,6 +1608,11 @@ static bool IsHmlSessionType(const JsonObject &jsonObject) int DeviceManagerServiceImpl::OpenAuthSession(const std::string& deviceId, const std::map &bindParam) { + if (bindParam.find(PARAM_KEY_IS_SERVICE_BIND) != bindParam.end() && + bindParam.at(PARAM_KEY_IS_SERVICE_BIND) == DM_VAL_TRUE) { + CHECK_NULL_RETURN(listener_, ERR_DM_FAILED); + return listener_->OpenAuthSessionWithPara(std::stoll(deviceId)); + } bool hmlEnable160M = false; int32_t hmlActionId = 0; int invalidSessionId = -1; @@ -1778,6 +1786,10 @@ int32_t DeviceManagerServiceImpl::ParseConnectAddr(const PeerTargetId &targetId, LOGE("GetDeviceInfo failed, ret: %{public}d", ret); } deviceInfo->addrNum = static_cast(index); + if (bindParam.find(PARAM_KEY_IS_SERVICE_BIND) != bindParam.end() && + bindParam.at(PARAM_KEY_IS_SERVICE_BIND) == DM_VAL_TRUE) { + deviceId = std::to_string(targetId.serviceId); + } if (softbusConnector_->AddMemberToDiscoverMap(deviceId, deviceInfo) != DM_OK) { LOGE("DeviceManagerServiceImpl::ParseConnectAddr failed, AddMemberToDiscoverMap failed."); return ERR_DM_INPUT_PARA_INVALID; @@ -3200,6 +3212,85 @@ void DeviceManagerServiceImpl::DeleteSessionKey(int32_t userId, DeviceProfileConnector::GetInstance().DeleteSessionKey(userId, skId); } +int32_t DeviceManagerServiceImpl::BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam) +{ + if (pkgName.empty()) { + LOGE("BindServiceTarget failed, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + std::map bindParamTmp = bindParam; + bindParamTmp[PARAM_KEY_IS_SERVICE_BIND] = DM_VAL_TRUE; + return BindTarget(pkgName, targetId, bindParamTmp); +} + +int32_t DeviceManagerServiceImpl::UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) +{ + if (pkgName.empty()) { + LOGE("UnbindServiceTarget failed, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + // check sink or src and delete acl extra data + int32_t ret = DeleteAclExtraDataServiceId(serviceId); + if (ret != DM_OK) { + LOGE("UnbindServiceTarget failed, DeleteAclExtraDataServiceId failed."); + return ret; + } + + // delete dp service info profile + ServiceInfoProfile serviceInfoProfile; + int32_t userId = -1; + ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByServiceId(serviceId, serviceInfoProfile); + if (ret != DM_OK) { + LOGE("UnbindServiceTarget failed, GetServiceInfoProfileByServiceId failed."); + return ret; + } + DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(serviceInfoProfile.regServiceId, false, userId); + + return DM_OK; +} + +int32_t DeviceManagerServiceImpl::DeleteAclExtraDataServiceId(int64_t serviceId) +{ + bool isDeletedExtra = false; + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + std::string deviceIdLocal = std::string(localDeviceId); + std::vector profiles = + DeviceProfileConnector::GetInstance().GetAllAclIncludeLnnAcl(); + for (auto &item : profiles) { + std::string extraData = item.GetExtraData(); + if (extraData.empty()) { + continue; + } + JsonObject json; + json.Parse(extraData); + if (json.IsDiscarded()) { + continue; + } + if (IsInt64(json, TAG_SERVICE_ID)) { + int64_t aclServiceId = json[TAG_SERVICE_ID].Get(); + if (aclServiceId != serviceId) { + continue; + } + } + + std::string accesserUdid = item.GetAccesser().GetAccesserDeviceId(); + int32_t accesserUserId = item.GetAccesser().GetAccesserUserId(); + if (accesserUdid == deviceIdLocal) { + isDeletedExtra = true; + json.Erase(TAG_SERVICE_ID); + item.SetExtraData(json.Dump()); + DistributedDeviceProfile::DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(item); + } + } + if (!isDeletedExtra) { + LOGE("DeleteAclExtraDataServiceId failed, local is sink, not allow unbind."); + return ERR_DM_FAILED; + } + return DM_OK; +} + extern "C" IDeviceManagerServiceImpl *CreateDMServiceObject(void) { return new DeviceManagerServiceImpl; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 709e7301f..6a098bf3d 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -264,6 +264,7 @@ public: std::vector &networkIds); void ProcessSyncAccountLogout(const std::string &accountId, const std::string &peerUdid, int32_t userId); int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m); + int32_t OpenAuthSessionWithPara(int64_t serviceId); int32_t UnRegisterPinHolderCallback(const std::string &pkgName); void ProcessReceiveRspAppUninstall(const std::string &remoteUdid); void ProcessReceiveRspAppUnbind(const std::string &remoteUdid); @@ -275,6 +276,9 @@ public: bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); + int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam); + int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 216835016..693d77303 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -93,6 +93,7 @@ public: std::string GetLocalDisplayDeviceName() override; int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override; + int32_t OpenAuthSessionWithPara(int64_t serviceId) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 949542bed..3126d7fdc 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -286,6 +286,9 @@ public: const DmAccessCallee &callee, const std::string &sinkUdid) = 0; virtual void DeleteHoDevice(const std::string &peerUdid, const std::vector &foreGroundUserIds, const std::vector &backGroundUserIds) = 0; + virtual int32_t BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam) = 0; + virtual int32_t UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) = 0; }; using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 707429bb2..8ff506fd3 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -4176,6 +4176,15 @@ int32_t DeviceManagerService::OpenAuthSessionWithPara(const std::string &deviceI return dmServiceImplExtResident_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); } +int32_t DeviceManagerService::OpenAuthSessionWithPara(int64_t serviceId) +{ + if (!IsDMServiceAdapterResidentLoad()) { + LOGE("failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->OpenAuthSessionWithPara(serviceId); +} + int32_t DeviceManagerService::UnRegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { @@ -4363,5 +4372,48 @@ void DeviceManagerService::HandleAccountLogoutEventCallback(const std::string &c MultipleUserConnector::GetCurrentDMAccountInfo()); } #endif + +int32_t DeviceManagerService::BindServiceTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam) +{ + LOGI("DeviceManagerService::BindServiceTarget"); + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGE("The caller does not have permission to call"); + return ERR_DM_NO_PERMISSION; + } + LOGI("Start for pkgName = %{public}s", pkgName.c_str()); + if (pkgName.empty() || pkgName == std::string(DM_PKG_NAME)) { + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("BindServiceTarget failed, DMServiceImpl instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + if (targetId.serviceId == 0) { + LOGE("Invalid parameter, service id is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + return dmServiceImpl_->BindServiceTarget(pkgName, targetId, bindParam); +} + +int32_t DeviceManagerService::UnbindServiceTarget(const std::string &pkgName, int64_t serviceId) +{ + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGE("The caller does not have permission to call"); + return ERR_DM_NO_PERMISSION; + } + LOGI("Start for pkgName = %{public}s", pkgName.c_str()); + if (pkgName.empty() || pkgName == std::string(DM_PKG_NAME)) { + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("UnbindServiceTarget failed, DMServiceImpl instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + return dmServiceImpl_->UnbindServiceTarget(pkgName, serviceId); +} + } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index bc47a6a81..8b3091915 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -1052,5 +1052,14 @@ int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(const std::string return ERR_DM_UNSUPPORTED_METHOD; #endif } + +int32_t DeviceManagerServiceListener::OpenAuthSessionWithPara(int64_t serviceId) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + return DeviceManagerService::GetInstance().OpenAuthSessionWithPara(serviceId); +#else + return ERR_DM_UNSUPPORTED_METHOD; +#endif +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index e8f908bca..9b39617dd 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -171,6 +171,7 @@ bool EncodePeerTargetId(const PeerTargetId &targetId, MessageParcel &parcel) bRet = (bRet && parcel.WriteString(targetId.bleMac)); bRet = (bRet && parcel.WriteString(targetId.wifiIp)); bRet = (bRet && parcel.WriteUint16(targetId.wifiPort)); + bRet = (bRet && parcel.WriteInt64(targetId.serviceId)); return bRet; } @@ -181,6 +182,7 @@ void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId) targetId.bleMac = parcel.ReadString(); targetId.wifiIp = parcel.ReadString(); targetId.wifiPort = parcel.ReadUint16(); + targetId.serviceId = parcel.ReadInt64(); } ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) @@ -2007,5 +2009,33 @@ ON_IPC_CMD(CHECK_SINK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) { return OnIpcCmd(CHECK_SINK_SAME_ACCOUNT, data, reply); } + +ON_IPC_CMD(BIND_SERVICE_TARGET, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + PeerTargetId targetId; + DecodePeerTargetId(data, targetId); + std::string bindParamStr = data.ReadString(); + std::map bindParam; + ParseMapFromJsonString(bindParamStr, bindParam); + int32_t result = DeviceManagerService::GetInstance().BindServiceTarget(pkgName, targetId, bindParam); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(UNBIND_SERVICE_TARGET, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int64_t serviceId = data.ReadInt64(); + int32_t result = DeviceManagerService::GetInstance().UnbindServiceTarget(pkgName, serviceId); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee