From f7cfc416bd27fe4bf1a948ca61e0e95b360c023d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Mon, 21 Jul 2025 11:45:38 +0800 Subject: [PATCH] service_code_3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../device_manager_ipc_interface_code.h | 6 + common/include/dm_constants.h | 6 + .../ipc/model/ipc_common_service_id_req.h | 40 ++ .../ipc/model/ipc_common_service_info_req.h | 40 ++ .../ipc/model/ipc_common_service_info_rsp.h | 58 +++ .../model/ipc_get_online_service_list_rsp.h | 41 ++ .../ipc_get_service_info_by_service_id_rsp.h | 41 ++ common/src/dm_constants.cpp | 6 + .../include/deviceprofile_connector.h | 17 + .../src/deviceprofile_connector.cpp | 180 ++++++++ .../native_cpp/include/device_manager.h | 7 + .../native_cpp/include/device_manager_impl.h | 7 + .../native_cpp/include/dm_device_info.h | 89 +++- .../native_cpp/src/device_manager_impl.cpp | 112 ++++- .../src/ipc/standard/ipc_cmd_parser.cpp | 216 ++++++++++ .../service/include/device_manager_service.h | 16 + .../service/src/device_manager_service.cpp | 215 ++++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 184 +++++++++ ...Test_dm_deviceprofile_connector_second.cpp | 43 ++ .../UTTest_device_manager_service_three.cpp | 384 ++++++++++++++++++ .../UTTest_device_manager_service_three.h | 8 + .../mock/device_manager_service_mock.cpp | 11 + .../mock/device_manager_service_mock.h | 8 +- .../mock/deviceprofile_connector_mock.cpp | 12 + .../mock/deviceprofile_connector_mock.h | 6 + ...distributed_device_profile_client_mock.cpp | 7 + .../distributed_device_profile_client_mock.h | 4 + 27 files changed, 1759 insertions(+), 5 deletions(-) create mode 100644 common/include/ipc/model/ipc_common_service_id_req.h create mode 100644 common/include/ipc/model/ipc_common_service_info_req.h create mode 100644 common/include/ipc/model/ipc_common_service_info_rsp.h create mode 100644 common/include/ipc/model/ipc_get_online_service_list_rsp.h create mode 100644 common/include/ipc/model/ipc_get_service_info_by_service_id_rsp.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 418684851..883cfe246 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -122,6 +122,12 @@ enum DMIpcCmdInterfaceCode { CHECK_SINK_ACCESS_CONTROL, CHECK_SRC_SAME_ACCOUNT, CHECK_SINK_SAME_ACCOUNT, + + GET_ONLINE_SERVICE_LIST, + GET_TRUSTED_SERVICE_LIST, + GET_SERVICE_INFO_BY_SERVICE_ID, + GET_CALLER_SERVICE_INFO, + // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 2505b96ba..09c64db96 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -174,6 +174,12 @@ DM_EXPORT extern const char* DM_BUSINESS_ID; DM_EXPORT extern const char* DM_RISK; DM_EXPORT extern const char* DM_SAFE; +DM_EXPORT extern const char* TAG_SERVICE_BIND; +DM_EXPORT extern const char* TAG_SERVICE_INFO; +DM_EXPORT extern const char* TAG_SERVICE_INFO_NUM; +DM_EXPORT extern const char* IS_BIND_SERVICE; +DM_EXPORT extern const char* SERVICE_ID; + // screen state enum ScreenState { DM_SCREEN_UNKNOWN = -1, diff --git a/common/include/ipc/model/ipc_common_service_id_req.h b/common/include/ipc/model/ipc_common_service_id_req.h new file mode 100644 index 000000000..f787a82f5 --- /dev/null +++ b/common/include/ipc/model/ipc_common_service_id_req.h @@ -0,0 +1,40 @@ +/* +* 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 compliancee 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 "AAS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +* See the License for the specific language governingpermissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_IPC_COMMON_SERVICE_ID_REQ_H +#define OHOS_DM_IPC_COMMON_SERVICE_ID_REQ_H +#include +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcCommonServiceIdReq : public IpcReq { + DECLARE_IPC_MODEL(IpcCommonServiceIdReq); +public: + int64_t GetServiceId() const + { + return serviceId_; + } + void SetServiceId(int64_t serviceId) + { + serviceId_ = serviceId; + } +private: + int64_t serviceId_; +}; +}// namespace DistributedHardware +}//namespace OHOS +#endif // OHOS_DM_IPC_COMMON_SERVICE_ID_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_common_service_info_req.h b/common/include/ipc/model/ipc_common_service_info_req.h new file mode 100644 index 000000000..70f5d10bc --- /dev/null +++ b/common/include/ipc/model/ipc_common_service_info_req.h @@ -0,0 +1,40 @@ +/* +* 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 compliancee 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 "AAS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +* See the License for the specific language governingpermissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_IPC_COMMON_SERVICE_INFO_REQ_H +#define OHOS_DM_IPC_COMMON_SERVICE_INFO_REQ_H +#include +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcCommonServiceInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcCommonServiceInfoReq); +public: + int64_t GetTokenId() const + { + return tokenId_; + } + void SetTokenId(int64_t tokenId) + { + tokenId_ = tokenId; + } +private: + int64_t tokenId_; +}; +}// namespace DistributedHardware +}//namespace OHOS +#endif // OHOS_DM_IPC_COMMON_SERVICE_INFO_REQ_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_common_service_info_rsp.h b/common/include/ipc/model/ipc_common_service_info_rsp.h new file mode 100644 index 000000000..a09be8b09 --- /dev/null +++ b/common/include/ipc/model/ipc_common_service_info_rsp.h @@ -0,0 +1,58 @@ +/* +* 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 compliancee 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 "AAS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +* See the License for the specific language governingpermissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_IPC_COMMON_SERVICE_INFO_RSP_H +#define OHOS_DM_IPC_COMMON_SERVICE_INFO_RSP_H +#include +#include "dm_device_info.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcCommonServiceInfoRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcCommonServiceInfoRsp); +public: + std::vector GetServiceInfos() const + { + return serviceInfoVec_; + } + void SetServiceInfos(std::vector &serviceInfoVec) + { + serviceInfoVec_ = serviceInfoVec; + } + int64_t GetTokenId() const + { + return tokenId_; + } + void SetTokenId(int64_t tokenId) + { + tokenId_ = tokenId; + } + void SetErrCode(int32_t errcode) + { + errcode_ = errcode; + } + int32_t GetErrCode() const + { + return errcode_; + } +private: + std::vector serviceInfoVec_; + int64_t tokenId_; + int32_t errcode_ = 0; +}; +}// namespace DistributedHardware +}//namespace OHOS +#endif // OHOS_DM_IPC_COMMON_SERVICE_INFO_RSP_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_get_online_service_list_rsp.h b/common/include/ipc/model/ipc_get_online_service_list_rsp.h new file mode 100644 index 000000000..78f07a565 --- /dev/null +++ b/common/include/ipc/model/ipc_get_online_service_list_rsp.h @@ -0,0 +1,41 @@ +/* +* 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 compliancee 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 "AAS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +* See the License for the specific language governingpermissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_IPC_GET_ONLINE_SERVICE_LIST_RSP_H +#define OHOS_DM_IPC_GET_ONLINE_SERVICE_LIST_RSP_H + +#include +#include "dm_device_info.h" +#include "ipc_rsp.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetOnlineServiceListRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetOnlineServiceListRsp); +public: + std::vector GetServiceInfoVec() const + { + return serviceInfoVec_; + } + void SetServiceInfoVec(std::vector &serviceInfoVec) + { + serviceInfoVec_ = serviceInfoVec; + } +private: + std::vector serviceInfoVec_; +}; +}//namespaceDistributedHardware +}//namespace OHOS +#endif // OHOS_OM_IPC_GET_TRUST_DEVICE_RSP_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_get_service_info_by_service_id_rsp.h b/common/include/ipc/model/ipc_get_service_info_by_service_id_rsp.h new file mode 100644 index 000000000..b302a72e9 --- /dev/null +++ b/common/include/ipc/model/ipc_get_service_info_by_service_id_rsp.h @@ -0,0 +1,41 @@ +/* +* 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 compliancee 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 "AAS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. +* See the License for the specific language governingpermissions and +* limitations under the License. +*/ + +#ifndef OHOS_DM_IPC_GET_SERVICE_SERVICE_INFO_BY_SERVICE_ID_RSP_H +#define OHOS_DM_IPC_GET_SERVICE_SERVICE_INFO_BY_SERVICE_ID_RSP_H + +#include +#include "dm_device_info.h" +#include "ipc_rsp.h" + +namespace OHOS{ +namespace DistributedHardware { +class IpcGetServiceInfoByServiceIdRsp : public IpcRsp{ + DECLARE_IPC_MODEL(IpcGetServiceInfoByServiceIdRsp); +public: + DmServiceInfo GetDmServiceInfo() const + { + return serviceInfo_; + } + void SetServiceInfo(DmServiceInfo &serviceInfo) + { + serviceInfo_ = serviceInfo; + } +private: + DmServiceInfo serviceInfo_; +}; +}// namespace DistributedHardware +}//namespace OHOS +#endif // OHOS_DM_IPC_GET_SERVICE_SERVICE_INFO_BY_SERVICE_ID_RSP_H \ No newline at end of file diff --git a/common/src/dm_constants.cpp b/common/src/dm_constants.cpp index 2a268e59e..da2dfa8ae 100644 --- a/common/src/dm_constants.cpp +++ b/common/src/dm_constants.cpp @@ -164,6 +164,12 @@ const char* DM_BUSINESS_ID = "business_id"; const char* DM_RISK = "risk"; const char* DM_SAFE = "safe"; +const char* TAG_SERVICE_BIND = "SERVICE_BIND"; +const char* TAG_SERVICE_INFO = "SERVICE_INFO"; +const char* TAG_SERVICE_INFO_NUM = "SERVICE_INFO_NUM"; +const char* IS_BIND_SERVICE = "isBindService"; +const char* SERVICE_ID = "serviceId"; + // errCode map const std::map MAP_ERROR_CODE = { { ERR_DM_TIME_OUT, 96929745 }, { ERR_DM_UNSUPPORTED_AUTH_TYPE, 96929760 }, { ERR_DM_AUTH_BUSINESS_BUSY, 96929761 }, diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index b6e6df3ec..ed1584e68 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -262,6 +262,18 @@ public: DM_EXPORT void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); + DM_EXPORT int32_t GetAllServiceInfoProfileList(std::vector &dmServiceInfoProfiles); + DM_EXPORT int32_t GetServiceInfoProfileListByTokenId(const DmServiceInfoUniqueKey &key, + std::vector &serviceInfos); + DM_EXPORT int32_t GetServiceInfoProfileListByDeviceId(const std::string &deviceId, + std::vector &serviceInfos); + DM_EXPORT int32_t DeleteServiceInfoProfile(const DmServiceInfoUniqueKey& key); + DM_EXPORT void GetLocalTokenIdByDeviceIdAndUserId(std::string localUdid, std::string udid, + std::map &tokenToKey); + DM_EXPORT int32_t GetServiceInfoByTokenId(DmServiceInfoUniqueKey key, + std::vector &serviceInfos); + + DM_EXPORT int32_t DeleteSessionKey(int32_t userId, int32_t sessionKeyId); DM_EXPORT int32_t GetSessionKey(int32_t userId, int32_t sessionKeyId, std::vector &sessionKeyArray); @@ -427,6 +439,11 @@ private: const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); bool CheckExtWhiteList(const std::string &bundleName); + + // void TransferDpToDmServiceInfoProfile(const DmServiceInfoProfile &dmServiceInfoProfile, + // DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile); + // void TransferDpToDmServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile, + // DMServiceInfoProfile &dmServiceInfoProfile); }; extern "C" IDeviceProfileConnector *CreateDpConnectorInstance(); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 132a0a795..3fe0de948 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -592,6 +592,56 @@ void DeviceProfileConnector::FilterNeedDeleteACLInfos( } } +// void DeviceProfileConnector::TransferDpToDmServiceInfoProfile(const DmServiceInfoProfile &dmServiceInfoProfile, +// DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile) +// { +// dpServiceInfoProfile.SetDeviceId(dmServiceInfoProfile.deviceId); +// dpServiceInfoProfile.SetuserId(dmServiceInfoProfile.userId); +// dpServiceInfoProfile.SetNetworkId(dmServiceInfoProfile.networkId); +// dpServiceInfoProfile.SetTokenId(dmServiceInfoProfile.tokenId); +// dpServiceInfoProfile.SetServiceId(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceId); +// dpServiceInfoProfile.SetServiceName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceName); +// dpServiceInfoProfile.SetServiceDisplayName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceDisplayName); +// dpServiceInfoProfile.SetCustomData(dmServiceInfoProfile.serviceRegInfo.serviceInfo.customData); +// dpServiceInfoProfile.SetCustomDataLen(dmServiceInfoProfile.serviceRegInfo.serviceInfo.dataLen); +// dpServiceInfoProfile.SetBundleName(dmServiceInfoProfile.serviceRegInfo.serviceInfo.bundleName); +// dpServiceInfoProfile.SetModuleName (dmServiceInfoProfile.serviceRegInfo.serviceInfo.moduleName); +// dpServiceInfoProfile.SetAbilityName(dmServiceInfoProfile.sserviceRegInfo.serviceInfo.abilityName); +// dpServiceInfoProfile.SetAuthBoxType(dmServiceInfoProfile.serviceRegInfo.authBoxType); +// dpServiceInfoProfile.SetAuthType(dmServiceInfoProfile.serviceRegInfo.authType); +// dpServiceInfoProfile.SetPinExchangeType (dmServiceInfoProfile.serviceRegInfo.pinExchangeType); +// dpServiceInfoProfile.SetPinCode(dmServiceInfoProfile.serviceRegInfo.pinCode); +// dpServiceInfoProfile.SetDescription(dmServiceInfoProfile.serviceRegInfo.description); +// dpServiceInfoProfile.SetServiceDicoveryScope(dmServiceInfoProfile.serviceRegInfo.serviceDiscoveryScope); +// dpServiceInfoProfile.SetExtraInfo(dmServiceInfoProfile.extraInfo); +// } + +// void DeviceProfileConnector::TransferDpToDmServiceInfoProfile( +// const DistributedDeviceProfile::ServiceInfoProfile &dpServiceInfoProfile, +// DMServiceInfoProfile &dmServiceInfoProfile) +// { +// dmServiceInfoProfile.deviceId = dpServiceInfoProfile.GetDeviceId(); +// dmServiceInfoProfile.userId = dpServiceInfoProfile.GetUserId(); +// dmServiceInfoProfile.networkId = dpServiceInfoProfile.GetNetworkId(); +// dmServiceInfoProfile.tokenId = dpServiceInfoProfile.GetTokenId(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceId = dpServiceInfoProfile.GetServiceId(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceType = dpServiceInfoProfile.GetServiceType(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceName = dpServiceInfoProfile.GetServiceName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.serviceDisplayName = dpServiceInfoProfile.GetServiceDisplayName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.customData = dpServiceInfoProfile.GetCustomData(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.dataLen = dpServiceInfoProfile.GetCustomDataLen(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.bundleName = dpServiceInfoProfile.GetBundleName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.moduleName = dpServiceInfoProfile.GetModuleName(); +// dmServiceInfoProfile.serviceRegInfo.serviceInfo.abilityName = dpServiceInfoProfile.GetAbilityName(); +// dmServiceInfoProfile.serviceRegInfo.authBoxType = dpServiceInfoProfile.GetAuthBoxType(); +// dmServiceInfoProfile.serviceReginfo.authType = dpServiceInfoProfile.GetAuthType(); +// dmServiceInfoProfile.serviceRegInfo.pinExchangeType= dpServiceInfoProfile.GetPinExchangeType(); +// dmServiceInfoProfile.serviceRegInfo.pinCode = dpServiceInfoProfile.GetPinCode(); +// dmServiceInfoProfile.serviceRegInfo.description = dpServiceInfoProfile.GetDescription(); +// dmServiceInfoProfile.serviceRegInfo.serviceDiscoveryScope = dpServiceInfoProfile.GetServieDicoveryScope(); +// dmServiceInfoProfile.extraInfo = dpServiceInfoProfile.GetExtraInfo(); +// } + DM_EXPORT std::vector DeviceProfileConnector::GetAccessControlProfile() { std::vector profiles; @@ -2716,6 +2766,136 @@ DM_EXPORT void DeviceProfileConnector::HandleDeviceUnBind(int32_t bindType, } } +DM_EXPORT int32_t DeviceProfileConnector::GetAllServiceInfoProfileList(std::vector &dmServiceInfoProfiles) +{ + // std::vector dpServiceInfoProfiles; + // int32_t ret = DistributedDeviceProfileClient::Getinstance().GetAllServiceInfoProfileList(dmServiceInfoProfiles); + // if (ret != DM_OK) { + // LOGE("failed: %{public}d",ret); + // return ret; + // } + // for (const auto &dpProfile : dpServiceInfoProfiles){ + // DmServiceInfoProfile dmProfile; + // TransferDpToDmServiceInfoProfile(dpProfile,dmProfile); + // dmServiceInfoProfiles.emplace_back(dmProfile); + // } + return DM_OK; +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId(const DmServiceInfoUniqueKey &key, + std::vector &serviceInfos) +{ + ServiceInfoUniqueKey dpKey; + dpKey.SetTokenId(key.tokenId); + dpKey.SetDeviceId(key.deviceId); + dpKey.SetUserId(key.userId); + std::vector dpServiceInfos; + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId(dpKey, + dpServiceInfos); + if (ret != DM_OK) { + LOGE("failed: %{public}d",ret); + return ret; + } + for (auto dpServiceInfoProfile : dpServiceInfos) { + DmServiceInfoProfile dmServiceInfoProfile; + //TransferDpToDmServiceInfoProfile(dpServiceInfoProfile,dmServiceInfoProfile); + serviceInfos.push_back(dmServiceInfoProfile); + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileListByDeviceId(const std::string &deviceId, + std::vector &serviceInfos) +{ + std::vector serviceInfoProfiles; + + if (GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.deviceId == deviceId) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DmServiceInfoUniqueKey& key) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey dpKey; + dpKey.SetDeviceId(key.deviceId); + dpKey.SetServiceId(key.serviceId); + dpKey.SetTokenId(key.tokenId); + dpKey.SetUserId(key.userId); + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile(dpKey); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +void DeviceProfileConnector::GetLocalTokenIdByDeviceIdAndUserId(std::string localUdid, std::string udid, + std::map &tokenToKey) +{ + int32_t userId = MultipleUserConnector::GetCurrentAccountUserID(); + std::vector profiles = GetAclProfileByDeviceIdAndUserId(localUdid, userId); + + uint64_t localToken; + uint64_t peerToken; + DmServiceInfoUniqueKey key = { 0 }; + key.deviceId = udid; + for (auto &item : profiles){ + if (item.GetStatus()!= ACTIVE) { + continue; + } + if (item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserDeviceId() == udid) { + localToken = static_cast(item.GetAccessee().GetAccesseeTokenId()); + peerToken = static_cast(item.GetAccesser().GetAccesserTokenId()); + key.tokenId = std::to_string(peerToken); + key.userId = item.GetAccesser().GetAccesserUserId(); + } + if (item.GetAccessee().GetAccesseeDeviceId() == udid && + item.GetAccesser().GetAccesserDeviceId() == localUdid) { + peerToken = static_cast(item.GetAccessee().GetAccesseeTokenId()); + localToken = static_cast(item.GetAccesser().GetAccesserTokenId()); + key.tokenId = std::to_string(peerToken); + key.userId = item.GetAccessee().GetAccesseeUserId(); + } + tokenToKey.insert(std::pair(std::to_string(localToken), key)); + } +} + +DM_EXPORT int32_t DeviceProfileConnector::GetServiceInfoByTokenId(DmServiceInfoUniqueKey key, + std::vector &serviceInfos) +{ + std::vector infos; + DistributedDeviceProfile::ServiceInfoUniqueKey keyIndex(key.deviceId, key.userId, key.tokenId, -1); + auto ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId(keyIndex, infos); + if (ret != 0) { + return ret; + } + DmServiceInfo serviceInfo; + for (auto info : infos) { + serviceInfo.serviceId = info.GetServiceId(); + serviceInfo.serviceType = info.GetServiceType(); + serviceInfo.serviceName = info.GetServiceName(); + serviceInfo.serviceDisplayName = info.GetServiceDisplayName(); + serviceInfo.customData = info.GetCustomData(); + serviceInfo.customDataLen = info.GetCustomDataLen(); + serviceInfo.bundleName = info.GetBundleName(); + serviceInfo.moduleName = info.GetModuleName(); + serviceInfo.abilityName = info.GetAbilityName(); + serviceInfos.push_back(serviceInfo); + } + return DM_OK; +} + DM_EXPORT int32_t DeviceProfileConnector::SubscribeDeviceProfileInited( sptr dpInitedCallback) { diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index da0db3936..6d74085df 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -653,6 +653,13 @@ 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 GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList) = 0; + virtual int32_t GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList) = 0; + virtual int32_t GetServiceInfoByServiceId(const int64_t serviceId, DmServiceInfo &serviceInfo) = 0; + virtual int32_t GetCallerServiceInfo(std::vector &serviceInfos) = 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..d79c4a794 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -440,6 +440,13 @@ public: virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) override; + virtual int32_t GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList) override; + virtual int32_t GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList) override; + virtual int32_t GetServiceInfoByServiceId(const int64_t serviceId, DmServiceInfo& serviceInfo) override; + virtual int32_t GetCallerServiceInfo(std::vector &serviceInfos) 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 67c3a32ae..d624a2675 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -30,6 +30,80 @@ namespace OHOS { namespace DistributedHardware { + +typedef struct DmServiceInfo { + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + uint32_t customDataLen = 0; + std::string bundleName; + std::string moduleName; + std::string abilityName; + //std::string extraInfo; +} DmServiceInfo; + +typedef struct ServiceRegInfo { + DmServiceInfo serviceInfo; + int32_t authBoxType = 0; + int32_t authType = 0; + int32_t pinExchangeType = 0; + std::string pinCode; + std::string description; + std::string serviceDiscoveryScope; +} ServiceRegInfo; + +typedef struct DmServiceInfoUniqueKey { + std::string deviceId; + int32_t userId = 0; + std::string tokenId; + int64_t serviceId = 0; +} DmServiceInfoUniqueKey; + +typedef struct DmServiceInfoProfile { + ServiceRegInfo serviceRegInfo; + std::string deviceId; + int32_t userId = 0; + std::string networkId; + std::string tokenId; + std::string extraInfo; +} DmServiceInfoProfile; + +typedef struct ServiceBindLocalInfo { + std::string localUdid; + int32_t userId = 0; + uint32_t tokenId = 0; +} ServiceBindLocalInfo; + +typedef struct DmServiceAddress{ + std::string bleMac; + uint32_t actionId = 0; +} DmServiceAddress; + +typedef struct DmServiceInfoDeviceProfile{ + std::string deviceId; + int32_t userId = 0; + std::string networkId; + std::string tokenId; + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + int32_t customDataLen = 0; + std::string bundleName; + std::string moduleName; + std::string abilityName; + int32_t authBoxType = 0; + int32_t authType = 0; + int32_t pinExchangeType = 0; + std::string pinCode; + std::string description; + std::string serviceDicoveryScope; + std::string extraInfo; +} DmServiceInfoDeviceProfile; + /** * @brief Device manager event notify. */ @@ -192,6 +266,9 @@ typedef struct DmDeviceInfo { * include json keys: "CONN_ADDR_TYPE", "BR_MAC_", "BLE_MAC", "WIFI_IP", "WIFI_PORT", "CUSTOM_DATA" */ std::string extraData; + + //std::vector serviceInfos; + std::map> tokenToServiceInfos; } DmDeviceInfo; /** @@ -292,11 +369,17 @@ typedef struct PeerTargetId { * wlan ip port. */ uint16_t wifiPort = 0; + /** + * service id. + */ + int64_t serviceId = 0; + 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 +389,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/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 0b2bfebae..dda3127df 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -26,8 +26,8 @@ #include "dm_random.h" #include "ipc_acl_profile_req.h" #include "ipc_authenticate_device_req.h" -#include "ipc_bind_device_req.h" #include "ipc_bind_target_req.h" +#include "ipc_bind_device_req.h" #include "ipc_check_access_control.h" #include "ipc_common_param_req.h" #include "ipc_create_pin_holder_req.h" @@ -68,6 +68,11 @@ #include "ipc_unbind_device_req.h" #include "ipc_unpublish_req.h" #include "securec.h" +#include "ipc_get_online_service_list_rsp.h" +#include "ipc_common_service_id_req.h" +#include "ipc_get_service_info_by_service_id_rsp.h" +#include "ipc_common_service_info_req.h" +#include "ipc_common_service_info_rsp.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "ipc_model_codec.h" #include "iservice_registry.h" @@ -2994,5 +2999,108 @@ bool DeviceManagerImpl::CheckAclByIpcCode(const DmAccessCaller &caller, const Dm anonyLocalUdid_); return result; } + +int32_t DeviceManagerImpl::GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerImpl::GetOnlineServiceList Start"); + std::string filterOptionsStr = ConvertMapToJsonString(filterOptions); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetFirstParam(filterOptionsStr); + int32_t ret = ipcClientProxy_->SendRequest(GET_ONLINE_SERVICE_LIST, req, rsp); + if (ret != DM_OK) { + LOGE("error:SendRequest failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("error:Failedwithret %{public}d", ret); + return ret; + } + serviceList = rsp->GetServiceInfoVec(); + LOGI("SQW client serviceList size=%{public}d", serviceList.size()); + for (auto serviceInfo : serviceList) { + // LOGI("SQW client serviceId = %{public}d, serviceDisplayName = %{public}s, serviceName = %{public}s, " + // "bundleName = %{public}s", serviceInfo.serviceId, serviceInfo.serviceDisplayName.c_str(), + // serviceInfo.serviceName.c_str(), serviceInfo.bundleName.c_str()); + } + return DM_OK; +} + +int32_t DeviceManagerImpl::GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerImpl::GetTrustedServiceList Start"); + std::string filterOptionsStr = ConvertMapToJsonString(filterOptions); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetFirstParam(filterOptionsStr); + int32_t ret = ipcClientProxy_->SendRequest(GET_TRUSTED_SERVICE_LIST, req, rsp); + if (ret != DM_OK) { + LOGE("error:Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("error:Failedwithret %{public}d", ret); + return ret; + } + serviceList = rsp->GetServiceInfoVec(); + LOGI("SQW client servicelist size=%{public}d", serviceList.size()); + for (auto serviceInfo : serviceList){ + // LOGI("SQW client serviceId = %{public}d, serviceDisplayName = %{public}s, serviceName = %{public}s,b" + // "undleName = %{public}s", serviceInfo.serviceId, serviceInfo.serviceDisplayName.c_str(), + // serviceInfo.serviceName.c_str(), serviceInfo.bundleName.c_str()); + } + return DM_OK; +} + +int32_t DeviceManagerImpl::GetServiceInfoByServiceId(const int64_t serviceId, DmServiceInfo& serviceInfo) +{ + LOGI("DeviceManagerImpl::GetServiceInfoByServiceId Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + //LOGI("SQW GetServiceInfoByServiceId serviceId = %{public}d", serviceId); + req->SetServiceId(serviceId); + //LOGI("SQW GetServiceInfoByServiceId serviceId = %{public}d", req->GetServiceId()); + int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICE_INFO_BY_SERVICE_ID, req, rsp); + if (ret != DM_OK) { + LOGE("error:Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("error:Failed with ret %{public}d", ret); + return ret; + } + serviceInfo = rsp->GetDmServiceInfo(); + return DM_OK; +} + +int32_t DeviceManagerImpl::GetCallerServiceInfo(std::vector &serviceInfos) +{ + LOGI("DeviceManagerImpl::GetCallerServiceInfo Start"); + + uint32_t tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + LOGI("Caller Token ID: %{public}s", GetAnonyInt32(tokenId).c_str()); + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + int32_t ret = ipcClientProxy_->SendRequest(GET_CALLER_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; + } + serviceInfos = rsp->GetServiceInfos(); + LOGI("Completed GetCallerServiceInfo, serviceInfos size: %{public}zu", serviceInfos.size()); + + return DM_OK; +} } // namespace DistributedHardware -} // namespace OHOS +} // 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 a30e5493b..9967f379f 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 @@ -70,6 +70,11 @@ #include "ipc_unpublish_req.h" #include "ipc_unauthenticate_device_req.h" #include "securec.h" +#include "ipc_get_online_service_list_rsp.h" +#include "ipc_common_service_id_req.h" +#include "ipc_get_service_info_by_service_id_rsp.h" +#include "ipc_common_service_info_rsp.h" +#include "ipc_common_service_info_req.h" namespace OHOS { class IRemoteObject; } namespace OHOS { @@ -103,6 +108,78 @@ int32_t ReadResponse(const DMIpcCmdInterfaceCode &ipcCode, MessageParcel &reply, return DM_OK; } +void DecodeDmServiceInfo(MessageParcel &parcel, DmServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = parcel.ReadInt64(); + serviceInfo.serviceType = parcel.ReadString(); + serviceInfo.serviceName = parcel.ReadString(); + serviceInfo.serviceDisplayName = parcel.ReadString(); + serviceInfo.customData = parcel.ReadString(); + serviceInfo.customDataLen = parcel.ReadUint32(); + serviceInfo.bundleName = parcel.ReadString(); + serviceInfo.moduleName = parcel.ReadString(); + serviceInfo.abilityName = parcel.ReadString(); +} + +void DecodeDmServiceInfo(std::map> &tokenToServiceInfos, + MessageParcel &parcel) +{ + int32_t mapSize = parcel.ReadInt32(); + if (mapSize == 0) { + return; + } + std::string token; + std::vector serviceInfos; + serviceInfos.reserve(10); + int32_t vectorSize; + int32_t dataLen; + int32_t i; + for(i = 0; i < mapSize; i++){ + serviceInfos.clear(); + token = parcel.ReadString(); + vectorSize = parcel.ReadInt32(); + dataLen = vectorSize * sizeof(DmServiceInfo); + DmServiceInfo *infoArray = static_cast(const_cast(parcel.ReadRawData(dataLen))); + if (infoArray != nullptr & memcpy_s(serviceInfos.data(),dataLen,infoArray,dataLen) != 0) { + LOGE("write serviceInfos failed"); + continue; + } + tokenToServiceInfos.emplace(token, serviceInfos); + } + return; +} + +void DecodeDmServiceInfoArray(std::map> &tokenToServiceInfos, + MessageParcel &parcel) +{ + int32_t mapSize = parcel.ReadInt32(); + if (mapSize == 0) { + return; + } + std::string token; + std::vector serviceInfos; + int32_t vectorSize; + int32_t dataLen; + int32_t i, j; + for (i = 0; i < mapSize; i++) { + serviceInfos.clear(); + token = parcel.ReadString(); + vectorSize = parcel.ReadInt32(); + LOGI("DmServiceInfo vector size:%{public}d", vectorSize); + dataLen = vectorSize * sizeof(DmServiceInfo); + DmServiceInfo *infoArray = static_cast(const_cast(parcel.ReadRawData(dataLen))); + if (infoArray == nullptr) { + LOGE("infoArray is nullptr"); + continue; + } + for (j = 0; j < vectorSize; j++) { + serviceInfos.push_back(infoArray[j]); + } + tokenToServiceInfos.emplace(token, serviceInfos); + } + return; +} + ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -2217,5 +2294,144 @@ ON_IPC_READ_RESPONSE(CHECK_SINK_SAME_ACCOUNT, MessageParcel &reply, std::shared_ { return ReadResponse(CHECK_SINK_SAME_ACCOUNT, reply, pBaseRsp); } + +ON_IPC_SET_REQUEST(GET_ONLINE_SERVICE_LIST, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseRegis null"); + return ERR_DM_FAILED; + } + std::shared_ptr pReq = + std::static_pointer_cast(pBaseReq); + LOGI("SQW first param=%{public}s", pReq->GetFirstParam().c_str()); + if (!data.WriteString(pReq->GetFirstParam())) { + LOGE("write filter options failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE (GET_ONLINE_SERVICE_LIST, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRspis null"); + return ERR_DM_FAILED; + } + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + int32_t serviceNum = reply.ReadInt32(); + std::vectorserviceInfoVec; + for (int32_t i = 0; i < serviceNum; i++) { + DmServiceInfo serviceInfo; + DecodeDmServiceInfo(reply, serviceInfo); + serviceInfoVec.emplace_back(serviceInfo); + // LOGI("SQW ON_IPC_READ_RESPONSE serviceld=%{publiic}ld, serviceDisplayName=%{public}s, serviceNambe + // =%{public}s, bundleName=%{public}s", serviceInfo.serviceId, + // serviceInfo.serviceDisplayName.c_str(), serviceInfo.serviceName.c_str(), serviceInfo.bundleN + // ame.c_str()); + } + pRsp->SetServiceInfoVec(serviceInfoVec); + pRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; + +} + +ON_IPC_SET_REQUEST(GET_TRUSTED_SERVICE_LIST, 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); + LOGI("SQW first param=%{public}s", pReq->GetFirstParam().c_str()); + if (!data.WriteString(pReq->GetFirstParam())) { + LOGE("write filter options failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_TRUSTED_SERVICE_LIST, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pRsp = + std::static_pointer_cast(pBaseRsp); + int32_t serviceNum = reply.ReadInt32(); + std::vector serviceInfoVec; + for (int32_t i = 0; i < serviceNum; i++) { + DmServiceInfo serviceInfo; + DecodeDmServiceInfo(reply, serviceInfo); + serviceInfoVec.emplace_back(serviceInfo); + //LOGI("SQW ON_IPC_READ_RESPONSE serviceld=%{public}ld,serviceDisplayName=%{public}s, serviceName + //=%{public}s, bundleName=%{public}s", serviceInfo.serviceId + // serviceInfo.serviceDisplayName.c_str(), serviceInfo.serviceName.c_str(), serviceInfo.bundleN + // ame.c_str()); + } + pRsp->SetServiceInfoVec(serviceInfoVec); + pRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_SERVICE_INFO_BY_SERVICE_ID, 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); + //LOGI("SQW GetServiceInfoByServiceId3 serviceld=%{public}ld",pReq->GetServiceId()); + if (!data.WriteInt64(pReq->GetServiceId())) { + LOGE("write filter options failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_SERVICE_INFO_BY_SERVICE_ID, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRspis null"); + return ERR_DM_FAILED; + } + LOGI("SQW back1"); + std::shared_ptr pRsp = + std::static_pointer_cast(pBaseRsp); + DmServiceInfo *serviceInfo = + static_cast(const_cast(reply.ReadRawData(sizeof(DmServiceInfo)))); + pRsp->SetServiceInfo(*serviceInfo); + pRsp->SetErrCode(reply.ReadInt32()); + LOGI("SQW back2"); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_CALLER_SERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +{ + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); + + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_CALLER_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + int32_t serviceNum = reply.ReadInt32(); + std::vector serviceInfoVec; + for (int32_t i = 0; i < serviceNum; i++) { + DmServiceInfo serviceInfo; + DecodeDmServiceInfo(reply, serviceInfo); + serviceInfoVec.emplace_back(serviceInfo); + } + pRsp->SetServiceInfos(serviceInfoVec); + pRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 069a2ad13..66d5af307 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -275,6 +275,22 @@ 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 GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList); + int32_t GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList); + int32_t GetServiceInfoByServiceId(const int64_t &serviceId, DmServiceInfo &dmServiceInfo); + + int32_t GetCallerServiceInfo(std::vector &serviceInfos); + + int32_t GetServiceInfosByTokenId(const int64_t &tokenId, + std::vector &serviceInfos); + +private: + int32_t GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo); + bool CheckIsDeviceOnline(const std::vector &onlineDeviceList, const std::string &peerUdid); + int32_t GetServiceInfoProfileByServiceId(const int64_t &serviceId, DmServiceInfoProfile &dmServiceInfoProfile); private: bool IsDMServiceImplReady(); bool IsDMImplSoLoaded(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f68075c02..f5ebcebc2 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -4638,5 +4638,220 @@ void DeviceManagerService::HandleAccountLogoutEventCallback(const std::string &c MultipleUserConnector::GetCurrentDMAccountInfo()); } #endif +int32_t DeviceManagerService::GetOnlineServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerService::GetOnlineServiceList Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + std::vector allTrustDeviceProfiles; + //std::vector allTrustDeviceProfiles = + // DeviceProfileConnector::GetInstance().GetAccessControProfileByUserId(localInfo.userId); + std::vector onlineDeviceList; + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); + ret = softbusListener_->GetTrustedDeviceList(onlineDeviceList); + if (ret != DM_OK) { + LOGE("GetTrustedDeviceList failed"); + return ret; + } + for (auto &profile : allTrustDeviceProfiles) { + DistributedDeviceProfile::Accesser accesser = profile.GetAccesser(); + DistributedDeviceProfile::Accessee accessee = profile.GetAccessee(); + std::string peerUdid = ""; + std::string peerTokenId = ""; + int32_t peerUserId = -1; + if (accesser.GetAccesserDeviceId() == localInfo.localUdid && + accesser.GetAccesserTokenId() == localInfo.tokenId) { + peerUdid = accessee.GetAccesseeDeviceId(); + peerTokenId = accessee.GetAccesseeTokenId(); + peerUserId = accessee.GetAccesseeUserId(); + } else if (accessee.GetAccesseeDeviceId() == localInfo.localUdid && accessee.GetAccesseeTokenId()== localInfo.tokenId) { + peerUdid = accesser.GetAccesserDeviceId(); + peerTokenId = accesser.GetAccesserTokenId(); + peerUserId = accesser.GetAccesserUserId(); + } + if (!CheckIsDeviceOnline(onlineDeviceList, peerUdid)) { + LOGE("DeviceManagerService::GetOnlineServiceList Device Is Offline"); + continue; + } + DmServiceInfoUniqueKey key; + key.tokenId = peerTokenId; + key.deviceId = peerUdid; + key.userId = peerUserId; + std::vector serviceInfoProfiles; + //DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + for (auto serviceInfoProfile : serviceInfoProfiles) { + serviceList.emplace_back(serviceInfoProfile.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetTrustedServiceList(const std::map &filterOptions, + std::vector &serviceList) +{ + LOGI("DeviceManagerService::GetTrustedServiceList Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + std::vector allTrustDeviceProfiles = + DeviceProfileConnector::GetInstance().GetAccessControlProfileByUserId(localInfo.userId); + + for (auto &profile : allTrustDeviceProfiles) { + DistributedDeviceProfile::Accesser accesser = profile.GetAccesser(); + DistributedDeviceProfile::Accessee accessee = profile.GetAccessee(); + std::string peerUdid = ""; + std::string peerTokenId = ""; + int32_t peerUserId = -1; + if (accesser.GetAccesserDeviceId() == localInfo.localUdid && + accesser.GetAccesserTokenId() == localInfo.tokenId) { + peerUdid = accessee.GetAccesseeDeviceId(); + peerTokenId = accessee.GetAccesseeTokenId(); + peerUserId = accessee.GetAccesseeUserId(); + } else if (accessee.GetAccesseeDeviceId() == localInfo.localUdid && + accessee.GetAccesseeTokenId() == localInfo.tokenId) { + peerUdid = accesser.GetAccesserDeviceId(); + peerTokenId = accesser.GetAccesserTokenId(); + peerUserId = accesser.GetAccesserUserId(); + } + DmServiceInfoUniqueKey key; + key.tokenId = peerTokenId; + key.deviceId = peerUdid; + key.userId = peerUserId; + std::vector serviceInfoProfiles; + //DeviceProfileConnector::Getinstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + for (auto serviceInfoProfile : serviceInfoProfiles) { + serviceList.emplace_back(serviceInfoProfile.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfoByServiceId(const int64_t &serviceId, DmServiceInfo &dmServiceInfo) +{ + LOGI("DeviceManagerService::GetServiceInfoByServiceId Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + DmServiceInfoUniqueKey serviceInfoUniqueKey; + serviceInfoUniqueKey.serviceId = serviceId; + serviceInfoUniqueKey.tokenId = std::to_string(localInfo.tokenId); + serviceInfoUniqueKey.userId = localInfo.userId; + serviceInfoUniqueKey.deviceId = localInfo.localUdid; + // LOGI("SQW GetServiceInfoByServiceId key serviceid=%{public}ld, tokenid=%{public}s, userid= + // %{public}d, deviceid=%{public}s", + // serviceInfoUniqueKey.serviceId, serviceInfoUniqueKey.tokenId.c_str(), serviceInfoUniqu + // eKey.userId, + // serviceInfoUniqueKey.deviceId.c_str()); + DmServiceInfoProfile dmServiceInfoProfile; + //ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(serviceInfoUniqueKey, + // dmServiceInfoProfile); + // LOGI("SQW GetServiceInfoByServiceId ret=%{public}d, ser"viceId=%{public}ld, service name=%{ + // public}s", + // ret, dmServiceInfoProfile.serviceRegInfo.servicelInfo.serviceId, dmServiceInfoProfile. + // erviceRegInfo.serviceInfo.serviceName.c_str()); + if (ret != DM_OK) { + return ret; + } + dmServiceInfo = dmServiceInfoProfile.serviceRegInfo.serviceInfo; + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfoProfileByServiceId(const int64_t &serviceId, + DmServiceInfoProfile &dmServiceInfoProfile) +{ + LOGI("DeviceManagerService::GetServiceInfoProfileByServiceId Start"); + ServiceBindLocalInfo localInfo; + int32_t ret = GetServiceBindLocalInfo(localInfo); + if (ret != DM_OK) { + return ret; + } + DmServiceInfoUniqueKey serviceInfoUniqueKey; + serviceInfoUniqueKey.serviceId = serviceId; + serviceInfoUniqueKey.tokenId = std::to_string(localInfo.tokenId); + serviceInfoUniqueKey.userId = localInfo.userId; + serviceInfoUniqueKey.deviceId = localInfo.localUdid; + + //ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(serviceInfoUniqueKey, + // dmServiceInfoProfile); + if (ret != DM_OK) { + return ret; + } + return DM_OK; +} + +int32_t DeviceManagerService::GetCallerServiceInfo(std::vector &serviceInfos) +{ + LOGI("DeviceManagerService::GetCallerServiceInfo Start"); + std::vector serviceInfoProfiles; + + int64_t tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == std::to_string(tokenId)) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo) +{ + DmDeviceInfo localDeviceInfo; + int32_t ret = GetLocalDeviceInfo(localDeviceInfo); + if (ret != DM_OK) { + LOGE("GetLocalDeviceInfo failed"); + return ret; + } + localInfo.localUdid = localDeviceInfo.deviceId; + localInfo.tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + MultipleUserConnector::GetCallerUserId(localInfo.userId); + + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfosByTokenId(const int64_t &tokenId, + std::vector &serviceInfos) +{ + std::vector serviceInfoProfiles; + + if (DeviceProfileConnector::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles)) { + return ERR_DM_FAILED; + } + if (serviceInfoProfiles.empty()) { + LOGE("GetServiceInfosByTokenId failed, serviceInfoProfiles is empty."); + return ERR_DM_FAILED; + } + for (auto const &item : serviceInfoProfiles) { + if (item.tokenId == std::to_string(tokenId)) { + serviceInfos.push_back(item.serviceRegInfo.serviceInfo); + } + } + return DM_OK; +} + +bool DeviceManagerService::CheckIsDeviceOnline(const std::vector &onlineDeviceList, const std::string &peerUdid) +{ + for (auto deviceInfo : onlineDeviceList) { + if (deviceInfo.deviceId == peerUdid) { + return true; + } + } + return false; +} } // 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..10b3c0bd8 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -46,6 +46,7 @@ #include "ipc_server_stub.h" #include "multiple_user_connector.h" #include "app_manager.h" + #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" #endif @@ -54,6 +55,86 @@ namespace DistributedHardware { const unsigned int XCOLLIE_TIMEOUT_S = 5; constexpr const char* SCENEBOARD_PROCESS = "com.ohos.sceneboard"; +int32_t EncodeDmServiceInfo(std::map> &tokenToServiceInfos, + MessageParcel &parcel) +{ + int32_t mapSize = tokenToServiceInfos.size(); + if (!parcel.WriteInt32(mapSize)) { + LOGE("write size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (mapSize == 0) { + return DM_OK; + } + for (auto it = tokenToServiceInfos.begin(); it != tokenToServiceInfos.end(); it++) { + if (!parcel.WriteString(it->first)) { + LOGE("write token failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + auto vectorSize = it->second.size(); + if (!parcel.WriteInt32(vectorSize)) { + LOGE("write vectorSize failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!parcel.WriteRawData(it->second.data(), sizeof(DmServiceInfo)*vectorSize)) { + LOGE("write serviceInfos failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + return DM_OK; +} + +bool EncodeDmServiceInfo(const DmServiceInfo &serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); + std::string serviceTypeStr(serviceInfo.serviceType); + bRet = (bRet && parcel.WriteString(serviceTypeStr)); + std::string serviceNameStr(serviceInfo.serviceName); + bRet = (bRet && parcel.WriteString(serviceNameStr)); + std::string serviceDisplayNameStr(serviceInfo.serviceDisplayName); + bRet = (bRet && parcel.WriteString(serviceDisplayNameStr)); + std::string customDataStr(serviceInfo.customData); + bRet = (bRet && parcel.WriteString(customDataStr)); + bRet = (bRet && parcel.WriteUint32(serviceInfo.customDataLen)); + std::string bundleNameStr(serviceInfo.bundleName); + bRet = (bRet && parcel.WriteString(bundleNameStr)); + std::string moduleNameStr(serviceInfo.moduleName); + bRet = (bRet && parcel.WriteString(moduleNameStr)); + std::string abilityNameStr(serviceInfo.abilityName); + bRet = (bRet && parcel.WriteString(abilityNameStr)); + return bRet; +} + +int32_t EncodeDmServiceInfoArray(std::map> &tokenToServiceInfos, + MessageParcel &parcel) +{ + int32_t mapSize = tokenToServiceInfos.size(); + if (!parcel.WriteInt32(mapSize)) { + LOGE("write size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (mapSize == 0) { + return DM_OK; + } + for (auto it = tokenToServiceInfos.begin(); it != tokenToServiceInfos.end(); it++) { + if (!parcel.WriteString(it->first)) { + LOGE("write token failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + auto vectorSize = it->second.size(); + if (!parcel.WriteInt32(vectorSize)) { + LOGE("write vectorSize failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!parcel.WriteRawData(it->second.data(), sizeof(DmServiceInfo) * vectorSize)) { + LOGE("write serviceInfos failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + return DM_OK; +} + void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller) { caller.accountId = parcel.ReadString(); @@ -171,6 +252,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 +263,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) @@ -191,6 +274,8 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, int32_t deviceState = pReq->GetDeviceState(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo(); + //std::map> tokenToServiceInfos = pReq->GetServiceInfos(); + std::map> tokenToServiceInfos = deviceInfo.tokenToServiceInfos; if (!data.WriteString(pkgName)) { LOGE("write pkgName failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -207,6 +292,10 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, LOGE("write dm device basic info failed"); return ERR_DM_IPC_WRITE_FAILED; } + if (EncodeDmServiceInfoArray(tokenToServiceInfos, data)) { + LOGE("write tokenToServiceInfos failed"); + return ERR_DM_IPC_WRITE_FAILED; + } return DM_OK; } @@ -258,6 +347,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, Me std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo(); + if (!data.WriteString(pkgName)) { LOGE("write pkgName failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -2007,5 +2097,99 @@ ON_IPC_CMD(CHECK_SINK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) { return OnIpcCmd(CHECK_SINK_SAME_ACCOUNT, data, reply); } + +ON_IPC_CMD(GET_ONLINE_SERVICE_LIST, MessageParcel &data, MessageParcel &reply) +{ + std::string filterOptionsStr = data.ReadString(); + std::map filterOptions; + ParseMapFromJsonString(filterOptionsStr, filterOptions); + std::vector onlineServiceList; + int32_t result = DeviceManagerService::GetInstance().GetOnlineServiceList(filterOptions, onlineServiceList); + if (!reply.WriteInt32((int32_t)onlineServiceList.size())) { + LOGE("write service list size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + //LOGI("SQW service servicelist size=%{public}ld", onlineServiceList.size()); + for (auto serviceInfo : onlineServiceList) { + // LOGI("SQW service serviceld=%{public}ld, serviceDisplayName=%{public}s, serviceName=%{public} + // s,bundleName=%{public}s", serviceInfo.serviceId, + // serviceInfo.serviceDisplayName.c_str(), serviceInfo.serviceName.c_str(), serviceInfo.bund + // leName.c_str()); + } + for (const auto &serviceInfo : onlineServiceList) { + if (!EncodeDmServiceInfo(serviceInfo, reply)) { + LOGE("Write service info failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + if(!reply.WriteInt32(result)){ + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(GET_TRUSTED_SERVICE_LIST, MessageParcel &data, MessageParcel &reply) +{ + std::string filterOptionsStr = data.ReadString(); + std::map filterOptions; + ParseMapFromJsonString(filterOptionsStr, filterOptions); + std::vector trustedServiceList; + int32_t result = DeviceManagerService::GetInstance().GetTrustedServiceList(filterOptions, trustedServiceList); + if (!reply.WriteInt32((int32_t)trustedServiceList.size())) { + LOGE("write service list size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + for (const auto &serviceInfo : trustedServiceList) { + if (!EncodeDmServiceInfo(serviceInfo, reply)) { + LOGE("write service infofailed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(GET_SERVICE_INFO_BY_SERVICE_ID, MessageParcel &data, MessageParcel &reply) +{ + int64_t serviceId = data.ReadInt64(); + DmServiceInfo dmServiceInfo; + int32_t result = DeviceManagerService::GetInstance().GetServiceInfoByServiceId(serviceId, dmServiceInfo); + if (!reply.WriteRawData(&dmServiceInfo, sizeof(DmServiceInfo))) { + LOGE("Write service list size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(GET_CALLER_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + std::vector serviceInfoList; + int32_t result = DeviceManagerService::GetInstance().GetCallerServiceInfo(serviceInfoList); + + if (!reply.WriteInt32((int32_t)serviceInfoList.size())) { + LOGE("write service list size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + for (const auto &serviceInfo : serviceInfoList) { + if (!EncodeDmServiceInfo(serviceInfo, reply)) { + LOGE("write service info failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 632006963..8bcd535e6 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -1717,5 +1717,48 @@ HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_004, auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, localUdid, tokenId); EXPECT_TRUE(result.empty()); } + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByTokenId_001, testing::ext::TestSize.Level1) +{ + DmServiceInfoUniqueKey key = { "deviceId123", 1, "tokenId123", 456789 }; + std::vector serviceInfos; + std::vector dpServiceInfos = + { DistributedDeviceProfile::ServiceInfoProfile() }; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(testing::_, _)) + .WillOnce(DoAll(SetArgReferee<1>(dpServiceInfos), Return(DM_OK))); + + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(serviceInfos.size(), dpServiceInfos.size()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByTokenId_002, testing::ext::TestSize.Level1) +{ + DmServiceInfoUniqueKey key = { "deviceId123", 1, "tokenId123", 456789 }; + std::vector serviceInfos; + std::vector dpServiceInfos; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(testing::_, _)) + .WillOnce(DoAll(SetArgReferee<1>(dpServiceInfos), Return(ERR_DM_FAILED))); + + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfos); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByTokenId_003, testing::ext::TestSize.Level1) +{ + DmServiceInfoUniqueKey key = { "deviceId123", 1, "tokenId123", 456789 }; + std::vector serviceInfos; + std::vector dpServiceInfos; + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(testing::_, _)) + .WillOnce(DoAll(SetArgReferee<1>(dpServiceInfos), Return(DM_OK))); + + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_TRUE(serviceInfos.empty()); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_three.cpp b/test/unittest/UTTest_device_manager_service_three.cpp index 5ca56ab14..1bb7e63ba 100644 --- a/test/unittest/UTTest_device_manager_service_three.cpp +++ b/test/unittest/UTTest_device_manager_service_three.cpp @@ -64,6 +64,8 @@ void DeviceManagerServiceThreeTest::TearDown() Mock::VerifyAndClearExpectations(permissionManagerMock_.get()); Mock::VerifyAndClearExpectations(softbusListenerMock_.get()); Mock::VerifyAndClearExpectations(deviceManagerServiceImplMock_.get()); + Mock::VerifyAndClearExpectations(deviceProfileConnectorMock_.get()); + Mock::VerifyAndClearExpectations(ipcSkeletonMock_.get()); } void DeviceManagerServiceThreeTest::SetUpTestCase() @@ -72,6 +74,9 @@ void DeviceManagerServiceThreeTest::SetUpTestCase() DmPermissionManager::dmPermissionManager = permissionManagerMock_; DmSoftbusListener::dmSoftbusListener = softbusListenerMock_; DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = deviceManagerServiceImplMock_; + DmDeviceProfileConnector::dmDeviceProfileConnector = deviceProfileConnectorMock_; + DMIPCSkeleton::dmIpcSkeleton_ = ipcSkeletonMock_; + DmMultipleUserConnector::dmMultipleUserConnector = multipleUserConnectorMock_; } void DeviceManagerServiceThreeTest::TearDownTestCase() @@ -84,6 +89,12 @@ void DeviceManagerServiceThreeTest::TearDownTestCase() softbusListenerMock_ = nullptr; DmDeviceManagerServiceImpl::dmDeviceManagerServiceImpl = nullptr; deviceManagerServiceImplMock_ = nullptr; + DmDeviceProfileConnector::dmDeviceProfileConnector = nullptr; + deviceProfileConnectorMock_ = nullptr; + DMIPCSkeleton::dmIpcSkeleton_ = ipcSkeletonMock_; + ipcSkeletonMock_ = nullptr; + DmMultipleUserConnector::dmMultipleUserConnector = nullptr; + multipleUserConnectorMock_ = nullptr; } namespace { @@ -909,6 +920,379 @@ HWTEST_F(DeviceManagerServiceThreeTest, UnloadDMDeviceRiskDetect_301, testing::e DeviceManagerService::GetInstance().UnloadDMDeviceRiskDetect(); EXPECT_EQ(DeviceManagerService::GetInstance().dmDeviceRiskDetect_, nullptr); } + +HWTEST_F(DeviceManagerServiceThreeTest, GetOnlineServiceList_001, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_)).Times(0); + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetOnlineServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetOnlineServiceList_002, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 12345; + localInfo.userId = 1; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetOnlineServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetOnlineServiceList_003, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 12345; + localInfo.userId = 1; + + std::vector onlineDeviceList = { { "device1" }, { "device2" } }; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_)) + .WillOnce(DoAll(SetArgReferee<0>(onlineDeviceList), Return(DM_OK))); + EXPECT_CALL(*deviceManagerServiceMock_, CheckIsDeviceOnline(_, _)) + .WillRepeatedly(Return(false)); + + int32_t ret = DeviceManagerService::GetInstance().GetOnlineServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, DM_OK); + EXPECT_TRUE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetOnlineServiceList_004, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 12345; + localInfo.userId = 1; + + std::vector onlineDeviceList = { { "device1" }, { "device2" } }; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + EXPECT_CALL(*softbusListenerMock_, GetTrustedDeviceList(_)) + .WillOnce(DoAll(SetArgReferee<0>(onlineDeviceList), Return(DM_OK))); + EXPECT_CALL(*deviceManagerServiceMock_, CheckIsDeviceOnline(_, _)) + .WillRepeatedly(Return(true)); + + int32_t ret = DeviceManagerService::GetInstance().GetOnlineServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, DM_OK); + EXPECT_FALSE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetTrustedServiceList_001, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetTrustedServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetTrustedServiceList_002, testing::ext::TestSize.Level1) +{ + std::map filterOptions; + std::vector serviceList; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 12345; + localInfo.userId = 1; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAccessControlProfileByUserId(localInfo.userId)) + .WillOnce(Return(std::vector{})); + + int32_t ret = DeviceManagerService::GetInstance().GetTrustedServiceList(filterOptions, serviceList); + EXPECT_EQ(ret, DM_OK); + EXPECT_TRUE(serviceList.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfoByServiceId_001, testing::ext::TestSize.Level1) +{ + int64_t serviceId = 12345; + DmServiceInfo dmServiceInfo; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoByServiceId(serviceId, dmServiceInfo); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfoByServiceId_002, testing::ext::TestSize.Level1) +{ + int64_t serviceId = 12345; + DmServiceInfo dmServiceInfo; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 67890; + localInfo.userId = 1; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoByServiceId(serviceId, dmServiceInfo); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfoProfileByServiceId_001, testing::ext::TestSize.Level1) +{ + int64_t serviceId = 12345; + DmServiceInfoProfile dmServiceInfoProfile; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoProfileByServiceId(serviceId, dmServiceInfoProfile); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfoProfileByServiceId_002, testing::ext::TestSize.Level1) +{ + int64_t serviceId = 12345; + DmServiceInfoProfile dmServiceInfoProfile; + + ServiceBindLocalInfo localInfo; + localInfo.localUdid = "localUdid"; + localInfo.tokenId = 67890; + localInfo.userId = 1; + + EXPECT_CALL(*deviceManagerServiceMock_, GetServiceBindLocalInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localInfo), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoProfileByServiceId(serviceId, dmServiceInfoProfile); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetCallerServiceInfo_001, testing::ext::TestSize.Level1) +{ + std::vector serviceInfos; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfo(serviceInfos); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetCallerServiceInfo_002, testing::ext::TestSize.Level1) +{ + std::vector serviceInfos; + std::vector serviceInfoProfiles; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfo(serviceInfos); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetCallerServiceInfo_003, testing::ext::TestSize.Level1) +{ + std::vector serviceInfos; + std::vector serviceInfoProfiles = { + { .tokenId = "12345", .serviceRegInfo = { .serviceInfo = { .serviceId = 1 } } }, + { .tokenId = "67890", .serviceRegInfo = { .serviceInfo = { .serviceId = 2 } } } + }; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + EXPECT_CALL(*ipcSkeletonMock_, GetCallingTokenID()).WillOnce(Return(99999)); + + int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfo(serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetCallerServiceInfo_004, testing::ext::TestSize.Level1) +{ + std::vector serviceInfos; + std::vector serviceInfoProfiles = { + { .tokenId = "12345", .serviceRegInfo = { .serviceInfo = { .serviceId = 1 } } }, + { .tokenId = "67890", .serviceRegInfo = { .serviceInfo = { .serviceId = 2 } } } + }; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + EXPECT_CALL(*ipcSkeletonMock_, GetCallingTokenID()).WillOnce(Return(1001)); + + int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfo(serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(serviceInfos.size(), 1); + // EXPECT_EQ(serviceInfos[0].serviceId, 1); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceBindLocalInfo_001, testing::ext::TestSize.Level1) +{ + ServiceBindLocalInfo localInfo; + + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceBindLocalInfo(localInfo); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceBindLocalInfo_002, testing::ext::TestSize.Level1) +{ + ServiceBindLocalInfo localInfo; + DmDeviceInfo localDeviceInfo; + strncpy(localDeviceInfo.deviceId, "localDeviceId", sizeof(localDeviceInfo.deviceId) - 1); + localDeviceInfo.deviceId[sizeof(localDeviceInfo.deviceId) - 1] = '\0'; + + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localDeviceInfo), Return(DM_OK))); + EXPECT_CALL(*multipleUserConnectorMock_, GetCallerUserId(_)) + .WillOnce(SetArgReferee<0>(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceBindLocalInfo(localInfo); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceBindLocalInfo_003, testing::ext::TestSize.Level1) +{ + ServiceBindLocalInfo localInfo; + DmDeviceInfo localDeviceInfo; + strncpy(localDeviceInfo.deviceId, "localDeviceId", sizeof(localDeviceInfo.deviceId) - 1); + localDeviceInfo.deviceId[sizeof(localDeviceInfo.deviceId) - 1] = '\0'; + + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(localDeviceInfo), Return(DM_OK))); + EXPECT_CALL(*multipleUserConnectorMock_, GetCallerUserId(_)) + .WillOnce(SetArgReferee<0>(localInfo.userId)); + + + int32_t ret = DeviceManagerService::GetInstance().GetServiceBindLocalInfo(localInfo); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(localInfo.localUdid, "localDeviceId"); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfosByTokenId_001, testing::ext::TestSize.Level1) +{ + int64_t tokenId = 12345; + std::vector serviceInfos; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(Return(ERR_DM_FAILED)); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfosByTokenId(tokenId, serviceInfos); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfosByTokenId_002, testing::ext::TestSize.Level1) +{ + int64_t tokenId = 12345; + std::vector serviceInfos; + std::vector serviceInfoProfiles; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfosByTokenId(tokenId, serviceInfos); + EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfosByTokenId_003, testing::ext::TestSize.Level1) +{ + int64_t tokenId = 12345; + std::vector serviceInfos; + std::vector serviceInfoProfiles = { + { .tokenId = "67890", .serviceRegInfo = { .serviceInfo = { .serviceId = 1 } } }, + { .tokenId = "98765", .serviceRegInfo = { .serviceInfo = { .serviceId = 2 } } } + }; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfosByTokenId(tokenId, serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_TRUE(serviceInfos.empty()); +} + +HWTEST_F(DeviceManagerServiceThreeTest, GetServiceInfosByTokenId_004, testing::ext::TestSize.Level1) +{ + int64_t tokenId = 12345; + std::vector serviceInfos; + std::vector serviceInfoProfiles = { + { .tokenId = "12345", .serviceRegInfo = { .serviceInfo = { .serviceId = 1 } } }, + { .tokenId = "67890", .serviceRegInfo = { .serviceInfo = { .serviceId = 2 } } } + }; + + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllServiceInfoProfileList(_)) + .WillOnce(DoAll(SetArgReferee<0>(serviceInfoProfiles), Return(DM_OK))); + + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfosByTokenId(tokenId, serviceInfos); + EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(serviceInfos.size(), 1); + EXPECT_EQ(serviceInfos[0].serviceId, 1); +} + +HWTEST_F(DeviceManagerServiceThreeTest, CheckIsDeviceOnline_001, testing::ext::TestSize.Level1) +{ + std::vector onlineDeviceList = { + { .deviceId = "device1" }, + { .deviceId = "device2" } + }; + std::string peerUdid = "device1"; + + bool result = DeviceManagerService::GetInstance().CheckIsDeviceOnline(onlineDeviceList, peerUdid); + EXPECT_TRUE(result); +} + +HWTEST_F(DeviceManagerServiceThreeTest, CheckIsDeviceOnline_002, testing::ext::TestSize.Level1) +{ + std::vector onlineDeviceList = { + { .deviceId = "device1" }, + { .deviceId = "device2" } + }; + std::string peerUdid = "device3"; + + bool result = DeviceManagerService::GetInstance().CheckIsDeviceOnline(onlineDeviceList, peerUdid); + EXPECT_FALSE(result); +} + +HWTEST_F(DeviceManagerServiceThreeTest, CheckIsDeviceOnline_003, testing::ext::TestSize.Level1) +{ + std::vector onlineDeviceList; + std::string peerUdid = "device1"; + + bool result = DeviceManagerService::GetInstance().CheckIsDeviceOnline(onlineDeviceList, peerUdid); + EXPECT_FALSE(result); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_three.h b/test/unittest/UTTest_device_manager_service_three.h index 4f7c7666b..33d66979d 100644 --- a/test/unittest/UTTest_device_manager_service_three.h +++ b/test/unittest/UTTest_device_manager_service_three.h @@ -31,6 +31,9 @@ #include "softbus_listener_mock.h" #include "device_manager_service_mock.h" #include "device_manager_service_impl_mock.h" +#include "deviceprofile_connector_mock.h" +#include "dm_ipc_skeleton_mock.h" +#include "multiple_user_connector_mock.h" namespace OHOS { namespace DistributedHardware { @@ -49,6 +52,11 @@ public: std::make_shared(); static inline std::shared_ptr deviceManagerServiceImplMock_ = std::make_shared(); + static inline std::shared_ptr deviceProfileConnectorMock_ = + std::make_shared(); + static inline std::shared_ptr ipcSkeletonMock_ = std::make_shared(); + static inline std::shared_ptr multipleUserConnectorMock_ = + std::make_shared(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/device_manager_service_mock.cpp b/test/unittest/mock/device_manager_service_mock.cpp index a6db438a6..4d9d01a7f 100644 --- a/test/unittest/mock/device_manager_service_mock.cpp +++ b/test/unittest/mock/device_manager_service_mock.cpp @@ -39,5 +39,16 @@ bool DeviceManagerService::IsDMServiceAdapterSoLoaded() { return DmDeviceManagerService::dmDeviceManagerService->IsDMServiceAdapterSoLoaded(); } + +int32_t DeviceManagerService::GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo) +{ + return DmDeviceManagerService::dmDeviceManagerService->GetServiceBindLocalInfo(localInfo); +} + +bool DeviceManagerService::CheckIsDeviceOnline(const std::vector &onlineDeviceList, + const std::string &peerUdid) +{ + return DmDeviceManagerService::dmDeviceManagerService->CheckIsDeviceOnline(onlineDeviceList, peerUdid); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/device_manager_service_mock.h b/test/unittest/mock/device_manager_service_mock.h index 2d5230c0e..11754439b 100644 --- a/test/unittest/mock/device_manager_service_mock.h +++ b/test/unittest/mock/device_manager_service_mock.h @@ -29,7 +29,10 @@ public: virtual bool IsDMServiceImplReady() = 0; virtual int32_t GetTrustedDeviceList(const std::string &pkgName, std::vector &deviceList) = 0; virtual bool IsDMServiceAdapterResidentLoad() = 0; - virtual bool IsDMServiceAdapterSoLoaded() = 0;; + virtual bool IsDMServiceAdapterSoLoaded() = 0; + virtual int32_t GetServiceBindLocalInfo(ServiceBindLocalInfo &localInfo) = 0; + virtual bool CheckIsDeviceOnline(const std::vector &onlineDeviceList, + const std::string &peerUdid) = 0; public: static inline std::shared_ptr dmDeviceManagerService = nullptr; }; @@ -40,6 +43,9 @@ public: MOCK_METHOD(int32_t, GetTrustedDeviceList, (const std::string &, std::vector &)); MOCK_METHOD(bool, IsDMServiceAdapterResidentLoad, ()); MOCK_METHOD(bool, IsDMServiceAdapterSoLoaded, ()); + MOCK_METHOD(int32_t, GetServiceBindLocalInfo, (ServiceBindLocalInfo &localInfo)); + MOCK_METHOD(bool, CheckIsDeviceOnline, (const std::vector &onlineDeviceList, + const std::string &peerUdid)); }; } } diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 603e20b2a..e07878bbd 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -200,5 +200,17 @@ bool DeviceProfileConnector::IsLnnAcl(const DistributedDeviceProfile::AccessCont { return DmDeviceProfileConnector::dmDeviceProfileConnector->IsLnnAcl(profile); } + +std::vector DeviceProfileConnector::GetAccessControlProfileByUserId( + int32_t userId) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAccessControlProfileByUserId(userId); +} + +int32_t DeviceProfileConnector::GetAllServiceInfoProfileList( + std::vector &dmServiceInfoProfiles) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->GetAllServiceInfoProfileList(dmServiceInfoProfiles); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 17d9b9333..2de715078 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -75,6 +75,9 @@ public: virtual void CacheAcerAclId(const DistributedDeviceProfile::AccessControlProfile &profile, std::vector &aclInfos) = 0; virtual bool IsLnnAcl(const DistributedDeviceProfile::AccessControlProfile &profile) = 0; + virtual std::vector GetAccessControlProfileByUserId( + int32_t userId) = 0; + virtual int32_t GetAllServiceInfoProfileList(std::vector &dmServiceInfoProfiles) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -124,6 +127,9 @@ public: MOCK_METHOD(void, CacheAcerAclId, (const DistributedDeviceProfile::AccessControlProfile &profile, std::vector &aclInfos)); MOCK_METHOD(bool, IsLnnAcl, (const DistributedDeviceProfile::AccessControlProfile &profile)); + MOCK_METHOD(std::vector, GetAccessControlProfileByUserId, ( + int32_t userId)); + MOCK_METHOD(int32_t, GetAllServiceInfoProfileList, (std::vector &dmServiceInfoProfiles)); }; } } diff --git a/test/unittest/mock/distributed_device_profile_client_mock.cpp b/test/unittest/mock/distributed_device_profile_client_mock.cpp index c67eda3c1..a5338be0b 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.cpp +++ b/test/unittest/mock/distributed_device_profile_client_mock.cpp @@ -96,5 +96,12 @@ int32_t DistributedDeviceProfileClient::PutBusinessEvent(const DistributedDevice { return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->PutBusinessEvent(event); } + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByTokenId( + const ServiceInfoUniqueKey& key, std::vector& serviceInfoProfiles) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->GetServiceInfoProfileListByTokenId( + key, serviceInfoProfiles); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/distributed_device_profile_client_mock.h b/test/unittest/mock/distributed_device_profile_client_mock.h index 13495ff3a..3ad019094 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.h +++ b/test/unittest/mock/distributed_device_profile_client_mock.h @@ -42,6 +42,8 @@ public: int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) = 0; virtual int32_t GetBusinessEvent(BusinessEvent &event) = 0; virtual int32_t PutBusinessEvent(const DistributedDeviceProfile::BusinessEvent &event) = 0; + virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) = 0; public: static inline std::shared_ptr dpDistributedDeviceProfileClient = nullptr; }; @@ -62,6 +64,8 @@ public: MOCK_METHOD(int32_t, GetLocalServiceInfoByBundleAndPinType, (const std::string&, int32_t, LocalServiceInfo&)); MOCK_METHOD(int32_t, GetBusinessEvent, (BusinessEvent &event)); MOCK_METHOD(int32_t, PutBusinessEvent, (const DistributedDeviceProfile::BusinessEvent &event)); + MOCK_METHOD(int32_t, GetServiceInfoProfileListByTokenId, (const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles)); }; } } -- Gitee