diff --git a/common/include/ipc/standard/ipc_remote_broker.h b/common/include/ipc/standard/ipc_remote_broker.h index 14853e6fddc31c056f41089df3066a3ad6923900..cef8c5c45439796935ee12d3288f59f1af651816 100644 --- a/common/include/ipc/standard/ipc_remote_broker.h +++ b/common/include/ipc/standard/ipc_remote_broker.h @@ -31,7 +31,7 @@ public: virtual int32_t SendCmd(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) = 0; public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.devicemanager"); + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedHardware.IDeviceServiceListenerIpc"); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 2068a5585b19c581039241a6e5110ae529ed7035..7a79415dec35c95ac8500fd7084778357ebb2806 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -146,6 +146,7 @@ if (defined(ohos_lite)) { "${devicemanager_path}/radar/include", "${utils_path}/include", "${json_path}/include", + "${devicemanager_path}/services/service/include", ] } @@ -181,6 +182,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 +190,7 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_client_stub.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "${devicemanager_path}/services/service/src/device_manager_notify_stub.cpp", ] public_configs = [ ":devicemanagersdk_config" ] @@ -200,7 +203,10 @@ if (defined(ohos_lite)) { "LOG_DOMAIN=0xD004111", ] - deps = [ "${json_path}:devicemanagerjson" ] + deps = [ + "${json_path}:devicemanagerjson", + "${devicemanager_path}/services/service: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 32892edcc098ad633956e9c7e8c483bd482bd5e2..6a29fe98b26fd20d663fa628673db90be41996f4 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,26 @@ 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 +242,23 @@ 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_ID_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 +347,40 @@ 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 */ @@ -407,6 +478,31 @@ typedef struct ProcessInfo { } } ProcessInfo; +typedef struct ProcessInfoExt : public ProcessInfo, public Parcelable { + using ProcessInfo::ProcessInfo; + + ProcessInfoExt(const ProcessInfo &processInfo) + { + userId = processInfo.userId; + pkgName = processInfo.pkgName; + } + + bool operator==(const ProcessInfoExt &other) const + { + return (userId == other.userId) && (pkgName == other.pkgName); + } + + bool operator<(const ProcessInfoExt &other) const + { + return (userId < other.userId) || + (userId == other.userId && pkgName < other.pkgName); + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static ProcessInfoExt *Unmarshalling(Parcel &parcel); +} ProcessInfoExt; + typedef struct DmNotifyKey { int32_t processUserId; std::string processPkgName; 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..22c56c8d79ffadf6bda202a3352b031dcbd47e84 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,27 @@ 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 = ""; @@ -101,6 +122,45 @@ 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); +} 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..5cb8491c76a905b442faa2d4d19257132beb1973 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 "device_manager_notify_stub.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/src/dm_device_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp index c80cbb4a4b72f9f5ce1096228e4d3b16335f732d..cd66e9f6a97eceaf535a21e8a3f8b6d69bff1ba6 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,141 @@ 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)); + return bRet; +} + +DmDeviceBasicInfoExt *DmDeviceBasicInfoExt::Unmarshalling(Parcel &parcel) +{ + DmDeviceBasicInfoExt *deviceBasicInfoExt = new (std::nothrow) DmDeviceBasicInfoExt(); + if (deviceBasicInfoExt == nullptr) { + LOGE("Create DmDeviceBasicInfoExt failed"); + return nullptr; + } + std::string deviceIdStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceId failed!"); + return nullptr; + } + std::string deviceNameStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceName failed!"); + return nullptr; + } + deviceBasicInfoExt->deviceTypeId = parcel.ReadUint16(); + std::string networkIdStr = parcel.ReadString(); + if (strcpy_s(deviceBasicInfoExt->networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s networkId failed!"); + return nullptr; + } + return deviceBasicInfoExt; +} + +bool 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; +} + +bool ProcessInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt32(userId)); + bRet = (bRet && parcel.WriteString(pkgName)); + return bRet; +} + +ProcessInfoExt *ProcessInfoExt::Unmarshalling(Parcel &parcel) +{ + auto *processInfoExt = new (std::nothrow) ProcessInfoExt(); + if (processInfoExt == nullptr) { + return nullptr; + } + + processInfoExt->userId = parcel.ReadInt32(); + processInfoExt->pkgName = parcel.ReadString(); + + return processInfoExt; +} } // 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..6a4fa3a5b3565c0b171976cda30393c95258e058 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_device_profile_info.cpp @@ -0,0 +1,163 @@ +/* + * 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" +namespace OHOS { +namespace DistributedHardware { +bool DmDeviceProfileInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(deviceSn)); + bRet = (bRet && parcel.WriteString(mac)); + bRet = (bRet && parcel.WriteString(model)); + bRet = (bRet && parcel.WriteString(internalModel)); + bRet = (bRet && parcel.WriteString(deviceType)); + bRet = (bRet && parcel.WriteString(manufacturer)); + bRet = (bRet && parcel.WriteString(deviceName)); + bRet = (bRet && parcel.WriteString(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)); + bRet = (bRet && parcel.WriteUint32(services.size())); + for (const auto &service : services) { + bRet = (bRet && parcel.WriteString(service.deviceId)); + bRet = (bRet && parcel.WriteString(service.serviceId)); + bRet = (bRet && parcel.WriteString(service.serviceType)); + bRet = (bRet && parcel.WriteUint32(service.data.size())); + for (const auto &entry : service.data) { + bRet = (bRet && parcel.WriteString(entry.first)); + bRet = (bRet && parcel.WriteString(entry.second)); + } + } + 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(); + + uint32_t servicesSize = parcel.ReadUint32(); + for (uint32_t i = 0; i < servicesSize; ++i) { + DmServiceProfileInfo service; + service.deviceId = parcel.ReadString(); + service.serviceId = parcel.ReadString(); + service.serviceType = parcel.ReadString(); + + uint32_t dataSize = parcel.ReadUint32(); + for (uint32_t j = 0; j < dataSize; ++j) { + std::string key = parcel.ReadString(); + std::string value = parcel.ReadString(); + service.data[key] = value; + } + + profileInfoExt->services.push_back(service); + } + + return profileInfoExt; +} + +bool DmDeviceIconInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(productId)); + bRet = (bRet && parcel.WriteString(subProductId)); + bRet = (bRet && parcel.WriteString(internalModel)); + bRet = (bRet && parcel.WriteString(imageType)); + bRet = (bRet && parcel.WriteString(specName)); + bRet = (bRet && parcel.WriteString(wiseVersion)); + bRet = (bRet && parcel.WriteString(version)); + bRet = (bRet && parcel.WriteString(url)); + bRet = (bRet && parcel.WriteUint32(icon.size())); + for (const auto &byte : icon) { + bRet = (bRet && parcel.WriteUint8(byte)); + } + return bRet; +} + +DmDeviceIconInfoExt *DmDeviceIconInfoExt::Unmarshalling(Parcel &parcel) +{ + auto *iconInfoExt = new (std::nothrow) DmDeviceIconInfoExt(); + if (iconInfoExt == nullptr) { + return nullptr; + } + + iconInfoExt->productId = parcel.ReadString(); + iconInfoExt->subProductId = parcel.ReadString(); + iconInfoExt->internalModel = parcel.ReadString(); + iconInfoExt->imageType = parcel.ReadString(); + iconInfoExt->specName = parcel.ReadString(); + iconInfoExt->wiseVersion = parcel.ReadString(); + iconInfoExt->version = parcel.ReadString(); + iconInfoExt->url = parcel.ReadString(); + + uint32_t iconSize = parcel.ReadUint32(); + for (uint32_t i = 0; i < iconSize; ++i) { + uint8_t byte = parcel.ReadUint8(); + iconInfoExt->icon.push_back(byte); + } + + return iconInfoExt; +} +} // 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 f912db8d9b4b7a98b7e23f8ff8101002f7bfa4fc..0b07cc3029d2182388ce4b9549fbcde38a89b382 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 @@ -31,7 +31,7 @@ #include "iservice_registry.h" #include "system_ability_definition.h" #include - +#include "device_manager_notify_stub.h" namespace OHOS { namespace DistributedHardware { void DmDeathRecipient::OnRemoteDied(const wptr &remote) @@ -73,6 +73,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; @@ -85,7 +86,7 @@ int32_t IpcClientManager::Init(const std::string &pkgName) return ret; } - sptr listener = sptr(new IpcClientStub()); + sptr listener = sptr(new DeviceManagerNotifyStub()); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); 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 a2e7cb3e1d9bf52842b98f1cce37635edd855e0d..c60db65533a99b7bf79b59c382f690933b2f421e 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 278ebade4d53d5d46cd43c5f43211105821592bf..812b2fb4b19f0dba3264c54ece5565f4f981d9af 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 @@ -675,7 +675,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/services/service/BUILD.gn b/services/service/BUILD.gn index c6d338d2fafeea7f9daae5f86fddc1164a82c1e5..ca9637e0bb2d9a08d7e2d5438f27e8c7f86a4551 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -11,10 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") if (defined(ohos_lite)) { import("//build/lite/config/component/lite_component.gni") } else { import("//build/ohos.gni") + import("//build/config/components/idl_tool/idl.gni") } import("//foundation/distributedhardware/device_manager/device_manager.gni") @@ -126,6 +128,33 @@ if (defined(ohos_lite)) { deps = [] } } else { +idl_gen_interface("device_manager_interface") { + src_idl = rebase_path("IDeviceServiceListenerIpc.idl") + log_tag = "devicemanagerservice" + log_domainid = "0xD004110" +} + +ohos_source_set("device_manager_ipc") { + sanitize = { + debug = false + cfi = true + cfi_cross_dso = true + } + output_values = get_target_outputs(":device_manager_interface") + sources = [] + sources += filter_include(output_values, [ "*.cpp" ]) + public_configs = [ ":devicemanagerservice_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" +} + config("devicemanagerservice_config") { include_dirs = [ "include", @@ -157,7 +186,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") { @@ -203,7 +234,10 @@ 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_notify_service.cpp", + "src/device_manager_notify_stub.cpp", "src/device_manager_service.cpp", "src/device_manager_service_listener.cpp", "src/devicenamemgr/device_name_change_monitor.cpp", @@ -213,7 +247,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", @@ -240,6 +273,7 @@ if (defined(ohos_lite)) { ] deps = [ + ":device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", @@ -347,6 +381,8 @@ if (defined(ohos_lite)) { "${common_path}/src/ipc/standard/ipc_cmd_register.cpp", "${common_path}/src/ipc/standard/ipc_model_codec.cpp", "src/advertise/advertise_manager.cpp", + "src/device_manager_notify_service.cpp", + "src/device_manager_notify_stub.cpp", "src/device_manager_service.cpp", "src/device_manager_service_listener.cpp", "src/devicenamemgr/device_name_change_monitor.cpp", @@ -356,7 +392,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", @@ -383,6 +418,7 @@ if (defined(ohos_lite)) { ] deps = [ + ":device_manager_ipc", "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", diff --git a/services/service/IDeviceServiceListenerIpc.idl b/services/service/IDeviceServiceListenerIpc.idl new file mode 100644 index 0000000000000000000000000000000000000000..293bd5f5beda0268ba4aa8a70f84af520fab0606 --- /dev/null +++ b/services/service/IDeviceServiceListenerIpc.idl @@ -0,0 +1,63 @@ +/* + * 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 DmDeviceInfo..OHOS.DistributedHardware.ProcessInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceProfileInfoExt; +sequenceable DmDeviceProfileInfo..OHOS.DistributedHardware.DmDeviceIconInfoExt; +interface OHOS.DistributedHardware.IDeviceServiceListenerIpc { +[ipccode 13] void ServerDeviceStateNotify([in] String pkgName, [in] int deviceState, [in] DmDeviceInfoExt dmDeviceInfoExt, + [in] DmDeviceBasicInfoExt dmDeviceBasicInfoExt, [in] ProcessInfoExt exprocessInfoExt); +[ipccode 14] void ServerDeviceFound([in] String pkgName, [in] unsigned short subscribeId, [in] DmDeviceInfoExt dmDeviceInfoExt, + [in] DmDeviceBasicInfoExt devBasicInfoExt, [in] ProcessInfoExt processInfoExt); +[ipccode 15] void ServerDeviceDiscovery([in] String pkgName, [in] short subscribeId, + [in] DmDeviceBasicInfoExt dmDeviceBasicInfoExt); +[ipccode 16] void ServerDiscoverFinish([in] String pkgName, [in] unsigned short subscribeId, [in] int failedReason, + [in] ProcessInfoExt processInfoExt); +[ipccode 17] void ServerPublishFinish([in] String pkgName, [in] int publishId, [in] int publishResult); +[ipccode 18] void ServerAuthResult([in] String pkgName, [in] String deviceId, [in] String token, [in] int status, [in] int reason, + [in] ProcessInfoExt processInfoExt); +[ipccode 22] void ServerDeviceFaNotify([in] String packagename, [in] String paramJson, [in] ProcessInfoExt processInfoExt); +[ipccode 23] void ServerCredentialResult([in] String pkgName, [in] int action, [in] String credentialResult, + [in] ProcessInfoExt processInfoExt); +[ipccode 44] void ServerCreatePinHolder([in] String pkgName, [in] String deviceId, [in] int pinType, [in] String payload, + [in] ProcessInfoExt processInfoExt); +[ipccode 45] void ServerDestroyPinHolder([in] String pkgName, [in] int pinType, [in] String payload, + [in] ProcessInfoExt processInfoExt); +[ipccode 46] void ServerCreatePinHolderResult([in] String pkgName, [in] int ret, [in] ProcessInfoExt processInfoExt); +[ipccode 47] void ServerDesTroyPinHolderResult([in] String pkgName, [in] int ret, [in] ProcessInfoExt processInfoExt); +[ipccode 48] void ServerOnPinHolderEvent([in] String pkgName, [in] int ret, [in] int pinHolderEvent, [in] String content, + [in] ProcessInfoExt processInfoExt); +[ipccode 57] void BindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, + [in] int status, [in] String content, [in] ProcessInfoExt processInfoExt); +[ipccode 58] void UnbindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, [in] String content, + [in] ProcessInfoExt processInfoExt); +[ipccode 67] void RemoteDeviceTrustChange([in] String pkgName, [in] String udid, [in] int authForm, [in] String uuid, + [in] ProcessInfoExt processInfoExt); +[ipccode 68] void ServerDeviceScreenStateNotify([in] String pkgName, [in] DmDeviceInfoExt dmDeviceInfoExt, + [in] ProcessInfoExt processInfoExt); +[ipccode 71] void ServerCredentialAuthStatusNotify([in] String pkgName, [in] String deviceList, [in] ProcessInfoExt processInfoExt, + [in] unsigned short deviceTypeId, [in] int err); +[ipccode 72] void SinkBindTargetResult([in] String pkgName, [in] PeerTargetIdExt targetIdExt, [in] int ret, [in] int status, + [in] String content, [in] ProcessInfoExt processInfoExt); +[ipccode 77] void GetDeviceProfileInfoListResult([in] String pkgName, [in] int code, [in] int deviceNum, + [in] List deviceProfileInfosExt, [in] ProcessInfoExt processInfoExt); +[ipccode 79] void GetDeviceIconInfoResult([in] String pkgName, [in] int code, [in] DmDeviceIconInfoExt deviceIconInfoExt, + [in] ProcessInfoExt processInfoExt); +[ipccode 83] void SetRemoteDeviceNameResult([in] String pkgName, [in] String deviceId, [in] int code, + [in] ProcessInfoExt processInfoExt); +[ipccode 85] void SetLocalDeviceNameResult([in] String pkgName, [in] int code, [in] ProcessInfoExt processInfoExt); +} \ No newline at end of file diff --git a/services/service/include/device_manager_notify_service.h b/services/service/include/device_manager_notify_service.h new file mode 100644 index 0000000000000000000000000000000000000000..d1b75dd89189152e3120ee14eab35472877f4a3d --- /dev/null +++ b/services/service/include/device_manager_notify_service.h @@ -0,0 +1,199 @@ +/* + * 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_service_listener_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_service_listener_ipc.h" +#include "device_manager_service_notify.h" +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotifyService : public DeviceServiceListenerIpcStub { + DM_DECLARE_SINGLE_INSTANCE_BASE(DeviceManagerNotifyService); +public: + DeviceManagerNotifyService(); + ~DeviceManagerNotifyService() = default; + + void RegisterSystemAbility(); + ErrCode ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt, + const ProcessInfoExt& exprocessInfoExt) override; + + ErrCode ServerDeviceFound( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &devBasicInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceDiscovery( + const std::string &pkgName, + short subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) override; + + ErrCode ServerDiscoverFinish( + const std::string &pkgName, + uint16_t subscribeId, + int32_t failedReason, + const ProcessInfoExt &processInfoExt) 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, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceFaNotify( + const std::string &packagename, + const std::string ¶mJson, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCredentialResult( + const std::string &pkgName, + int32_t action, + const std::string &credentialResult, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCreatePinHolder( + const std::string &pkgName, + const std::string &deviceId, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDestroyPinHolder( + const std::string &pkgName, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCreatePinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerOnPinHolderEvent( + const std::string &pkgName, + int32_t ret, + int32_t pinHolderEvent, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode BindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode UnbindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode RemoteDeviceTrustChange( + const std::string &pkgName, + const std::string &udid, + int32_t authForm, + const std::string &uuid, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceScreenStateNotify( + const std::string &pkgName, + const DmDeviceInfoExt &dmDeviceInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + const ProcessInfoExt &processInfoExt, + 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, + const ProcessInfoExt &processInfoExt) override; + + ErrCode GetDeviceProfileInfoListResult( + const std::string &pkgName, + int32_t code, + int32_t deviceNum, + const std::vector &deviceProfileInfosExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode SetRemoteDeviceNameResult( + const std::string &pkgName, + const std::string &deviceId, + int32_t code, + const ProcessInfoExt &processInfoExt) override; + + ErrCode SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code, + const ProcessInfoExt& processInfoExt) override; + +private: + DmPinType Int32ToDmPinType(int32_t value); + DmPinHolderEvent Int32ToDmPinHolderEvent(int32_t value); + DmAuthForm Int32ToDmAuthForm(int32_t value); + +private: + std::shared_ptr dmIpcUtils_; +}; + +} +} +#endif // DEVICE_MANAGER_NOTIFY_SERVICE_H diff --git a/services/service/include/device_manager_notify_stub.h b/services/service/include/device_manager_notify_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..a9a3c01aad172ff000dc9570c19fdac072549232 --- /dev/null +++ b/services/service/include/device_manager_notify_stub.h @@ -0,0 +1,180 @@ +/* + * 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_STUB_H + #define DEVICE_MANAGER_NOTIFY_STUB_H + + #include "device_service_listener_ipc_stub.h" + #include "dm_device_info.h" + #include "dm_device_profile_info.h" + #include "dm_ipc_utils.h" + #include "idevice_service_listener_ipc.h" + namespace OHOS { + namespace DistributedHardware { + class DeviceManagerNotifyStub : public DeviceServiceListenerIpcStub { + public: + DeviceManagerNotifyStub() {}; + ~DeviceManagerNotifyStub() = default; + + ErrCode ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt, + const ProcessInfoExt& exprocessInfoExt) override; + + ErrCode ServerDeviceFound( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &devBasicInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceDiscovery( + const std::string &pkgName, + short subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) override; + + ErrCode ServerDiscoverFinish( + const std::string &pkgName, + uint16_t subscribeId, + int32_t failedReason, + const ProcessInfoExt &processInfoExt) 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, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceFaNotify( + const std::string &packagename, + const std::string ¶mJson, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCredentialResult( + const std::string &pkgName, + int32_t action, + const std::string &credentialResult, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCreatePinHolder( + const std::string &pkgName, + const std::string &deviceId, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDestroyPinHolder( + const std::string &pkgName, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCreatePinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerOnPinHolderEvent( + const std::string &pkgName, + int32_t ret, + int32_t pinHolderEvent, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode BindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode UnbindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + const std::string &content, + const ProcessInfoExt &processInfoExt) override; + + ErrCode RemoteDeviceTrustChange( + const std::string &pkgName, + const std::string &udid, + int32_t authForm, + const std::string &uuid, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerDeviceScreenStateNotify( + const std::string &pkgName, + const DmDeviceInfoExt &dmDeviceInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + const ProcessInfoExt &processInfoExt, + 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, + const ProcessInfoExt &processInfoExt) override; + + ErrCode GetDeviceProfileInfoListResult( + const std::string &pkgName, + int32_t code, + int32_t deviceNum, + const std::vector &deviceProfileInfosExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt, + const ProcessInfoExt &processInfoExt) override; + + ErrCode SetRemoteDeviceNameResult( + const std::string &pkgName, + const std::string &deviceId, + int32_t code, + const ProcessInfoExt &processInfoExt) override; + + ErrCode SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code, + const ProcessInfoExt& processInfoExt) override; + }; + + } + } + #endif // DEVICE_MANAGER_NOTIFY_STUB_H + \ 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 fbf03d22ab075989afc2b3f3cefeca6d724a6801..a336ed46042d8abbfe039a2cb57eb926c3a69de0 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_service_listener_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, @@ -128,11 +129,12 @@ private: void RemoveNotExistProcess(); private: #if !defined(__LITEOS_M__) - IpcServerListener ipcServerListener_; static std::mutex alreadyNotifyPkgNameLock_; static std::map alreadyOnlinePkgName_; static std::unordered_set highPriorityPkgNameSet_; #endif +private: + std::shared_ptr ipcServerStub_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index 4756323015470d3d3237c4062accb45a41c08fe8..003716a8d6ef72fb1c5981d5c2a3c4e82819dafc 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_service_listener_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_notify_service.cpp b/services/service/src/device_manager_notify_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef413c7c6e3a9cc14bb1466dddd2b97d44cfcc17 --- /dev/null +++ b/services/service/src/device_manager_notify_service.cpp @@ -0,0 +1,433 @@ +/* + * 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 "device_manager_service.h" +#include "system_ability.h" +#include "system_ability_definition.h" +#include "iservice_registry.h" +namespace OHOS { +namespace DistributedHardware { +DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotifyService); +DeviceManagerNotifyService::DeviceManagerNotifyService() +{ + dmIpcUtils_ = std::make_shared(); + LOGI("DeviceManagerNotifyService constructor called."); +} + +void DeviceManagerNotifyService::RegisterSystemAbility() +{ + LOGI("Registering DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID system ability..."); + + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + LOGE("Failed to get SystemAbilityManager."); + return; + } + + int32_t ret = systemAbilityManager->AddSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, this); + if (ret != ERR_OK) { + LOGE("Failed to register DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, error code: %{public}d", ret); + return; + } + + LOGI("Successfully registered DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID."); +} + +ErrCode DeviceManagerNotifyService::ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt, + const ProcessInfoExt& exprocessInfoExt) +{ + LOGI("DM IDL DMNS::ServerDeviceStateNotify pkgName %{public}s", + exprocessInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + 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, + short subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) +{ + 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, + const ProcessInfoExt &processInfoExt) +{ + 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) +{ + 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, + const ProcessInfoExt &processInfoExt) +{ + 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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerDeviceFaNotify, pkgName: %{public}s, paramJson: %{public}s, packagename: %{public}s", + processInfoExt.pkgName.c_str(), 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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerCredentialResult %{public}s, action %{public}d, resultInfo %{public}s, pkgName %{public}s", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + 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(), processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerDestroyPinHolder : pkgName %{public}s, payload %{public}s", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerCreatePinHolderResult pkgName %{public}s, result %{public}d", + processInfoExt.pkgName.c_str(), ret); + DeviceManagerNotify::GetInstance().OnCreateResult(pkgName, ret); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerDesTroyPinHolderResult pkgName %{public}s, result %{public}d", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::ServerOnPinHolderEvent pkgName %{public}s, content %{public}s", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::BindTargetResult pkgName %{public}s, ret %{public}d, status %{public}d, content %{public}s.", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::UnbindTargetResult pkgName %{public}s, ret %{public}d, content %{public}s.", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + 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, + const ProcessInfoExt &processInfoExt) +{ + DmDeviceInfo dmDeviceInfo = dmIpcUtils_->ConvertToDmDeviceInfo(dmDeviceInfoExt); + DeviceManagerNotify::GetInstance().OnDeviceScreenStatus(pkgName, dmDeviceInfo); + return 0; +} + +ErrCode DeviceManagerNotifyService::ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + const ProcessInfoExt &processInfoExt, + uint16_t deviceTypeId, + int32_t err) +{ + LOGI("DM IDL DMNS::ServerCredentialAuthStatusNotify, pkgName = %{public}s, deviceList = %{public}s," + "deviceTypeId = %{public}u, err = %{public}d", + processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::OnSinkBindResult pkgName %{public}s, userId %{public}d.", + processInfoExt.pkgName.c_str(), processInfoExt.userId); + 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, + int32_t deviceNum, + const std::vector &deviceProfileInfosExt, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::GetDeviceProfileInfoListResult pkgName %{public}s.", processInfoExt.pkgName.c_str()); + std::vector deviceProfileInfos; + if (deviceNum > 0 && deviceNum <= MAX_DEVICE_PROFILE_SIZE) { + for (int32_t i = 0; i < deviceNum; ++i) { + DmDeviceProfileInfo deviceInfo; + dmIpcUtils_->ConvertToDmDeviceProfileInfo(deviceProfileInfos, deviceProfileInfosExt); + } + } + + DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, deviceProfileInfos, code); + return 0; +} + +ErrCode DeviceManagerNotifyService::GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::GetDeviceIconInfoResult pkgName %{public}s.", processInfoExt.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, + const ProcessInfoExt &processInfoExt) +{ + LOGI("DM IDL DMNS::SetRemoteDeviceNameResult pkgName %{public}s.", processInfoExt.pkgName.c_str()); + DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, code); + return 0; +} + +ErrCode DeviceManagerNotifyService::SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code, + const ProcessInfoExt& processInfoExt) +{ + LOGI("DM IDL DMNS::SetLocalDeviceNameResult pkgName %{public}s.", processInfoExt.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/src/device_manager_notify_stub.cpp b/services/service/src/device_manager_notify_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f882774310cec7d0cb3270c658a1f47e55cd2db --- /dev/null +++ b/services/service/src/device_manager_notify_stub.cpp @@ -0,0 +1,234 @@ +/* + * 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 "device_manager_notify_stub.h" + + namespace OHOS { + namespace DistributedHardware { + + ErrCode DeviceManagerNotifyStub::ServerDeviceStateNotify( + const std::string &pkgName, + int32_t deviceState, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt, + const ProcessInfoExt& exprocessInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDeviceFound( + const std::string &pkgName, + uint16_t subscribeId, + const DmDeviceInfoExt &dmDeviceInfoExt, + const DmDeviceBasicInfoExt &devBasicInfoExt, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDeviceDiscovery( + const std::string &pkgName, + short subscribeId, + const DmDeviceBasicInfoExt &dmDeviceBasicInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDiscoverFinish( + const std::string &pkgName, + uint16_t subscribeId, + int32_t failedReason, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerPublishFinish( + const std::string &pkgName, + int32_t publishId, + int32_t publishResult) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerAuthResult( + const std::string &pkgName, + const std::string &deviceId, + const std::string &token, + int32_t status, + int32_t reason, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDeviceFaNotify( + const std::string &packagename, + const std::string ¶mJson, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerCredentialResult( + const std::string &pkgName, + int32_t action, + const std::string &credentialResult, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerCreatePinHolder( + const std::string &pkgName, + const std::string &deviceId, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDestroyPinHolder( + const std::string &pkgName, + int32_t pinType, + const std::string &payload, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerCreatePinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDesTroyPinHolderResult( + const std::string &pkgName, + int32_t ret, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerOnPinHolderEvent( + const std::string &pkgName, + int32_t ret, + int32_t pinHolderEvent, + const std::string &content, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::BindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::UnbindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + const std::string &content, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::RemoteDeviceTrustChange( + const std::string &pkgName, + const std::string &udid, + int32_t authForm, + const std::string &uuid, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerDeviceScreenStateNotify( + const std::string &pkgName, + const DmDeviceInfoExt &dmDeviceInfoExt, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::ServerCredentialAuthStatusNotify( + const std::string &pkgName, + const std::string &deviceList, + const ProcessInfoExt &processInfoExt, + uint16_t deviceTypeId, + int32_t err) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::SinkBindTargetResult( + const std::string &pkgName, + const PeerTargetIdExt &targetIdExt, + int32_t ret, + int32_t status, + const std::string &content, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::GetDeviceProfileInfoListResult( + const std::string &pkgName, + int32_t code, + int32_t deviceNum, + const std::vector &deviceProfileInfosExt, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::GetDeviceIconInfoResult( + const std::string &pkgName, + int32_t code, + const DmDeviceIconInfoExt &deviceIconInfoExt, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::SetRemoteDeviceNameResult( + const std::string &pkgName, + const std::string &deviceId, + int32_t code, + const ProcessInfoExt &processInfoExt) + { + return 0; + } + + ErrCode DeviceManagerNotifyStub::SetLocalDeviceNameResult( + const std::string &pkgName, + int32_t code, + const ProcessInfoExt& processInfoExt) + { + return 0; + } + } + } \ No newline at end of file diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index d1d0a84b8377d0256468ec5d844b975814030128..57de493f5d6ea4365786ee3e53cea78a0d177870 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_; @@ -59,6 +61,12 @@ std::map DeviceManagerServiceListener::alreadyOnlineP std::unordered_set DeviceManagerServiceListener::highPriorityPkgNameSet_ = { "ohos.deviceprofile", "ohos.distributeddata.service" }; +DeviceManagerServiceListener::DeviceManagerServiceListener() +{ + LOGI("DeviceManagerServiceListener constructor called."); + ipcServerStub_ = std::make_shared(); +} + void handleExtraData(const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo) { cJSON *extraDataJsonObj = cJSON_Parse(info.extraData.c_str()); @@ -121,41 +129,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) { @@ -191,6 +164,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; @@ -225,11 +200,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_->GetAllProcessInfo(); switch (static_cast(state)) { case static_cast(DmDeviceState::DEVICE_STATE_ONLINE): ProcessAppOnline(processInfoVec, processInfo, state, info, deviceBasicInfo); @@ -249,6 +225,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)) { @@ -264,229 +242,262 @@ 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); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(deviceInfo, dmDeviceInfoExt); + DmDeviceBasicInfoExt devBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(devBasicInfo, devBasicInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerDeviceFound(processInfoExt.pkgName, subscribeId, dmDeviceInfoExt, + devBasicInfoExt, processInfoExt); } 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); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerDiscoverFinish(processInfoExt.pkgName, subscribeId, failedReason, + processInfoExt); } 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); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerDiscoverFinish(processInfoExt.pkgName, (uint16_t)subscribeId, DM_OK, + processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->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); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerAuthResult(processInfoExt.pkgName, deviceIdToUse, token, status, reason, + processInfoExt); } 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()); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerDeviceFaNotify(processInfoExt.pkgName, paramJson, processInfoExt); } 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()); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->ServerCredentialResult(processInfoExt.pkgName, action, resultInfo, processInfoExt); } 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; + PeerTargetIdExt targetIdExt; + DmIpcUtils::ConvertToPeerTargetIdExt(targetId, targetIdExt); + 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); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->BindTargetResult(processInfoExt.pkgName, returnTargetId, result, + status, content, processInfoExt); } 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()); + PeerTargetIdExt targetIdExt; + DmIpcUtils::ConvertToPeerTargetIdExt(targetId, targetIdExt); + PeerTargetId 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->UnbindTargetResult(processInfoExt.pkgName, returnTargetId, result, content, + processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerCreatePinHolder(processInfoExt.pkgName, deviceId, pinType, payload, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerDestroyPinHolder(processInfoExt.pkgName, pinType, payload, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerCreatePinHolderResult(processInfoExt.pkgName, result, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerDesTroyPinHolderResult(processInfoExt.pkgName, result, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerOnPinHolderEvent(processInfoExt.pkgName, result, event, content, processInfoExt); } #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"); @@ -512,6 +523,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"); @@ -529,10 +542,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(); @@ -540,60 +552,60 @@ 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; + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(item, processInfoExt); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + deviceServiceListenerIpc->RemoteDeviceTrustChange(processInfoExt.pkgName, udid, authForm, uuid, + processInfoExt); } - 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(); #endif 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); + for (const auto &item : processInfoVec) + { + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(devInfo, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(item, processInfoExt); + DmDeviceBasicInfoExt emptyDeviceBasicInfoExt; + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, 0, dmDeviceInfoExt, + emptyDeviceBasicInfoExt, processInfoExt); } } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(devInfo, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(item, processInfoExt); + DmDeviceBasicInfoExt emptyDeviceBasicInfoExt; + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, 0, dmDeviceInfoExt, + emptyDeviceBasicInfoExt, processInfoExt); } } } @@ -616,22 +628,26 @@ 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(); #endif 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); + for (const auto &item : processInfoVec) + { + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(item); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", item.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(item, processInfoExt); + deviceServiceListenerIpc->ServerCredentialAuthStatusNotify(processInfoExt.pkgName, deviceList, processInfoExt, + deviceTypeId, errcode); } } @@ -650,23 +666,23 @@ 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; + PeerTargetIdExt targetIdExt; + DmIpcUtils::ConvertToPeerTargetIdExt(targetId, targetIdExt); + PeerTargetId 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_->GetAllProcessInfo(); ProcessInfo processInfoTemp; for (auto item : processInfos) { if (item.pkgName == processInfo.pkgName) { @@ -677,17 +693,21 @@ 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfoTemp, processInfoExt); + deviceServiceListenerIpc->SinkBindTargetResult(processInfoExt.pkgName, returnTargetId, result, status, content, + processInfoExt); } 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 {}; @@ -715,6 +735,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 {}; @@ -725,8 +747,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_->GetAllProcessInfo(); + std::set systemSA = ipcServerStub_->GetSystemSA(); std::vector processInfosTemp; for (auto item : processInfos) { if (systemSA.find(item.pkgName) != systemSA.end()) { @@ -747,7 +769,7 @@ std::vector DeviceManagerServiceListener::GetNotifyProcessInfoByUse ProcessInfo DeviceManagerServiceListener::DealBindProcessInfo(const ProcessInfo &processInfo) { - std::set systemSA = ipcServerListener_.GetSystemSA(); + std::set systemSA = ipcServerStub_->GetSystemSA(); if (systemSA.find(processInfo.pkgName) == systemSA.end()) { return processInfo; } @@ -760,10 +782,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; @@ -775,8 +795,19 @@ void DeviceManagerServiceListener::ProcessDeviceOnline(const std::vector deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(it, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, notifyState, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } @@ -784,11 +815,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::string notifyPkgName = it.pkgName + "#" + std::to_string(it.userId) + "#" + std::string(info.deviceId); { @@ -799,8 +828,19 @@ void DeviceManagerServiceListener::ProcessDeviceOffline(const std::vector deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(it, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } @@ -808,13 +848,22 @@ 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(it, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } @@ -822,10 +871,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; @@ -837,9 +884,20 @@ void DeviceManagerServiceListener::ProcessAppOnline(const std::vector deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceServiceListenerIpc == 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); + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(it, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } @@ -847,11 +905,9 @@ 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); @@ -863,8 +919,19 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(it); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", it.pkgName.c_str()); + return; + } + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(it, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } else { std::string notifyPkgName = processInfo.pkgName + "#" + std::to_string(processInfo.userId) + "#" + @@ -877,8 +944,20 @@ void DeviceManagerServiceListener::ProcessAppOffline(const std::vector deviceServiceListenerIpc = + IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(info, dmDeviceInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, state, dmDeviceInfoExt, + dmDeviceBasicInfoExt, processInfoExt); } } @@ -898,6 +977,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); @@ -908,12 +989,22 @@ void DeviceManagerServiceListener::OnDevStateCallbackAdd(const ProcessInfo &proc } alreadyOnlinePkgName_[notifyPkgName] = item; } + sptr deviceServiceListenerIpc = + IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == 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); + DmDeviceInfoExt dmDeviceInfoExt; + DmIpcUtils::ConvertToDmDeviceInfoExt(item, dmDeviceInfoExt); + DmDeviceBasicInfoExt dmDeviceBasicInfoExt; + DmIpcUtils::ConvertToDmDeviceBasicInfoExt(deviceBasicInfo, dmDeviceBasicInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->ServerDeviceStateNotify(processInfoExt.pkgName, DmDeviceState::DEVICE_STATE_ONLINE, + dmDeviceInfoExt, dmDeviceBasicInfoExt, processInfoExt); } } @@ -941,52 +1032,41 @@ 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); -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) - std::string userDefinedDeviceName = DeviceNameManager::GetInstance().GetUserDefinedDeviceName(); - if (code == DM_OK && !userDefinedDeviceName.empty()) { - std::vector temVec = deviceProfileInfos; - for (auto &item : temVec) { - if (item.isLocalDevice) { - item.deviceName = userDefinedDeviceName; - break; - } - } - pReq->SetDeviceProfileInfoList(temVec); + LOGI("DM IDL DMSL::OnGetDeviceProfileInfoListResult pkgName %{public}s.", processInfo.pkgName.c_str()); + + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; } -#endif - pReq->SetResult(code); - pReq->SetProcessInfo(processInfo); - ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + std::vector deviceProfileInfosExt; + DmIpcUtils::ConvertToDmDeviceProfileInfoExt(deviceProfileInfos, deviceProfileInfosExt); + deviceServiceListenerIpc->GetDeviceProfileInfoListResult(processInfoExt.pkgName, code, 0, + deviceProfileInfosExt, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + DmDeviceIconInfoExt deviceIconInfoExt; + DmIpcUtils::ConvertToDmDeviceIconInfoExt(dmDeviceIconInfo, deviceIconInfoExt); + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->GetDeviceIconInfoResult(processInfoExt.pkgName, code, deviceIconInfoExt, processInfoExt); } 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); @@ -994,21 +1074,28 @@ void DeviceManagerServiceListener::OnSetLocalDeviceNameResult(const ProcessInfo #else (void) deviceName; #endif - ipcServerListener_.SendRequest(SET_LOCAL_DEVICE_NAME_RESULT, pReq, pRsp); + sptr deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->SetLocalDeviceNameResult(processInfoExt.pkgName, code, processInfoExt); } 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 deviceServiceListenerIpc = IpcServerStub::GetInstance().GetDmListener(processInfo); + if (deviceServiceListenerIpc == nullptr) { + LOGE("cannot get listener for package:%{public}s.", processInfo.pkgName.c_str()); + return; + } + ProcessInfoExt processInfoExt; + DmIpcUtils::ConvertToProcessInfoExt(processInfo, processInfoExt); + deviceServiceListenerIpc->SetRemoteDeviceNameResult(processInfoExt.pkgName, deviceId, code, processInfoExt); } std::string DeviceManagerServiceListener::GetLocalDisplayDeviceNameForPrivacy() diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 58517d1567c15030abaa37ca975a1aa5333b1c8b..55623fb43667fafb83720c9e14194ac5f59df548 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -49,6 +49,7 @@ #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "multiple_user_connector.h" #endif +#include "device_service_listener_ipc_proxy.h" namespace OHOS { namespace DistributedHardware { const unsigned int XCOLLIE_TIMEOUT_S = 5; @@ -184,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(); @@ -464,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 DeviceServiceListenerIpcProxy(listener)); if (callback == nullptr) { LOGE("create ipc server client proxy failed."); CancelXcollieTimer(timerId); @@ -785,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(); @@ -1073,121 +824,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(); @@ -1229,121 +865,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(); @@ -1370,41 +891,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(); @@ -1473,65 +959,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(); @@ -1579,42 +1006,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(); @@ -1664,42 +1055,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(); @@ -1733,35 +1088,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(); @@ -1845,36 +1171,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(); @@ -1888,41 +1184,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_listener.cpp b/services/service/src/ipc/standard/ipc_server_listener.cpp deleted file mode 100644 index b40ee0a405d49b3ee8a084a2eb4ea28a5e810c6e..0000000000000000000000000000000000000000 --- a/services/service/src/ipc/standard/ipc_server_listener.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "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" - -namespace OHOS { -namespace DistributedHardware { -int32_t IpcServerListener::SendRequest(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp) -{ - 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); -} - -std::vector IpcServerListener::GetAllProcessInfo() -{ - return IpcServerStub::GetInstance().GetAllProcessInfo(); -} - -std::set IpcServerListener::GetSystemSA() -{ - return IpcServerStub::GetInstance().GetSystemSA(); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index c85383af7292f05e11704bbdbc510063dd097d6b..a21b1c462961c3143b5f2baaa5eef830e5797f78 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -282,7 +282,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."); @@ -370,7 +371,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/commonfuzztest/ondatareceived_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn index dd80157794d06d5c381710448d812a825de7e44f..69c74db74cfe83f57bb919addf023feb9db32757 100644 --- a/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceived_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("OnDataReceivedFuzzTest") { sources = [ "on_data_received_fuzzer.cpp" ] deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", diff --git a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn index b81e1b47298dfc17c2d5288fd1d947d192304f19..57eaa74b7f83dfee2a91111cade59c3f5b1a13f0 100644 --- a/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn +++ b/test/commonfuzztest/ondatareceivedv2_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("OnDataReceivedV2FuzzTest") { sources = [ "on_data_received_fuzzer.cpp" ] deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservice", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutils", diff --git a/test/commonfuzztest/onerror_fuzzer/BUILD.gn b/test/commonfuzztest/onerror_fuzzer/BUILD.gn index 9d9d2801dca8be36635b71501fe25472f0f6f4bb..d82978df3d143ca4ce9e6222cf8c5717fca2d3da 100644 --- a/test/commonfuzztest/onerror_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onerror_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("OnErrorFuzzTest") { sources = [ "on_error_fuzzer.cpp" ] deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", diff --git a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn index 3881335e7ec7603209f9d3df225a0bfac04a99fc..a2614aac733f0c27444a5188482cf6668234dc6d 100644 --- a/test/commonfuzztest/onfinish_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onfinish_fuzzer/BUILD.gn @@ -44,6 +44,7 @@ ohos_fuzztest("OnFinishFuzzTest") { sources = [ "on_finish_fuzzer.cpp" ] deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", diff --git a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn index 34a301d7aee7e05919d7e95f7b072e3580581445..119b92c299d284ea1ded3e4c7dc528e86aa7057b 100644 --- a/test/commonfuzztest/onrequest_fuzzer/BUILD.gn +++ b/test/commonfuzztest/onrequest_fuzzer/BUILD.gn @@ -45,6 +45,7 @@ ohos_fuzztest("OnRequestFuzzTest") { sources = [ "on_request_fuzzer.cpp" ] deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservicetest", "${servicesimpl_path}:devicemanagerserviceimpl", "${utils_path}:devicemanagerutilstest", diff --git a/test/commonunittest/UTTest_dm_device_state_manager.cpp b/test/commonunittest/UTTest_dm_device_state_manager.cpp index 80aaf0bbf38f2d751c39ed2c7ce3387082572af4..b0d77a1be5eae0934c95ce9f937cb7e15d128869 100644 --- a/test/commonunittest/UTTest_dm_device_state_manager.cpp +++ b/test/commonunittest/UTTest_dm_device_state_manager.cpp @@ -80,31 +80,6 @@ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_002, testing::ext::TestS EXPECT_EQ(p, nullptr); } -/** - * @tc.name: OnDbReady_001 - * @tc.desc: set info.deviceId to some para, and return it - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(DmDeviceStateManagerTest, OnDbReady_001, testing::ext::TestSize.Level0) -{ - std::string pkgName; - std::string deviceId; - 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); -} - /** * @tc.name: RegisterOffLineTimer_001 * @tc.desc: call RegisterOffLineTimer diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 074d1cd33715a9f81bbaddd058e4493560e36ee3..afcd8616e154df9f56051ead5e84bd19d7d61b55 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -41,7 +41,6 @@ group("fuzztest") { "ipcclientmanager_fuzzer:fuzztest", "ipccmdregister_fuzzer:fuzztest", "ipcserverclientproxy_fuzzer:fuzztest", - "ipcserverlistener_fuzzer:fuzztest", "ipcserverstub_fuzzer:fuzztest", "notifyevent_fuzzer:fuzztest", "registerdevicemanagerfacallback_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn index 810c280fa413d44bfa645e6d74ccd78f7bb6bb3b..a4bbf9272c7071c28021ba9b27765f9977836172 100644 --- a/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authconfirm_fuzzer/BUILD.gn @@ -58,6 +58,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..848f35ba856355c0dca9a43ca47afee5b99fc20c 100644 --- a/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmanager_fuzzer/BUILD.gn @@ -58,6 +58,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..f01482900a022181e7921505f54bfe9f9822da42 100644 --- a/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/authmessageprocessor_fuzzer/BUILD.gn @@ -58,6 +58,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/ipcserverstub_fuzzer/BUILD.gn b/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn index a021875d7d5d56c2d21c49abe99fc350f4e6e78e..3c233954141363463e9bf48a5f45a62e776282f7 100644 --- a/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/ipcserverstub_fuzzer/BUILD.gn @@ -74,6 +74,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/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn index 872e0c8a2e6246e43ec7944faae911f92ad0c0ad..8ab843ec9b6c0b16cc425c27cba41c252719309b 100644 --- a/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onbytesreceived_fuzzer/BUILD.gn @@ -62,6 +62,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/softbussessionobject_fuzzer/BUILD.gn b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn index 7f61cc1610435e9f11573f65cb16b8ad34d6dc35..0e8615677a9fe3aa0482af9e3b5e577f1711b9e6 100644 --- a/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/softbussessionobject_fuzzer/BUILD.gn @@ -57,6 +57,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/unittest/BUILD.gn b/test/unittest/BUILD.gn index 4901c787a25e7b7b385bad8cfb3cb6578736629d..67741db8b9e25944b027c230aaac21e04beac436 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -41,7 +41,6 @@ group("unittest") { ":UTTest_device_manager_service_three", ":UTTest_device_name_manager", ":UTTest_discovery_filter", - ":UTTest_discovery_manager", ":UTTest_dm_account_common_event", ":UTTest_dm_adapter_manager", ":UTTest_dm_anonymous", @@ -82,10 +81,9 @@ group("unittest") { ":UTTest_ipc_cmd_parser_service", ":UTTest_ipc_cmd_register", ":UTTest_ipc_get_device_info_rsp", + ":UTTest_json_object", ":UTTest_ipc_server_client_proxy", - ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", - ":UTTest_json_object", ":UTTest_kv_adapter_manager", ":UTTest_mine_hichain_connector", ":UTTest_mine_softbus_listener", @@ -127,6 +125,7 @@ ohos_unittest("UTTest_pin_auth") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -154,6 +153,7 @@ ohos_unittest("UTTest_pin_auth_ui") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -180,6 +180,7 @@ ohos_unittest("UTTest_ipc_cmd_parser_client") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -213,8 +214,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", @@ -246,6 +247,7 @@ ohos_unittest("UTTest_ipc_cmd_register") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -274,6 +276,7 @@ ohos_unittest("UTTest_dm_pin_holder") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -290,6 +293,7 @@ ohos_unittest("UTTest_ipc_get_device_info_rsp") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -309,6 +313,7 @@ ohos_unittest("UTTest_dm_common_event_manager") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -326,6 +331,7 @@ ohos_unittest("device_manager_impl_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -361,6 +367,7 @@ ohos_unittest("UTTest_dm_credential_manager") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -402,6 +409,7 @@ ohos_unittest("UTTest_device_manager_service") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -429,6 +437,7 @@ ohos_unittest("UTTest_dm_softbus_cache") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -462,6 +471,7 @@ ohos_unittest("UTTest_device_manager_service_three") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -486,6 +496,7 @@ ohos_unittest("UTTest_device_manager_service_notify") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -508,6 +519,7 @@ ohos_unittest("UTTest_hichain_auth_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -533,6 +545,7 @@ ohos_unittest("UTTest_hichain_connector") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -555,6 +568,7 @@ ohos_unittest("UTTest_mine_hichain_connector") { "dsoftbus:softbus_client", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -591,6 +605,7 @@ ohos_unittest("UTTest_mine_softbus_listener") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "openssl:libcrypto_shared", + "safwk:system_ability_fwk", ] } @@ -623,6 +638,7 @@ ohos_unittest("UTTest_softbus_connector") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "os_account:libaccountkits", + "safwk:system_ability_fwk", ] } @@ -661,6 +677,7 @@ ohos_unittest("UTTest_softbus_listener") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -693,6 +710,7 @@ ohos_unittest("UTTest_softbus_listener_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -724,6 +742,7 @@ ohos_unittest("UTTest_softbus_publish") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -751,6 +770,7 @@ ohos_unittest("UTTest_softbus_session") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -768,6 +788,7 @@ ohos_unittest("UTTest_dm_adapter_manager") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -791,6 +812,7 @@ ohos_unittest("UTTest_dm_anonymous") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -811,6 +833,7 @@ ohos_unittest("UTTest_dm_timer") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -829,6 +852,7 @@ ohos_unittest("UTTest_dm_transport") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -846,6 +870,7 @@ ohos_unittest("UTTest_dm_transport_msg") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -862,6 +887,7 @@ ohos_unittest("UTTest_dm_service_load") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -880,6 +906,7 @@ ohos_unittest("UTTest_ipc_client_manager") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -897,6 +924,7 @@ ohos_unittest("UTTest_ipc_client_proxy") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -918,6 +946,7 @@ ohos_unittest("UTTest_ipc_client_stub") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1023,6 +1052,7 @@ ohos_unittest("UTTest_device_manager_impl") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] cflags = [ @@ -1054,6 +1084,7 @@ ohos_unittest("UTTest_dm_import_auth_code") { "googletest:gmock", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -1078,6 +1109,7 @@ ohos_unittest("UTTest_multiple_user_connector") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1107,6 +1139,7 @@ ohos_unittest("UTTest_permission_manager") { "googletest:gmock_main", "hilog:libhilog", "selinux_adapter:librestorecon", + "safwk:system_ability_fwk", ] } @@ -1166,6 +1199,7 @@ ohos_unittest("UTTest_device_manager_notify") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1183,6 +1217,7 @@ ohos_unittest("UTTest_ipc_client_server_proxy") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1208,6 +1243,7 @@ ohos_unittest("UTTest_dm_device_state_manager") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1237,6 +1273,7 @@ ohos_unittest("UTTest_dm_device_state_manager_two") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1257,6 +1294,7 @@ ohos_unittest("UTTest_dm_dfx") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1289,6 +1327,7 @@ ohos_unittest("UTTest_device_manager_service_impl") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1319,6 +1358,7 @@ ohos_unittest("UTTest_device_manager_service_impl_first") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1345,9 +1385,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", ] } @@ -1373,6 +1415,7 @@ ohos_unittest("UTTest_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1394,6 +1437,7 @@ ohos_unittest("UTTest_auth_response_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1415,6 +1459,7 @@ ohos_unittest("UTTest_auth_request_state") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1432,6 +1477,7 @@ ohos_unittest("ipc_client_manager_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1466,6 +1512,7 @@ ohos_unittest("UTTest_dm_auth_manager_first") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -1508,6 +1555,7 @@ ohos_unittest("UTTest_dm_auth_manager_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1532,6 +1580,7 @@ ohos_unittest("UTTest_dm_auth_manager_third") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] cflags = [ @@ -1566,6 +1615,7 @@ ohos_unittest("UTTest_dm_radar_helper_test") { "device_auth:deviceauth_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1591,6 +1641,7 @@ ohos_unittest("UTTest_discovery_filter") { "device_info_manager:distributed_device_profile_sdk", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1618,6 +1669,7 @@ ohos_unittest("UTTest_discovery_manager") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1649,6 +1701,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1678,6 +1731,7 @@ ohos_unittest("UTTest_dm_deviceprofile_connector_second") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1702,6 +1756,7 @@ ohos_unittest("UTTest_dm_distributed_hardware_load") { "googletest:gmock", "hilog:libhilog", "hitrace:hitrace_meter", + "safwk:system_ability_fwk", ] } @@ -1725,6 +1780,7 @@ ohos_unittest("UTTest_dm_comm_tool") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1743,6 +1799,7 @@ ohos_unittest("UTTest_dm_crypto") { external_deps = [ "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1760,7 +1817,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 }}} @@ -1781,6 +1841,7 @@ ohos_unittest("UTTest_dm_publish_common_event") { "bluetooth:btframework", "hilog:libhilog", "wifi:wifi_sdk", + "safwk:system_ability_fwk", ] } @@ -1802,6 +1863,7 @@ ohos_unittest("UTTest_dm_screen_common_event") { "bluetooth:btframework", "hilog:libhilog", "wifi:wifi_sdk", + "safwk:system_ability_fwk", ] } @@ -1822,6 +1884,7 @@ ohos_unittest("UTTest_relationship_sync_mgr") { "cJSON:cjson", "ffrt:libffrt", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1838,7 +1901,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 }}} @@ -1872,6 +1938,7 @@ ohos_unittest("UTTest_dp_inited_callback") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1898,6 +1965,7 @@ ohos_unittest("UTTest_kv_adapter_manager") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -1932,6 +2000,7 @@ ohos_unittest("UTTest_app_manager") { "hilog:libhilog", "os_account:libaccountkits", "os_account:os_account_innerkits", + "safwk:system_ability_fwk", ] } @@ -1950,7 +2019,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 }}} @@ -1982,6 +2054,7 @@ ohos_unittest("UTTest_device_name_manager") { "hilog:libhilog", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "safwk:system_ability_fwk", ] } @@ -2012,6 +2085,7 @@ ohos_unittest("UTTest_advertise_manager") { "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2029,6 +2103,7 @@ ohos_unittest("UTTest_mini_tools_kit") { "ffrt:libffrt", "googletest:gmock", "googletest:gmock_main", + "safwk:system_ability_fwk", ] } @@ -2047,6 +2122,7 @@ ohos_unittest("UTTest_json_object") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2076,6 +2152,7 @@ ohos_unittest("UTTest_auth_pin_auth_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2103,6 +2180,7 @@ ohos_unittest("UTTest_dm_auth_message_processor") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2134,6 +2212,7 @@ ohos_unittest("UTTest_auth_credential_state") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2165,6 +2244,7 @@ ohos_unittest("UTTest_auth_acl") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2199,6 +2279,7 @@ ohos_unittest("UTTest_auth_negotiate") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } @@ -2259,6 +2340,7 @@ ohos_unittest("UTTest_auth_confirm") { "googletest:gmock", "googletest:gmock_main", "hilog:libhilog", + "safwk:system_ability_fwk", ] } diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 4f654d2d4e797eecea27ab8cf69ac1a32ebb2353..3baa498a9cec3bbcb64911e819cee6643fbf2d84 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -692,19 +692,6 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceTrustChange_001, testing::ext 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(); @@ -1067,33 +1054,6 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnSinkBindResult_002, testing::ext::T 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, OpenAuthSessionWithPara_001, testing::ext::TestSize.Level1) -{ - const std::string deviceId = "OpenAuthSessionWithPara"; - int32_t actionId = 0; - bool isEnable160m = false; - std::shared_ptr listener_ = std::make_shared(); - int32_t ret = listener_->OpenAuthSessionWithPara(deviceId, actionId, isEnable160m); - EXPECT_NE(ret, DM_OK); -} } // namespace } // namespace DistributedHardware } // namespace OHOS 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_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index 67f91bd307d257e4801efb489f0035e909361e68..a98bbb59940ed183dd085e609aae0d5375302625 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -217,125 +217,6 @@ HWTEST_F(IpcServerStubTest, QueryServiceState_001, testing::ext::TestSize.Level0 ASSERT_EQ(state, ServiceRunningState::STATE_NOT_START); } -/** - * @tc.name: RegisterDeviceManagerListener_001 - * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener - * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_001, testing::ext::TestSize.Level0) -{ - std::string pkgName = ""; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = nullptr; - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - ASSERT_EQ(ret, ERR_DM_POINT_NULL); -} - -/** - * @tc.name: RegisterDeviceManagerListener_002 - * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener - * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_002, testing::ext::TestSize.Level0) -{ - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: RegisterDeviceManagerListener_003 - * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener - * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_003, testing::ext::TestSize.Level0) -{ - std::string pkgName = ""; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - ASSERT_EQ(ret, ERR_DM_POINT_NULL); -} - -/** - * @tc.name: RegisterDeviceManagerListener_004 - * @tc.desc: 1. Set PkgName is com.ohos.test - * 2. Call IpcServerStub RegisterDeviceManagerListener with param - * 3. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_004, testing::ext::TestSize.Level0) -{ - // 1. Set PkgName is com.ohos.test - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - // 2. Call IpcServerStub RegisterDeviceManagerListener with param - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - // 3. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); -} - -/** - * @tc.name: RegisterDeviceManagerListener_005 - * @tc.desc: 1. Set PkgName is com.ohos.test - * 2. Call IpcServerStub RegisterDeviceManagerListener with param - * 3. check ret is DM_OK - * 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener - * 5. check result is DM_OK - * 6. earse pkgName for appRecipient_ - * 7. check result is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_005, testing::ext::TestSize.Level0) -{ - // 1. Set PkgName is com.ohos.test - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - int result = 0; - sptr listener = sptr(new IpcClientStub()); - // 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()); - // 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()); - // 6. earse pkgName for appRecipient_ - IpcServerStub::GetInstance().appRecipient_.erase(processInfo); - result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener3); - // 7. check result is DM_OK - ASSERT_EQ(result, DM_OK); -} - /** * @tc.name: UnRegisterDeviceManagerListener_001 * @tc.desc: 1. Call IpcServerStub UnRegisterDeviceManagerListener @@ -351,36 +232,6 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_001, testing::ext::T ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } -/** - * @tc.name: UnRegisterDeviceManagerListener_002 - * @tc.desc: 1. Set PkgName is com.ohos.test - * 2. Call IpcServerStub RegisterDeviceManagerListener with param - * 3. check ret is DM_OK - * 4. Call IpcServerStub UnRegisterDeviceManagerListener - * 5. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_002, testing::ext::TestSize.Level0) -{ - // 1. Set PkgName is com.ohos.test - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - // 2. Call IpcServerStub RegisterDeviceManagerListener with param - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - // 3. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); - int result = 0; - // 4. Call IpcServerStub UnRegisterDeviceManagerListener - result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo); - // 5. check ret is DM_OK - ASSERT_EQ(result, DM_OK); -} - /** * @tc.name: UnRegisterDeviceManagerListener_003 * @tc.desc: 1. Set pkgName is com.ohos.test @@ -403,204 +254,6 @@ HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_003, testing::ext::T ASSERT_EQ(ret, DM_OK); } -/** - * @tc.name: UnRegisterDeviceManagerListener_004 - * @tc.desc: 1. Set PkgName is com.ohos.test - * 2. Call IpcServerStub RegisterDeviceManagerListener with param - * 3. check ret is DM_OK - * 4. Call IpcServerStub UnRegisterDeviceManagerListener - * 5. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_004, testing::ext::TestSize.Level0) -{ - // 1. Set PkgName is com.ohos.test - std::string pkgName = "com.ohos.test1"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - // 2. Call IpcServerStub RegisterDeviceManagerListener with param - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - // 3. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); - int result = 0; - // 4. Call IpcServerStub UnRegisterDeviceManagerListener - result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo); - // 5. check ret is DM_OK - ASSERT_EQ(result, DM_OK); - sptr dmListener = IpcServerStub::GetInstance().dmListener_[processInfo]; - ASSERT_EQ(dmListener, nullptr); -} - -/** - * @tc.name: UnRegisterDeviceManagerListener_005 - * @tc.desc: 1. Set PkgName is com.ohos.test - * 2. Call IpcServerStub RegisterDeviceManagerListener with param - * 3. check ret is DM_OK - * 4. Call IpcServerStub UnRegisterDeviceManagerListener - * 5. check ret is DM_OK - * 6. Call IpcServerStub UnRegisterDeviceManagerListener - * 7. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_005, testing::ext::TestSize.Level0) -{ - // 1. Set PkgName is com.ohos.test - std::string pkgName = "com.ohos.test2"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - processInfo.userId = 100; - int ret = 0; - sptr listener = sptr(new IpcClientStub()); - // 2. Call IpcServerStub RegisterDeviceManagerListener with param - ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, listener); - // 3. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); - int result = 0; - // 4. Call IpcServerStub UnRegisterDeviceManagerListener - std::string testPkgName = "com.test"; - result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo); - // 5. check ret is DM_OK - ASSERT_EQ(result, DM_OK); - IpcServerStub::GetInstance().appRecipient_.erase(processInfo); - // 6. Call IpcServerStub UnRegisterDeviceManagerListener - result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo); - // 7. check ret is DM_OK - ASSERT_EQ(result, DM_OK); -} - -/** - * @tc.name: GetDmListener_001 - * @tc.desc: 1. Set pkgName is com.ohos.test - * 2. Call IpcServerStub GetDmListener - * 3. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -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; - // 2. Call IpcServerStub UnRegisterDeviceManagerListener - ret = IpcServerStub::GetInstance().GetDmListener(processInfo); - // 3. check ret is DM_OK - ASSERT_EQ(ret, nullptr); -} - -/** - * @tc.name: GetDmListener_002 - * @tc.desc: 1. Set pkgName is com.ohos.test - * 2. Call IpcServerStub GetDmListener - * 3. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, GetDmListener_002, testing::ext::TestSize.Level0) -{ - // 1. Set pkgName is com.ohos.test - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - int result = 0; - sptr listener = sptr(new IpcClientStub()); - // 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; - // 2. Call IpcServerStub UnRegisterDeviceManagerListener - ret = IpcServerStub::GetInstance().GetDmListener(processInfo); - // 3. check ret is DM_OK - ASSERT_NE(ret, nullptr); -} - -/** - * @tc.name: GetDmListener_003 - * @tc.desc: 1. Set pkgName is com.ohos.test - * 2. Call IpcServerStub GetDmListener - * 3. check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, GetDmListener_003, testing::ext::TestSize.Level0) -{ - // 1. Set pkgName is com.ohos.test - std::string pkgName = "com.ohos.test"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - int result = 0; - sptr listener = sptr(new IpcClientStub()); - // 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; - // 2. Call IpcServerStub UnRegisterDeviceManagerListener - ret = IpcServerStub::GetInstance().GetDmListener(processInfo); - // 3. check ret is DM_OK - ASSERT_NE(ret, nullptr); -} - -/** - * @tc.name: GetDmListener_004 - * @tc.desc: 1. Set pkgName is com.ohos.test - * 2. Call IpcServerStub GetDmListener - * 3. check ret is ERR_DM_POINT_NULL - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, GetDmListener_004, testing::ext::TestSize.Level0) -{ - // 1. Set pkgName is null - std::string pkgName = ""; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - int result = 0; - sptr listener = sptr(new IpcClientStub()); - // 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; - // 2. Call IpcServerStub UnRegisterDeviceManagerListener - ret = IpcServerStub::GetInstance().GetDmListener(processInfo); - // 3. check ret is nullptr - ASSERT_EQ(ret, nullptr); -} - -/** - * @tc.name: GetDmListener_005 - * @tc.desc: 1. Set pkgName is com.ohos.test - * 2. Call IpcServerStub GetDmListener - * 3. check ret is ERR_DM_POINT_NULL - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(IpcServerStubTest, GetDmListener_005, testing::ext::TestSize.Level0) -{ - // 1. Set pkgName is null - std::string pkgName = "com.test.ohos"; - ProcessInfo processInfo; - processInfo.pkgName = pkgName; - int result = 0; - 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; - // 2. Call IpcServerStub UnRegisterDeviceManagerListener - ret = IpcServerStub::GetInstance().GetDmListener(processInfo); - // 3. check ret is nullptr - ASSERT_EQ(ret, nullptr); -} - /** * @tc.name: OnRemoveSystemAbility_001 * @tc.type: FUNC diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 7f4e0fe83efd156c1d13e2cca2b4c7fa15c707b5..560d78bf941f7dfe0ab5e8e2e3a6fb7d1f8ee580 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -125,8 +125,11 @@ 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", "src/appInfo/standard/app_manager.cpp", "src/crypto/dm_crypto.cpp", + "src/dm_ipc_utils.cpp", "src/dm_random.cpp", "src/kvadapter/dm_kv_info.cpp", "src/kvadapter/kv_adapter.cpp", diff --git a/services/service/include/ipc/standard/ipc_server_listener.h b/utils/include/dm_ipc_utils.h similarity index 30% rename from services/service/include/ipc/standard/ipc_server_listener.h rename to utils/include/dm_ipc_utils.h index fd6731f6e2b4adbab07b28899960b1113d87df7d..e42dcb42dc6558c5bd873988f41c6e649acfaeb5 100644 --- a/services/service/include/ipc/standard/ipc_server_listener.h +++ b/utils/include/dm_ipc_utils.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 @@ -12,37 +12,36 @@ * 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 -#ifndef OHOS_DM_IPC_SERVER_LISTENER_H -#define OHOS_DM_IPC_SERVER_LISTENER_H - -#include -#include "ipc_req.h" -#include "ipc_rsp.h" +#include +#include +#include "dm_device_info.h" +#include "dm_device_profile_info.h" namespace OHOS { namespace DistributedHardware { -class IpcServerListener { -public: - IpcServerListener() = default; - virtual ~IpcServerListener() = default; +class DmIpcUtils { 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 void ConvertToProcessInfoExt(const ProcessInfo &base, ProcessInfoExt &ext); + static void ConvertToDmDeviceIconInfoExt(const DmDeviceIconInfo &base, DmDeviceIconInfoExt &ext); + static void ConvertToDmDeviceProfileInfoExt(const std::vector &baseVector, + const std::vector &extVector); + static void ConvertToPeerTargetIdExt(const PeerTargetId &base, PeerTargetIdExt &ext); + static void ConvertToDmDeviceInfoExt(const DmDeviceInfo &base, DmDeviceInfoExt &ext); + static void ConvertToDmDeviceBasicInfoExt(const DmDeviceBasicInfo &base, DmDeviceBasicInfoExt &ext); - /** - * @tc.name: IpcServerListener::GetAllProcessInfo - * @tc.desc: Get All PkgName from stub - * @tc.type: FUNC - */ - std::vector GetAllProcessInfo(); - std::set GetSystemSA(); + static ProcessInfo ConvertToProcessInfo(ProcessInfoExt &ext); + static DmDeviceIconInfo ConvertToDmDeviceIconInfo(const DmDeviceIconInfoExt &ext); + static void ConvertToDmDeviceProfileInfo(const std::vector &baseVector, + const std::vector &extVector); + static PeerTargetId ConvertToPeerTargetId(const PeerTargetIdExt &ext); + static DmDeviceInfo ConvertToDmDeviceInfo(const DmDeviceInfoExt &ext); + static DmDeviceBasicInfo ConvertToDmDeviceBasicInfo(const DmDeviceBasicInfoExt &ext); }; + } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_IPC_SERVER_LISTENER_H +#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..ec38dcd0138c7ca278993605d057a13dd55db637 --- /dev/null +++ b/utils/src/dm_ipc_utils.cpp @@ -0,0 +1,206 @@ +/* + * 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::ConvertToProcessInfoExt(const ProcessInfo& base, ProcessInfoExt& ext) +{ + ext.userId = base.userId; + ext.pkgName = base.pkgName; +} + +ProcessInfo DmIpcUtils::ConvertToProcessInfo(ProcessInfoExt& ext) +{ + ProcessInfo base; + base.userId = ext.userId; + base.pkgName = ext.pkgName; + return base; +} + +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; +} + +void DmIpcUtils::ConvertToDmDeviceProfileInfoExt(const std::vector &baseVector, + const std::vector &extVector) +{ + 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); + } +} + +void DmIpcUtils::ConvertToDmDeviceProfileInfo(const std::vector &baseVector, + 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); + } +} + +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_ID_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_ID_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_ID_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_ID_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; +} +} +} \ No newline at end of file