From f06332ec549ad26b334bc50a54aa2c21ee5e9ae1 Mon Sep 17 00:00:00 2001 From: Sly <1298008151@qq.com> Date: Mon, 7 Apr 2025 18:01:48 +0800 Subject: [PATCH 1/5] temp Signed-off-by: Sly <1298008151@qq.com> Change-Id: I3c895d5336295606c86543b3fd2961d088b73047 --- .../native_cpp/IDeviceManagerClient.idl | 91 + .../include/device_manager_client_proxy.h | 299 ++ .../include/idevice_manager_client.h | 373 +++ .../src/device_manager_client_proxy.cpp | 2848 +++++++++++++++++ .../native_cpp/src/dm_device_profile_info.cpp | 93 + .../native_cpp/src/dm_publish_info.cpp | 49 + .../standard/device_manager_client_service.h | 317 ++ .../device_manager_client_service.cpp | 858 +++++ utils/include/dm_ipc_utils.h | 44 + utils/src/dm_ipc_utils.cpp | 183 ++ 10 files changed, 5155 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl create mode 100644 interfaces/inner_kits/native_cpp/include/device_manager_client_proxy.h create mode 100644 interfaces/inner_kits/native_cpp/include/idevice_manager_client.h create mode 100644 interfaces/inner_kits/native_cpp/src/device_manager_client_proxy.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp create mode 100644 services/service/include/ipc/standard/device_manager_client_service.h create mode 100644 services/service/src/ipc/standard/device_manager_client_service.cpp create mode 100644 utils/include/dm_ipc_utils.h create mode 100644 utils/src/dm_ipc_utils.cpp diff --git a/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl new file mode 100644 index 000000000..5a90e5c4b --- /dev/null +++ b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// import DeviceManagerType; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmDeviceInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.PeerTargetIdExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCallerExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCalleeExt; +sequenceable DmPublishInfo..OHOS.DistributedHardware.DmPublishInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceProfileInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DMServiceInfoExt; +interface OHOS.DistributedHardware.IDeviceManagerClient { + [ipccode 2] void GetTrustedDeviceList([in] String pkgName, [in] String extra, [in] boolean isRefresh, [out] List deviceListExt); + [ipccode 3] void GetLocalDeviceInfo([in] String pkgName, [out] DmDeviceInfoExt deviceInfoExt); + [ipccode 4] void GetUdidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String udid); + [ipccode 5] void GetUuidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String uuid); + [ipccode 6] void GetNetworkTypeByNetworkId([in] String pkgName,[in] String netWorkId, [out] int netWorkType); + [ipccode 7] void PublishDeviceDiscovery([in] String pkgName, [in] DmPublishInfoExt publishInfoExt); + [ipccode 8] void UnPublishDeviceDiscovery([in] String pkgName, [in] int publishId); + // AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo, const std::string &extra, std::shared_ptr callback) + [ipccode 9] void AuthenticateDevice([in] String pkgName, [in] int authType, [in] String deviceId, [in] String extra); + [ipccode 10] void UnAuthenticateDevice([in] String pkgName, [in] String netWorkId); + [ipccode 11] void StopAuthenticateDevice([in] String pkgName); + [ipccode 20] void CheckCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 21] void SetUserOperation([in] String pkgName, [in] int action, [in] String params); + // RequestCredential(const std::string &pkgName, const std::string &reqJsonStr, std::string &returnJsonStr) + // RequestCredential(const std::string &pkgName, std::string &returnJsonStr) + [ipccode 26] void RequestCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 27] void ImportCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 28] void DeleteCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 29] void RegisterCredentialCallback([in] String pkgName); + [ipccode 30] void UnRegisterCredentialCallback([in] String pkgName); + [ipccode 31] void NotifyEvent([in] String pkgName, [in] int eventId, [in] String event); + [ipccode 32] void GetDeviceInfo([in] String pkgName, [in] String networkId, [out] DmDeviceInfoExt deviceInfoExt); + [ipccode 33] void GetEncryptedUuidByNetworkId([in] String pkgName, [in] String networkId,[out] String uuid); + [ipccode 34] void GenerateEncryptedUuid([in] String pkgName, [in] String uuid, [in] String appId, [out] String encryptedUuid); + [ipccode 35] void BindDevice([in] String pkgName, [in] int bindType, [in] String deviceId, [in] String extra); + // UnBindDevice(const std::string &pkgName, const std::string &deviceId); + // UnBindDevice(const std::string &pkgName, const std::string &deviceId, const std::string &extra); + [ipccode 36] void UnBindDevice([in] String pkgName, [in] String deviceId, [in] String extra); + [ipccode 37] void RegisterUiStateCallback([in] String pkgName); + [ipccode 38] void UnRegisterUiStateCallback([in] String pkgName); + [ipccode 39] void ImportAuthCode([in] String pkgName, [in] String authCode); + [ipccode 40] void ExportAuthCode([out] String authCode); + [ipccode 41] void RegisterPinHolderCallback([in] String pkgName); + [ipccode 42] void CreatePinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinTypeInt, [in] String payload); + [ipccode 43] void DestroyPinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinType, [in] String payload); + [ipccode 49] void RegisterDiscoveryCallback([in] String pkgName, [in] Map discoverParam, [in] Map filterOptions); + [ipccode 50] void UnRegisterDiscoveryCallback([in] String pkgName); + [ipccode 51] void StartDiscovering([in] String pkgName, [in] Map discoverParam, [in] Map filterOptions); + [ipccode 52] void StopDiscovering([in] String pkgName, [in] Map discoverParam); + [ipccode 53] void StartAdvertising([in] String pkgName, [in] String adverParaStr); + [ipccode 54] void StopAdvertising([in] String pkgName, [in] String adverParaStr); + [ipccode 55] void BindTarget([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] String bindParam); + [ipccode 56] void UnbindTarget([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] String unbindParam); + [ipccode 59] void DpAclAdd([in] long accessControlId, [in] String udid, [in] int bindType); + [ipccode 60] void GetDeviceSecurityLevel([in] String pkgName, [in] String networkId,[out] int securityLevel); + [ipccode 61] boolean IsSameAccount([in] String netWorkId); + [ipccode 62] void CheckApiPermission([in] int permissionLevel); + [ipccode 63] boolean CheckAccessControl([in] DmAccessCallerExt callerExt, [in] DmAccessCalleeExt calleeExt); + [ipccode 64] boolean CheckIsSameAccount([in] DmAccessCallerExt callerExt, [in] DmAccessCalleeExt calleeExt); + [ipccode 65] void ShiftLNNGear([in] String pkgName); + [ipccode 66] void SetDnPolicy([in] String pkgName, [in] Map policy); + [ipccode 69] void GetDeviceScreenStatus([in] String pkgName, [in] String networkId, [out] int screenStatus); + [ipccode 70] void GetNetworkIdByUdid([in] String pkgName, [in] String udid, [out] String networkId); + [ipccode 73] void SyncCallbackToService([in] int dmCommonNotifyEvent, [in] String pkgName); + [ipccode 74] void GetAnonyLocalUdid([in] String pkgName, [out] String anonyUdid); + [ipccode 75] void RegisterAuthenticationType([in] String pkgName, [in] String authTypeStr); + [ipccode 80] void PutDeviceProfileInfoList([in] String pkgName, [in] List deviceProfileInfoListExt); + [ipccode 81] void GetLocalDisplayDeviceName([in] String pkgName, [in] int maxNameLength, [out] String displayName); + [ipccode 86] void GetAllTrustedDeviceList([in] String pkgName, [in] String extra, [out] List deviceListExt); + [ipccode 87] void RegisterLocalServiceInfo([in] DMLocalServiceInfo info); + [ipccode 88] void UnRegisterLocalServiceInfo([in] String bundleName, [in] int pinExchangeType); + [ipccode 89] void UpdateLocalServiceInfo([in] DMLocalServiceInfo info); + [ipccode 90] void GetLocalServiceInfoByBundleNameAndPinExchangeType([in] string bundleName,[in] int pinExchangeType,[out] DMLocalServiceInfo info); + [ipccode 91] void RestoreLocalDeivceName ([in] String pkgName); + [ipccode 92] void GetDeviceNetworkIdList([in] string pkgName,[in] NetworkIdQueryFilter queryFilter,[out] List netWorkId); + +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_client_proxy.h b/interfaces/inner_kits/native_cpp/include/device_manager_client_proxy.h new file mode 100644 index 000000000..a14066299 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/device_manager_client_proxy.h @@ -0,0 +1,299 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTEDHARDWARE_DEVICEMANAGERCLIENTPROXY_H +#define OHOS_DISTRIBUTEDHARDWARE_DEVICEMANAGERCLIENTPROXY_H + +#include +#include "idevice_manager_client.h" + +namespace OHOS { +namespace DistributedHardware { + +class DeviceManagerClientProxy : public IRemoteProxy { +public: + explicit DeviceManagerClientProxy( + const sptr& remote) + : IRemoteProxy(remote) + {} + + virtual ~DeviceManagerClientProxy() + {} + + ErrCode GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) override; + + ErrCode GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) override; + + ErrCode GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) override; + + ErrCode GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) override; + + ErrCode GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) override; + + ErrCode PublishDeviceDiscovery( + const std::string& pkgName, + const DmPublishInfoExt& publishInfoExt) override; + + ErrCode UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) override; + + ErrCode AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) override; + + ErrCode UnAuthenticateDevice( + const std::string& pkgName, + const std::string& netWorkId) override; + + ErrCode StopAuthenticateDevice( + const std::string& pkgName) override; + + ErrCode CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + ErrCode SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) override; + + ErrCode RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + ErrCode ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + ErrCode DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + ErrCode RegisterCredentialCallback( + const std::string& pkgName) override; + + ErrCode UnRegisterCredentialCallback( + const std::string& pkgName) override; + + ErrCode NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) override; + + ErrCode GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) override; + + ErrCode GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) override; + + ErrCode GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) override; + + ErrCode BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) override; + + ErrCode UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) override; + + ErrCode RegisterUiStateCallback( + const std::string& pkgName) override; + + ErrCode UnRegisterUiStateCallback( + const std::string& pkgName) override; + + ErrCode ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) override; + + ErrCode ExportAuthCode( + std::string& authCode) override; + + ErrCode RegisterPinHolderCallback( + const std::string& pkgName) override; + + ErrCode CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) override; + + ErrCode DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinType, + const std::string& payload) override; + + ErrCode RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + ErrCode UnRegisterDiscoveryCallback( + const std::string& pkgName) override; + + ErrCode StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + ErrCode StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) override; + + ErrCode StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + ErrCode StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + ErrCode BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) override; + + ErrCode UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) override; + + ErrCode DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) override; + + ErrCode GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) override; + + ErrCode IsSameAccount( + const std::string& netWorkId, + bool& funcResult) override; + + ErrCode CheckApiPermission( + int32_t permissionLevel) override; + + ErrCode CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + ErrCode CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + ErrCode ShiftLNNGear( + const std::string& pkgName) override; + + ErrCode SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) override; + + ErrCode GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) override; + + ErrCode GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& networkId) override; + + ErrCode SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) override; + + ErrCode GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) override; + + ErrCode RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) override; + + ErrCode PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) override; + + ErrCode GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) override; + + ErrCode GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) override; + + ErrCode RegisterServiceInfo( + const DMServiceInfoExt& info) override; + + ErrCode UnRegisterServiceInfo( + int64_t serviceId) override; + + ErrCode UpdateServiceInfo( + const DMServiceInfoExt& info) override; + + ErrCode GetServiceInfoByServiceId( + int64_t serviceId, + DMServiceInfoExt& serviceInfoExt) override; + + ErrCode GetCallerServiceInfos( + std::vector& serviceInfoExt) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTEDHARDWARE_DEVICEMANAGERCLIENTPROXY_H + diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h new file mode 100644 index 000000000..8c56d1953 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H +#define OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H + +#include +#include +#include +#include +#include +#include "dm_device_info.h" +#include "dm_device_profile_info.h" +#include "dm_publish_info.h" +#include "hilog/log.h" + +using OHOS::DistributedHardware::DmDeviceInfoExt; +using OHOS::DistributedHardware::PeerTargetIdExt; +using OHOS::DistributedHardware::DmAccessCallerExt; +using OHOS::DistributedHardware::DmAccessCalleeExt; +using OHOS::DistributedHardware::DmPublishInfoExt; +using OHOS::DistributedHardware::DmDeviceProfileInfoExt; +using OHOS::DistributedHardware::DMServiceInfoExt; + +namespace OHOS { +namespace DistributedHardware { + +enum class IDeviceManagerClientIpcCode { + COMMAND_GET_TRUSTED_DEVICE_LIST = 2, + COMMAND_GET_LOCAL_DEVICE_INFO = 3, + COMMAND_GET_UDID_BY_NETWORK_ID = 4, + COMMAND_GET_UUID_BY_NETWORK_ID = 5, + COMMAND_GET_NETWORK_TYPE_BY_NETWORK_ID = 6, + COMMAND_PUBLISH_DEVICE_DISCOVERY = 7, + COMMAND_UN_PUBLISH_DEVICE_DISCOVERY = 8, + COMMAND_AUTHENTICATE_DEVICE = 9, + COMMAND_UN_AUTHENTICATE_DEVICE = 10, + COMMAND_STOP_AUTHENTICATE_DEVICE = 11, + COMMAND_CHECK_CREDENTIAL = 20, + COMMAND_SET_USER_OPERATION = 21, + COMMAND_REQUEST_CREDENTIAL = 26, + COMMAND_IMPORT_CREDENTIAL = 27, + COMMAND_DELETE_CREDENTIAL = 28, + COMMAND_REGISTER_CREDENTIAL_CALLBACK = 29, + COMMAND_UN_REGISTER_CREDENTIAL_CALLBACK = 30, + COMMAND_NOTIFY_EVENT = 31, + COMMAND_GET_DEVICE_INFO = 32, + COMMAND_GET_ENCRYPTED_UUID_BY_NETWORK_ID = 33, + COMMAND_GENERATE_ENCRYPTED_UUID = 34, + COMMAND_BIND_DEVICE = 35, + COMMAND_UN_BIND_DEVICE = 36, + COMMAND_REGISTER_UI_STATE_CALLBACK = 37, + COMMAND_UN_REGISTER_UI_STATE_CALLBACK = 38, + COMMAND_IMPORT_AUTH_CODE = 39, + COMMAND_EXPORT_AUTH_CODE = 40, + COMMAND_REGISTER_PIN_HOLDER_CALLBACK = 41, + COMMAND_CREATE_PIN_HOLDER = 42, + COMMAND_DESTROY_PIN_HOLDER = 43, + COMMAND_REGISTER_DISCOVERY_CALLBACK = 49, + COMMAND_UN_REGISTER_DISCOVERY_CALLBACK = 50, + COMMAND_START_DISCOVERING = 51, + COMMAND_STOP_DISCOVERING = 52, + COMMAND_START_ADVERTISING = 53, + COMMAND_STOP_ADVERTISING = 54, + COMMAND_BIND_TARGET = 55, + COMMAND_UNBIND_TARGET = 56, + COMMAND_DP_ACL_ADD = 59, + COMMAND_GET_DEVICE_SECURITY_LEVEL = 60, + COMMAND_IS_SAME_ACCOUNT = 61, + COMMAND_CHECK_API_PERMISSION = 62, + COMMAND_CHECK_ACCESS_CONTROL = 63, + COMMAND_CHECK_IS_SAME_ACCOUNT = 64, + COMMAND_SHIFT_L_N_N_GEAR = 65, + COMMAND_SET_DN_POLICY = 66, + COMMAND_GET_DEVICE_SCREEN_STATUS = 69, + COMMAND_GET_NETWORK_ID_BY_UDID = 70, + COMMAND_SYNC_CALLBACK_TO_SERVICE = 73, + COMMAND_GET_ANONY_LOCAL_UDID = 74, + COMMAND_REGISTER_AUTHENTICATION_TYPE = 75, + COMMAND_PUT_DEVICE_PROFILE_INFO_LIST = 80, + COMMAND_GET_LOCAL_DISPLAY_DEVICE_NAME = 81, + COMMAND_GET_ALL_TRUSTED_DEVICE_LIST = 86, + COMMAND_REGISTER_SERVICE_INFO = 88, + COMMAND_UN_REGISTER_SERVICE_INFO = 89, + COMMAND_UPDATE_SERVICE_INFO = 90, + COMMAND_GET_SERVICE_INFO_BY_SERVICE_ID = 91, + COMMAND_GET_CALLER_SERVICE_INFOS = 92, +}; + +class IDeviceManagerClient : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedHardware.IDeviceManagerClient"); + + virtual ErrCode GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) = 0; + + virtual ErrCode GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) = 0; + + virtual ErrCode GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) = 0; + + virtual ErrCode GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) = 0; + + virtual ErrCode GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) = 0; + + virtual ErrCode PublishDeviceDiscovery( + const std::string& pkgName, + const DmPublishInfoExt& publishInfoExt) = 0; + + virtual ErrCode UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) = 0; + + virtual ErrCode AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) = 0; + + virtual ErrCode UnAuthenticateDevice( + const std::string& pkgName, + const std::string& netWorkId) = 0; + + virtual ErrCode StopAuthenticateDevice( + const std::string& pkgName) = 0; + + virtual ErrCode CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) = 0; + + virtual ErrCode SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) = 0; + + virtual ErrCode RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) = 0; + + virtual ErrCode ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) = 0; + + virtual ErrCode DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) = 0; + + virtual ErrCode RegisterCredentialCallback( + const std::string& pkgName) = 0; + + virtual ErrCode UnRegisterCredentialCallback( + const std::string& pkgName) = 0; + + virtual ErrCode NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) = 0; + + virtual ErrCode GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) = 0; + + virtual ErrCode GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) = 0; + + virtual ErrCode GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) = 0; + + virtual ErrCode BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) = 0; + + virtual ErrCode UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) = 0; + + virtual ErrCode RegisterUiStateCallback( + const std::string& pkgName) = 0; + + virtual ErrCode UnRegisterUiStateCallback( + const std::string& pkgName) = 0; + + virtual ErrCode ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) = 0; + + virtual ErrCode ExportAuthCode( + std::string& authCode) = 0; + + virtual ErrCode RegisterPinHolderCallback( + const std::string& pkgName) = 0; + + virtual ErrCode CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) = 0; + + virtual ErrCode DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinType, + const std::string& payload) = 0; + + virtual ErrCode RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) = 0; + + virtual ErrCode UnRegisterDiscoveryCallback( + const std::string& pkgName) = 0; + + virtual ErrCode StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) = 0; + + virtual ErrCode StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) = 0; + + virtual ErrCode StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) = 0; + + virtual ErrCode StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) = 0; + + virtual ErrCode BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) = 0; + + virtual ErrCode UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) = 0; + + virtual ErrCode DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) = 0; + + virtual ErrCode GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) = 0; + + virtual ErrCode IsSameAccount( + const std::string& netWorkId, + bool& funcResult) = 0; + + virtual ErrCode CheckApiPermission( + int32_t permissionLevel) = 0; + + virtual ErrCode CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) = 0; + + virtual ErrCode CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) = 0; + + virtual ErrCode ShiftLNNGear( + const std::string& pkgName) = 0; + + virtual ErrCode SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) = 0; + + virtual ErrCode GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) = 0; + + virtual ErrCode GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& networkId) = 0; + + virtual ErrCode SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) = 0; + + virtual ErrCode GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) = 0; + + virtual ErrCode RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) = 0; + + virtual ErrCode PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) = 0; + + virtual ErrCode GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) = 0; + + virtual ErrCode GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) = 0; + + virtual ErrCode RegisterServiceInfo( + const DMServiceInfoExt& info) = 0; + + virtual ErrCode UnRegisterServiceInfo( + int64_t serviceId) = 0; + + virtual ErrCode UpdateServiceInfo( + const DMServiceInfoExt& info) = 0; + + virtual ErrCode GetServiceInfoByServiceId( + int64_t serviceId, + DMServiceInfoExt& serviceInfoExt) = 0; + + virtual ErrCode GetCallerServiceInfos( + std::vector& serviceInfoExt) = 0; +protected: + static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD004111, "distributedhardware"}; + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int SET_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H + diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_client_proxy.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_client_proxy.cpp new file mode 100644 index 000000000..5fa564f37 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/device_manager_client_proxy.cpp @@ -0,0 +1,2848 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_client_proxy.h" +#include "hilog/log.h" +#include "hitrace_meter.h" + +using OHOS::HiviewDFX::HiLog; + +namespace OHOS { +namespace DistributedHardware { + +ErrCode DeviceManagerClientProxy::GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(extra))) { + HiLog::Error(LABEL, "Write [extra] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(isRefresh ? 1 : 0)) { + HiLog::Error(LABEL, "Write [isRefresh] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_TRUSTED_DEVICE_LIST), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_TRUSTED_DEVICE_LIST)); + return errCode; + } + + int32_t deviceListExtSize = reply.ReadInt32(); + if (deviceListExtSize > static_cast(VECTOR_MAX_SIZE)) { + HiLog::Error(LABEL, "The vector/array size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + for (int32_t i1 = 0; i1 < deviceListExtSize; ++i1) { + std::unique_ptr value1(reply.ReadParcelable()); + if (!value1) { + HiLog::Error(LABEL, "Read [DmDeviceInfoExt] failed!"); + return ERR_INVALID_DATA; + } + + deviceListExt.push_back(*value1); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_LOCAL_DEVICE_INFO), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_LOCAL_DEVICE_INFO)); + return errCode; + } + + std::unique_ptr deviceInfoExtInfo(reply.ReadParcelable()); + if (deviceInfoExtInfo != nullptr) { + deviceInfoExt = *deviceInfoExtInfo; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(netWorkId))) { + HiLog::Error(LABEL, "Write [netWorkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_UDID_BY_NETWORK_ID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_UDID_BY_NETWORK_ID)); + return errCode; + } + + udid = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(netWorkId))) { + HiLog::Error(LABEL, "Write [netWorkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_UUID_BY_NETWORK_ID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_UUID_BY_NETWORK_ID)); + return errCode; + } + + uuid = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(netWorkId))) { + HiLog::Error(LABEL, "Write [netWorkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_NETWORK_TYPE_BY_NETWORK_ID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_NETWORK_TYPE_BY_NETWORK_ID)); + return errCode; + } + + netWorkType = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::PublishDeviceDiscovery( + const std::string& pkgName, + const DmPublishInfoExt& publishInfoExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&publishInfoExt)) { + HiLog::Error(LABEL, "Write [publishInfoExt] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_PUBLISH_DEVICE_DISCOVERY), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_PUBLISH_DEVICE_DISCOVERY)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(publishId)) { + HiLog::Error(LABEL, "Write [publishId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_PUBLISH_DEVICE_DISCOVERY), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_PUBLISH_DEVICE_DISCOVERY)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(authType)) { + HiLog::Error(LABEL, "Write [authType] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(deviceId))) { + HiLog::Error(LABEL, "Write [deviceId] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(extra))) { + HiLog::Error(LABEL, "Write [extra] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_AUTHENTICATE_DEVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_AUTHENTICATE_DEVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnAuthenticateDevice( + const std::string& pkgName, + const std::string& netWorkId) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(netWorkId))) { + HiLog::Error(LABEL, "Write [netWorkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_AUTHENTICATE_DEVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_AUTHENTICATE_DEVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::StopAuthenticateDevice( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_AUTHENTICATE_DEVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_AUTHENTICATE_DEVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(reqJsonStr))) { + HiLog::Error(LABEL, "Write [reqJsonStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_CREDENTIAL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_CREDENTIAL)); + return errCode; + } + + returnJsonStr = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(action)) { + HiLog::Error(LABEL, "Write [action] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(params))) { + HiLog::Error(LABEL, "Write [params] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_SET_USER_OPERATION), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_SET_USER_OPERATION)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(reqJsonStr))) { + HiLog::Error(LABEL, "Write [reqJsonStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REQUEST_CREDENTIAL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REQUEST_CREDENTIAL)); + return errCode; + } + + returnJsonStr = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(reqJsonStr))) { + HiLog::Error(LABEL, "Write [reqJsonStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_IMPORT_CREDENTIAL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_IMPORT_CREDENTIAL)); + return errCode; + } + + returnJsonStr = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(reqJsonStr))) { + HiLog::Error(LABEL, "Write [reqJsonStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_DELETE_CREDENTIAL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_DELETE_CREDENTIAL)); + return errCode; + } + + returnJsonStr = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterCredentialCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_CREDENTIAL_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_CREDENTIAL_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnRegisterCredentialCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_CREDENTIAL_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_CREDENTIAL_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(eventId)) { + HiLog::Error(LABEL, "Write [eventId] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(event))) { + HiLog::Error(LABEL, "Write [event] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_NOTIFY_EVENT), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_NOTIFY_EVENT)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(networkId))) { + HiLog::Error(LABEL, "Write [networkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_INFO), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_INFO)); + return errCode; + } + + std::unique_ptr deviceInfoExtInfo(reply.ReadParcelable()); + if (deviceInfoExtInfo != nullptr) { + deviceInfoExt = *deviceInfoExtInfo; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(networkId))) { + HiLog::Error(LABEL, "Write [networkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ENCRYPTED_UUID_BY_NETWORK_ID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ENCRYPTED_UUID_BY_NETWORK_ID)); + return errCode; + } + + uuid = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(uuid))) { + HiLog::Error(LABEL, "Write [uuid] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(appId))) { + HiLog::Error(LABEL, "Write [appId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GENERATE_ENCRYPTED_UUID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GENERATE_ENCRYPTED_UUID)); + return errCode; + } + + encryptedUuid = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(bindType)) { + HiLog::Error(LABEL, "Write [bindType] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(deviceId))) { + HiLog::Error(LABEL, "Write [deviceId] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(extra))) { + HiLog::Error(LABEL, "Write [extra] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_BIND_DEVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_BIND_DEVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(deviceId))) { + HiLog::Error(LABEL, "Write [deviceId] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(extra))) { + HiLog::Error(LABEL, "Write [extra] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_BIND_DEVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_BIND_DEVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterUiStateCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_UI_STATE_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_UI_STATE_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnRegisterUiStateCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_UI_STATE_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_UI_STATE_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(authCode))) { + HiLog::Error(LABEL, "Write [authCode] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_IMPORT_AUTH_CODE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_IMPORT_AUTH_CODE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::ExportAuthCode( + std::string& authCode) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_EXPORT_AUTH_CODE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_EXPORT_AUTH_CODE)); + return errCode; + } + + authCode = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterPinHolderCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_PIN_HOLDER_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_PIN_HOLDER_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&targetIdExt)) { + HiLog::Error(LABEL, "Write [targetIdExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(pinTypeInt)) { + HiLog::Error(LABEL, "Write [pinTypeInt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(payload))) { + HiLog::Error(LABEL, "Write [payload] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_CREATE_PIN_HOLDER), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_CREATE_PIN_HOLDER)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinType, + const std::string& payload) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&targetIdExt)) { + HiLog::Error(LABEL, "Write [targetIdExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(pinType)) { + HiLog::Error(LABEL, "Write [pinType] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(payload))) { + HiLog::Error(LABEL, "Write [payload] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_DESTROY_PIN_HOLDER), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_DESTROY_PIN_HOLDER)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (discoverParam.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(discoverParam.size()); + for (auto it2 = discoverParam.begin(); it2 != discoverParam.end(); ++it2) { + if (!data.WriteString16(Str8ToStr16((it2->first)))) { + HiLog::Error(LABEL, "Write [(it2->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it2->second)))) { + HiLog::Error(LABEL, "Write [(it2->second)] failed!"); + return ERR_INVALID_DATA; + } + } + if (filterOptions.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(filterOptions.size()); + for (auto it3 = filterOptions.begin(); it3 != filterOptions.end(); ++it3) { + if (!data.WriteString16(Str8ToStr16((it3->first)))) { + HiLog::Error(LABEL, "Write [(it3->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it3->second)))) { + HiLog::Error(LABEL, "Write [(it3->second)] failed!"); + return ERR_INVALID_DATA; + } + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_DISCOVERY_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_DISCOVERY_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnRegisterDiscoveryCallback( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_DISCOVERY_CALLBACK), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_DISCOVERY_CALLBACK)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (discoverParam.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(discoverParam.size()); + for (auto it4 = discoverParam.begin(); it4 != discoverParam.end(); ++it4) { + if (!data.WriteString16(Str8ToStr16((it4->first)))) { + HiLog::Error(LABEL, "Write [(it4->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it4->second)))) { + HiLog::Error(LABEL, "Write [(it4->second)] failed!"); + return ERR_INVALID_DATA; + } + } + if (filterOptions.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(filterOptions.size()); + for (auto it5 = filterOptions.begin(); it5 != filterOptions.end(); ++it5) { + if (!data.WriteString16(Str8ToStr16((it5->first)))) { + HiLog::Error(LABEL, "Write [(it5->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it5->second)))) { + HiLog::Error(LABEL, "Write [(it5->second)] failed!"); + return ERR_INVALID_DATA; + } + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_START_DISCOVERING), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_START_DISCOVERING)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (discoverParam.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(discoverParam.size()); + for (auto it6 = discoverParam.begin(); it6 != discoverParam.end(); ++it6) { + if (!data.WriteString16(Str8ToStr16((it6->first)))) { + HiLog::Error(LABEL, "Write [(it6->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it6->second)))) { + HiLog::Error(LABEL, "Write [(it6->second)] failed!"); + return ERR_INVALID_DATA; + } + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_DISCOVERING), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_DISCOVERING)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(adverParaStr))) { + HiLog::Error(LABEL, "Write [adverParaStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_START_ADVERTISING), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_START_ADVERTISING)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(adverParaStr))) { + HiLog::Error(LABEL, "Write [adverParaStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_ADVERTISING), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_STOP_ADVERTISING)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&targetIdExt)) { + HiLog::Error(LABEL, "Write [targetIdExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(bindParam))) { + HiLog::Error(LABEL, "Write [bindParam] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_BIND_TARGET), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_BIND_TARGET)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&targetIdExt)) { + HiLog::Error(LABEL, "Write [targetIdExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(unbindParam))) { + HiLog::Error(LABEL, "Write [unbindParam] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UNBIND_TARGET), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UNBIND_TARGET)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(accessControlId)) { + HiLog::Error(LABEL, "Write [accessControlId] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(udid))) { + HiLog::Error(LABEL, "Write [udid] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(bindType)) { + HiLog::Error(LABEL, "Write [bindType] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_DP_ACL_ADD), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_DP_ACL_ADD)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(networkId))) { + HiLog::Error(LABEL, "Write [networkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_SECURITY_LEVEL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_SECURITY_LEVEL)); + return errCode; + } + + securityLevel = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::IsSameAccount( + const std::string& netWorkId, + bool& funcResult) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(netWorkId))) { + HiLog::Error(LABEL, "Write [netWorkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_IS_SAME_ACCOUNT), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_IS_SAME_ACCOUNT)); + return errCode; + } + + funcResult = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::CheckApiPermission( + int32_t permissionLevel) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(permissionLevel)) { + HiLog::Error(LABEL, "Write [permissionLevel] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_API_PERMISSION), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_API_PERMISSION)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&callerExt)) { + HiLog::Error(LABEL, "Write [callerExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&calleeExt)) { + HiLog::Error(LABEL, "Write [calleeExt] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_ACCESS_CONTROL), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_ACCESS_CONTROL)); + return errCode; + } + + funcResult = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&callerExt)) { + HiLog::Error(LABEL, "Write [callerExt] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteParcelable(&calleeExt)) { + HiLog::Error(LABEL, "Write [calleeExt] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_IS_SAME_ACCOUNT), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_CHECK_IS_SAME_ACCOUNT)); + return errCode; + } + + funcResult = reply.ReadInt32() == 1 ? true : false; + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::ShiftLNNGear( + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_SHIFT_L_N_N_GEAR), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_SHIFT_L_N_N_GEAR)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (policy.size() > static_cast(MAP_MAX_SIZE)) { + HiLog::Error(LABEL, "The map size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + + data.WriteInt32(policy.size()); + for (auto it7 = policy.begin(); it7 != policy.end(); ++it7) { + if (!data.WriteString16(Str8ToStr16((it7->first)))) { + HiLog::Error(LABEL, "Write [(it7->first)] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16((it7->second)))) { + HiLog::Error(LABEL, "Write [(it7->second)] failed!"); + return ERR_INVALID_DATA; + } + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_SET_DN_POLICY), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_SET_DN_POLICY)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(networkId))) { + HiLog::Error(LABEL, "Write [networkId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_SCREEN_STATUS), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_DEVICE_SCREEN_STATUS)); + return errCode; + } + + screenStatus = reply.ReadInt32(); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& networkId) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(udid))) { + HiLog::Error(LABEL, "Write [udid] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_NETWORK_ID_BY_UDID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_NETWORK_ID_BY_UDID)); + return errCode; + } + + networkId = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(dmCommonNotifyEvent)) { + HiLog::Error(LABEL, "Write [dmCommonNotifyEvent] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_SYNC_CALLBACK_TO_SERVICE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_SYNC_CALLBACK_TO_SERVICE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ANONY_LOCAL_UDID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ANONY_LOCAL_UDID)); + return errCode; + } + + anonyUdid = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(authTypeStr))) { + HiLog::Error(LABEL, "Write [authTypeStr] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_AUTHENTICATION_TYPE), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_AUTHENTICATION_TYPE)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (deviceProfileInfoListExt.size() > static_cast(VECTOR_MAX_SIZE)) { + HiLog::Error(LABEL, "The list size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + data.WriteInt32(deviceProfileInfoListExt.size()); + for (auto it8 = deviceProfileInfoListExt.begin(); it8 != deviceProfileInfoListExt.end(); ++it8) { + if (!data.WriteParcelable(&(*it8))) { + HiLog::Error(LABEL, "Write [(*it8)] failed!"); + return ERR_INVALID_DATA; + } + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_PUT_DEVICE_PROFILE_INFO_LIST), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_PUT_DEVICE_PROFILE_INFO_LIST)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteInt32(maxNameLength)) { + HiLog::Error(LABEL, "Write [maxNameLength] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_LOCAL_DISPLAY_DEVICE_NAME), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_LOCAL_DISPLAY_DEVICE_NAME)); + return errCode; + } + + displayName = Str16ToStr8(reply.ReadString16()); + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteString16(Str8ToStr16(pkgName))) { + HiLog::Error(LABEL, "Write [pkgName] failed!"); + return ERR_INVALID_DATA; + } + if (!data.WriteString16(Str8ToStr16(extra))) { + HiLog::Error(LABEL, "Write [extra] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ALL_TRUSTED_DEVICE_LIST), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_ALL_TRUSTED_DEVICE_LIST)); + return errCode; + } + + int32_t deviceListExtSize = reply.ReadInt32(); + if (deviceListExtSize > static_cast(VECTOR_MAX_SIZE)) { + HiLog::Error(LABEL, "The vector/array size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + for (int32_t i9 = 0; i9 < deviceListExtSize; ++i9) { + std::unique_ptr value9(reply.ReadParcelable()); + if (!value9) { + HiLog::Error(LABEL, "Read [DmDeviceInfoExt] failed!"); + return ERR_INVALID_DATA; + } + + deviceListExt.push_back(*value9); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::RegisterServiceInfo( + const DMServiceInfoExt& info) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&info)) { + HiLog::Error(LABEL, "Write [info] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_SERVICE_INFO), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_REGISTER_SERVICE_INFO)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UnRegisterServiceInfo( + int64_t serviceId) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(serviceId)) { + HiLog::Error(LABEL, "Write [serviceId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_SERVICE_INFO), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UN_REGISTER_SERVICE_INFO)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::UpdateServiceInfo( + const DMServiceInfoExt& info) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteParcelable(&info)) { + HiLog::Error(LABEL, "Write [info] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_UPDATE_SERVICE_INFO), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_UPDATE_SERVICE_INFO)); + return errCode; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetServiceInfoByServiceId( + int64_t serviceId, + DMServiceInfoExt& serviceInfoExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(serviceId)) { + HiLog::Error(LABEL, "Write [serviceId] failed!"); + return ERR_INVALID_DATA; + } + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_SERVICE_INFO_BY_SERVICE_ID), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_SERVICE_INFO_BY_SERVICE_ID)); + return errCode; + } + + std::unique_ptr serviceInfoExtInfo(reply.ReadParcelable()); + if (serviceInfoExtInfo != nullptr) { + serviceInfoExt = *serviceInfoExtInfo; + } + + return ERR_OK; +} + +ErrCode DeviceManagerClientProxy::GetCallerServiceInfos( + std::vector& serviceInfoExt) +{ + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_MANAGER, __PRETTY_FUNCTION__); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(GetDescriptor())) { + HiLog::Error(LABEL, "Write interface token failed!"); + return ERR_INVALID_VALUE; + } + + + sptr remote = Remote(); + if (!remote) { + HiLog::Error(LABEL, "Remote is nullptr!"); + return ERR_INVALID_DATA; + } + int32_t result = remote->SendRequest( + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_CALLER_SERVICE_INFOS), data, reply, option); + if (FAILED(result)) { + HiLog::Error(LABEL, "Send request failed!"); + return result; + } + + ErrCode errCode = reply.ReadInt32(); + if (FAILED(errCode)) { + HiLog::Error(LABEL, "Read result failed, code is: %{public}d.", + static_cast(IDeviceManagerClientIpcCode::COMMAND_GET_CALLER_SERVICE_INFOS)); + return errCode; + } + + int32_t serviceInfoExtSize = reply.ReadInt32(); + if (serviceInfoExtSize > static_cast(VECTOR_MAX_SIZE)) { + HiLog::Error(LABEL, "The vector/array size exceeds the security limit!"); + return ERR_INVALID_DATA; + } + for (int32_t i10 = 0; i10 < serviceInfoExtSize; ++i10) { + std::unique_ptr value10(reply.ReadParcelable()); + if (!value10) { + HiLog::Error(LABEL, "Read [DMServiceInfoExt] failed!"); + return ERR_INVALID_DATA; + } + + serviceInfoExt.push_back(*value10); + } + return ERR_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp new file mode 100644 index 000000000..48c300555 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include + #include + #include + + #include "dm_device_profile_info.h" + #include "dm_log.h" + + namespace OHOS { + namespace DistributedHardware { + bool DmDeviceProfileInfoExt::Marshalling(Parcel &parcel) const + { + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(deviceSn)); + bRet = (bRet && parcel.WriteString(mac)); + bRet = (bRet && parcel.WriteString(model)); + bRet = (bRet && parcel.WriteString(innerModel)); + bRet = (bRet && parcel.WriteString(deviceType)); + bRet = (bRet && parcel.WriteString(manufacturer)); + bRet = (bRet && parcel.WriteString(deviceName)); + bRet = (bRet && parcel.WriteString(productId)); + bRet = (bRet && parcel.WriteString(subProductId)); + bRet = (bRet && parcel.WriteString(sdkVersion)); + bRet = (bRet && parcel.WriteString(bleMac)); + bRet = (bRet && parcel.WriteString(brMac)); + bRet = (bRet && parcel.WriteString(sleMac)); + bRet = (bRet && parcel.WriteString(firmwareVersion)); + bRet = (bRet && parcel.WriteString(hardwareVersion)); + bRet = (bRet && parcel.WriteString(softwareVersion)); + bRet = (bRet && parcel.WriteInt32(protocolType)); + bRet = (bRet && parcel.WriteInt32(setupType)); + bRet = (bRet && parcel.WriteString(wiseDeviceId)); + bRet = (bRet && parcel.WriteString(wiseUserId)); + bRet = (bRet && parcel.WriteString(registerTime)); + bRet = (bRet && parcel.WriteString(modifyTime)); + bRet = (bRet && parcel.WriteString(shareTime)); + bRet = (bRet && parcel.WriteBool(isLocalDevice)); + + return bRet; + } + + DmDeviceProfileInfoExt *DmDeviceProfileInfoExt::Unmarshalling(Parcel &parcel) + { + DmDeviceProfileInfoExt *profileInfoExt = new (std::nothrow) DmDeviceProfileInfoExt(); + if (profileInfoExt == nullptr) { + LOGE("Create DmDeviceProfileInfoExt failed"); + return nullptr; + } + profileInfoExt->deviceId = parcel.ReadString(); + profileInfoExt->deviceSn = parcel.ReadString(); + profileInfoExt->mac = parcel.ReadString(); + profileInfoExt->model = parcel.ReadString(); + profileInfoExt->innerModel = parcel.ReadString(); + profileInfoExt->deviceType = parcel.ReadString(); + profileInfoExt->manufacturer = parcel.ReadString(); + profileInfoExt->deviceName = parcel.ReadString(); + profileInfoExt->productId = parcel.ReadString(); + profileInfoExt->subProductId = parcel.ReadString(); + profileInfoExt->sdkVersion = parcel.ReadString(); + profileInfoExt->bleMac = parcel.ReadString(); + profileInfoExt->brMac = parcel.ReadString(); + profileInfoExt->sleMac = parcel.ReadString(); + profileInfoExt->firmwareVersion = parcel.ReadString(); + profileInfoExt->hardwareVersion = parcel.ReadString(); + profileInfoExt->softwareVersion = parcel.ReadString(); + profileInfoExt->protocolType = parcel.ReadInt32(); + profileInfoExt->setupType = parcel.ReadInt32(); + profileInfoExt->wiseDeviceId = parcel.ReadString(); + profileInfoExt->wiseUserId = parcel.ReadString(); + profileInfoExt->registerTime = parcel.ReadString(); + profileInfoExt->modifyTime = parcel.ReadString(); + profileInfoExt->shareTime = parcel.ReadString(); + profileInfoExt->isLocalDevice = parcel.ReadBool(); + + return profileInfoExt; + } + } // namespace DistributedHardware + } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp new file mode 100644 index 000000000..080860862 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "dm_publish_info.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +bool DmPublishInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt32(publishId)); + bRet = (bRet && parcel.WriteInt32(mode)); + bRet = (bRet && parcel.WriteInt32(freq)); + bRet = (bRet && parcel.WriteBool(ranging)); + return bRet; +} + +DmPublishInfoExt *DmPublishInfoExt::Unmarshalling(Parcel &parcel) +{ + DmPublishInfoExt *publishInfo = new (std::nothrow) DmPublishInfoExt(); + if (publishInfo == nullptr) { + LOGE("Create DmPublishInfo failed"); + return nullptr; + } + publishInfo->publishId = parcel.ReadInt32(); + publishInfo->mode = static_cast(parcel.ReadInt32()); + publishInfo->freq = static_cast(parcel.ReadInt32()); + publishInfo->ranging = parcel.ReadBool(); + return publishInfo; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/service/include/ipc/standard/device_manager_client_service.h b/services/service/include/ipc/standard/device_manager_client_service.h new file mode 100644 index 000000000..965e1a745 --- /dev/null +++ b/services/service/include/ipc/standard/device_manager_client_service.h @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_DEVICE_MANAGER_SERVICE_H +#define OHOS_DM_IPC_DEVICE_MANAGER_SERVICE_H + +#include +#include +#include +#include +#include +#include +#include + +#include "ipc_remote_broker.h" +#include "ipc_req.h" +#include "ipc_rsp.h" +#include "iremote_stub.h" +#include "idevice_manager_client.h" +#include "dm_device_info.h" +#include "dm_single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; + +class AppDeathRecipient : public IRemoteObject::DeathRecipient { +public: + /** + * @tc.name: AppDeathRecipient::OnRemoteDied + * @tc.desc: OnRemoteDied function of the App DeathRecipient + * @tc.type: FUNC + */ + void OnRemoteDied(const wptr &remote) override; + AppDeathRecipient() = default; + ~AppDeathRecipient() override = default; +}; + +class DeviceManagerClientService : public DeviceManagerClientStub { + DM_DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerClientService); + // -------------------------------IPC Service Method-------------------------------- + virtual ErrCode GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) override; + + virtual ErrCode GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) override; + + virtual ErrCode GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) override; + + virtual ErrCode GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) override; + + virtual ErrCode GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) override; + + virtual ErrCode PublishDeviceDiscovery( + const std::string& pkgName, + const DmPublishInfoExt& publishInfoExt) override; + + virtual ErrCode UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) override; + + virtual ErrCode AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode UnAuthenticateDevice( + const std::string& pkgName, + const std::string &netWorkId) override; + + virtual ErrCode StopAuthenticateDevice( + const std::string& pkgName) override; + + virtual ErrCode CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) override; + + virtual ErrCode RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode RegisterCredentialCallback( + const std::string& pkgName) override; + + virtual ErrCode UnRegisterCredentialCallback( + const std::string& pkgName) override; + + virtual ErrCode NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) override; + + virtual ErrCode GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) override; + + virtual ErrCode GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) override; + + virtual ErrCode GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) override; + + virtual ErrCode BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode RegisterUiStateCallback( + const std::string& pkgName) override; + + virtual ErrCode UnRegisterUiStateCallback( + const std::string& pkgName) override; + + virtual ErrCode ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) override; + + virtual ErrCode ExportAuthCode( + std::string& authCode) override; + + virtual ErrCode RegisterPinHolderCallback( + const std::string& pkgName) override; + + virtual ErrCode CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) override; + + virtual ErrCode DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinType, + const std::string& payload) override; + + virtual ErrCode RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + virtual ErrCode UnRegisterDiscoveryCallback( + const std::string& pkgName) override; + + virtual ErrCode StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + virtual ErrCode StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) override; + + virtual ErrCode StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + virtual ErrCode StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + virtual ErrCode BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) override; + + virtual ErrCode UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) override; + + virtual ErrCode DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) override; + + virtual ErrCode GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) override; + + virtual ErrCode IsSameAccount( + const std::string& netWorkId, + bool& funcResult) override; + + virtual ErrCode CheckApiPermission( + int32_t permissionLevel) override; + + virtual ErrCode CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + virtual ErrCode CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + virtual ErrCode ShiftLNNGear( + const std::string& pkgName) override; + + virtual ErrCode SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) override; + + virtual ErrCode GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) override; + + virtual ErrCode GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& networkId) override; + + virtual ErrCode SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) override; + + virtual ErrCode GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) override; + + virtual ErrCode RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) override; + + virtual ErrCode PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) override; + + virtual ErrCode GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) override; + + virtual ErrCode GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) override; + + virtual ErrCode GetCallerServiceInfos( + std::vector& serviceInfoExt) override; + + +private: + DeviceManagerClientService(); + ~DeviceManagerClientService() override = default; + bool Init(); + void AddSystemSA(const std::string &pkgName); + void RemoveSystemSA(const std::string &pkgName); + +private: + bool registerToService_; + ServiceRunningState state_; + mutable std::mutex listenerLock_; + std::map> appRecipient_; + std::map> dmListener_; + std::set systemSA_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_SERVER_STUB_H diff --git a/services/service/src/ipc/standard/device_manager_client_service.cpp b/services/service/src/ipc/standard/device_manager_client_service.cpp new file mode 100644 index 000000000..5c86e0323 --- /dev/null +++ b/services/service/src/ipc/standard/device_manager_client_service.cpp @@ -0,0 +1,858 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_client_stub.h" +#include "foundation/distributedhardware/device_manager/services/service/include/ipc/standard/device_manager_client_service.h" +#include "foundation/distributedhardware/device_manager/services/service/include/device_manager_service.h" +#include "if_system_ability_manager.h" +#include "ipc_cmd_register.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iservice_registry.h" +#include "foundation/distributedhardware/device_manager/utils/include/dm_ipc_utils.h" +#include "dm_radar_helper.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#endif +#ifdef SUPPORT_MEMMGR +#include "mem_mgr_client.h" +#include "mem_mgr_proxy.h" +#endif // SUPPORT_MEMMGR + +#include "string_ex.h" +#include "system_ability_definition.h" +#include "device_manager_ipc_interface_code.h" +#include "dm_constants.h" +#include "dm_device_info.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +// -------------------------------IPC Service Method-------------------------------- +ErrCode DeviceManagerClientService::GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) +{ + std::vector deviceList; + DeviceManagerService service; + int32_t result = service.GetTrustedDeviceList(pkgName, extra, deviceList); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetTrustedDeviceList", + // deviceList, result, anonyLocalUdid_); + LOGI("GetTrustedDeviceList error, failed ret: %{public}d", result); + return result; + } + DmIpcUtils::ConvertToDeviceInfoExtVector(deviceList, deviceListExt); + return result; +} + +ErrCode DeviceManagerClientService::GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) +{ + (void) pkgName; + DmDeviceInfo localDeviceInfo; + DeviceManagerService service; + int32_t result = service.GetLocalDeviceInfo(localDeviceInfo); + if (result != DM_OK) { + // DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", + // info, result, anonyLocalUdid_); + LOGE("DeviceManagerImpl::GetLocalDeviceInfo error, Send Request failed ret: %{public}d", result); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + DmIpcUtils::ConvertToDeviceInfo(deviceInfoExt, localDeviceInfo); + return result; +} + +ErrCode DeviceManagerClientService::GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.GetUdidByNetworkId(pkgName, netWorkId, udid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.GetUuidByNetworkId(pkgName, netWorkId, uuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) +{ + netWorkType = -1; + DeviceManagerService service; + int32_t result = service.GetNetworkTypeByNetworkId(pkgName, netWorkId, netWorkType); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientService::PublishDeviceDiscovery( + const std::string &pkgName, + const DmPublishInfoExt &publishInfoExt) +{ + DmPublishInfo publishInfo; + DmIpcUtils utils; + utils.ConvertToPublishInfo(publishInfoExt, publishInfo); + DeviceManagerService service; + int32_t result = service.PublishDeviceDiscovery(pkgName, publishInfo); + if (result != ERR_OK) + { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "PublishDeviceDiscovery", result, anonyLocalUdid_); + LOGE("PublishDeviceDiscovery error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) +{ + DeviceManagerService service; + int32_t result = service.UnPublishDeviceDiscovery(pkgName, publishId); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnPublishDeviceDiscovery", result, anonyLocalUdid_); + LOGE("UnPublishDeviceDiscovery error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.AuthenticateDevice(pkgName, authType, deviceId, extra); + if (result != ERR_OK) { + LOGE("AuthenticateDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnAuthenticateDevice( + const std::string& pkgName, + const std::string &netWorkId) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.UnAuthenticateDevice(pkgName, netWorkId); + if (result != ERR_OK) { + LOGE("UnAuthenticateDevice error: Failed with ret %{public}d", result); + // SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_FAILED), DM_HISYEVENT_BEHAVIOR, + // std::string(UNAUTHENTICATE_DEVICE_FAILED_MSG)); + } + return result; +} + +ErrCode DeviceManagerClientService::StopAuthenticateDevice( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.StopAuthenticateDevice(pkgName); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", result, anonyLocalUdid_); + LOGE("StopAuthenticateDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + DeviceManagerService service; + int32_t result = service.CheckCredential(pkgName, reqJsonStr, returnJsonStr); + if (result != ERR_OK) { + LOGE("failed to get return errcode while Check credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) +{ + DeviceManagerService service; + int32_t result = service.SetUserOperation(pkgName, action, params); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + int32_t result = ERR_DM_FAILED; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.RequestCredential(requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStr); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.MineRequestCredential(pkgName, returnJsonStr); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while request credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + std::unordered_map outputResult; + int32_t result = ERR_DM_FAILED; + std::string returnJsonStrTemp; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.ImportCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR]); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.ImportCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStrTemp); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); + outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStrTemp); + } + if (result == ERR_OK && !returnJsonStrTemp.empty()) { + returnJsonStr = ConvertMapToJsonString(outputResult); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while import credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + std::unordered_map outputResult; + std::string returnJsonStrTemp; + int32_t result = ERR_DM_FAILED; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.DeleteCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR]); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.DeleteCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStrTemp); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); + outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStrTemp); + } + if (result == ERR_OK && !returnJsonStrTemp.empty()) { + returnJsonStr = ConvertMapToJsonString(outputResult); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while delete credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterCredentialCallback( + const std::string& pkgName) +{ + int result = ERR_OK; + DeviceManagerService service; + result = service.RegisterCredentialCallback(pkgName); + if (result != ERR_OK) { + LOGE("RegisterCredentialCallback error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterCredentialCallback( + const std::string& pkgName) +{ + DeviceManagerService service; + int result = service.UnRegisterCredentialCallback(pkgName); + if (result != ERR_OK) { + LOGE("UnRegisterCredentialCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) +{ + DeviceManagerService service; + int32_t result = service.NotifyEvent(pkgName, eventId, event); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", result, anonyLocalUdid_); + LOGE("NotifyEvent failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) +{ + DmDeviceInfo deviceInfo; + DeviceManagerService service; + int32_t result = service.GetDeviceInfo(networkId, deviceInfo); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", + // deviceInfo, result, anonyLocalUdid_); + LOGE("DeviceManagerImpl::GetDeviceInfo error, failed ret: %{public}d", result); + return result; + } + return result; +} + +ErrCode DeviceManagerClientService::GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) +{ + DeviceManagerService service; + int32_t result = service.GetEncryptedUuidByNetworkId(pkgName, networkId, uuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) +{ + DeviceManagerService service; + int32_t result = service.GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.BindDevice(pkgName, bindType, deviceId, extra); + if (result != ERR_OK) { + LOGE("BindDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result; + DeviceManagerService service; + if (extra == "") { + result = service.UnBindDevice(pkgName, deviceId); + } else { + result = service.UnBindDevice(pkgName, deviceId, extra); + } + if (result != ERR_OK) { + LOGE("UnBindDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterUiStateCallback( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.RegisterUiStateCallback(pkgName); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterUiStateCallback", result, anonyLocalUdid_); + LOGE("RegisterUiStateCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterUiStateCallback( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.UnRegisterUiStateCallback(pkgName); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnRegisterUiStateCallback", result, anonyLocalUdid_); + LOGE("UnRegisterUiStateCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) +{ + DeviceManagerService service; + int32_t result = service.ImportAuthCode(pkgName, authCode); + if (result != ERR_OK) { + LOGE("ImportAuthCode Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ExportAuthCode( + std::string& authCode) +{ + DeviceManagerService service; + int32_t result = service.ExportAuthCode(authCode); + if (result != ERR_OK) { + LOGE("ExportAuthCode Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterPinHolderCallback( + const std::string& pkgName) +{ + DeviceManagerService service; + int32_t result = service.RegisterPinHolderCallback(pkgName); + if (result != DM_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", result, anonyLocalUdid_); // TODO anonyLocalUdid_ + LOGE("RegisterPinHolderCallback Failed with ret %{public}d", result); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientService::CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) +{ + PeerTargetId targetId; + DmIpcUtils utils; + utils.ConvertToPeerTargetId(targetIdExt, targetId); + DmPinType pinType = static_cast(pinTypeInt); + DeviceManagerService service; + int32_t result = service.CreatePinHolder(pkgName, targetId, pinType, payload); + if (result != ERR_OK) { + LOGE("CreatePinHolder Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) +{ + PeerTargetId targetId; + DmIpcUtils utils; + utils.ConvertToPeerTargetId(targetIdExt, targetId); + DmPinType pinType = static_cast(pinTypeInt); + DeviceManagerService service; + int32_t result = service.DestroyPinHolder(pkgName, targetId, pinType, payload); + return ERR_OK; +} + +ErrCode DeviceManagerClientService::RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + DeviceManagerService service; + int32_t result = service.EnableDiscoveryListener(pkgName, discoverParam, filterOptions); + if (result != ERR_OK) { + LOGE("RegisterDiscoveryCallback error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterDiscoveryCallback( + const std::string& pkgName) +{ + // int32_t result = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam); + // if (result != ERR_OK) { + // // DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", + // // result, anonyLocalUdid_); + // LOGE("UnRegisterDiscoveryCallback error: Failed with ret %{public}d", result); + // } + return DM_OK; +} + +ErrCode DeviceManagerClientService::StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + DeviceManagerService service; + int32_t result = service.StartDiscovering(pkgName, discoverParam, filterOptions); + if (result != ERR_OK) { + LOGE("StartDiscovering error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) +{ + DeviceManagerService service; + int32_t result = service.StopDiscovering(pkgName, discoverParam); + if (result != ERR_OK) { + LOGE("StopDiscovering error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + std::unordered_map advertiseParam; + ParseMapFromJsonString(adverParaStr, advertiseParam); + DeviceManagerService service; + int32_t result = service.StartAdvertising(pkgName, advertiseParam); + if (result != ERR_OK) { + LOGE("StartAdvertising error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + std::unordered_map advertiseParam; + ParseMapFromJsonString(adverParaStr, advertiseParam); + DeviceManagerService service; + int32_t result = service.StopAdvertising(pkgName, advertiseParam); + if (result != ERR_OK) { + LOGE("StopAdvertising error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) +{ + + std::unordered_map bindMapParam; + ParseMapFromJsonString(bindParam, bindMapParam); + PeerTargetId targetId; + DmIpcUtils::ConvertToPeerTargetId(targetIdExt, targetId); + DeviceManagerService service; + int32_t result = service.BindTarget(pkgName, targetId, bindMapParam); + if (result != ERR_OK) { + LOGE("BindTarget error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) +{ + std::unordered_map unbindMapParam; + ParseMapFromJsonString(unbindParam, unbindMapParam); + PeerTargetId targetId; + DmIpcUtils::ConvertToPeerTargetId(targetIdExt, targetId); + DeviceManagerService service; + int32_t result = service.UnbindTarget(pkgName, targetId, unbindMapParam); + if (result != ERR_OK) { + LOGE("UnbindTarget error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) +{ + DeviceManagerService service; + int32_t result = service.DpAclAdd(udid); + if (result != ERR_OK) { + LOGE("DpAclAdd error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) +{ + securityLevel = -1; + DeviceManagerService service; + int32_t result = service.GetDeviceSecurityLevel(pkgName, networkId, securityLevel); + if (result != DM_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", result, anonyLocalUdid_); + LOGE("GetDeviceSecurityLevel Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::IsSameAccount( + const std::string& netWorkId, bool& funcResult) +{ + DeviceManagerService service; + int32_t result = service.IsSameAccount(netWorkId); + if (result != ERR_OK) { + LOGE("IsSameAccount Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckApiPermission( + int32_t permissionLevel) +{ + DeviceManagerService service; + int32_t result = service.CheckApiPermission(permissionLevel); + if (result != ERR_OK) { + LOGE("Check permission failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DmIpcUtils::ConvertToDmAccessCaller(callerExt, caller); + DmIpcUtils::ConvertToDmAccessCallee(calleeExt, callee); + DeviceManagerService service; + int32_t result = service.CheckAccessControl(caller, callee); + funcResult = result == 1 ? true : false; + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", result, anonyLocalUdid_); + LOGE("CheckAccessControl Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DmIpcUtils::ConvertToDmAccessCaller(callerExt, caller); + DmIpcUtils::ConvertToDmAccessCallee(calleeExt, callee); + DeviceManagerService service; + int32_t result = service.CheckIsSameAccount(caller, callee); + funcResult = result == 1 ? true : false; + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", result, anonyLocalUdid_); + LOGE("CheckIsSameAccount Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ShiftLNNGear( + const std::string& pkgName) +{ + DeviceManagerService service; + int32_t result = service.ShiftLNNGear(pkgName, pkgName, true, true); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", result, anonyLocalUdid_); + LOGE("ShiftLNNGear error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) +{ + DeviceManagerService service; + int32_t result = service.SetDnPolicy(pkgName, policy); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", result, anonyLocalUdid_); + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) +{ + screenStatus = -1; + DeviceManagerService service; + int32_t result = service.GetDeviceScreenStatus(pkgName, networkId, screenStatus); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& netWorkId) +{ + DeviceManagerService service; + int32_t result = service.GetNetworkIdByUdid(pkgName, udid, netWorkId); + if (result != ERR_OK) { + LOGE("GetNetworkIdByUdid Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) +{ + // ProcessInfo processInfo; + // processInfo.pkgName = pkgName; + // MultipleUserConnector::GetCallerUserId(processInfo.userId); + // int32_t result = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfo); + // if (dmCommonNotifyEvent == static_cast(DmCommonNotifyEvent::REG_DEVICE_STATE)) { + // DeviceManagerService::GetInstance().RegDevStateCallbackToService(pkgName); + // } + // if (result != ERR_OK) { + // LOGE("Failed with ret %{public}d", result); + // } + return DM_OK; +} + +ErrCode DeviceManagerClientService::GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) +{ + DeviceManagerService service; + int32_t result = service.GetAnonyLocalUdid(pkgName, anonyUdid); + if (result != ERR_OK) { + LOGE("GetAnonyLocalUdid Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) +{ + // int32_t result = DeviceManagerService::GetInstance().RegisterAuthenticationType(pkgName, authParam); + // if (result != ERR_OK) { + // LOGE("Failed with ret %{public}d", result); + // } + //return result; + return DM_OK; +} + +ErrCode DeviceManagerClientService::PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) +{ + DeviceManagerService service; + std::vector deviceProfileInfoList; + int32_t result = service.PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) +{ + DeviceManagerService service; + int32_t result = service.GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) +{ + std::vector deviceList; + DeviceManagerService service; + int32_t result = service.GetAllTrustedDeviceList(pkgName, extra, deviceList); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetCallerServiceInfos( + std::vector& serviceInfoExt) +{ + // DMServiceInfo serviceInfos; + // DmIpcUtils::ConvertToDMServiceInfo(serviceInfos, serviceInfoExt); + // int32_t result = DeviceManagerService::GetInstance().GetCallerServiceInfos(serviceInfos); + // if (result != ERR_OK) { + // LOGE("Failed with ret %{public}d", result); + // } + // return result; + return DM_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/include/dm_ipc_utils.h b/utils/include/dm_ipc_utils.h new file mode 100644 index 000000000..fea875365 --- /dev/null +++ b/utils/include/dm_ipc_utils.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_DM_IPC_UTILS_H +#define OHOS_DM_IPC_UTILS_H + +#include +#include "dm_device_info.h" +#include "dm_publish_info.h" +#include "dm_device_profile_info.h" +namespace OHOS { +namespace DistributedHardware { + +class DmIpcUtils { +public: + static void ConvertToDeviceInfoVector(const std::vector& extVector, std::vector& baseVector); + static void ConvertToDeviceInfoExtVector(const std::vector& baseVector, std::vector& extVector); + static void ConvertToPublishInfo(const DmPublishInfoExt& ext, DmPublishInfo& base); + static void ConvertToDeviceInfo(const DmDeviceInfoExt& ext, DmDeviceInfo& base); + static void ConvertToPeerTargetId(const PeerTargetIdExt& ext, PeerTargetId& base); + static void ConvertToDmAccessCaller(const DmAccessCallerExt& ext, DmAccessCaller& base); + static void ConvertToDmAccessCallee(const DmAccessCalleeExt& ext, DmAccessCallee& base); + static void ConvertToDmDeviceProfileInfoVector(const std::vector& deviceProfileInfoListExt, + std::vector &deviceProfileInfoList); + static void ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos); + static void ConvertToDMServiceInfo(const DMServiceInfoExt& ext, DMServiceInfo& base); +}; + +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DM_IPC_UTILS_H \ No newline at end of file diff --git a/utils/src/dm_ipc_utils.cpp b/utils/src/dm_ipc_utils.cpp new file mode 100644 index 000000000..bf5e28f2c --- /dev/null +++ b/utils/src/dm_ipc_utils.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "dm_ipc_utils.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmIpcUtils::ConvertToDeviceInfoVector(const std::vector& extVector, std::vector& baseVector) +{ + baseVector.clear(); + baseVector.reserve(extVector.size()); // 预留空间以避免多次分配内存 + + for (const auto& ext : extVector) { + DmDeviceInfo base; + memcpy(base.deviceId, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(base.deviceName, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy(base.networkId, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.range = ext.range; + base.networkType = ext.networkType; + base.authForm = ext.authForm; + base.extraData = ext.extraData; + baseVector.push_back(base); + } +} + +void DmIpcUtils::ConvertToDeviceInfoExtVector(const std::vector& baseVector, std::vector& extVector) +{ + extVector.clear(); + extVector.reserve(baseVector.size()); // 预留空间以避免多次分配内存 + + for (const auto& base : baseVector) { + DmDeviceInfoExt ext; + memcpy(ext.deviceId, base.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(ext.deviceName, base.deviceName, DM_MAX_DEVICE_NAME_LEN); + ext.deviceTypeId = base.deviceTypeId; + memcpy(ext.networkId, base.networkId, DM_MAX_DEVICE_ID_LEN); + ext.range = base.range; + ext.networkType = base.networkType; + ext.authForm = base.authForm; + ext.extraData = base.extraData; + extVector.push_back(ext); + } +} + +void DmIpcUtils::ConvertToPublishInfo(const DmPublishInfoExt& ext, DmPublishInfo& base) +{ + base.publishId = ext.publishId; + base.mode = ext.mode; + base.freq = ext.freq; + base.ranging = ext.ranging; +} + +void DmIpcUtils::ConvertToDeviceInfo(const DmDeviceInfoExt& ext, DmDeviceInfo& base) +{ + memcpy(base.deviceId, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(base.deviceName, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy(base.networkId, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.range = ext.range; + base.networkType = ext.networkType; + base.authForm = ext.authForm; + base.extraData = ext.extraData; +} + +void DmIpcUtils::ConvertToPeerTargetId(const PeerTargetIdExt& ext, PeerTargetId& base) +{ + base.deviceId = ext.deviceId; + base.brMac = ext.brMac; + base.bleMac = ext.bleMac; + base.wifiIp = ext.wifiIp; + base.wifiPort = ext.wifiPort; +} + +void DmIpcUtils::ConvertToDmAccessCaller(const DmAccessCallerExt& ext, DmAccessCaller& base) +{ + base.accountId = ext.accountId; + base.pkgName = ext.pkgName; + base.networkId = ext.networkId; + base.userId = ext.userId; + base.tokenId = ext.tokenId; + base.extra = ext.extra; +} + +void DmIpcUtils::ConvertToDmAccessCallee(const DmAccessCalleeExt& ext, DmAccessCallee& base) +{ + base.accountId = ext.accountId; + base.networkId = ext.networkId; + base.peerId = ext.peerId; + base.userId = ext.userId; + base.extra = ext.extra; +} + +void DmIpcUtils::ConvertToDmDeviceProfileInfoVector(const std::vector& deviceProfileInfoListExt, + std::vector &deviceProfileInfoList) +{ + deviceProfileInfoList.clear(); + deviceProfileInfoList.reserve(deviceProfileInfoListExt.size()); + for (const auto& ext : deviceProfileInfoListExt) { + DmDeviceProfileInfo base; + base.deviceId = ext.deviceId; + base.deviceSn = ext.deviceSn; + base.mac = ext.mac; + base.model = ext.model; + base.innerModel = ext.innerModel; + base.deviceType = ext.deviceType; + base.manufacturer = ext.manufacturer; + base.deviceName = ext.deviceName; + base.productId = ext.productId; + base.subProductId = ext.subProductId; + base.sdkVersion = ext.sdkVersion; + base.bleMac = ext.bleMac; + base.brMac = ext.brMac; + base.sleMac = ext.sleMac; + base.firmwareVersion = ext.firmwareVersion; + base.hardwareVersion = ext.hardwareVersion; + base.softwareVersion = ext.softwareVersion; + base.protocolType = ext.protocolType; + base.setupType = ext.setupType; + base.wiseDeviceId = ext.wiseDeviceId; + base.wiseUserId = ext.wiseUserId; + base.registerTime = ext.registerTime; + base.modifyTime = ext.modifyTime; + base.shareTime = ext.shareTime; + base.isLocalDevice = ext.isLocalDevice; + } +} + +void DmIpcUtils::ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos) +{ + serviceInfos.clear(); + serviceInfos.reserve(serviceInfoExt.size()); + for (const auto& ext : serviceInfoExt) { + DMServiceInfo base; + base.serviceId = ext.serviceId; + base.serviceType = ext.serviceType; + base.serviceName = ext.serviceName; + base.serviceDisplayName = ext.serviceDisplayName; + base.customData = ext.customData; + base.bundleName = ext.bundleName; + base.moduleName = ext.moduleName; + base.abilityName = ext.abilityName; + base.authBoxType = ext.authBoxType; + base.authType = ext.authType; + base.pinExchangeType = ext.pinExchangeType; + base.pinCode = ext.pinCode; + base.description = ext.description; + base.serviceDiscoveryScope = ext.serviceDiscoveryScope; + } +} + +void DmIpcUtils::ConvertToDMServiceInfo(const DMServiceInfoExt& ext, DMServiceInfo& base) +{ + base.serviceId = ext.serviceId; + base.serviceType = ext.serviceType; + base.serviceName = ext.serviceName; + base.serviceDisplayName = ext.serviceDisplayName; + base.customData = ext.customData; + base.bundleName = ext.bundleName; + base.moduleName = ext.moduleName; + base.abilityName = ext.abilityName; + base.authBoxType = ext.authBoxType; + base.authType = ext.authType; + base.pinExchangeType = ext.pinExchangeType; + base.pinCode = ext.pinCode; + base.description = ext.description; + base.serviceDiscoveryScope = ext.serviceDiscoveryScope; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee From f8c93aa59dc8e084ca39788fb47223c3c7aa6c4a Mon Sep 17 00:00:00 2001 From: Sly <1298008151@qq.com> Date: Thu, 10 Apr 2025 19:07:25 +0800 Subject: [PATCH 2/5] idl Signed-off-by: Sly <1298008151@qq.com> Change-Id: Id1b7645675428f763906d8259ed2833bb98d173d --- .vscode/settings.json | 63 ++ .../ipc/model/ipc_get_localserviceinfo_rsp.h | 6 +- .../ipc/model/ipc_register_serviceinfo_req.h | 6 +- common/include/ipc/standard/ipc_model_codec.h | 8 +- common/src/dm_anonymous.cpp | 2 +- common/src/ipc/standard/ipc_model_codec.cpp | 12 +- interfaces/inner_kits/native_cpp/BUILD.gn | 43 +- .../native_cpp/IDeviceManagerClient.idl | 93 ++ .../native_cpp/include/device_manager.h | 6 +- .../native_cpp/include/device_manager_impl.h | 15 +- .../native_cpp/include/dm_device_info.h | 123 ++- .../include/dm_device_profile_info.h | 57 ++ .../native_cpp/include/dm_publish_info.h | 17 + .../native_cpp/src/device_manager_impl.cpp | 110 ++- .../native_cpp/src/dm_device_info.cpp | 209 ++++ .../native_cpp/src/dm_device_profile_info.cpp | 118 +++ .../native_cpp/src/dm_publish_info.cpp | 49 + .../src/ipc/standard/ipc_cmd_parser.cpp | 6 +- .../include/device_manager_service_impl.h | 2 +- .../src/authentication/dm_auth_manager.cpp | 22 +- .../src/device_manager_service_impl.cpp | 7 +- services/service/BUILD.gn | 1 + .../service/include/device_manager_service.h | 21 +- .../include/idevice_manager_service_impl.h | 6 +- .../standard/device_manager_client_service.h | 337 +++++++ .../service/src/device_manager_service.cpp | 16 +- .../device_manager_client_service.cpp | 909 ++++++++++++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 14 +- utils/BUILD.gn | 1 + utils/include/dm_ipc_utils.h | 46 + utils/src/dm_ipc_utils.cpp | 178 ++++ 31 files changed, 2377 insertions(+), 126 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl create mode 100644 interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp create mode 100644 interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp create mode 100644 services/service/include/ipc/standard/device_manager_client_service.h create mode 100644 services/service/src/ipc/standard/device_manager_client_service.cpp create mode 100644 utils/include/dm_ipc_utils.h create mode 100644 utils/src/dm_ipc_utils.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..b6d6bd10c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,63 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "valarray": "cpp" + } +} \ No newline at end of file diff --git a/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h index 98a8137c7..a41d5ce59 100644 --- a/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h +++ b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h @@ -25,17 +25,17 @@ class IpcGetLocalServiceInfoRsp : public IpcRsp { DECLARE_IPC_MODEL(IpcGetLocalServiceInfoRsp); public: - const DMLocalServiceInfo &GetLocalServiceInfo() const + const DmLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetLocalServiceInfo(const DMLocalServiceInfo &info) + void SetLocalServiceInfo(const DmLocalServiceInfo &info) { serviceInfo_ = info; } private: - DMLocalServiceInfo serviceInfo_; + DmLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_register_serviceinfo_req.h b/common/include/ipc/model/ipc_register_serviceinfo_req.h index d9308dc57..01bfcada4 100644 --- a/common/include/ipc/model/ipc_register_serviceinfo_req.h +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.h @@ -25,17 +25,17 @@ class IpcRegServiceInfoReq : public IpcReq { DECLARE_IPC_MODEL(IpcRegServiceInfoReq); public: - const DMLocalServiceInfo &GetLocalServiceInfo() const + const DmLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetLocalServiceInfo(const DMLocalServiceInfo &info) + void SetLocalServiceInfo(const DmLocalServiceInfo &info) { serviceInfo_ = info; } private: - DMLocalServiceInfo serviceInfo_; + DmLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index e06af83a9..32c359eab 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -48,10 +48,10 @@ public: static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, MessageParcel &parcel); static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); - static bool EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel); - static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); - static bool DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo); - static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); + static bool EncodeLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, MessageParcel &parcel); + static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); + static bool DecodeLocalServiceInfo(MessageParcel &parcel, DmLocalServiceInfo &serviceInfo); + static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); static bool EncodeNetworkIdQueryFilter(const NetworkIdQueryFilter &queryFilter, MessageParcel &parcel); static bool DecodeNetworkIdQueryFilter(MessageParcel &parcel, NetworkIdQueryFilter &queryFilter); static bool EncodeStringVector(const std::vector &vec, MessageParcel &parcel); diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 15d940b42..6a1183802 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -191,7 +191,7 @@ std::string ConvertMapToJsonString(const std::map &par return jsonStr; } -void ParseMapFromJsonString(const std::string &jsonStr, std::map ¶mMap) +void ParseMapFromJsonString(const std::string &jsonStr, std::unordered_map ¶mMap) { if (jsonStr.empty()) { return; diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index 1091961c6..83840c2a7 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -356,7 +356,7 @@ void IpcModelCodec::DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devI devInfo.extraData = parcel.ReadString(); } -bool IpcModelCodec::EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, MessageParcel &parcel) { bool bRet = true; bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); @@ -369,7 +369,7 @@ bool IpcModelCodec::EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo return bRet; } -bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) { uint32_t num = static_cast(serviceInfos.size()); if (!parcel.WriteUint32(num)) { @@ -378,7 +378,7 @@ bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos) +bool IpcModelCodec::DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) { uint32_t num = 0; READ_HELPER_RET(parcel, Uint32, num, false); bool bRet = true; for (uint32_t k = 0; k < num; k++) { - DMLocalServiceInfo serviceInfo; + DmLocalServiceInfo serviceInfo; bRet = DecodeLocalServiceInfo(parcel, serviceInfo); if (!bRet) { LOGE("DecodeLocalServiceInfo failed"); diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 9311ca50b..d17b22ab3 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -10,14 +10,39 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import("//build/config/components/idl_tool/idl.gni") if (defined(ohos_lite)) { import("//build/lite/config/component/lite_component.gni") } else { import("//build/ohos.gni") } import("//foundation/distributedhardware/device_manager/device_manager.gni") - +idl_gen_interface("device_manager_interface") { + src_idl = rebase_path("IDeviceManagerClient.idl") + hitrace = "HITRACE_TAG_DEVICE_MANAGER" + log_domainid = "0xD004111" + log_tag = "distributedhardware" +} +ohos_source_set("device_manager_ipc") { + sanitize = { + debug = false + cfi = true + cfi_cross_dso = true + } + output_values = get_target_outputs(":device_manager_interface") + sources = [] + sources += filter_include(output_values, [ "*.cpp" ]) + public_configs = [ ":devicemanagersdk_config" ] + deps = [ ":device_manager_interface" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + ] + subsystem_name = "distributedhardware" + part_name = "device_manager" +} if (defined(ohos_lite)) { if (ohos_kernel_type == "liteos_m") { static_library("devicemanagersdk") { @@ -37,6 +62,7 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//base/security/device_auth/interfaces/inner_api", "//base/startup/init/interfaces/innerkits/include/syspara", + "${target_gen_dir}", ] sources = [ @@ -51,6 +77,7 @@ if (defined(ohos_lite)) { "//foundation/systemabilitymgr/samgr_lite/samgr", "//third_party/bounds_checking_function:libsec_static", "//third_party/cJSON:cjson", + ":device_manager_ipc" ] cflags = [ @@ -88,6 +115,7 @@ if (defined(ohos_lite)) { "${interfaces_path}/c/ipc/include", "//foundation/distributedshedule/samgr_lite/interfaces/kits/samgr", "//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include", + "${target_gen_dir}", ] sources = [ @@ -107,6 +135,9 @@ if (defined(ohos_lite)) { "src/ipc/lite/ipc_client_stub.cpp", "src/ipc/lite/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "src/dm_device_info.cpp", + "src/dm_device_profile_info.cpp", + "src/dm_publish_info.cpp" ] defines = [ @@ -127,6 +158,7 @@ if (defined(ohos_lite)) { "//foundation/systemabilitymgr/safwk_lite:safwk_lite", "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", "//third_party/bounds_checking_function:libsec_shared", + ":device_manager_ipc", ] } } @@ -146,6 +178,8 @@ if (defined(ohos_lite)) { "${devicemanager_path}/radar/include", "${utils_path}/include", "${json_path}/include", + "${target_gen_dir}", + "${devicemanager_path}/commondependency/include", ] } @@ -188,8 +222,11 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_client_stub.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "src/dm_publish_info.cpp", + "src/dm_device_profile_info.cpp", ] + deps = [ ":device_manager_ipc" ] public_configs = [ ":devicemanagersdk_config" ] innerapi_tags = [ "platformsdk" ] @@ -201,7 +238,7 @@ if (defined(ohos_lite)) { "__CJSON_USE_INT64", ] - deps = [ "${json_path}:devicemanagerjson" ] + deps += [ "${json_path}:devicemanagerjson" ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl new file mode 100644 index 000000000..b0f8142b8 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// import DeviceManagerType; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmDeviceInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.PeerTargetIdExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCallerExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCalleeExt; +sequenceable DmPublishInfo..OHOS.DistributedHardware.DmPublishInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceProfileInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmLocalServiceInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.NetworkIdQueryFilterExt; + +interface OHOS.DistributedHardware.IDeviceManagerClient { + [ipccode 2] void GetTrustedDeviceList([in] String pkgName, [in] String extra, [in] boolean isRefresh, [out] List deviceListExt); + [ipccode 3] void GetLocalDeviceInfo([in] String pkgName, [out] DmDeviceInfoExt deviceInfoExt); + [ipccode 4] void GetUdidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String udid); + [ipccode 5] void GetUuidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String uuid); + [ipccode 6] void GetNetworkTypeByNetworkId([in] String pkgName,[in] String netWorkId, [out] int netWorkType); + [ipccode 7] void PublishDeviceDiscovery([in] String pkgName, [in] DmPublishInfoExt publishInfoExt); + [ipccode 8] void UnPublishDeviceDiscovery([in] String pkgName, [in] int publishId); + // AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo, const std::string &extra, std::shared_ptr callback) + [ipccode 9] void AuthenticateDevice([in] String pkgName, [in] int authType, [in] String deviceId, [in] String extra); + [ipccode 10] void UnAuthenticateDevice([in] String pkgName, [in] String netWorkId); + [ipccode 11] void StopAuthenticateDevice([in] String pkgName); + [ipccode 20] void CheckCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 21] void SetUserOperation([in] String pkgName, [in] int action, [in] String params); + // RequestCredential(const std::string &pkgName, const std::string &reqJsonStr, std::string &returnJsonStr) + // RequestCredential(const std::string &pkgName, std::string &returnJsonStr) + [ipccode 26] void RequestCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 27] void ImportCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 28] void DeleteCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); + [ipccode 29] void RegisterCredentialCallback([in] String pkgName); + [ipccode 30] void UnRegisterCredentialCallback([in] String pkgName); + [ipccode 31] void NotifyEvent([in] String pkgName, [in] int eventId, [in] String event); + [ipccode 32] void GetDeviceInfo([in] String pkgName, [in] String networkId, [out] DmDeviceInfoExt deviceInfoExt); + [ipccode 33] void GetEncryptedUuidByNetworkId([in] String pkgName, [in] String networkId,[out] String uuid); + [ipccode 34] void GenerateEncryptedUuid([in] String pkgName, [in] String uuid, [in] String appId, [out] String encryptedUuid); + [ipccode 35] void BindDevice([in] String pkgName, [in] int bindType, [in] String deviceId, [in] String extra); + // UnBindDevice(const std::string &pkgName, const std::string &deviceId); + // UnBindDevice(const std::string &pkgName, const std::string &deviceId, const std::string &extra); + [ipccode 36] void UnBindDevice([in] String pkgName, [in] String deviceId, [in] String extra); + [ipccode 37] void RegisterUiStateCallback([in] String pkgName); + [ipccode 38] void UnRegisterUiStateCallback([in] String pkgName); + [ipccode 39] void ImportAuthCode([in] String pkgName, [in] String authCode); + [ipccode 40] void ExportAuthCode([out] String authCode); + [ipccode 41] void RegisterPinHolderCallback([in] String pkgName); + [ipccode 42] void CreatePinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinTypeInt, [in] String payload); + [ipccode 43] void DestroyPinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinType, [in] String payload); + [ipccode 49] void RegisterDiscoveryCallback([in] String pkgName, [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); + [ipccode 50] void UnRegisterDiscoveryCallback([in] String pkgName); + [ipccode 51] void StartDiscovering([in] String pkgName, [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); + [ipccode 52] void StopDiscovering([in] String pkgName, [in] OrderedMap discoverParam); + [ipccode 53] void StartAdvertising([in] String pkgName, [in] String adverParaStr); + [ipccode 54] void StopAdvertising([in] String pkgName, [in] String adverParaStr); + [ipccode 55] void BindTarget([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] String bindParam); + [ipccode 56] void UnbindTarget([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] String unbindParam); + [ipccode 59] void DpAclAdd([in] long accessControlId, [in] String udid, [in] int bindType); + [ipccode 60] void GetDeviceSecurityLevel([in] String pkgName, [in] String networkId,[out] int securityLevel); + [ipccode 61] boolean IsSameAccount([in] String netWorkId); + [ipccode 62] void CheckApiPermission([in] int permissionLevel); + [ipccode 63] boolean CheckAccessControl([in] DmAccessCallerExt callerExt, [in] DmAccessCalleeExt calleeExt); + [ipccode 64] boolean CheckIsSameAccount([in] DmAccessCallerExt callerExt, [in] DmAccessCalleeExt calleeExt); + [ipccode 65] void ShiftLNNGear([in] String pkgName); + [ipccode 66] void SetDnPolicy([in] String pkgName, [in] OrderedMap policy); + [ipccode 69] void GetDeviceScreenStatus([in] String pkgName, [in] String networkId, [out] int screenStatus); + [ipccode 70] void GetNetworkIdByUdid([in] String pkgName, [in] String udid, [out] String networkId); + [ipccode 73] void SyncCallbackToService([in] int dmCommonNotifyEvent, [in] String pkgName); + [ipccode 74] void GetAnonyLocalUdid([in] String pkgName, [out] String anonyUdid); + [ipccode 75] void RegisterAuthenticationType([in] String pkgName, [in] String authTypeStr); + [ipccode 80] void PutDeviceProfileInfoList([in] String pkgName, [in] List deviceProfileInfoListExt); + [ipccode 81] void GetLocalDisplayDeviceName([in] String pkgName, [in] int maxNameLength, [out] String displayName); + [ipccode 86] void GetAllTrustedDeviceList([in] String pkgName, [in] String extra, [out] List deviceListExt); + [ipccode 87] void RegisterLocalServiceInfo([in] DmLocalServiceInfoExt info); + [ipccode 88] void UnRegisterLocalServiceInfo([in] String bundleName, [in] int pinExchangeType); + [ipccode 89] void UpdateLocalServiceInfo([in] DmLocalServiceInfoExt info); + [ipccode 90] void GetLocalServiceInfoByBundleNameAndPinExchangeType([in] String bundleName,[in] int pinExchangeType,[out] DmLocalServiceInfoExt info); + [ipccode 91] void RestoreLocalDeviceName ([in] String pkgName); + [ipccode 92] void GetDeviceNetworkIdList([in] String pkgName,[in] NetworkIdQueryFilterExt queryFilter,[out] List networkIds); + +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 8c75216bf..cca939e64 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -647,11 +647,11 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; - virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &info) = 0; virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; - virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) = 0; + virtual int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &info) = 0; virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DMLocalServiceInfo &info) = 0; + int32_t pinExchangeType, DmLocalServiceInfo &info) = 0; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) = 0; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, 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 61298898a..792932dc8 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -20,6 +20,8 @@ #if !defined(__LITEOS_M__) #include "ipc_client_manager.h" #include "ipc_client_proxy.h" +#include "idevice_manager_client.h" +#include "device_manager_client_proxy.h" #endif #include @@ -420,11 +422,11 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; - virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &info) override; virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) override; - virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) override; + virtual int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &info) override; virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DMLocalServiceInfo &info) override; + int32_t pinExchangeType, DmLocalServiceInfo &info) override; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) override; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, @@ -441,7 +443,7 @@ private: DeviceManagerImpl(DeviceManagerImpl &&) = delete; DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete; - uint16_t AddDiscoveryCallback(const std::string &pkgName, std::map &discoverParam, + uint16_t AddDiscoveryCallback(const std::string &pkgName, std::unordered_map &discoverParam, std::shared_ptr callback); uint16_t RemoveDiscoveryCallback(const std::string &pkgName); int32_t AddPublishCallback(const std::string &pkgName); @@ -456,12 +458,13 @@ private: #if !defined(__LITEOS_M__) std::shared_ptr ipcClientProxy_ = std::make_shared(std::make_shared()); + std::shared_ptr deviceManagerClientProxy_; #endif std::mutex subMapLock; - std::map pkgName2SubIdMap_; + std::unordered_map pkgName2SubIdMap_; std::mutex pubMapLock; - std::map pkgName2PubIdMap_; + std::unordered_map pkgName2PubIdMap_; std::string anonyLocalUdid_; 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 243012f27..26a0ed74d 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -20,6 +20,7 @@ #include #include "dm_app_image_info.h" +#include "parcel.h" #define DM_MAX_DEVICE_ID_LEN (97) #define DM_MAX_DEVICE_NAME_LEN (129) @@ -423,25 +424,25 @@ typedef struct DmNotifyKey { } } DmNotifyKey; -enum class DMLocalServiceInfoAuthType : int32_t { +enum class DmLocalServiceInfoAuthType : int32_t { TRUST_ONETIME = 0, TRUST_ALWAYS = 6, CANCEL = 1 }; -enum class DMLocalServiceInfoPinExchangeType : int32_t { +enum class DmLocalServiceInfoPinExchangeType : int32_t { PINBOX = 1, ULTRASOUND = 2, FROMDP = 3 }; -enum class DMLocalServiceInfoAuthBoxType : int32_t { +enum class DmLocalServiceInfoAuthBoxType : int32_t { STATE3 = 1, SKIP_CONFIRM = 2, TWO_IN1 = 3 }; -typedef struct DMLocalServiceInfo { +typedef struct DmLocalServiceInfo { std::string bundleName; int32_t authBoxType = 0; int32_t authType = 0; @@ -449,7 +450,119 @@ typedef struct DMLocalServiceInfo { std::string pinCode; std::string description; std::string extraInfo; -} DMLocalServiceInfo; +} DmLocalServiceInfo; +struct DmDeviceInfoExt : public DmDeviceInfo, public Parcelable +{ + using DmDeviceInfo::DmDeviceInfo; + + DmDeviceInfoExt(const DmDeviceInfo& devInfo) + { + memcpy(deviceId, devInfo.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(deviceName, devInfo.deviceName, DM_MAX_DEVICE_NAME_LEN); + deviceTypeId = devInfo.deviceTypeId; + memcpy(networkId, devInfo.networkId, DM_MAX_DEVICE_ID_LEN); + range = devInfo.range; + networkType = devInfo.networkType; + authForm = devInfo.authForm; + extraData = devInfo.extraData; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmDeviceInfoExt *Unmarshalling(Parcel &parcel); +}; + +struct PeerTargetIdExt : public PeerTargetId, public Parcelable { + + using PeerTargetId::PeerTargetId; + + PeerTargetIdExt(const PeerTargetId& peerTargetId) + { + deviceId = peerTargetId.deviceId; + brMac = peerTargetId.brMac; + bleMac = peerTargetId.bleMac; + wifiIp = peerTargetId.wifiIp; + wifiPort = peerTargetId.wifiPort; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static PeerTargetIdExt *Unmarshalling(Parcel &parcel); +}; + +struct DmAccessCallerExt : public DmAccessCaller, public Parcelable { + + using DmAccessCaller::DmAccessCaller; + + DmAccessCallerExt(const DmAccessCaller& dmAccessCaller) + { + accountId = dmAccessCaller.accountId; + pkgName = dmAccessCaller.pkgName; + networkId = dmAccessCaller.networkId; + userId = dmAccessCaller.userId; + tokenId = dmAccessCaller.tokenId; + extra = dmAccessCaller.extra; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmAccessCallerExt *Unmarshalling(Parcel &parcel); +}; + +struct DmAccessCalleeExt : public DmAccessCallee, public Parcelable { + + using DmAccessCallee::DmAccessCallee; + + DmAccessCalleeExt(const DmAccessCallee& dmAccessCallee) + { + accountId = dmAccessCallee.accountId; + networkId = dmAccessCallee.networkId; + peerId = dmAccessCallee.peerId; + userId = dmAccessCallee.userId; + extra = dmAccessCallee.extra; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmAccessCalleeExt *Unmarshalling(Parcel &parcel); +}; + +struct DmDeviceBasicInfoExt : public DmDeviceBasicInfo, public Parcelable +{ + using DmDeviceBasicInfo::DmDeviceBasicInfo; + + DmDeviceBasicInfoExt(const DmDeviceBasicInfo& devBasicInfo) + { + memcpy(deviceId, devBasicInfo.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(deviceName, devBasicInfo.deviceName, DM_MAX_DEVICE_NAME_LEN); + deviceTypeId = devBasicInfo.deviceTypeId; + memcpy(networkId, devBasicInfo.networkId, DM_MAX_DEVICE_ID_LEN); + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmDeviceBasicInfoExt *Unmarshalling(Parcel &parcel); +}; + +struct DmLocalServiceInfoExt : public DmLocalServiceInfo, public Parcelable +{ + using DmLocalServiceInfo::DmLocalServiceInfo; + + DmLocalServiceInfoExt(const DmLocalServiceInfo& devLocalServiceInfo) { + bundleName = devLocalServiceInfo.bundleName; + authBoxType = devLocalServiceInfo.authBoxType; + authType = devLocalServiceInfo.authType; + pinExchangeType = devLocalServiceInfo.pinExchangeType; + pinCode = devLocalServiceInfo.pinCode; + description = devLocalServiceInfo.description; + extraInfo = devLocalServiceInfo.extraInfo; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmLocalServiceInfoExt *Unmarshalling(Parcel &parcel); + +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h index b110b9176..35a3cd8cc 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h @@ -21,6 +21,8 @@ #include #include +#include "parcel.h" + namespace OHOS { namespace DistributedHardware { typedef struct DmProductInfo { @@ -99,6 +101,61 @@ typedef struct NetworkIdQueryFilter { std::string deviceProductId = ""; std::string deviceModel = ""; } NetworkIdQueryFilter; + +struct DmDeviceProfileInfoExt : public DmDeviceProfileInfo, public Parcelable +{ + using DmDeviceProfileInfo::DmDeviceProfileInfo; + + DmDeviceProfileInfoExt(const DmDeviceProfileInfo& devProfileInfo) { + deviceId = devProfileInfo.deviceId; + deviceSn = devProfileInfo.deviceSn; + mac = devProfileInfo.mac; + model = devProfileInfo.model; + internalModel = devProfileInfo.internalModel; + deviceType = devProfileInfo.deviceType; + manufacturer = devProfileInfo.manufacturer; + deviceName = devProfileInfo.deviceName; + productId = devProfileInfo.productId; + subProductId = devProfileInfo.subProductId; + sdkVersion = devProfileInfo.sdkVersion; + bleMac = devProfileInfo.bleMac; + brMac = devProfileInfo.brMac; + sleMac = devProfileInfo.sleMac; + firmwareVersion = devProfileInfo.firmwareVersion; + hardwareVersion = devProfileInfo.hardwareVersion; + softwareVersion = devProfileInfo.softwareVersion; + protocolType = devProfileInfo.protocolType; + setupType = devProfileInfo.setupType; + wiseDeviceId = devProfileInfo.wiseDeviceId; + wiseUserId = devProfileInfo.wiseUserId; + registerTime = devProfileInfo.registerTime; + modifyTime = devProfileInfo.modifyTime; + shareTime = devProfileInfo.shareTime; + isLocalDevice = devProfileInfo.isLocalDevice; + services = devProfileInfo.services; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmDeviceProfileInfoExt *Unmarshalling(Parcel &parcel); +}; + +struct NetworkIdQueryFilterExt : public NetworkIdQueryFilter, public Parcelable +{ + using NetworkIdQueryFilter::NetworkIdQueryFilter; + + NetworkIdQueryFilterExt(const NetworkIdQueryFilter& devNetworkIdQueryFilter) { + wiseDeviceId = devNetworkIdQueryFilter.wiseDeviceId; + onlineStatus = devNetworkIdQueryFilter.onlineStatus; + deviceType = devNetworkIdQueryFilter.deviceType; + deviceProductId = devNetworkIdQueryFilter.deviceProductId; + deviceModel = devNetworkIdQueryFilter.deviceModel; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static NetworkIdQueryFilterExt *Unmarshalling(Parcel &parcel); +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_PROFILE_INFO_H diff --git a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h index f3e7b0b34..a869f0ead 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_publish_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_publish_info.h @@ -17,6 +17,7 @@ #define OHOS_DM_PUBLISH_INFO_H #include "dm_subscribe_info.h" +#include "parcel.h" namespace OHOS { namespace DistributedHardware { @@ -45,6 +46,22 @@ typedef struct { */ DmExchangeMedium medium; } DmPublishInfo; + +struct DmPublishInfoExt : public DmPublishInfo, public Parcelable { + using DmPublishInfo::DmPublishInfo; + + DmPublishInfoExt(const DmPublishInfo& publishInfo) + { + publishId = publishInfo.publishId; + mode = publishInfo.mode; + freq = publishInfo.freq; + ranging = publishInfo.ranging; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmPublishInfoExt *Unmarshalling(Parcel &parcel); +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_PUBLISH_INFO_H 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 55f081c22..47fc57e7e 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -351,32 +351,53 @@ int32_t DeviceManagerImpl::GetDeviceInfo(const std::string &pkgName, const std:: return DM_OK; } +// int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) +// { +// LOGD("Start, pkgName: %{public}s", GetAnonyString(pkgName).c_str()); +// DmTraceStart(std::string(DM_HITRACE_GET_LOCAL_DEVICE_INFO)); +// std::shared_ptr req = std::make_shared(); +// std::shared_ptr rsp = std::make_shared(); +// req->SetPkgName(pkgName); +// int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DEVICE_INFO, req, rsp); +// if (ret != DM_OK) { +// DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", +// info, ret, anonyLocalUdid_); +// LOGE("DeviceManagerImpl::GetLocalDeviceInfo error, Send Request failed ret: %{public}d", ret); +// return ERR_DM_IPC_SEND_REQUEST_FAILED; +// } + +// ret = rsp->GetErrCode(); +// if (ret != DM_OK) { +// DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", +// info, ret, anonyLocalUdid_); +// LOGI("DeviceManagerImpl::GetLocalDeviceInfo error, failed ret: %{public}d", ret); +// SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_FAILED), DM_HISYEVENT_BEHAVIOR, +// std::string(GET_LOCAL_DEVICE_INFO_FAILED_MSG)); +// return ret; +// } + +// info = rsp->GetLocalDeviceInfo(); +// DmTraceEnd(); +// LOGI("Completed"); +// SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_SUCCESS), DM_HISYEVENT_BEHAVIOR, +// std::string(GET_LOCAL_DEVICE_INFO_SUCCESS_MSG)); +// DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", +// info, DM_OK, anonyLocalUdid_); +// return DM_OK; +// } + int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) { LOGD("Start, pkgName: %{public}s", GetAnonyString(pkgName).c_str()); DmTraceStart(std::string(DM_HITRACE_GET_LOCAL_DEVICE_INFO)); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DEVICE_INFO, req, rsp); + DmDeviceInfoExt dmDeviceInfoExt(info); + int32_t ret = deviceManagerClientProxy_->GetLocalDeviceInfo(pkgName, dmDeviceInfoExt); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", info, ret, anonyLocalUdid_); LOGE("DeviceManagerImpl::GetLocalDeviceInfo error, Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", - info, ret, anonyLocalUdid_); - LOGI("DeviceManagerImpl::GetLocalDeviceInfo error, failed ret: %{public}d", ret); - SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_FAILED), DM_HISYEVENT_BEHAVIOR, - std::string(GET_LOCAL_DEVICE_INFO_FAILED_MSG)); - return ret; - } - - info = rsp->GetLocalDeviceInfo(); DmTraceEnd(); LOGI("Completed"); SysEventWrite(std::string(GET_LOCAL_DEVICE_INFO_SUCCESS), DM_HISYEVENT_BEHAVIOR, @@ -480,11 +501,11 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::map discParam; + std::unordered_map discParam; discParam.insert(std::pair(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeInfo.subscribeId))); discParam.insert(std::pair(PARAM_KEY_DISC_MEDIUM, std::to_string(subscribeInfo.medium))); - std::map filterOps; + std::unordered_map filterOps; filterOps.insert(std::pair(PARAM_KEY_FILTER_OPTIONS, extra)); return StartDiscovering(pkgName, discParam, filterOps, callback); } @@ -496,9 +517,9 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, uint LOGE("DeviceManagerImpl::StartDeviceDiscovery error: Invalid para, pkgName: %{public}s", pkgName.c_str()); return ERR_DM_INPUT_PARA_INVALID; } - std::map discParam; + std::unordered_map discParam; discParam.insert(std::pair(PARAM_KEY_SUBSCRIBE_ID, std::to_string(tokenId))); - std::map filterOps; + std::unordered_map filterOps; filterOps.insert(std::pair(PARAM_KEY_FILTER_OPTIONS, filterOptions)); return StartDiscovering(pkgName, discParam, filterOps, callback); } @@ -509,7 +530,7 @@ int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint1 LOGE("DeviceManagerImpl::StopDeviceDiscovery Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - std::map discParam; + std::unordered_map discParam; discParam.insert(std::pair(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId))); return StopDiscovering(pkgName, discParam); } @@ -520,13 +541,13 @@ int32_t DeviceManagerImpl::StopDeviceDiscovery(uint64_t tokenId, const std::stri LOGE("DeviceManagerImpl::StopDeviceDiscovery Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; } - std::map discParam; + std::unordered_map discParam; discParam.insert(std::pair(PARAM_KEY_SUBSCRIBE_ID, std::to_string(tokenId))); return StopDiscovering(pkgName, discParam); } int32_t DeviceManagerImpl::StartDiscovering(const std::string &pkgName, - std::map &discoverParam, const std::map &filterOptions, + std::unordered_map &discoverParam, const std::unordered_map &filterOptions, std::shared_ptr callback) { if (pkgName.empty() || callback == nullptr) { @@ -540,7 +561,6 @@ int32_t DeviceManagerImpl::StartDiscovering(const std::string &pkgName, discoverParam.emplace(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId)); std::string discParaStr = ConvertMapToJsonString(discoverParam); std::string filterOpStr = ConvertMapToJsonString(filterOptions); - std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(ComposeStr(pkgName, subscribeId)); @@ -565,7 +585,7 @@ int32_t DeviceManagerImpl::StartDiscovering(const std::string &pkgName, } int32_t DeviceManagerImpl::StopDiscovering(const std::string &pkgName, - std::map &discoverParam) + std::unordered_map &discoverParam) { if (pkgName.empty()) { LOGE("DeviceManagerImpl::StopDiscovering failed: input pkgName is empty."); @@ -1011,7 +1031,7 @@ int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, const s return ERR_DM_INPUT_PARA_INVALID; } LOGI("start to RequestCredential."); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); std::string reqParaStr = ConvertMapToJsonString(requestParam); @@ -1044,7 +1064,7 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st return ERR_DM_INPUT_PARA_INVALID; } LOGI("start to ImportCredential."); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, credentialInfo); std::string reqParaStr = ConvertMapToJsonString(requestParam); @@ -1076,7 +1096,7 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st return ERR_DM_INPUT_PARA_INVALID; } LOGI("start to DeleteCredential."); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, deleteInfo); std::string reqParaStr = ConvertMapToJsonString(requestParam); @@ -1203,7 +1223,7 @@ int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, std::st return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); std::string reqParaStr = ConvertMapToJsonString(requestParam); std::shared_ptr req = std::make_shared(); @@ -1262,7 +1282,7 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); std::string reqParaStr = ConvertMapToJsonString(requestParam); @@ -1295,7 +1315,7 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::map requestParam; + std::unordered_map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); std::string reqParaStr = ConvertMapToJsonString(requestParam); @@ -1695,7 +1715,7 @@ int32_t DeviceManagerImpl::ExportAuthCode(std::string &authCode) } int32_t DeviceManagerImpl::RegisterDiscoveryCallback(const std::string &pkgName, - std::map &discoverParam, const std::map &filterOptions, + std::unordered_map &discoverParam, const std::unordered_map &filterOptions, std::shared_ptr callback) { if (pkgName.empty() || callback == nullptr) { @@ -1744,7 +1764,7 @@ int32_t DeviceManagerImpl::UnRegisterDiscoveryCallback(const std::string &pkgNam LOGE("DeviceManagerImpl::UnRegisterDiscoveryCallback failed: cannot find pkgName in cache map."); return ERR_DM_INPUT_PARA_INVALID; } - std::map extraParam; + std::unordered_map extraParam; extraParam.emplace(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId)); std::string extraParaStr = ConvertMapToJsonString(extraParam); @@ -1773,7 +1793,7 @@ int32_t DeviceManagerImpl::UnRegisterDiscoveryCallback(const std::string &pkgNam } int32_t DeviceManagerImpl::StartAdvertising(const std::string &pkgName, - std::map &advertiseParam, std::shared_ptr callback) + std::unordered_map &advertiseParam, std::shared_ptr callback) { if (pkgName.empty() || callback == nullptr) { LOGE("DeviceManagerImpl::StartAdvertising error: pkgName %{public}s invalid para", pkgName.c_str()); @@ -1810,7 +1830,7 @@ int32_t DeviceManagerImpl::StartAdvertising(const std::string &pkgName, } int32_t DeviceManagerImpl::StopAdvertising(const std::string &pkgName, - std::map &advertiseParam) + std::unordered_map &advertiseParam) { if (pkgName.empty()) { LOGE("DeviceManagerImpl::StopAdvertising failed: input pkgName is empty."); @@ -1851,7 +1871,7 @@ int32_t DeviceManagerImpl::StopAdvertising(const std::string &pkgName, } int32_t DeviceManagerImpl::BindTarget(const std::string &pkgName, const PeerTargetId &targetId, - std::map &bindParam, std::shared_ptr callback) + std::unordered_map &bindParam, std::shared_ptr callback) { if (pkgName.empty() || IsInvalidPeerTargetId(targetId)) { LOGE("DeviceManagerImpl::BindTarget failed: input pkgName or targetId is empty."); @@ -1884,7 +1904,7 @@ int32_t DeviceManagerImpl::BindTarget(const std::string &pkgName, const PeerTarg } int32_t DeviceManagerImpl::UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, - std::map &unbindParam, std::shared_ptr callback) + std::unordered_map &unbindParam, std::shared_ptr callback) { if (pkgName.empty() || IsInvalidPeerTargetId(targetId)) { LOGE("DeviceManagerImpl::UnbindTarget failed: input pkgName or targetId is empty."); @@ -1915,7 +1935,7 @@ int32_t DeviceManagerImpl::UnbindTarget(const std::string &pkgName, const PeerTa } int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, - const std::map &filterOptions, bool isRefresh, + const std::unordered_map &filterOptions, bool isRefresh, std::vector &deviceList) { if (pkgName.empty()) { @@ -1927,7 +1947,7 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, } int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, - const std::map &extraParam, std::shared_ptr callback) + const std::unordered_map &extraParam, std::shared_ptr callback) { (void)extraParam; if (pkgName.empty() || callback == nullptr) { @@ -1952,7 +1972,7 @@ int32_t DeviceManagerImpl::CheckAccessToTarget(uint64_t tokenId, const std::stri } uint16_t DeviceManagerImpl::AddDiscoveryCallback(const std::string &pkgName, - std::map &discoverParam, std::shared_ptr callback) + std::unordered_map &discoverParam, std::shared_ptr callback) { if (discoverParam.empty() || callback == nullptr) { LOGE("input param invalid."); @@ -2301,7 +2321,7 @@ int32_t DeviceManagerImpl::ShiftLNNGear(const std::string &pkgName) return DM_OK; } -int32_t DeviceManagerImpl::SetDnPolicy(const std::string &pkgName, std::map &policy) +int32_t DeviceManagerImpl::SetDnPolicy(const std::string &pkgName, std::unordered_map &policy) { const size_t SET_DN_POLICY_PARAM_SIZE = 2; if (pkgName.empty() || policy.size() != SET_DN_POLICY_PARAM_SIZE) { @@ -2597,7 +2617,7 @@ void DeviceManagerImpl::SyncCallbacksToService(std::map &authParam) + const std::unordered_map &authParam) { const size_t AUTH_TYPE_PARAM_SIZE = 1; if (pkgName.empty() || authParam.size() != AUTH_TYPE_PARAM_SIZE) { @@ -2731,7 +2751,7 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, return DM_OK; } -int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DMLocalServiceInfo &info) +int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DmLocalServiceInfo &info) { LOGI("Start"); std::shared_ptr req = std::make_shared(); @@ -2772,7 +2792,7 @@ int32_t DeviceManagerImpl::UnRegisterLocalServiceInfo(const std::string &bundleN return DM_OK; } -int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DMLocalServiceInfo &info) +int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DmLocalServiceInfo &info) { LOGI("Start"); std::shared_ptr req = std::make_shared(); @@ -2793,7 +2813,7 @@ int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DMLocalServiceInfo &info } int32_t DeviceManagerImpl::GetLocalServiceInfoByBundleNameAndPinExchangeType( - const std::string &bundleName, int32_t pinExchangeType, DMLocalServiceInfo &info) + const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfo &info) { std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp index c80cbb4a4..f1a52c702 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp +++ b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp @@ -13,6 +13,15 @@ * limitations under the License. */ +#include +#include +#include + +#include "dm_device_info.h" + +#include "dm_log.h" +#include "dm_constants.h" + namespace OHOS { namespace DistributedHardware { const char* DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; @@ -25,5 +34,205 @@ const char* DEVICE_TYPE_WIFICAMERA_STRING = "WiFiCamera"; const char* DEVICE_TYPE_PC_STRING = "PC"; const char* DEVICE_TYPE_SMART_DISPLAY_STRING = "SMART_DISPLAY"; const char* DEVICE_TYPE_2IN1_STRING = "2IN1"; + +bool DmDeviceInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + std::string deviceIdStr(deviceId); + bRet = (bRet && parcel.WriteString(deviceIdStr)); + std::string deviceNameStr(deviceName); + bRet = (bRet && parcel.WriteString(deviceNameStr)); + bRet = (bRet && parcel.WriteUint16(deviceTypeId)); + std::string networkIdStr(networkId); + bRet = (bRet && parcel.WriteString(networkIdStr)); + bRet = (bRet && parcel.WriteInt32(range)); + bRet = (bRet && parcel.WriteInt32(networkType)); + bRet = (bRet && parcel.WriteInt32(static_cast(authForm))); + bRet = (bRet && parcel.WriteString(extraData)); + return bRet; +} + +DmDeviceInfoExt *DmDeviceInfoExt::Unmarshalling(Parcel &parcel) +{ + DmDeviceInfoExt *deviceInfoExt = new (std::nothrow) DmDeviceInfoExt(); + if (deviceInfoExt == nullptr) { + LOGE("Create DmDeviceInfoExt failed"); + return nullptr; + } + std::string deviceIdStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceId failed!"); + delete deviceInfoExt; + return nullptr; + } + std::string deviceNameStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceName failed!"); + delete deviceInfoExt; + return nullptr; + } + deviceInfoExt->deviceTypeId = parcel.ReadUint16(); + std::string networkIdStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s networkId failed!"); + delete deviceInfoExt; + return nullptr; + } + deviceInfoExt->range = parcel.ReadInt32(); + deviceInfoExt->networkType = parcel.ReadInt32(); + deviceInfoExt->authForm = static_cast(parcel.ReadInt32()); + deviceInfoExt->extraData = parcel.ReadString(); + return deviceInfoExt; +} + +bool PeerTargetIdExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(brMac)); + bRet = (bRet && parcel.WriteString(bleMac)); + bRet = (bRet && parcel.WriteString(wifiIp)); + bRet = (bRet && parcel.WriteUint16(wifiPort)); + return bRet; +} + +PeerTargetIdExt *PeerTargetIdExt::Unmarshalling(Parcel &parcel) +{ + PeerTargetIdExt *targetIdExt = new (std::nothrow) PeerTargetIdExt(); + if (targetIdExt == nullptr) { + LOGE("Create PeerTargetIdExt failed"); + return nullptr; + } + targetIdExt->deviceId = parcel.ReadString(); + targetIdExt->brMac = parcel.ReadString(); + targetIdExt->bleMac = parcel.ReadString(); + targetIdExt->wifiIp = parcel.ReadString(); + targetIdExt->wifiPort = parcel.ReadUint16(); + return targetIdExt; +} + +bool DmAccessCallerExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(accountId)); + bRet = (bRet && parcel.WriteString(pkgName)); + bRet = (bRet && parcel.WriteString(networkId)); + bRet = (bRet && parcel.WriteInt32(userId)); + bRet = (bRet && parcel.WriteUint64(tokenId)); + bRet = (bRet && parcel.WriteString(extra)); + return bRet; +} + +DmAccessCallerExt *DmAccessCallerExt::Unmarshalling(Parcel &parcel) +{ + DmAccessCallerExt *callerExt = new (std::nothrow) DmAccessCallerExt(); + if (callerExt == nullptr) { + LOGE("Create DmAccessCallerExt failed"); + return nullptr; + } + callerExt->accountId = parcel.ReadString(); + callerExt->pkgName = parcel.ReadString(); + callerExt->networkId = parcel.ReadString(); + callerExt->userId = parcel.ReadInt32(); + callerExt->tokenId = parcel.ReadUint64(); + callerExt->extra = parcel.ReadString(); + return callerExt; +} + +bool DmAccessCalleeExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(accountId)); + bRet = (bRet && parcel.WriteString(networkId)); + bRet = (bRet && parcel.WriteString(peerId)); + bRet = (bRet && parcel.WriteInt32(userId)); + bRet = (bRet && parcel.WriteString(extra)); + return bRet; +} + +DmAccessCalleeExt *DmAccessCalleeExt::Unmarshalling(Parcel &parcel) +{ + DmAccessCalleeExt *calleeExt = new (std::nothrow) DmAccessCalleeExt(); + if (calleeExt == nullptr) { + LOGE("Create DmAccessCallerExt failed"); + return nullptr; + } + calleeExt->accountId = parcel.ReadString(); + calleeExt->networkId = parcel.ReadString(); + calleeExt->peerId = parcel.ReadString(); + calleeExt->userId = parcel.ReadInt32(); + calleeExt->extra = parcel.ReadString(); + + return calleeExt; +} + +bool DmDeviceBasicInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + std::string deviceIdStr(deviceId); + bRet = (bRet && parcel.WriteString(deviceIdStr)); + std::string deviceNameStr(deviceName); + bRet = (bRet && parcel.WriteString(deviceNameStr)); + bRet = (bRet && parcel.WriteUint16(deviceTypeId)); + std::string networkIdStr(networkId); + bRet = (bRet && parcel.WriteString(networkIdStr)); + return bRet; +} + +DmDeviceBasicInfoExt *DmDeviceBasicInfoExt::Unmarshalling(Parcel &parcel) +{ + DmDeviceBasicInfoExt *deviceBasicInfoExt = new (std::nothrow) DmDeviceBasicInfoExt(); + if (deviceBasicInfoExt == nullptr) { + LOGE("Create DmDeviceBasicInfoExt failed"); + return nullptr; + } + std::string deviceIdStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceId failed!"); + return nullptr; + } + std::string deviceNameStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceName failed!"); + return nullptr; + } + deviceBasicInfoExt->deviceTypeId = parcel.ReadUint16(); + std::string networkIdStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s networkId failed!"); + return nullptr; + } + return deviceBasicInfoExt; +} + +bool DmLocalServiceInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(bundleName)); + bRet = (bRet && parcel.WriteInt32(authBoxType)); + bRet = (bRet && parcel.WriteInt32(authType)); + bRet = (bRet && parcel.WriteInt32(pinExchangeType)); + bRet = (bRet && parcel.WriteString(pinCode)); + bRet = (bRet && parcel.WriteString(description)); + bRet = (bRet && parcel.WriteString(extraInfo)); + return bRet; +} + +DmLocalServiceInfoExt *DmLocalServiceInfoExt::Unmarshalling(Parcel &parcel) +{ + DmLocalServiceInfoExt *localServiceinfoExt = new (std::nothrow) DmLocalServiceInfoExt(); + if (localServiceinfoExt == nullptr) { + LOGE("Create DmLocalServiceInfoExt failed"); + return nullptr; + } + localServiceinfoExt->bundleName = parcel.ReadString(); + localServiceinfoExt->authBoxType = parcel.ReadInt32(); + localServiceinfoExt->authType = parcel.ReadInt32(); + localServiceinfoExt->pinExchangeType = parcel.ReadInt32(); + localServiceinfoExt->pinCode = parcel.ReadString(); + localServiceinfoExt->description = parcel.ReadString(); + localServiceinfoExt->extraInfo = parcel.ReadString(); + return localServiceinfoExt; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp new file mode 100644 index 000000000..d6d7c77ad --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include + #include + #include + + #include "dm_device_profile_info.h" + #include "dm_log.h" + + namespace OHOS { + namespace DistributedHardware { + bool DmDeviceProfileInfoExt::Marshalling(Parcel &parcel) const + { + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(deviceSn)); + bRet = (bRet && parcel.WriteString(mac)); + bRet = (bRet && parcel.WriteString(model)); + bRet = (bRet && parcel.WriteString(internalModel)); + bRet = (bRet && parcel.WriteString(deviceType)); + bRet = (bRet && parcel.WriteString(manufacturer)); + bRet = (bRet && parcel.WriteString(deviceName)); + bRet = (bRet && parcel.WriteString(productId)); + bRet = (bRet && parcel.WriteString(subProductId)); + bRet = (bRet && parcel.WriteString(sdkVersion)); + bRet = (bRet && parcel.WriteString(bleMac)); + bRet = (bRet && parcel.WriteString(brMac)); + bRet = (bRet && parcel.WriteString(sleMac)); + bRet = (bRet && parcel.WriteString(firmwareVersion)); + bRet = (bRet && parcel.WriteString(hardwareVersion)); + bRet = (bRet && parcel.WriteString(softwareVersion)); + bRet = (bRet && parcel.WriteInt32(protocolType)); + bRet = (bRet && parcel.WriteInt32(setupType)); + bRet = (bRet && parcel.WriteString(wiseDeviceId)); + bRet = (bRet && parcel.WriteString(wiseUserId)); + bRet = (bRet && parcel.WriteString(registerTime)); + bRet = (bRet && parcel.WriteString(modifyTime)); + bRet = (bRet && parcel.WriteString(shareTime)); + bRet = (bRet && parcel.WriteBool(isLocalDevice)); + + return bRet; + } + + DmDeviceProfileInfoExt *DmDeviceProfileInfoExt::Unmarshalling(Parcel &parcel) + { + DmDeviceProfileInfoExt *profileInfoExt = new (std::nothrow) DmDeviceProfileInfoExt(); + if (profileInfoExt == nullptr) { + LOGE("Create DmDeviceProfileInfoExt failed"); + return nullptr; + } + profileInfoExt->deviceId = parcel.ReadString(); + profileInfoExt->deviceSn = parcel.ReadString(); + profileInfoExt->mac = parcel.ReadString(); + profileInfoExt->model = parcel.ReadString(); + profileInfoExt->internalModel = parcel.ReadString(); + profileInfoExt->deviceType = parcel.ReadString(); + profileInfoExt->manufacturer = parcel.ReadString(); + profileInfoExt->deviceName = parcel.ReadString(); + profileInfoExt->productId = parcel.ReadString(); + profileInfoExt->subProductId = parcel.ReadString(); + profileInfoExt->sdkVersion = parcel.ReadString(); + profileInfoExt->bleMac = parcel.ReadString(); + profileInfoExt->brMac = parcel.ReadString(); + profileInfoExt->sleMac = parcel.ReadString(); + profileInfoExt->firmwareVersion = parcel.ReadString(); + profileInfoExt->hardwareVersion = parcel.ReadString(); + profileInfoExt->softwareVersion = parcel.ReadString(); + profileInfoExt->protocolType = parcel.ReadInt32(); + profileInfoExt->setupType = parcel.ReadInt32(); + profileInfoExt->wiseDeviceId = parcel.ReadString(); + profileInfoExt->wiseUserId = parcel.ReadString(); + profileInfoExt->registerTime = parcel.ReadString(); + profileInfoExt->modifyTime = parcel.ReadString(); + profileInfoExt->shareTime = parcel.ReadString(); + profileInfoExt->isLocalDevice = parcel.ReadBool(); + + return profileInfoExt; + } + bool NetworkIdQueryFilterExt::Marshalling(Parcel &parcel) const + { + bool bRet = true; + bRet = (bRet && parcel.WriteString(wiseDeviceId)); + bRet = (bRet && parcel.WriteInt32(onlineStatus)); + bRet = (bRet && parcel.WriteString(deviceType)); + bRet = (bRet && parcel.WriteString(deviceProductId)); + bRet = (bRet && parcel.WriteString(deviceModel)); + return bRet; + } + + NetworkIdQueryFilterExt *NetworkIdQueryFilterExt::Unmarshalling(Parcel &parcel) + { + NetworkIdQueryFilterExt *networkIdQueryExt = new (std::nothrow) NetworkIdQueryFilterExt(); + if (networkIdQueryExt == nullptr) { + LOGE("Create NetworkIdQueryFilterExt failed"); + return nullptr; + } + networkIdQueryExt->wiseDeviceId = parcel.ReadString(); + networkIdQueryExt->onlineStatus = parcel.ReadInt32(); + networkIdQueryExt->deviceType = parcel.ReadString(); + networkIdQueryExt->deviceProductId = parcel.ReadString(); + networkIdQueryExt->deviceModel = parcel.ReadString(); + return networkIdQueryExt; + } + } // namespace DistributedHardware + } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp new file mode 100644 index 000000000..c5042afe0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_publish_info.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include + #include + #include + + #include "dm_publish_info.h" + #include "dm_log.h" + + namespace OHOS { + namespace DistributedHardware { + bool DmPublishInfoExt::Marshalling(Parcel &parcel) const + { + bool bRet = true; + bRet = (bRet && parcel.WriteInt32(publishId)); + bRet = (bRet && parcel.WriteInt32(mode)); + bRet = (bRet && parcel.WriteInt32(freq)); + bRet = (bRet && parcel.WriteBool(ranging)); + return bRet; + } + + DmPublishInfoExt *DmPublishInfoExt::Unmarshalling(Parcel &parcel) + { + DmPublishInfoExt *publishInfo = new (std::nothrow) DmPublishInfoExt(); + if (publishInfo == nullptr) { + LOGE("Create DmPublishInfo failed"); + return nullptr; + } + publishInfo->publishId = parcel.ReadInt32(); + publishInfo->mode = static_cast(parcel.ReadInt32()); + publishInfo->freq = static_cast(parcel.ReadInt32()); + publishInfo->ranging = parcel.ReadBool(); + return publishInfo; + } + } // namespace DistributedHardware + } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 0423e4731..747e11b2e 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 @@ -1864,7 +1864,7 @@ ON_IPC_SET_REQUEST(REG_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, Mess return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + const DmLocalServiceInfo& info = pReq->GetLocalServiceInfo(); if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1917,7 +1917,7 @@ ON_IPC_SET_REQUEST(UPDATE_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, M return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + const DmLocalServiceInfo& info = pReq->GetLocalServiceInfo(); if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1965,7 +1965,7 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel if (pBaseRsp->GetErrCode() == DM_OK) { std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - DMLocalServiceInfo info; + DmLocalServiceInfo info; bool ret = IpcModelCodec::DecodeLocalServiceInfo(reply, info); if (!ret) { LOGE("DecodeLocalServiceInfo failed"); diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 423e5be0f..7da1dce7f 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -50,7 +50,7 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel, const std::string &extra); - int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); + int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 17d8b08f3..18ab5f1ac 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1608,14 +1608,14 @@ bool DmAuthManager::CanUsePincodeFromDp() { CHECK_NULL_RETURN(authResponseContext_, false); return (IsPinCodeValid(serviceInfoProfile_.GetPinCode()) && - serviceInfoProfile_.GetPinExchangeType() == (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); + serviceInfoProfile_.GetPinExchangeType() == (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP); } bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) { - if (authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME && - authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ALWAYS && - authType != (int32_t)DMLocalServiceInfoAuthType::CANCEL) { + if (authType != (int32_t)DmLocalServiceInfoAuthType::TRUST_ONETIME && + authType != (int32_t)DmLocalServiceInfoAuthType::TRUST_ALWAYS && + authType != (int32_t)DmLocalServiceInfoAuthType::CANCEL) { return false; } return true; @@ -1623,8 +1623,8 @@ bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) { - if (authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::STATE3 && - authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { + if (authBoxType != (int32_t)DmLocalServiceInfoAuthBoxType::STATE3 && + authBoxType != (int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { return false; } return true; @@ -1632,9 +1632,9 @@ bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) { - if (pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::PINBOX && - pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP && - pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND) { + if (pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::PINBOX && + pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP && + pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::ULTRASOUND) { return false; } return true; @@ -1737,7 +1737,7 @@ void DmAuthManager::ShowConfigDialog() return; } if (authResponseContext_->authType == AUTH_TYPE_NFC && - serviceInfoProfile_.GetAuthBoxType() == (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { + serviceInfoProfile_.GetAuthBoxType() == (int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { LOGI("no need confirm dialog"); StartAuthProcess(serviceInfoProfile_.GetAuthType()); return; @@ -3309,7 +3309,7 @@ void DmAuthManager::GetLocalServiceInfoInDp() { DistributedDeviceProfile::LocalServiceInfo localServiceInfo; int32_t result = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( - authResponseContext_->hostPkgName, (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); + authResponseContext_->hostPkgName, (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); if (result != DM_OK) { return; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 12ad2f7fd..f4fc004ee 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -30,6 +30,7 @@ #include "dm_common_event_manager.h" #include "parameter.h" #include "common_event_support.h" +#include "dm_ipc_utils.h" using namespace OHOS::EventFwk; #endif @@ -149,7 +150,7 @@ int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const return authMgr_->UnBindDevice(pkgName, udid, bindLevel, extra); } -int32_t DeviceManagerServiceImpl::SetUserOperation(std::string &pkgName, int32_t action, +int32_t DeviceManagerServiceImpl::SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) { if (pkgName.empty() || params.empty()) { @@ -773,14 +774,14 @@ int32_t DeviceManagerServiceImpl::GetBindLevel(const std::string &pkgName, const return DeviceProfileConnector::GetInstance().GetBindLevel(pkgName, localUdid, udid, tokenId); } -std::map DeviceManagerServiceImpl::GetDeviceIdAndBindLevel(int32_t userId) +std::unordered_map DeviceManagerServiceImpl::GetDeviceIdAndBindLevel(int32_t userId) { char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); std::string localUdid = std::string(localUdidTemp); std::vector userIds; userIds.push_back(userId); - return DeviceProfileConnector::GetInstance().GetDeviceIdAndBindLevel(userIds, localUdid); + return std::DmIpcUtils::StringIntConvertToUMap(DeviceProfileConnector::GetInstance().GetDeviceIdAndBindLevel(userIds, localUdid)); } std::multimap DeviceManagerServiceImpl::GetDeviceIdAndUserId(int32_t userId, diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index d76727825..60b5691f4 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -211,6 +211,7 @@ if (defined(ohos_lite)) { "src/discovery/discovery_filter.cpp", "src/discovery/discovery_manager.cpp", "src/hichain/hichain_listener.cpp", + "src/ipc/standard/device_manager_client_service.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/ipc/standard/ipc_server_client_proxy.cpp", "src/ipc/standard/ipc_server_listener.cpp", diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 8b40da361..42e31ace4 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -99,7 +99,7 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udidHash, const std::string &extra); - int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); + int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); @@ -176,8 +176,7 @@ public: int32_t StopAdvertising(const std::string &pkgName, const std::map &advertiseParam); - int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam); + int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId,const std::string& bindParam); int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &unbindParam); @@ -227,11 +226,11 @@ public: int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName); std::vector GetDeviceNamePrefixs(); int32_t RestoreLocalDeviceName(const std::string &pkgName); - int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); + int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &serviceInfo); int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType); - int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); + int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &serviceInfo); int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, int32_t pinExchangeType, - DMLocalServiceInfo &serviceInfo); + DmLocalServiceInfo &serviceInfo); void ClearPublishIdCache(const std::string &pkgName); bool IsPC(); int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, @@ -311,12 +310,12 @@ private: int32_t SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid); - bool InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, + bool InitDPLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem); void InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem, - DMLocalServiceInfo &serviceInfo); + DmLocalServiceInfo &serviceInfo); void InitServiceInfos(const std::vector &dpLocalServiceItems, - std::vector &serviceInfos); + std::vector &serviceInfos); void HandleUserSwitched(); void NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); @@ -330,13 +329,13 @@ private: void HandleUserSwitchedEvent(int32_t currentUserId, int32_t beforeUserId); void HandleUserStopEvent(int32_t stopUserId); void DivideNotifyMethod(const std::vector &peerUdids, std::vector &bleUdids, - std::map &wifiDevices); + std::unordered_map &wifiDevices); void NotifyRemoteLocalUserStop(const std::string &localUdid, const std::vector &peerUdids, int32_t stopUserId); void SendUserStopBroadCast(const std::vector &peerUdids, int32_t stopUserId); void HandleUserStopBroadCast(int32_t stopUserId, const std::string &remoteUdid); void NotifyRemoteLocalUserStopByWifi(const std::string &localUdid, - const std::map &wifiDevices, int32_t stopUserId); + const std::unordered_map &wifiDevices, int32_t stopUserId); #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) void SubscribePublishCommonEvent(); void QueryDependsSwitchState(); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 7d2e34906..f4e60422e 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -67,7 +67,7 @@ public: * @tc.desc: Se tUser Operation of device manager service impl * @tc.type: FUNC */ - virtual int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms) = 0; + virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) = 0; /** * @tc.name: IDeviceManagerServiceImpl::HandleDeviceStatusChange @@ -195,7 +195,7 @@ public: * @tc.type: FUNC */ virtual int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, - const std::map &bindParam) = 0; + const std::unordered_map &bindParam) = 0; /** * @tc.name: IDeviceManagerServiceImpl::LoadHardwareFwkService @@ -251,7 +251,7 @@ public: virtual void HandleSyncUserIdEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus) = 0; virtual void HandleRemoteUserRemoved(int32_t userId, const std::string &remoteUdid) = 0; - virtual std::map GetDeviceIdAndBindLevel(int32_t userId) = 0; + virtual std::unordered_map GetDeviceIdAndBindLevel(int32_t userId) = 0; virtual std::multimap GetDeviceIdAndUserId(int32_t localUserId) = 0; virtual int32_t SaveOnlineDeviceInfo(const std::vector &deviceList) = 0; virtual void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, diff --git a/services/service/include/ipc/standard/device_manager_client_service.h b/services/service/include/ipc/standard/device_manager_client_service.h new file mode 100644 index 000000000..c744416bf --- /dev/null +++ b/services/service/include/ipc/standard/device_manager_client_service.h @@ -0,0 +1,337 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_DEVICE_MANAGER_SERVICE_H +#define OHOS_DM_IPC_DEVICE_MANAGER_SERVICE_H + +#include +#include +#include +#include +#include +#include +#include + +#include "ipc_remote_broker.h" +#include "ipc_req.h" +#include "ipc_rsp.h" +#include "iremote_stub.h" +#include "idevice_manager_client.h" +#include "dm_device_info.h" +#include "dm_single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; + +class AppDeathRecipient : public IRemoteObject::DeathRecipient { +public: + /** + * @tc.name: AppDeathRecipient::OnRemoteDied + * @tc.desc: OnRemoteDied function of the App DeathRecipient + * @tc.type: FUNC + */ + void OnRemoteDied(const wptr &remote) override; + AppDeathRecipient() = default; + ~AppDeathRecipient() override = default; +}; + +class DeviceManagerClientService : public DeviceManagerClientStub { + DM_DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerClientService); + // -------------------------------IPC Service Method-------------------------------- + virtual ErrCode GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) override; + + virtual ErrCode GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) override; + + virtual ErrCode GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) override; + + virtual ErrCode GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) override; + + virtual ErrCode GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) override; + + virtual ErrCode PublishDeviceDiscovery( + const std::string& pkgName, + const DmPublishInfoExt& publishInfoExt) override; + + virtual ErrCode UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) override; + + virtual ErrCode AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode UnAuthenticateDevice( + const std::string& pkgName, + const std::string &netWorkId) override; + + virtual ErrCode StopAuthenticateDevice( + const std::string& pkgName) override; + + virtual ErrCode CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) override; + + virtual ErrCode RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) override; + + virtual ErrCode RegisterCredentialCallback( + const std::string& pkgName) override; + + virtual ErrCode UnRegisterCredentialCallback( + const std::string& pkgName) override; + + virtual ErrCode NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) override; + + virtual ErrCode GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) override; + + virtual ErrCode GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) override; + + virtual ErrCode GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) override; + + virtual ErrCode BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) override; + + virtual ErrCode RegisterUiStateCallback( + const std::string& pkgName) override; + + virtual ErrCode UnRegisterUiStateCallback( + const std::string& pkgName) override; + + virtual ErrCode ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) override; + + virtual ErrCode ExportAuthCode( + std::string& authCode) override; + + virtual ErrCode RegisterPinHolderCallback( + const std::string& pkgName) override; + + virtual ErrCode CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) override; + + virtual ErrCode DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinType, + const std::string& payload) override; + + virtual ErrCode RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + virtual ErrCode UnRegisterDiscoveryCallback( + const std::string& pkgName) override; + + virtual ErrCode StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) override; + + virtual ErrCode StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) override; + + virtual ErrCode StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + virtual ErrCode StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) override; + + virtual ErrCode BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) override; + + virtual ErrCode UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) override; + + virtual ErrCode DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) override; + + virtual ErrCode GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) override; + + virtual ErrCode IsSameAccount( + const std::string& netWorkId, + bool& funcResult) override; + + virtual ErrCode CheckApiPermission( + int32_t permissionLevel) override; + + virtual ErrCode CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + virtual ErrCode CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) override; + + virtual ErrCode ShiftLNNGear( + const std::string& pkgName) override; + + virtual ErrCode SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) override; + + virtual ErrCode GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) override; + + virtual ErrCode GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& networkId) override; + + virtual ErrCode SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) override; + + virtual ErrCode GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) override; + + virtual ErrCode RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) override; + + virtual ErrCode PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) override; + + virtual ErrCode GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) override; + + virtual ErrCode GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) override; + + virtual ErrCode RegisterLocalServiceInfo( + const DmLocalServiceInfoExt& info) override; + + virtual ErrCode UnRegisterLocalServiceInfo( + const std::string& bundleName, + int32_t pinExchangeType) override; + + virtual ErrCode UpdateLocalServiceInfo( + const DmLocalServiceInfoExt& info) override; + + virtual ErrCode GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string& bundleName, + int32_t pinExchangeType, + DmLocalServiceInfoExt& info) override; + + virtual ErrCode RestoreLocalDeviceName( + const std::string& pkgName) override; + + virtual ErrCode GetDeviceNetworkIdList( + const std::string& bundleName, + const NetworkIdQueryFilterExt& queryFilter, + std::vector& networkIds) override; + + +private: + DeviceManagerClientService(); + ~DeviceManagerClientService() override = default; + bool Init(); + void AddSystemSA(const std::string &pkgName); + void RemoveSystemSA(const std::string &pkgName); + +private: + bool registerToService_; + ServiceRunningState state_; + mutable std::mutex listenerLock_; + std::map> appRecipient_; + std::map> dmListener_; + std::set systemSA_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_SERVER_STUB_H diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 4aedfa71e..87ab6ab46 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -803,7 +803,7 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std return DM_OK; } -int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms) +int32_t DeviceManagerService::SetUserOperation(const std::string &pkgName, int32_t action, const std::string ¶ms) { if (!PermissionManager::GetInstance().CheckPermission()) { LOGE("The caller: %{public}s does not have permission to call SetUserOperation.", pkgName.c_str()); @@ -1563,7 +1563,7 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -bool DeviceManagerService::InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, +bool DeviceManagerService::InitDPLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo) { dpLocalServiceInfo.SetBundleName(serviceInfo.bundleName); @@ -1577,7 +1577,7 @@ bool DeviceManagerService::InitDPLocalServiceInfo(const DMLocalServiceInfo &serv } void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo, - DMLocalServiceInfo &serviceInfo) + DmLocalServiceInfo &serviceInfo) { serviceInfo.bundleName = dpLocalServiceInfo.GetBundleName(); serviceInfo.authBoxType = dpLocalServiceInfo.GetAuthBoxType(); @@ -1590,17 +1590,17 @@ void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::Local void DeviceManagerService::InitServiceInfos( const std::vector &dpLocalServiceInfos, - std::vector &serviceInfos) + std::vector &serviceInfos) { for (const auto &dpInfoItem : dpLocalServiceInfos) { - DMLocalServiceInfo infoItem; + DmLocalServiceInfo infoItem; InitServiceInfo(dpInfoItem, infoItem); serviceInfos.emplace_back(infoItem); } } #endif -int32_t DeviceManagerService::RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) +int32_t DeviceManagerService::RegisterLocalServiceInfo(const DmLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1627,7 +1627,7 @@ int32_t DeviceManagerService::UnRegisterLocalServiceInfo(const std::string &bund #endif } -int32_t DeviceManagerService::UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) +int32_t DeviceManagerService::UpdateLocalServiceInfo(const DmLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1644,7 +1644,7 @@ int32_t DeviceManagerService::UpdateLocalServiceInfo(const DMLocalServiceInfo &s } int32_t DeviceManagerService::GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DMLocalServiceInfo &serviceInfo) + int32_t pinExchangeType, DmLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; diff --git a/services/service/src/ipc/standard/device_manager_client_service.cpp b/services/service/src/ipc/standard/device_manager_client_service.cpp new file mode 100644 index 000000000..02b671f27 --- /dev/null +++ b/services/service/src/ipc/standard/device_manager_client_service.cpp @@ -0,0 +1,909 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_manager_client_stub.h" +#include "foundation/distributedhardware/device_manager/services/service/include/ipc/standard/device_manager_client_service.h" +#include "foundation/distributedhardware/device_manager/services/service/include/device_manager_service.h" +#include "if_system_ability_manager.h" +#include "ipc_cmd_register.h" +#include "ipc_skeleton.h" +#include "ipc_types.h" +#include "iservice_registry.h" +#include "foundation/distributedhardware/device_manager/utils/include/dm_ipc_utils.h" +#include "foundation/distributedhardware/device_manager/radar/include/dm_radar_helper.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#endif +#ifdef SUPPORT_MEMMGR +#include "mem_mgr_client.h" +#include "mem_mgr_proxy.h" +#endif // SUPPORT_MEMMGR + +#include "string_ex.h" +#include "system_ability_definition.h" +#include "device_manager_ipc_interface_code.h" +#include "dm_constants.h" +#include "dm_device_info.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +// -------------------------------IPC Service Method-------------------------------- +ErrCode DeviceManagerClientService::GetTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + bool isRefresh, + std::vector& deviceListExt) +{ + std::vector deviceList; + DeviceManagerService service; + int32_t result = service.GetTrustedDeviceList(pkgName, extra, deviceList); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetTrustedDeviceList", + // deviceList, result, anonyLocalUdid_); + LOGI("GetTrustedDeviceList error, failed ret: %{public}d", result); + return result; + } + DmIpcUtils::ConvertToDeviceInfoExtVector(deviceList, deviceListExt); + return result; +} + +ErrCode DeviceManagerClientService::GetLocalDeviceInfo( + const std::string& pkgName, + DmDeviceInfoExt& deviceInfoExt) +{ + (void) pkgName; + DmDeviceInfo localDeviceInfo; + DeviceManagerService service; + int32_t result = service.GetLocalDeviceInfo(localDeviceInfo); + if (result != DM_OK) { + // DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", + // info, result, anonyLocalUdid_); + LOGE("DeviceManagerImpl::GetLocalDeviceInfo error, Send Request failed ret: %{public}d", result); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + DmIpcUtils::ConvertToDeviceInfo(deviceInfoExt, localDeviceInfo); + return result; +} + +ErrCode DeviceManagerClientService::GetUdidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& udid) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.GetUdidByNetworkId(pkgName, netWorkId, udid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetUuidByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + std::string& uuid) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.GetUuidByNetworkId(pkgName, netWorkId, uuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetNetworkTypeByNetworkId( + const std::string& pkgName, + const std::string& netWorkId, + int32_t& netWorkType) +{ + netWorkType = -1; + DeviceManagerService service; + int32_t result = service.GetNetworkTypeByNetworkId(pkgName, netWorkId, netWorkType); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientService::PublishDeviceDiscovery( + const std::string &pkgName, + const DmPublishInfoExt &publishInfoExt) +{ + DmPublishInfo publishInfo; + DmIpcUtils utils; + utils.ConvertToPublishInfo(publishInfoExt, publishInfo); + DeviceManagerService service; + int32_t result = service.PublishDeviceDiscovery(pkgName, publishInfo); + if (result != ERR_OK) + { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "PublishDeviceDiscovery", result, anonyLocalUdid_); + LOGE("PublishDeviceDiscovery error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnPublishDeviceDiscovery( + const std::string& pkgName, + int32_t publishId) +{ + DeviceManagerService service; + int32_t result = service.UnPublishDeviceDiscovery(pkgName, publishId); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnPublishDeviceDiscovery", result, anonyLocalUdid_); + LOGE("UnPublishDeviceDiscovery error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::AuthenticateDevice( + const std::string& pkgName, + int32_t authType, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.AuthenticateDevice(pkgName, authType, deviceId, extra); + if (result != ERR_OK) { + LOGE("AuthenticateDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnAuthenticateDevice( + const std::string& pkgName, + const std::string &netWorkId) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.UnAuthenticateDevice(pkgName, netWorkId); + if (result != ERR_OK) { + LOGE("UnAuthenticateDevice error: Failed with ret %{public}d", result); + // SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_FAILED), DM_HISYEVENT_BEHAVIOR, + // std::string(UNAUTHENTICATE_DEVICE_FAILED_MSG)); + } + return result; +} + +ErrCode DeviceManagerClientService::StopAuthenticateDevice( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.StopAuthenticateDevice(pkgName); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", result, anonyLocalUdid_); + LOGE("StopAuthenticateDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + DeviceManagerService service; + int32_t result = service.CheckCredential(pkgName, reqJsonStr, returnJsonStr); + if (result != ERR_OK) { + LOGE("failed to get return errcode while Check credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::SetUserOperation( + const std::string& pkgName, + int32_t action, + const std::string& params) +{ + DeviceManagerService service; + int32_t result = service.SetUserOperation(pkgName, action, params); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RequestCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + int32_t result = ERR_DM_FAILED; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.RequestCredential(requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStr); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.MineRequestCredential(pkgName, returnJsonStr); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while request credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::ImportCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + std::unordered_map outputResult; + int32_t result = ERR_DM_FAILED; + std::string returnJsonStrTemp; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.ImportCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR]); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.ImportCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStrTemp); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); + outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStrTemp); + } + if (result == ERR_OK && !returnJsonStrTemp.empty()) { + returnJsonStr = ConvertMapToJsonString(outputResult); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while import credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::DeleteCredential( + const std::string& pkgName, + const std::string& reqJsonStr, + std::string& returnJsonStr) +{ + std::unordered_map requestParam; + ParseMapFromJsonString(reqJsonStr, requestParam); + std::unordered_map outputResult; + std::string returnJsonStrTemp; + int32_t result = ERR_DM_FAILED; + DeviceManagerService service; + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) { + result = service.DeleteCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR]); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); + } + if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) { + result = service.DeleteCredential(pkgName, requestParam[DM_CREDENTIAL_REQJSONSTR], + returnJsonStrTemp); + outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); + outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStrTemp); + } + if (result == ERR_OK && !returnJsonStrTemp.empty()) { + returnJsonStr = ConvertMapToJsonString(outputResult); + } + if (result != ERR_OK) { + LOGE("failed to get return errcode while delete credential."); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterCredentialCallback( + const std::string& pkgName) +{ + int result = ERR_OK; + DeviceManagerService service; + result = service.RegisterCredentialCallback(pkgName); + if (result != ERR_OK) { + LOGE("RegisterCredentialCallback error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterCredentialCallback( + const std::string& pkgName) +{ + DeviceManagerService service; + int result = service.UnRegisterCredentialCallback(pkgName); + if (result != ERR_OK) { + LOGE("UnRegisterCredentialCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::NotifyEvent( + const std::string& pkgName, + int32_t eventId, + const std::string& event) +{ + DeviceManagerService service; + int32_t result = service.NotifyEvent(pkgName, eventId, event); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", result, anonyLocalUdid_); + LOGE("NotifyEvent failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceInfo( + const std::string& pkgName, + const std::string& networkId, + DmDeviceInfoExt& deviceInfoExt) +{ + DmDeviceInfo deviceInfo; + DeviceManagerService service; + int32_t result = service.GetDeviceInfo(networkId, deviceInfo); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", + // deviceInfo, result, anonyLocalUdid_); + LOGE("DeviceManagerImpl::GetDeviceInfo error, failed ret: %{public}d", result); + return result; + } + return result; +} + +ErrCode DeviceManagerClientService::GetEncryptedUuidByNetworkId( + const std::string& pkgName, + const std::string& networkId, + std::string& uuid) +{ + DeviceManagerService service; + int32_t result = service.GetEncryptedUuidByNetworkId(pkgName, networkId, uuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GenerateEncryptedUuid( + const std::string& pkgName, + const std::string& uuid, + const std::string& appId, + std::string& encryptedUuid) +{ + DeviceManagerService service; + int32_t result = service.GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); + if (result != ERR_OK) { + LOGE("CheckAuthentication Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::BindDevice( + const std::string& pkgName, + int32_t bindType, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.BindDevice(pkgName, bindType, deviceId, extra); + if (result != ERR_OK) { + LOGE("BindDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnBindDevice( + const std::string& pkgName, + const std::string& deviceId, + const std::string& extra) +{ + int32_t result; + DeviceManagerService service; + if (extra == "") { + result = service.UnBindDevice(pkgName, deviceId); + } else { + result = service.UnBindDevice(pkgName, deviceId, extra); + } + if (result != ERR_OK) { + LOGE("UnBindDevice error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterUiStateCallback( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.RegisterUiStateCallback(pkgName); + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterUiStateCallback", result, anonyLocalUdid_); + LOGE("RegisterUiStateCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterUiStateCallback( + const std::string& pkgName) +{ + int32_t result = ERR_OK; + DeviceManagerService service; + result = service.UnRegisterUiStateCallback(pkgName); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnRegisterUiStateCallback", result, anonyLocalUdid_); + LOGE("UnRegisterUiStateCallback Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ImportAuthCode( + const std::string& pkgName, + const std::string& authCode) +{ + DeviceManagerService service; + int32_t result = service.ImportAuthCode(pkgName, authCode); + if (result != ERR_OK) { + LOGE("ImportAuthCode Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ExportAuthCode( + std::string& authCode) +{ + DeviceManagerService service; + int32_t result = service.ExportAuthCode(authCode); + if (result != ERR_OK) { + LOGE("ExportAuthCode Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterPinHolderCallback( + const std::string& pkgName) +{ + DeviceManagerService service; + int32_t result = service.RegisterPinHolderCallback(pkgName); + if (result != DM_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", result, anonyLocalUdid_); // TODO anonyLocalUdid_ + LOGE("RegisterPinHolderCallback Failed with ret %{public}d", result); + } + return ERR_OK; +} + +ErrCode DeviceManagerClientService::CreatePinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) +{ + PeerTargetId targetId; + DmIpcUtils utils; + utils.ConvertToPeerTargetId(targetIdExt, targetId); + DmPinType pinType = static_cast(pinTypeInt); + DeviceManagerService service; + int32_t result = service.CreatePinHolder(pkgName, targetId, pinType, payload); + if (result != ERR_OK) { + LOGE("CreatePinHolder Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::DestroyPinHolder( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + int32_t pinTypeInt, + const std::string& payload) +{ + PeerTargetId targetId; + DmIpcUtils utils; + utils.ConvertToPeerTargetId(targetIdExt, targetId); + DmPinType pinType = static_cast(pinTypeInt); + DeviceManagerService service; + int32_t result = service.DestroyPinHolder(pkgName, targetId, pinType, payload); + return ERR_OK; +} + +ErrCode DeviceManagerClientService::RegisterDiscoveryCallback( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + DeviceManagerService service; + int32_t result = service.EnableDiscoveryListener(pkgName, discoverParam, filterOptions); + if (result != ERR_OK) { + LOGE("RegisterDiscoveryCallback error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterDiscoveryCallback( + const std::string& pkgName) +{ + // int32_t result = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam); + // if (result != ERR_OK) { + // // DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", + // // result, anonyLocalUdid_); + // LOGE("UnRegisterDiscoveryCallback error: Failed with ret %{public}d", result); + // } + return DM_OK; +} + +ErrCode DeviceManagerClientService::StartDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam, + const std::unordered_map& filterOptions) +{ + DeviceManagerService service; + int32_t result = service.StartDiscovering(pkgName, discoverParam, filterOptions); + if (result != ERR_OK) { + LOGE("StartDiscovering error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StopDiscovering( + const std::string& pkgName, + const std::unordered_map& discoverParam) +{ + DeviceManagerService service; + int32_t result = service.StopDiscovering(pkgName, discoverParam); + if (result != ERR_OK) { + LOGE("StopDiscovering error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StartAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + std::unordered_map advertiseParam; + ParseMapFromJsonString(adverParaStr, advertiseParam); + DeviceManagerService service; + int32_t result = service.StartAdvertising(pkgName, adverParaStr); + if (result != ERR_OK) { + LOGE("StartAdvertising error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::StopAdvertising( + const std::string& pkgName, + const std::string& adverParaStr) +{ + DeviceManagerService service; + int32_t result = service.StopAdvertising(pkgName, adverParaStr); + if (result != ERR_OK) { + LOGE("StopAdvertising error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::BindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& bindParam) +{ + PeerTargetId targetId; + DmIpcUtils::ConvertToPeerTargetId(targetIdExt, targetId); + DeviceManagerService service; + int32_t result = service.BindTarget(pkgName, targetId, bindParam); + if (result != ERR_OK) { + LOGE("BindTarget error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnbindTarget( + const std::string& pkgName, + const PeerTargetIdExt& targetIdExt, + const std::string& unbindParam) +{ + PeerTargetId targetId; + DmIpcUtils::ConvertToPeerTargetId(targetIdExt, targetId); + DeviceManagerService service; + int32_t result = service.UnbindTarget(pkgName, targetId, unbindParam); + if (result != ERR_OK) { + LOGE("UnbindTarget error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::DpAclAdd( + int64_t accessControlId, + const std::string& udid, + int32_t bindType) +{ + DeviceManagerService service; + int32_t result = service.DpAclAdd(udid); + if (result != ERR_OK) { + LOGE("DpAclAdd error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceSecurityLevel( + const std::string& pkgName, + const std::string& networkId, + int32_t& securityLevel) +{ + securityLevel = -1; + DeviceManagerService service; + int32_t result = service.GetDeviceSecurityLevel(pkgName, networkId, securityLevel); + if (result != DM_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", result, anonyLocalUdid_); + LOGE("GetDeviceSecurityLevel Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::IsSameAccount( + const std::string& netWorkId, bool& funcResult) +{ + DeviceManagerService service; + int32_t result = service.IsSameAccount(netWorkId); + if (result != ERR_OK) { + LOGE("IsSameAccount Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckApiPermission( + int32_t permissionLevel) +{ + DeviceManagerService service; + int32_t result = service.CheckApiPermission(permissionLevel); + if (result != ERR_OK) { + LOGE("Check permission failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckAccessControl( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DmIpcUtils::ConvertToDmAccessCaller(callerExt, caller); + DmIpcUtils::ConvertToDmAccessCallee(calleeExt, callee); + DeviceManagerService service; + int32_t result = service.CheckAccessControl(caller, callee); + funcResult = result == 1 ? true : false; + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", result, anonyLocalUdid_); + LOGE("CheckAccessControl Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::CheckIsSameAccount( + const DmAccessCallerExt& callerExt, + const DmAccessCalleeExt& calleeExt, + bool& funcResult) +{ + DmAccessCaller caller; + DmAccessCallee callee; + DmIpcUtils::ConvertToDmAccessCaller(callerExt, caller); + DmIpcUtils::ConvertToDmAccessCallee(calleeExt, callee); + DeviceManagerService service; + int32_t result = service.CheckIsSameAccount(caller, callee); + funcResult = result == 1 ? true : false; + if (result != ERR_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", result, anonyLocalUdid_); + LOGE("CheckIsSameAccount Failed with ret: %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::ShiftLNNGear( + const std::string& pkgName) +{ + DeviceManagerService service; + int32_t result = service.ShiftLNNGear(pkgName, pkgName, true, true); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", result, anonyLocalUdid_); + LOGE("ShiftLNNGear error: Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::SetDnPolicy( + const std::string& pkgName, + const std::unordered_map& policy) +{ + DeviceManagerService service; + int32_t result = service.SetDnPolicy(pkgName, policy); + if (result != ERR_OK) { + //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", result, anonyLocalUdid_); + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetDeviceScreenStatus( + const std::string& pkgName, + const std::string& networkId, + int32_t& screenStatus) +{ + screenStatus = -1; + DeviceManagerService service; + int32_t result = service.GetDeviceScreenStatus(pkgName, networkId, screenStatus); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetNetworkIdByUdid( + const std::string& pkgName, + const std::string& udid, + std::string& netWorkId) +{ + DeviceManagerService service; + int32_t result = service.GetNetworkIdByUdid(pkgName, udid, netWorkId); + if (result != ERR_OK) { + LOGE("GetNetworkIdByUdid Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::SyncCallbackToService( + int32_t dmCommonNotifyEvent, + const std::string& pkgName) +{ + // ProcessInfo processInfo; + // processInfo.pkgName = pkgName; + // MultipleUserConnector::GetCallerUserId(processInfo.userId); + // int32_t result = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfo); + // if (dmCommonNotifyEvent == static_cast(DmCommonNotifyEvent::REG_DEVICE_STATE)) { + // DeviceManagerService::GetInstance().RegDevStateCallbackToService(pkgName); + // } + // if (result != ERR_OK) { + // LOGE("Failed with ret %{public}d", result); + // } + return DM_OK; +} + +ErrCode DeviceManagerClientService::GetAnonyLocalUdid( + const std::string& pkgName, + std::string& anonyUdid) +{ + DeviceManagerService service; + int32_t result = service.GetAnonyLocalUdid(pkgName, anonyUdid); + if (result != ERR_OK) { + LOGE("GetAnonyLocalUdid Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterAuthenticationType( + const std::string& pkgName, + const std::string& authTypeStr) +{ + // int32_t result = DeviceManagerService::GetInstance().RegisterAuthenticationType(pkgName, authParam); + // if (result != ERR_OK) { + // LOGE("Failed with ret %{public}d", result); + // } + //return result; + return DM_OK; +} + +ErrCode DeviceManagerClientService::PutDeviceProfileInfoList( + const std::string& pkgName, + const std::vector& deviceProfileInfoListExt) +{ + DeviceManagerService service; + std::vector deviceProfileInfoList; + int32_t result = service.PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetLocalDisplayDeviceName( + const std::string& pkgName, + int32_t maxNameLength, + std::string& displayName) +{ + DeviceManagerService service; + int32_t result = service.GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetAllTrustedDeviceList( + const std::string& pkgName, + const std::string& extra, + std::vector& deviceListExt) +{ + std::vector deviceList; + DeviceManagerService service; + int32_t result = service.GetAllTrustedDeviceList(pkgName, extra, deviceList); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RegisterLocalServiceInfo( + const DmLocalServiceInfoExt& info) +{ + DeviceManagerService service; + int32_t result = service.RegisterLocalServiceInfo(info); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UnRegisterLocalServiceInfo( + const std::string &bundleName, int32_t pinExchangeType) +{ + DeviceManagerService service; + int32_t result = service.UnRegisterLocalServiceInfo(bundleName,pinExchangeType); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::UpdateLocalServiceInfo( + const DmLocalServiceInfoExt& info) +{ + DmLocalServiceInfoExt serviceInfo; + DmIpcUtils::ConvertToDmLocalServiceInfo(info, serviceInfo); + DeviceManagerService service; + int32_t result = service.UpdateLocalServiceInfo(info); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfoExt &info) +{ + DmLocalServiceInfoExt serviceInfo; + DmIpcUtils::ConvertToDmLocalServiceInfo(serviceInfo, info); + DeviceManagerService service; + int32_t result = service.GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, pinExchangeType,info); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} + +ErrCode DeviceManagerClientService::RestoreLocalDeviceName( + const std::string &pkgName) +{ + DeviceManagerService service; + int32_t result = service.RestoreLocalDeviceName(pkgName); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return DM_OK; +} +ErrCode DeviceManagerClientService::GetDeviceNetworkIdList( + const std::string &bundleName, + const NetworkIdQueryFilterExt &queryFilter, + std::vector &networkIds) +{ + DeviceManagerService service; + int32_t result = service.GetDeviceNetworkIdList(bundleName,queryFilter,networkIds); + if (result != ERR_OK) { + LOGE("Failed with ret %{public}d", result); + } + return result; +} +} // 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 607e50b9f..4f5d23458 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -958,7 +958,7 @@ ON_IPC_CMD(START_ADVERTISING, MessageParcel &data, MessageParcel &reply) std::string adverParaStr = data.ReadString(); std::map advertiseParam; ParseMapFromJsonString(adverParaStr, advertiseParam); - int32_t result = DeviceManagerService::GetInstance().StartAdvertising(pkgName, advertiseParam); + int32_t result = DeviceManagerService::GetInstance().StartAdvertising(pkgName, adverParaStr); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -972,7 +972,7 @@ ON_IPC_CMD(STOP_ADVERTISING, MessageParcel &data, MessageParcel &reply) std::string adverParaStr = data.ReadString(); std::map advertiseParam; ParseMapFromJsonString(adverParaStr, advertiseParam); - int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName, advertiseParam); + int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName, adverParaStr); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -988,7 +988,7 @@ ON_IPC_CMD(BIND_TARGET, MessageParcel &data, MessageParcel &reply) std::string bindParamStr = data.ReadString(); std::map bindParam; ParseMapFromJsonString(bindParamStr, bindParam); - int32_t result = DeviceManagerService::GetInstance().BindTarget(pkgName, targetId, bindParam); + int32_t result = DeviceManagerService::GetInstance().BindTarget(pkgName, targetId, bindParamStr); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1004,7 +1004,7 @@ ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply) std::string unbindParamStr = data.ReadString(); std::map unbindParam; ParseMapFromJsonString(unbindParamStr, unbindParam); - int32_t result = DeviceManagerService::GetInstance().UnbindTarget(pkgName, targetId, unbindParam); + int32_t result = DeviceManagerService::GetInstance().UnbindTarget(pkgName, targetId, unbindParamStr); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1739,7 +1739,7 @@ ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &re ON_IPC_CMD(REG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - DMLocalServiceInfo serviceInfo; + DmLocalServiceInfo serviceInfo; IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); int32_t result = DeviceManagerService::GetInstance().RegisterLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { @@ -1763,7 +1763,7 @@ ON_IPC_CMD(UNREG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) ON_IPC_CMD(UPDATE_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - DMLocalServiceInfo serviceInfo; + DmLocalServiceInfo serviceInfo; IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); int32_t result = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { @@ -1777,7 +1777,7 @@ ON_IPC_CMD(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &data, Me { std::string bundleName = data.ReadString(); int32_t pinExchangeType = data.ReadInt32(); - DMLocalServiceInfo serviceInfo; + DmLocalServiceInfo serviceInfo; int32_t result = DeviceManagerService::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( bundleName, pinExchangeType, serviceInfo); if (!reply.WriteInt32(result)) { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 56deeecf3..7006a8083 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -132,6 +132,7 @@ if (defined(ohos_lite)) { "src/kvadapter/kv_adapter.cpp", "src/kvadapter/kv_adapter_manager.cpp", "src/timer/dm_timer.cpp", + "src/dm_ipc_utils.cpp", ] if (support_jsapi) { diff --git a/utils/include/dm_ipc_utils.h b/utils/include/dm_ipc_utils.h new file mode 100644 index 000000000..56e7d2638 --- /dev/null +++ b/utils/include/dm_ipc_utils.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_DM_IPC_UTILS_H +#define OHOS_DM_IPC_UTILS_H + +#include +#include "dm_device_info.h" +#include "dm_publish_info.h" +#include "dm_device_profile_info.h" +namespace OHOS { +namespace DistributedHardware { + +class DmIpcUtils { +public: + static void ConvertToDeviceInfoVector(const std::vector& extVector, std::vector& baseVector); + static void ConvertToDeviceInfoExtVector(const std::vector& baseVector, std::vector& extVector); + static void ConvertToPublishInfo(const DmPublishInfoExt& ext, DmPublishInfo& base); + static void ConvertToDeviceInfo(const DmDeviceInfoExt& ext, DmDeviceInfo& base); + static void ConvertToPeerTargetId(const PeerTargetIdExt& ext, PeerTargetId& base); + static void ConvertToDmAccessCaller(const DmAccessCallerExt& ext, DmAccessCaller& base); + static void ConvertToDmAccessCallee(const DmAccessCalleeExt& ext, DmAccessCallee& base); + static void ConvertToDmDeviceProfileInfoVector(const std::vector& deviceProfileInfoListExt, + std::vector &deviceProfileInfoList); + static void ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos); + static void ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, DmLocalServiceInfo& base); + static std::map DoubleStringConvertToMap(const std::unordered_map &base); + static std::unordered_map StringIntConvertToUMap(const std::map &base); +}; + +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DM_IPC_UTILS_H \ No newline at end of file diff --git a/utils/src/dm_ipc_utils.cpp b/utils/src/dm_ipc_utils.cpp new file mode 100644 index 000000000..3b9a0af39 --- /dev/null +++ b/utils/src/dm_ipc_utils.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "dm_ipc_utils.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmIpcUtils::ConvertToDeviceInfoVector(const std::vector& extVector, std::vector& baseVector) +{ + baseVector.clear(); + baseVector.reserve(extVector.size()); // 预留空间以避免多次分配内存 + + for (const auto& ext : extVector) { + DmDeviceInfo base; + memcpy(base.deviceId, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(base.deviceName, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy(base.networkId, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.range = ext.range; + base.networkType = ext.networkType; + base.authForm = ext.authForm; + base.extraData = ext.extraData; + baseVector.push_back(base); + } +} + +void DmIpcUtils::ConvertToDeviceInfoExtVector(const std::vector& baseVector, std::vector& extVector) +{ + extVector.clear(); + extVector.reserve(baseVector.size()); // 预留空间以避免多次分配内存 + + for (const auto& base : baseVector) { + DmDeviceInfoExt ext; + memcpy(ext.deviceId, base.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(ext.deviceName, base.deviceName, DM_MAX_DEVICE_NAME_LEN); + ext.deviceTypeId = base.deviceTypeId; + memcpy(ext.networkId, base.networkId, DM_MAX_DEVICE_ID_LEN); + ext.range = base.range; + ext.networkType = base.networkType; + ext.authForm = base.authForm; + ext.extraData = base.extraData; + extVector.push_back(ext); + } +} + +void DmIpcUtils::ConvertToPublishInfo(const DmPublishInfoExt& ext, DmPublishInfo& base) +{ + base.publishId = ext.publishId; + base.mode = ext.mode; + base.freq = ext.freq; + base.ranging = ext.ranging; +} + +void DmIpcUtils::ConvertToDeviceInfo(const DmDeviceInfoExt& ext, DmDeviceInfo& base) +{ + memcpy(base.deviceId, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy(base.deviceName, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy(base.networkId, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.range = ext.range; + base.networkType = ext.networkType; + base.authForm = ext.authForm; + base.extraData = ext.extraData; +} + +void DmIpcUtils::ConvertToPeerTargetId(const PeerTargetIdExt& ext, PeerTargetId& base) +{ + base.deviceId = ext.deviceId; + base.brMac = ext.brMac; + base.bleMac = ext.bleMac; + base.wifiIp = ext.wifiIp; + base.wifiPort = ext.wifiPort; +} + +void DmIpcUtils::ConvertToDmAccessCaller(const DmAccessCallerExt& ext, DmAccessCaller& base) +{ + base.accountId = ext.accountId; + base.pkgName = ext.pkgName; + base.networkId = ext.networkId; + base.userId = ext.userId; + base.tokenId = ext.tokenId; + base.extra = ext.extra; +} + +void DmIpcUtils::ConvertToDmAccessCallee(const DmAccessCalleeExt& ext, DmAccessCallee& base) +{ + base.accountId = ext.accountId; + base.networkId = ext.networkId; + base.peerId = ext.peerId; + base.userId = ext.userId; + base.extra = ext.extra; +} + +void DmIpcUtils::ConvertToDmDeviceProfileInfoVector(const std::vector& deviceProfileInfoListExt, + std::vector &deviceProfileInfoList) +{ + deviceProfileInfoList.clear(); + deviceProfileInfoList.reserve(deviceProfileInfoListExt.size()); + for (const auto& ext : deviceProfileInfoListExt) { + DmDeviceProfileInfo base; + base.deviceId = ext.deviceId; + base.deviceSn = ext.deviceSn; + base.mac = ext.mac; + base.model = ext.model; + base.internalModel = ext.internalModel; + base.deviceType = ext.deviceType; + base.manufacturer = ext.manufacturer; + base.deviceName = ext.deviceName; + base.productId = ext.productId; + base.subProductId = ext.subProductId; + base.sdkVersion = ext.sdkVersion; + base.bleMac = ext.bleMac; + base.brMac = ext.brMac; + base.sleMac = ext.sleMac; + base.firmwareVersion = ext.firmwareVersion; + base.hardwareVersion = ext.hardwareVersion; + base.softwareVersion = ext.softwareVersion; + base.protocolType = ext.protocolType; + base.setupType = ext.setupType; + base.wiseDeviceId = ext.wiseDeviceId; + base.wiseUserId = ext.wiseUserId; + base.registerTime = ext.registerTime; + base.modifyTime = ext.modifyTime; + base.shareTime = ext.shareTime; + base.isLocalDevice = ext.isLocalDevice; + } +} + +void DmIpcUtils::ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos) +{ + serviceInfos.clear(); + serviceInfos.reserve(serviceInfoExt.size()); + for (const auto& ext : serviceInfoExt) { + DmLocalServiceInfo base; + base.bundleName = ext.bundleName; + base.authBoxType = ext.authBoxType; + base.authType = ext.authType; + base.pinExchangeType = ext.pinExchangeType; + base.pinCode = ext.pinCode; + base.description = ext.description; + base.extraInfo = ext.extraInfo; + } +} + +void DmIpcUtils::ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, DmLocalServiceInfo& base) +{ + + base.bundleName = ext.bundleName; + base.authBoxType = ext.authBoxType; + base.authType = ext.authType; + base.pinExchangeType = ext.pinExchangeType; + base.pinCode = ext.pinCode; + base.description = ext.description; + base.extraInfo = ext.extraInfo; +} +std::map DmIpcUtils::DoubleStringConvertToMap(const std::unordered_map &base) +{ + return std::map(base.begin(), base.end()); +} +std::unordered_map DmIpcUtils::StringIntConvertToUMap(const std::map &base) +{ + return std::unordered_map(base.begin(), base.end()); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee From 603e628d2ccbedfd275e33d5e1f641e172034112 Mon Sep 17 00:00:00 2001 From: Sly <1298008151@qq.com> Date: Mon, 14 Apr 2025 15:11:34 +0800 Subject: [PATCH 3/5] Instead of proxy by idl. Signed-off-by: Sly <1298008151@qq.com> Change-Id: I3b7a30eed43a2af69b8cb46d68fefdacb00476b4 --- .../include/idevice_manager_client.h | 29 +- .../native_cpp/src/device_manager_impl.cpp | 1182 +++++++++-------- .../standard/device_manager_client_service.h | 2 +- .../device_manager_client_service.cpp | 6 +- utils/include/dm_ipc_utils.h | 1 + utils/src/dm_ipc_utils.cpp | 9 + 6 files changed, 634 insertions(+), 595 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h index 8adbec350..5ae075b44 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h @@ -345,21 +345,30 @@ public: const std::string& extra, std::vector& deviceListExt) = 0; - virtual ErrCode RegisterServiceInfo( + virtual ErrCode RegisterLocalServiceInfo( const DmLocalServiceInfoExt& info) = 0; - virtual ErrCode UnRegisterServiceInfo( - int64_t serviceId) = 0; + virtual ErrCode UnRegisterLocalServiceInfo( + const std::string &bundleName, + int32_t pinExchangeType) = 0; - virtual ErrCode UpdateServiceInfo( + virtual ErrCode UpdateLocalServiceInfo( const DmLocalServiceInfoExt& info) = 0; - virtual ErrCode GetServiceInfoByServiceId( - int64_t serviceId, - DmLocalServiceInfoExt& serviceInfoExt) = 0; - - virtual ErrCode GetCallerServiceInfos( - std::vector& serviceInfoExt) = 0; + virtual ErrCode GetLocalServiceInfoByBundleNameAndPinExchangeType( + const std::string &bundleName, + int32_t pinExchangeType, + DmLocalServiceInfoExt &info) = 0; + + virtual ErrCode RestoreLocalDeviceName( + const std::string &pkgName) = 0; + + virtual ErrCode GetDeviceNetworkIdList( + const std::string &bundleName, + const NetworkIdQueryFilterExt &queryFilter, + std::vector &networkIds) = 0; + + protected: static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD004111, "distributedhardware"}; const int VECTOR_MAX_SIZE = 102400; 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 4940c8e07..80880288f 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -328,11 +328,12 @@ int32_t DeviceManagerImpl::GetDeviceInfo(const std::string &pkgName, const std:: } LOGI("Start, pkgName: %{public}s networKId : %{public}s", pkgName.c_str(), GetAnonyString(networkId).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetNetWorkId(networkId); - int32_t ret = ipcClientProxy_->SendRequest(GET_DEVICE_INFO, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetNetWorkId(networkId); + DmDeviceInfoExt dmDeviceInfoExt(deviceInfo); + int32_t ret = deviceManagerInterface_->GetDeviceInfo(pkgName, networkId, dmDeviceInfoExt); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", deviceInfo, ret, anonyLocalUdid_); @@ -340,16 +341,16 @@ int32_t DeviceManagerImpl::GetDeviceInfo(const std::string &pkgName, const std:: return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", - deviceInfo, ret, anonyLocalUdid_); - LOGE("DeviceManagerImpl::GetDeviceInfo error, failed ret: %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", + // deviceInfo, ret, anonyLocalUdid_); + // LOGE("DeviceManagerImpl::GetDeviceInfo error, failed ret: %{public}d", ret); + // return ret; + // } - deviceInfo = rsp->GetDeviceInfo(); - LOGI("Completed, networKId = %{public}s deviceName = %{public}s", GetAnonyString(req->GetNetWorkId()).c_str(), + // deviceInfo = rsp->GetDeviceInfo(); + LOGI("Completed, networKId = %{public}s deviceName = %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str()); DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", deviceInfo, DM_OK, anonyLocalUdid_); @@ -566,21 +567,21 @@ int32_t DeviceManagerImpl::StartDiscovering(const std::string &pkgName, discoverParam.emplace(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId)); std::string discParaStr = ConvertMapToJsonString(discoverParam); std::string filterOpStr = ConvertMapToJsonString(filterOptions); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(ComposeStr(pkgName, subscribeId)); - req->SetFirstParam(discParaStr); - req->SetSecondParam(filterOpStr); - int32_t ret = ipcClientProxy_->SendRequest(START_DISCOVERING, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(ComposeStr(pkgName, subscribeId)); + // req->SetFirstParam(discParaStr); + // req->SetSecondParam(filterOpStr); + int32_t ret = deviceManagerInterface_->StartDiscovering(pkgName, discoverParam, filterOptions); if (ret != DM_OK) { LOGE("StartDiscovering error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("StartDiscovering error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("StartDiscovering error: Failed with ret %{public}d", ret); + // return ret; + // } DmTraceEnd(); LOGI("Completed"); @@ -610,20 +611,20 @@ int32_t DeviceManagerImpl::StopDiscovering(const std::string &pkgName, discoverParam.emplace(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId)); std::string discParaStr = ConvertMapToJsonString(discoverParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(ComposeStr(pkgName, subscribeId)); - req->SetFirstParam(discParaStr); - int32_t ret = ipcClientProxy_->SendRequest(STOP_DISCOVERING, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(ComposeStr(pkgName, subscribeId)); + // req->SetFirstParam(discParaStr); + int32_t ret = deviceManagerInterface_->StopDiscovering(pkgName, discoverParam); if (ret != DM_OK) { LOGE("StopDiscovering error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("StopDiscovering error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("StopDiscovering error: Failed with ret %{public}d", ret); + // return ret; + // } RemoveDiscoveryCallback(pkgNameTemp); LOGI("Completed"); return DM_OK; @@ -647,8 +648,8 @@ int32_t DeviceManagerImpl::PublishDeviceDiscovery(const std::string &pkgName, co // req->SetPkgName(pkgName); // req->SetPublishInfo(publishInfo); DmPublishInfoExt publishInfoExt; + DmIpcUtils::ConvertToPublishInfo(publishInfo, publishInfoExt); int32_t ret = deviceManagerInterface_->PublishDeviceDiscovery(pkgName, publishInfoExt); - DmIpcUtils::ConvertToPublishInfo(publishInfoExt, publishInfo); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "PublishDeviceDiscovery", ret, anonyLocalUdid_); LOGE("PublishDeviceDiscovery error: Send Request failed ret: %{public}d", ret); @@ -762,18 +763,18 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons // req->SetPkgName(pkgName); // req->SetDeviceInfo(deviceInfo); std::string strDeviceId = deviceInfo.deviceId; - int32_t ret = deviceManagerInterface_->UnAuthenticateDevice(pkgName, deviceId); + int32_t ret = deviceManagerInterface_->UnAuthenticateDevice(pkgName, strDeviceId); if (ret != DM_OK) { LOGE("UnAuthenticateDevice error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("UnAuthenticateDevice error: Failed with ret %{public}d", ret); - SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_FAILED), DM_HISYEVENT_BEHAVIOR, - std::string(UNAUTHENTICATE_DEVICE_FAILED_MSG)); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("UnAuthenticateDevice error: Failed with ret %{public}d", ret); + // SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_FAILED), DM_HISYEVENT_BEHAVIOR, + // std::string(UNAUTHENTICATE_DEVICE_FAILED_MSG)); + // return ret; + // } SysEventWrite(std::string(UNAUTHENTICATE_DEVICE_SUCCESS), DM_HISYEVENT_BEHAVIOR, std::string(UNAUTHENTICATE_DEVICE_SUCCESS_MSG)); @@ -790,21 +791,21 @@ int32_t DeviceManagerImpl::StopAuthenticateDevice(const std::string &pkgName) return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(STOP_AUTHENTICATE_DEVICE, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + int32_t ret = deviceManagerInterface_->StopAuthenticateDevice(pkgName); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", ret, anonyLocalUdid_); LOGE("StopAuthenticateDevice error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", ret, anonyLocalUdid_); - LOGE("StopAuthenticateDevice error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", ret, anonyLocalUdid_); + // LOGE("StopAuthenticateDevice error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; @@ -873,23 +874,23 @@ int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetOperation(action); - req->SetParams(params); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetOperation(action); + // req->SetParams(params); - int32_t ret = ipcClientProxy_->SendRequest(SERVER_USER_AUTH_OPERATION, req, rsp); + int32_t ret = deviceManagerInterface_->SetUserOperation(pkgName, action, params); if (ret != DM_OK) { LOGI("SetUserOperation Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("CheckAuthentication Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("CheckAuthentication Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -1043,24 +1044,24 @@ int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, const s std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); - int32_t ret = ipcClientProxy_->SendRequest(REQUEST_CREDENTIAL, req, rsp); + int32_t ret = deviceManagerInterface_->RequestCredential(pkgName, reqJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("RequestCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while request credential."); - return ret; - } - returnJsonStr = rsp->GetCredentialResult(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while request credential."); + // return ret; + // } + // returnJsonStr = rsp->GetCredentialResult(); LOGI("request device credential completed."); return DM_OK; } @@ -1076,23 +1077,23 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, credentialInfo); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); - - int32_t ret = ipcClientProxy_->SendRequest(IMPORT_CREDENTIAL, req, rsp); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); + std::string returnJsonStr; + int32_t ret = deviceManagerInterface_->ImportCredential(pkgName, returnJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("ImportCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while import credential."); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while import credential."); + // return ret; + // } LOGI("import credential to device completed."); return DM_OK; } @@ -1108,23 +1109,23 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, deleteInfo); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); - - int32_t ret = ipcClientProxy_->SendRequest(DELETE_CREDENTIAL, req, rsp); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); + std::string returnJsonStr; + int32_t ret = deviceManagerInterface_->DeleteCredential(pkgName, returnJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("DeleteCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while import credential."); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while import credential."); + // return ret; + // } LOGI("delete credential from device completed."); return DM_OK; } @@ -1139,21 +1140,21 @@ int32_t DeviceManagerImpl::RegisterCredentialCallback(const std::string &pkgName LOGI("Start, pkgName: %{public}s", pkgName.c_str()); DeviceManagerNotify::GetInstance().RegisterCredentialCallback(pkgName, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(REGISTER_CREDENTIAL_CALLBACK, req, rsp); + int32_t ret = deviceManagerInterface_->RegisterCredentialCallback(pkgName); if (ret != DM_OK) { LOGI("RegisterCredentialCallback Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("RegisterCredentialCallback error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("RegisterCredentialCallback error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); return DM_OK; } @@ -1167,21 +1168,21 @@ int32_t DeviceManagerImpl::UnRegisterCredentialCallback(const std::string &pkgNa LOGI("Start, pkgName: %{public}s", pkgName.c_str()); DeviceManagerNotify::GetInstance().UnRegisterCredentialCallback(pkgName); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(UNREGISTER_CREDENTIAL_CALLBACK, req, rsp); + int32_t ret = deviceManagerInterface_->UnRegisterCredentialCallback(pkgName); if (ret != DM_OK) { LOGI("UnRegisterCredentialCallback Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("UnRegisterCredentialCallback Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("UnRegisterCredentialCallback Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -1201,25 +1202,25 @@ int32_t DeviceManagerImpl::NotifyEvent(const std::string &pkgName, const int32_t return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetEventId(eventId); - req->SetEvent(event); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetEventId(eventId); + // req->SetEvent(event); - int32_t ret = ipcClientProxy_->SendRequest(NOTIFY_EVENT, req, rsp); + int32_t ret = deviceManagerInterface_->NotifyEvent(pkgName, eventId, event); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", ret, anonyLocalUdid_); LOGI("NotifyEvent Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", ret, anonyLocalUdid_); - LOGE("NotifyEvent failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", ret, anonyLocalUdid_); + // LOGE("NotifyEvent failed with ret %{public}d", ret); + // return ret; + // } DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", DM_OK, anonyLocalUdid_); LOGI("Completed"); return DM_OK; @@ -1234,22 +1235,22 @@ int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, std::st LOGI("Start, pkgName: %{public}s", pkgName.c_str()); std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); - int32_t ret = ipcClientProxy_->SendRequest(REQUEST_CREDENTIAL, req, rsp); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); + int32_t ret = deviceManagerInterface_->RequestCredential(pkgName, returnJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("RequestCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while request credential."); - return ret; - } - returnJsonStr = rsp->GetCredentialResult(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while request credential."); + // return ret; + // } + // returnJsonStr = rsp->GetCredentialResult(); LOGI("Completed."); return DM_OK; } @@ -1262,23 +1263,23 @@ int32_t DeviceManagerImpl::CheckCredential(const std::string &pkgName, const std return ERR_DM_INPUT_PARA_INVALID; } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqJsonStr); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqJsonStr); - int32_t ret = ipcClientProxy_->SendRequest(SERVER_GET_DMFA_INFO, req, rsp); + int32_t ret = deviceManagerInterface_->CheckCredential(pkgName, reqJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("CheckCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while Check credential."); - return ret; - } - returnJsonStr = rsp->GetCredentialResult(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while Check credential."); + // return ret; + // } + // returnJsonStr = rsp->GetCredentialResult(); LOGI("Completed."); return DM_OK; } @@ -1294,24 +1295,24 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); - int32_t ret = ipcClientProxy_->SendRequest(IMPORT_CREDENTIAL, req, rsp); + int32_t ret = deviceManagerInterface_->ImportCredential(pkgName, reqJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("ImportCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while import credential."); - return ret; - } - returnJsonStr = rsp->GetCredentialResult(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while import credential."); + // return ret; + // } + // returnJsonStr = rsp->GetCredentialResult(); LOGI("Completed."); return DM_OK; } @@ -1327,24 +1328,24 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); - std::string reqParaStr = ConvertMapToJsonString(requestParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetCredentialParam(reqParaStr); + // std::string reqParaStr = ConvertMapToJsonString(requestParam); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetCredentialParam(reqParaStr); - int32_t ret = ipcClientProxy_->SendRequest(DELETE_CREDENTIAL, req, rsp); + int32_t ret = deviceManagerInterface_->DeleteCredential(pkgName, reqJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("DeleteCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("failed to get return errcode while import credential."); - return ret; - } - returnJsonStr = rsp->GetCredentialResult(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("failed to get return errcode while import credential."); + // return ret; + // } + // returnJsonStr = rsp->GetCredentialResult(); LOGI("Completed."); return DM_OK; } @@ -1370,23 +1371,23 @@ int32_t DeviceManagerImpl::GetEncryptedUuidByNetworkId(const std::string &pkgNam } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetNetWorkId(networkId); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetNetWorkId(networkId); - int32_t ret = ipcClientProxy_->SendRequest(GET_ENCRYPTED_UUID_BY_NETWOEKID, req, rsp); + int32_t ret = deviceManagerInterface_->GetEncryptedUuidByNetworkId(pkgName, networkId, uuid); if (ret != DM_OK) { LOGI("GetEncryptedUuidByNetworkId Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("CheckAuthentication Failed with ret %{public}d", ret); - return ret; - } - uuid = rsp->GetUuid(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("CheckAuthentication Failed with ret %{public}d", ret); + // return ret; + // } + // uuid = rsp->GetUuid(); LOGI("Complete, uuid: %{public}s", GetAnonyString(uuid).c_str()); return DM_OK; } @@ -1400,24 +1401,24 @@ int32_t DeviceManagerImpl::GenerateEncryptedUuid(const std::string &pkgName, con } LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetUuid(uuid); - req->SetAppId(appId); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetUuid(uuid); + // req->SetAppId(appId); - int32_t ret = ipcClientProxy_->SendRequest(GENERATE_ENCRYPTED_UUID, req, rsp); + int32_t ret = deviceManagerInterface_->GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid); if (ret != DM_OK) { LOGI("GenerateEncryptedUuid Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("CheckAuthentication Failed with ret %{public}d", ret); - return ret; - } - encryptedUuid = rsp->GetUuid(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("CheckAuthentication Failed with ret %{public}d", ret); + // return ret; + // } + // encryptedUuid = rsp->GetUuid(); LOGI("Complete, encryptedUuid: %{public}s", GetAnonyString(encryptedUuid).c_str()); return DM_OK; } @@ -1550,23 +1551,24 @@ int32_t DeviceManagerImpl::BindDevice(const std::string &pkgName, int32_t bindTy paramJson[TOKENID] = std::to_string(OHOS::IPCSkeleton::GetSelfTokenID()); #endif DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetBindParam(SafetyDump(paramJson)); - req->SetBindType(bindType); - req->SetDeviceId(deviceId); - int32_t ret = ipcClientProxy_->SendRequest(BIND_DEVICE, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetBindParam(SafetyDump(paramJson)); + // req->SetBindType(bindType); + // req->SetDeviceId(deviceId); + std::string bindParamStr = SafetyDump(paramJson); + int32_t ret = deviceManagerInterface_->BindDevice(pkgName, bindType, deviceId, bindParamStr); if (ret != DM_OK) { LOGE("BindDevice error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("BindDevice error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("BindDevice error: Failed with ret %{public}d", ret); + // return ret; + // } DmTraceEnd(); LOGI("End"); return DM_OK; @@ -1580,20 +1582,20 @@ int32_t DeviceManagerImpl::UnBindDevice(const std::string &pkgName, const std::s } LOGI("Start, pkgName: %{public}s, deviceId: %{public}s", pkgName.c_str(), GetAnonyString(std::string(deviceId)).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetDeviceId(deviceId); - int32_t ret = ipcClientProxy_->SendRequest(UNBIND_DEVICE, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetDeviceId(deviceId); + int32_t ret = deviceManagerInterface_->UnBindDevice(pkgName, deviceId, ""); if (ret != DM_OK) { LOGE("UnBindDevice error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("UnBindDevice error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("UnBindDevice error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("End"); return DM_OK; @@ -1608,22 +1610,22 @@ int32_t DeviceManagerImpl::UnBindDevice(const std::string &pkgName, const std::s } LOGI("Start, pkgName: %{public}s, deviceId: %{public}s", pkgName.c_str(), GetAnonyString(std::string(deviceId)).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetDeviceId(deviceId); - req->SetExtraInfo(extra); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetDeviceId(deviceId); + // req->SetExtraInfo(extra); LOGI("DeviceManagerImpl::UnBindDevice extra: %{public}s.", extra.c_str()); - int32_t ret = ipcClientProxy_->SendRequest(UNBIND_DEVICE, req, rsp); + int32_t ret = deviceManagerInterface_->UnBindDevice(pkgName, deviceId, extra); if (ret != DM_OK) { LOGE("UnBindDevice error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("UnBindDevice error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("UnBindDevice error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("End"); return DM_OK; @@ -1680,22 +1682,22 @@ int32_t DeviceManagerImpl::ImportAuthCode(const std::string &pkgName, const std: } } - std::shared_ptr req = std::make_shared(); - req->SetAuthCode(authCode); - req->SetPkgName(pkgName); - std::shared_ptr rsp = std::make_shared(); + // std::shared_ptr req = std::make_shared(); + // req->SetAuthCode(authCode); + // req->SetPkgName(pkgName); + // std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(IMPORT_AUTH_CODE, req, rsp); + int32_t ret = deviceManagerInterface_->ImportAuthCode(pkgName, authCode); if (ret != DM_OK) { LOGI("ImportAuthCode Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("ImportAuthCode Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("ImportAuthCode Failed with ret %{public}d", ret); + // return ret; + // } return DM_OK; } @@ -1703,22 +1705,22 @@ int32_t DeviceManagerImpl::ExportAuthCode(std::string &authCode) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(EXPORT_AUTH_CODE, req, rsp); + int32_t ret = deviceManagerInterface_->ExportAuthCode(authCode); if (ret != DM_OK) { LOGI("ExportAuthCode Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("ExportAuthCode Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("ExportAuthCode Failed with ret %{public}d", ret); + // return ret; + // } - authCode = rsp->GetAuthCode(); + // authCode = rsp->GetAuthCode(); LOGI("Success, authCode: %{public}s.", GetAnonyString(authCode).c_str()); return DM_OK; } @@ -1737,21 +1739,21 @@ int32_t DeviceManagerImpl::RegisterDiscoveryCallback(const std::string &pkgName, std::string discParaStr = ConvertMapToJsonString(discoverParam); std::string filterOpStr = ConvertMapToJsonString(filterOptions); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(ComposeStr(pkgName, subscribeId)); - req->SetFirstParam(discParaStr); - req->SetSecondParam(filterOpStr); - int32_t ret = ipcClientProxy_->SendRequest(REGISTER_DISCOVERY_CALLBACK, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(ComposeStr(pkgName, subscribeId)); + // req->SetFirstParam(discParaStr); + // req->SetSecondParam(filterOpStr); + int32_t ret = deviceManagerInterface_->RegisterDiscoveryCallback(pkgName, discoverParam, filterOptions); if (ret != DM_OK) { LOGE("RegisterDiscoveryCallback error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("RegisterDiscoveryCallback error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("RegisterDiscoveryCallback error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -1777,24 +1779,24 @@ int32_t DeviceManagerImpl::UnRegisterDiscoveryCallback(const std::string &pkgNam extraParam.emplace(PARAM_KEY_SUBSCRIBE_ID, std::to_string(subscribeId)); std::string extraParaStr = ConvertMapToJsonString(extraParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(ComposeStr(pkgName, subscribeId)); - req->SetFirstParam(extraParaStr); - int32_t ret = ipcClientProxy_->SendRequest(UNREGISTER_DISCOVERY_CALLBACK, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(ComposeStr(pkgName, subscribeId)); + // req->SetFirstParam(extraParaStr); + int32_t ret = deviceManagerInterface_->UnRegisterDiscoveryCallback(pkgName); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", ret, anonyLocalUdid_); LOGE("UnRegisterDiscoveryCallback error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", - ret, anonyLocalUdid_); - LOGE("UnRegisterDiscoveryCallback error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", + // ret, anonyLocalUdid_); + // LOGE("UnRegisterDiscoveryCallback error: Failed with ret %{public}d", ret); + // return ret; + // } RemoveDiscoveryCallback(pkgNameTemp); DmRadarHelper::GetInstance().ReportDmBehavior(pkgNameTemp, "UnRegisterDiscoveryCallback", DM_OK, anonyLocalUdid_); LOGI("Completed"); @@ -1819,20 +1821,20 @@ int32_t DeviceManagerImpl::StartAdvertising(const std::string &pkgName, } std::string adverParaStr = ConvertMapToJsonString(advertiseParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetFirstParam(adverParaStr); - int32_t ret = ipcClientProxy_->SendRequest(START_ADVERTISING, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetFirstParam(adverParaStr); + int32_t ret = deviceManagerInterface_->StartAdvertising(pkgName, adverParaStr); if (ret != DM_OK) { LOGE("StartAdvertising error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("StartAdvertising error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("StartAdvertising error: Failed with ret %{public}d", ret); + // return ret; + // } DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); LOGI("Completed"); return DM_OK; @@ -1860,20 +1862,20 @@ int32_t DeviceManagerImpl::StopAdvertising(const std::string &pkgName, } std::string adverParaStr = ConvertMapToJsonString(advertiseParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetFirstParam(adverParaStr); - int32_t ret = ipcClientProxy_->SendRequest(STOP_ADVERTISING, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetFirstParam(adverParaStr); + int32_t ret = deviceManagerInterface_->StopAdvertising(pkgName, adverParaStr); if (ret != DM_OK) { LOGE("StopAdvertising error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("StopAdvertising error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("StopAdvertising error: Failed with ret %{public}d", ret); + // return ret; + // } DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(pkgName, publishId); LOGI("Completed"); return DM_OK; @@ -1892,21 +1894,22 @@ int32_t DeviceManagerImpl::BindTarget(const std::string &pkgName, const PeerTarg #endif std::string bindParamStr = ConvertMapToJsonString(bindParam); DeviceManagerNotify::GetInstance().RegisterBindCallback(pkgName, targetId, callback); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetPeerTargetId(targetId); - req->SetBindParam(bindParamStr); - int32_t ret = ipcClientProxy_->SendRequest(BIND_TARGET, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetPeerTargetId(targetId); + // req->SetBindParam(bindParamStr); + PeerTargetIdExt targetIdExt(targetId); + int32_t ret = deviceManagerInterface_->BindTarget(pkgName, targetIdExt, bindParamStr); if (ret != DM_OK) { LOGE("BindTarget error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("BindTarget error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("BindTarget error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; @@ -1922,21 +1925,22 @@ int32_t DeviceManagerImpl::UnbindTarget(const std::string &pkgName, const PeerTa LOGI("Start, pkgName: %{public}s", pkgName.c_str()); std::string unbindParamStr = ConvertMapToJsonString(unbindParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetPeerTargetId(targetId); - req->SetBindParam(unbindParamStr); - int32_t ret = ipcClientProxy_->SendRequest(UNBIND_TARGET, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetPeerTargetId(targetId); + // req->SetBindParam(unbindParamStr); + PeerTargetIdExt targetIdExt(targetId); + int32_t ret = deviceManagerInterface_->UnbindTarget(pkgName, targetIdExt, unbindParamStr); if (ret != DM_OK) { LOGE("UnbindTarget error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("UnbindTarget error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("UnbindTarget error: Failed with ret %{public}d", ret); + // return ret; + // } DeviceManagerNotify::GetInstance().RegisterUnbindCallback(pkgName, targetId, callback); LOGI("Completed"); @@ -2069,22 +2073,22 @@ int32_t DeviceManagerImpl::RegisterPinHolderCallback(const std::string &pkgName, return ERR_DM_INPUT_PARA_INVALID; } DeviceManagerNotify::GetInstance().RegisterPinHolderCallback(pkgName, callback); - std::shared_ptr req = std::make_shared(); - req->SetPkgName(pkgName); - std::shared_ptr rsp = std::make_shared(); + // std::shared_ptr req = std::make_shared(); + // req->SetPkgName(pkgName); + // std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(REGISTER_PIN_HOLDER_CALLBACK, req, rsp); + int32_t ret = deviceManagerInterface_->RegisterPinHolderCallback(pkgName); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", ret, anonyLocalUdid_); LOGI("RegisterPinHolderCallback Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", ret, anonyLocalUdid_); - LOGE("RegisterPinHolderCallback Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", ret, anonyLocalUdid_); + // LOGE("RegisterPinHolderCallback Failed with ret %{public}d", ret); + // return ret; + // } DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", DM_OK, anonyLocalUdid_); return DM_OK; } @@ -2099,23 +2103,24 @@ int32_t DeviceManagerImpl::CreatePinHolder(const std::string &pkgName, const Pee "%{public}zu", pkgName.c_str(), pinType, payload.length()); return ERR_DM_INPUT_PARA_INVALID; } - std::shared_ptr req = std::make_shared(); - req->SetPkgName(pkgName); - req->SetPeerTargetId(targetId); - req->SetPinType(pinType); - req->SetPayload(payload); - std::shared_ptr rsp = std::make_shared(); - - int32_t ret = ipcClientProxy_->SendRequest(CREATE_PIN_HOLDER, req, rsp); + // std::shared_ptr req = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetPeerTargetId(targetId); + // req->SetPinType(pinType); + // req->SetPayload(payload); + // std::shared_ptr rsp = std::make_shared(); + PeerTargetIdExt targetIdExt(targetId); + int32_t pinTypeInt = static_cast(pinType); + int32_t ret = deviceManagerInterface_->CreatePinHolder(pkgName, targetIdExt, pinTypeInt, payload); if (ret != DM_OK) { LOGI("CreatePinHolder Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("CreatePinHolder Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("CreatePinHolder Failed with ret %{public}d", ret); + // return ret; + // } return DM_OK; } @@ -2129,23 +2134,24 @@ int32_t DeviceManagerImpl::DestroyPinHolder(const std::string &pkgName, const Pe "%{public}zu", pkgName.c_str(), pinType, payload.length()); return ERR_DM_INPUT_PARA_INVALID; } - std::shared_ptr req = std::make_shared(); - req->SetPkgName(pkgName); - req->SetPeerTargetId(targetId); - req->SetPinType(pinType); - req->SetPayload(payload); - std::shared_ptr rsp = std::make_shared(); - - int32_t ret = ipcClientProxy_->SendRequest(DESTROY_PIN_HOLDER, req, rsp); + // std::shared_ptr req = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetPeerTargetId(targetId); + // req->SetPinType(pinType); + // req->SetPayload(payload); + // std::shared_ptr rsp = std::make_shared(); + PeerTargetIdExt targetIdExt(targetId); + int32_t pinTypeInt = static_cast(pinType); + int32_t ret = deviceManagerInterface_->DestroyPinHolder(pkgName, targetIdExt, pinTypeInt, payload); if (ret != DM_OK) { LOGI("DestroyPinHolder Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("DestroyPinHolder Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("DestroyPinHolder Failed with ret %{public}d", ret); + // return ret; + // } return DM_OK; } @@ -2156,19 +2162,19 @@ int32_t DeviceManagerImpl::DpAclAdd(const int64_t accessControlId, const std::st LOGI("DeviceManagerImpl::DpAclAdd is not identical account"); return DM_OK; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetStr(udid); - int32_t ret = ipcClientProxy_->SendRequest(DP_ACL_ADD, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetStr(udid); + int32_t ret = deviceManagerInterface_->DpAclAdd(accessControlId, udid, bindType); if (ret != DM_OK) { LOGE("DpAclAdd error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("DpAclAdd error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("DpAclAdd error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2186,25 +2192,25 @@ int32_t DeviceManagerImpl::GetDeviceSecurityLevel(const std::string &pkgName, co LOGI("Start: pkgName: %{public}s, networkId: %{public}s", pkgName.c_str(), GetAnonyString(networkId).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetNetWorkId(networkId); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetNetWorkId(networkId); - int32_t ret = ipcClientProxy_->SendRequest(GET_SECURITY_LEVEL, req, rsp); + int32_t ret = deviceManagerInterface_->GetDeviceSecurityLevel(pkgName, networkId, securityLevel); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", ret, anonyLocalUdid_); LOGE("GetDeviceSecurityLevel Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", ret, anonyLocalUdid_); - LOGE("GetDeviceSecurityLevel Failed with ret %{public}d", ret); - return ret; - } - securityLevel = rsp->GetSecurityLevel(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", ret, anonyLocalUdid_); + // LOGE("GetDeviceSecurityLevel Failed with ret %{public}d", ret); + // return ret; + // } + // securityLevel = rsp->GetSecurityLevel(); DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", DM_OK, anonyLocalUdid_); return DM_OK; } @@ -2212,20 +2218,20 @@ int32_t DeviceManagerImpl::GetDeviceSecurityLevel(const std::string &pkgName, co int32_t DeviceManagerImpl::CheckApiPermission(int32_t permissionLevel) { LOGI("PermissionLevel: %{public}d", permissionLevel); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPermissionLevel(permissionLevel); - int32_t ret = ipcClientProxy_->SendRequest(CHECK_API_PERMISSION, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPermissionLevel(permissionLevel); + int32_t ret = deviceManagerInterface_->CheckApiPermission(permissionLevel); 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("Check permission failed with ret: %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Check permission failed with ret: %{public}d", ret); + // return ret; + // } LOGD("The caller declare the DM permission!"); return DM_OK; } @@ -2236,15 +2242,16 @@ bool DeviceManagerImpl::IsSameAccount(const std::string &netWorkId) LOGE("DeviceManagerImpl::IsSameAccount error: netWorkId: %{public}s", GetAnonyString(netWorkId).c_str()); return false; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetStr(netWorkId); - int32_t ret = ipcClientProxy_->SendRequest(IS_SAME_ACCOUNT, req, rsp); - if (ret != DM_OK) { - LOGE("IsSameAccount Send Request failed ret: %{public}d", ret); - return false; - } - ret = rsp->GetErrCode(); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetStr(netWorkId); + bool result = false; + bool ret = deviceManagerInterface_->IsSameAccount(netWorkId, result); + // if (ret != DM_OK) { + // LOGE("IsSameAccount Send Request failed ret: %{public}d", ret); + // return false; + // } + // ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("IsSameAccount Failed with ret: %{public}d", ret); return false; @@ -2255,22 +2262,25 @@ bool DeviceManagerImpl::IsSameAccount(const std::string &netWorkId) bool DeviceManagerImpl::CheckAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetAccessCaller(caller); - req->SetAccessCallee(callee); - int32_t ret = ipcClientProxy_->SendRequest(CHECK_ACCESS_CONTROL, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetAccessCaller(caller); + // req->SetAccessCallee(callee); + DmAccessCallerExt callerExt(caller); + DmAccessCalleeExt calleeExt(callee); + bool funcResult = false; + int32_t ret = deviceManagerInterface_->CheckAccessControl(callerExt, calleeExt, funcResult); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", ret, anonyLocalUdid_); LOGE("CheckAccessControl Send Request failed ret: %{public}d", ret); return false; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", ret, anonyLocalUdid_); - LOGE("CheckAccessControl Failed with ret: %{public}d", ret); - return false; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", ret, anonyLocalUdid_); + // LOGE("CheckAccessControl Failed with ret: %{public}d", ret); + // return false; + // } DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckAccessControl", DM_OK, anonyLocalUdid_); return true; } @@ -2278,22 +2288,25 @@ bool DeviceManagerImpl::CheckAccessControl(const DmAccessCaller &caller, const D bool DeviceManagerImpl::CheckIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetAccessCaller(caller); - req->SetAccessCallee(callee); - int32_t ret = ipcClientProxy_->SendRequest(CHECK_SAME_ACCOUNT, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetAccessCaller(caller); + // req->SetAccessCallee(callee); + DmAccessCallerExt callerExt(caller); + DmAccessCalleeExt calleeExt(callee); + bool funcResult = false; + int32_t ret = deviceManagerInterface_->CheckIsSameAccount(callerExt, calleeExt, funcResult); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", ret, anonyLocalUdid_); LOGE("CheckIsSameAccount Send Request failed ret: %{public}d", ret); return false; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", ret, anonyLocalUdid_); - LOGE("CheckIsSameAccount Failed with ret: %{public}d", ret); - return false; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", ret, anonyLocalUdid_); + // LOGE("CheckIsSameAccount Failed with ret: %{public}d", ret); + // return false; + // } DmRadarHelper::GetInstance().ReportDmBehavior(caller.pkgName, "CheckIsSameAccount", DM_OK, anonyLocalUdid_); return true; } @@ -2310,21 +2323,21 @@ int32_t DeviceManagerImpl::GetErrCode(int32_t errCode) int32_t DeviceManagerImpl::ShiftLNNGear(const std::string &pkgName) { LOGI("Start. pkgName = %{public}s", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(SHIFT_LNN_GEAR, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + int32_t ret = deviceManagerInterface_->ShiftLNNGear(pkgName); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", ret, anonyLocalUdid_); LOGE("ShiftLNNGear error: Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", ret, anonyLocalUdid_); - LOGE("ShiftLNNGear error: Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", ret, anonyLocalUdid_); + // LOGE("ShiftLNNGear error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "ShiftLNNGear", DM_OK, anonyLocalUdid_); return DM_OK; @@ -2340,24 +2353,24 @@ int32_t DeviceManagerImpl::SetDnPolicy(const std::string &pkgName, std::map req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetFirstParam(strategy); - int32_t ret = ipcClientProxy_->SendRequest(SET_DN_POLICY, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetFirstParam(strategy); + int32_t ret = deviceManagerInterface_->SetDnPolicy(pkgName, policy); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", ret, anonyLocalUdid_); LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", ret, anonyLocalUdid_); - LOGE("Failed with ret %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", ret, anonyLocalUdid_); + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", DM_OK, anonyLocalUdid_); return DM_OK; @@ -2413,23 +2426,23 @@ int32_t DeviceManagerImpl::GetDeviceScreenStatus(const std::string &pkgName, con } LOGI("Start: pkgName: %{public}s, networkId: %{public}s", pkgName.c_str(), GetAnonyString(networkId).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetNetWorkId(networkId); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetNetWorkId(networkId); - int32_t ret = ipcClientProxy_->SendRequest(GET_DEVICE_SCREEN_STATUS, req, rsp); + int32_t ret = deviceManagerInterface_->GetDeviceScreenStatus(pkgName, networkId, screenStatus); 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; - } - screenStatus = rsp->GetScreenStatus(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } + // screenStatus = rsp->GetScreenStatus(); return DM_OK; } @@ -2443,23 +2456,23 @@ int32_t DeviceManagerImpl::GetNetworkIdByUdid(const std::string &pkgName, const } LOGD("Start, pkgName: %{public}s", GetAnonyString(pkgName).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetUdid(udid); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetUdid(udid); - int32_t ret = ipcClientProxy_->SendRequest(GET_NETWORKID_BY_UDID, req, rsp); + int32_t ret = deviceManagerInterface_->GetNetworkIdByUdid(pkgName, udid, networkId); if (ret != DM_OK) { LOGI("GetNetworkIdByUdid Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("GetNetworkIdByUdid Failed with ret %{public}d", ret); - return ret; - } - networkId = rsp->GetNetWorkId(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("GetNetworkIdByUdid Failed with ret %{public}d", ret); + // return ret; + // } + // networkId = rsp->GetNetWorkId(); return DM_OK; } @@ -2514,21 +2527,21 @@ int32_t DeviceManagerImpl::UnRegisterSinkBindCallback(const std::string &pkgName int32_t DeviceManagerImpl::GetAnonyLocalUdid(const std::string &pkgName, std::string &anonyUdid) { LOGD("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(GET_ANONY_LOCAL_UDID, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + int32_t ret = deviceManagerInterface_->GetAnonyLocalUdid(pkgName, anonyUdid); if (ret != DM_OK) { LOGI("GetAnonyLocalUdid Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("GetAnonyLocalUdid Failed with ret %{public}d", ret); - return ret; - } - anonyUdid = rsp->GetAnonyUdid(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("GetAnonyLocalUdid Failed with ret %{public}d", ret); + // return ret; + // } + // anonyUdid = rsp->GetAnonyUdid(); return DM_OK; } @@ -2553,20 +2566,21 @@ void DeviceManagerImpl::SyncCallbackToService(DmCommonNotifyEvent dmCommonNotify LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); return; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetDmCommonNotifyEvent(static_cast(dmCommonNotifyEvent)); - int32_t ret = ipcClientProxy_->SendRequest(SYNC_CALLBACK, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetDmCommonNotifyEvent(static_cast(dmCommonNotifyEvent)); + int32_t dmCommonNotifyEventInt = static_cast(dmCommonNotifyEvent); + int32_t ret = deviceManagerInterface_->SyncCallbackToService(dmCommonNotifyEventInt, pkgName); if (ret != DM_OK) { LOGI("Send Request failed ret: %{public}d", ret); return; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("Failed with ret %{public}d", ret); - return; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return; + // } } int32_t DeviceManagerImpl::GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, @@ -2582,11 +2596,12 @@ int32_t DeviceManagerImpl::GetAllTrustedDeviceList(const std::string &pkgName, c LOGI("Start, pkgName: %{public}s, extra: %{public}s", GetAnonyString(pkgName).c_str(), GetAnonyString(extra).c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetExtra(extra); - int32_t ret = ipcClientProxy_->SendRequest(GET_ALL_TRUST_DEVICE_LIST, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetExtra(extra); + std::vector deviceListExt; + int32_t ret = deviceManagerInterface_->GetAllTrustedDeviceList(pkgName, extra, deviceListExt); if (ret != DM_OK) { DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", deviceList, ret, anonyLocalUdid_); @@ -2594,15 +2609,15 @@ int32_t DeviceManagerImpl::GetAllTrustedDeviceList(const std::string &pkgName, c return ERR_DM_IPC_SEND_REQUEST_FAILED; } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", - deviceList, ret, anonyLocalUdid_); - LOGE("GetAllTrustedDeviceList error, failed ret: %{public}d", ret); - return ret; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", + // deviceList, ret, anonyLocalUdid_); + // LOGE("GetAllTrustedDeviceList error, failed ret: %{public}d", ret); + // return ret; + // } - deviceList = rsp->GetDeviceVec(); + // deviceList = rsp->GetDeviceVec(); LOGI("Completed, device size %{public}zu", deviceList.size()); DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", deviceList, DM_OK, anonyLocalUdid_); @@ -2637,20 +2652,20 @@ int32_t DeviceManagerImpl::RegisterAuthenticationType(const std::string &pkgName LOGI("Start"); std::string authTypeStr = ConvertMapToJsonString(authParam); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetFirstParam(authTypeStr); - int32_t ret = ipcClientProxy_->SendRequest(REG_AUTHENTICATION_TYPE, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetFirstParam(authTypeStr); + int32_t ret = deviceManagerInterface_->RegisterAuthenticationType(pkgName, authTypeStr); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2719,20 +2734,21 @@ int32_t DeviceManagerImpl::PutDeviceProfileInfoList(const std::string &pkgName, const std::vector &deviceProfileInfoList) { LOGI("In pkgName:%{public}s,", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetDeviceProfileInfoList(deviceProfileInfoList); - int32_t ret = ipcClientProxy_->SendRequest(PUT_DEVICE_PROFILE_INFO_LIST, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetDeviceProfileInfoList(deviceProfileInfoList); + std::vector deviceProfileInfoListExt; + int32_t ret = deviceManagerInterface_->PutDeviceProfileInfoList(pkgName, deviceProfileInfoListExt); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2741,21 +2757,21 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, std::string &displayName) { LOGI("In pkgName:%{public}s,", pkgName.c_str()); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - req->SetMaxNameLength(maxNameLength); - int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DISPLAY_DEVICE_NAME, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + // req->SetMaxNameLength(maxNameLength); + int32_t ret = deviceManagerInterface_->GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); if (ret != DM_OK) { return ERR_DM_IPC_SEND_REQUEST_FAILED; LOGE("error: Send Request failed ret: %{public}d", ret); } - ret = rsp->GetErrCode(); - if (ret != DM_OK) { - LOGE("error: Failed with ret %{public}d", ret); - return ret; - } - displayName = rsp->GetDisplayName(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("error: Failed with ret %{public}d", ret); + // return ret; + // } + // displayName = rsp->GetDisplayName(); LOGI("Completed"); return DM_OK; } @@ -2763,19 +2779,19 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DmLocalServiceInfo &info) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetLocalServiceInfo(info); - int32_t ret = ipcClientProxy_->SendRequest(REG_LOCALSERVICE_INFO, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetLocalServiceInfo(info); + int32_t ret = deviceManagerInterface_->RegisterLocalServiceInfo(info); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2783,20 +2799,20 @@ int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DmLocalServiceInfo &in int32_t DeviceManagerImpl::UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetFirstParam(bundleName); - req->SetInt32Param(pinExchangeType); - int32_t ret = ipcClientProxy_->SendRequest(UNREG_LOCALSERVICE_INFO, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetFirstParam(bundleName); + // req->SetInt32Param(pinExchangeType); + int32_t ret = deviceManagerInterface_->UnRegisterLocalServiceInfo(bundleName, pinExchangeType); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2804,19 +2820,19 @@ int32_t DeviceManagerImpl::UnRegisterLocalServiceInfo(const std::string &bundleN int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DmLocalServiceInfo &info) { LOGI("Start"); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetLocalServiceInfo(info); - int32_t ret = ipcClientProxy_->SendRequest(UPDATE_LOCALSERVICE_INFO, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetLocalServiceInfo(info); + int32_t ret = deviceManagerInterface_->UpdateLocalServiceInfo(info); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2824,21 +2840,22 @@ int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DmLocalServiceInfo &info int32_t DeviceManagerImpl::GetLocalServiceInfoByBundleNameAndPinExchangeType( const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfo &info) { - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetFirstParam(bundleName); - req->SetInt32Param(pinExchangeType); - int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetFirstParam(bundleName); + // req->SetInt32Param(pinExchangeType); + DmLocalServiceInfoExt dmLocalServiceInfoExt(info); + int32_t ret = deviceManagerInterface_->GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, pinExchangeType, dmLocalServiceInfoExt); 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; - } - info = rsp->GetLocalServiceInfo(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } + // info = rsp->GetLocalServiceInfo(); LOGI("Completed"); return DM_OK; } @@ -2917,19 +2934,19 @@ int32_t DeviceManagerImpl::RestoreLocalDeviceName(const std::string &pkgName) LOGE("param invalid, pkgName : %{public}s", pkgName.c_str()); return ERR_DM_INPUT_PARA_INVALID; } - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - int32_t ret = ipcClientProxy_->SendRequest(RESTORE_LOCAL_DEVICE_NAME, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(pkgName); + int32_t ret = deviceManagerInterface_->RestoreLocalDeviceName(pkgName); 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; - } + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("error: Failed with ret %{public}d", ret); + // return ret; + // } LOGI("Completed"); return DM_OK; } @@ -2937,21 +2954,22 @@ int32_t DeviceManagerImpl::RestoreLocalDeviceName(const std::string &pkgName) int32_t DeviceManagerImpl::GetDeviceNetworkIdList(const std::string &bundleName, const NetworkIdQueryFilter &queryFilter, std::vector &networkIds) { - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(bundleName); - req->SetQueryFilter(queryFilter); - int32_t ret = ipcClientProxy_->SendRequest(GET_DEVICE_NETWORK_ID_LIST, req, rsp); + // std::shared_ptr req = std::make_shared(); + // std::shared_ptr rsp = std::make_shared(); + // req->SetPkgName(bundleName); + // req->SetQueryFilter(queryFilter); + NetworkIdQueryFilterExt networkIdQueryFilterExt(queryFilter); + int32_t ret = deviceManagerInterface_->GetDeviceNetworkIdList(bundleName, networkIdQueryFilterExt, networkIds); 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; - } - networkIds = rsp->GetNetworkIds(); + // ret = rsp->GetErrCode(); + // if (ret != DM_OK) { + // LOGE("Failed with ret %{public}d", ret); + // return ret; + // } + // networkIds = rsp->GetNetworkIds(); LOGI("Completed"); return DM_OK; } diff --git a/services/service/include/ipc/standard/device_manager_client_service.h b/services/service/include/ipc/standard/device_manager_client_service.h index fd200330c..9666c1c0b 100644 --- a/services/service/include/ipc/standard/device_manager_client_service.h +++ b/services/service/include/ipc/standard/device_manager_client_service.h @@ -315,7 +315,7 @@ class DeviceManagerClientService : public DeviceManagerClientStub { const std::string& bundleName, const NetworkIdQueryFilterExt& queryFilter, std::vector& networkIds) override; - + private: DeviceManagerClientService(); diff --git a/services/service/src/ipc/standard/device_manager_client_service.cpp b/services/service/src/ipc/standard/device_manager_client_service.cpp index 443777084..e84944146 100644 --- a/services/service/src/ipc/standard/device_manager_client_service.cpp +++ b/services/service/src/ipc/standard/device_manager_client_service.cpp @@ -880,7 +880,7 @@ ErrCode DeviceManagerClientService::GetLocalServiceInfoByBundleNameAndPinExchang const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfoExt &info) { DmLocalServiceInfoExt serviceInfo; - DmIpcUtils::ConvertToDmLocalServiceInfo(serviceInfo, info); + DmIpcUtils::ConvertToDmLocalServiceInfo(info, serviceInfo); DeviceManagerService service; int32_t result = service.GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, pinExchangeType,info); if (result != ERR_OK) { @@ -905,7 +905,9 @@ ErrCode DeviceManagerClientService::GetDeviceNetworkIdList( std::vector &networkIds) { DeviceManagerService service; - int32_t result = service.GetDeviceNetworkIdList(bundleName,queryFilter,networkIds); + NetworkIdQueryFilter networkIdQueryFilter; + DmIpcUtils::ConvertToNetworkIdQueryFilter(queryFilter, networkIdQueryFilter); + int32_t result = service.GetDeviceNetworkIdList(bundleName,networkIdQueryFilter,networkIds); if (result != ERR_OK) { LOGE("Failed with ret %{public}d", result); } diff --git a/utils/include/dm_ipc_utils.h b/utils/include/dm_ipc_utils.h index 5cdf07ed6..901d9ddea 100644 --- a/utils/include/dm_ipc_utils.h +++ b/utils/include/dm_ipc_utils.h @@ -36,6 +36,7 @@ public: static void ConverToDMServiceInfoVector(std::vector& serviceInfoExt, std::vector &serviceInfos); static void ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, DmLocalServiceInfo& base); + static void ConvertToNetworkIdQueryFilter(const NetworkIdQueryFilterExt& ext, NetworkIdQueryFilter& base); }; } // namespace DistributedHardware diff --git a/utils/src/dm_ipc_utils.cpp b/utils/src/dm_ipc_utils.cpp index 780421a54..901e8e87f 100644 --- a/utils/src/dm_ipc_utils.cpp +++ b/utils/src/dm_ipc_utils.cpp @@ -166,5 +166,14 @@ void DmIpcUtils::ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, D base.description = ext.description; base.extraInfo = ext.extraInfo; } + +void DmIpcUtils::ConvertToNetworkIdQueryFilter(const NetworkIdQueryFilterExt& ext, NetworkIdQueryFilter& base) +{ + base.wiseDeviceId = ext.wiseDeviceId; + base.onlineStatus = ext.onlineStatus; + base.deviceType = ext.deviceType; + base.deviceProductId = ext.deviceProductId; + base.deviceModel = ext.deviceModel; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 740fa8331b039b9c52a4e42f235996bdb857e984 Mon Sep 17 00:00:00 2001 From: Sly <1298008151@qq.com> Date: Tue, 15 Apr 2025 17:25:02 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sly <1298008151@qq.com> Change-Id: Ib3e7395a5008a90350af6943084607d484dae858 --- interfaces/inner_kits/native_cpp/include/device_manager_impl.h | 1 - 1 file changed, 1 deletion(-) 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 0cdda05ce..6a3d17151 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -457,7 +457,6 @@ private: #if !defined(__LITEOS_M__) std::shared_ptr ipcClientProxy_ = std::make_shared(std::make_shared()); - std::shared_ptr deviceManagerClient_; std::shared_ptr deviceManagerInterface_ = nullptr; #endif std::mutex subMapLock; -- Gitee From 0ecbd775b32f40af6a2325fa0675f294413c649c Mon Sep 17 00:00:00 2001 From: Sly <1298008151@qq.com> Date: Wed, 23 Apr 2025 20:21:55 +0800 Subject: [PATCH 5/5] fixed the review comments. Signed-off-by: Sly <1298008151@qq.com> Change-Id: I3a2aa5f7cab47565b4032a07c42151d183dc2ca9 --- .../ipc/model/ipc_get_localserviceinfo_rsp.h | 6 +- .../ipc/model/ipc_register_serviceinfo_req.h | 6 +- common/include/ipc/standard/ipc_model_codec.h | 8 +- common/src/ipc/standard/ipc_model_codec.cpp | 12 +- interfaces/inner_kits/native_cpp/BUILD.gn | 4 +- .../native_cpp/IDeviceManagerClient.idl | 31 +- .../native_cpp/include/device_manager.h | 6 +- .../native_cpp/include/device_manager_impl.h | 6 +- .../native_cpp/include/dm_device_info.h | 18 +- .../include/idevice_manager_client.h | 382 ------------------ .../native_cpp/src/device_manager.cpp | 2 +- .../native_cpp/src/device_manager_impl.cpp | 25 +- .../native_cpp/src/dm_device_info.cpp | 8 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 6 +- .../src/authentication/dm_auth_manager.cpp | 22 +- .../src/device_manager_service_impl.cpp | 1 - services/service/BUILD.gn | 2 + .../service/include/device_manager_service.h | 15 +- .../standard/device_manager_client_service.h | 6 +- .../service/src/device_manager_service.cpp | 14 +- .../device_manager_client_service.cpp | 77 ++-- .../src/ipc/standard/ipc_cmd_parser.cpp | 8 +- .../UTTest_dm_auth_manager_first.cpp | 28 +- .../UTTest_dm_auth_manager_second.cpp | 12 +- test/unittest/UTTest_device_manager_impl.cpp | 6 +- .../UTTest_device_manager_service_two.cpp | 18 +- .../unittest/UTTest_ipc_cmd_parser_client.cpp | 10 +- .../UTTest_ipc_cmd_parser_service.cpp | 8 +- utils/include/dm_ipc_utils.h | 6 +- utils/src/dm_ipc_utils.cpp | 8 +- 30 files changed, 200 insertions(+), 561 deletions(-) delete mode 100644 interfaces/inner_kits/native_cpp/include/idevice_manager_client.h diff --git a/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h index a41d5ce59..98a8137c7 100644 --- a/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h +++ b/common/include/ipc/model/ipc_get_localserviceinfo_rsp.h @@ -25,17 +25,17 @@ class IpcGetLocalServiceInfoRsp : public IpcRsp { DECLARE_IPC_MODEL(IpcGetLocalServiceInfoRsp); public: - const DmLocalServiceInfo &GetLocalServiceInfo() const + const DMLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetLocalServiceInfo(const DmLocalServiceInfo &info) + void SetLocalServiceInfo(const DMLocalServiceInfo &info) { serviceInfo_ = info; } private: - DmLocalServiceInfo serviceInfo_; + DMLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_register_serviceinfo_req.h b/common/include/ipc/model/ipc_register_serviceinfo_req.h index 01bfcada4..d9308dc57 100644 --- a/common/include/ipc/model/ipc_register_serviceinfo_req.h +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.h @@ -25,17 +25,17 @@ class IpcRegServiceInfoReq : public IpcReq { DECLARE_IPC_MODEL(IpcRegServiceInfoReq); public: - const DmLocalServiceInfo &GetLocalServiceInfo() const + const DMLocalServiceInfo &GetLocalServiceInfo() const { return serviceInfo_; } - void SetLocalServiceInfo(const DmLocalServiceInfo &info) + void SetLocalServiceInfo(const DMLocalServiceInfo &info) { serviceInfo_ = info; } private: - DmLocalServiceInfo serviceInfo_; + DMLocalServiceInfo serviceInfo_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index 32c359eab..e06af83a9 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -48,10 +48,10 @@ public: static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, MessageParcel &parcel); static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); - static bool EncodeLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, MessageParcel &parcel); - static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); - static bool DecodeLocalServiceInfo(MessageParcel &parcel, DmLocalServiceInfo &serviceInfo); - static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); + static bool EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel); + static bool EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); + static bool DecodeLocalServiceInfo(MessageParcel &parcel, DMLocalServiceInfo &serviceInfo); + static bool DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); static bool EncodeNetworkIdQueryFilter(const NetworkIdQueryFilter &queryFilter, MessageParcel &parcel); static bool DecodeNetworkIdQueryFilter(MessageParcel &parcel, NetworkIdQueryFilter &queryFilter); static bool EncodeStringVector(const std::vector &vec, MessageParcel &parcel); diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index 83840c2a7..1091961c6 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -356,7 +356,7 @@ void IpcModelCodec::DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devI devInfo.extraData = parcel.ReadString(); } -bool IpcModelCodec::EncodeLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, MessageParcel &parcel) { bool bRet = true; bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); @@ -369,7 +369,7 @@ bool IpcModelCodec::EncodeLocalServiceInfo(const DmLocalServiceInfo &serviceInfo return bRet; } -bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) +bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) { uint32_t num = static_cast(serviceInfos.size()); if (!parcel.WriteUint32(num)) { @@ -378,7 +378,7 @@ bool IpcModelCodec::EncodeLocalServiceInfos(const std::vector &serviceInfos) +bool IpcModelCodec::DecodeLocalServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) { uint32_t num = 0; READ_HELPER_RET(parcel, Uint32, num, false); bool bRet = true; for (uint32_t k = 0; k < num; k++) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; bRet = DecodeLocalServiceInfo(parcel, serviceInfo); if (!bRet) { LOGE("DecodeLocalServiceInfo failed"); diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 94ad915c7..9ccdcffc8 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -62,7 +62,6 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//base/security/device_auth/interfaces/inner_api", "//base/startup/init/interfaces/innerkits/include/syspara", - "${target_gen_dir}", ] sources = [ @@ -77,7 +76,6 @@ if (defined(ohos_lite)) { "//foundation/systemabilitymgr/samgr_lite/samgr", "//third_party/bounds_checking_function:libsec_static", "//third_party/cJSON:cjson", - ":device_manager_ipc" ] cflags = [ @@ -223,7 +221,7 @@ if (defined(ohos_lite)) { "src/notify/device_manager_notify.cpp", "src/dm_publish_info.cpp", "src/dm_device_profile_info.cpp", - "${utils_path}/src//dm_ipc_utils.cpp", + "${utils_path}/src/dm_ipc_utils.cpp", ] deps = [ ":device_manager_ipc" ] diff --git a/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl index b2428f1a1..0458e94ba 100644 --- a/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl +++ b/interfaces/inner_kits/native_cpp/IDeviceManagerClient.idl @@ -20,25 +20,23 @@ sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCallerExt; sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmAccessCalleeExt; sequenceable DmPublishInfo..OHOS.DistributedHardware.DmPublishInfoExt; sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceProfileInfoExt; -sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmLocalServiceInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DMLocalServiceInfoExt; sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.NetworkIdQueryFilterExt; interface OHOS.DistributedHardware.IDeviceManagerClient { - [ipccode 2] void GetTrustedDeviceList([in] String pkgName, [in] String extra, [in] boolean isRefresh, [out] List deviceListExt); + [ipccode 2] void GetTrustedDeviceList([in] String pkgName, + [in] String extra, [in] boolean isRefresh, [out] List deviceListExt); [ipccode 3] void GetLocalDeviceInfo([in] String pkgName, [out] DmDeviceInfoExt deviceInfoExt); [ipccode 4] void GetUdidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String udid); [ipccode 5] void GetUuidByNetworkId([in] String pkgName, [in] String netWorkId, [out] String uuid); - [ipccode 6] void GetNetworkTypeByNetworkId([in] String pkgName,[in] String netWorkId, [out] int netWorkType); + [ipccode 6] void GetNetworkTypeByNetworkId([in] String pkgName, [in] String netWorkId, [out] int netWorkType); [ipccode 7] void PublishDeviceDiscovery([in] String pkgName, [in] DmPublishInfoExt publishInfoExt); [ipccode 8] void UnPublishDeviceDiscovery([in] String pkgName, [in] int publishId); - // AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo, const std::string &extra, std::shared_ptr callback) [ipccode 9] void AuthenticateDevice([in] String pkgName, [in] int authType, [in] String deviceId, [in] String extra); [ipccode 10] void UnAuthenticateDevice([in] String pkgName, [in] String netWorkId); [ipccode 11] void StopAuthenticateDevice([in] String pkgName); [ipccode 20] void CheckCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); [ipccode 21] void SetUserOperation([in] String pkgName, [in] int action, [in] String params); - // RequestCredential(const std::string &pkgName, const std::string &reqJsonStr, std::string &returnJsonStr) - // RequestCredential(const std::string &pkgName, std::string &returnJsonStr) [ipccode 26] void RequestCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); [ipccode 27] void ImportCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); [ipccode 28] void DeleteCredential([in] String pkgName, [in] String reqJsonStr, [out] String returnJsonStr); @@ -46,11 +44,9 @@ interface OHOS.DistributedHardware.IDeviceManagerClient { [ipccode 30] void UnRegisterCredentialCallback([in] String pkgName); [ipccode 31] void NotifyEvent([in] String pkgName, [in] int eventId, [in] String event); [ipccode 32] void GetDeviceInfo([in] String pkgName, [in] String networkId, [out] DmDeviceInfoExt deviceInfoExt); - [ipccode 33] void GetEncryptedUuidByNetworkId([in] String pkgName, [in] String networkId,[out] String uuid); + [ipccode 33] void GetEncryptedUuidByNetworkId([in] String pkgName, [in] String networkId, [out] String uuid); [ipccode 34] void GenerateEncryptedUuid([in] String pkgName, [in] String uuid, [in] String appId, [out] String encryptedUuid); [ipccode 35] void BindDevice([in] String pkgName, [in] int bindType, [in] String deviceId, [in] String extra); - // UnBindDevice(const std::string &pkgName, const std::string &deviceId); - // UnBindDevice(const std::string &pkgName, const std::string &deviceId, const std::string &extra); [ipccode 36] void UnBindDevice([in] String pkgName, [in] String deviceId, [in] String extra); [ipccode 37] void RegisterUiStateCallback([in] String pkgName); [ipccode 38] void UnRegisterUiStateCallback([in] String pkgName); @@ -59,9 +55,11 @@ interface OHOS.DistributedHardware.IDeviceManagerClient { [ipccode 41] void RegisterPinHolderCallback([in] String pkgName); [ipccode 42] void CreatePinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinTypeInt, [in] String payload); [ipccode 43] void DestroyPinHolder([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int pinType, [in] String payload); - [ipccode 49] void RegisterDiscoveryCallback([in] String pkgName, [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); + [ipccode 49] void RegisterDiscoveryCallback([in] String pkgName, + [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); [ipccode 50] void UnRegisterDiscoveryCallback([in] String pkgName); - [ipccode 51] void StartDiscovering([in] String pkgName, [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); + [ipccode 51] void StartDiscovering([in] String pkgName, + [in] OrderedMap discoverParam, [in] OrderedMap filterOptions); [ipccode 52] void StopDiscovering([in] String pkgName, [in] OrderedMap discoverParam); [ipccode 53] void StartAdvertising([in] String pkgName, [in] String adverParaStr); [ipccode 54] void StopAdvertising([in] String pkgName, [in] String adverParaStr); @@ -83,10 +81,11 @@ interface OHOS.DistributedHardware.IDeviceManagerClient { [ipccode 80] void PutDeviceProfileInfoList([in] String pkgName, [in] List deviceProfileInfoListExt); [ipccode 81] void GetLocalDisplayDeviceName([in] String pkgName, [in] int maxNameLength, [out] String displayName); [ipccode 86] void GetAllTrustedDeviceList([in] String pkgName, [in] String extra, [out] List deviceListExt); - [ipccode 87] void RegisterLocalServiceInfo([in] DmLocalServiceInfoExt info); + [ipccode 87] void RegisterLocalServiceInfo([in] DMLocalServiceInfoExt info); [ipccode 88] void UnRegisterLocalServiceInfo([in] String bundleName, [in] int pinExchangeType); - [ipccode 89] void UpdateLocalServiceInfo([in] DmLocalServiceInfoExt info); - [ipccode 90] void GetLocalServiceInfoByBundleNameAndPinExchangeType([in] String bundleName,[in] int pinExchangeType,[out] DmLocalServiceInfoExt info); - [ipccode 91] void RestoreLocalDeviceName ([in] String pkgName); - [ipccode 92] void GetDeviceNetworkIdList([in] String pkgName,[in] NetworkIdQueryFilterExt queryFilter,[out] List networkIds); + [ipccode 89] void UpdateLocalServiceInfo([in] DMLocalServiceInfoExt info); + [ipccode 90] void GetLocalServiceInfoByBundleNameAndPinExchangeType([in] String bundleName, + [in] int pinExchangeType, [out] DMLocalServiceInfoExt info); + [ipccode 91] void RestoreLocalDeviceName([in] String pkgName); + [ipccode 92] void GetDeviceNetworkIdList([in] String pkgName, [in] NetworkIdQueryFilterExt queryFilter, [out] List networkIds); } \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index cca939e64..8c75216bf 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -647,11 +647,11 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; - virtual int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &info) = 0; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) = 0; virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) = 0; - virtual int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &info) = 0; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) = 0; virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DmLocalServiceInfo &info) = 0; + int32_t pinExchangeType, DMLocalServiceInfo &info) = 0; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) = 0; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, 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 6a3d17151..31958f2d1 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -421,11 +421,11 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; - virtual int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &info) override; + virtual int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &info) override; virtual int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType) override; - virtual int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &info) override; + virtual int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &info) override; virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DmLocalServiceInfo &info) override; + int32_t pinExchangeType, DMLocalServiceInfo &info) override; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) override; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, 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 26a0ed74d..7c6608008 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -424,25 +424,25 @@ typedef struct DmNotifyKey { } } DmNotifyKey; -enum class DmLocalServiceInfoAuthType : int32_t { +enum class DMLocalServiceInfoAuthType : int32_t { TRUST_ONETIME = 0, TRUST_ALWAYS = 6, CANCEL = 1 }; -enum class DmLocalServiceInfoPinExchangeType : int32_t { +enum class DMLocalServiceInfoPinExchangeType : int32_t { PINBOX = 1, ULTRASOUND = 2, FROMDP = 3 }; -enum class DmLocalServiceInfoAuthBoxType : int32_t { +enum class DMLocalServiceInfoAuthBoxType : int32_t { STATE3 = 1, SKIP_CONFIRM = 2, TWO_IN1 = 3 }; -typedef struct DmLocalServiceInfo { +typedef struct DMLocalServiceInfo { std::string bundleName; int32_t authBoxType = 0; int32_t authType = 0; @@ -450,7 +450,7 @@ typedef struct DmLocalServiceInfo { std::string pinCode; std::string description; std::string extraInfo; -} DmLocalServiceInfo; +} DMLocalServiceInfo; struct DmDeviceInfoExt : public DmDeviceInfo, public Parcelable { using DmDeviceInfo::DmDeviceInfo; @@ -544,11 +544,11 @@ struct DmDeviceBasicInfoExt : public DmDeviceBasicInfo, public Parcelable static DmDeviceBasicInfoExt *Unmarshalling(Parcel &parcel); }; -struct DmLocalServiceInfoExt : public DmLocalServiceInfo, public Parcelable +struct DMLocalServiceInfoExt : public DMLocalServiceInfo, public Parcelable { - using DmLocalServiceInfo::DmLocalServiceInfo; + using DMLocalServiceInfo::DMLocalServiceInfo; - DmLocalServiceInfoExt(const DmLocalServiceInfo& devLocalServiceInfo) { + DMLocalServiceInfoExt(const DMLocalServiceInfo& devLocalServiceInfo) { bundleName = devLocalServiceInfo.bundleName; authBoxType = devLocalServiceInfo.authBoxType; authType = devLocalServiceInfo.authType; @@ -560,7 +560,7 @@ struct DmLocalServiceInfoExt : public DmLocalServiceInfo, public Parcelable virtual bool Marshalling(Parcel &parcel) const override; - static DmLocalServiceInfoExt *Unmarshalling(Parcel &parcel); + static DMLocalServiceInfoExt *Unmarshalling(Parcel &parcel); }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h deleted file mode 100644 index 5ae075b44..000000000 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_client.h +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H -#define OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H - -#include -#include -#include -#include -#include -#include "dm_device_info.h" -#include "dm_device_profile_info.h" -#include "dm_publish_info.h" -#include "hilog/log.h" - -using OHOS::DistributedHardware::DmDeviceInfoExt; -using OHOS::DistributedHardware::PeerTargetIdExt; -using OHOS::DistributedHardware::DmAccessCallerExt; -using OHOS::DistributedHardware::DmAccessCalleeExt; -using OHOS::DistributedHardware::DmPublishInfoExt; -using OHOS::DistributedHardware::DmDeviceProfileInfoExt; -using OHOS::DistributedHardware::DmLocalServiceInfoExt; - -namespace OHOS { -namespace DistributedHardware { - -enum class IDeviceManagerClientIpcCode { - COMMAND_GET_TRUSTED_DEVICE_LIST = 2, - COMMAND_GET_LOCAL_DEVICE_INFO = 3, - COMMAND_GET_UDID_BY_NETWORK_ID = 4, - COMMAND_GET_UUID_BY_NETWORK_ID = 5, - COMMAND_GET_NETWORK_TYPE_BY_NETWORK_ID = 6, - COMMAND_PUBLISH_DEVICE_DISCOVERY = 7, - COMMAND_UN_PUBLISH_DEVICE_DISCOVERY = 8, - COMMAND_AUTHENTICATE_DEVICE = 9, - COMMAND_UN_AUTHENTICATE_DEVICE = 10, - COMMAND_STOP_AUTHENTICATE_DEVICE = 11, - COMMAND_CHECK_CREDENTIAL = 20, - COMMAND_SET_USER_OPERATION = 21, - COMMAND_REQUEST_CREDENTIAL = 26, - COMMAND_IMPORT_CREDENTIAL = 27, - COMMAND_DELETE_CREDENTIAL = 28, - COMMAND_REGISTER_CREDENTIAL_CALLBACK = 29, - COMMAND_UN_REGISTER_CREDENTIAL_CALLBACK = 30, - COMMAND_NOTIFY_EVENT = 31, - COMMAND_GET_DEVICE_INFO = 32, - COMMAND_GET_ENCRYPTED_UUID_BY_NETWORK_ID = 33, - COMMAND_GENERATE_ENCRYPTED_UUID = 34, - COMMAND_BIND_DEVICE = 35, - COMMAND_UN_BIND_DEVICE = 36, - COMMAND_REGISTER_UI_STATE_CALLBACK = 37, - COMMAND_UN_REGISTER_UI_STATE_CALLBACK = 38, - COMMAND_IMPORT_AUTH_CODE = 39, - COMMAND_EXPORT_AUTH_CODE = 40, - COMMAND_REGISTER_PIN_HOLDER_CALLBACK = 41, - COMMAND_CREATE_PIN_HOLDER = 42, - COMMAND_DESTROY_PIN_HOLDER = 43, - COMMAND_REGISTER_DISCOVERY_CALLBACK = 49, - COMMAND_UN_REGISTER_DISCOVERY_CALLBACK = 50, - COMMAND_START_DISCOVERING = 51, - COMMAND_STOP_DISCOVERING = 52, - COMMAND_START_ADVERTISING = 53, - COMMAND_STOP_ADVERTISING = 54, - COMMAND_BIND_TARGET = 55, - COMMAND_UNBIND_TARGET = 56, - COMMAND_DP_ACL_ADD = 59, - COMMAND_GET_DEVICE_SECURITY_LEVEL = 60, - COMMAND_IS_SAME_ACCOUNT = 61, - COMMAND_CHECK_API_PERMISSION = 62, - COMMAND_CHECK_ACCESS_CONTROL = 63, - COMMAND_CHECK_IS_SAME_ACCOUNT = 64, - COMMAND_SHIFT_L_N_N_GEAR = 65, - COMMAND_SET_DN_POLICY = 66, - COMMAND_GET_DEVICE_SCREEN_STATUS = 69, - COMMAND_GET_NETWORK_ID_BY_UDID = 70, - COMMAND_SYNC_CALLBACK_TO_SERVICE = 73, - COMMAND_GET_ANONY_LOCAL_UDID = 74, - COMMAND_REGISTER_AUTHENTICATION_TYPE = 75, - COMMAND_PUT_DEVICE_PROFILE_INFO_LIST = 80, - COMMAND_GET_LOCAL_DISPLAY_DEVICE_NAME = 81, - COMMAND_GET_ALL_TRUSTED_DEVICE_LIST = 86, - COMMAND_REGISTER_SERVICE_INFO = 88, - COMMAND_UN_REGISTER_SERVICE_INFO = 89, - COMMAND_UPDATE_SERVICE_INFO = 90, - COMMAND_GET_SERVICE_INFO_BY_SERVICE_ID = 91, - COMMAND_GET_CALLER_SERVICE_INFOS = 92, -}; - -class IDeviceManagerClient : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedHardware.IDeviceManagerClient"); - - virtual ErrCode GetTrustedDeviceList( - const std::string& pkgName, - const std::string& extra, - bool isRefresh, - std::vector& deviceListExt) = 0; - - virtual ErrCode GetLocalDeviceInfo( - const std::string& pkgName, - DmDeviceInfoExt& deviceInfoExt) = 0; - - virtual ErrCode GetUdidByNetworkId( - const std::string& pkgName, - const std::string& netWorkId, - std::string& udid) = 0; - - virtual ErrCode GetUuidByNetworkId( - const std::string& pkgName, - const std::string& netWorkId, - std::string& uuid) = 0; - - virtual ErrCode GetNetworkTypeByNetworkId( - const std::string& pkgName, - const std::string& netWorkId, - int32_t& netWorkType) = 0; - - virtual ErrCode PublishDeviceDiscovery( - const std::string& pkgName, - const DmPublishInfoExt& publishInfoExt) = 0; - - virtual ErrCode UnPublishDeviceDiscovery( - const std::string& pkgName, - int32_t publishId) = 0; - - virtual ErrCode AuthenticateDevice( - const std::string& pkgName, - int32_t authType, - const std::string& deviceId, - const std::string& extra) = 0; - - virtual ErrCode UnAuthenticateDevice( - const std::string& pkgName, - const std::string& netWorkId) = 0; - - virtual ErrCode StopAuthenticateDevice( - const std::string& pkgName) = 0; - - virtual ErrCode CheckCredential( - const std::string& pkgName, - const std::string& reqJsonStr, - std::string& returnJsonStr) = 0; - - virtual ErrCode SetUserOperation( - const std::string& pkgName, - int32_t action, - const std::string& params) = 0; - - virtual ErrCode RequestCredential( - const std::string& pkgName, - const std::string& reqJsonStr, - std::string& returnJsonStr) = 0; - - virtual ErrCode ImportCredential( - const std::string& pkgName, - const std::string& reqJsonStr, - std::string& returnJsonStr) = 0; - - virtual ErrCode DeleteCredential( - const std::string& pkgName, - const std::string& reqJsonStr, - std::string& returnJsonStr) = 0; - - virtual ErrCode RegisterCredentialCallback( - const std::string& pkgName) = 0; - - virtual ErrCode UnRegisterCredentialCallback( - const std::string& pkgName) = 0; - - virtual ErrCode NotifyEvent( - const std::string& pkgName, - int32_t eventId, - const std::string& event) = 0; - - virtual ErrCode GetDeviceInfo( - const std::string& pkgName, - const std::string& networkId, - DmDeviceInfoExt& deviceInfoExt) = 0; - - virtual ErrCode GetEncryptedUuidByNetworkId( - const std::string& pkgName, - const std::string& networkId, - std::string& uuid) = 0; - - virtual ErrCode GenerateEncryptedUuid( - const std::string& pkgName, - const std::string& uuid, - const std::string& appId, - std::string& encryptedUuid) = 0; - - virtual ErrCode BindDevice( - const std::string& pkgName, - int32_t bindType, - const std::string& deviceId, - const std::string& extra) = 0; - - virtual ErrCode UnBindDevice( - const std::string& pkgName, - const std::string& deviceId, - const std::string& extra) = 0; - - virtual ErrCode RegisterUiStateCallback( - const std::string& pkgName) = 0; - - virtual ErrCode UnRegisterUiStateCallback( - const std::string& pkgName) = 0; - - virtual ErrCode ImportAuthCode( - const std::string& pkgName, - const std::string& authCode) = 0; - - virtual ErrCode ExportAuthCode( - std::string& authCode) = 0; - - virtual ErrCode RegisterPinHolderCallback( - const std::string& pkgName) = 0; - - virtual ErrCode CreatePinHolder( - const std::string& pkgName, - const PeerTargetIdExt& targetIdExt, - int32_t pinTypeInt, - const std::string& payload) = 0; - - virtual ErrCode DestroyPinHolder( - const std::string& pkgName, - const PeerTargetIdExt& targetIdExt, - int32_t pinType, - const std::string& payload) = 0; - - virtual ErrCode RegisterDiscoveryCallback( - const std::string& pkgName, - const std::map& discoverParam, - const std::map& filterOptions) = 0; - - virtual ErrCode UnRegisterDiscoveryCallback( - const std::string& pkgName) = 0; - - virtual ErrCode StartDiscovering( - const std::string& pkgName, - const std::map& discoverParam, - const std::map& filterOptions) = 0; - - virtual ErrCode StopDiscovering( - const std::string& pkgName, - const std::map& discoverParam) = 0; - - virtual ErrCode StartAdvertising( - const std::string& pkgName, - const std::string& adverParaStr) = 0; - - virtual ErrCode StopAdvertising( - const std::string& pkgName, - const std::string& adverParaStr) = 0; - - virtual ErrCode BindTarget( - const std::string& pkgName, - const PeerTargetIdExt& targetIdExt, - const std::string& bindParam) = 0; - - virtual ErrCode UnbindTarget( - const std::string& pkgName, - const PeerTargetIdExt& targetIdExt, - const std::string& unbindParam) = 0; - - virtual ErrCode DpAclAdd( - int64_t accessControlId, - const std::string& udid, - int32_t bindType) = 0; - - virtual ErrCode GetDeviceSecurityLevel( - const std::string& pkgName, - const std::string& networkId, - int32_t& securityLevel) = 0; - - virtual ErrCode IsSameAccount( - const std::string& netWorkId, - bool& funcResult) = 0; - - virtual ErrCode CheckApiPermission( - int32_t permissionLevel) = 0; - - virtual ErrCode CheckAccessControl( - const DmAccessCallerExt& callerExt, - const DmAccessCalleeExt& calleeExt, - bool& funcResult) = 0; - - virtual ErrCode CheckIsSameAccount( - const DmAccessCallerExt& callerExt, - const DmAccessCalleeExt& calleeExt, - bool& funcResult) = 0; - - virtual ErrCode ShiftLNNGear( - const std::string& pkgName) = 0; - - virtual ErrCode SetDnPolicy( - const std::string& pkgName, - const std::map& policy) = 0; - - virtual ErrCode GetDeviceScreenStatus( - const std::string& pkgName, - const std::string& networkId, - int32_t& screenStatus) = 0; - - virtual ErrCode GetNetworkIdByUdid( - const std::string& pkgName, - const std::string& udid, - std::string& networkId) = 0; - - virtual ErrCode SyncCallbackToService( - int32_t dmCommonNotifyEvent, - const std::string& pkgName) = 0; - - virtual ErrCode GetAnonyLocalUdid( - const std::string& pkgName, - std::string& anonyUdid) = 0; - - virtual ErrCode RegisterAuthenticationType( - const std::string& pkgName, - const std::string& authTypeStr) = 0; - - virtual ErrCode PutDeviceProfileInfoList( - const std::string& pkgName, - const std::vector& deviceProfileInfoListExt) = 0; - - virtual ErrCode GetLocalDisplayDeviceName( - const std::string& pkgName, - int32_t maxNameLength, - std::string& displayName) = 0; - - virtual ErrCode GetAllTrustedDeviceList( - const std::string& pkgName, - const std::string& extra, - std::vector& deviceListExt) = 0; - - virtual ErrCode RegisterLocalServiceInfo( - const DmLocalServiceInfoExt& info) = 0; - - virtual ErrCode UnRegisterLocalServiceInfo( - const std::string &bundleName, - int32_t pinExchangeType) = 0; - - virtual ErrCode UpdateLocalServiceInfo( - const DmLocalServiceInfoExt& info) = 0; - - virtual ErrCode GetLocalServiceInfoByBundleNameAndPinExchangeType( - const std::string &bundleName, - int32_t pinExchangeType, - DmLocalServiceInfoExt &info) = 0; - - virtual ErrCode RestoreLocalDeviceName( - const std::string &pkgName) = 0; - - virtual ErrCode GetDeviceNetworkIdList( - const std::string &bundleName, - const NetworkIdQueryFilterExt &queryFilter, - std::vector &networkIds) = 0; - - -protected: - static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD004111, "distributedhardware"}; - const int VECTOR_MAX_SIZE = 102400; - const int LIST_MAX_SIZE = 102400; - const int SET_MAX_SIZE = 102400; - const int MAP_MAX_SIZE = 102400; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DISTRIBUTEDHARDWARE_IDEVICEMANAGERCLIENT_H - diff --git a/interfaces/inner_kits/native_cpp/src/device_manager.cpp b/interfaces/inner_kits/native_cpp/src/device_manager.cpp index 028022b16..0f33b5a3d 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager.cpp @@ -14,7 +14,7 @@ */ #include "device_manager.h" -#include "ipc_client_proxy.h" + #include "device_manager_impl.h" namespace OHOS { diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 80880288f..e5df8076c 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -1077,13 +1077,13 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, credentialInfo); - // std::string reqParaStr = ConvertMapToJsonString(requestParam); + std::string reqParaStr = ConvertMapToJsonString(requestParam); // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetPkgName(pkgName); // req->SetCredentialParam(reqParaStr); std::string returnJsonStr; - int32_t ret = deviceManagerInterface_->ImportCredential(pkgName, returnJsonStr, returnJsonStr); + int32_t ret = deviceManagerInterface_->ImportCredential(pkgName, reqParaStr, returnJsonStr); if (ret != DM_OK) { LOGI("ImportCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -1109,13 +1109,13 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, deleteInfo); - // std::string reqParaStr = ConvertMapToJsonString(requestParam); + std::string reqParaStr = ConvertMapToJsonString(requestParam); // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetPkgName(pkgName); // req->SetCredentialParam(reqParaStr); std::string returnJsonStr; - int32_t ret = deviceManagerInterface_->DeleteCredential(pkgName, returnJsonStr, returnJsonStr); + int32_t ret = deviceManagerInterface_->DeleteCredential(pkgName, reqParaStr, returnJsonStr); if (ret != DM_OK) { LOGI("DeleteCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -1235,12 +1235,12 @@ int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, std::st LOGI("Start, pkgName: %{public}s", pkgName.c_str()); std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); - // std::string reqParaStr = ConvertMapToJsonString(requestParam); + std::string reqParaStr = ConvertMapToJsonString(requestParam); // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetPkgName(pkgName); // req->SetCredentialParam(reqParaStr); - int32_t ret = deviceManagerInterface_->RequestCredential(pkgName, returnJsonStr, returnJsonStr); + int32_t ret = deviceManagerInterface_->RequestCredential(pkgName, reqParaStr, returnJsonStr); if (ret != DM_OK) { LOGI("RequestCredential Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; @@ -1295,7 +1295,7 @@ int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); - // std::string reqParaStr = ConvertMapToJsonString(requestParam); + std::string reqParaStr = ConvertMapToJsonString(requestParam); // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetPkgName(pkgName); @@ -1328,12 +1328,11 @@ int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const st std::map requestParam; requestParam.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE); requestParam.emplace(DM_CREDENTIAL_REQJSONSTR, reqJsonStr); - // std::string reqParaStr = ConvertMapToJsonString(requestParam); + std::string reqParaStr = ConvertMapToJsonString(requestParam); // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetPkgName(pkgName); // req->SetCredentialParam(reqParaStr); - int32_t ret = deviceManagerInterface_->DeleteCredential(pkgName, reqJsonStr, returnJsonStr); if (ret != DM_OK) { LOGI("DeleteCredential Send Request failed ret: %{public}d", ret); @@ -2776,7 +2775,7 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, return DM_OK; } -int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DmLocalServiceInfo &info) +int32_t DeviceManagerImpl::RegisterLocalServiceInfo(const DMLocalServiceInfo &info) { LOGI("Start"); // std::shared_ptr req = std::make_shared(); @@ -2817,7 +2816,7 @@ int32_t DeviceManagerImpl::UnRegisterLocalServiceInfo(const std::string &bundleN return DM_OK; } -int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DmLocalServiceInfo &info) +int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DMLocalServiceInfo &info) { LOGI("Start"); // std::shared_ptr req = std::make_shared(); @@ -2838,13 +2837,13 @@ int32_t DeviceManagerImpl::UpdateLocalServiceInfo(const DmLocalServiceInfo &info } int32_t DeviceManagerImpl::GetLocalServiceInfoByBundleNameAndPinExchangeType( - const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfo &info) + const std::string &bundleName, int32_t pinExchangeType, DMLocalServiceInfo &info) { // std::shared_ptr req = std::make_shared(); // std::shared_ptr rsp = std::make_shared(); // req->SetFirstParam(bundleName); // req->SetInt32Param(pinExchangeType); - DmLocalServiceInfoExt dmLocalServiceInfoExt(info); + DMLocalServiceInfoExt dmLocalServiceInfoExt(info); int32_t ret = deviceManagerInterface_->GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, pinExchangeType, dmLocalServiceInfoExt); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp index f1a52c702..0bf7bcefd 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp +++ b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp @@ -205,7 +205,7 @@ DmDeviceBasicInfoExt *DmDeviceBasicInfoExt::Unmarshalling(Parcel &parcel) return deviceBasicInfoExt; } -bool DmLocalServiceInfoExt::Marshalling(Parcel &parcel) const +bool DMLocalServiceInfoExt::Marshalling(Parcel &parcel) const { bool bRet = true; bRet = (bRet && parcel.WriteString(bundleName)); @@ -218,11 +218,11 @@ bool DmLocalServiceInfoExt::Marshalling(Parcel &parcel) const return bRet; } -DmLocalServiceInfoExt *DmLocalServiceInfoExt::Unmarshalling(Parcel &parcel) +DMLocalServiceInfoExt *DMLocalServiceInfoExt::Unmarshalling(Parcel &parcel) { - DmLocalServiceInfoExt *localServiceinfoExt = new (std::nothrow) DmLocalServiceInfoExt(); + DMLocalServiceInfoExt *localServiceinfoExt = new (std::nothrow) DMLocalServiceInfoExt(); if (localServiceinfoExt == nullptr) { - LOGE("Create DmLocalServiceInfoExt failed"); + LOGE("Create DMLocalServiceInfoExt failed"); return nullptr; } localServiceinfoExt->bundleName = parcel.ReadString(); 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 747e11b2e..0423e4731 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 @@ -1864,7 +1864,7 @@ ON_IPC_SET_REQUEST(REG_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, Mess return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DmLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1917,7 +1917,7 @@ ON_IPC_SET_REQUEST(UPDATE_LOCALSERVICE_INFO, std::shared_ptr pBaseReq, M return ERR_DM_FAILED; } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - const DmLocalServiceInfo& info = pReq->GetLocalServiceInfo(); + const DMLocalServiceInfo& info = pReq->GetLocalServiceInfo(); if (!IpcModelCodec::EncodeLocalServiceInfo(info, data)) { LOGE("EncodeLocalServiceInfo failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1965,7 +1965,7 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel if (pBaseRsp->GetErrCode() == DM_OK) { std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - DmLocalServiceInfo info; + DMLocalServiceInfo info; bool ret = IpcModelCodec::DecodeLocalServiceInfo(reply, info); if (!ret) { LOGE("DecodeLocalServiceInfo failed"); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 18ab5f1ac..17d8b08f3 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1608,14 +1608,14 @@ bool DmAuthManager::CanUsePincodeFromDp() { CHECK_NULL_RETURN(authResponseContext_, false); return (IsPinCodeValid(serviceInfoProfile_.GetPinCode()) && - serviceInfoProfile_.GetPinExchangeType() == (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP); + serviceInfoProfile_.GetPinExchangeType() == (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); } bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) { - if (authType != (int32_t)DmLocalServiceInfoAuthType::TRUST_ONETIME && - authType != (int32_t)DmLocalServiceInfoAuthType::TRUST_ALWAYS && - authType != (int32_t)DmLocalServiceInfoAuthType::CANCEL) { + if (authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME && + authType != (int32_t)DMLocalServiceInfoAuthType::TRUST_ALWAYS && + authType != (int32_t)DMLocalServiceInfoAuthType::CANCEL) { return false; } return true; @@ -1623,8 +1623,8 @@ bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) { - if (authBoxType != (int32_t)DmLocalServiceInfoAuthBoxType::STATE3 && - authBoxType != (int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { + if (authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::STATE3 && + authBoxType != (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { return false; } return true; @@ -1632,9 +1632,9 @@ bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) { - if (pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::PINBOX && - pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP && - pinExchangeType != (int32_t)DmLocalServiceInfoPinExchangeType::ULTRASOUND) { + if (pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::PINBOX && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND) { return false; } return true; @@ -1737,7 +1737,7 @@ void DmAuthManager::ShowConfigDialog() return; } if (authResponseContext_->authType == AUTH_TYPE_NFC && - serviceInfoProfile_.GetAuthBoxType() == (int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { + serviceInfoProfile_.GetAuthBoxType() == (int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM) { LOGI("no need confirm dialog"); StartAuthProcess(serviceInfoProfile_.GetAuthType()); return; @@ -3309,7 +3309,7 @@ void DmAuthManager::GetLocalServiceInfoInDp() { DistributedDeviceProfile::LocalServiceInfo localServiceInfo; int32_t result = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( - authResponseContext_->hostPkgName, (int32_t)DmLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); + authResponseContext_->hostPkgName, (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP, localServiceInfo); if (result != DM_OK) { return; } diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index a678e7e81..f6b034e0c 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -30,7 +30,6 @@ #include "dm_common_event_manager.h" #include "parameter.h" #include "common_event_support.h" -#include "dm_ipc_utils.h" using namespace OHOS::EventFwk; #endif diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index 60b5691f4..a6e8e739b 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -151,6 +151,7 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${servicesimpl_path}/include/dependency/deviceprofile", "${softbuscache_parh}/include", + "${utils_path}/include", "${utils_path}/include/appInfo/standard", "${utils_path}/include/crypto", "${utils_path}/include/kvadapter", @@ -230,6 +231,7 @@ if (defined(ohos_lite)) { "src/relationshipsyncmgr/relationship_sync_mgr.cpp", "src/softbus/mine_softbus_listener.cpp", "src/softbus/softbus_listener.cpp", + "${utils_path}/src/dm_ipc_utils.cpp", ] public_configs = [ ":devicemanagerservice_config" ] diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 750afad69..9c75b81a3 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -176,7 +176,8 @@ public: int32_t StopAdvertising(const std::string &pkgName, const std::map &advertiseParam); - int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId,const std::map &bindParam); + int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, + const std::map &bindParam); int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &unbindParam); @@ -226,11 +227,11 @@ public: int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName); std::vector GetDeviceNamePrefixs(); int32_t RestoreLocalDeviceName(const std::string &pkgName); - int32_t RegisterLocalServiceInfo(const DmLocalServiceInfo &serviceInfo); + int32_t RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); int32_t UnRegisterLocalServiceInfo(const std::string &bundleName, int32_t pinExchangeType); - int32_t UpdateLocalServiceInfo(const DmLocalServiceInfo &serviceInfo); + int32_t UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo); int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, int32_t pinExchangeType, - DmLocalServiceInfo &serviceInfo); + DMLocalServiceInfo &serviceInfo); void ClearPublishIdCache(const std::string &pkgName); bool IsPC(); int32_t GetDeviceNetworkIdList(const std::string &pkgName, const NetworkIdQueryFilter &queryFilter, @@ -310,12 +311,12 @@ private: int32_t SendUserIdsByWifi(const std::string &networkId, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); void HandleUserSwitchTimeout(int32_t curUserId, int32_t preUserId, const std::string &udid); - bool InitDPLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, + bool InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem); void InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceItem, - DmLocalServiceInfo &serviceInfo); + DMLocalServiceInfo &serviceInfo); void InitServiceInfos(const std::vector &dpLocalServiceItems, - std::vector &serviceInfos); + std::vector &serviceInfos); void HandleUserSwitched(); void NotifyRemoteLocalUserSwitch(const std::string &localUdid, const std::vector &peerUdids, const std::vector &foregroundUserIds, const std::vector &backgroundUserIds); diff --git a/services/service/include/ipc/standard/device_manager_client_service.h b/services/service/include/ipc/standard/device_manager_client_service.h index 9666c1c0b..928b898be 100644 --- a/services/service/include/ipc/standard/device_manager_client_service.h +++ b/services/service/include/ipc/standard/device_manager_client_service.h @@ -294,19 +294,19 @@ class DeviceManagerClientService : public DeviceManagerClientStub { std::vector& deviceListExt) override; virtual ErrCode RegisterLocalServiceInfo( - const DmLocalServiceInfoExt& info) override; + const DMLocalServiceInfoExt& info) override; virtual ErrCode UnRegisterLocalServiceInfo( const std::string& bundleName, int32_t pinExchangeType) override; virtual ErrCode UpdateLocalServiceInfo( - const DmLocalServiceInfoExt& info) override; + const DMLocalServiceInfoExt& info) override; virtual ErrCode GetLocalServiceInfoByBundleNameAndPinExchangeType( const std::string& bundleName, int32_t pinExchangeType, - DmLocalServiceInfoExt& info) override; + DMLocalServiceInfoExt& info) override; virtual ErrCode RestoreLocalDeviceName( const std::string& pkgName) override; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 42e7ce38d..7d473d7e6 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1566,7 +1566,7 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -bool DeviceManagerService::InitDPLocalServiceInfo(const DmLocalServiceInfo &serviceInfo, +bool DeviceManagerService::InitDPLocalServiceInfo(const DMLocalServiceInfo &serviceInfo, DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo) { dpLocalServiceInfo.SetBundleName(serviceInfo.bundleName); @@ -1580,7 +1580,7 @@ bool DeviceManagerService::InitDPLocalServiceInfo(const DmLocalServiceInfo &serv } void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo, - DmLocalServiceInfo &serviceInfo) + DMLocalServiceInfo &serviceInfo) { serviceInfo.bundleName = dpLocalServiceInfo.GetBundleName(); serviceInfo.authBoxType = dpLocalServiceInfo.GetAuthBoxType(); @@ -1593,17 +1593,17 @@ void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::Local void DeviceManagerService::InitServiceInfos( const std::vector &dpLocalServiceInfos, - std::vector &serviceInfos) + std::vector &serviceInfos) { for (const auto &dpInfoItem : dpLocalServiceInfos) { - DmLocalServiceInfo infoItem; + DMLocalServiceInfo infoItem; InitServiceInfo(dpInfoItem, infoItem); serviceInfos.emplace_back(infoItem); } } #endif -int32_t DeviceManagerService::RegisterLocalServiceInfo(const DmLocalServiceInfo &serviceInfo) +int32_t DeviceManagerService::RegisterLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1630,7 +1630,7 @@ int32_t DeviceManagerService::UnRegisterLocalServiceInfo(const std::string &bund #endif } -int32_t DeviceManagerService::UpdateLocalServiceInfo(const DmLocalServiceInfo &serviceInfo) +int32_t DeviceManagerService::UpdateLocalServiceInfo(const DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1647,7 +1647,7 @@ int32_t DeviceManagerService::UpdateLocalServiceInfo(const DmLocalServiceInfo &s } int32_t DeviceManagerService::GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string &bundleName, - int32_t pinExchangeType, DmLocalServiceInfo &serviceInfo) + int32_t pinExchangeType, DMLocalServiceInfo &serviceInfo) { #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; diff --git a/services/service/src/ipc/standard/device_manager_client_service.cpp b/services/service/src/ipc/standard/device_manager_client_service.cpp index e84944146..70d08b684 100644 --- a/services/service/src/ipc/standard/device_manager_client_service.cpp +++ b/services/service/src/ipc/standard/device_manager_client_service.cpp @@ -14,15 +14,15 @@ */ #include "device_manager_client_stub.h" -#include "foundation/distributedhardware/device_manager/services/service/include/ipc/standard/device_manager_client_service.h" -#include "foundation/distributedhardware/device_manager/services/service/include/device_manager_service.h" +#include "device_manager_client_service.h" +#include "device_manager_service.h" #include "if_system_ability_manager.h" #include "ipc_cmd_register.h" #include "ipc_skeleton.h" #include "ipc_types.h" #include "iservice_registry.h" -#include "foundation/distributedhardware/device_manager/utils/include/dm_ipc_utils.h" -#include "foundation/distributedhardware/device_manager/radar/include/dm_radar_helper.h" +#include "dm_ipc_utils.h" +#include "dm_radar_helper.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #endif #ifdef SUPPORT_MEMMGR @@ -36,7 +36,6 @@ #include "dm_constants.h" #include "dm_device_info.h" #include "dm_log.h" - namespace OHOS { namespace DistributedHardware { // -------------------------------IPC Service Method-------------------------------- @@ -48,10 +47,12 @@ ErrCode DeviceManagerClientService::GetTrustedDeviceList( { std::vector deviceList; DeviceManagerService service; + std::string anonyLocalUdid_; int32_t result = service.GetTrustedDeviceList(pkgName, extra, deviceList); if (result != ERR_OK) { - // DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetTrustedDeviceList", - // deviceList, result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetTrustedDeviceList", + deviceList, result, anonyLocalUdid_); LOGI("GetTrustedDeviceList error, failed ret: %{public}d", result); return result; } @@ -66,10 +67,12 @@ ErrCode DeviceManagerClientService::GetLocalDeviceInfo( (void) pkgName; DmDeviceInfo localDeviceInfo; DeviceManagerService service; + std::string anonyLocalUdid_; int32_t result = service.GetLocalDeviceInfo(localDeviceInfo); if (result != DM_OK) { - // DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", - // info, result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceInfo", + localDeviceInfo, result, anonyLocalUdid_); LOGE("DeviceManagerImpl::GetLocalDeviceInfo error, Send Request failed ret: %{public}d", result); return ERR_DM_IPC_SEND_REQUEST_FAILED; } @@ -127,10 +130,12 @@ ErrCode DeviceManagerClientService::PublishDeviceDiscovery( DmIpcUtils utils; utils.ConvertToPublishInfo(publishInfoExt, publishInfo); DeviceManagerService service; + std::string anonyLocalUdid_; int32_t result = service.PublishDeviceDiscovery(pkgName, publishInfo); if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "PublishDeviceDiscovery", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "PublishDeviceDiscovery", result, anonyLocalUdid_); LOGE("PublishDeviceDiscovery error: Failed with ret %{public}d", result); } return result; @@ -141,9 +146,11 @@ ErrCode DeviceManagerClientService::UnPublishDeviceDiscovery( int32_t publishId) { DeviceManagerService service; + std::string anonyLocalUdid_; int32_t result = service.UnPublishDeviceDiscovery(pkgName, publishId); if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnPublishDeviceDiscovery", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnPublishDeviceDiscovery", result, anonyLocalUdid_); LOGE("UnPublishDeviceDiscovery error: Failed with ret %{public}d", result); } return result; @@ -184,9 +191,11 @@ ErrCode DeviceManagerClientService::StopAuthenticateDevice( { int32_t result = ERR_OK; DeviceManagerService service; + std::string anonyLocalUdid_; result = service.StopAuthenticateDevice(pkgName); if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "StopAuthenticateDevice", result, anonyLocalUdid_); LOGE("StopAuthenticateDevice error: Failed with ret %{public}d", result); } return result; @@ -330,8 +339,10 @@ ErrCode DeviceManagerClientService::NotifyEvent( { DeviceManagerService service; int32_t result = service.NotifyEvent(pkgName, eventId, event); + std::string anonyLocalUdid_; if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "NotifyEvent", result, anonyLocalUdid_); LOGE("NotifyEvent failed with ret %{public}d", result); } return result; @@ -345,9 +356,11 @@ ErrCode DeviceManagerClientService::GetDeviceInfo( DmDeviceInfo deviceInfo; DeviceManagerService service; int32_t result = service.GetDeviceInfo(networkId, deviceInfo); + std::string anonyLocalUdid_; if (result != ERR_OK) { - // DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", - // deviceInfo, result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportGetDeviceInfo(pkgName, "GetDeviceInfo", + deviceInfo, result, anonyLocalUdid_); LOGE("DeviceManagerImpl::GetDeviceInfo error, failed ret: %{public}d", result); return result; } @@ -420,8 +433,10 @@ ErrCode DeviceManagerClientService::RegisterUiStateCallback( int32_t result = ERR_OK; DeviceManagerService service; result = service.RegisterUiStateCallback(pkgName); + std::string anonyLocalUdid_; if (result != ERR_OK) { - // DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterUiStateCallback", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterUiStateCallback", result, anonyLocalUdid_); LOGE("RegisterUiStateCallback Failed with ret %{public}d", result); } return result; @@ -433,8 +448,10 @@ ErrCode DeviceManagerClientService::UnRegisterUiStateCallback( int32_t result = ERR_OK; DeviceManagerService service; result = service.UnRegisterUiStateCallback(pkgName); + std::string anonyLocalUdid_; if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnRegisterUiStateCallback", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "UnRegisterUiStateCallback", result, anonyLocalUdid_); LOGE("UnRegisterUiStateCallback Failed with ret %{public}d", result); } return result; @@ -468,8 +485,10 @@ ErrCode DeviceManagerClientService::RegisterPinHolderCallback( { DeviceManagerService service; int32_t result = service.RegisterPinHolderCallback(pkgName); + std::string anonyLocalUdid_; if (result != DM_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", result, anonyLocalUdid_); // TODO anonyLocalUdid_ + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "RegisterPinHolderCallback", result, anonyLocalUdid_); LOGE("RegisterPinHolderCallback Failed with ret %{public}d", result); } return ERR_OK; @@ -641,8 +660,10 @@ ErrCode DeviceManagerClientService::GetDeviceSecurityLevel( securityLevel = -1; DeviceManagerService service; int32_t result = service.GetDeviceSecurityLevel(pkgName, networkId, securityLevel); + std::string anonyLocalUdid_; if (result != DM_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "GetDeviceSecurityLevel", result, anonyLocalUdid_); LOGE("GetDeviceSecurityLevel Failed with ret %{public}d", result); } return result; @@ -726,8 +747,10 @@ ErrCode DeviceManagerClientService::SetDnPolicy( { DeviceManagerService service; int32_t result = service.SetDnPolicy(pkgName, policy); + std::string anonyLocalUdid_; if (result != ERR_OK) { - //DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", result, anonyLocalUdid_); + service.GetAnonyLocalUdid(pkgName, anonyLocalUdid_); + DmRadarHelper::GetInstance().ReportDmBehavior(pkgName, "SetDnPolicy", result, anonyLocalUdid_); LOGE("Failed with ret %{public}d", result); } return result; @@ -842,7 +865,7 @@ ErrCode DeviceManagerClientService::GetAllTrustedDeviceList( } ErrCode DeviceManagerClientService::RegisterLocalServiceInfo( - const DmLocalServiceInfoExt& info) + const DMLocalServiceInfoExt& info) { DeviceManagerService service; int32_t result = service.RegisterLocalServiceInfo(info); @@ -864,10 +887,10 @@ ErrCode DeviceManagerClientService::UnRegisterLocalServiceInfo( } ErrCode DeviceManagerClientService::UpdateLocalServiceInfo( - const DmLocalServiceInfoExt& info) + const DMLocalServiceInfoExt& info) { - DmLocalServiceInfoExt serviceInfo; - DmIpcUtils::ConvertToDmLocalServiceInfo(info, serviceInfo); + DMLocalServiceInfoExt serviceInfo; + DmIpcUtils::ConvertToDMLocalServiceInfo(info, serviceInfo); DeviceManagerService service; int32_t result = service.UpdateLocalServiceInfo(info); if (result != ERR_OK) { @@ -877,10 +900,10 @@ ErrCode DeviceManagerClientService::UpdateLocalServiceInfo( } ErrCode DeviceManagerClientService::GetLocalServiceInfoByBundleNameAndPinExchangeType( - const std::string &bundleName, int32_t pinExchangeType, DmLocalServiceInfoExt &info) + const std::string &bundleName, int32_t pinExchangeType, DMLocalServiceInfoExt &info) { - DmLocalServiceInfoExt serviceInfo; - DmIpcUtils::ConvertToDmLocalServiceInfo(info, serviceInfo); + DMLocalServiceInfoExt serviceInfo; + DmIpcUtils::ConvertToDMLocalServiceInfo(info, serviceInfo); DeviceManagerService service; int32_t result = service.GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, pinExchangeType,info); if (result != ERR_OK) { diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 16b92ac60..607e50b9f 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -972,7 +972,7 @@ ON_IPC_CMD(STOP_ADVERTISING, MessageParcel &data, MessageParcel &reply) std::string adverParaStr = data.ReadString(); std::map advertiseParam; ParseMapFromJsonString(adverParaStr, advertiseParam); - int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName,advertiseParam); + int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName, advertiseParam); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; @@ -1739,7 +1739,7 @@ ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &re ON_IPC_CMD(REG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); int32_t result = DeviceManagerService::GetInstance().RegisterLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { @@ -1763,7 +1763,7 @@ ON_IPC_CMD(UNREG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) ON_IPC_CMD(UPDATE_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo); int32_t result = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { @@ -1777,7 +1777,7 @@ ON_IPC_CMD(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &data, Me { std::string bundleName = data.ReadString(); int32_t pinExchangeType = data.ReadInt32(); - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; int32_t result = DeviceManagerService::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( bundleName, pinExchangeType, serviceInfo); if (!reply.WriteInt32(result)) { diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 153ef7bab..3eeb05cbd 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -2045,7 +2045,7 @@ HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestS authManager_->authResponseContext_->authType = AUTH_TYPE_NFC; authManager_->serviceInfoProfile_.SetPinCode(std::to_string(PINCODE)); authManager_->serviceInfoProfile_.SetPinExchangeType( - static_cast(DmLocalServiceInfoPinExchangeType::FROMDP)); + static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); bool ret = authManager_->CheckNeedShowAuthInfoDialog(errorCode); ASSERT_TRUE(ret); @@ -2058,9 +2058,9 @@ HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestS authManager_->GetLocalServiceInfoInDp(); DistributedDeviceProfile::LocalServiceInfo localServiceInfo; - localServiceInfo.SetAuthType(static_cast(DmLocalServiceInfoAuthType::TRUST_ONETIME)); - localServiceInfo.SetAuthBoxType(static_cast(DmLocalServiceInfoAuthBoxType::STATE3)); - localServiceInfo.SetPinExchangeType(static_cast(DmLocalServiceInfoPinExchangeType::FROMDP)); + localServiceInfo.SetAuthType(static_cast(DMLocalServiceInfoAuthType::TRUST_ONETIME)); + localServiceInfo.SetAuthBoxType(static_cast(DMLocalServiceInfoAuthBoxType::STATE3)); + localServiceInfo.SetPinExchangeType(static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); localServiceInfo.SetPinCode(std::to_string(PINCODE)); EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _)) .WillOnce(DoAll(SetArgReferee<2>(localServiceInfo), Return(DM_OK))); @@ -2086,17 +2086,17 @@ HWTEST_F(DmAuthManagerTest, IsPinCodeValid_001, testing::ext::TestSize.Level1) authManager_->authResponseContext_ = std::make_shared(); authManager_->serviceInfoProfile_.SetAuthBoxType( - static_cast(DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM)); + static_cast(DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM)); authManager_->authResponseContext_->authType = AUTH_TYPE_NFC; authManager_->serviceInfoProfile_.SetPinCode(std::to_string(PINCODE)); authManager_->serviceInfoProfile_.SetPinExchangeType( - static_cast(DmLocalServiceInfoPinExchangeType::FROMDP)); + static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); authManager_->ShowConfigDialog(); authManager_->authResponseContext_->isShowDialog = false; authManager_->serviceInfoProfile_.SetPinExchangeType( - static_cast(DmLocalServiceInfoPinExchangeType::PINBOX)); + static_cast(DMLocalServiceInfoPinExchangeType::PINBOX)); authManager_->ShowConfigDialog(); authManager_->authResponseContext_->isShowDialog = true; @@ -2139,15 +2139,15 @@ HWTEST_F(DmAuthManagerTest, IsLocalServiceInfoValid_001, testing::ext::TestSize. profile.SetAuthType(2); ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetAuthType(static_cast(DmLocalServiceInfoAuthType::TRUST_ONETIME)); + profile.SetAuthType(static_cast(DMLocalServiceInfoAuthType::TRUST_ONETIME)); profile.SetAuthBoxType(3); ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetAuthBoxType(static_cast(DmLocalServiceInfoAuthBoxType::STATE3)); + profile.SetAuthBoxType(static_cast(DMLocalServiceInfoAuthBoxType::STATE3)); profile.SetPinExchangeType(4); ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile)); - profile.SetPinExchangeType(static_cast(DmLocalServiceInfoPinExchangeType::FROMDP)); + profile.SetPinExchangeType(static_cast(DMLocalServiceInfoPinExchangeType::FROMDP)); profile.SetPinCode(""); ASSERT_TRUE(authManager_->IsLocalServiceInfoValid(profile)); @@ -2196,9 +2196,9 @@ HWTEST_F(DmAuthManagerTest, ParseHmlInfoInJsonObject_001, testing::ext::TestSize HWTEST_F(DmAuthManagerTest, CanUsePincodeFromDp_001, testing::ext::TestSize.Level1) { DistributedDeviceProfile::LocalServiceInfo info; - info.SetAuthBoxType((int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM); - info.SetAuthType((int32_t)DmLocalServiceInfoAuthType::TRUST_ONETIME); - info.SetPinExchangeType((int32_t)DmLocalServiceInfoPinExchangeType::FROMDP); + info.SetAuthBoxType((int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM); + info.SetAuthType((int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME); + info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); info.SetPinCode("******"); authManager_->serviceInfoProfile_ = info; ASSERT_FALSE(authManager_->CanUsePincodeFromDp()); @@ -2212,7 +2212,7 @@ HWTEST_F(DmAuthManagerTest, CanUsePincodeFromDp_001, testing::ext::TestSize.Leve authManager_->serviceInfoProfile_ = info; ASSERT_TRUE(authManager_->CanUsePincodeFromDp()); - info.SetPinExchangeType((int32_t)DmLocalServiceInfoPinExchangeType::ULTRASOUND); + info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND); info.SetPinCode("123456"); authManager_->serviceInfoProfile_ = info; ASSERT_FALSE(authManager_->CanUsePincodeFromDp()); diff --git a/test/commonunittest/UTTest_dm_auth_manager_second.cpp b/test/commonunittest/UTTest_dm_auth_manager_second.cpp index 308b27162..89df6d0d3 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_second.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_second.cpp @@ -519,9 +519,9 @@ HWTEST_F(DmAuthManagerTest, ConfirmProcessExt_003, testing::ext::TestSize.Level1 HWTEST_F(DmAuthManagerTest, ConfirmProcessExt_004, testing::ext::TestSize.Level0) { DistributedDeviceProfile::LocalServiceInfo info; - info.SetAuthBoxType((int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM); - info.SetAuthType((int32_t)DmLocalServiceInfoAuthType::TRUST_ONETIME); - info.SetPinExchangeType((int32_t)DmLocalServiceInfoPinExchangeType::FROMDP); + info.SetAuthBoxType((int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM); + info.SetAuthType((int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME); + info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); info.SetPinCode("123456"); authManager_->serviceInfoProfile_ = info; ASSERT_TRUE(authManager_->CanUsePincodeFromDp()); @@ -747,9 +747,9 @@ HWTEST_F(DmAuthManagerTest, ShowAuthInfoDialog_003, testing::ext::TestSize.Level HWTEST_F(DmAuthManagerTest, ShowAuthInfoDialog_004, testing::ext::TestSize.Level0) { DistributedDeviceProfile::LocalServiceInfo info; - info.SetAuthBoxType((int32_t)DmLocalServiceInfoAuthBoxType::SKIP_CONFIRM); - info.SetAuthType((int32_t)DmLocalServiceInfoAuthType::TRUST_ONETIME); - info.SetPinExchangeType((int32_t)DmLocalServiceInfoPinExchangeType::FROMDP); + info.SetAuthBoxType((int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM); + info.SetAuthType((int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME); + info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::FROMDP); info.SetPinCode("123456"); authManager_->serviceInfoProfile_ = info; ASSERT_TRUE(authManager_->CanUsePincodeFromDp()); diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 6c399076a..e711089af 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2600,7 +2600,7 @@ HWTEST_F(DeviceManagerImplTest, GetAllTrustedDeviceList_001, testing::ext::TestS HWTEST_F(DeviceManagerImplTest, RegisterLocalServiceInfo_001, testing::ext::TestSize.Level0) { - DmLocalServiceInfo info; + DMLocalServiceInfo info; std::shared_ptr mockInstance = std::make_shared(); std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; @@ -2637,7 +2637,7 @@ HWTEST_F(DeviceManagerImplTest, UnRegisterLocalServiceInfo_001, testing::ext::Te HWTEST_F(DeviceManagerImplTest, UpdateLocalServiceInfo_001, testing::ext::TestSize.Level0) { - DmLocalServiceInfo info; + DMLocalServiceInfo info; std::shared_ptr mockInstance = std::make_shared(); std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; @@ -2657,7 +2657,7 @@ HWTEST_F(DeviceManagerImplTest, GetLocalServiceInfoByBundleNameAndPinExchangeTyp { std::string bundleName = "b*********kl"; int32_t pinExchangeType = 1; - DmLocalServiceInfo info; + DMLocalServiceInfo info; std::shared_ptr mockInstance = std::make_shared(); std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 330007bbd..d98ba1211 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1463,7 +1463,7 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceInfo_202, testing::ext::TestSize.Lev HWTEST_F(DeviceManagerServiceTest, InitDPLocalServiceInfo_201, testing::ext::TestSize.Level1) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; bool ret = DeviceManagerService::GetInstance().InitDPLocalServiceInfo(serviceInfo, dpLocalServiceInfo); EXPECT_TRUE(ret); @@ -1471,13 +1471,13 @@ HWTEST_F(DeviceManagerServiceTest, InitDPLocalServiceInfo_201, testing::ext::Tes DeviceManagerService::GetInstance().InitServiceInfo(dpLocalServiceInfo, serviceInfo); std::vector dpLocalServiceInfos; dpLocalServiceInfos.push_back(dpLocalServiceInfo); - std::vector serviceInfos; + std::vector serviceInfos; DeviceManagerService::GetInstance().InitServiceInfos(dpLocalServiceInfos, serviceInfos); } HWTEST_F(DeviceManagerServiceTest, RegisterLocalServiceInfo_201, testing::ext::TestSize.Level1) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; EXPECT_CALL(*deviceProfileConnectorMock_, PutLocalServiceInfo(_)).WillOnce(Return(DM_OK)); int32_t ret = DeviceManagerService::GetInstance().RegisterLocalServiceInfo(serviceInfo); EXPECT_EQ(ret, DM_OK); @@ -1507,7 +1507,7 @@ HWTEST_F(DeviceManagerServiceTest, UnRegisterLocalServiceInfo_201, testing::ext: HWTEST_F(DeviceManagerServiceTest, UpdateLocalServiceInfo_201, testing::ext::TestSize.Level1) { - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; EXPECT_CALL(*deviceProfileConnectorMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(DM_OK)); int32_t ret = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo); EXPECT_EQ(ret, DM_OK); @@ -1562,7 +1562,7 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalServiceInfoByBundleNameAndPinExchange { std::string bundleName = "bund******98"; int32_t pinExchangeType = 1; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _)) .WillOnce(Return(DM_OK)); int32_t ret = DeviceManagerService::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, @@ -1606,7 +1606,7 @@ HWTEST_F(DeviceManagerServiceTest, GetLocalServiceInfoByBundleNameAndPinExchange HWTEST_F(DeviceManagerServiceTest, InitDPLocalServiceInfo_001, testing::ext::TestSize.Level0) { - DmLocalServiceInfo dmServiceInfo; + DMLocalServiceInfo dmServiceInfo; dmServiceInfo.bundleName = "testbundle"; dmServiceInfo.extraInfo = "testextra"; DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1617,7 +1617,7 @@ HWTEST_F(DeviceManagerServiceTest, InitDPLocalServiceInfo_001, testing::ext::Tes HWTEST_F(DeviceManagerServiceTest, InitServiceInfo_001, testing::ext::TestSize.Level0) { - DmLocalServiceInfo dmServiceInfo; + DMLocalServiceInfo dmServiceInfo; DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; dpLocalServiceInfo.SetBundleName("testbundle"); dpLocalServiceInfo.SetExtraInfo("testextra"); @@ -1628,7 +1628,7 @@ HWTEST_F(DeviceManagerServiceTest, InitServiceInfo_001, testing::ext::TestSize.L HWTEST_F(DeviceManagerServiceTest, InitServiceInfos_001, testing::ext::TestSize.Level0) { - std::vector dmServiceInfos; + std::vector dmServiceInfos; std::vector dpLocalServiceInfos; for (int k = 0; k < NUM_5; k++) { DistributedDeviceProfile::LocalServiceInfo dpLocalServiceInfo; @@ -1638,7 +1638,7 @@ HWTEST_F(DeviceManagerServiceTest, InitServiceInfos_001, testing::ext::TestSize. } DeviceManagerService::GetInstance().InitServiceInfos(dpLocalServiceInfos, dmServiceInfos); for (int k = 0; k < NUM_5; k++) { - DmLocalServiceInfo &dmServiceInfo = dmServiceInfos[k]; + DMLocalServiceInfo &dmServiceInfo = dmServiceInfos[k]; DistributedDeviceProfile::LocalServiceInfo &dpLocalServiceInfo = dpLocalServiceInfos[k]; EXPECT_TRUE(dmServiceInfo.bundleName == dpLocalServiceInfo.GetBundleName()); EXPECT_TRUE(dmServiceInfo.extraInfo == dpLocalServiceInfo.GetExtraInfo()); diff --git a/test/unittest/UTTest_ipc_cmd_parser_client.cpp b/test/unittest/UTTest_ipc_cmd_parser_client.cpp index dee532b0d..58f9bd3ed 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_client.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_client.cpp @@ -392,7 +392,7 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_090, testing::ext::TestSize.Le MessageParcel reply2; reply2.WriteInt32(DM_OK); - DmLocalServiceInfo info; + DMLocalServiceInfo info; info.bundleName = "debug"; ASSERT_TRUE(IpcModelCodec::EncodeLocalServiceInfo(info, reply2)); if (ptr) { @@ -648,7 +648,7 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_015, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_031, testing::ext::TestSize.Level0) { int32_t cmdCode = REG_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetLocalServiceInfo(serviceInfo); @@ -664,7 +664,7 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_031, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_032, testing::ext::TestSize.Level0) { int32_t cmdCode = UNREG_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetFirstParam(std::string("testbundle")); @@ -681,7 +681,7 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_032, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_033, testing::ext::TestSize.Level0) { int32_t cmdCode = UPDATE_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetLocalServiceInfo(serviceInfo); @@ -697,7 +697,7 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_033, testing::ext::TestSize.L HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_034, testing::ext::TestSize.Level0) { int32_t cmdCode = GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetFirstParam(std::string("testbundle")); diff --git a/test/unittest/UTTest_ipc_cmd_parser_service.cpp b/test/unittest/UTTest_ipc_cmd_parser_service.cpp index a7cab804b..bdc61c11e 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_service.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_service.cpp @@ -1321,7 +1321,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_054, testing::ext::TestSize.Level HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_060, testing::ext::TestSize.Level0) { int32_t cmdCode = REG_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; serviceInfo.bundleName = "testbundle"; serviceInfo.extraInfo = "testextra"; MessageParcel data; @@ -1344,7 +1344,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_060, testing::ext::TestSize.Level HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_061, testing::ext::TestSize.Level0) { int32_t cmdCode = UNREG_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetFirstParam(std::string("testbundle")); @@ -1366,7 +1366,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_061, testing::ext::TestSize.Level HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_062, testing::ext::TestSize.Level0) { int32_t cmdCode = UPDATE_LOCALSERVICE_INFO; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetLocalServiceInfo(serviceInfo); @@ -1387,7 +1387,7 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_062, testing::ext::TestSize.Level HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_063, testing::ext::TestSize.Level0) { int32_t cmdCode = GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE; - DmLocalServiceInfo serviceInfo; + DMLocalServiceInfo serviceInfo; MessageParcel data; std::shared_ptr req = std::make_shared(); req->SetFirstParam(std::string("testbundle")); diff --git a/utils/include/dm_ipc_utils.h b/utils/include/dm_ipc_utils.h index 901d9ddea..4b53c3467 100644 --- a/utils/include/dm_ipc_utils.h +++ b/utils/include/dm_ipc_utils.h @@ -33,9 +33,9 @@ public: static void ConvertToDmAccessCallee(const DmAccessCalleeExt& ext, DmAccessCallee& base); static void ConvertToDmDeviceProfileInfoVector(const std::vector& deviceProfileInfoListExt, std::vector &deviceProfileInfoList); - static void ConverToDMServiceInfoVector(std::vector& serviceInfoExt, - std::vector &serviceInfos); - static void ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, DmLocalServiceInfo& base); + static void ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos); + static void ConvertToDMLocalServiceInfo(const DMLocalServiceInfoExt& ext, DMLocalServiceInfo& base); static void ConvertToNetworkIdQueryFilter(const NetworkIdQueryFilterExt& ext, NetworkIdQueryFilter& base); }; diff --git a/utils/src/dm_ipc_utils.cpp b/utils/src/dm_ipc_utils.cpp index 901e8e87f..669242db5 100644 --- a/utils/src/dm_ipc_utils.cpp +++ b/utils/src/dm_ipc_utils.cpp @@ -138,13 +138,13 @@ void DmIpcUtils::ConvertToDmDeviceProfileInfoVector(const std::vector& serviceInfoExt, - std::vector &serviceInfos) +void DmIpcUtils::ConverToDMServiceInfoVector(std::vector& serviceInfoExt, + std::vector &serviceInfos) { serviceInfos.clear(); serviceInfos.reserve(serviceInfoExt.size()); for (const auto& ext : serviceInfoExt) { - DmLocalServiceInfo base; + DMLocalServiceInfo base; base.bundleName = ext.bundleName; base.authBoxType = ext.authBoxType; base.authType = ext.authType; @@ -155,7 +155,7 @@ void DmIpcUtils::ConverToDMServiceInfoVector(std::vector& } } -void DmIpcUtils::ConvertToDmLocalServiceInfo(const DmLocalServiceInfoExt& ext, DmLocalServiceInfo& base) +void DmIpcUtils::ConvertToDMLocalServiceInfo(const DMLocalServiceInfoExt& ext, DMLocalServiceInfo& base) { base.bundleName = ext.bundleName; -- Gitee