From 95a2fb74f90f107b58e20f36a3030fd8ce08da17 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sun, 12 Jan 2025 16:25:28 +0800 Subject: [PATCH] register service info Signed-off-by: zhuzhihui7 Change-Id: Ib18831bd0bbc5b9bf7b0032ca5c6e6377a020179 --- .../device_manager_ipc_interface_code.h | 6 +- .../ipc/model/ipc_register_serviceinfo_req.h | 54 +++++++++ .../native_cpp/include/device_manager.h | 3 + .../include/device_manager_callback.h | 21 +++- .../native_cpp/include/device_manager_impl.h | 3 +- .../native_cpp/include/dm_device_info.h | 23 ++++ .../include/notify/device_manager_notify.h | 4 + .../native_cpp/src/device_manager_impl.cpp | 46 ++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 107 ++++++++++++++++++ .../src/notify/device_manager_notify.cpp | 79 +++++++++++++ .../dp_register_serviceinfo_callback.h | 37 ++++++ .../service/include/device_manager_service.h | 3 + .../service/src/device_manager_service.cpp | 18 +++ .../src/ipc/standard/ipc_cmd_parser.cpp | 43 +++++++ 14 files changed, 443 insertions(+), 4 deletions(-) create mode 100644 common/include/ipc/model/ipc_register_serviceinfo_req.h create mode 100644 services/implementation/include/dependency/deviceprofile/dp_register_serviceinfo_callback.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 80a875a0c..c4109798f 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -99,7 +99,11 @@ enum DMIpcCmdInterfaceCode { GET_ANONY_LOCAL_UDID, REG_AUTHENTICATION_TYPE, // Add ipc msg here - IPC_MSG_BUTT + IPC_MSG_BUTT, + REG_SERVICE_INFO, + REG_SERVICE_INFO_RESULT, + UNREG_SERVICE_INFO, + UNREG_SERVICE_INFO_RESULT }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_register_serviceinfo_req.h b/common/include/ipc/model/ipc_register_serviceinfo_req.h new file mode 100644 index 000000000..ef4badaf0 --- /dev/null +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.h @@ -0,0 +1,54 @@ +/* + * 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_REGISTER_SERVICE_INFO_REQ_H +#define OHOS_DM_IPC_REGISTER_SERVICE_INFO_REQ_H + +#include "ipc_req.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcRegServiceInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcRegServiceInfoReq); + +public: + const ServiceInfo &GetServiceInfo() const + { + return serviceInfo_; + } + + void SetServiceInfo(const ServiceInfo &info) + { + serviceInfo_ = info; + } + + bool GetIsRegister() const + { + return isRegister_; + } + + void SetIsRegister(bool isRegister) + { + isRegister_ = isRegister; + } + +private: + ServiceInfo serviceInfo_; + bool isRegister_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_REGISTER_SERVICE_INFO_REQ_H diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 5dc128a3c..01bd8d6d3 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -635,6 +635,9 @@ public: virtual int32_t UnRegisterSinkBindCallback(const std::string &pkgName) = 0; virtual int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) = 0; + + virtual int32_t RegisterServiceInfo(ServiceInfo& info, std::shared_ptr registerCallback) = 0; + virtual int32_t UnRegisterServiceInfo(ServiceInfo& info, std::shared_ptr registerCallback) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 61989ccf3..abebd96a3 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_CALLBACK_H -#define OHOS_DM_CALLBACK_H +#ifndef OHOS_DM_REGISTER_SERVICE_CALLBACK_H +#define OHOS_DM_REGISTER_SERVICE_CALLBACK_H #include #include @@ -156,6 +156,23 @@ public: } virtual void OnCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; }; + +class ResiterServiceInfoCallback { +public: + virtual void OnServiceRegistered(const ServiceInfo& info, int errorCode) + { + } + virtual void OnServiceRegistrationFailed(const ServiceInfo& info, int errorCode) + { + } + virtual void OnServiceUnregistered(const ServiceInfo& info, int errorCode) + { + } + virtual void OnServiceUnregistrationFailed(const ServiceInfo& info, int errorCode) + { + } +}; + } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CALLBACK_H 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 324f721b9..40a77fccc 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -409,7 +409,8 @@ public: void SyncCallbacksToService(std::map> &callbackMap); virtual int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) override; - + virtual int32_t RegisterServiceInfo(ServiceInfo& info, std::shared_ptr registerCallback) override; + virtual int32_t UnRegisterServiceInfo(ServiceInfo& info, std::shared_ptr registerCallback) override; private: DeviceManagerImpl() = default; ~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 00d087fcb..31a56f797 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -413,6 +413,29 @@ typedef struct DmNotifyKey { notifyUserId == other.notifyUserId && udid < other.udid); } } DmNotifyKey; + +typedef struct DMServiceInfo { + uint64_t serviceId; + std::string serviceType; + std::string serviceSubType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + std::string authDescription; + std::string serviceDiscoveryScope; + std::string authType; + std::string pinExchangeType; + std::string pinCode; +} ServiceInfo; + +//typedef struct ServiceInfoProfile { +// std::string udid; +// int32_t userId; +// uint64_t tokenId; +// ServiceInfo serviceInfo; +//}; + + } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index cf7be62ad..1f7bb8ebe 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -76,6 +76,7 @@ public: void UnRegisterCredentialAuthStatusCallback(const std::string &pkgName); void RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterSinkBindCallback(const std::string &pkgName); + int32_t RegisterUnregServiceInfoCallback(const std::string &pkgName, std::shared_ptr registerCallback) public: static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); @@ -129,6 +130,7 @@ public: std::shared_ptr GetDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId); void GetCallBack(std::map> &callbackMap); + void OnSinkUnregisterInfoResult(const std::string &pkgName, const ServiceInfo& servieInfo, const int32_t result); private: #if !defined(__LITEOS_M__) std::mutex lock_; @@ -148,6 +150,8 @@ private: std::map> deviceScreenStatusCallback_; std::map> credentialAuthStatusCallback_; std::map> sinkBindTargetCallback_; + std::map> registerServiceInfoCallback_; + std::mutex bindLock_; }; } // namespace DistributedHardware 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 3da3d1d08..48d3fff70 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -50,6 +50,7 @@ #include "ipc_notify_event_req.h" #include "ipc_permission_req.h" #include "ipc_publish_req.h" +#include "ipc_register_serviceinfo.h" #include "ipc_req.h" #include "ipc_rsp.h" #include "ipc_set_credential_req.h" @@ -2583,5 +2584,50 @@ int32_t DeviceManagerImpl::RegisterAuthenticationType(const std::string &pkgName LOGI("Completed"); return DM_OK; } + +int32_t DeviceManagerImpl::RegisterServiceInfo(const std::string &pkgName, ServiceInfo& info, std::shared_ptr registerCallback) +{ + LOGI("Start"); + DeviceManagerNotify::GetInstance().RegisterRegServiceInfoCallback(pkgName, callback); + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceInfo(info); + req->SetIsRegister(true); + int32_t ret = ipcClientProxy_->SendRequest(REG_SERVICE_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::UnRegisterServiceInfo(ServiceInfo& info, std::shared_ptr registerCallback) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceInfo(info); + req->SetIsRegister(false); + int32_t ret = ipcClientProxy_->SendRequest(REG_SERVICE_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + LOGI("Completed"); + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file 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 e5bbebb13..ede87c0d6 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 @@ -151,6 +151,40 @@ bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) return bRet; } +bool EncodeServiceInfo(const ServiceInfo& serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceSubType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); + bRet = (bRet && parcel.WriteString(serviceInfo.customData)); + bRet = (bRet && parcel.WriteString(serviceInfo.authDescription)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + bRet = (bRet && parcel.WriteString(serviceInfo.authType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + bRet = (bRet && parcel.WriteString(serviceInfo.accountId)); + return bRet; +} + +void DecodeServiceInfo(MessageParcel &parcel, ServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = parcel.ReadUint64(); + serviceInfo.serviceId = parcel.serviceType(); + serviceInfo.serviceId = parcel.serviceSubType(); + serviceInfo.serviceId = parcel.serviceName(); + serviceInfo.serviceId = parcel.serviceDisplayName(); + serviceInfo.serviceId = parcel.customData(); + serviceInfo.serviceId = parcel.authDescription(); + serviceInfo.serviceId = parcel.serviceDiscoveryScope(); + serviceInfo.serviceId = parcel.authType(); + serviceInfo.serviceId = parcel.pinExchangeType(); + serviceInfo.serviceId = parcel.pinCode(); + serviceInfo.serviceId = parcel.accountId(); +} + ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -2096,5 +2130,78 @@ ON_IPC_READ_RESPONSE(REG_AUTHENTICATION_TYPE, MessageParcel &reply, std::shared_ pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_SET_REQUEST(REG_SERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + const ServiceInfo& info = pReq->GetServiceInfo(); + if (!EncodeServiceInfo(info, data)) { + LOGE("EncodeServiceInfo failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(REG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_CMD(REG_SERVICE_INFO_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int32_t result = data.ReadInt32(); + ServiceInfo serviceInfo; + DecodeServiceInfo(data, serviceInfo); + DeviceManagerNotify::GetInstance().OnSinkRegisterInfoResult(pkgName, serviceInfo, result); + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_SET_REQUEST(UNREG_SERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + const ServiceInfo& info = pReq->GetServiceInfo(); + if (!EncodeServiceInfo(info, data)) { + LOGE("EncodeServiceInfo failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_CMD(UNREG_SERVICE_INFO_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int32_t result = data.ReadInt32(); + ServiceInfo serviceInfo; + DecodeServiceInfo(data, serviceInfo); + DeviceManagerNotify::GetInstance().OnSinkRegisterInfoResult(pkgName, serviceInfo, result); + reply.WriteInt32(DM_OK); + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index ad9113f72..2931ed887 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -1242,5 +1242,84 @@ void DeviceManagerNotify::GetCallBack(std::map registerCallback) +{ + LOGI("Start"); + if (pkgName.empty() || callback == nullptr) { + LOGE("Invalid parameter, pkgName is empty or callback is nullptr."); + return; + } + std::lock_guard autoLock(lock_); + registerServiceInfoCallback_[pkgName] = callback; +} + +void DeviceManagerNotify::OnSinkRegisterInfoResult(const std::string &pkgName, const ServiceInfo& servieInfo, const int32_t result) +{ + if (pkgName.empty()) { + LOGE("Invalid para, pkgName: %{public}s.", pkgName.c_str()); + return; + } + LOGI("DeviceManagerNotify::OnSinkRegisterInfoResult in, pkgName:%{public}s, result:%{public}d", pkgName.c_str(), result); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + if (registerServiceInfoCallback_.find(pkgName) == registerServiceInfoCallback_.end()) { + LOGE("error, sink bind callback not register."); + return; + } + tempCbk = registerServiceInfoCallback_[pkgName]; + } + if (tempCbk == nullptr) { + LOGE("error, registered serviceinfo callback is nullptr."); + return; + } + //todo: when remove callback + if (result == 0) { + tempCbk->OnServiceRegistered(servieInfo, result); + } else { + tempCbk->OnServiceRegistrationFailed(servieInfo, result); + } +} + +int32_t DeviceManagerNotify::RegisterUnregServiceInfoCallback(const std::string &pkgName, std::shared_ptr registerCallback) +{ + LOGI("Start"); + if (pkgName.empty() || callback == nullptr) { + LOGE("Invalid parameter, pkgName is empty or callback is nullptr."); + return; + } + std::lock_guard autoLock(lock_); + unregisterServiceInfoCallback_[pkgName] = callback; +} + +void DeviceManagerNotify::OnSinkUnregisterInfoResult(const std::string &pkgName, const ServiceInfo& servieInfo, const int32_t result) +{ + if (pkgName.empty()) { + LOGE("Invalid para, pkgName: %{public}s.", pkgName.c_str()); + return; + } + LOGI("DeviceManagerNotify::OnSinkRegisterInfoResult in, pkgName:%{public}s, result:%{public}d", pkgName.c_str(), result); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + if (unregisterServiceInfoCallback_.find(pkgName) == unregisterServiceInfoCallback_.end()) { + LOGE("error, sink bind callback not register."); + return; + } + tempCbk = unregisterServiceInfoCallback_[pkgName]; + } + if (tempCbk == nullptr) { + LOGE("error, registered serviceinfo callback is nullptr."); + return; + } + //todo: when remove callback + if (result == 0) { + tempCbk->OnServiceUnregistered(servieInfo, result); + } else { + tempCbk->OnServiceUnregistrationFailed(servieInfo, result); + } +} + } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/dependency/deviceprofile/dp_register_serviceinfo_callback.h b/services/implementation/include/dependency/deviceprofile/dp_register_serviceinfo_callback.h new file mode 100644 index 000000000..24978b220 --- /dev/null +++ b/services/implementation/include/dependency/deviceprofile/dp_register_serviceinfo_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 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_DP_INITED_LISTENER_H +#define OHOS_DP_INITED_LISTENER_H + +#include "dp_inited_callback_stub.h" +#include "dm_device_info.h" +#include "trusted_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class DpInitedCallback : public DistributedDeviceProfile::DpInitedCallbackStub { +public: + DpInitedCallback(); + ~DpInitedCallback(); + int32_t OnDpInited() override; +private: + void PutAllTrustedDevices(); + bool ConvertToTrustedDeviceInfo(const std::unordered_map &authFormMap, + const DmDeviceInfo &deviceInfo, DistributedDeviceProfile::TrustedDeviceInfo &trustedDeviceInfo); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DP_INITED_LISTENER_H \ No newline at end of file diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 0a20ee474..f27ac9107 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -183,6 +183,9 @@ public: int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &unbindParam); + int32_t RegisterServiceInfo(const std::string &pkgName, ServiceInfo& serviceInfo); + int32_t UnregisterServiceInfo(const std::string &pkgName, ServiceInfo& serviceInfo); + int32_t DpAclAdd(const std::string &udid); int32_t GetDeviceSecurityLevel(const std::string &pkgName, const std::string &networkId, int32_t &networkType); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index e8fa03cef..a0f89298d 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1489,6 +1489,24 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee return dmServiceImplExt_->UnbindTargetExt(pkgName, targetId, unbindParam); } +int32_t DeviceManagerService::RegisterServiceInfo(const std::string &pkgName, ServiceInfo& serviceInfo) +{ + ServiceInfoProfile profile; + profile.serviceInfo = serviceInfo; + profile.tokenId = IPCSkeleton::GetCallingTokenID(); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + profile.udid = localDeviceId; + profile.userId = IPCSkeleton::GetCallingUid(); + + +} + +int32_t DeviceManagerService::UnregisterServiceInfo(const std::string &pkgName, ServiceInfo& serviceInfo) +{ + +} + int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 3877ee4d7..426468d25 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -122,6 +122,22 @@ void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee) callee.extra = parcel.ReadString(); } +void DecodeServiceInfo(MessageParcel &parcel, ServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = parcel.ReadUint64(); + serviceInfo.serviceId = parcel.serviceType(); + serviceInfo.serviceId = parcel.serviceSubType(); + serviceInfo.serviceId = parcel.serviceName(); + serviceInfo.serviceId = parcel.serviceDisplayName(); + serviceInfo.serviceId = parcel.customData(); + serviceInfo.serviceId = parcel.authDescription(); + serviceInfo.serviceId = parcel.serviceDiscoveryScope(); + serviceInfo.serviceId = parcel.authType(); + serviceInfo.serviceId = parcel.pinExchangeType(); + serviceInfo.serviceId = parcel.pinCode(); + serviceInfo.serviceId = parcel.accountId(); +} + ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -1678,5 +1694,32 @@ ON_IPC_CMD(REG_AUTHENTICATION_TYPE, MessageParcel &data, MessageParcel &reply) } return DM_OK; } + +ON_IPC_CMD(REG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + SerivceInfo serviceInfo; + DecodeServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().RegisterServiceInfo(pkgName, serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + SerivceInfo serviceInfo; + DecodeServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().UnregisterServiceInfo(pkgName, serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee