From 9e5099fc73ad325adc97f50db3006ae12b8078dd Mon Sep 17 00:00:00 2001 From: guoyi Date: Sat, 13 Sep 2025 21:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E9=87=8D=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guoyi --- common/include/dm_error_type.h | 2 + .../include/deviceprofile_connector.h | 6 +- .../src/deviceprofile_connector.cpp | 94 ++++++++++++------- 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 0bca1de1b..c918838db 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -145,6 +145,8 @@ enum { ERR_DM_SOCKET_IN_USED = 969298356, ERR_DM_ANTI_DISTURB_MODE = 969298357, ERR_DM_SKIP_AUTHENTICATE = 969298358, + ERR_DM_SERVICE_INFO_NOT_EXIST = 969298360, + ERR_DM_SERVICE_HAS_BEEN_REGISTER = 969298361, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 5e94c6c84..9a1c125b6 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -23,6 +23,7 @@ #include "i_dp_inited_callback.h" #include "local_service_info.h" #include "parameter.h" +#include "service_info_profile_new.h" #include "trusted_device_info.h" #include "json_object.h" @@ -230,11 +231,12 @@ public: DM_EXPORT DmOfflineParam HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId); DM_EXPORT int32_t GetServiceInfoProfileByServiceId(int64_t serviceId, ServiceInfoProfile &serviceInfoProfile); + DM_EXPORT int32_t GetServiceInfoProfileByRegServiceId(int32_t regServiceId, ServiceInfoProfile &serviceInfoProfile); + DM_EXPORT int32_t GetServiceInfoProfileByTokenId(int64_t tokenId, std::vector &serviceInfos); DM_EXPORT int32_t PutServiceInfoProfile(const ServiceInfoProfile &serviceInfoProfile); DM_EXPORT int32_t DeleteServiceInfoProfile(int32_t regServiceId, int32_t userId); DM_EXPORT void GetRemoteTokenIds(const std::string &localUdid, const std::string &udid, std::vector &remoteTokenIds); - DM_EXPORT int32_t GetServiceInfoByTokenId(int64_t tokenId, ServiceInfoProfile &serviceInfo); DM_EXPORT std::vector GetAllAccessControlProfile(); DM_EXPORT std::vector GetAllAclIncludeLnnAcl(); @@ -440,6 +442,8 @@ private: const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); bool CheckExtWhiteList(const std::string &bundleName); + void ConverToDmServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfileNew &dpServiceInfo, + ServiceInfoProfile &dmServiceInfo); }; extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 61eb21de2..878478d7d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -2342,24 +2342,57 @@ DmOfflineParam DeviceProfileConnector::HandleServiceUnBindEvent(int32_t remoteUs DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileByServiceId(int64_t serviceId, ServiceInfoProfile &serviceInfoProfile) { - LOGI("GetServiceInfoProfileByServiceId start"); - ServiceInfoProfileNew serviceInfoProfileDp; + LOGI("start"); + ServiceInfoProfileNew dpServiceInfo; int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByServiceId( - serviceId, serviceInfoProfileDp); + serviceId, dpServiceInfo); + if (ret != DM_OK) { + LOGE("GetServiceInfoProfileByServiceId failed, result: %{public}d", ret); + if (ret == DP_NOT_FIND_DATA) { + ret = ERR_DM_SERVICE_INFO_NOT_EXIST; + } + return ret; + } + ConverToDmServiceInfoProfile(dpServiceInfo, serviceInfoProfile); + LOGI("success"); + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileByRegServiceId(int32_t regServiceId, + ServiceInfoProfile &serviceInfoProfile) +{ + LOGI("start"); + ServiceInfoProfileNew dpServiceInfo; + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByRegServiceId(regServiceId, + dpServiceInfo); if (ret != DM_OK) { LOGE("GetServiceInfoProfileByServiceId failed, result: %{public}d", ret); + if (ret == DP_NOT_FIND_DATA) { + ret = ERR_DM_SERVICE_INFO_NOT_EXIST; + } return ret; } - serviceInfoProfile.regServiceId = serviceInfoProfileDp.GetRegServiceId(); - serviceInfoProfile.deviceId = serviceInfoProfileDp.GetDeviceId(); - serviceInfoProfile.userId = serviceInfoProfileDp.GetUserId(); - serviceInfoProfile.tokenId = serviceInfoProfileDp.GetTokenId(); - serviceInfoProfile.publishState = serviceInfoProfileDp.GetSerPubState(); - serviceInfoProfile.serviceId = serviceInfoProfileDp.GetServiceId(); - serviceInfoProfile.serviceType = serviceInfoProfileDp.GetServiceType(); - serviceInfoProfile.serviceName = serviceInfoProfileDp.GetServiceName(); - serviceInfoProfile.serviceDisplayName = serviceInfoProfileDp.GetServiceDisplayName(); - LOGI("GetServiceInfoProfileByServiceId success"); + ConverToDmServiceInfoProfile(dpServiceInfo, serviceInfoProfile); + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileByTokenId(int64_t tokenId, + std::vector &serviceInfos) +{ + std::vector dpServiceInfos; + auto ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByTokenId(tokenId, dpServiceInfos); + if (ret != 0) { + LOGE("GetServiceInfoProfileByTokenId failed."); + if (ret == DP_NOT_FIND_DATA) { + ret = ERR_DM_SERVICE_INFO_NOT_EXIST; + } + return ret; + } + for (const auto &dpServiceInfo : dpServiceInfos) { + ServiceInfoProfile dmServiceInfo; + ConverToDmServiceInfoProfile(dpServiceInfo, dmServiceInfo); + serviceInfos.emplace_back(dmServiceInfo); + } return DM_OK; } @@ -3588,27 +3621,6 @@ DM_EXPORT void DeviceProfileConnector::GetRemoteTokenIds(const std::string &loca } } -DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoByTokenId(int64_t tokenId, - ServiceInfoProfile &serviceInfo) -{ - DistributedDeviceProfile::ServiceInfoProfileNew dpServiceInfo; - auto ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByTokenId(tokenId, dpServiceInfo); - if (ret != 0) { - LOGE("GetServiceInfoByTokenId GetServiceInfoProfileByTokenId failed."); - return ret; - } - serviceInfo.regServiceId = dpServiceInfo.GetRegServiceId(); - serviceInfo.deviceId = dpServiceInfo.GetDeviceId(); - serviceInfo.userId = dpServiceInfo.GetUserId(); - serviceInfo.tokenId = dpServiceInfo.GetTokenId(); - serviceInfo.publishState = dpServiceInfo.GetSerPubState(); - serviceInfo.serviceId = dpServiceInfo.GetServiceId(); - serviceInfo.serviceType = dpServiceInfo.GetServiceType(); - serviceInfo.serviceName = dpServiceInfo.GetServiceName(); - serviceInfo.serviceDisplayName = dpServiceInfo.GetServiceDisplayName(); - return DM_OK; -} - bool DeviceProfileConnector::CheckExtWhiteList(const std::string &pkgName) { LOGI("start pkgName %{public}s.", pkgName.c_str()); @@ -3659,6 +3671,20 @@ int32_t DeviceProfileConnector::GetAuthOnceUdids(std::unordered_set return DM_OK; } +void DeviceProfileConnector::ConverToDmServiceInfoProfile( + const ServiceInfoProfileNew &dpServiceInfo, ServiceInfoProfile &dmServiceInfo) +{ + dmServiceInfo.regServiceId = dpServiceInfo.GetRegServiceId(); + dmServiceInfo.deviceId = dpServiceInfo.GetDeviceId(); + dmServiceInfo.userId = dpServiceInfo.GetUserId(); + dmServiceInfo.tokenId = dpServiceInfo.GetTokenId(); + dmServiceInfo.publishState = dpServiceInfo.GetSerPubState(); + dmServiceInfo.serviceId = dpServiceInfo.GetServiceId(); + dmServiceInfo.serviceType = dpServiceInfo.GetServiceType(); + dmServiceInfo.serviceName = dpServiceInfo.GetServiceName(); + dmServiceInfo.serviceDisplayName = dpServiceInfo.GetServiceDisplayName(); +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); -- Gitee