diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..e9fc8ec83ec8f20d99dc3a7c2621c4e342202171 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,60 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "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", + "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" + } +} \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 2068a5585b19c581039241a6e5110ae529ed7035..904fe32daf414327c0790aaeda40c2cc7b17a0fb 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -15,6 +15,7 @@ if (defined(ohos_lite)) { import("//build/lite/config/component/lite_component.gni") } else { import("//build/ohos.gni") + import("//build/config/components/idl_tool/idl.gni") } import("//foundation/distributedhardware/device_manager/device_manager.gni") @@ -146,13 +147,43 @@ if (defined(ohos_lite)) { "${devicemanager_path}/radar/include", "${utils_path}/include", "${json_path}/include", + "${devicemanager_path}/services/service/include", + "${target_gen_dir}", ] } + idl_gen_interface("device_manager_interface") { + src_idl = rebase_path("${devicemanager_path}/services/service/IDeviceManagerIpc.idl") + log_tag = "devicemanagerservice" + log_domainid = "0xD004110" + } + ohos_source_set("device_manager_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + 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" + } ohos_shared_library("devicemanagersdk") { branch_protector_ret = "pac_ret" - sanitize = { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false boundary_sanitize = true integer_overflow = true ubsan = true @@ -181,6 +212,7 @@ if (defined(ohos_lite)) { "src/device_manager.cpp", "src/device_manager_impl.cpp", "src/dm_device_info.cpp", + "src/dm_device_profile_info.cpp", "src/ipc/ipc_client_proxy.cpp", "src/ipc/standard/dm_service_load.cpp", "src/ipc/standard/ipc_client_manager.cpp", @@ -188,6 +220,8 @@ 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/notify/device_manager_notify_service.cpp", + "${devicemanager_path}/utils/src/dm_ipc_utils.cpp", ] public_configs = [ ":devicemanagersdk_config" ] @@ -200,7 +234,10 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004111", ] - deps = [ "${json_path}:devicemanagerjson" ] + deps = [ + "${json_path}:devicemanagerjson", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", 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 67c3a32aec0a6114bef43e50c0ce4ad577cbf7eb..836e02d15e956df99849dbb8b99070aa0b5c3b7a 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -20,7 +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) @@ -194,6 +194,23 @@ typedef struct DmDeviceInfo { std::string extraData; } DmDeviceInfo; +typedef struct DmDeviceInfoExt : public DmDeviceInfo, public Parcelable { + using DmDeviceInfo::DmDeviceInfo; + DmDeviceInfoExt(const DmDeviceInfo &devInfo) + { + memcpy_s(deviceId, DM_MAX_DEVICE_ID_LEN, devInfo.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(deviceName, DM_MAX_DEVICE_NAME_LEN, devInfo.deviceName, DM_MAX_DEVICE_NAME_LEN); + deviceTypeId = devInfo.deviceTypeId; + memcpy_s(networkId, DM_MAX_DEVICE_ID_LEN, 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); +} DmDeviceInfoExt; + /** * @brief Device Basic Information. */ @@ -222,6 +239,20 @@ DmDeviceBasicInfo { std::string extraData; } DmDeviceBasicInfo; +typedef struct DmDeviceBasicInfoExt : public DmDeviceBasicInfo, public Parcelable { + using DmDeviceBasicInfo::DmDeviceBasicInfo; + DmDeviceBasicInfoExt(const DmDeviceBasicInfo &devBasicInfo) + { + memcpy_s(deviceId, DM_MAX_DEVICE_ID_LEN, devBasicInfo.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(deviceName, DM_MAX_DEVICE_NAME_LEN, devBasicInfo.deviceName, DM_MAX_DEVICE_NAME_LEN); + deviceTypeId = devBasicInfo.deviceTypeId; + memcpy_s(networkId, DM_MAX_DEVICE_ID_LEN, devBasicInfo.networkId, DM_MAX_DEVICE_ID_LEN); + extraData = devBasicInfo.extraData; + } + virtual bool Marshalling(Parcel &parcel) const override; + static DmDeviceBasicInfoExt *Unmarshalling(Parcel &parcel); +} DmDeviceBasicInfoExt; + /** * @brief Device Authentication param. */ @@ -310,6 +341,34 @@ typedef struct PeerTargetId { } } PeerTargetId; +typedef 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; + } + bool operator==(const PeerTargetIdExt &other) const + { + return (deviceId == other.deviceId) && (brMac == other.brMac) && + (bleMac == other.bleMac) && (wifiIp == other.wifiIp) && (wifiPort == other.wifiPort); + } + bool operator<(const PeerTargetIdExt &other) const + { + return (deviceId < other.deviceId) || + (deviceId == other.deviceId && brMac < other.brMac) || + (deviceId == other.deviceId && brMac == other.brMac && bleMac < other.bleMac) || + (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp < other.wifiIp) || + (deviceId == other.deviceId && brMac == other.brMac && bleMac == other.bleMac && wifiIp == other.wifiIp && + wifiPort < other.wifiPort); + } + virtual bool Marshalling(Parcel &parcel) const override; + static PeerTargetIdExt *Unmarshalling(Parcel &parcel); +} PeerTargetIdExt; + typedef enum { BIT_NETWORK_TYPE_UNKNOWN = 0, /**< Unknown network type */ BIT_NETWORK_TYPE_WIFI, /**< WIFI network type */ 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 21bde5a1eabd48704fc3c4913abf7102e1e352e9..a6b9ead8a4635d0ad9385997ea59f4ed74bb5589 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 @@ -20,7 +20,7 @@ #include #include #include - +#include "parcel.h" namespace OHOS { namespace DistributedHardware { typedef struct DmProductInfo { @@ -59,6 +59,24 @@ typedef struct DmDeviceIconInfo { } } DmDeviceIconInfo; +typedef struct DmDeviceIconInfoExt : public DmDeviceIconInfo, public Parcelable { + using DmDeviceIconInfo::DmDeviceIconInfo; + DmDeviceIconInfoExt(const DmDeviceIconInfo &iconInfo) + { + productId = iconInfo.productId; + subProductId = iconInfo.subProductId; + internalModel = iconInfo.internalModel; + imageType = iconInfo.imageType; + specName = iconInfo.specName; + wiseVersion = iconInfo.wiseVersion; + version = iconInfo.version; + url = iconInfo.url; + icon = iconInfo.icon; + } + virtual bool Marshalling(Parcel &parcel) const override; + static DmDeviceIconInfoExt *Unmarshalling(Parcel &parcel); +} DmDeviceIconInfoExt; + typedef struct DmServiceProfileInfo { std::string deviceId = ""; std::string serviceId = ""; @@ -66,6 +84,19 @@ typedef struct DmServiceProfileInfo { std::map data = {}; } DmServiceProfileInfo; +typedef struct DmServiceProfileInfoExt : public DmServiceProfileInfo, public Parcelable { + using DmServiceProfileInfo::DmServiceProfileInfo; + DmServiceProfileInfoExt(const DmServiceProfileInfo &svrInfo) + { + deviceId = svrInfo.deviceId; + serviceId = svrInfo.serviceId; + serviceType = svrInfo.serviceType; + data = svrInfo.data; + } + virtual bool Marshalling(Parcel &parcel) const override; + static DmServiceProfileInfoExt *Unmarshalling(Parcel &parcel); +} DmServiceProfileInfoExt; + typedef struct DmDeviceProfileInfoFilterOptions { bool isCloud = true; std::vector deviceIdList = {}; @@ -101,6 +132,46 @@ typedef struct DmDeviceProfileInfo { std::vector services = {}; } DmDeviceProfileInfo; +typedef struct DmDeviceProfileInfoExt : public DmDeviceProfileInfo, public Parcelable { + using DmDeviceProfileInfo::DmDeviceProfileInfo; + DmDeviceProfileInfoExt(const DmDeviceProfileInfo &profileInfo) + { + deviceId = profileInfo.deviceId; + deviceSn = profileInfo.deviceSn; + mac = profileInfo.mac; + model = profileInfo.model; + internalModel = profileInfo.internalModel; + deviceType = profileInfo.deviceType; + manufacturer = profileInfo.manufacturer; + deviceName = profileInfo.deviceName; + productName = profileInfo.productName; + productId = profileInfo.productId; + subProductId = profileInfo.subProductId; + sdkVersion = profileInfo.sdkVersion; + bleMac = profileInfo.bleMac; + brMac = profileInfo.brMac; + sleMac = profileInfo.sleMac; + firmwareVersion = profileInfo.firmwareVersion; + hardwareVersion = profileInfo.hardwareVersion; + softwareVersion = profileInfo.softwareVersion; + protocolType = profileInfo.protocolType; + setupType = profileInfo.setupType; + wiseDeviceId = profileInfo.wiseDeviceId; + wiseUserId = profileInfo.wiseUserId; + registerTime = profileInfo.registerTime; + modifyTime = profileInfo.modifyTime; + shareTime = profileInfo.shareTime; + isLocalDevice = profileInfo.isLocalDevice; + services = profileInfo.services; + } + + virtual bool Marshalling(Parcel &parcel) const override; + static DmDeviceProfileInfoExt *Unmarshalling(Parcel &parcel); + static void DecodeDmServiceProfileInfos(Parcel &parcel, std::vector &svrInfos); + static bool EncodeDmServiceProfileInfos(const std::vector &svrInfos, + Parcel &parcel); +} DmDeviceProfileInfoExt; + typedef struct NetworkIdQueryFilter { std::string wiseDeviceId = ""; int32_t onlineStatus = 0; diff --git a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h index ef49a67ea933013c0a5c8f55e7280b4746c2f513..d62dc534386ff8e3a56b61947c05cdf9c3f41aec 100644 --- a/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h +++ b/interfaces/inner_kits/native_cpp/include/ipc/standard/ipc_client_manager.h @@ -19,7 +19,7 @@ #include "ipc_client.h" #include "ipc_client_stub.h" #include "system_ability_status_change_stub.h" - +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { class DmDeathRecipient : public IRemoteObject::DeathRecipient { @@ -70,7 +70,7 @@ private: void SubscribeDMSAChangeListener(); private: std::mutex lock_; - std::map> dmListener_; + std::map> dmListener_; sptr dmInterface_ { nullptr }; sptr dmRecipient_ { nullptr }; std::atomic isSubscribeDMSAChangeListener = false; diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 39a229cc8fa23bb023351d03ab785b694637c7ab..178f263824d85d5d35b49242bc1f6498bb7db5c7 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -120,7 +120,7 @@ public: void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult); void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, int32_t status, int32_t reason); - void OnUiCall(std::string &pkgName, std::string ¶mJson); + void OnUiCall(const std::string &pkgName, const std::string ¶mJson); void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult); void OnPinHolderCreate(const std::string &deviceId, const std::string &pkgName, DmPinType pinType, const std::string &payload); diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h new file mode 100644 index 0000000000000000000000000000000000000000..9f53fc7f7599ff5e73d99309872b71bd68d40946 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify_service.h @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVICE_MANAGER_NOTIFY_SERVICE_H +#define DEVICE_MANAGER_NOTIFY_SERVICE_H +#include +#include +#include +#include +#include +#include +#include + +#include "device_manager_ipc_stub.h" +#include "device_manager_notify.h" +#include "dm_device_info.h" +#include "dm_device_profile_info.h" +#include "dm_ipc_utils.h" +#include "dm_single_instance.h" +#include "idevice_manager_ipc.h" +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotifyService : public DeviceManagerIpcStub { + DM_DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerNotifyService); +public: + DeviceManagerNotifyService(); + ~DeviceManagerNotifyService() = default; + + ErrCode ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) override; + + ErrCode ServerDeviceFound( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &devBasicInfoExt) override; + + ErrCode ServerDeviceDiscovery( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) override; + + ErrCode ServerDiscoverFinish( + const std::string &pkgName, + uint16_t subscribeId, + int32_t failedReason) override; + + ErrCode ServerPublishFinish( + const std::string &pkgName, + int32_t publishId, + int32_t publishResult) override; + + ErrCode ServerAuthResult( + const std::string &pkgName, + const std::string &deviceId, + const std::string &token, + int32_t status, + int32_t reason) override; + + ErrCode ServerDeviceFaNotify( + const std::string &packagename, + const std::string ¶mJson) override; + + ErrCode ServerCredentialResult( + const std::string &pkgName, + int32_t action, + const std::string &credentialResult) override; + + ErrCode ServerCreatePinHolder( + const std::string &pkgName, + const std::string &deviceId, + int32_t pinType, + const std::string &payload) override; + + ErrCode ServerDestroyPinHolder( + const std::string &pkgName, + int32_t pinType, + const std::string &payload) override; + + ErrCode ServerCreatePinHolderResult( + const std::string &pkgName, + int32_t ret) override; + + ErrCode ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret) override; + + ErrCode ServerOnPinHolderEvent( + const std::string &pkgName, + int32_t ret, + int32_t pinHolderEvent, + const std::string &content) override; + + ErrCode BindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content) override; + + ErrCode UnbindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + const std::string &content) override; + + ErrCode RemoteDeviceTrustChange( + const std::string &pkgName, + const std::string &udid, + int32_t authForm, + const std::string &uuid) override; + + ErrCode ServerDeviceScreenStateNotify( + const std::string &pkgName, + const DmDeviceInfoExt &dmDeviceInfoExt) override; + + ErrCode ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + uint16_t deviceTypeId, + int32_t err) override; + + ErrCode SinkBindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content) override; + + ErrCode GetDeviceProfileInfoListResult( + const std::string &pkgName, + int32_t code, + const std::vector &deviceProfileInfosExt) override; + + ErrCode GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt) override; + + ErrCode SetRemoteDeviceNameResult( + const std::string &pkgName, + const std::string &deviceId, + int32_t code) override; + + ErrCode SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code) override; + +private: + DmPinType Int32ToDmPinType(int32_t value); + DmPinHolderEvent Int32ToDmPinHolderEvent(int32_t value); + DmAuthForm Int32ToDmAuthForm(int32_t value); + +private: + std::shared_ptr dmIpcUtils_; + std::mutex onIpcCmdFuncMapLock_; +}; + +} +} +#endif // DEVICE_MANAGER_NOTIFY_SERVICE_H 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 c80cbb4a4b72f9f5ce1096228e4d3b16335f732d..12308dd74406201dad916fd6023e7ac8c88f1c7f 100644 --- a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp +++ b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp @@ -12,7 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include +#include +#include "dm_device_info.h" +#include "dm_log.h" +#include "dm_error_type.h" namespace OHOS { namespace DistributedHardware { const char* DEVICE_TYPE_UNKNOWN_STRING = "UNKNOWN"; @@ -25,5 +31,122 @@ 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 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)); + bRet = (bRet && parcel.WriteString(extraData)); + 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; + } + deviceBasicInfoExt->extraData = parcel.ReadString(); + return deviceBasicInfoExt; +} + +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 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; +} } // 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 0000000000000000000000000000000000000000..e793cc83a44f99d68f3aee5ebc491a7300b734b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include "dm_device_profile_info.h" +#include "dm_log.h" +#include "message_parcel.h" +namespace OHOS { +namespace DistributedHardware { +const int32_t MAX_DEVICE_PROFILE_SIZE = 500; +constexpr int32_t MAX_ICON_SIZE = 4 * 1024 * 1024; +bool DmDeviceProfileInfoExt::EncodeDmServiceProfileInfos(const std::vector &svrInfos, + Parcel &parcel) +{ + if (!parcel.WriteInt32((int32_t)svrInfos.size())) { + return false; + } + for (const auto &svrInfo : svrInfos) { + if (!svrInfo.Marshalling(parcel)) { + LOGE("write dm service profile info failed"); + return false; + } + } + return true; +} + +void DmDeviceProfileInfoExt::DecodeDmServiceProfileInfos(Parcel &parcel, std::vector &svrInfos) +{ + int32_t svrNum = parcel.ReadInt32(); + if (svrNum > 0 && svrNum <= MAX_DEVICE_PROFILE_SIZE) { + for (int32_t i = 0; i < svrNum; ++i) { + DmServiceProfileInfoExt *svrInfo = DmServiceProfileInfoExt::Unmarshalling(parcel); + if (svrInfo == nullptr) { + LOGE("Failed to unmarshal service profile info at index %d", i); + continue; + } + svrInfos.emplace_back(*svrInfo); + delete svrInfo; + } + } +} + +bool DmServiceProfileInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(serviceId)); + bRet = (bRet && parcel.WriteString(serviceType)); + if (bRet) { + if (!parcel.WriteInt32((int32_t) data.size())) { + return false; + } + for (const auto &[key, value] : data) { + if (!parcel.WriteString(key)) { + return false; + } + if (!parcel.WriteString(value)) { + return false; + } + } + } + return bRet; +} + +DmServiceProfileInfoExt *DmServiceProfileInfoExt::Unmarshalling(Parcel &parcel) +{ + auto *svrInfo = new (std::nothrow) DmServiceProfileInfoExt(); + if (svrInfo == nullptr) { + return nullptr; + } + + svrInfo->deviceId = parcel.ReadString(); + svrInfo->serviceId = parcel.ReadString(); + svrInfo->serviceType = parcel.ReadString(); + int32_t num = parcel.ReadInt32(); + if (num > 0 && num <= MAX_DEVICE_PROFILE_SIZE) { + for (int32_t i = 0; i < num; ++i) { + std::string key = parcel.ReadString(); + std::string value = parcel.ReadString(); + svrInfo->data[key] = value; + } + } + return svrInfo; +} + +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(productName)); + 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)); + std::vector extendedServices; + for (const auto &service : services) { + extendedServices.emplace_back(service); + } + bRet = (bRet && EncodeDmServiceProfileInfos(extendedServices, parcel)); + return bRet; +} + +DmDeviceProfileInfoExt *DmDeviceProfileInfoExt::Unmarshalling(Parcel &parcel) +{ + auto *profileInfoExt = new (std::nothrow) DmDeviceProfileInfoExt(); + if (profileInfoExt == nullptr) { + 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->productName = 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(); + std::vector extendedServices; + for (const auto &service : profileInfoExt->services) { + extendedServices.emplace_back(service); + } + DecodeDmServiceProfileInfos(parcel, extendedServices); + return profileInfoExt; +} + +bool DmDeviceIconInfoExt::Marshalling(Parcel &parcel) const +{ + MessageParcel *messageParcel = reinterpret_cast(&parcel); + bool bRet = true; + bRet = (bRet && messageParcel->WriteString(productId)); + bRet = (bRet && messageParcel->WriteString(subProductId)); + bRet = (bRet && messageParcel->WriteString(internalModel)); + bRet = (bRet && messageParcel->WriteString(imageType)); + bRet = (bRet && messageParcel->WriteString(specName)); + bRet = (bRet && messageParcel->WriteString(version)); + bRet = (bRet && messageParcel->WriteString(url)); + int32_t length = static_cast(icon.size()); + bRet = (bRet && messageParcel->WriteInt32(length)); + if (bRet && length > 0) { + const unsigned char *buffer = reinterpret_cast(icon.data()); + bRet = (bRet && messageParcel->WriteRawData(buffer, length)); + } + return bRet; +} + +DmDeviceIconInfoExt *DmDeviceIconInfoExt::Unmarshalling(Parcel &parcel) +{ + MessageParcel *messageParcel = reinterpret_cast(&parcel); + auto *deviceIconInfo = new (std::nothrow) DmDeviceIconInfoExt(); + if (deviceIconInfo == nullptr) { + return nullptr; + } + deviceIconInfo->productId = messageParcel->ReadString(); + deviceIconInfo->subProductId = messageParcel->ReadString(); + deviceIconInfo->internalModel = messageParcel->ReadString(); + deviceIconInfo->imageType = messageParcel->ReadString(); + deviceIconInfo->specName = messageParcel->ReadString(); + deviceIconInfo->version = messageParcel->ReadString(); + deviceIconInfo->url = messageParcel->ReadString(); + int32_t length = messageParcel->ReadInt32(); + if (length > 0 && length <= MAX_ICON_SIZE) { + const unsigned char *buffer = nullptr; + if ((buffer = reinterpret_cast(messageParcel->ReadRawData((size_t)length))) == nullptr) { + LOGE("read raw data failed, length = %{public}d", length); + delete deviceIconInfo; + return nullptr; + } + std::vector icon(buffer, buffer + length); + deviceIconInfo->icon = icon; + } + return deviceIconInfo; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp index 93b2ef4fbdf31ee0d8153ce557ba65eb2dd2f63a..cf78b0c07131fdb1bda0e0b012b32627340c8248 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_manager.cpp @@ -32,7 +32,8 @@ #include "iservice_registry.h" #include "system_ability_definition.h" #include - +#include "device_manager_notify_service.h" +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { void DmDeathRecipient::OnRemoteDied(const wptr &remote) @@ -74,6 +75,7 @@ int32_t IpcClientManager::ClientInit() int32_t IpcClientManager::Init(const std::string &pkgName) { + LOGI("DM IDL begin, pkgName: %{public}s", pkgName.c_str()); if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; @@ -90,11 +92,11 @@ int32_t IpcClientManager::Init(const std::string &pkgName) return ERR_DM_FAILED; } - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new (std::nothrow) DeviceManagerNotifyService()); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); - req->SetListener(listener); + req->SetListener(listener->AsObject()); ret = dmInterface_->SendCmd(REGISTER_DEVICE_MANAGER_LISTENER, req, rsp); if (ret != DM_OK) { LOGE("InitDeviceManager: RegisterDeviceManagerListener Failed with ret %{public}d", ret); 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 a30e5493b2b6ea81ff6113a7f7f820ed819f662a..2a5042fabcee6f93e411b4d58255c15be353e677 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 @@ -452,123 +452,6 @@ ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shar return DM_OK; } -ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - DmDeviceState deviceState = static_cast(data.ReadInt32()); - DmDeviceInfo dmDeviceInfo; - IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo); - - DmDeviceBasicInfo dmDeviceBasicInfo; - IpcModelCodec::DecodeDmDeviceBasicInfo(data, dmDeviceBasicInfo); - switch (deviceState) { - case DEVICE_STATE_ONLINE: - LOGI("Online pkgName:%{public}s", pkgName.c_str()); - DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo); - DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceBasicInfo); - break; - case DEVICE_STATE_OFFLINE: - LOGI("Offline pkgName:%{public}s", pkgName.c_str()); - DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo); - DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceBasicInfo); - break; - case DEVICE_INFO_CHANGED: - DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo); - DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceBasicInfo); - break; - case DEVICE_INFO_READY: - LOGI("OnDeviceReady in, pkgName:%{public}s, networkId: %{public}s.", - pkgName.c_str(), GetAnonyString(dmDeviceInfo.networkId).c_str()); - DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo); - DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceBasicInfo); - break; - default: - LOGE("unknown device state:%{public}d", deviceState); - break; - } - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int16_t subscribeId = data.ReadInt16(); - DmDeviceInfo dmDeviceInfo; - IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo); - DmDeviceBasicInfo devBasicInfo; - IpcModelCodec::DecodeDmDeviceBasicInfo(data, devBasicInfo); - LOGD("pkgName:%{public}s, subscribeId:%{public}d.", GetAnonyString(pkgName).c_str(), (int32_t)subscribeId); - DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo); - DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, devBasicInfo); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DEVICE_DISCOVERY, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int16_t subscribeId = data.ReadInt16(); - DmDeviceBasicInfo dmDeviceBasicInfo; - IpcModelCodec::DecodeDmDeviceBasicInfo(data, dmDeviceBasicInfo); - DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceBasicInfo); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int16_t subscribeId = data.ReadInt16(); - int32_t failedReason = data.ReadInt32(); - - if (failedReason == DM_OK) { - DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); - } else { - DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); - } - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_PUBLISH_FINISH, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t publishId = data.ReadInt32(); - int32_t publishResult = data.ReadInt32(); - - DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, publishResult); - if (!reply.WriteInt32(DM_OK)) { - LOGE("write return failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - std::string deviceId = data.ReadString(); - std::string token = data.ReadString(); - int32_t status = data.ReadInt32(); - int32_t reason = data.ReadInt32(); - DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply) -{ - std::string packagename = data.ReadString(); - std::string paramJson = data.ReadString(); - DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson); - if (!reply.WriteInt32(DM_OK)) { - LOGE("write return failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -743,17 +626,6 @@ ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &reply, std:: return DM_OK; } -ON_IPC_CMD(SERVER_CREDENTIAL_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t action = data.ReadInt32(); - std::string credentialResult = data.ReadString(); - - DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(NOTIFY_EVENT, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1218,33 +1090,6 @@ ON_IPC_READ_RESPONSE(UNBIND_TARGET, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1371,49 +1216,6 @@ ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared return DM_OK; } -ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - std::string deviceId = data.ReadString(); - DmPinType pinType = static_cast(data.ReadInt32()); - std::string payload = data.ReadString(); - - DeviceManagerNotify::GetInstance().OnPinHolderCreate(pkgName, deviceId, pinType, payload); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - DmPinType pinType = static_cast(data.ReadInt32()); - std::string payload = data.ReadString(); - - DeviceManagerNotify::GetInstance().OnPinHolderDestroy(pkgName, pinType, payload); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t result = data.ReadInt32(); - - DeviceManagerNotify::GetInstance().OnCreateResult(pkgName, result); - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t result = data.ReadInt32(); - - DeviceManagerNotify::GetInstance().OnDestroyResult(pkgName, result); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(DP_ACL_ADD, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1457,18 +1259,6 @@ ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL, MessageParcel &reply, std::shared_ptr(data.ReadInt32()); - std::string content = data.ReadString(); - - DeviceManagerNotify::GetInstance().OnPinHolderEvent(pkgName, pinHolderEvent, result, content); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1545,28 +1335,6 @@ ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1635,32 +1403,6 @@ ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID, MessageParcel &reply, std::shared_pt return DM_OK; } -ON_IPC_CMD(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - std::string deviceList = data.ReadString(); - uint16_t deviceTypeId = data.ReadUint16(); - int32_t errCode = data.ReadInt32(); - DeviceManagerNotify::GetInstance().OnCredentialAuthStatus(pkgName, deviceList, deviceTypeId, errCode); - - reply.WriteInt32(DM_OK); - return DM_OK; -} - -ON_IPC_CMD(SINK_BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - PeerTargetId targetId; - IpcModelCodec::DecodePeerTargetId(data, targetId); - int32_t result = data.ReadInt32(); - int32_t status = data.ReadInt32(); - std::string content = data.ReadString(); - - DeviceManagerNotify::GetInstance().OnSinkBindResult(pkgName, targetId, result, status, content); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1749,25 +1491,6 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &reply, std::sh return DM_OK; } -ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t code = data.ReadInt32(); - int32_t deviceNum = data.ReadInt32(); - std::vector deviceProfileInfos; - if (deviceNum > 0 && deviceNum <= MAX_DEVICE_PROFILE_SIZE) { - for (int32_t i = 0; i < deviceNum; ++i) { - DmDeviceProfileInfo deviceInfo; - IpcModelCodec::DecodeDmDeviceProfileInfo(data, deviceInfo); - deviceProfileInfos.emplace_back(deviceInfo); - } - } - - DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, deviceProfileInfos, code); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -1791,17 +1514,6 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO, MessageParcel &reply, std::shared_ptr return DM_OK; } -ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t code = data.ReadInt32(); - DmDeviceIconInfo deviceIconInfo; - IpcModelCodec::DecodeDmDeviceIconInfo(data, deviceIconInfo); - DeviceManagerNotify::GetInstance().OnGetDeviceIconInfoResult(pkgName, deviceIconInfo, code); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_SET_REQUEST(PUT_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseReq, MessageParcel &data) { CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); @@ -2009,15 +1721,6 @@ ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME, MessageParcel &reply, std::shared_pt return DM_OK; } -ON_IPC_CMD(SET_LOCAL_DEVICE_NAME_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - int32_t code = data.ReadInt32(); - DeviceManagerNotify::GetInstance().OnSetLocalDeviceNameResult(pkgName, code); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME, MessageParcel &reply, std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { @@ -2053,16 +1756,6 @@ ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME, std::shared_ptr pBaseReq, Mes return DM_OK; } -ON_IPC_CMD(SET_REMOTE_DEVICE_NAME_RESULT, MessageParcel &data, MessageParcel &reply) -{ - std::string pkgName = data.ReadString(); - std::string deviceId = data.ReadString(); - int32_t code = data.ReadInt32(); - DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, code); - reply.WriteInt32(DM_OK); - return DM_OK; -} - ON_IPC_READ_RESPONSE(RESTORE_LOCAL_DEVICE_NAME, MessageParcel &reply, std::shared_ptr pBaseRsp) { if (pBaseRsp == nullptr) { diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 8e276a232153ce1efdc016a5a98fb434b4307164..879706efa5cbb9b635f681fc9108e8e33f4ebbd6 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -711,7 +711,7 @@ void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::st } } -void DeviceManagerNotify::OnUiCall(std::string &pkgName, std::string ¶mJson) +void DeviceManagerNotify::OnUiCall(const std::string &pkgName, const std::string ¶mJson) { if (pkgName.empty()) { LOGE("DeviceManagerNotify::OnUiCall error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d00541337c68f2e563a1cb4c0e3cb4bae65b5b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify_service.cpp @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "device_manager_notify_service.h" +#include "device_manager_notify.h" +#include "dm_error_type.h" +#include "dm_log.h" +#include "dm_constants.h" +#include "dm_anonymous.h" +namespace OHOS { +namespace DistributedHardware { +DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotifyService); +DeviceManagerNotifyService::DeviceManagerNotifyService() +{ + dmIpcUtils_ = std::make_shared(); + LOGI("DeviceManagerNotifyService constructor called."); +} + +ErrCode DeviceManagerNotifyService::ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDeviceStateNotify pkgName %{public}s", + pkgName.c_str()); + DmDeviceInfo dmDeviceInfo = dmIpcUtils_->ConvertToDmDeviceInfo(dmDeviceInfoExt); + DmDeviceBasicInfo devBasicInfo = dmIpcUtils_->ConvertToDmDeviceBasicInfo(dmDeviceBasicInfoExt); + switch (deviceState) { + case DEVICE_STATE_ONLINE: + LOGI("Online pkgName:%{public}s", pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, devBasicInfo); + break; + case DEVICE_STATE_OFFLINE: + LOGI("Offline pkgName:%{public}s", pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, devBasicInfo); + break; + case DEVICE_INFO_CHANGED: + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, devBasicInfo); + break; + case DEVICE_INFO_READY: + LOGI("OnDeviceReady in, pkgName:%{public}s, networkId: %{public}s.", + pkgName.c_str(), GetAnonyString(dmDeviceInfo.networkId).c_str()); + DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, devBasicInfo); + break; + default: + LOGE("unknown device state:%{public}d", deviceState); + break; + } + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDeviceFound( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &devBasicInfoExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDeviceFound, pkgName: %{public}s, subscribeId: %{public}d", + pkgName.c_str(), subscribeId); + DmDeviceInfo dmDeviceInfo = dmIpcUtils_->ConvertToDmDeviceInfo(dmDeviceInfoExt); + DmDeviceBasicInfo devBasicInfo = dmIpcUtils_->ConvertToDmDeviceBasicInfo(devBasicInfoExt); + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo); + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, devBasicInfo); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDeviceDiscovery( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + DmDeviceBasicInfoExt dmDeviceBasicInfo = dmIpcUtils_->ConvertToDmDeviceBasicInfo(dmDeviceBasicInfoExt); + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceBasicInfo); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDiscoverFinish( + const std::string &pkgName, + uint16_t subscribeId, + int32_t failedReason) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDiscoverFinish, pkgName: %{public}s, subscribeId: %{public}d, reason: %{public}d", + pkgName.c_str(), subscribeId, failedReason); + if (failedReason == DM_OK) { + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + } else { + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); + } + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerPublishFinish( + const std::string &pkgName, + int32_t publishId, + int32_t publishResult) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerPublishFinish : pkgName: %{public}s, publishId: %{public}d, publishResult: %{public}d", + pkgName.c_str(), publishResult, publishResult); + DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, publishResult); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerAuthResult( + const std::string &pkgName, + const std::string &deviceId, + const std::string &token, + int32_t status, + int32_t reason) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerAuthResult, pkgName %{public}s, deviceId %{public}s, token %{public}s, status %{public}d," + "reason: %{public}d", pkgName.c_str(), deviceId.c_str(), + GetAnonyString(token).c_str(), status, reason); + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDeviceFaNotify( + const std::string &packagename, + const std::string ¶mJson) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDeviceFaNotify, paramJson: %{public}s, packagename: %{public}s", + paramJson.c_str(), packagename.c_str()); + DeviceManagerNotify::GetInstance().OnUiCall(packagename, paramJson); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerCredentialResult( + const std::string &pkgName, + int32_t action, + const std::string &credentialResult) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerCredentialResult %{public}s, action %{public}d, resultInfo %{public}s, pkgName %{public}s", + pkgName.c_str(), action, credentialResult.c_str(), pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerCreatePinHolder( + const std::string &pkgName, + const std::string &deviceId, + int32_t pinType, + const std::string &payload) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerCreatePinHolder : pkgName %{public}s, deviceId %{public}s, payload %{public}s, %{public}s", + pkgName.c_str(), deviceId.c_str(), payload.c_str(), pkgName.c_str()); + DmPinType dmpinType = Int32ToDmPinType(pinType); + DeviceManagerNotify::GetInstance().OnPinHolderCreate(pkgName, deviceId, dmpinType, payload); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDestroyPinHolder( + const std::string &pkgName, + int32_t pinType, + const std::string &payload) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDestroyPinHolder : pkgName %{public}s, payload %{public}s", + pkgName.c_str(), payload.c_str()); + DmPinType dmpinType = Int32ToDmPinType(pinType); + DeviceManagerNotify::GetInstance().OnPinHolderDestroy(pkgName, dmpinType, payload); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerCreatePinHolderResult( + const std::string &pkgName, + int32_t ret) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerCreatePinHolderResult pkgName %{public}s, result %{public}d", + pkgName.c_str(), ret); + DeviceManagerNotify::GetInstance().OnCreateResult(pkgName, ret); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerDesTroyPinHolderResult pkgName %{public}s, result %{public}d", + pkgName.c_str(), ret); + DeviceManagerNotify::GetInstance().OnDestroyResult(pkgName, ret); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerOnPinHolderEvent( + const std::string &pkgName, + int32_t ret, + int32_t pinHolderEvent, + const std::string &content) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerOnPinHolderEvent pkgName %{public}s, content %{public}s", + pkgName.c_str(), content.c_str()); + DmPinHolderEvent dmpinHolderEvent = Int32ToDmPinHolderEvent(pinHolderEvent); + DeviceManagerNotify::GetInstance().OnPinHolderEvent(pkgName, dmpinHolderEvent, ret, content); + return 0; +} + +ErrCode DeviceManagerNotifyService::BindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::BindTargetResult pkgName %{public}s, ret %{public}d, status %{public}d, content %{public}s.", + pkgName.c_str(), ret, status, content.c_str()); + PeerTargetId targetId = dmIpcUtils_->ConvertToPeerTargetId(targetIdExt); + DeviceManagerNotify::GetInstance().OnBindResult(pkgName, targetId, ret, status, content); + return 0; +} + +ErrCode DeviceManagerNotifyService::UnbindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + const std::string &content) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::UnbindTargetResult pkgName %{public}s, ret %{public}d, content %{public}s.", + pkgName.c_str(), ret, content.c_str()); + PeerTargetId targetId = dmIpcUtils_->ConvertToPeerTargetId(targetIdExt); + DeviceManagerNotify::GetInstance().OnUnbindResult(pkgName, targetId, ret, content); + return 0; +} + +ErrCode DeviceManagerNotifyService::RemoteDeviceTrustChange( + const std::string &pkgName, + const std::string &udid, + int32_t authForm, + const std::string &uuid) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::RemoteDeviceTrustChange udid %{public}s, authForm %{public}d, uuid %{public}s.", + GetAnonyString(udid).c_str(), authForm, GetAnonyString(uuid).c_str()); + DmAuthForm dmAuthForm = Int32ToDmAuthForm(authForm); + DeviceManagerNotify::GetInstance().OnDeviceTrustChange(pkgName, udid, uuid, dmAuthForm); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDeviceScreenStateNotify( + const std::string &pkgName, + const DmDeviceInfoExt &dmDeviceInfoExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + DmDeviceInfo dmDeviceInfo = dmIpcUtils_->ConvertToDmDeviceInfo(dmDeviceInfoExt); + DeviceManagerNotify::GetInstance().OnDeviceScreenStatus(pkgName, dmDeviceInfo); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + uint16_t deviceTypeId, + int32_t err) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::ServerCredentialAuthStatusNotify, pkgName = %{public}s, deviceList = %{public}s," + "deviceTypeId = %{public}u, err = %{public}d", + pkgName.c_str(), deviceList.c_str(), deviceTypeId, err); + DeviceManagerNotify::GetInstance().OnCredentialAuthStatus(pkgName, deviceList, deviceTypeId, err); + return 0; +} + +ErrCode DeviceManagerNotifyService::SinkBindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::OnSinkBindResult pkgName %{public}s", pkgName.c_str()); + PeerTargetId targetId = dmIpcUtils_->ConvertToPeerTargetId(targetIdExt); + DeviceManagerNotify::GetInstance().OnSinkBindResult(pkgName, targetId, ret, status, content); + return 0; +} + +ErrCode DeviceManagerNotifyService::GetDeviceProfileInfoListResult( + const std::string &pkgName, + int32_t code, + const std::vector &deviceProfileInfosExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::GetDeviceProfileInfoListResult pkgName %{public}s.", pkgName.c_str()); + std::vector deviceProfileInfos = + dmIpcUtils_->ConvertToDmDeviceProfileInfo(deviceProfileInfosExt); + DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, deviceProfileInfos, code); + return 0; +} + +ErrCode DeviceManagerNotifyService::GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::GetDeviceIconInfoResult pkgName %{public}s.", pkgName.c_str()); + DmDeviceIconInfo deviceIconInfo = dmIpcUtils_->ConvertToDmDeviceIconInfo(deviceIconInfoExt); + DeviceManagerNotify::GetInstance().OnGetDeviceIconInfoResult(pkgName, deviceIconInfo, code); + return 0; +} + +ErrCode DeviceManagerNotifyService::SetRemoteDeviceNameResult( + const std::string &pkgName, + const std::string &deviceId, + int32_t code) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::SetRemoteDeviceNameResult pkgName %{public}s.", pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, code); + return 0; +} + +ErrCode DeviceManagerNotifyService::SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code) +{ + std::lock_guard autoLock(onIpcCmdFuncMapLock_); + LOGI("DM IDL DMNS::SetLocalDeviceNameResult pkgName %{public}s.", pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnSetLocalDeviceNameResult(pkgName, code); + return 0; +} + +DmPinType DeviceManagerNotifyService::Int32ToDmPinType(int32_t value) +{ + switch (value) { + case static_cast(DmPinType::NUMBER_PIN_CODE): + return DmPinType::NUMBER_PIN_CODE; + case static_cast(DmPinType::QR_CODE): + return DmPinType::QR_CODE; + case static_cast(DmPinType::VISIBLE_LLIGHT): + return DmPinType::VISIBLE_LLIGHT; + case static_cast(DmPinType::SUPER_SONIC): + return DmPinType::SUPER_SONIC; + default: + return static_cast(-1); + } +} + +DmPinHolderEvent DeviceManagerNotifyService::Int32ToDmPinHolderEvent(int32_t value) +{ + switch (value) { + case static_cast(DmPinHolderEvent::CREATE): + return DmPinHolderEvent::CREATE; + case static_cast(DmPinHolderEvent::CREATE_RESULT): + return DmPinHolderEvent::CREATE_RESULT; + case static_cast(DmPinHolderEvent::DESTROY): + return DmPinHolderEvent::DESTROY; + case static_cast(DmPinHolderEvent::DESTROY_RESULT): + return DmPinHolderEvent::DESTROY_RESULT; + case static_cast(DmPinHolderEvent::PIN_TYPE_CHANGE): + return DmPinHolderEvent::PIN_TYPE_CHANGE; + case static_cast(DmPinHolderEvent::PIN_TYPE_CHANGE_RESULT): + return DmPinHolderEvent::PIN_TYPE_CHANGE_RESULT; + default: + return static_cast(-1); + } +} + +DmAuthForm DeviceManagerNotifyService::Int32ToDmAuthForm(int32_t value) +{ + switch (value) { + case static_cast(DmAuthForm::INVALID_TYPE): + return DmAuthForm::INVALID_TYPE; + case static_cast(DmAuthForm::PEER_TO_PEER): + return DmAuthForm::PEER_TO_PEER; + case static_cast(DmAuthForm::IDENTICAL_ACCOUNT): + return DmAuthForm::IDENTICAL_ACCOUNT; + case static_cast(DmAuthForm::ACROSS_ACCOUNT): + return DmAuthForm::ACROSS_ACCOUNT; + default: + return static_cast(-1); + } +} +} +} \ No newline at end of file diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index 8f1711c48ddf429198c46d31baad4c813d0ac3a5..4a815b3f616e5bf64d9169206a9fe4c126dae544 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -155,7 +155,9 @@ if (defined(ohos_lite)) { "${utils_path}/include/crypto", "${utils_path}/include/kvadapter", "${utils_path}/include/timer", + "${devicemanager_path}/services/service/include", "${json_path}/include", + "${target_gen_dir}", ] } config("cflags_config") { @@ -201,6 +203,7 @@ if (defined(ohos_lite)) { "${common_path}/src/dm_anonymous.cpp", "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", "${common_path}/src/ipc/standard/ipc_model_codec.cpp", + "${devicemanager_path}/utils/src/dm_ipc_utils.cpp", "src/advertise/advertise_manager.cpp", "src/device_manager_service.cpp", "src/device_manager_service_listener.cpp", @@ -211,7 +214,6 @@ if (defined(ohos_lite)) { "src/hichain/hichain_listener.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/ipc/standard/ipc_server_client_proxy.cpp", - "src/ipc/standard/ipc_server_listener.cpp", "src/ipc/standard/ipc_server_stub.cpp", "src/notify/device_manager_service_notify.cpp", "src/permission/standard/permission_manager.cpp", @@ -238,6 +240,7 @@ if (defined(ohos_lite)) { ] deps = [ + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${innerkits_path}/native_cpp:devicemanagersdk", @@ -354,7 +357,6 @@ if (defined(ohos_lite)) { "src/hichain/hichain_listener.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/ipc/standard/ipc_server_client_proxy.cpp", - "src/ipc/standard/ipc_server_listener.cpp", "src/ipc/standard/ipc_server_stub.cpp", "src/notify/device_manager_service_notify.cpp", "src/permission/standard/permission_manager.cpp", @@ -381,6 +383,7 @@ if (defined(ohos_lite)) { ] deps = [ + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${innerkits_path}/native_cpp:devicemanagersdk", diff --git a/services/service/IDeviceManagerIpc.idl b/services/service/IDeviceManagerIpc.idl new file mode 100644 index 0000000000000000000000000000000000000000..1e9e8dab4215aaadc914237bbb22cafa304d6fdb --- /dev/null +++ b/services/service/IDeviceManagerIpc.idl @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmDeviceBasicInfoExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.PeerTargetIdExt; +sequenceable DmDeviceInfo..OHOS.DistributedHardware.DmDeviceInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceProfileInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceIconInfoExt; +interface OHOS.DistributedHardware.IDeviceManagerIpc { +[oneway, ipccode 13] void ServerDeviceStateNotify([in] String pkgName, [in] int deviceState, [in] DmDeviceInfoExt dmDeviceInfoExt, + [in] DmDeviceBasicInfoExt dmDeviceBasicInfoExt); +[oneway, ipccode 14] void ServerDeviceFound([in] String pkgName, [in] unsigned short subscribeId, [in] DmDeviceInfoExt dmDeviceInfoExt, + [in] DmDeviceBasicInfoExt devBasicInfoExt); +[oneway, ipccode 15] void ServerDeviceDiscovery([in] String pkgName, [in] unsigned short subscribeId, + [in] DmDeviceBasicInfoExt dmDeviceBasicInfoExt); +[oneway, ipccode 16] void ServerDiscoverFinish([in] String pkgName, [in] unsigned short subscribeId, [in] int failedReason); +[oneway, ipccode 17] void ServerPublishFinish([in] String pkgName, [in] int publishId, [in] int publishResult); +[oneway, ipccode 18] void ServerAuthResult([in] String pkgName, [in] String deviceId, [in] String token, [in] int status, [in] int reason); +[oneway, ipccode 22] void ServerDeviceFaNotify([in] String packagename, [in] String paramJson); +[oneway, ipccode 23] void ServerCredentialResult([in] String pkgName, [in] int action, [in] String credentialResult); +[oneway, ipccode 44] void ServerCreatePinHolder([in] String pkgName, [in] String deviceId, [in] int pinType, [in] String payload); +[oneway, ipccode 45] void ServerDestroyPinHolder([in] String pkgName, [in] int pinType, [in] String payload); +[oneway, ipccode 46] void ServerCreatePinHolderResult([in] String pkgName, [in] int ret); +[oneway, ipccode 47] void ServerDesTroyPinHolderResult([in] String pkgName, [in] int ret); +[oneway, ipccode 48] void ServerOnPinHolderEvent([in] String pkgName, [in] int ret, [in] int pinHolderEvent, [in] String content); +[oneway, ipccode 57] void BindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, + [in] int status, [in] String content); +[oneway, ipccode 58] void UnbindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, [in] String content); +[oneway, ipccode 67] void RemoteDeviceTrustChange([in] String pkgName, [in] String udid, [in] int authForm, [in] String uuid); +[oneway, ipccode 68] void ServerDeviceScreenStateNotify([in] String pkgName, [in] DmDeviceInfoExt dmDeviceInfoExt); +[oneway, ipccode 71] void ServerCredentialAuthStatusNotify([in] String pkgName, [in] String deviceList, + [in] unsigned short deviceTypeId, [in] int err); +[oneway, ipccode 72] void SinkBindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, [in] int status, + [in] String content); +[oneway, ipccode 77] void GetDeviceProfileInfoListResult([in] String pkgName, [in] int code, + [in] List deviceProfileInfosExt); +[oneway, ipccode 79] void GetDeviceIconInfoResult([in] String pkgName, [in] int code, [in] DmDeviceIconInfoExt deviceIconInfoExt); +[oneway, ipccode 83] void SetRemoteDeviceNameResult([in] String pkgName, [in] String deviceId, [in] int code); +[oneway, ipccode 85] void SetLocalDeviceNameResult([in] String pkgName, [in] int code); +} \ No newline at end of file diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 216835016a96327f3e1961ba1e80cab2facb1e72..d090ed90bcfbf99a63e0b3f3e7cbfc290a71c47d 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -25,20 +25,21 @@ #include "dm_device_info.h" #include "dm_device_profile_info.h" #include "idevice_manager_service_listener.h" +#include "dm_ipc_utils.h" +#include "idevice_manager_ipc.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "kv_adapter_manager.h" #endif #if !defined(__LITEOS_M__) #include "ipc_notify_dmfa_result_req.h" -#include "ipc_server_listener.h" #endif #include "ipc_notify_device_state_req.h" - +#include "ipc_server_stub.h" namespace OHOS { namespace DistributedHardware { class DM_EXPORT DeviceManagerServiceListener : public IDeviceManagerServiceListener { public: - DeviceManagerServiceListener() {}; + DeviceManagerServiceListener(); virtual ~DeviceManagerServiceListener() {}; void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, @@ -97,15 +98,11 @@ public: private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); - void SetDeviceInfo(std::shared_ptr pReq, const ProcessInfo &processInfo, - const DmDeviceState &state, const DmDeviceInfo &deviceInfo, const DmDeviceBasicInfo &deviceBasicInfo); int32_t FillUdidAndUuidToDeviceInfo(const std::string &pkgName, DmDeviceInfo &dmDeviceInfo); void ProcessDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo); void ProcessAppStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo); - void SetDeviceScreenInfo(std::shared_ptr pReq, const ProcessInfo &processInfo, - const DmDeviceInfo &deviceInfo); void RemoveOnlinePkgName(const DmDeviceInfo &info); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DM_EXPORT int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName, @@ -129,7 +126,6 @@ private: void RemoveNotExistProcess(); private: #if !defined(__LITEOS_M__) - IpcServerListener ipcServerListener_; static std::mutex alreadyNotifyPkgNameLock_; static std::map alreadyOnlinePkgName_; static std::unordered_set highPriorityPkgNameSet_; diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index 4756323015470d3d3237c4062accb45a41c08fe8..f3d5afe406328ae8859b8ebe4d41f6c68e42aa85 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -32,7 +32,7 @@ #include "dm_device_info.h" #include "dm_single_instance.h" - +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; @@ -54,6 +54,8 @@ class IpcServerStub : public SystemAbility, public IRemoteStub DM_DECLARE_SINGLE_INSTANCE_BASE(IpcServerStub); public: + IpcServerStub(); + ~IpcServerStub() override = default; /** * @tc.name: IpcServerStub::OnStart * @tc.desc: OnStart of the IpcServerStub @@ -87,7 +89,7 @@ public: * @tc.desc: Register DeviceManager Listener of the IpcServerStub * @tc.type: FUNC */ - int32_t RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener); + int32_t RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener); /** * @tc.name: IpcServerStub::UnRegisterDeviceManagerListener @@ -115,7 +117,7 @@ public: * @tc.desc: Get DmListener of the IpcServerStub * @tc.type: FUNC */ - const sptr GetDmListener(ProcessInfo processInfo) const; + const sptr GetDmListener(ProcessInfo processInfo) const; /** * @tc.name: IpcServerStub::GetDmListenerPkgName @@ -147,8 +149,6 @@ public: std::set GetSystemSA(); private: - IpcServerStub(); - ~IpcServerStub() override = default; bool Init(); void AddSystemSA(const std::string &pkgName); void RemoveSystemSA(const std::string &pkgName); @@ -164,7 +164,7 @@ private: ServiceRunningState state_; mutable std::mutex listenerLock_; std::map> appRecipient_; - std::map> dmListener_; + std::map> dmListener_; std::set systemSA_; int64_t startBeginTime_ = 0; }; diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index bc47a6a81fc2c3d3908b7aa811a1d160a185c12a..de4d3f277b77b0cd2af256d6c3c2eb5c96384186 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -42,6 +42,7 @@ #include "ipc_notify_set_local_device_name_req.h" #include "ipc_notify_set_remote_device_name_req.h" #include "ipc_server_stub.h" +#include "dm_ipc_utils.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "datetime_ex.h" #include "device_name_manager.h" @@ -51,7 +52,8 @@ #endif #include "parameter.h" #include "permission_manager.h" - +#include "iservice_registry.h" +#include "system_ability_definition.h" namespace OHOS { namespace DistributedHardware { std::mutex DeviceManagerServiceListener::alreadyNotifyPkgNameLock_; @@ -61,6 +63,11 @@ std::set DeviceManagerServiceListener::actUnrelatedPkgName_ = {}; std::unordered_set DeviceManagerServiceListener::highPriorityPkgNameSet_ = { "ohos.deviceprofile", "ohos.distributeddata.service" }; +DeviceManagerServiceListener::DeviceManagerServiceListener() +{ + LOGI("DeviceManagerServiceListener constructor called."); +} + void handleExtraData(const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo) { cJSON *extraDataJsonObj = cJSON_Parse(info.extraData.c_str()); @@ -123,41 +130,6 @@ void DeviceManagerServiceListener::ConvertDeviceInfoToDeviceBasicInfo(const std: handleExtraData(info, deviceBasicInfo); } -void DeviceManagerServiceListener::SetDeviceInfo(std::shared_ptr pReq, - const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &deviceInfo, - const DmDeviceBasicInfo &deviceBasicInfo) -{ - pReq->SetPkgName(processInfo.pkgName); - pReq->SetProcessInfo(processInfo); - pReq->SetDeviceState(state); - DmDeviceInfo dmDeviceInfo = deviceInfo; - FillUdidAndUuidToDeviceInfo(processInfo.pkgName, dmDeviceInfo); -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::string appId = ""; - if (AppManager::GetInstance().GetAppIdByPkgName(processInfo.pkgName, appId) != DM_OK) { - pReq->SetDeviceInfo(dmDeviceInfo); - pReq->SetDeviceBasicInfo(deviceBasicInfo); - return; - } - ConvertUdidHashToAnoyAndSave(processInfo.pkgName, dmDeviceInfo); - DmDeviceBasicInfo dmDeviceBasicInfo = deviceBasicInfo; - if (memset_s(dmDeviceBasicInfo.deviceId, DM_MAX_DEVICE_ID_LEN, 0, DM_MAX_DEVICE_ID_LEN) != DM_OK) { - LOGE("ConvertNodeBasicInfoToDmDevice memset failed."); - return; - } - if (memcpy_s(dmDeviceBasicInfo.deviceId, sizeof(dmDeviceBasicInfo.deviceId), dmDeviceInfo.deviceId, - std::min(sizeof(dmDeviceBasicInfo.deviceId), sizeof(dmDeviceInfo.deviceId))) != DM_OK) { - LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); - return; - } - pReq->SetDeviceInfo(dmDeviceInfo); - pReq->SetDeviceBasicInfo(dmDeviceBasicInfo); - return; -#endif - pReq->SetDeviceInfo(dmDeviceInfo); - pReq->SetDeviceBasicInfo(deviceBasicInfo); -} - int32_t DeviceManagerServiceListener::FillUdidAndUuidToDeviceInfo(const std::string &pkgName, DmDeviceInfo &dmDeviceInfo) { @@ -193,6 +165,8 @@ int32_t DeviceManagerServiceListener::FillUdidAndUuidToDeviceInfo(const std::str void DeviceManagerServiceListener::ProcessDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo) { + LOGI("DM IDL ProcessDeviceStateChange In, pkgName: %{public}s, state: %{public}d", + processInfo.pkgName.c_str(), static_cast(state)); std::vector processInfoVec = GetNotifyProcessInfoByUserId(processInfo.userId, DmCommonNotifyEvent::REG_DEVICE_STATE); std::vector hpProcessInfoVec; @@ -227,11 +201,12 @@ void DeviceManagerServiceListener::ProcessDeviceStateChange(const ProcessInfo &p void DeviceManagerServiceListener::ProcessAppStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo) { - LOGI("In"); + LOGI("DM IDL DMSL::ProcessAppStateChange In, pkgName: %{public}s, state: %{public}d", + processInfo.pkgName.c_str(), static_cast(state)); std::vector processInfoVec = GetWhiteListSAProcessInfo(DmCommonNotifyEvent::REG_DEVICE_STATE); ProcessInfo bindProcessInfo = DealBindProcessInfo(processInfo); processInfoVec.push_back(bindProcessInfo); - std::vector allProcessInfos = ipcServerListener_.GetAllProcessInfo(); + std::vector allProcessInfos = IpcServerStub::GetInstance().GetAllProcessInfo(); switch (static_cast(state)) { case static_cast(DmDeviceState::DEVICE_STATE_ONLINE): ProcessAppOnline(processInfoVec, processInfo, state, info, deviceBasicInfo); @@ -251,6 +226,8 @@ void DeviceManagerServiceListener::ProcessAppStateChange(const ProcessInfo &proc void DeviceManagerServiceListener::OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info) { + LOGI("DM IDL DMSL::OnDeviceStateChange, pkgName: %{public}s, state: %{public}d", + processInfo.pkgName.c_str(), static_cast(state)); DmDeviceBasicInfo deviceBasicInfo; ConvertDeviceInfoToDeviceBasicInfo(processInfo.pkgName, info, deviceBasicInfo); if (processInfo.pkgName == std::string(DM_PKG_NAME)) { @@ -266,229 +243,228 @@ void DeviceManagerServiceListener::OnDeviceStateChange(const ProcessInfo &proces void DeviceManagerServiceListener::OnDeviceFound(const ProcessInfo &processInfo, uint16_t subscribeId, const DmDeviceInfo &info) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::OnDeviceFound, pkgName: %{public}s, subscribeId: %{public}d", + processInfo.pkgName.c_str(), subscribeId); DmDeviceInfo deviceInfo = info; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) ConvertUdidHashToAnoyAndSave(processInfo.pkgName, deviceInfo); #endif DmDeviceBasicInfo devBasicInfo; ConvertDeviceInfoToDeviceBasicInfo(processInfo.pkgName, deviceInfo, devBasicInfo); - pReq->SetDeviceBasicInfo(devBasicInfo); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetSubscribeId(subscribeId); - pReq->SetDeviceInfo(deviceInfo); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_FOUND, pReq, pRsp); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(deviceInfo); + auto devBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(devBasicInfo); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDeviceFound(processInfo.pkgName, subscribeId, dmDeviceInfoExt, + devBasicInfoExt); } void DeviceManagerServiceListener::OnDiscoveryFailed(const ProcessInfo &processInfo, uint16_t subscribeId, int32_t failedReason) { - LOGI("OnDiscoveryFailed"); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetSubscribeId(subscribeId); - pReq->SetResult(failedReason); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + LOGI("DM IDL DMSL::OnDiscoveryFailed, pkgName: %{public}s, subscribeId: %{public}d, reason: %{public}d", + processInfo.pkgName.c_str(), subscribeId, failedReason); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDiscoverFinish(processInfo.pkgName, subscribeId, failedReason); } void DeviceManagerServiceListener::OnDiscoverySuccess(const ProcessInfo &processInfo, int32_t subscribeId) { - LOGI("OnDiscoverySuccess"); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetSubscribeId((uint16_t)subscribeId); - pReq->SetResult(DM_OK); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); + LOGI("DM IDL DMSL::OnDiscoverySuccess, pkgName: %{public}s, subscribeId: %{public}d", + processInfo.pkgName.c_str(), subscribeId); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDiscoverFinish(processInfo.pkgName, (uint16_t)subscribeId, DM_OK); } void DeviceManagerServiceListener::OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) { - LOGI("OnPublishResult : %{public}d", publishResult); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(pkgName); - pReq->SetPublishId(publishId); - pReq->SetResult(publishResult); - ipcServerListener_.SendRequest(SERVER_PUBLISH_FINISH, pReq, pRsp); + LOGI("DM IDL DMSL::OnPublishResult : pkgName: %{public}s, publishId: %{public}d, publishResult: %{public}d", + pkgName.c_str(), publishResult, publishResult); + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerPublishFinish(pkgName, publishId, publishResult); } void DeviceManagerServiceListener::OnAuthResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::OnAuthResult, pkgName: %{public}s, deviceId: %{public}s, token: %{public}s, status: %{public}d," + "reason: %{public}d", processInfo.pkgName.c_str(), deviceId.c_str(), + GetAnonyString(token).c_str(), status, reason); if (status < STATUS_DM_AUTH_FINISH && status > STATUS_DM_AUTH_DEFAULT) { status = STATUS_DM_AUTH_DEFAULT; } - pReq->SetDeviceId(deviceId); + std::string deviceIdToUse = deviceId; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string deviceIdTemp = ""; if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, deviceId, deviceIdTemp) == DM_OK) { - pReq->SetDeviceId(deviceIdTemp); + deviceIdToUse = deviceIdTemp; } #endif - pReq->SetPkgName(processInfo.pkgName); - pReq->SetToken(token); - pReq->SetStatus(status); - pReq->SetReason(reason); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerAuthResult(processInfo.pkgName, deviceIdToUse, token, status, reason); } void DeviceManagerServiceListener::OnUiCall(const ProcessInfo &processInfo, std::string ¶mJson) { - LOGI("OnUiCall in"); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetJsonParam(paramJson); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_FA_NOTIFY, pReq, pRsp); + LOGI("DM IDL DMSL::OnUiCall in, pkgName: %{public}s, paramJson: %{public}s", + processInfo.pkgName.c_str(), paramJson.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDeviceFaNotify(processInfo.pkgName, paramJson); } void DeviceManagerServiceListener::OnCredentialResult(const ProcessInfo &processInfo, int32_t action, const std::string &resultInfo) { - LOGI("call OnCredentialResult for %{public}s, action %{public}d", processInfo.pkgName.c_str(), action); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetCredentialAction(action); - pReq->SetCredentialResult(resultInfo); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREDENTIAL_RESULT, pReq, pRsp); + LOGI("DM IDL DMSL::OnCredentialResult for %{public}s, action %{public}d, resultInfo %{public}s", + processInfo.pkgName.c_str(), action, resultInfo.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerCredentialResult(processInfo.pkgName, action, resultInfo); } void DeviceManagerServiceListener::OnBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, int32_t status, std::string content) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::OnBindResult pkgName %{public}s, result %{public}d, status %{public}d, content %{public}s.", + processInfo.pkgName.c_str(), result, status, content.c_str()); if (status < STATUS_DM_AUTH_FINISH && status > STATUS_DM_AUTH_DEFAULT) { status = STATUS_DM_AUTH_DEFAULT; } - PeerTargetId returnTargetId = targetId; + auto targetIdExt = DmIpcUtils::ConvertToPeerTargetIdExtWrapper(targetId); + PeerTargetIdExt returnTargetId = targetIdExt; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string deviceIdTemp = ""; DmKVValue kvValue; - if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetId.deviceId, deviceIdTemp) == DM_OK && + if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetIdExt.deviceId, deviceIdTemp) == DM_OK && KVAdapterManager::GetInstance().Get(deviceIdTemp, kvValue) == DM_OK) { returnTargetId.deviceId = deviceIdTemp; } #endif - pReq->SetPkgName(processInfo.pkgName); - pReq->SetPeerTargetId(returnTargetId); - pReq->SetResult(result); - pReq->SetStatus(status); - pReq->SetContent(content); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(BIND_TARGET_RESULT, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->BindTargetResult(processInfo.pkgName, returnTargetId, result, + status, content); } void DeviceManagerServiceListener::OnUnbindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, std::string content) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - PeerTargetId returnTargetId = targetId; + LOGI("DM IDL DMSL::OnUnbindResult pkgName %{public}s, result %{public}d, content %{public}s.", + processInfo.pkgName.c_str(), result, content.c_str()); + auto targetIdExt = DmIpcUtils::ConvertToPeerTargetIdExtWrapper(targetId); + PeerTargetIdExt returnTargetId = targetIdExt; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string deviceIdTemp = ""; DmKVValue kvValue; - if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetId.deviceId, deviceIdTemp) == DM_OK && + if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetIdExt.deviceId, deviceIdTemp) == DM_OK && KVAdapterManager::GetInstance().Get(deviceIdTemp, kvValue) == DM_OK) { returnTargetId.deviceId = deviceIdTemp; } #endif - pReq->SetPkgName(processInfo.pkgName); - pReq->SetPeerTargetId(returnTargetId); - pReq->SetResult(result); - pReq->SetContent(content); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(UNBIND_TARGET_RESULT, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->UnbindTargetResult(processInfo.pkgName, returnTargetId, result, content); } void DeviceManagerServiceListener::OnPinHolderCreate(const ProcessInfo &processInfo, const std::string &deviceId, DmPinType pinType, const std::string &payload) { - LOGI("OnPinHolderCreate : %{public}s", processInfo.pkgName.c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetDeviceId(deviceId); - pReq->SetPinType(pinType); - pReq->SetPayload(payload); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER, pReq, pRsp); + LOGI("DM IDL DMSL::OnPinHolderCreate : pkgName %{public}s, deviceId %{public}s, payload %{public}s", + processInfo.pkgName.c_str(), deviceId.c_str(), payload.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerCreatePinHolder(processInfo.pkgName, deviceId, pinType, payload); } void DeviceManagerServiceListener::OnPinHolderDestroy(const ProcessInfo &processInfo, DmPinType pinType, const std::string &payload) { - LOGI("OnPinHolderDestroy : %{public}s", processInfo.pkgName.c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetPinType(pinType); - pReq->SetPayload(payload); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER, pReq, pRsp); + LOGI("DM IDL DMSL::OnPinHolderDestroy : pkgName %{public}s, payload %{public}s", + processInfo.pkgName.c_str(), payload.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDestroyPinHolder(processInfo.pkgName, pinType, payload); } void DeviceManagerServiceListener::OnCreateResult(const ProcessInfo &processInfo, int32_t result) { - LOGI("OnCreateResult : %{public}d", result); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetResult(result); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_CREATE_PIN_HOLDER_RESULT, pReq, pRsp); + LOGI("DM IDL DMSL::OnCreateResult : pkgName %{public}s, result %{public}d", processInfo.pkgName.c_str(), result); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerCreatePinHolderResult(processInfo.pkgName, result); } void DeviceManagerServiceListener::OnDestroyResult(const ProcessInfo &processInfo, int32_t result) { - LOGI("OnDestroyResult : %{public}d", result); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetResult(result); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_DESTROY_PIN_HOLDER_RESULT, pReq, pRsp); + LOGI("DM IDL DMSL::OnDestroyResult : pkgName %{public}s, result %{public}d", processInfo.pkgName.c_str(), result); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerDesTroyPinHolderResult(processInfo.pkgName, result); } void DeviceManagerServiceListener::OnPinHolderEvent(const ProcessInfo &processInfo, DmPinHolderEvent event, int32_t result, const std::string &content) { - LOGI("OnPinHolderEvent pkgName: %{public}s, event: %{public}d, result: %{public}d", - processInfo.pkgName.c_str(), event, result); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - - pReq->SetPkgName(processInfo.pkgName); - pReq->SetPinHolderEvent(event); - pReq->SetResult(result); - pReq->SetContent(content); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(SERVER_ON_PIN_HOLDER_EVENT, pReq, pRsp); + LOGI("DM IDL DMSL::OnPinHolderEvent pkgName %{public}s, event %{public}d, result %{public}d, content %{public}s", + processInfo.pkgName.c_str(), event, result, content.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerOnPinHolderEvent(processInfo.pkgName, result, event, content); } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo) { + LOGI("DM IDL DMSL::ConvertUdidHashToAnoyAndSave, pkgName: %{public}s, deviceId: %{public}s", + pkgName.c_str(), GetAnonyString(deviceInfo.deviceId).c_str()); std::string appId = ""; if (AppManager::GetInstance().GetAppIdByPkgName(pkgName, appId) != DM_OK) { LOGD("GetAppIdByPkgName failed"); @@ -514,6 +490,8 @@ int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyAndSave(const std::st int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyDeviceId(const std::string &pkgName, const std::string &udidHash, std::string &anoyDeviceId) { + LOGI("DM IDL DMSL::ConvertUdidHashToAnoyDeviceId, pkgName: %{public}s, udidHash: %{public}s", + pkgName.c_str(), GetAnonyString(udidHash).c_str()); std::string appId = ""; if (AppManager::GetInstance().GetAppIdByPkgName(pkgName, appId) != DM_OK) { LOGD("GetAppIdByPkgName failed"); @@ -531,10 +509,9 @@ int32_t DeviceManagerServiceListener::ConvertUdidHashToAnoyDeviceId(const std::s void DeviceManagerServiceListener::OnDeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm) { - LOGI("udid %{public}s, authForm %{public}d, uuid %{public}s.", GetAnonyString(udid).c_str(), - authForm, GetAnonyString(uuid).c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::OnDeviceTrustChange udid %{public}s, authForm %{public}d, uuid %{public}s.", + GetAnonyString(udid).c_str(), authForm, GetAnonyString(uuid).c_str()); + int32_t userId = -1; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) userId = MultipleUserConnector::GetFirstForegroundUserId(); @@ -542,41 +519,19 @@ void DeviceManagerServiceListener::OnDeviceTrustChange(const std::string &udid, std::vector processInfoVec = GetNotifyProcessInfoByUserId(userId, DmCommonNotifyEvent::REG_REMOTE_DEVICE_TRUST_CHANGE); for (const auto &item : processInfoVec) { - pReq->SetPkgName(item.pkgName); - pReq->SetUdid(udid); - pReq->SetUuid(uuid); - pReq->SetAuthForm(authForm); - pReq->SetProcessInfo(item); - ipcServerListener_.SendRequest(REMOTE_DEVICE_TRUST_CHANGE, pReq, pRsp); - } -} - -void DeviceManagerServiceListener::SetDeviceScreenInfo(std::shared_ptr pReq, - const ProcessInfo &processInfo, const DmDeviceInfo &deviceInfo) -{ - LOGI("In"); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetProcessInfo(processInfo); -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::string appId = ""; - if (AppManager::GetInstance().GetAppIdByPkgName(processInfo.pkgName, appId) != DM_OK) { - pReq->SetDeviceInfo(deviceInfo); - return; + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + deviceManagerIpc->RemoteDeviceTrustChange(item.pkgName, udid, authForm, uuid); } - DmDeviceInfo dmDeviceInfo = deviceInfo; - ConvertUdidHashToAnoyAndSave(processInfo.pkgName, dmDeviceInfo); - pReq->SetDeviceInfo(dmDeviceInfo); - return; -#endif - pReq->SetDeviceInfo(deviceInfo); } void DeviceManagerServiceListener::OnDeviceScreenStateChange(const ProcessInfo &processInfo, DmDeviceInfo &devInfo) { - LOGI("In, pkgName = %{public}s", processInfo.pkgName.c_str()); + LOGI("DM IDL DMSL::OnDeviceScreenStateChange In, pkgName = %{public}s", processInfo.pkgName.c_str()); if (processInfo.pkgName == std::string(DM_PKG_NAME)) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); int32_t userId = -1; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) userId = MultipleUserConnector::GetFirstForegroundUserId(); @@ -584,18 +539,26 @@ void DeviceManagerServiceListener::OnDeviceScreenStateChange(const ProcessInfo & std::vector processInfoVec = GetNotifyProcessInfoByUserId(userId, DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE); for (const auto &item : processInfoVec) { - SetDeviceScreenInfo(pReq, item, devInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(devInfo); + deviceManagerIpc->ServerDeviceScreenStateNotify(item.pkgName, dmDeviceInfoExt); } } else { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); std::vector processInfoVec = GetWhiteListSAProcessInfo(DmCommonNotifyEvent::REG_DEVICE_SCREEN_STATE); processInfoVec.push_back(processInfo); for (const auto &item : processInfoVec) { - SetDeviceScreenInfo(pReq, item, devInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_SCREEN_STATE_NOTIFY, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(devInfo); + deviceManagerIpc->ServerDeviceScreenStateNotify(processInfo.pkgName, dmDeviceInfoExt); } } } @@ -618,7 +581,9 @@ void DeviceManagerServiceListener::RemoveOnlinePkgName(const DmDeviceInfo &info) void DeviceManagerServiceListener::OnCredentialAuthStatus(const ProcessInfo &processInfo, const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) { - LOGI("In, pkgName = %{public}s", processInfo.pkgName.c_str()); + LOGI("DM IDL DMSL::OnCredentialAuthStatus In, pkgName = %{public}s, deviceList = %{public}s," + "deviceTypeId = %{public}u, errcode = %{public}d", + processInfo.pkgName.c_str(), deviceList.c_str(), deviceTypeId, errcode); int32_t userId = -1; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) userId = MultipleUserConnector::GetFirstForegroundUserId(); @@ -626,14 +591,13 @@ void DeviceManagerServiceListener::OnCredentialAuthStatus(const ProcessInfo &pro std::vector processInfoVec = GetNotifyProcessInfoByUserId(userId, DmCommonNotifyEvent::REG_CREDENTIAL_AUTH_STATUS_NOTIFY); for (const auto &item : processInfoVec) { - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - pReq->SetDeviceList(deviceList); - pReq->SetDeviceTypeId(deviceTypeId); - pReq->SetErrCode(errcode); - pReq->SetPkgName(item.pkgName); - pReq->SetProcessInfo(item); - ipcServerListener_.SendRequest(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + deviceManagerIpc->ServerCredentialAuthStatusNotify(item.pkgName, deviceList, + deviceTypeId, errcode); } } @@ -652,23 +616,22 @@ void DeviceManagerServiceListener::OnAppUnintall(const std::string &pkgName) void DeviceManagerServiceListener::OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result, int32_t status, std::string content) { - LOGI("pkgName %{public}s, userId %{public}d.", processInfo.pkgName.c_str(), processInfo.userId); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::OnSinkBindResult pkgName %{public}s, userId %{public}d.", + processInfo.pkgName.c_str(), processInfo.userId); if (status < STATUS_DM_AUTH_FINISH && status > STATUS_DM_AUTH_DEFAULT) { status = STATUS_DM_AUTH_DEFAULT; } - PeerTargetId returnTargetId = targetId; + auto targetIdExt = DmIpcUtils::ConvertToPeerTargetIdExtWrapper(targetId); + PeerTargetIdExt returnTargetId = targetIdExt; #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string deviceIdTemp = ""; DmKVValue kvValue; - if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetId.deviceId, deviceIdTemp) == DM_OK && + if (ConvertUdidHashToAnoyDeviceId(processInfo.pkgName, targetIdExt.deviceId, deviceIdTemp) == DM_OK && KVAdapterManager::GetInstance().Get(deviceIdTemp, kvValue) == DM_OK) { returnTargetId.deviceId = deviceIdTemp; } #endif - pReq->SetPkgName(processInfo.pkgName); - std::vector processInfos = ipcServerListener_.GetAllProcessInfo(); + std::vector processInfos = IpcServerStub::GetInstance().GetAllProcessInfo(); ProcessInfo processInfoTemp; for (auto item : processInfos) { if (item.pkgName == processInfo.pkgName) { @@ -679,17 +642,18 @@ void DeviceManagerServiceListener::OnSinkBindResult(const ProcessInfo &processIn LOGI("not register listener"); return; } - pReq->SetProcessInfo(processInfoTemp); - pReq->SetPeerTargetId(returnTargetId); - pReq->SetResult(result); - pReq->SetStatus(status); - pReq->SetContent(content); - ipcServerListener_.SendRequest(SINK_BIND_TARGET_RESULT, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->SinkBindTargetResult(processInfo.pkgName, returnTargetId, result, status, content); } std::vector DeviceManagerServiceListener::GetWhiteListSAProcessInfo( DmCommonNotifyEvent dmCommonNotifyEvent) { + LOGI("DM IDL DMSL::GetWhiteListSAProcessInfo dmCommonNotifyEvent: %{public}d", dmCommonNotifyEvent); if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); return {}; @@ -717,6 +681,8 @@ std::vector DeviceManagerServiceListener::GetWhiteListSAProcessInfo std::vector DeviceManagerServiceListener::GetNotifyProcessInfoByUserId(int32_t userId, DmCommonNotifyEvent dmCommonNotifyEvent) { + LOGI("DM IDL DMSL::GetNotifyProcessInfoByUserId userId: %{public}d, dmCommonNotifyEvent: %{public}d", userId, + dmCommonNotifyEvent); if (!IsDmCommonNotifyEventValid(dmCommonNotifyEvent)) { LOGE("Invalid dmCommonNotifyEvent: %{public}d.", dmCommonNotifyEvent); return {}; @@ -727,8 +693,8 @@ std::vector DeviceManagerServiceListener::GetNotifyProcessInfoByUse LOGE("callback not exist dmCommonNotifyEvent: %{public}d", dmCommonNotifyEvent); return {}; } - std::vector processInfos = ipcServerListener_.GetAllProcessInfo(); - std::set systemSA = ipcServerListener_.GetSystemSA(); + std::vector processInfos = IpcServerStub::GetInstance().GetAllProcessInfo(); + std::set systemSA = IpcServerStub::GetInstance().GetSystemSA(); std::vector processInfosTemp; for (auto item : processInfos) { if (systemSA.find(item.pkgName) != systemSA.end()) { @@ -749,7 +715,7 @@ std::vector DeviceManagerServiceListener::GetNotifyProcessInfoByUse ProcessInfo DeviceManagerServiceListener::DealBindProcessInfo(const ProcessInfo &processInfo) { - std::set systemSA = ipcServerListener_.GetSystemSA(); + std::set systemSA = IpcServerStub::GetInstance().GetSystemSA(); if (systemSA.find(processInfo.pkgName) == systemSA.end()) { return processInfo; } @@ -762,10 +728,8 @@ void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector(state), - GetAnonyString(info.deviceId).c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::ProcessDeviceOnline userId %{public}d, state %{public}d, udidhash %{public}s.", + processInfo.userId, static_cast(state), GetAnonyString(info.deviceId).c_str()); for (const auto &it : procInfoVec) { std::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); DmDeviceState notifyState = state; @@ -777,8 +741,15 @@ void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(it.pkgName, notifyState, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } } @@ -786,11 +757,9 @@ void DeviceManagerServiceListener::ProcessDeviceOffline(const std::vector(state), - GetAnonyString(info.deviceId).c_str()); + LOGI("DM IDL DMSL::ProcessDeviceOffline userId %{public}d, state %{public}d, udidhash %{public}s.", + processInfo.userId, static_cast(state), GetAnonyString(info.deviceId).c_str()); RemoveNotExistProcess(); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); for (const auto &it : procInfoVec) { { std::lock_guard autoLock(alreadyNotifyPkgNameLock_); @@ -807,8 +776,15 @@ void DeviceManagerServiceListener::ProcessDeviceOffline(const std::vector deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(it.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } { std::lock_guard autoLock(alreadyNotifyPkgNameLock_); @@ -820,13 +796,18 @@ void DeviceManagerServiceListener::ProcessDeviceInfoChange(const std::vector(state), - GetAnonyString(info.deviceId).c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::ProcessDeviceInfoChange userId %{public}d, state %{public}d, udidhash %{public}s.", + processInfo.userId, static_cast(state), GetAnonyString(info.deviceId).c_str()); for (const auto &it : procInfoVec) { - SetDeviceInfo(pReq, it, state, info, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(it.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } } @@ -834,10 +815,8 @@ void DeviceManagerServiceListener::ProcessAppOnline(const std::vector(state), - GetAnonyString(info.deviceId).c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + LOGI("DM IDL DMSL::ProcessAppOnline userId %{public}d, state %{public}d, udidhash %{public}s.", + processInfo.userId, static_cast(state), GetAnonyString(info.deviceId).c_str()); for (const auto &it : procInfoVec) { std::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); DmDeviceState notifyState = state; @@ -849,9 +828,16 @@ void DeviceManagerServiceListener::ProcessAppOnline(const std::vector deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } LOGI("ProcessAppOnline notifyState = %{public}d", notifyState); - SetDeviceInfo(pReq, it, notifyState, info, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(it.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } } @@ -859,11 +845,10 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector(state), - GetAnonyString(info.deviceId).c_str()); + LOGI("DM IDL DMSL::ProcessAppOffline userId %{public}d, state %{public}d, udidhash %{public}s.", + processInfo.userId, static_cast(state), GetAnonyString(info.deviceId).c_str()); RemoveNotExistProcess(); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); + if (!SoftbusCache::GetInstance().CheckIsOnline(std::string(info.deviceId))) { for (const auto &it : procInfoVec) { std::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); @@ -875,8 +860,15 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(it.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } } else { std::string notifyPkgName = processInfo.pkgName + "#" + std::to_string(processInfo.userId) + "#" + @@ -889,8 +881,15 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(info); + deviceManagerIpc->ServerDeviceStateNotify(processInfo.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt); } } @@ -910,6 +909,8 @@ void DeviceManagerServiceListener::OnProcessRemove(const ProcessInfo &processInf void DeviceManagerServiceListener::OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) { + LOGI("DM IDL DMSL::OnDevStateCallbackAdd pkgName %{public}s, userId %{public}d, deviceList size %{public}zu.", + processInfo.pkgName.c_str(), processInfo.userId, deviceList.size()); for (auto item : deviceList) { std::string notifyPkgName = processInfo.pkgName + "#" + std::to_string(processInfo.userId) + "#" + std::string(item.deviceId); @@ -920,12 +921,17 @@ void DeviceManagerServiceListener::OnDevStateCallbackAdd(const ProcessInfo &proc } alreadyOnlinePkgName_[notifyPkgName] = item; } + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } DmDeviceBasicInfo deviceBasicInfo; - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); ConvertDeviceInfoToDeviceBasicInfo(processInfo.pkgName, item, deviceBasicInfo); - SetDeviceInfo(pReq, processInfo, DmDeviceState::DEVICE_STATE_ONLINE, item, deviceBasicInfo); - ipcServerListener_.SendRequest(SERVER_DEVICE_STATE_NOTIFY, pReq, pRsp); + auto dmDeviceInfoExt = DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(item); + auto dmDeviceBasicInfoExt = DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(deviceBasicInfo); + deviceManagerIpc->ServerDeviceStateNotify(processInfo.pkgName, DmDeviceState::DEVICE_STATE_ONLINE, + dmDeviceInfoExt, dmDeviceBasicInfoExt); } } @@ -953,12 +959,14 @@ void DeviceManagerServiceListener::RemoveNotExistProcess() void DeviceManagerServiceListener::OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) { - LOGI("pkgName %{public}s.", processInfo.pkgName.c_str()); - std::shared_ptr pReq = - std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetDeviceProfileInfoList(deviceProfileInfos); + LOGI("DM IDL DMSL::OnGetDeviceProfileInfoListResult pkgName %{public}s.", processInfo.pkgName.c_str()); + + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + auto deviceProfileInfosExt = DmIpcUtils::ConvertToDmDeviceProfileInfoExtWrapper(deviceProfileInfos); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) std::string userDefinedDeviceName = DeviceNameManager::GetInstance().GetUserDefinedDeviceName(); if (code == DM_OK && !userDefinedDeviceName.empty()) { @@ -969,36 +977,30 @@ void DeviceManagerServiceListener::OnGetDeviceProfileInfoListResult(const Proces break; } } - pReq->SetDeviceProfileInfoList(temVec); + auto deviceProfileInfosExt = DmIpcUtils::ConvertToDmDeviceProfileInfoExtWrapper(deviceProfileInfos); } #endif - pReq->SetResult(code); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); + deviceManagerIpc->GetDeviceProfileInfoListResult(processInfo.pkgName, code, + deviceProfileInfosExt); } void DeviceManagerServiceListener::OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, const DmDeviceIconInfo &dmDeviceIconInfo, int32_t code) { - LOGI("pkgName %{public}s.", processInfo.pkgName.c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetDmDeviceIconInfo(dmDeviceIconInfo); - pReq->SetResult(code); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(GET_DEVICE_ICON_INFO_RESULT, pReq, pRsp); + LOGI("DM IDL DMSL::OnGetDeviceIconInfoResult pkgName %{public}s.", processInfo.pkgName.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + auto deviceIconInfoExt = DmIpcUtils::ConvertToDmDeviceIconInfoExtWrapper(dmDeviceIconInfo); + deviceManagerIpc->GetDeviceIconInfoResult(processInfo.pkgName, code, deviceIconInfoExt); } void DeviceManagerServiceListener::OnSetLocalDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceName, int32_t code) { - LOGI("pkgName %{public}s.", processInfo.pkgName.c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetResult(code); - pReq->SetProcessInfo(processInfo); + LOGI("DM IDL DMSL::OnSetLocalDeviceNameResult pkgName %{public}s.", processInfo.pkgName.c_str()); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) if (code == DM_OK) { DeviceNameManager::GetInstance().ModifyUserDefinedName(deviceName); @@ -1006,21 +1008,24 @@ void DeviceManagerServiceListener::OnSetLocalDeviceNameResult(const ProcessInfo #else (void) deviceName; #endif - ipcServerListener_.SendRequest(SET_LOCAL_DEVICE_NAME_RESULT, pReq, pRsp); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->SetLocalDeviceNameResult(processInfo.pkgName, code); } void DeviceManagerServiceListener::OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &deviceName, int32_t code) { - LOGI("pkgName %{public}s.", processInfo.pkgName.c_str()); - std::shared_ptr pReq = std::make_shared(); - std::shared_ptr pRsp = std::make_shared(); - pReq->SetPkgName(processInfo.pkgName); - pReq->SetDeviceId(deviceId); - pReq->SetResult(code); - pReq->SetProcessInfo(processInfo); - (void) deviceName; - ipcServerListener_.SendRequest(SET_REMOTE_DEVICE_NAME_RESULT, pReq, pRsp); + LOGI("DM IDL DMSL::OnSetRemoteDeviceNameResult pkgName %{public}s.", processInfo.pkgName.c_str()); + sptr deviceManagerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceManagerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceManagerIpc->SetRemoteDeviceNameResult(processInfo.pkgName, deviceId, code); } void DeviceManagerServiceListener::SetExistPkgName(const std::set &pkgNameSet) diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index e8f908bca808e91b7bef061b7d87ed46e4c9e3c3..6ce0175fdad23d0d6b8da4307675bcd70cfef757 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -49,6 +49,8 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" #endif +#include "device_manager_ipc_proxy.h" +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { const unsigned int XCOLLIE_TIMEOUT_S = 5; @@ -183,226 +185,6 @@ void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId) targetId.wifiPort = parcel.ReadUint16(); } -ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t deviceState = pReq->GetDeviceState(); - DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); - DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(deviceState)) { - LOGE("write state failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceInfo(deviceInfo, data)) { - LOGE("write dm device info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceBasicInfo(deviceBasicInfo, data)) { - LOGE("write dm device basic info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - uint16_t subscribeId = pReq->GetSubscribeId(); - DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); - DmDeviceBasicInfo devBasicInfo = pReq->GetDeviceBasicInfo(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt16((int16_t)subscribeId)) { - LOGE("write subscribeId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceInfo(deviceInfo, data)) { - LOGE("write dm device info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceBasicInfo(devBasicInfo, data)) { - LOGE("write dm device basic info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - uint16_t subscribeId = pReq->GetSubscribeId(); - DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt16((int16_t)subscribeId)) { - LOGE("write subscribeId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceBasicInfo(deviceBasicInfo, data)) { - LOGE("write dm device basic info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - uint16_t subscribeId = pReq->GetSubscribeId(); - int32_t result = pReq->GetResult(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt16((int16_t)subscribeId)) { - LOGE("write subscribeId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t publishId = pReq->GetPublishId(); - int32_t result = pReq->GetResult(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(publishId)) { - LOGE("write publishId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - - std::string pkgName = pReq->GetPkgName(); - std::string deviceId = pReq->GetDeviceId(); - std::string token = pReq->GetPinToken(); - int32_t status = pReq->GetStatus(); - int32_t reason = pReq->GetReason(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(deviceId)) { - LOGE("write deviceId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(token)) { - LOGE("write token failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(status)) { - LOGE("write status failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(reason)) { - LOGE("write reason failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - - std::string packagname = pReq->GetPkgName(); - std::string paramJson = pReq->GetJsonParam(); - if (!data.WriteString(packagname)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(paramJson)) { - LOGE("write paramJson failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -463,7 +245,7 @@ ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel CancelXcollieTimer(timerId); return ERR_DM_POINT_NULL; } - sptr callback(new IpcServerClientProxy(listener)); + sptr callback(new DeviceManagerIpcProxy(listener)); if (callback == nullptr) { LOGE("create ipc server client proxy failed."); CancelXcollieTimer(timerId); @@ -784,36 +566,6 @@ ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t action = pReq->GetCredentialAction(); - std::string credentialResult = pReq->GetCredentialResult(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(action)) { - LOGE("write action failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(credentialResult)) { - LOGE("write credentialResult failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1068,121 +820,6 @@ ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - PeerTargetId targetId = pReq->GetPeerTargetId(); - int32_t result = pReq->GetResult(); - int32_t status = pReq->GetStatus(); - std::string content = pReq->GetContent(); - - if (!data.WriteString(pkgName)) { - LOGE("write bind pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodePeerTargetId(targetId, data)) { - LOGE("write bind peer target id failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write bind result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(status)) { - LOGE("write bind result status failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(content)) { - LOGE("write bind result content failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - PeerTargetId targetId = pReq->GetPeerTargetId(); - int32_t result = pReq->GetResult(); - int32_t status = pReq->GetStatus(); - std::string content = pReq->GetContent(); - - if (!data.WriteString(pkgName)) { - LOGE("write bind pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodePeerTargetId(targetId, data)) { - LOGE("write bind peer target id failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write bind result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(status)) { - LOGE("write bind result status failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(content)) { - LOGE("write bind result content failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - PeerTargetId targetId = pReq->GetPeerTargetId(); - int32_t result = pReq->GetResult(); - std::string content = pReq->GetContent(); - - if (!data.WriteString(pkgName)) { - LOGE("write unbind pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodePeerTargetId(targetId, data)) { - LOGE("write unbind peer target id failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write unbind result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(content)) { - LOGE("write unbind result content failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1224,121 +861,6 @@ ON_IPC_CMD(DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - std::string deviceId = pReq->GetDeviceId(); - int32_t pinType = pReq->GetPinType(); - std::string payload = pReq->GetPayload(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(deviceId)) { - LOGE("write deviceId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(pinType)) { - LOGE("write pinType failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(payload)) { - LOGE("write payload failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t pinType = pReq->GetPinType(); - std::string payload = pReq->GetPayload(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(pinType)) { - LOGE("write pinType failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(payload)) { - LOGE("write payload failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t result = pReq->GetResult(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t result = pReq->GetResult(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(DP_ACL_ADD, MessageParcel &data, MessageParcel &reply) { std::string udid = data.ReadString(); @@ -1365,41 +887,6 @@ ON_IPC_CMD(GET_SECURITY_LEVEL, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - int32_t pinHolderEvent = pReq->GetPinHolderEvent(); - int32_t result = pReq->GetResult(); - std::string content = pReq->GetContent(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(result)) { - LOGE("write result failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(pinHolderEvent)) { - LOGE("write pinHolderEvent failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(content)) { - LOGE("write content failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(IS_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply) { std::string netWorkId = data.ReadString(); @@ -1468,65 +955,6 @@ ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - std::string udid = pReq->GetUdid(); - int32_t authForm = pReq->GetAuthForm(); - std::string uuid = pReq->GetUuid(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(udid)) { - LOGE("write udid failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(authForm)) { - LOGE("write authForm code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(uuid)) { - LOGE("write uuid code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(REMOTE_DEVICE_TRUST_CHANGE, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - -ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!EncodeDmDeviceInfo(deviceInfo, data)) { - LOGE("write dm device info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(GET_DEVICE_SCREEN_STATUS, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1574,42 +1002,6 @@ ON_IPC_CMD(GET_ANONY_LOCAL_UDID, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = - std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - std::string deviceList = pReq->GetDeviceList(); - uint16_t deviceTypeId = pReq->GetDeviceTypeId(); - int32_t errCode = pReq->GetErrCode(); - - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteString(deviceList)) { - LOGE("write deviceList failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteUint16(deviceTypeId)) { - LOGE("write deviceTypeId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!data.WriteInt32(errCode)) { - LOGE("write errCode failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(SYNC_CALLBACK, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1659,42 +1051,6 @@ ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &rep return DM_OK; } -ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = - std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - int32_t result = pReq->GetResult(); - if (!data.WriteInt32(result)) { - LOGE("write result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - std::vector deviceProfileInfos = pReq->GetDeviceProfileInfoList(); - if (!data.WriteInt32((int32_t)deviceProfileInfos.size())) { - LOGE("write device list size failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - for (const auto &devInfo : deviceProfileInfos) { - if (!IpcModelCodec::EncodeDmDeviceProfileInfo(devInfo, data)) { - LOGE("write dm device profile info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(PUT_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1728,35 +1084,6 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); - std::shared_ptr pReq = - std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - int32_t result = pReq->GetResult(); - if (!data.WriteInt32(result)) { - LOGE("write result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - if (!IpcModelCodec::EncodeDmDeviceIconInfo(pReq->GetDmDeviceIconInfo(), data)) { - LOGE("write dm device icon info failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1840,36 +1167,6 @@ ON_IPC_CMD(SET_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SET_LOCAL_DEVICE_NAME_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - std::shared_ptr pReq = - std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - int32_t result = pReq->GetResult(); - if (!data.WriteInt32(result)) { - LOGE("write result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(SET_REMOTE_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); @@ -1883,41 +1180,6 @@ ON_IPC_CMD(SET_REMOTE_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) return DM_OK; } -ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) -{ - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - std::shared_ptr pReq = - std::static_pointer_cast(pBaseReq); - std::string pkgName = pReq->GetPkgName(); - if (!data.WriteString(pkgName)) { - LOGE("write pkgName failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - std::string deviceId = pReq->GetDeviceId(); - if (!data.WriteString(deviceId)) { - LOGE("write deviceId failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - int32_t result = pReq->GetResult(); - if (!data.WriteInt32(result)) { - LOGE("write result code failed"); - return ERR_DM_IPC_WRITE_FAILED; - } - return DM_OK; -} - -ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} - ON_IPC_CMD(RESTORE_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index acc8499e74fc3f0e1a283b0c4a5e5c60f9b88311..f04ddac21d4cdc3c2e2e431c1a0ceecc3a2004eb 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -300,7 +300,8 @@ ServiceRunningState IpcServerStub::QueryServiceState() const return state_; } -int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processInfo, sptr listener) +int32_t IpcServerStub::RegisterDeviceManagerListener(const ProcessInfo &processInfo, + sptr listener) { if (processInfo.pkgName.empty() || listener == nullptr) { LOGE("RegisterDeviceManagerListener error: input parameter invalid."); @@ -388,7 +389,7 @@ std::vector IpcServerStub::GetAllProcessInfo() return processInfoVec; } -const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo) const +const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo) const { if (processInfo.pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); diff --git a/test/benchmarktest/device_manager_test/BUILD.gn b/test/benchmarktest/device_manager_test/BUILD.gn index 8de2eb535d467d4a31fef977a62ead75c13211f2..50f66196dc4f94f41ac6c4a965a4df909e06e2ca 100644 --- a/test/benchmarktest/device_manager_test/BUILD.gn +++ b/test/benchmarktest/device_manager_test/BUILD.gn @@ -30,6 +30,7 @@ ohos_benchmarktest("DeviceManagerTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] external_deps = [ + "c_utils:utils", "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", diff --git a/test/commonfuzztest/authacl_fuzzer/BUILD.gn b/test/commonfuzztest/authacl_fuzzer/BUILD.gn index 6800b459d3b2c731b2f82380c8e4cb6794888e23..b417b6e502130e467194c4cafe6b7529cfbf4f94 100644 --- a/test/commonfuzztest/authacl_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authacl_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("AuthAclFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn index 95b5069e4f0c78ddbbcb2657e40271225c833b1d..369b4616dda7b4ef9393d0a3d267df8b67d360b5 100644 --- a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("AuthCredentialFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/authenticatedevice_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedevice_fuzzer/BUILD.gn index 11daa7b6b34c829ef7fc318abc6e538c381be7b7..0b2ea9ed7968a222fed28243045bf97269380b1d 100644 --- a/test/commonfuzztest/authenticatedevice_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedevice_fuzzer/BUILD.gn @@ -64,6 +64,7 @@ ohos_fuzztest("AuthenticateDeviceFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn index cab2d2cd65eebdef01255ee0801d34016abb3351..49dc2a55e1c4f644f8ce0033a316762f2380062b 100644 --- a/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceservice_fuzzer/BUILD.gn @@ -59,6 +59,7 @@ ohos_fuzztest("AuthenticateDeviceServiceFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservicetest", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn index 91a31da58defc09e577b9606d58cc7b7d0bc0567..c483bac8b129d581e9d3aba129318b4e18603dc0 100644 --- a/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn +++ b/test/commonfuzztest/authenticatedeviceserviceimpl_fuzzer/BUILD.gn @@ -69,6 +69,7 @@ ohos_fuzztest("AuthenticateDeviceServiceImplFuzzTest") { "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", "${devicemanager_path}/services/service:devicemanagerservicetest", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn index 1d394b8ad08031b12cdae65d7a128a8067ab2620..35c9303cc6759dab037758b5ffdc85a9bfe4e250 100644 --- a/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmauthmanager_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("DmAuthManagerFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn b/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn index fb2de39cab0aa6a70aefea49cc690e3e5d00b8f4..a831ec97ffe54659f8418eb01010209346005aa7 100644 --- a/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmauthmanagerv2_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("DmAuthManagerV2FuzzTest") { "${services_path}:devicemanagerservice", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutils", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/dmcredentialimpl_fuzzer/BUILD.gn b/test/commonfuzztest/dmcredentialimpl_fuzzer/BUILD.gn index 05d532c4cb98d96033d7ebaaa145d8b21ecb399a..2c1c78887a8175b60c0bfaa4aa41e037c203d4f9 100644 --- a/test/commonfuzztest/dmcredentialimpl_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmcredentialimpl_fuzzer/BUILD.gn @@ -52,7 +52,10 @@ ohos_fuzztest("DMCredentialImplFuzzTest") { sources = [ "dm_credential_impl_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn index 01ef24d272ca6803d48870076ae9785cf7196113..35a801dc1b00c6462c7437976a00d697512f9e0f 100644 --- a/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("DmFreezeProcessFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn b/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn index 1ce9887cd4b0e4ace91da4fa32475a623b8540a2..3fc6b59068a3c9f5d3555ebddef900983f874868 100644 --- a/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("DmNegotiateProcessFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/generateencrypteduuid_fuzzer/BUILD.gn b/test/commonfuzztest/generateencrypteduuid_fuzzer/BUILD.gn index b6d56f31ee781fe79c44bd71183a715df969b8cc..c4d341d080365eaa0851de14e390a76dd50703b7 100644 --- a/test/commonfuzztest/generateencrypteduuid_fuzzer/BUILD.gn +++ b/test/commonfuzztest/generateencrypteduuid_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GenerateEncryptedUuidFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/getdeviceinfo_fuzzer/BUILD.gn b/test/commonfuzztest/getdeviceinfo_fuzzer/BUILD.gn index c8cbead482d1639466f483420938ff4c07f44c54..e501c9e7370535db9739491595fdc3bfee9e07e7 100644 --- a/test/commonfuzztest/getdeviceinfo_fuzzer/BUILD.gn +++ b/test/commonfuzztest/getdeviceinfo_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GetDeviceInfoFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn index dd80157794d06d5c381710448d812a825de7e44f..377d25ce0f5158f9e6c0d03f8673600951158500 100644 --- a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("OnDataReceivedFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn index b81e1b47298dfc17c2d5288fd1d947d192304f19..8b01474d955f36a3f2c6134ca7a23f8061cd6b25 100644 --- a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("OnDataReceivedV2FuzzTest") { "${services_path}:devicemanagerservice", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutils", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/onerror_fuzzer/BUILD.gn b/test/commonfuzztest/onerror_fuzzer/BUILD.gn index 9d9d2801dca8be36635b71501fe25472f0f6f4bb..bafffdeb031fd80d9ba11e65edb1d8fb27190ad2 100644 --- a/test/commonfuzztest/onerror_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onerror_fuzzer/BUILD.gn @@ -47,6 +47,7 @@ ohos_fuzztest("OnErrorFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn index 3881335e7ec7603209f9d3df225a0bfac04a99fc..244c9b89c80a78a6858d6d15895309e0471df258 100644 --- a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn @@ -47,6 +47,7 @@ ohos_fuzztest("OnFinishFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn index 34a301d7aee7e05919d7e95f7b072e3580581445..c58b04daac4f7265d3998c9b70c9c48d37844917 100644 --- a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn @@ -48,6 +48,7 @@ ohos_fuzztest("OnRequestFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/commonfuzztest/pinauth_fuzzer/BUILD.gn b/test/commonfuzztest/pinauth_fuzzer/BUILD.gn index f8ad7083e43ef54d023c3130781729ff1d6b5590..1fcae814b0651ae988883cabd3b66fe4549adf1a 100644 --- a/test/commonfuzztest/pinauth_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinauth_fuzzer/BUILD.gn @@ -68,6 +68,7 @@ ohos_fuzztest("PinAuthFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn b/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn index c24e87558f6367d5ebbbef8f4e7c2186e85bf5c1..733b36eb23a43b81b8c2a030d9e86ed58b42aa20 100644 --- a/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinauthui_fuzzer/BUILD.gn @@ -69,6 +69,7 @@ ohos_fuzztest("PinAuthUiFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonfuzztest/pinholder_fuzzer/BUILD.gn b/test/commonfuzztest/pinholder_fuzzer/BUILD.gn index c673b1edcd1b2c3452c73ea9dcc7cade5a785a17..d0947247c3aa000a7ecb9f7cdf95dbc06290f76c 100644 --- a/test/commonfuzztest/pinholder_fuzzer/BUILD.gn +++ b/test/commonfuzztest/pinholder_fuzzer/BUILD.gn @@ -69,6 +69,7 @@ ohos_fuzztest("PinHolderFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/commonunittest/UTTest_dm_device_state_manager.cpp b/test/commonunittest/UTTest_dm_device_state_manager.cpp index 80aaf0bbf38f2d751c39ed2c7ce3387082572af4..c9151d5e55555cf04edfb4fc5d7208f3b4d0ce95 100644 --- a/test/commonunittest/UTTest_dm_device_state_manager.cpp +++ b/test/commonunittest/UTTest_dm_device_state_manager.cpp @@ -93,16 +93,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDbReady_001, testing::ext::TestSize.Level0) DmDeviceInfo info; strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); dmDeviceStateManager->OnDbReady(pkgName, deviceId); - std::shared_ptr pReq = - std::static_pointer_cast(listener_->ipcServerListener_.req_); - DmDeviceInfo dminfo; - if (pReq == nullptr) { - strcpy_s(dminfo.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); - } else { - dminfo = pReq->GetDeviceInfo(); - } - int result = strcmp(info.deviceId, dminfo.deviceId); - EXPECT_EQ(result, 0); + EXPECT_NE(dmDeviceStateManager->softbusConnector_, nullptr); } /** diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn index a7e9c70382236ee1d7ae696f97438bb8ea36608b..6e03a0d6837b274b429a1a9cc3387573454dfe0c 100755 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -64,6 +64,7 @@ ohos_fuzztest("DeviceManagerImplFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index e6a972d7f23f1b823e1fd87fa3308e49dc573888..4de1c9e8655998eb949995e18767ffc723382368 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -42,8 +42,6 @@ group("fuzztest") { "ipcclientmanager_fuzzer:fuzztest", "ipccmdregister_fuzzer:fuzztest", "ipcserverclientproxy_fuzzer:fuzztest", - "ipcserverlistener_fuzzer:fuzztest", - "ipcserverstub_fuzzer:fuzztest", "notifyevent_fuzzer:fuzztest", "registerdevicemanagerfacallback_fuzzer:fuzztest", "registerdevstatecallback_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn index 810c280fa413d44bfa645e6d74ccd78f7bb6bb3b..d0687570cad926bc22fbbf640eb9a02e435787ac 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("AuthConfirmFuzzTest") { "${json_path}:devicemanagerjson", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ @@ -58,6 +59,7 @@ ohos_fuzztest("AuthConfirmFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "kv_store:distributeddata_inner", + "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn index c2add4c2d3e2dec16c3e15b5de7c93fe3a0eac8a..3a552d88acf1f02c3e3bfbebe57b76cbb3268c36 100644 --- a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("AuthManagerFuzzTest") { "${json_path}:devicemanagerjson", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ @@ -58,6 +59,7 @@ ohos_fuzztest("AuthManagerFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "kv_store:distributeddata_inner", + "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn b/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn index 03a5e37e89f666721cb7be213e389163c67875b4..a51fe6ead8f58a66b3fc1cf61f749963a1b03d6e 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("AuthMessageProcessorFuzzTest") { "${json_path}:devicemanagerjson", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ @@ -58,6 +59,7 @@ ohos_fuzztest("AuthMessageProcessorFuzzTest") { "init:libbegetutil", "ipc:ipc_single", "kv_store:distributeddata_inner", + "safwk:system_ability_fwk", "samgr:samgr_proxy", ] diff --git a/test/servicesfuzztest/devicediscovery_fuzzer/BUILD.gn b/test/servicesfuzztest/devicediscovery_fuzzer/BUILD.gn index d25753b45ffe1f0b7d77d77c8f81367c531a27f3..f00f02026449c0d2d02570ddbc7f126359885ff8 100644 --- a/test/servicesfuzztest/devicediscovery_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicediscovery_fuzzer/BUILD.gn @@ -59,7 +59,10 @@ ohos_fuzztest("DeviceDiscoveryFuzzTest") { ] sources = [ "device_discovery_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/devicelist_fuzzer/BUILD.gn b/test/servicesfuzztest/devicelist_fuzzer/BUILD.gn index dabde34eb15d93fbedbc1b110d106a3849d186d3..6a0bb8b97b671631040e23c4e554dee811361a0a 100644 --- a/test/servicesfuzztest/devicelist_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicelist_fuzzer/BUILD.gn @@ -60,7 +60,10 @@ ohos_fuzztest("DeviceListFuzzTest") { ] sources = [ "device_list_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/devicelistrefresh_fuzzer/BUILD.gn b/test/servicesfuzztest/devicelistrefresh_fuzzer/BUILD.gn index e8f6491639ec04868ed0349a427112839b08ca74..4dc13b1b4091f4cac107547e79743a6103b89d4f 100644 --- a/test/servicesfuzztest/devicelistrefresh_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicelistrefresh_fuzzer/BUILD.gn @@ -59,7 +59,10 @@ ohos_fuzztest("DeviceListRefreshFuzzTest") { ] sources = [ "device_list_refresh_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/devicemanagernotify_fuzzer/BUILD.gn b/test/servicesfuzztest/devicemanagernotify_fuzzer/BUILD.gn index d0a50b7ff2c2df6cab1c950c27776a8881a11a98..a43c9116e933951751734b85cb0810061701671f 100644 --- a/test/servicesfuzztest/devicemanagernotify_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicemanagernotify_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("DeviceManagerNotifyFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn index 21041b11a8e10d60cb6d6176ba98092a71aa77c0..1fdceed9b0bd0a0842d291912199d02e54681e94 100644 --- a/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicemanagerservice_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("DeviceManagerServiceFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservicetest", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/servicesfuzztest/devicepublish_fuzzer/BUILD.gn b/test/servicesfuzztest/devicepublish_fuzzer/BUILD.gn index 52a8b23f3a4d3d82a062eafabda45b0d44e6444c..e4e89f55b451a7b8701a59ef68ca92752127cc53 100644 --- a/test/servicesfuzztest/devicepublish_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicepublish_fuzzer/BUILD.gn @@ -63,6 +63,7 @@ ohos_fuzztest("DevicePublishFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn index 414caff5abfa17dc56bf5c8fb441f024548bd039..5df91ad091fd566f006095fd59d352c69a18e4fa 100644 --- a/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/dmsoftbuslistener_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("DmSoftbusListenerFuzzTest") { "${devicemanager_path}/services/service:devicemanagerservicetest", "${json_path}:devicemanagerjson", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/servicesfuzztest/getlocaldeviceinfo_fuzzer/BUILD.gn b/test/servicesfuzztest/getlocaldeviceinfo_fuzzer/BUILD.gn index f90940c283f0fa28cd3ec4c6fb31212d66eab56c..8dfb2dfbf6f93ac0a21069312abc82863e6872b8 100644 --- a/test/servicesfuzztest/getlocaldeviceinfo_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/getlocaldeviceinfo_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("GetLocalDeviceInfoFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] defines = [ diff --git a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn index 7c353daa95ce804e8b2107f7a9d9cf9c0bcd3a5c..7055a23a8eca02edf42fad6d82f8ee700b86885c 100644 --- a/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/gettrusteddevicelistservice_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("GetTrustedDeviceListServiceFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservicetest", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/servicesfuzztest/getudidbynetworkid_fuzzer/BUILD.gn b/test/servicesfuzztest/getudidbynetworkid_fuzzer/BUILD.gn index 380474c9d2921318fc78c9c26df46436f8220988..9cd0789038ed33d35245a287257c0c8038f97d33 100644 --- a/test/servicesfuzztest/getudidbynetworkid_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/getudidbynetworkid_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("GetUdidByNetworkIdFuzzTest") { ] sources = [ "get_udid_by_network_id_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/getuuidbynetworkid_fuzzer/BUILD.gn b/test/servicesfuzztest/getuuidbynetworkid_fuzzer/BUILD.gn index 6f32db722bf5d5f7dbc86ce505079dd3174bd188..47092baf36445bf628c04e95bbb3117cb6113949 100644 --- a/test/servicesfuzztest/getuuidbynetworkid_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/getuuidbynetworkid_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("GetUuidByNetworkIdFuzzTest") { ] sources = [ "get_uuid_by_network_id_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/initdevicemanager_fuzzer/BUILD.gn b/test/servicesfuzztest/initdevicemanager_fuzzer/BUILD.gn index 800fcc952a3507416d31cc643c4dec292bc83007..bcc91e1fe9e2e5623364138ddc1bd6094d20fd55 100644 --- a/test/servicesfuzztest/initdevicemanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/initdevicemanager_fuzzer/BUILD.gn @@ -52,7 +52,10 @@ ohos_fuzztest("InitDeviceManagerFuzzTest") { sources = [ "init_device_manager_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/ipcclientmanager_fuzzer/BUILD.gn b/test/servicesfuzztest/ipcclientmanager_fuzzer/BUILD.gn index 04ab3d1024423451c829534a719a31bd4e7018c7..b14d02f6cb9d6492b5a1d151cee5a1c8c508b65f 100644 --- a/test/servicesfuzztest/ipcclientmanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/ipcclientmanager_fuzzer/BUILD.gn @@ -61,7 +61,10 @@ ohos_fuzztest("IpcClientManagerFuzzTest") { sources = [ "ipc_client_manager_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn b/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn index a021875d7d5d56c2d21c49abe99fc350f4e6e78e..29e6e4c4f692a2c3406c81402d01993020af7e92 100644 --- a/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn @@ -60,7 +60,10 @@ ohos_fuzztest("IpcServerStubFuzzTest") { sources = [ "ipc_server_stub_fuzzer.cpp" ] - deps = [ "${devicemanager_path}/services/service:devicemanagerservicetest" ] + deps = [ + "${devicemanager_path}/services/service:devicemanagerservicetest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", @@ -74,6 +77,7 @@ ohos_fuzztest("IpcServerStubFuzzTest") { "data_share:datashare_common", "data_share:datashare_consumer", "device_auth:deviceauth_sdk", + "ffrt:libffrt", "ipc:ipc_core", "ipc:ipc_single", "napi:ace_napi", diff --git a/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp b/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp index 1a75d5056d5d3646ec456a6daa445b3059a94823..2c05cdfbbd809f70d1635aa882fcfa631e4399ac 100644 --- a/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp +++ b/test/servicesfuzztest/ipcserverstub_fuzzer/ipc_server_stub_fuzzer.cpp @@ -53,7 +53,6 @@ void IpcServerStubFuzzTest(const uint8_t* data, size_t size) IpcServerStub::GetInstance().Init(); IpcServerStub::GetInstance().OnRemoteRequest(code, data1, reply, option); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); IpcServerStub::GetInstance().GetDmListener(processInfo); IpcServerStub::GetInstance().SendCmd(code, req, rsp); IpcServerStub::GetInstance().GetAllProcessInfo(); diff --git a/test/servicesfuzztest/notifyevent_fuzzer/BUILD.gn b/test/servicesfuzztest/notifyevent_fuzzer/BUILD.gn index dfd1270d57c54b9dc0118f620ea02bd4d017590d..7daa2fc637308353517898d35a2218cc48b6c18e 100644 --- a/test/servicesfuzztest/notifyevent_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/notifyevent_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("NotifyEventFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/servicesfuzztest/registerdevicemanagerfacallback_fuzzer/BUILD.gn b/test/servicesfuzztest/registerdevicemanagerfacallback_fuzzer/BUILD.gn index 9db7b0d3d2848910b7d76832c2a722cf3c3cd319..0c8e244cd97508516b878eb02b7b4cc9cd4befec 100644 --- a/test/servicesfuzztest/registerdevicemanagerfacallback_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/registerdevicemanagerfacallback_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("RegisterDeviceManagerFaCallbackFuzzTest") { sources = [ "register_device_manager_fa_callback_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/registerdevstatecallback_fuzzer/BUILD.gn b/test/servicesfuzztest/registerdevstatecallback_fuzzer/BUILD.gn index bef378127c31e339f37da25c4751447925a55858..2169e0f68939eca769d7d74cfe00281f3d56e6fc 100644 --- a/test/servicesfuzztest/registerdevstatecallback_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/registerdevstatecallback_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("RegisterDevStateCallbackFuzzTest") { sources = [ "register_dev_state_callback_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/setuseroperation_fuzzer/BUILD.gn b/test/servicesfuzztest/setuseroperation_fuzzer/BUILD.gn index 6c09931f42e43a2b42a0568c498fe3ecce03f178..155fd93cfd6f4b9f05f1f43f705765ffe6475ed6 100644 --- a/test/servicesfuzztest/setuseroperation_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/setuseroperation_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("SetUserOperationFuzzTest") { sources = [ "set_user_operation_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn index a43f96e63a55531e3fb205e09ab9fccb7fc4857c..8ac368a24e0e38b6b23ca0b0a8cc1ccbcb5bf03c 100644 --- a/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/shiftlnngeardeviceservice_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("ShiftLNNGearDeviceServiceFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservicetest", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/servicesfuzztest/unauthenticatedevice_fuzzer/BUILD.gn b/test/servicesfuzztest/unauthenticatedevice_fuzzer/BUILD.gn index e84dc5c3da069cc7d763368acb287790d5e83628..b500a7a0558aa863beebd7a298a8992632979d84 100644 --- a/test/servicesfuzztest/unauthenticatedevice_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/unauthenticatedevice_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("UnAuthenticateDeviceFuzzTest") { sources = [ "un_authenticate_device_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/servicesfuzztest/unregisterdevicemanagerfacallback_fuzzer/BUILD.gn b/test/servicesfuzztest/unregisterdevicemanagerfacallback_fuzzer/BUILD.gn index a2b11c1168336b5d16a5352c86b2093ab89189d6..aba66d6d42c029926aaf6cd7a32b2258093d3373 100644 --- a/test/servicesfuzztest/unregisterdevicemanagerfacallback_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/unregisterdevicemanagerfacallback_fuzzer/BUILD.gn @@ -58,7 +58,10 @@ ohos_fuzztest("UnRegisterDeviceManagerFaCallbackFuzzTest") { sources = [ "un_register_device_manager_fa_call_back_fuzzer.cpp" ] - deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] defines = [ "HI_LOG_ENABLE", diff --git a/test/softbusfuzztest/closedmradarhelperobj_fuzzer/BUILD.gn b/test/softbusfuzztest/closedmradarhelperobj_fuzzer/BUILD.gn index be65e803c71cc017401a696d1edd29caab62a0f4..87a241199b76d5616d0ea0b60d5697cdca5af4d2 100644 --- a/test/softbusfuzztest/closedmradarhelperobj_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/closedmradarhelperobj_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("CloseDmRadarHelperObjFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn index 872e0c8a2e6246e43ec7944faae911f92ad0c0ad..cc972847e8a12a47375c0de335588ba9f3dfa845 100644 --- a/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn @@ -55,6 +55,7 @@ ohos_fuzztest("OnBytesReceivedFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ @@ -62,6 +63,7 @@ ohos_fuzztest("OnBytesReceivedFuzzTest") { "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", + "ffrt:libffrt", "init:libbegetutil", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/onparameterchgcallback_fuzzer/BUILD.gn b/test/softbusfuzztest/onparameterchgcallback_fuzzer/BUILD.gn index 7ba953e6c881dda203cea0e306c56a8ac23b056a..d135756db1c02c54a6fc3255052ab8564a5ee186 100644 --- a/test/softbusfuzztest/onparameterchgcallback_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onparameterchgcallback_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("OnParameterChgCallbackFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn index 420fe22764d20857ee06c49a31cbd8c2d43d3110..5bdc5be99c0c3d4a61959a87aafdbd7a855e523b 100644 --- a/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("OnSoftbusDeviceInfoChangedFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn index aa9cd8d97b35452d029e68379cdd3113aa461314..f11778186dbce8866edcdace78d2eaba091a6447 100644 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("OnSoftbusDeviceOfflineFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn index 83ffef54469c1a1a9b70e28c44fd8ba9260ef27b..1dde0ef6851302df692647c6ded8cc09fbd07873 100644 --- a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("OnSoftbusDeviceOnlineFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn index fc2e6cd206a218d9f7622be4d4434bfc028cfe84..a87e64cf34377ad909ddf33f9426acd51284f792 100644 --- a/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn @@ -43,6 +43,7 @@ ohos_fuzztest("OnSoftbusListenerDeviceFoundFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn index c3066fa506e90d0e45bb12206983b5898580e37f..6b07754f74303832f4a7dda728107b1e357cbcd5 100644 --- a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("PublishSoftbusLnnFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn index 2a4a650e9ec5459b9bafe91e6721f71723a78486..7a9de53d64a85010a87d4e48c94d16f4e09249c1 100644 --- a/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("RefreshSoftbusLnnFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/BUILD.gn b/test/softbusfuzztest/softbuslistener_fuzzer/BUILD.gn index 56c9f5fac539b66bc84fc4972390d371c0ab3321..f60da9f88cb40e546ae7de7acf746f1a8215eaca 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbuslistener_fuzzer/BUILD.gn @@ -49,6 +49,7 @@ ohos_fuzztest("SoftbusListenerFuzzTest") { "${json_path}:devicemanagerjson", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/softbuslistenergetlocaldeviceinfo_fuzzer/BUILD.gn b/test/softbusfuzztest/softbuslistenergetlocaldeviceinfo_fuzzer/BUILD.gn index 46986b2f80415ee98a9c38a12e0e094b50a6cae6..e1ea0c1a1a47fa453355347c038c37303e72f508 100644 --- a/test/softbusfuzztest/softbuslistenergetlocaldeviceinfo_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbuslistenergetlocaldeviceinfo_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("SoftbusListenerGetLocalDeviceInfoFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn index 7f61cc1610435e9f11573f65cb16b8ad34d6dc35..998e4c174f17985dd775d833be35286dc7ea1405 100644 --- a/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn @@ -50,6 +50,7 @@ ohos_fuzztest("SoftbusSessionObjectFuzzTest") { "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ @@ -57,6 +58,7 @@ ohos_fuzztest("SoftbusSessionObjectFuzzTest") { "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", + "ffrt:libffrt", "init:libbegetutil", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn index c844e2e0c4c9d455e33d0da29903cde9b6110cb9..9434d4f75ff90a7bdbc2cc366f92c0fc9ddeedf8 100644 --- a/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("StopRefreshSoftbusLnnFuzzTest") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", ] external_deps = [ diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index b405c21c927c710508bc4d276da3ff41f866c576..9cd989c5f28c7ed524f05f72a5a94424cf8bed26 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -33,11 +33,12 @@ group("unittest") { ":UTTest_auth_response_state", ":UTTest_crypto_mgr", ":UTTest_device_manager_impl", + ":UTTest_device_manager_notify_service", ":UTTest_device_manager_notify", ":UTTest_device_manager_service", ":UTTest_device_manager_service_impl", - ":UTTest_device_manager_service_impl_first", ":UTTest_device_manager_service_listener", + ":UTTest_device_manager_service_impl_first", ":UTTest_device_manager_service_notify", ":UTTest_device_manager_service_three", ":UTTest_device_name_manager", @@ -83,8 +84,6 @@ group("unittest") { ":UTTest_ipc_cmd_parser_service", ":UTTest_ipc_cmd_register", ":UTTest_ipc_get_device_info_rsp", - ":UTTest_ipc_server_client_proxy", - ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", ":UTTest_json_object", ":UTTest_json_str_handle", @@ -117,7 +116,10 @@ ohos_unittest("UTTest_pin_auth") { sources = [ "${devicemanager_path}/test/commonunittest/UTTest_pin_auth.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "data_share:datashare_common", @@ -129,6 +131,7 @@ ohos_unittest("UTTest_pin_auth") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -146,7 +149,10 @@ ohos_unittest("UTTest_pin_auth_ui") { sources = [ "${devicemanager_path}/test/commonunittest/UTTest_pin_auth_ui.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -156,6 +162,7 @@ ohos_unittest("UTTest_pin_auth_ui") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -182,6 +189,7 @@ ohos_unittest("UTTest_ipc_cmd_parser_client") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -215,8 +223,8 @@ ohos_unittest("UTTest_ipc_cmd_parser_service") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", - "eventhandler:libeventhandler", "dsoftbus:softbus_client", + "eventhandler:libeventhandler", "ffrt:libffrt", "googletest:gmock", "hicollie:libhicollie", @@ -248,6 +256,7 @@ ohos_unittest("UTTest_ipc_cmd_register") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -337,6 +346,7 @@ ohos_unittest("UTTest_dm_pin_holder") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -353,6 +363,7 @@ ohos_unittest("UTTest_ipc_get_device_info_rsp") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -372,6 +383,7 @@ ohos_unittest("UTTest_dm_common_event_manager") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -389,6 +401,7 @@ ohos_unittest("device_manager_impl_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -411,7 +424,10 @@ ohos_unittest("UTTest_dm_credential_manager") { sources = [ "${devicemanager_path}/test/commonunittest/UTTest_dm_credential_manager.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -424,6 +440,7 @@ ohos_unittest("UTTest_dm_credential_manager") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -448,7 +465,10 @@ ohos_unittest("UTTest_device_manager_service") { "mock/softbus_listener_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -465,6 +485,7 @@ ohos_unittest("UTTest_device_manager_service") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -476,7 +497,10 @@ ohos_unittest("UTTest_dm_softbus_cache") { sources = [ "UTTest_dm_softbus_cache.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -492,6 +516,7 @@ ohos_unittest("UTTest_dm_softbus_cache") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -509,7 +534,10 @@ ohos_unittest("UTTest_device_manager_service_three") { "mock/softbus_listener_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -525,6 +553,7 @@ ohos_unittest("UTTest_device_manager_service_three") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -549,6 +578,7 @@ ohos_unittest("UTTest_device_manager_service_notify") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -571,6 +601,7 @@ ohos_unittest("UTTest_hichain_auth_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -596,6 +627,7 @@ ohos_unittest("UTTest_hichain_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -618,6 +650,7 @@ ohos_unittest("UTTest_mine_hichain_connector") { "dsoftbus:softbus_client", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -654,6 +687,7 @@ ohos_unittest("UTTest_mine_softbus_listener") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "openssl:libcrypto_shared", + "safwk:system_ability_fwk", ] } @@ -686,6 +720,7 @@ ohos_unittest("UTTest_softbus_connector") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "os_account:libaccountkits", + "safwk:system_ability_fwk", ] } @@ -724,6 +759,7 @@ ohos_unittest("UTTest_softbus_listener") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -756,6 +792,7 @@ ohos_unittest("UTTest_softbus_listener_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -775,7 +812,10 @@ ohos_unittest("UTTest_softbus_publish") { "${devicemanager_path}/test/unittest/mock/parameter.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -787,6 +827,7 @@ ohos_unittest("UTTest_softbus_publish") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -802,7 +843,10 @@ ohos_unittest("UTTest_softbus_session") { "${devicemanager_path}/test/softbusunittest/UTTest_softbus_session.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -814,6 +858,7 @@ ohos_unittest("UTTest_softbus_session") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -831,6 +876,7 @@ ohos_unittest("UTTest_dm_adapter_manager") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -854,6 +900,7 @@ ohos_unittest("UTTest_dm_anonymous") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -874,6 +921,7 @@ ohos_unittest("UTTest_dm_timer") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -892,6 +940,7 @@ ohos_unittest("UTTest_dm_transport") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -909,6 +958,7 @@ ohos_unittest("UTTest_dm_transport_msg") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -925,6 +975,7 @@ ohos_unittest("UTTest_dm_service_load") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -943,6 +994,7 @@ ohos_unittest("UTTest_ipc_client_manager") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -960,6 +1012,7 @@ ohos_unittest("UTTest_ipc_client_proxy") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -981,6 +1034,7 @@ ohos_unittest("UTTest_ipc_client_stub") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -995,7 +1049,10 @@ ohos_unittest("UTTest_ipc_server_client_proxy") { "UTTest_ipc_server_client_proxy.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "cJSON:cjson", @@ -1065,6 +1122,15 @@ ohos_unittest("UTTest_ipc_server_stub") { ohos_unittest("UTTest_device_manager_impl") { module_out_path = module_out_path + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + boundary_sanitize = true + integer_overflow = true + ubsan = true + } + sources = [ "UTTest_device_manager_impl.cpp", "UTTest_device_manager_impl_three.cpp", @@ -1086,6 +1152,7 @@ ohos_unittest("UTTest_device_manager_impl") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] cflags = [ @@ -1105,7 +1172,10 @@ ohos_unittest("UTTest_dm_import_auth_code") { sources = [ "UTTest_dm_import_auth_code.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -1117,6 +1187,7 @@ ohos_unittest("UTTest_dm_import_auth_code") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -1141,6 +1212,7 @@ ohos_unittest("UTTest_multiple_user_connector") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1170,6 +1242,7 @@ ohos_unittest("UTTest_permission_manager") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -1229,6 +1302,7 @@ ohos_unittest("UTTest_device_manager_notify") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1246,6 +1320,7 @@ ohos_unittest("UTTest_ipc_client_server_proxy") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1259,7 +1334,10 @@ ohos_unittest("UTTest_dm_device_state_manager") { sources = [ "${devicemanager_path}/test/commonunittest/UTTest_dm_device_state_manager.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1271,6 +1349,7 @@ ohos_unittest("UTTest_dm_device_state_manager") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1288,7 +1367,10 @@ ohos_unittest("UTTest_dm_device_state_manager_two") { "mock/softbus_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1300,6 +1382,7 @@ ohos_unittest("UTTest_dm_device_state_manager_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1320,6 +1403,7 @@ ohos_unittest("UTTest_dm_dfx") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1338,7 +1422,10 @@ ohos_unittest("UTTest_device_manager_service_impl") { "mock/softbus_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1352,6 +1439,7 @@ ohos_unittest("UTTest_device_manager_service_impl") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1368,7 +1456,10 @@ ohos_unittest("UTTest_device_manager_service_impl_first") { "mock/multiple_user_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1382,6 +1473,7 @@ ohos_unittest("UTTest_device_manager_service_impl_first") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1397,10 +1489,13 @@ ohos_unittest("UTTest_device_manager_service_listener") { "mock/dm_crypto_mock.cpp", "mock/dm_softbus_cache_mock.cpp", "mock/ipc_server_listener_mock.cpp", + "mock/ipc_server_stub_mock.cpp", "mock/kv_adapter_manager_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1408,9 +1503,11 @@ ohos_unittest("UTTest_device_manager_service_listener") { "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "ffrt:libffrt", "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1436,6 +1533,7 @@ ohos_unittest("UTTest_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1447,7 +1545,10 @@ ohos_unittest("UTTest_auth_response_state") { sources = [ "UTTest_auth_response_state.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1457,6 +1558,7 @@ ohos_unittest("UTTest_auth_response_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1468,7 +1570,10 @@ ohos_unittest("UTTest_auth_request_state") { sources = [ "UTTest_auth_request_state.cpp" ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -1478,6 +1583,7 @@ ohos_unittest("UTTest_auth_request_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1495,6 +1601,7 @@ ohos_unittest("ipc_client_manager_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1529,6 +1636,7 @@ ohos_unittest("UTTest_dm_auth_manager_first") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -1571,6 +1679,7 @@ ohos_unittest("UTTest_dm_auth_manager_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1595,6 +1704,7 @@ ohos_unittest("UTTest_dm_auth_manager_third") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -1629,6 +1739,7 @@ ohos_unittest("UTTest_dm_radar_helper_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1654,6 +1765,7 @@ ohos_unittest("UTTest_discovery_filter") { "device_info_manager:distributed_device_profile_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1669,7 +1781,10 @@ ohos_unittest("UTTest_discovery_manager") { "${devicemanager_path}/test/commonunittest/UTTest_discovery_manager.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "cJSON:cjson", @@ -1681,6 +1796,7 @@ ohos_unittest("UTTest_discovery_manager") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1703,7 +1819,10 @@ ohos_unittest("UTTest_dm_deviceprofile_connector") { "${devicemanager_path}/test/unittest/mock/multiple_user_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_info_manager:distributed_device_profile_common", @@ -1712,6 +1831,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1741,6 +1861,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1765,6 +1886,7 @@ ohos_unittest("UTTest_dm_distributed_hardware_load") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1788,6 +1910,7 @@ ohos_unittest("UTTest_dm_comm_tool") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1806,6 +1929,7 @@ ohos_unittest("UTTest_dm_crypto") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1823,7 +1947,10 @@ ohos_unittest("UTTest_dm_account_common_event") { deps = [ ":device_manager_test_common" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "hilog:libhilog", + "safwk:system_ability_fwk", + ] } ## UnitTest UTTest_dm_account_common_event }}} @@ -1844,6 +1971,7 @@ ohos_unittest("UTTest_dm_publish_common_event") { "bluetooth:btframework", "hilog:libhilog", "wifi:wifi_sdk", + "safwk:system_ability_fwk", ] } @@ -1865,6 +1993,7 @@ ohos_unittest("UTTest_dm_screen_common_event") { "bluetooth:btframework", "hilog:libhilog", "wifi:wifi_sdk", + "safwk:system_ability_fwk", ] } @@ -1885,6 +2014,7 @@ ohos_unittest("UTTest_relationship_sync_mgr") { "cJSON:cjson", "ffrt:libffrt", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1901,7 +2031,10 @@ ohos_unittest("UTTest_hichain_listener") { deps = [ ":device_manager_test_common" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "hilog:libhilog", + "safwk:system_ability_fwk", + ] } ## UnitTest UTTest_hichain_listener }}} @@ -1935,6 +2068,7 @@ ohos_unittest("UTTest_dp_inited_callback") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1961,6 +2095,7 @@ ohos_unittest("UTTest_kv_adapter_manager") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1995,6 +2130,7 @@ ohos_unittest("UTTest_app_manager") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -2013,7 +2149,10 @@ ohos_unittest("UTTest_crypto_mgr") { deps = [ ":device_manager_test_common" ] - external_deps = [ "hilog:libhilog" ] + external_deps = [ + "hilog:libhilog", + "safwk:system_ability_fwk", + ] } ## UnitTest UTTest_crypto_mgr }}} @@ -2045,6 +2184,7 @@ ohos_unittest("UTTest_device_name_manager") { "hilog:libhilog", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "safwk:system_ability_fwk", ] } @@ -2075,6 +2215,7 @@ ohos_unittest("UTTest_advertise_manager") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2095,6 +2236,7 @@ ohos_unittest("UTTest_mini_tools_kit") { "ffrt:libffrt", "googletest:gmock", "googletest:gmock_main", + "safwk:system_ability_fwk", "selinux_adapter:librestorecon", ] } @@ -2114,6 +2256,7 @@ ohos_unittest("UTTest_json_object") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2132,7 +2275,10 @@ ohos_unittest("UTTest_auth_pin_auth_state") { "${devicemanager_path}/test/unittest/mock/hichain_auth_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -2143,6 +2289,7 @@ ohos_unittest("UTTest_auth_pin_auth_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2170,6 +2317,7 @@ ohos_unittest("UTTest_dm_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2190,7 +2338,10 @@ ohos_unittest("UTTest_auth_credential_state") { "${devicemanager_path}/test/unittest/mock/softbus_session_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -2201,6 +2352,7 @@ ohos_unittest("UTTest_auth_credential_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2221,7 +2373,10 @@ ohos_unittest("UTTest_auth_acl") { "${devicemanager_path}/test/unittest/mock/softbus_session_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -2232,6 +2387,7 @@ ohos_unittest("UTTest_auth_acl") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2252,7 +2408,10 @@ ohos_unittest("UTTest_auth_negotiate") { "${devicemanager_path}/test/unittest/mock/distributed_device_profile_client_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -2266,6 +2425,7 @@ ohos_unittest("UTTest_auth_negotiate") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2283,7 +2443,10 @@ ohos_unittest("UTTest_auth_manager") { "${devicemanager_path}/test/unittest/mock/distributed_device_profile_client_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "access_token:libaccesstoken_sdk", @@ -2297,6 +2460,7 @@ ohos_unittest("UTTest_auth_manager") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2315,7 +2479,10 @@ ohos_unittest("UTTest_auth_confirm") { "${devicemanager_path}/test/unittest/mock/hichain_auth_connector_mock.cpp", ] - deps = [ ":device_manager_test_common" ] + deps = [ + ":device_manager_test_common", + "${devicemanager_path}/interfaces/inner_kits/native_cpp:device_manager_ipc", + ] external_deps = [ "device_auth:deviceauth_sdk", @@ -2326,6 +2493,7 @@ ohos_unittest("UTTest_auth_confirm") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2470,3 +2638,24 @@ ohos_unittest("UTTest_freeze_process") { } ## UnitTest UTTest_freeze_process }}} + +## UnitTest UTTest_device_manager_notify_service {{{ +ohos_unittest("UTTest_device_manager_notify_service") { + module_out_path = module_out_path + + sources = [ + "UTTest_device_manager_notify_service.cpp", + ] + + deps = [ ":device_manager_test_common" ] + + external_deps = [ + "device_auth:deviceauth_sdk", + "ffrt:libffrt", + "googletest:gmock", + "hilog:libhilog", + "safwk:system_ability_fwk", + ] +} + +## UnitTest UTTest_device_manager_notify_service }}} \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_notify_service.cpp b/test/unittest/UTTest_device_manager_notify_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a701e56f6aea16e0f19764184fe4accf9b7a360c --- /dev/null +++ b/test/unittest/UTTest_device_manager_notify_service.cpp @@ -0,0 +1,596 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_device_manager_notify_service.h" +#include "device_manager_notify_service.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr int32_t DM_OK = 0; +void DeviceManagerNotifyServiceTest::SetUp() {} + +void DeviceManagerNotifyServiceTest::TearDown() {} + +void DeviceManagerNotifyServiceTest::SetUpTestCase() {} + +void DeviceManagerNotifyServiceTest::TearDownTestCase() {} +namespace { +/** + * @tc.name: ServerDeviceStateNotify_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDeviceStateNotify_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t deviceState1 = DEVICE_STATE_ONLINE; + int32_t deviceState2 = DEVICE_STATE_OFFLINE; + int32_t deviceState3 = DEVICE_INFO_CHANGED; + int32_t deviceState4 = DEVICE_INFO_READY; + int32_t deviceState5 = 9999; + + DmDeviceInfoExt dmDeviceInfoExt; + strcpy_s(dmDeviceInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "test_device_001"); + strcpy_s(dmDeviceInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "TestDevice"); + strcpy_s(dmDeviceInfoExt.networkId, sizeof(dmDeviceInfoExt.networkId), "network_001"); + + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + strcpy_s(dmDeviceBasicInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "test_device_001"); + strcpy_s(dmDeviceBasicInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "TestDevice"); + strcpy_s(dmDeviceBasicInfoExt.networkId, sizeof(dmDeviceBasicInfoExt.networkId), "network_001"); + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result1 = DeviceManagerNotifyService::GetInstance().ServerDeviceStateNotify( + pkgName, deviceState1, dmDeviceInfoExt, dmDeviceBasicInfoExt); + ErrCode result2 = DeviceManagerNotifyService::GetInstance().ServerDeviceStateNotify( + pkgName, deviceState2, dmDeviceInfoExt, dmDeviceBasicInfoExt); + ErrCode result3 = DeviceManagerNotifyService::GetInstance().ServerDeviceStateNotify( + pkgName, deviceState3, dmDeviceInfoExt, dmDeviceBasicInfoExt); + ErrCode result4 = DeviceManagerNotifyService::GetInstance().ServerDeviceStateNotify( + pkgName, deviceState4, dmDeviceInfoExt, dmDeviceBasicInfoExt); + ErrCode result5 = DeviceManagerNotifyService::GetInstance().ServerDeviceStateNotify( + pkgName, deviceState5, dmDeviceInfoExt, dmDeviceBasicInfoExt); + + EXPECT_EQ(result1, 0); + EXPECT_EQ(result2, 0); + EXPECT_EQ(result3, 0); + EXPECT_EQ(result4, 0); + EXPECT_EQ(result5, 0); +} +/** + * @tc.name: ServerDeviceFound_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDeviceFound_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + uint16_t subscribeId = 123; + + DmDeviceInfoExt dmDeviceInfoExt; + strcpy_s(dmDeviceInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "found_device_001"); + strcpy_s(dmDeviceInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "FoundDevice1"); + strcpy_s(dmDeviceInfoExt.networkId, sizeof(dmDeviceInfoExt.networkId), "found_network_001"); + + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + strcpy_s(dmDeviceBasicInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "found_device_001"); + strcpy_s(dmDeviceBasicInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "FoundDevice1"); + strcpy_s(dmDeviceBasicInfoExt.networkId, sizeof(dmDeviceBasicInfoExt.networkId), "found_network_001"); + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDeviceFound( + pkgName, subscribeId, dmDeviceInfoExt, dmDeviceBasicInfoExt); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerDeviceDiscovery_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDeviceDiscovery_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + uint16_t subscribeId = 123; + + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + strcpy_s(dmDeviceBasicInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "found_device_001"); + strcpy_s(dmDeviceBasicInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "FoundDevice1"); + strcpy_s(dmDeviceBasicInfoExt.networkId, sizeof(dmDeviceBasicInfoExt.networkId), "found_network_001"); + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDeviceDiscovery( + pkgName, subscribeId, dmDeviceBasicInfoExt); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerDiscoverFinish_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDiscoverFinish_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + uint16_t subscribeId = 123; + int32_t failedRefason1 = DM_OK; + int32_t failedRefason2 = -1; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result1 = DeviceManagerNotifyService::GetInstance().ServerDiscoverFinish( + pkgName, subscribeId, failedRefason1); + ErrCode result2 = DeviceManagerNotifyService::GetInstance().ServerDiscoverFinish( + pkgName, subscribeId, failedRefason2); + + EXPECT_EQ(result1, 0); + EXPECT_EQ(result2, 0); +} +/** + * @tc.name: ServerPublishFinish_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerPublishFinish_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + uint16_t subscribeId = 456; + int32_t publishResult = DM_OK; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerPublishFinish( + pkgName, subscribeId, publishResult); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerAuthResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerAuthResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "test_device_001"; + std::string token = "auth_token_001"; + int32_t status = 0; + int32_t reason = 0; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerAuthResult( + pkgName, deviceId, token, status, reason); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerDeviceFaNotify_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDeviceFaNotify_001, testing::ext::TestSize.Level0) +{ + std::string packagename = "com.ohos.test"; + std::string paramJson = "{\"action\":\"AUTH_REQUEST\",\"deviceId\":\"test_device_001\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(packagename, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDeviceFaNotify( + packagename, paramJson); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerCredentialResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerCredentialResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t action = 1; + std::string credentialResult = "{\"result\":\"SUCCESS\",\"credentialId\":\"cred_001\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerCredentialResult( + pkgName, action, credentialResult); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerCreatePinHolder_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerCreatePinHolder_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "test_device_001"; + int32_t pinType = 1; + std::string payload = "{\"pinCode\":\"123456\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerCreatePinHolder( + pkgName, deviceId, pinType, payload); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerDestroyPinHolder_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDestroyPinHolder_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t pinType = 1; + std::string payload = "{\"reason\":\"timeout\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDestroyPinHolder( + pkgName, pinType, payload); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerCreatePinHolderResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerCreatePinHolderResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t ret1 = 0; + int32_t ret2 = -1; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result1 = DeviceManagerNotifyService::GetInstance().ServerCreatePinHolderResult( + pkgName, ret1); + ErrCode result2 = DeviceManagerNotifyService::GetInstance().ServerCreatePinHolderResult( + pkgName, ret2); + + + EXPECT_EQ(result1, 0); + EXPECT_EQ(result2, 0); +} +/** + * @tc.name: ServerDesTroyPinHolderResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDesTroyPinHolderResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t ret = 0; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDesTroyPinHolderResult( + pkgName, ret); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerOnPinHolderEvent_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerOnPinHolderEvent_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t ret = 0; + int32_t pinHolderEvent = 1; + std::string content = "{\"event\":\"PIN_CREATED\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerOnPinHolderEvent( + pkgName, ret, pinHolderEvent, content); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: BindTargetResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, BindTargetResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + PeerTargetIdExt targetIdExt; + targetIdExt.deviceId = "target_device_001"; + targetIdExt.brMac = "AA:BB:CC:DD:EE:FF"; + targetIdExt.bleMac = "11:22:33:44:55:66"; + targetIdExt.wifiIp = "192.168.1.100"; + targetIdExt.wifiPort = 8080; + + int32_t ret = 0; + int32_t status = 1; + std::string content = "{\"bind\":\"success\"}"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().BindTargetResult( + pkgName, targetIdExt, ret, status, content); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: UnbindTargetResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, UnbindTargetResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + PeerTargetIdExt targetIdExt; + targetIdExt.deviceId = "target_device_001"; + targetIdExt.brMac = "AA:BB:CC:DD:EE:FF"; + targetIdExt.bleMac = "11:22:33:44:55:66"; + targetIdExt.wifiIp = "192.168.1.101"; + targetIdExt.wifiPort = 8081; + + int32_t ret = 0; + std::string content = "{\"unbind\":\"success\"}"; + + ErrCode result = DeviceManagerNotifyService::GetInstance().UnbindTargetResult( + pkgName, targetIdExt, ret, content); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: RemoteDeviceTrustChange_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, RemoteDeviceTrustChange_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string udid = "test_udid_001"; + int32_t authForm = 1; + std::string uuid = "test_uuid_001"; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().RemoteDeviceTrustChange( + pkgName, udid, authForm, uuid); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerDeviceScreenStateNotify_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerDeviceScreenStateNotify_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + + DmDeviceInfoExt dmDeviceInfoExt; + strcpy_s(dmDeviceInfoExt.deviceId, DM_MAX_DEVICE_ID_LEN, "screen_device_001"); + strcpy_s(dmDeviceInfoExt.deviceName, DM_MAX_DEVICE_NAME_LEN, "ScreenDevice"); + strcpy_s(dmDeviceInfoExt.networkId, sizeof(dmDeviceInfoExt.networkId), "screen_network_001"); + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerDeviceScreenStateNotify( + pkgName, dmDeviceInfoExt); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: ServerCredentialAuthStatusNotify_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, ServerCredentialAuthStatusNotify_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceList = "[\"device_001\",\"device_002\"]"; + uint16_t deviceTypeId = 1; + int32_t err = 0; + + std::shared_ptr callback = std::make_shared(); + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + + ErrCode result = DeviceManagerNotifyService::GetInstance().ServerCredentialAuthStatusNotify( + pkgName, deviceList, deviceTypeId, err); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: SinkBindTargetResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, SinkBindTargetResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + PeerTargetIdExt targetIdExt; + targetIdExt.deviceId = "sink_device_001"; + targetIdExt.brMac = "AA:BB:CC:DD:EE:FF"; + targetIdExt.bleMac = "11:22:33:44:55:66"; + targetIdExt.wifiIp = "192.168.1.102"; + targetIdExt.wifiPort = 8082; + + int32_t ret = 0; + int32_t status = 1; + std::string content = "{\"sink_bind\":\"success\"}"; + + ErrCode result = DeviceManagerNotifyService::GetInstance().SinkBindTargetResult( + pkgName, targetIdExt, ret, status, content); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: GetDeviceProfileInfoListResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, GetDeviceProfileInfoListResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t code = 0; + std::vector deviceProfileInfosExt; + + DmDeviceProfileInfoExt profileInfo; + profileInfo.deviceId = "profile_device_001"; + profileInfo.deviceName = "ProfileDevice"; + deviceProfileInfosExt.push_back(profileInfo); + + ErrCode result = DeviceManagerNotifyService::GetInstance().GetDeviceProfileInfoListResult( + pkgName, code, deviceProfileInfosExt); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: GetDeviceIconInfoResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, GetDeviceIconInfoResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t code = 0; + + DmDeviceIconInfoExt deviceIconInfoExt; + + ErrCode result = DeviceManagerNotifyService::GetInstance().GetDeviceIconInfoResult( + pkgName, code, deviceIconInfoExt); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: SetRemoteDeviceNameResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, SetRemoteDeviceNameResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "remote_device_001"; + int32_t code = 0; + + ErrCode result = DeviceManagerNotifyService::GetInstance().SetRemoteDeviceNameResult( + pkgName, deviceId, code); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: SetLocalDeviceNameResult_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, SetLocalDeviceNameResult_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t code = 0; + + ErrCode result = DeviceManagerNotifyService::GetInstance().SetLocalDeviceNameResult( + pkgName, code); + + EXPECT_EQ(result, 0); +} +/** + * @tc.name: Int32ToDmPinType_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, Int32ToDmPinType_001, testing::ext::TestSize.Level0) +{ + int32_t value1 = static_cast(DmPinType::NUMBER_PIN_CODE); + DmPinType result1 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinType(value1); + EXPECT_EQ(result1, DmPinType::NUMBER_PIN_CODE); + + int32_t value2 = static_cast(DmPinType::QR_CODE); + DmPinType result2 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinType(value2); + EXPECT_EQ(result2, DmPinType::QR_CODE); + + int32_t value3 = static_cast(DmPinType::VISIBLE_LLIGHT); + DmPinType result3 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinType(value3); + EXPECT_EQ(result3, DmPinType::VISIBLE_LLIGHT); + + int32_t value4 = static_cast(DmPinType::SUPER_SONIC); + DmPinType result4 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinType(value4); + EXPECT_EQ(result4, DmPinType::SUPER_SONIC); + + int32_t value5 = 9999; + DmPinType result5 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinType(value5); + EXPECT_EQ(result5, static_cast(-1)); +} +/** + * @tc.name: Int32ToDmPinHolderEvent_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, Int32ToDmPinHolderEvent_001, testing::ext::TestSize.Level0) +{ + int32_t value1 = static_cast(DmPinHolderEvent::CREATE); + DmPinHolderEvent result1 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value1); + EXPECT_EQ(result1, DmPinHolderEvent::CREATE); + + int32_t value2 = static_cast(DmPinHolderEvent::CREATE_RESULT); + DmPinHolderEvent result2 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value2); + EXPECT_EQ(result2, DmPinHolderEvent::CREATE_RESULT); + + int32_t value3 = static_cast(DmPinHolderEvent::DESTROY); + DmPinHolderEvent result3 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value3); + EXPECT_EQ(result3, DmPinHolderEvent::DESTROY); + + int32_t value4 = static_cast(DmPinHolderEvent::DESTROY_RESULT); + DmPinHolderEvent result4 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value4); + EXPECT_EQ(result4, DmPinHolderEvent::DESTROY_RESULT); + + int32_t value5 = static_cast(DmPinHolderEvent::PIN_TYPE_CHANGE); + DmPinHolderEvent result5 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value5); + EXPECT_EQ(result5, DmPinHolderEvent::PIN_TYPE_CHANGE); + + int32_t value6 = static_cast(DmPinHolderEvent::PIN_TYPE_CHANGE_RESULT); + DmPinHolderEvent result6 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value6); + EXPECT_EQ(result6, DmPinHolderEvent::PIN_TYPE_CHANGE_RESULT); + + int32_t value7 = 9999; + DmPinHolderEvent result7 = DeviceManagerNotifyService::GetInstance().Int32ToDmPinHolderEvent(value7); + EXPECT_EQ(result7, static_cast(-1)); +} +/** + * @tc.name: Int32ToDmAuthForm_001 + * @tc.type: FUNC + */ +HWTEST_F(DeviceManagerNotifyServiceTest, Int32ToDmAuthForm_001, testing::ext::TestSize.Level0) +{ + int32_t value1 = static_cast(DmAuthForm::INVALID_TYPE); + DmAuthForm result1 = DeviceManagerNotifyService::GetInstance().Int32ToDmAuthForm(value1); + EXPECT_EQ(result1, DmAuthForm::INVALID_TYPE); + + int32_t value2 = static_cast(DmAuthForm::PEER_TO_PEER); + DmAuthForm result2 = DeviceManagerNotifyService::GetInstance().Int32ToDmAuthForm(value2); + EXPECT_EQ(result2, DmAuthForm::PEER_TO_PEER); + + int32_t value3 = static_cast(DmAuthForm::IDENTICAL_ACCOUNT); + DmAuthForm result3 = DeviceManagerNotifyService::GetInstance().Int32ToDmAuthForm(value3); + EXPECT_EQ(result3, DmAuthForm::IDENTICAL_ACCOUNT); + + int32_t value4 = static_cast(DmAuthForm::ACROSS_ACCOUNT); + DmAuthForm result4 = DeviceManagerNotifyService::GetInstance().Int32ToDmAuthForm(value4); + EXPECT_EQ(result4, DmAuthForm::ACROSS_ACCOUNT); + + int32_t value5 = 9999; + DmAuthForm result5 = DeviceManagerNotifyService::GetInstance().Int32ToDmAuthForm(value5); + EXPECT_EQ(result5, static_cast(-1)); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_notify_service.h b/test/unittest/UTTest_device_manager_notify_service.h new file mode 100644 index 0000000000000000000000000000000000000000..8cd2f4f018efbe9b82087b3c9b7601b8b9ce7b75 --- /dev/null +++ b/test/unittest/UTTest_device_manager_notify_service.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DEVICE_MANAGER_NOTIFY_SERVICE_TEST_H +#define OHOS_DEVICE_MANAGER_NOTIFY_SERVICE_TEST_H + +#include + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" +#include "device_manager_callback.h" +#include "dm_single_instance.h" +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotifyServiceTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +class DeviceStateCallbackTest : public DeviceStateCallback { +public: + DeviceStateCallbackTest() : DeviceStateCallback() {} + virtual ~DeviceStateCallbackTest() {} + void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override {} + void OnDeviceReady(const DmDeviceInfo &deviceInfo) override {} + void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override {} + void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override {} +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DEVICE_MANAGER_NOTIFY_SERVICE_TEST_H diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index ff761bb5399e6cb47271deaaf5f4f7e0d605c6eb..1b1b7d200be247f8ad8e567cdefabb2bd5030e0b 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -46,9 +46,9 @@ void DeviceManagerServiceListenerTest::SetUpTestCase() { DmSoftbusCache::dmSoftbusCache = softbusCacheMock_; DmCrypto::dmCrypto = cryptoMock_; - DmIpcServerListener::dmIpcServerListener = ipcServerListenerMock_; DmKVAdapterManager::dmKVAdapterManager = kVAdapterManagerMock_; DmAppManager::dmAppManager = appManagerMock_; + DmIpcServerStub::dmIpcServerStub = ipcServerStubMock_; } void DeviceManagerServiceListenerTest::TearDownTestCase() @@ -57,14 +57,13 @@ void DeviceManagerServiceListenerTest::TearDownTestCase() softbusCacheMock_ = nullptr; DmCrypto::dmCrypto = nullptr; cryptoMock_ = nullptr; - DmIpcServerListener::dmIpcServerListener = nullptr; - ipcServerListenerMock_ = nullptr; DmKVAdapterManager::dmKVAdapterManager = nullptr; kVAdapterManagerMock_ = nullptr; DmAppManager::dmAppManager = nullptr; appManagerMock_ = nullptr; + DmIpcServerStub::dmIpcServerStub = nullptr; + ipcServerStubMock_ = nullptr; } - namespace { /** * @tc.name: OnDeviceStateChange_001 @@ -193,6 +192,34 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceFound_001, testing::ext::Test uint16_t subscribeId = 1; EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDeviceFound(processInfo, subscribeId, info); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnDeviceFound_002 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId, info + * deviceId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceFound_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + processInfo.userId = 100; + DmDeviceInfo info = { + .deviceId = "dkdkd", + .deviceName = "asda", + .deviceTypeId = 1, + }; + uint16_t subscribeId = 1; + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDeviceFound(processInfo, subscribeId, info); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -212,6 +239,27 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoveryFailed_001, testing::ext:: processInfo.pkgName = pkgName; uint16_t subscribeId = 1; int32_t failedReason = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDiscoveryFailed(processInfo, subscribeId, failedReason); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnDiscoveryFailed_002 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId, failedReason + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoveryFailed_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + std::string deviceId = "dkdkd"; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + uint16_t subscribeId = 1; + int32_t failedReason = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDiscoveryFailed(processInfo, subscribeId, failedReason); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -229,6 +277,25 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoverySuccess_001, testing::ext: uint16_t subscribeId = 1; ProcessInfo processInfo; processInfo.pkgName = pkgName; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDiscoverySuccess(processInfo, subscribeId); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnDiscoverySuccess_002 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoverySuccess_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + uint16_t subscribeId = 1; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDiscoverySuccess(processInfo, subscribeId); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -246,6 +313,9 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPublishResult_001, testing::ext::Te std::string deviceId = "dkdkd"; int32_t publishId = 1; int32_t failedReason = 1; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnPublishResult(pkgName, publishId, failedReason); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -262,6 +332,28 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPublishResult_002, testing::ext::Te std::string pkgName = "com.ohos.helloworld"; int32_t publishId = 1; int32_t failedReason = 0; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnPublishResult(pkgName, publishId, failedReason); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnPublishResult_003 + * @tc.desc: OnDeviceResult,construct a dummy listener, pass in pkgName, publishId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnPublishResult_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + int32_t publishId = 1; + int32_t failedReason = 0; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnPublishResult(pkgName, publishId, failedReason); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -279,6 +371,25 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnUiCall_001, testing::ext::TestSize. ProcessInfo processInfo; processInfo.pkgName = "com.ohos.helloworld"; processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnUiCall(processInfo, paramJson); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnUiCall_002 + * @tc.desc: OnUiCall, construct a dummy listener, pass in pkgName, paramJson + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnUiCall_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string paramJson = "ahaha"; + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnUiCall(processInfo, paramJson); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -296,6 +407,25 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnCredentialResult_001, testing::ext: processInfo.pkgName = pkgName; int32_t action = 1; std::string resultInfo = "resultInfo"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnCredentialResult(processInfo, action, resultInfo); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnCredentialResult_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnCredentialResult_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + ProcessInfo processInfo; + processInfo.pkgName = pkgName; + int32_t action = 1; + std::string resultInfo = "resultInfo"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnCredentialResult(processInfo, action, resultInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -315,6 +445,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_001, testing::ext::TestS ProcessInfo processInfo; processInfo.pkgName = "com.ohos.helloworld"; processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnBindResult(processInfo, targetId, result, status, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -334,6 +465,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_002, testing::ext::TestS ProcessInfo processInfo; processInfo.pkgName = "com.ohos.helloworld"; processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnBindResult(processInfo, targetId, result, status, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -353,6 +485,27 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_003, testing::ext::TestS ProcessInfo processInfo; processInfo.pkgName = "com.ohos.helloworld"; processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnBindResult(processInfo, targetId, result, status, content); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnBindResult_005 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnBindResult_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + PeerTargetId targetId; + int32_t result = 0; + int32_t status = 1; + std::string content = "content"; + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnBindResult(processInfo, targetId, result, status, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -371,6 +524,26 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnUnbindResult_001, testing::ext::Tes ProcessInfo processInfo; processInfo.pkgName = "com.ohos.helloworld"; processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnUnbindResult(processInfo, targetId, result, content); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnUnbindResult_003 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnUnbindResult_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + PeerTargetId targetId; + int32_t result = 0; + std::string content = "content"; + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnUnbindResult(processInfo, targetId, result, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -408,6 +581,26 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderCreate_001, testing::ext:: ProcessInfo processInfo; processInfo.userId = 100; processInfo.pkgName = "com.ohos.helloworld"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnPinHolderCreate(processInfo, deviceId, pinType, payload); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnPinHolderCreate_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderCreate_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string deviceId = "153123"; + DmPinType pinType = static_cast(1); + std::string payload = "payload"; + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnPinHolderCreate(processInfo, deviceId, pinType, payload); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -425,6 +618,25 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderDestroy_001, testing::ext: processInfo.pkgName = "com.ohos.helloworld"; DmPinType pinType = static_cast(1); std::string payload = "payload"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnPinHolderDestroy(processInfo, pinType, payload); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnPinHolderDestroy_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderDestroy_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + DmPinType pinType = static_cast(1); + std::string payload = "payload"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnPinHolderDestroy(processInfo, pinType, payload); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -441,6 +653,24 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnCreateResult_001, testing::ext::Tes processInfo.userId = 100; processInfo.pkgName = "com.ohos.helloworld"; int32_t result = 0; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnCreateResult(processInfo, result); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnCreateResult_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnCreateResult_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + int32_t result = 0; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnCreateResult(processInfo, result); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -457,6 +687,24 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDestroyResult_001, testing::ext::Te processInfo.userId = 100; processInfo.pkgName = "com.ohos.helloworld"; int32_t result = 0; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDestroyResult(processInfo, result); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnDestroyResult_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDestroyResult_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + int32_t result = 0; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDestroyResult(processInfo, result); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -475,6 +723,26 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderEvent_001, testing::ext::T DmPinHolderEvent event = DmPinHolderEvent::CREATE_RESULT; int32_t result = 0; std::string content = "content"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnPinHolderEvent(processInfo, event, result, content); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +/** + * @tc.name: OnPinHolderEvent_002 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnPinHolderEvent_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + DmPinHolderEvent event = DmPinHolderEvent::CREATE_RESULT; + int32_t result = 0; + std::string content = "content"; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnPinHolderEvent(processInfo, event, result, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -493,6 +761,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceScreenStateChange_001, testin DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfoTmp); EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnDeviceScreenStateChange(processInfo, devInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); @@ -506,10 +775,30 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceScreenStateChange_001, testin processInfos.push_back(processInfo1); std::set systemSA; systemSA.insert("pkgName"); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDeviceScreenStateChange(processInfo, devInfo); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceScreenStateChange_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.userId = 100; + processInfo.pkgName = "com.ohos.helloworld"; + DmDeviceInfo devInfo; + ProcessInfo processInfoTmp; + processInfoTmp.pkgName = "ohos.deviceprofile"; + processInfoTmp.userId = 106; + int32_t dmCommonNotifyEvent = 3; + DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfoTmp); + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDeviceScreenStateChange(processInfo, devInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -541,7 +830,8 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnSinkBindResult_001, testing::ext::T EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyDeviceId(_, _, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); std::vector processInfos; - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnSinkBindResult(processInfo, targetId, result, status, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -556,6 +846,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnProcessRemove_001, testing::ext::Te listener_->alreadyOnlinePkgName_["com.ohos.helloworld#100"] = dmDeviceInfo; DmDeviceInfo dmDeviceInfo1; listener_->alreadyOnlinePkgName_["com.ohos.network"] = dmDeviceInfo; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnProcessRemove(processInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -611,10 +902,12 @@ HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceStateChange_001, testing DmDeviceState state = DmDeviceState::DEVICE_STATE_ONLINE; DmDeviceInfo info; DmDeviceBasicInfo deviceBasicInfo; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->ProcessDeviceStateChange(processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); state = DmDeviceState::DEVICE_INFO_CHANGED; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->ProcessDeviceStateChange(processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -633,11 +926,12 @@ HWTEST_F(DeviceManagerServiceListenerTest, ProcessAppStateChange_001, testing::e ProcessInfo processInfo1; processInfo1.pkgName = "_pickerProxy_" + processInfo.pkgName; allProcessInfos.push_back(processInfo1); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(allProcessInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(allProcessInfos)); EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(4)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)) .Times(::testing::AtLeast(4)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->ProcessAppStateChange(processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -686,25 +980,13 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceTrustChange_001, testing::ext processInfos.push_back(processInfo); std::set systemSA; systemSA.insert("pkgName"); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnDeviceTrustChange(udid, uuid, authForm); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } -HWTEST_F(DeviceManagerServiceListenerTest, SetDeviceScreenInfo_001, testing::ext::TestSize.Level1) -{ - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr pReq = std::make_shared(); - ProcessInfo processInfo; - DmDeviceInfo deviceInfo; - processInfo.pkgName = "pkgName"; - EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - listener_->SetDeviceScreenInfo(pReq, processInfo, deviceInfo); - EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); -} - HWTEST_F(DeviceManagerServiceListenerTest, RemoveOnlinePkgName_001, testing::ext::TestSize.Level1) { std::shared_ptr listener_ = std::make_shared(); @@ -746,8 +1028,9 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnCredentialAuthStatus_002, testing:: processInfos.push_back(processInfo1); std::set systemSA; systemSA.insert("pkgName"); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo1)).WillOnce(Return(nullptr)); listener_->OnCredentialAuthStatus(processInfo, deviceList, deviceTypeId, errcode); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -795,8 +1078,8 @@ HWTEST_F(DeviceManagerServiceListenerTest, GetNotifyProcessInfoByUserId_001, tes processInfos.push_back(processInfo); std::set systemSA; systemSA.insert("pkgName"); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); ret = listener_->GetNotifyProcessInfoByUserId(userId, dmCommonNotifyEvent); EXPECT_EQ(ret.empty(), false); @@ -805,8 +1088,8 @@ HWTEST_F(DeviceManagerServiceListenerTest, GetNotifyProcessInfoByUserId_001, tes processInfo.pkgName = "packName"; processInfos.push_back(processInfo); systemSA.insert("packName"); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); ret = listener_->GetNotifyProcessInfoByUserId(userId, dmCommonNotifyEvent); EXPECT_EQ(ret.empty(), true); @@ -816,14 +1099,14 @@ HWTEST_F(DeviceManagerServiceListenerTest, GetNotifyProcessInfoByUserId_001, tes processInfo1.userId = 102; processInfos.push_back(processInfo1); userId = 102; - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); ret = listener_->GetNotifyProcessInfoByUserId(userId, dmCommonNotifyEvent); EXPECT_EQ(ret.empty(), true); DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmNotifyEvent, processInfo1); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); ret = listener_->GetNotifyProcessInfoByUserId(userId, dmCommonNotifyEvent); EXPECT_EQ(ret.empty(), false); } @@ -835,7 +1118,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, DealBindProcessInfo_001, testing::ext processInfo.pkgName = "pkgName"; std::set systemSA; systemSA.insert("pkgName"); - EXPECT_CALL(*ipcServerListenerMock_, GetSystemSA()).WillOnce(Return(systemSA)); + EXPECT_CALL(*ipcServerStubMock_, GetSystemSA()).WillOnce(Return(systemSA)); ProcessInfo pro = listener_->DealBindProcessInfo(processInfo); EXPECT_EQ(pro.pkgName, "pkgName"); } @@ -855,9 +1138,27 @@ HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceOnline_001, testing::ext EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(4)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)) .Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(nullptr)); + listener_->ProcessDeviceOnline(procInfoVec, processInfo, state, info, deviceBasicInfo); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(nullptr)); listener_->ProcessDeviceOnline(procInfoVec, processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} +HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceOnline_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::vector procInfoVec; + ProcessInfo pro; + pro.pkgName = "pkgName"; + pro.userId = 101; + procInfoVec.push_back(pro); + ProcessInfo processInfo; + DmDeviceState state = DmDeviceState::DEVICE_INFO_CHANGED; + DmDeviceInfo info; + DmDeviceBasicInfo deviceBasicInfo; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(deviceManagerIpc)); listener_->ProcessDeviceOnline(procInfoVec, processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -876,6 +1177,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceOffline_001, testing::ex DmDeviceBasicInfo deviceBasicInfo; std::string notifyPkgName = pro.pkgName + "#" + std::to_string(pro.userId) + "#" + std::string(info.deviceId); listener_->alreadyOnlinePkgName_[notifyPkgName] = info; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(nullptr)); listener_->ProcessDeviceOffline(procInfoVec, processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } @@ -895,10 +1197,48 @@ HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceInfoChange_001, testing: EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)) .Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(nullptr)); listener_->ProcessDeviceInfoChange(procInfoVec, processInfo, state, info, deviceBasicInfo); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); } +HWTEST_F(DeviceManagerServiceListenerTest, ProcessDeviceInfoChange_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::vector procInfoVec; + ProcessInfo pro; + pro.pkgName = "pkgName"; + pro.userId = 101; + procInfoVec.push_back(pro); + ProcessInfo processInfo; + DmDeviceState state = DmDeviceState::DEVICE_INFO_CHANGED; + DmDeviceInfo info; + DmDeviceBasicInfo deviceBasicInfo; + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)) + .Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(deviceManagerIpc)); + listener_->ProcessDeviceInfoChange(procInfoVec, processInfo, state, info, deviceBasicInfo); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), true); +} + +HWTEST_F(DeviceManagerServiceListenerTest, ProcessAppOnline_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::vector procInfoVec; + ProcessInfo pro; + pro.pkgName = "pkgName"; + pro.userId = 101; + procInfoVec.push_back(pro); + ProcessInfo processInfo; + DmDeviceState state = DmDeviceState::DEVICE_INFO_CHANGED; + DmDeviceInfo info; + DmDeviceBasicInfo deviceBasicInfo; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(pro)).WillOnce(Return(deviceManagerIpc)); + listener_->ProcessAppOnline(procInfoVec, processInfo, state, info, deviceBasicInfo); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + HWTEST_F(DeviceManagerServiceListenerTest, ProcessAppOffline_001, testing::ext::TestSize.Level1) { std::shared_ptr listener_ = std::make_shared(); @@ -943,11 +1283,37 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDevStateCallbackAdd_001, testing::e deviceList.push_back(info); EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDevStateCallbackAdd(processInfo, deviceList); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); + + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnDevStateCallbackAdd(processInfo, deviceList); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnDevStateCallbackAdd_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.pkgName = "pkgNamewer"; + processInfo.userId = 110; + std::vector deviceList; + DmDeviceInfo info; + info.authForm = DmAuthForm::ACROSS_ACCOUNT; + info.deviceTypeId = 1; + deviceList.push_back(info); + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDevStateCallbackAdd(processInfo, deviceList); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnDevStateCallbackAdd(processInfo, deviceList); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -960,6 +1326,20 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnGetDeviceProfileInfoListResult_001, processInfo.userId = 101; std::vector deviceProfileInfos; int32_t code = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnGetDeviceProfileInfoListResult(processInfo, deviceProfileInfos, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnGetDeviceProfileInfoListResult_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.pkgName = "pkgName"; + processInfo.userId = 101; + std::vector deviceProfileInfos; + int32_t code = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnGetDeviceProfileInfoListResult(processInfo, deviceProfileInfos, code); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -972,6 +1352,20 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnGetDeviceIconInfoResult_001, testin processInfo.userId = 101; DmDeviceIconInfo dmDeviceIconInfo; int32_t code = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnGetDeviceIconInfoResult(processInfo, dmDeviceIconInfo, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnGetDeviceIconInfoResult_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + ProcessInfo processInfo; + processInfo.pkgName = "pkgName"; + processInfo.userId = 101; + DmDeviceIconInfo dmDeviceIconInfo; + int32_t code = 1; + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnGetDeviceIconInfoResult(processInfo, dmDeviceIconInfo, code); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -1028,6 +1422,24 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_004, testing::ext::TestS processInfo.userId = 100; EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyDeviceId(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnAuthResult(processInfo, deviceId, token, status, reason); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string deviceId = "dkdkd"; + std::string token = "kdkddk"; + int32_t status = 1; + int32_t reason = 2006; + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.hellojk"; + processInfo.userId = 100; + EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyDeviceId(_, _, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnAuthResult(processInfo, deviceId, token, status, reason); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -1044,6 +1456,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnUnbindResult_002, testing::ext::Tes EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyDeviceId(_, _, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); listener_->OnUnbindResult(processInfo, targetId, result, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } @@ -1063,28 +1476,12 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnSinkBindResult_002, testing::ext::T EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); std::vector processInfos; processInfos.push_back(processInfo); - EXPECT_CALL(*ipcServerListenerMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetAllProcessInfo()).WillOnce(Return(processInfos)); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); listener_->OnSinkBindResult(processInfo, targetId, result, status, content); EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); } -HWTEST_F(DeviceManagerServiceListenerTest, SetDeviceInfo_001, testing::ext::TestSize.Level1) -{ - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr pReq = std::make_shared(); - ProcessInfo processInfo; - processInfo.pkgName = "pkgNameqaz"; - DmDeviceState state = DmDeviceState::DEVICE_INFO_CHANGED; - DmDeviceInfo deviceInfo; - DmDeviceBasicInfo deviceBasicInfo; - - EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).Times(::testing::AtLeast(3)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetAppIdByPkgName(_, _)).Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - listener_->SetDeviceInfo(pReq, processInfo, state, deviceInfo, deviceBasicInfo); - EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); -} - HWTEST_F(DeviceManagerServiceListenerTest, GetLocalDisplayDeviceName_001, testing::ext::TestSize.Level1) { std::shared_ptr listener_ = std::make_shared(); @@ -1103,6 +1500,60 @@ HWTEST_F(DeviceManagerServiceListenerTest, OpenAuthSessionWithPara_001, testing: int32_t ret = listener_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); EXPECT_NE(ret, DM_OK); } + +HWTEST_F(DeviceManagerServiceListenerTest, OnSetLocalDeviceNameResult_001, testing::ext::TestSize.Level1) +{ + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + std::string deviceName = "SetLocalDeviceName"; + int32_t code = 1; + std::shared_ptr listener_ = std::make_shared(); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnSetLocalDeviceNameResult(processInfo, deviceName, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnSetLocalDeviceNameResult_002, testing::ext::TestSize.Level1) +{ + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + std::string deviceName = "SetLocalDeviceName"; + int32_t code = 1; + std::shared_ptr listener_ = std::make_shared(); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); + listener_->OnSetLocalDeviceNameResult(processInfo, deviceName, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnSetRemoteDeviceNameResult_001, testing::ext::TestSize.Level1) +{ + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + std::string deviceId = "OnSetRemoteDeviceNameResult"; + std::string deviceName = "DeviceName"; + int32_t code = 1; + std::shared_ptr listener_ = std::make_shared(); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(nullptr)); + listener_->OnSetRemoteDeviceNameResult(processInfo, deviceId, deviceName, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} + +HWTEST_F(DeviceManagerServiceListenerTest, OnSetRemoteDeviceNameResult_002, testing::ext::TestSize.Level1) +{ + ProcessInfo processInfo; + processInfo.pkgName = "com.ohos.helloworld"; + processInfo.userId = 100; + std::string deviceId = "OnSetRemoteDeviceNameResult"; + std::string deviceName = "DeviceName"; + int32_t code = 1; + std::shared_ptr listener_ = std::make_shared(); + EXPECT_CALL(*ipcServerStubMock_, GetDmListener(processInfo)).WillOnce(Return(deviceManagerIpc)); + listener_->OnSetRemoteDeviceNameResult(processInfo, deviceId, deviceName, code); + EXPECT_EQ(listener_->alreadyOnlinePkgName_.empty(), false); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_listener.h b/test/unittest/UTTest_device_manager_service_listener.h index 771c197222f711ddf2b22a877a7a5de19be62730..796e73717d6e553a524420016ef1a5f60924d486 100644 --- a/test/unittest/UTTest_device_manager_service_listener.h +++ b/test/unittest/UTTest_device_manager_service_listener.h @@ -22,6 +22,8 @@ #include "device_manager_service_listener.h" #include "dm_device_info.h" #include "ipc_server_listener.h" +#include "ipc_server_stub_mock.h" +#include "device_manager_notify_service.h" #include "dm_softbus_cache_mock.h" #include "dm_crypto_mock.h" #include "ipc_server_listener_mock.h" @@ -44,6 +46,8 @@ public: static inline std::shared_ptr kVAdapterManagerMock_ = std::make_shared(); static inline std::shared_ptr appManagerMock_ = std::make_shared(); + static inline std::shared_ptr ipcServerStubMock_ = std::make_shared(); + sptr deviceManagerIpc = sptr(new DeviceManagerNotifyService()); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_client_manager.cpp b/test/unittest/UTTest_ipc_client_manager.cpp index 24d55d29e826e812c80faf9f35727a0b528820a0..ba1a9f5b330666a2c55de50f76450bf613ccfc0c 100644 --- a/test/unittest/UTTest_ipc_client_manager.cpp +++ b/test/unittest/UTTest_ipc_client_manager.cpp @@ -17,6 +17,7 @@ #include "device_manager_ipc_interface_code.h" #include "device_manager_notify.h" +#include "device_manager_notify_service.h" #include "dm_device_info.h" #include "ipc_client_stub.h" #include "ipc_register_listener_req.h" @@ -132,7 +133,7 @@ HWTEST_F(IpcClientManagerTest, ClientInit_002, testing::ext::TestSize.Level0) HWTEST_F(IpcClientManagerTest, Init_001, testing::ext::TestSize.Level0) { // 1. new a listener - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. set a pkgName not null std::string pkgName = "com.ohos.test"; std::shared_ptr instance = std::make_shared(); @@ -294,7 +295,7 @@ HWTEST_F(IpcClientManagerTest, UnInit_002, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); instance->dmInterface_ = mockInstance; // 4. set IpcClientManager dmListener_ not null - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); instance->dmListener_[pkgName] = listener; // 5. call UnInit with pkgName int32_t ret = instance->UnInit(pkgName); @@ -326,7 +327,7 @@ HWTEST_F(IpcClientManagerTest, UnInit_003, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); instance->dmInterface_ = mockInstance; // 4. set IpcClientManager dmListener_ not null - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); instance->dmListener_[pkgName] = listener; // 5. call UnInit with pkgName int32_t ret = instance->UnInit(pkgName); @@ -358,7 +359,7 @@ HWTEST_F(IpcClientManagerTest, UnInit_004, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); instance->dmInterface_ = mockInstance; // 4. set IpcClientManager dmListener_ not null - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); instance->dmListener_[pkgName] = listener; // 5. call UnInit with pkgName int32_t ret = instance->UnInit(pkgName); @@ -390,7 +391,7 @@ HWTEST_F(IpcClientManagerTest, UnInit_005, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); instance->dmInterface_ = mockInstance; // 4. set IpcClientManager dmListener_ not null - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); instance->dmListener_[pkgName] = listener; // 5. call UnInit with pkgName int32_t ret = instance->UnInit(pkgName); @@ -449,7 +450,7 @@ HWTEST_F(IpcClientManagerTest, SendRequest_002, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); // 3. set IpcClientManager dmInterface_ not null instance->dmInterface_ = mockInstance; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 4. set IpcClientManager dmListener_ not null instance->dmListener_[pkgName] = listener; // 5. call SendRequest with parameter @@ -484,7 +485,7 @@ HWTEST_F(IpcClientManagerTest, SendRequest_003, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); // 3. set IpcClientManager dmInterface_ not null instance->dmInterface_ = mockInstance; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 4. set IpcClientManager dmListener_ not null instance->dmListener_[pkgName] = listener; // 5. call SendRequest with parameter @@ -519,7 +520,7 @@ HWTEST_F(IpcClientManagerTest, SendRequest_004, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); // 3. set IpcClientManager dmInterface_ not null instance->dmInterface_ = mockInstance; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 4. set IpcClientManager dmListener_ not null instance->dmListener_[pkgName] = listener; // 5. call SendRequest with parameter @@ -554,7 +555,7 @@ HWTEST_F(IpcClientManagerTest, SendRequest_005, testing::ext::TestSize.Level0) std::shared_ptr instance = std::make_shared(); // 3. set IpcClientManager dmInterface_ not null instance->dmInterface_ = mockInstance; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 4. set IpcClientManager dmListener_ not null instance->dmListener_[pkgName] = listener; // 5. call SendRequest with parameter diff --git a/test/unittest/UTTest_ipc_client_stub.cpp b/test/unittest/UTTest_ipc_client_stub.cpp index 07492955556e7d090df2e1fb7a522473cf16fabd..fa8433b68f4373548f3413366aa79e2e994fecf2 100644 --- a/test/unittest/UTTest_ipc_client_stub.cpp +++ b/test/unittest/UTTest_ipc_client_stub.cpp @@ -93,34 +93,6 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) ASSERT_EQ(result, ERR_DM_FAILED); } -/** - * @tc.name: OnRemoteRequest_002 - * @tc.desc: 1. set MessageOption not null - * set MessageParcel not null - * set MessageParcel not null - * 2. set set code is SERVER_DEVICE_FA_NOTIFY - * 3. call IpcClientStub OnRemoteRequest with parameter - * 4. check result is ERR_DM_IPC_READ_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) -{ - // 1. set MessageOption not null - MessageOption option; - // set MessageParcel not null - MessageParcel data; - // set MessageParcel not null - MessageParcel reply; - // 2. set set code is SERVER_DEVICE_FA_NOTIFY - int code = SERVER_DEVICE_FA_NOTIFY; - sptr instance(new IpcClientStub()); - // 3. call IpcClientStub OnRemoteRequest with parameter - int ret = instance->OnRemoteRequest(code, data, reply, option); - // 4. check result is ERR_DM_IPC_READ_FAILED - ASSERT_EQ(ret, ERR_DM_IPC_READ_FAILED); -} - /** * @tc.name: OnRemoteRequest_003 * @tc.type: FUNC @@ -140,31 +112,6 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_003, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } -/** - * @tc.name: SendCmd_001 - * @tc.desc: 1. set set code is SERVER_DEVICE_FA_NOTIFY - * set req is nullptr - * set rsp is nullptr - * 2. call IpcClientStub SendCmd with parameter - * 3. check result is ERR_DM_IPC_SEND_REQUEST_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcClientStubTest, SendCmd_001, testing::ext::TestSize.Level0) -{ - // 1. set set code is SERVER_DEVICE_FA_NOTIFY - int cmdCode = SERVER_DEVICE_FA_NOTIFY; - // set req is nullptr - std::shared_ptr req = nullptr; - // set rsp is nullptr - std::shared_ptr rsp = nullptr; - sptr instance(new IpcClientStub()); - // 2. call IpcClientStub SendCmd with parameter - int ret = instance->SendCmd(cmdCode, req, rsp); - // 3. check result is ERR_DM_IPC_SEND_REQUEST_FAILED - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: SendCmd_002 * @tc.type: FUNC diff --git a/test/unittest/UTTest_ipc_cmd_parser_client.cpp b/test/unittest/UTTest_ipc_cmd_parser_client.cpp index 58f9bd3eddc2a92ae28567b8ac8f3848b1fe3f2b..cac107e600fd9e9802ab4cf0f896f24061d2cf02 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_client.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_client.cpp @@ -710,233 +710,6 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_034, testing::ext::TestSize.L ASSERT_EQ(DM_OK, ret); } -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_001, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_DISCOVERY; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - int16_t subscribeId = 100; - std::string deviceId = "xxx"; - data.WriteString(pkgName); - data.WriteInt16(subscribeId); - DmDeviceBasicInfo basicInfo; - data.WriteRawData(&basicInfo, sizeof(DmDeviceBasicInfo)); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_002, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = BIND_TARGET_RESULT; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - PeerTargetId targetId; - int32_t result = 1; - int32_t status = 1; - std::string content = "XX"; - data.WriteString(pkgName); - EncodePeerTargetId(targetId, data); - data.WriteInt32(result); - data.WriteInt32(status); - data.WriteString(content); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_003, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = UNBIND_TARGET_RESULT; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - PeerTargetId targetId; - int32_t result = 1; - std::string content = "XX"; - data.WriteString(pkgName); - EncodePeerTargetId(targetId, data); - data.WriteInt32(result); - data.WriteString(content); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_004, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - std::string deviceId = "xxx"; - int32_t pinType = 1; - std::string payload = "xx"; - data.WriteString(pkgName); - data.WriteString(deviceId); - data.WriteInt32(pinType); - data.WriteString(payload); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_005, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - int32_t pinType = 1; - std::string payload = "xx"; - data.WriteString(pkgName); - data.WriteInt32(pinType); - data.WriteString(payload); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_006, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER_RESULT; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - int32_t result = 1; - data.WriteString(pkgName); - data.WriteInt32(result); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_007, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER_RESULT; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - int32_t result = 1; - data.WriteString(pkgName); - data.WriteInt32(result); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_008, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_ON_PIN_HOLDER_EVENT; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - int32_t result = 1; - std::string content = "xxx"; - int32_t pinHolderEvent = 1; - data.WriteString(pkgName); - data.WriteInt32(result); - data.WriteInt32(pinHolderEvent); - data.WriteString(content); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_009, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = REMOTE_DEVICE_TRUST_CHANGE; - int32_t ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - MessageParcel data; - MessageParcel reply; - std::string pkgName = "ohos.dm.test"; - std::string deviceId = "xxx"; - int32_t authForm = 1; - data.WriteString(pkgName); - data.WriteString(deviceId); - data.WriteInt32(authForm); - OnIpcCmdFunc ptr = GetIpcCmdFunc(cmdCode); - if (ptr) { - ret = ptr(data, reply); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_010, testing::ext::TestSize.Level0) -{ - auto ptr = GetIpcCmdFunc(SERVER_DEVICE_STATE_NOTIFY); - ASSERT_TRUE(ptr != nullptr); - - MessageParcel reply; - MessageParcel data1; - data1.WriteString("com.ohos.test"); - data1.WriteInt32(DEVICE_INFO_READY); - size_t deviceSize = sizeof(DmDeviceInfo); - data1.WriteRawData(nullptr, deviceSize); - EXPECT_EQ(ptr(data1, reply), DM_OK); - - MessageParcel data2; - data2.WriteString("com.ohos.test"); - data2.WriteInt32(DEVICE_STATE_UNKNOWN); - EXPECT_EQ(ptr(data2, reply), DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_011, testing::ext::TestSize.Level0) -{ - auto ptr = GetIpcCmdFunc(SERVER_DEVICE_SCREEN_STATE_NOTIFY); - ASSERT_TRUE(ptr != nullptr); - - MessageParcel reply; - MessageParcel data; - EXPECT_EQ(ptr(data, reply), DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_012, testing::ext::TestSize.Level0) -{ - auto ptr = GetIpcCmdFunc(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY); - ASSERT_TRUE(ptr != nullptr); - - MessageParcel reply; - MessageParcel data; - EXPECT_EQ(ptr(data, reply), DM_OK); -} - -HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_013, testing::ext::TestSize.Level0) -{ - auto ptr = GetIpcCmdFunc(SINK_BIND_TARGET_RESULT); - ASSERT_TRUE(ptr != nullptr); - - MessageParcel reply; - MessageParcel data; - EXPECT_EQ(ptr(data, reply), DM_OK); -} - HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_016, testing::ext::TestSize.Level0) { auto ptr = GetIpcRequestFunc(SERVER_GET_DMFA_INFO); diff --git a/test/unittest/UTTest_ipc_cmd_parser_service.cpp b/test/unittest/UTTest_ipc_cmd_parser_service.cpp index 719df2374e2b2874720fc3a2343ad8423ed554f6..6282c7558b5cbf07a95622684594e14bf135782f 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_service.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_service.cpp @@ -148,331 +148,6 @@ bool EncodePeerTargetId(const PeerTargetId &targetId, MessageParcel &parcel) return bRet; } -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_001, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_001, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_002, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_002, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FOUND; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_003, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FOUND; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_004, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FOUND; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_003, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_DISCOVERY; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_005, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_DISCOVERY; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_006, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_DISCOVERY; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_004, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DISCOVER_FINISH; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_007, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DISCOVER_FINISH; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_008, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DISCOVER_FINISH; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_005, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_PUBLISH_FINISH; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_009, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_PUBLISH_FINISH; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_010, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_PUBLISH_FINISH; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_006, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_AUTH_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_011, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_AUTH_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_012, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_AUTH_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_007, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FA_NOTIFY; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_013, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FA_NOTIFY; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_014, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FA_NOTIFY; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_008, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREDENTIAL_RESULT; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_015, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREDENTIAL_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_016, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREDENTIAL_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_009, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = BIND_TARGET_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_017, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = BIND_TARGET_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_018, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = BIND_TARGET_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_010, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = UNBIND_TARGET_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestIpcRequestFuncReqNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_019, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = UNBIND_TARGET_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_020, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = UNBIND_TARGET_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_011, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - req->SetPkgName(pkgName); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_021, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_022, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_012, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - req->SetPkgName(pkgName); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_023, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_024, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_013, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER_RESULT; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - req->SetPkgName(pkgName); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_025, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_026, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREATE_PIN_HOLDER_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_014, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER_RESULT; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - req->SetPkgName(pkgName); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_027, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER_RESULT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_028, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DESTROY_PIN_HOLDER_RESULT; - ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); -} - HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_001, testing::ext::TestSize.Level0) { int32_t cmdCode = BIND_DEVICE; @@ -1406,136 +1081,6 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_063, testing::ext::TestSize.Level EXPECT_EQ(cmdptr(data, reply), DM_OK); } -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_016, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_DISCOVERY; - MessageParcel data; - std::shared_ptr pReq = std::make_shared(); - std::string pkgName = "com.ohos.test"; - uint16_t subscribeId = 100; - DmDeviceBasicInfo deviceBasicInfo; - pReq->SetPkgName(pkgName); - pReq->SetSubscribeId(subscribeId); - pReq->SetDeviceBasicInfo(deviceBasicInfo); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(pReq, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_017, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_AUTH_RESULT; - MessageParcel data; - std::shared_ptr pReq = std::make_shared(); - std::string pkgName = "com.ohos.test"; - std::string deviceId = "112233445"; - std::string token = "134354656"; - int32_t status = 1; - int32_t reason = 1; - pReq->SetPkgName(pkgName); - pReq->SetDeviceId(deviceId); - pReq->SetToken(token); - pReq->SetStatus(status); - pReq->SetReason(reason); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(pReq, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_018, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FA_NOTIFY; - MessageParcel data; - std::shared_ptr pReq = std::make_shared(); - std::string pkgName = "com.ohos.test"; - std::string paramJson = "{}"; - pReq->SetPkgName(pkgName); - pReq->SetJsonParam(paramJson); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(pReq, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_019, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = BIND_TARGET_RESULT; - MessageParcel data; - std::shared_ptr pReq = std::make_shared(); - std::string pkgName = "com.ohos.test"; - PeerTargetId targetId; - int32_t result = 1; - int32_t status = 1; - std::string content = ""; - pReq->SetPkgName(pkgName); - pReq->SetPeerTargetId(targetId); - pReq->SetResult(result); - pReq->SetStatus(status); - pReq->SetContent(content); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(pReq, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_020, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = UNBIND_TARGET_RESULT; - MessageParcel data; - std::shared_ptr pReq = std::make_shared(); - std::string pkgName = "com.ohos.test"; - PeerTargetId targetId; - int32_t result = 1; - std::string content = ""; - pReq->SetPkgName(pkgName); - pReq->SetPeerTargetId(targetId); - pReq->SetResult(result); - pReq->SetContent(content); - int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(pReq, data); - } - ASSERT_EQ(DM_OK, ret); -} - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_021, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_ON_PIN_HOLDER_EVENT; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - req->SetPkgName(pkgName); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_029, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_ON_PIN_HOLDER_EVENT; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} - HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_055, testing::ext::TestSize.Level0) { int32_t cmdCode = CHECK_ACCESS_CONTROL; @@ -1562,39 +1107,6 @@ HWTEST_F(IpcCmdParserServiceTest, OnIpcCmdFunc_055, testing::ext::TestSize.Level } ASSERT_EQ(ret, DM_OK); } - -HWTEST_F(IpcCmdParserServiceTest, SetIpcRequestFunc_022, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY; - MessageParcel data; - std::shared_ptr req = nullptr; - int ret = ERR_DM_FAILED; - SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, ERR_DM_FAILED); - - req = std::make_shared(); - std::string pkgName = "com.ohos.test"; - std::string deviceList = "test"; - uint16_t deviceTypeId = 0x00; - int32_t errcode = -1; - req->SetPkgName(pkgName); - req->SetDeviceList(deviceList); - req->SetDeviceTypeId(deviceTypeId); - req->SetErrCode(errcode); - if (ptr) { - ret = ptr(req, data); - } - ASSERT_EQ(ret, DM_OK); -} - -HWTEST_F(IpcCmdParserServiceTest, ReadResponseFunc_030, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY; - ASSERT_EQ(ERR_DM_FAILED, TestReadResponseRspNull(cmdCode)); -} } // namespace } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_ipc_cmd_register.cpp b/test/unittest/UTTest_ipc_cmd_register.cpp index 912b90eeb69a50eed0aa11fa9725b5864299a7e9..fec2a1685ede9202fdd6391a23cc2e0d08fb0301 100644 --- a/test/unittest/UTTest_ipc_cmd_register.cpp +++ b/test/unittest/UTTest_ipc_cmd_register.cpp @@ -768,158 +768,6 @@ HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_IPC_COMMAND); } -/** - * @tc.name: OnIpcCmd_002 - * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - * 2. data.WriteString(pkgname) - * data.WriteInt32(DEVICE_STATE_ONLINE) - * data.WriteRawData(&dmDeviceInfo, deviceSize) - * 3. call IpcCmdRegister OnIpcCmd with parameter - * 4. check ret is DM_OK - * check result is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_002, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - MessageParcel reply; - MessageParcel data; - // 2. data.WriteString(pkgname) - data.WriteString("com.ohos.test"); - // data.WriteInt32(DEVICE_STATE_ONLINE) - data.WriteInt32(DEVICE_STATE_ONLINE); - DmDeviceInfo dmDeviceInfo; - size_t deviceSize = sizeof(DmDeviceInfo); - // data.WriteRawData(&dmDeviceInfo, deviceSize) - data.WriteRawData(&dmDeviceInfo, deviceSize); - // 3. call IpcCmdRegister OnIpcCmd with parameter - int ret = 0; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - // check ret is DEVICEMANAGER_IPC_NOT_REGISTER_FUNC - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_003 - * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - * 2. data.WriteString(pkgname) - * data.WriteInt32(DEVICE_STATE_ONLINE) - * data.WriteRawData(nullptr, deviceSize) - * 3. call IpcCmdRegister OnIpcCmd with parameter - * 4. check ret is DEVICEMANAGER_OK - * check result is DEVICE_STATE_ONLINE - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_003, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - MessageParcel reply; - MessageParcel data; - // 2. data.WriteString(pkgname) - data.WriteString("com.ohos.test"); - // data.WriteInt32(DEVICE_STATE_ONLINE) - data.WriteInt32(DEVICE_STATE_ONLINE); - // data.WriteRawData(nullptr, deviceSize) - size_t deviceSize = sizeof(DmDeviceInfo); - data.WriteRawData(nullptr, deviceSize); - // 3. call IpcCmdRegister OnIpcCmd with parameter - int ret = 0; - int32_t result = 0; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - result = reply.ReadInt32(); - // 4. check result is DEVICE_STATE_ONLINE - ASSERT_EQ(result, DEVICE_STATE_ONLINE); - // check ret is DM_OK - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_004 - * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - * 2. data.WriteString(pkgname) - * data.WriteInt32(DEVICE_STATE_OFFLINE) - * data.WriteRawData(nullptr, deviceSize) - * 3. call IpcCmdRegister OnIpcCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_004, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - MessageParcel reply; - MessageParcel data; - // 2. data.WriteString(pkgname) - data.WriteString("com.ohos.test"); - // data.WriteInt32(DEVICE_STATE_OFFLINE) - data.WriteInt32(DEVICE_STATE_OFFLINE); - size_t deviceSize = sizeof(DmDeviceInfo); - // data.WriteRawData(nullptr, deviceSize) - data.WriteRawData(nullptr, deviceSize); - // 3. call IpcCmdRegister OnIpcCmd with parameter - int ret = 0; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - // check ret is DM_OK - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_005 - * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - * 2. data.WriteString(pkgname) - * data.WriteInt32(DEVICE_INFO_CHANGED) - * data.WriteRawData(nullptr, deviceSize) - * 3. call IpcCmdRegister OnIpcCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_005, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - MessageParcel reply; - MessageParcel data; - // 2. data.WriteString(pkgname) - data.WriteString("com.ohos.test"); - // data.WriteInt32(DEVICE_INFO_CHANGED) - data.WriteInt32(DEVICE_INFO_CHANGED); - size_t deviceSize = sizeof(DmDeviceInfo); - // data.WriteRawData(nullptr, deviceSize) - data.WriteRawData(nullptr, deviceSize); - // 3. call IpcCmdRegister OnIpcCmd with parameter - int ret = 0; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - // 4.check ret is DM_OK - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_006 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_006, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FOUND; - MessageParcel reply; - MessageParcel data; - uint16_t subscribeId = 1; - DmDeviceInfo deviceInfo; - data.WriteString("com.ohos.test"); - data.WriteInt16(subscribeId); - size_t deviceSize = sizeof(DmDeviceInfo); - data.WriteRawData(&deviceInfo, deviceSize); - int ret = 0; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: OnIpcCmd_007 * @tc.type: FUNC @@ -946,105 +794,6 @@ HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_008, testing::ext::TestSize.Level0) ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_IPC_COMMAND); } -/** - * @tc.name: OnIpcCmd_009 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_009, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DISCOVER_FINISH; - MessageParcel reply; - MessageParcel data; - uint16_t subscribeId = 1; - int32_t failedReason = 0; - data.WriteString("com.ohos.test"); - data.WriteInt16(subscribeId); - data.WriteInt32(failedReason); - int ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_010 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_010, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_PUBLISH_FINISH; - MessageParcel reply; - MessageParcel data; - int32_t publishId = 1; - int32_t publishResult = 0; - data.WriteString("com.ohos.test"); - data.WriteInt32(publishId); - data.WriteInt32(publishResult); - int ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_011 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_011, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_AUTH_RESULT; - MessageParcel reply; - MessageParcel data; - std::string pkgName = "ohos.test"; - std::string deviceId = "123"; - std::string token = "123456"; - int32_t status = 1; - int32_t reason = 0; - data.WriteString(pkgName); - data.WriteString(deviceId); - data.WriteString(token); - data.WriteInt32(status); - data.WriteInt32(reason); - int ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_013 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_013, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_DEVICE_FA_NOTIFY; - MessageParcel reply; - MessageParcel data; - std::string pkgName = "ohos.test"; - std::string paramJson = "123"; - data.WriteString(pkgName); - data.WriteString(paramJson); - int ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: OnIpcCmd_014 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_014, testing::ext::TestSize.Level0) -{ - int32_t cmdCode = SERVER_CREDENTIAL_RESULT; - MessageParcel reply; - MessageParcel data; - std::string pkgName = "ohos.test"; - std::string credentialResult = "123"; - int32_t action = 0; - data.WriteString(pkgName); - data.WriteInt32(action); - data.WriteString(credentialResult); - int ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); - ASSERT_EQ(ret, DM_OK); -} } // namespace } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_ipc_server_client_proxy.cpp b/test/unittest/UTTest_ipc_server_client_proxy.cpp index f37d754c0a3594112360fc20e97847d5dc44dee6..ed53eec051211da9a3d8a1ec52f38f7e341109d4 100644 --- a/test/unittest/UTTest_ipc_server_client_proxy.cpp +++ b/test/unittest/UTTest_ipc_server_client_proxy.cpp @@ -75,178 +75,6 @@ HWTEST_F(IpcServerClientProxyTest, SendCmd_001, testing::ext::TestSize.Level0) // 4. check ret is DEVICEMANAGER_NULLPTR ASSERT_EQ(ret, ERR_DM_POINT_NULL); } - -/** - * @tc.name: SendCmd_002 - * @tc.desc: 1. set cmdCode not null - * set pkgName not null - * set action not null - * 2. set remoteObject not nullptr - * set req not null - * set rsp not null - * 3. call IpcServerClientProxy SendCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerClientProxyTest, SendCmd_002, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode not null - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - // set pkgName not null - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - // set action not null - int deviceState = 1; - DmDeviceInfo deviceInfo; - // 2. set remoteObject not nullptr - sptr remoteObject = sptr(new IpcClientStub()); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, remoteObject); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - // set req not null - req->SetPkgName(pkgName); - // set rsp not null - req->SetDeviceState(deviceState); - req->SetDeviceInfo(deviceInfo); - // 3. call IpcServerClientProxy SendCmd with parameter - int ret = 0; - std::shared_ptr ipcServerListener = std::make_shared(); - ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 4. check ret is not ERR_DM_FAILED - ASSERT_NE(ret, ERR_DM_FAILED); -} - -/** - * @tc.name: SendCmd_003 - * @tc.desc: 1. set cmdCode not null - * set pkgName not null - * set action not null - * 2. set remoteObject not nullptr - * set req not null - * set rsp not null - * 3. call IpcServerClientProxy SendCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerClientProxyTest, SendCmd_003, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode not null - int32_t cmdCode = SERVER_DEVICE_FOUND; - // set pkgName not null - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - // set action not null - uint16_t subscribeId = 1; - DmDeviceInfo dmDeviceInfo; - // 2. set remoteObject not nullptr - sptr remoteObject = sptr(new IpcClientStub()); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, remoteObject); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - // set req not null - req->SetPkgName(pkgName); - // set rsp not null - req->SetSubscribeId(subscribeId); - req->SetDeviceInfo(dmDeviceInfo); - // 3. call IpcServerClientProxy SendCmd with parameter - int ret = 0; - std::shared_ptr ipcServerListener = std::make_shared(); - ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 4. check ret is not ERR_DM_FAILED - ASSERT_NE(ret, ERR_DM_FAILED); -} - -/** - * @tc.name: SendCmd_004 - * @tc.desc: 1. set cmdCode not null - * set pkgName not null - * set action not null - * 2. set remoteObject not nullptr - * set req not null - * set rsp not null - * 3. call IpcServerClientProxy SendCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerClientProxyTest, SendCmd_004, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode not null - int32_t cmdCode = SERVER_DISCOVER_FINISH; - // set pkgName not null - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - // set action not null - uint16_t subscribeId = 1; - int32_t result = 1; - // 2. set remoteObject not nullptr - sptr remoteObject = sptr(new IpcClientStub()); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, remoteObject); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - // set req not null - req->SetPkgName(pkgName); - // set rsp not null - req->SetSubscribeId(subscribeId); - req->SetResult(result); - // 3. call IpcServerClientProxy SendCmd with parameter - int ret = 0; - std::shared_ptr ipcServerListener = std::make_shared(); - ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 4. check ret is not ERR_DM_FAILED - ASSERT_NE(ret, ERR_DM_FAILED); -} - -/** - * @tc.name: SendCmd_005 - * @tc.desc: 1. set cmdCode not null - * set pkgName not null - * set action not null - * 2. set remoteObject not nullptr - * set req not null - * set rsp not null - * 3. call IpcServerClientProxy SendCmd with parameter - * 4. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: I5N1K3 - */ -HWTEST_F(IpcServerClientProxyTest, SendCmd_005, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode not null - int32_t cmdCode = SERVER_PUBLISH_FINISH; - // set pkgName not null - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - // set action not null - int32_t publishId = 1; - int32_t result = 1; - // 2. set remoteObject not nullptr - sptr remoteObject = sptr(new IpcClientStub()); - IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, remoteObject); - std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); - // set req not null - req->SetPkgName(pkgName); - // set rsp not null - req->SetPublishId(publishId); - req->SetResult(result); - // 3. call IpcServerClientProxy SendCmd with parameter - int ret = 0; - std::shared_ptr ipcServerListener = std::make_shared(); - ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 4. check ret is not ERR_DM_FAILED - ASSERT_NE(ret, ERR_DM_FAILED); -} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_server_listener.cpp b/test/unittest/UTTest_ipc_server_listener.cpp index dfe72c781c2818aa6e08f9929b8e59700dd3957b..6513e0025275a1d1983045c71eb1e25d341553e0 100644 --- a/test/unittest/UTTest_ipc_server_listener.cpp +++ b/test/unittest/UTTest_ipc_server_listener.cpp @@ -82,35 +82,6 @@ HWTEST_F(IpcServerListenerTest, SendRequest_001, testing::ext::TestSize.Level0) ASSERT_NE(ret, DM_OK); } -/** - * @tc.name: SendRequest_002 - * @tc.desc: 1. set cmdCode not null - * set pkgName null - * 2. set req not null - * set rsp not null - * 3. call IpcServerListener SendRequest - * 4. check ret is ERR_DM_IPC_RESPOND_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerListenerTest, SendRequest_002, testing::ext::TestSize.Level0) -{ - // 1. set cmdCode not null - int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; - // set pkgName not null - std::string pkgName; - // set req not null - std::shared_ptr req = std::make_shared(); - // set rsp not null - std::shared_ptr rsp = std::make_shared(); - req->SetPkgName(pkgName); - // 2. call IpcServerListener SendRequest - std::shared_ptr ipcServerListener = std::make_shared(); - int ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 3. check ret is not ERR_DM_IPC_RESPOND_FAILED - ASSERT_NE(ret, ERR_DM_IPC_RESPOND_FAILED); -} - /** * @tc.name: SendRequest_003 * @tc.desc: 1. set cmdCode not null diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index adc33ab53c1bb534285886645528d21208a98aec..19ccea3906436bb8afd3c42c76d731323020a812 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -20,6 +20,7 @@ #include #include "device_manager_ipc_interface_code.h" +#include "device_manager_notify_service.h" #include "device_manager_service.h" #include "dm_device_info.h" #include "ipc_remote_broker.h" @@ -141,28 +142,6 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) ASSERT_NE(ret, DM_OK); } -/** - * @tc.name: OnRemoteRequest_002 - * @tc.desc: 1. Set Code = 999 - * 2. Call IpcServerStub OnRemoteRequest with param - * 3. check ret not DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) -{ - // 1. Set Code is SERVER_DEVICE_STATE_NOTIFY - uint32_t code = SERVER_DEVICE_STATE_NOTIFY; - MessageParcel data; - MessageParcel reply; - MessageOption option; - int ret = 0; - // 2. Call IpcServerStub OnRemoteRequest with param - ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); - // 3. check ret not DM_OK - ASSERT_NE(ret, DM_OK); -} - /** * @tc.name: SendCmd_001 * @tc.desc: 1. Call IpcServerStub SendCmd @@ -231,7 +210,7 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_001, testing::ext::Tes processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = nullptr; + sptr listener = nullptr; ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); ASSERT_EQ(ret, ERR_DM_POINT_NULL); } @@ -250,7 +229,7 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_002, testing::ext::Tes processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); ASSERT_EQ(ret, DM_OK); } @@ -269,7 +248,7 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_003, testing::ext::Tes processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); ASSERT_EQ(ret, ERR_DM_POINT_NULL); } @@ -290,7 +269,7 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_004, testing::ext::Tes processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK @@ -318,17 +297,17 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_005, testing::ext::Tes processInfo.userId = 100; int ret = 0; int result = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK ASSERT_EQ(ret, DM_OK); - sptr listener2 = sptr(new IpcClientStub()); + sptr listener2 = sptr(new DeviceManagerNotifyService()); // 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener2); // 5. check result is DM_OK ASSERT_EQ(result, DM_OK); - sptr listener3 = sptr(new IpcClientStub()); + sptr listener3 = sptr(new DeviceManagerNotifyService()); // 6. earse pkgName for appRecipient_ IpcServerStub::GetInstance().appRecipient_.erase(processInfo); result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener3); @@ -336,6 +315,7 @@ HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_005, testing::ext::Tes ASSERT_EQ(result, DM_OK); } + /** * @tc.name: UnRegisterDeviceManagerListener_001 * @tc.desc: 1. Call IpcServerStub UnRegisterDeviceManagerListener @@ -369,7 +349,7 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_002, testing::ext::T processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK @@ -421,7 +401,7 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_004, testing::ext::T processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK @@ -431,7 +411,7 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_004, testing::ext::T result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo); // 5. check ret is DM_OK ASSERT_EQ(result, DM_OK); - sptr dmListener = IpcServerStub::GetInstance().dmListener_[processInfo]; + sptr dmListener = IpcServerStub::GetInstance().dmListener_[processInfo]; ASSERT_EQ(dmListener, nullptr); } @@ -455,7 +435,7 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_005, testing::ext::T processInfo.pkgName = pkgName; processInfo.userId = 100; int ret = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK @@ -486,7 +466,7 @@ HWTEST_F(IpcServerStubTest, GetDmListener_001, testing::ext::TestSize.Level0) // 1. Set pkgName is com.ohos.test ProcessInfo processInfo; processInfo.pkgName = "com.ohos.test"; - sptr ret = nullptr; + sptr ret = nullptr; // 2. Call IpcServerStub UnRegisterDeviceManagerListener ret = IpcServerStub::GetInstance().GetDmListener(processInfo); // 3. check ret is DM_OK @@ -508,12 +488,12 @@ HWTEST_F(IpcServerStubTest, GetDmListener_002, testing::ext::TestSize.Level0) ProcessInfo processInfo; processInfo.pkgName = pkgName; int result = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK ASSERT_EQ(result, DM_OK); - sptr ret = nullptr; + sptr ret = nullptr; // 2. Call IpcServerStub UnRegisterDeviceManagerListener ret = IpcServerStub::GetInstance().GetDmListener(processInfo); // 3. check ret is DM_OK @@ -535,12 +515,12 @@ HWTEST_F(IpcServerStubTest, GetDmListener_003, testing::ext::TestSize.Level0) ProcessInfo processInfo; processInfo.pkgName = pkgName; int result = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is DM_OK ASSERT_EQ(result, DM_OK); - sptr ret = nullptr; + sptr ret = nullptr; // 2. Call IpcServerStub UnRegisterDeviceManagerListener ret = IpcServerStub::GetInstance().GetDmListener(processInfo); // 3. check ret is DM_OK @@ -562,12 +542,12 @@ HWTEST_F(IpcServerStubTest, GetDmListener_004, testing::ext::TestSize.Level0) ProcessInfo processInfo; processInfo.pkgName = pkgName; int result = 0; - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyService()); // 2. Call IpcServerStub RegisterDeviceManagerListener with param result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is ERR_DM_POINT_NULL ASSERT_EQ(result, ERR_DM_POINT_NULL); - sptr ret = nullptr; + sptr ret = nullptr; // 2. Call IpcServerStub UnRegisterDeviceManagerListener ret = IpcServerStub::GetInstance().GetDmListener(processInfo); // 3. check ret is nullptr @@ -589,12 +569,12 @@ HWTEST_F(IpcServerStubTest, GetDmListener_005, testing::ext::TestSize.Level0) ProcessInfo processInfo; processInfo.pkgName = pkgName; int result = 0; - sptr listener = nullptr; + sptr listener = nullptr; // 2. Call IpcServerStub RegisterDeviceManagerListener with param result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); // 3. check ret is ERR_DM_POINT_NULL ASSERT_EQ(result, ERR_DM_POINT_NULL); - sptr ret = nullptr; + sptr ret = nullptr; // 2. Call IpcServerStub UnRegisterDeviceManagerListener ret = IpcServerStub::GetInstance().GetDmListener(processInfo); // 3. check ret is nullptr @@ -839,4 +819,4 @@ HWTEST_F(IpcServerStubTest, JoinPath2_006, testing::ext::TestSize.Level0) } } // namespace } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/service/src/ipc/standard/ipc_server_listener.cpp b/test/unittest/mock/ipc_server_stub_mock.cpp similarity index 32% rename from services/service/src/ipc/standard/ipc_server_listener.cpp rename to test/unittest/mock/ipc_server_stub_mock.cpp index b40ee0a405d49b3ee8a084a2eb4ea28a5e810c6e..67206d1a1e65a0372deaf75d5469fea752d74560 100644 --- a/services/service/src/ipc/standard/ipc_server_listener.cpp +++ b/test/unittest/mock/ipc_server_stub_mock.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,45 +13,24 @@ * limitations under the License. */ -#include "ipc_server_listener.h" - -#include "device_manager_ipc_interface_code.h" -#include "dm_error_type.h" -#include "dm_log.h" -#include "ipc_server_stub.h" +#include "ipc_server_stub_mock.h" namespace OHOS { namespace DistributedHardware { -int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) +DM_IMPLEMENT_SINGLE_INSTANCE(IpcServerStub); +const sptr IpcServerStub::GetDmListener(ProcessInfo processInfo) const { - if (rsp == nullptr || req == nullptr) { - return ERR_DM_INPUT_PARA_INVALID; - } - if (cmdCode < 0 || cmdCode >= IPC_MSG_BUTT) { - LOGE("IpcServerListener::SendRequest cmdCode param invalid!"); - return ERR_DM_UNSUPPORTED_IPC_COMMAND; - } - ProcessInfo processInfo = req->GetProcessInfo(); - if (processInfo.pkgName.empty()) { - LOGE("Invalid parameter, pkgName is empty."); - return ERR_DM_INPUT_PARA_INVALID; - } - sptr listener = IpcServerStub::GetInstance().GetDmListener(processInfo); - if (listener == nullptr) { - LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); - return ERR_DM_POINT_NULL; - } - return listener->SendCmd(cmdCode, req, rsp); + return DmIpcServerStub::dmIpcServerStub->GetDmListener(processInfo); } -std::vector IpcServerListener::GetAllProcessInfo() +std::vector IpcServerStub::GetAllProcessInfo() { - return IpcServerStub::GetInstance().GetAllProcessInfo(); + return DmIpcServerStub::dmIpcServerStub->GetAllProcessInfo(); } -std::set IpcServerListener::GetSystemSA() +std::set IpcServerStub::GetSystemSA() { - return IpcServerStub::GetInstance().GetSystemSA(); + return DmIpcServerStub::dmIpcServerStub->GetSystemSA(); } } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/service/include/ipc/standard/ipc_server_listener.h b/test/unittest/mock/ipc_server_stub_mock.h similarity index 43% rename from services/service/include/ipc/standard/ipc_server_listener.h rename to test/unittest/mock/ipc_server_stub_mock.h index fd6731f6e2b4adbab07b28899960b1113d87df7d..52a1360653cba737459659a54989aa0e1c5c59d9 100644 --- a/services/service/include/ipc/standard/ipc_server_listener.h +++ b/test/unittest/mock/ipc_server_stub_mock.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,36 +13,34 @@ * limitations under the License. */ -#ifndef OHOS_DM_IPC_SERVER_LISTENER_H -#define OHOS_DM_IPC_SERVER_LISTENER_H +#ifndef OHOS_IPC_SERVER_STUB_MOCK_H +#define OHOS_IPC_SERVER_STUB_MOCK_H -#include -#include "ipc_req.h" -#include "ipc_rsp.h" +#include +#include "ipc_server_stub.h" +#include "idevice_manager_ipc.h" namespace OHOS { namespace DistributedHardware { -class IpcServerListener { -public: - IpcServerListener() = default; - virtual ~IpcServerListener() = default; +class DmIpcServerStub { +public: + DmIpcServerStub() = default; + virtual ~DmIpcServerStub() = default; + virtual const sptr GetDmListener(ProcessInfo processInfo) const = 0; + virtual std::vector GetAllProcessInfo() = 0; + virtual std::set GetSystemSA() = 0; public: - /** - * @tc.name: IpcServerListener::SendRequest - * @tc.desc: Send Request of the Ipc Server Listener - * @tc.type: FUNC - */ - int32_t SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp); + static inline std::shared_ptr dmIpcServerStub = nullptr; +}; - /** - * @tc.name: IpcServerListener::GetAllProcessInfo - * @tc.desc: Get All PkgName from stub - * @tc.type: FUNC - */ - std::vector GetAllProcessInfo(); - std::set GetSystemSA(); +class IpcServerStubMock : public DmIpcServerStub { +public: + MOCK_METHOD(const sptr, GetDmListener, (ProcessInfo processInfo), (const)); + MOCK_METHOD((std::vector), GetAllProcessInfo, ()); + MOCK_METHOD((std::set), GetSystemSA, ()); }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_IPC_SERVER_LISTENER_H + +#endif \ No newline at end of file diff --git a/utils/BUILD.gn b/utils/BUILD.gn index b533b2e49bcbcb25f65a09f9c7df111d74186e46..507fd11b4612ad12e303709018d94cb11d303f5c 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -129,9 +129,12 @@ if (defined(ohos_lite)) { sources = [ "${common_path}/src/dm_anonymous.cpp", + "${innerkits_path}/native_cpp/src/dm_device_info.cpp", + "${innerkits_path}/native_cpp/src/dm_device_profile_info.cpp", "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", + "src/dm_ipc_utils.cpp", "src/dm_random.cpp", "src/jsonstr_handle/dm_jsonstr_handle.cpp", "src/kvadapter/dm_kv_info.cpp", @@ -209,11 +212,14 @@ if (defined(ohos_lite)) { ] sources = [ + "${innerkits_path}/native_cpp/src/dm_device_info.cpp", + "${innerkits_path}/native_cpp/src/dm_device_profile_info.cpp", "${common_path}/src/dm_anonymous.cpp", "${common_path}/src/dm_constants.cpp", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", "src/dm_random.cpp", + "src/dm_ipc_utils.cpp", "src/kvadapter/dm_kv_info.cpp", "src/kvadapter/kv_adapter.cpp", "src/kvadapter/kv_adapter_manager.cpp", diff --git a/utils/include/dm_ipc_utils.h b/utils/include/dm_ipc_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..1d06261bb66aaff5ce0338ea806d610f49d93a0e --- /dev/null +++ b/utils/include/dm_ipc_utils.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_DM_IPC_UTILS_H +#define OHOS_DM_IPC_UTILS_H + +#include +#include + +#include "dm_device_info.h" +#include "dm_device_profile_info.h" +namespace OHOS { +namespace DistributedHardware { + +class DmIpcUtils { +public: + static void ConvertToDmDeviceIconInfoExt(const DmDeviceIconInfo &base, DmDeviceIconInfoExt &ext); + static std::vector ConvertToDmDeviceProfileInfoExt( + const std::vector &baseVector); + static void ConvertToPeerTargetIdExt(const PeerTargetId &base, PeerTargetIdExt &ext); + static void ConvertToDmDeviceInfoExt(const DmDeviceInfo &base, DmDeviceInfoExt &ext); + static void ConvertToDmDeviceBasicInfoExt(const DmDeviceBasicInfo &base, DmDeviceBasicInfoExt &ext); + + static DmDeviceIconInfo ConvertToDmDeviceIconInfo(const DmDeviceIconInfoExt &ext); + static std::vector ConvertToDmDeviceProfileInfo( + const std::vector &extVector); + static PeerTargetId ConvertToPeerTargetId(const PeerTargetIdExt &ext); + static DmDeviceInfo ConvertToDmDeviceInfo(const DmDeviceInfoExt &ext); + static DmDeviceBasicInfo ConvertToDmDeviceBasicInfo(const DmDeviceBasicInfoExt &ext); + + static DmDeviceIconInfoExt ConvertToDmDeviceIconInfoExtWrapper(const DmDeviceIconInfo &base); + static std::vector + ConvertToDmDeviceProfileInfoExtWrapper(const std::vector &baseVector); + static PeerTargetIdExt ConvertToPeerTargetIdExtWrapper(const PeerTargetId &base); + static DmDeviceInfoExt ConvertToDmDeviceInfoExtWrapper(const DmDeviceInfo& base); + static DmDeviceBasicInfoExt ConvertToDmDeviceBasicInfoExtWrapper(const DmDeviceBasicInfo &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 0000000000000000000000000000000000000000..ff2d1e27bbe849b88a5b80b300020ecd26ac5b5d --- /dev/null +++ b/utils/src/dm_ipc_utils.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "dm_ipc_utils.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmIpcUtils::ConvertToDmDeviceIconInfoExt(const DmDeviceIconInfo& base, DmDeviceIconInfoExt& ext) +{ + ext.productId = base.productId; + ext.subProductId = base.subProductId; + ext.internalModel = base.internalModel; + ext.imageType = base.imageType; + ext.specName = base.specName; + ext.wiseVersion = base.wiseVersion; + ext.version = base.version; + ext.url = base.url; + ext.icon = base.icon; +} + +DmDeviceIconInfo DmIpcUtils::ConvertToDmDeviceIconInfo(const DmDeviceIconInfoExt& ext) +{ + DmDeviceIconInfo base; + base.productId = ext.productId; + base.subProductId = ext.subProductId; + base.internalModel = ext.internalModel; + base.imageType = ext.imageType; + base.specName = ext.specName; + base.wiseVersion = ext.wiseVersion; + base.version = ext.version; + base.url = ext.url; + base.icon = ext.icon; + return base; +} + +std::vector DmIpcUtils::ConvertToDmDeviceProfileInfoExt( + const std::vector &baseVector) +{ + std::vector tempVector; + tempVector.reserve(baseVector.size()); + for (const auto& base : baseVector) { + DmDeviceProfileInfoExt ext; + ext.deviceId = base.deviceId; + ext.deviceSn = base.deviceSn; + ext.mac = base.mac; + ext.model = base.model; + ext.internalModel = base.internalModel; + ext.deviceType = base.deviceType; + ext.manufacturer = base.manufacturer; + ext.deviceName = base.deviceName; + ext.productName = base.productName; + ext.productId = base.productId; + ext.subProductId = base.subProductId; + ext.sdkVersion = base.sdkVersion; + ext.bleMac = base.bleMac; + ext.brMac = base.brMac; + ext.sleMac = base.sleMac; + ext.firmwareVersion = base.firmwareVersion; + ext.hardwareVersion = base.hardwareVersion; + ext.softwareVersion = base.softwareVersion; + ext.protocolType = base.protocolType; + ext.setupType = base.setupType; + ext.wiseDeviceId = base.wiseDeviceId; + ext.wiseUserId = base.wiseUserId; + ext.registerTime = base.registerTime; + ext.modifyTime = base.modifyTime; + ext.shareTime = base.shareTime; + ext.isLocalDevice = base.isLocalDevice; + ext.services = base.services; + tempVector.push_back(ext); + } + return tempVector; +} + +std::vector DmIpcUtils::ConvertToDmDeviceProfileInfo( + const std::vector &extVector) +{ + std::vector tempVector; + tempVector.reserve(extVector.size()); + for (const auto& ext : extVector) { + 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.productName = ext.productName; + 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; + base.services = ext.services; + tempVector.push_back(base); + } + return tempVector; +} + +void DmIpcUtils::ConvertToPeerTargetIdExt(const PeerTargetId& base, PeerTargetIdExt& ext) +{ + ext.deviceId = base.deviceId; + ext.brMac = base.brMac; + ext.bleMac = base.bleMac; + ext.wifiIp = base.wifiIp; + ext.wifiPort = base.wifiPort; +} + +PeerTargetId 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; + return base; +} + +void DmIpcUtils::ConvertToDmDeviceInfoExt(const DmDeviceInfo& base, DmDeviceInfoExt& ext) +{ + memcpy_s(ext.deviceId, DM_MAX_DEVICE_ID_LEN, base.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(ext.deviceName, DM_MAX_DEVICE_NAME_LEN, base.deviceName, DM_MAX_DEVICE_NAME_LEN); + ext.deviceTypeId = base.deviceTypeId; + memcpy_s(ext.networkId, DM_MAX_DEVICE_ID_LEN, base.networkId, DM_MAX_DEVICE_ID_LEN); + ext.range = base.range; + ext.networkType = base.networkType; + ext.authForm = base.authForm; + ext.extraData = base.extraData; +} + +DmDeviceInfo DmIpcUtils::ConvertToDmDeviceInfo(const DmDeviceInfoExt& ext) +{ + DmDeviceInfo base; + memcpy_s(base.deviceId, DM_MAX_DEVICE_ID_LEN, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(base.deviceName, DM_MAX_DEVICE_NAME_LEN, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy_s(base.networkId, DM_MAX_DEVICE_ID_LEN, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.range = ext.range; + base.networkType = ext.networkType; + base.authForm = ext.authForm; + base.extraData = ext.extraData; + return base; +} + +void DmIpcUtils::ConvertToDmDeviceBasicInfoExt(const DmDeviceBasicInfo& base, DmDeviceBasicInfoExt& ext) +{ + memcpy_s(ext.deviceId, DM_MAX_DEVICE_ID_LEN, base.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(ext.deviceName, DM_MAX_DEVICE_NAME_LEN, base.deviceName, DM_MAX_DEVICE_NAME_LEN); + ext.deviceTypeId = base.deviceTypeId; + memcpy_s(ext.networkId, DM_MAX_DEVICE_ID_LEN, base.networkId, DM_MAX_DEVICE_ID_LEN); + ext.extraData = base.extraData; +} + +DmDeviceBasicInfo DmIpcUtils::ConvertToDmDeviceBasicInfo(const DmDeviceBasicInfoExt& ext) +{ + DmDeviceBasicInfo base; + memcpy_s(base.deviceId, DM_MAX_DEVICE_ID_LEN, ext.deviceId, DM_MAX_DEVICE_ID_LEN); + memcpy_s(base.deviceName, DM_MAX_DEVICE_NAME_LEN, ext.deviceName, DM_MAX_DEVICE_NAME_LEN); + base.deviceTypeId = ext.deviceTypeId; + memcpy_s(base.networkId, DM_MAX_DEVICE_ID_LEN, ext.networkId, DM_MAX_DEVICE_ID_LEN); + base.extraData = ext.extraData; + return base; +} + +DmDeviceIconInfoExt DmIpcUtils::ConvertToDmDeviceIconInfoExtWrapper(const DmDeviceIconInfo &base) +{ + DmDeviceIconInfoExt ext; + DmIpcUtils::ConvertToDmDeviceIconInfoExt(base, ext); + return ext; +} + +std::vector DmIpcUtils::ConvertToDmDeviceProfileInfoExtWrapper( + const std::vector &baseVector) +{ + std::vector extVector; + extVector.reserve(baseVector.size()); + extVector = DmIpcUtils::ConvertToDmDeviceProfileInfoExt(baseVector); + return extVector; +} + +PeerTargetIdExt DmIpcUtils::ConvertToPeerTargetIdExtWrapper(const PeerTargetId &base) +{ + PeerTargetIdExt ext; + DmIpcUtils::ConvertToPeerTargetIdExt(base, ext); + return ext; +} + +DmDeviceInfoExt DmIpcUtils::ConvertToDmDeviceInfoExtWrapper(const DmDeviceInfo& base) +{ + DmDeviceInfoExt ext; + DmIpcUtils::ConvertToDmDeviceInfoExt(base, ext); + return ext; +} + +DmDeviceBasicInfoExt DmIpcUtils::ConvertToDmDeviceBasicInfoExtWrapper(const DmDeviceBasicInfo &base) +{ + DmDeviceBasicInfoExt ext; + ConvertToDmDeviceBasicInfoExt(base, ext); + return ext; +} +} +} \ No newline at end of file