diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 80a875a0ce3e758c3926dd6ac6bf83b8f6422272..9abaafaec8f94733f44b7a36f0bbefc7c61a79d8 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -98,6 +98,8 @@ enum DMIpcCmdInterfaceCode { SYNC_CALLBACK, GET_ANONY_LOCAL_UDID, REG_AUTHENTICATION_TYPE, + GET_DEVICE_PROFILE_INFO_LIST, + GET_DEVICE_PROFILE_INFO_LIST_RESULT, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index b31e4dee9edb125365f5b9a6e40a8a78ff08b6b7..ca3b153024c0a39ae426a4333ed6e3de5b0f2e16 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -122,7 +122,13 @@ enum { ERR_DM_SAVE_SESSION_KEY_FAILED = 96929821, ERR_DM_CRYPTO_OPT_FAILED = 96929822, ERR_DM_CRYPTO_PARA_INVALID = 96929823, - ERR_DM_SECURITY_FUNC_FAILED = 96929824 + ERR_DM_SECURITY_FUNC_FAILED = 96929824, + ERR_DM_MAX_SIZE_FAIL = 96929825, + ERR_DM_HILINKSVC_RSP_PARSE_FAILD = 96929826, + ERR_DM_HILINKSVC_REPLY_FAILED = 96929827, + ERR_DM_HILINKSVC_ICON_URL_EMPTY = 96929828, + ERR_DM_HILINKSVC_DISCONNECT = 96929829, + ERR_DM_WISE_NEED_LOGIN = 96929830 }; constexpr const char* TAG_GROUP_ID = "groupId"; @@ -277,6 +283,10 @@ const std::string CREATE_PINHOLDER = "CreatePinHolder"; const std::string DESTROY_PINHOLDER = "DestroyPinHolder"; const std::string SET_DNPOLICY = "SetDnPolicy"; const std::string BIND_FOR_DEVICE_LEVEL = "BindForDeviceLevel"; + +// wise device +constexpr int32_t MAX_DEVICE_PROFILE_SIZE = 500; +constexpr int32_t MAX_CONTAINER_SIZE = 500; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CONSTANTS_H \ No newline at end of file diff --git a/common/include/ipc/model/ipc_get_device_profile_info_list_req.h b/common/include/ipc/model/ipc_get_device_profile_info_list_req.h new file mode 100644 index 0000000000000000000000000000000000000000..0ea05cf5da90da84ce086e2ceb53c126ccab6ce9 --- /dev/null +++ b/common/include/ipc/model/ipc_get_device_profile_info_list_req.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_GET_DEVICE_PROFILE_INFO_LIST_REQ_H +#define OHOS_DM_IPC_GET_DEVICE_PROFILE_INFO_LIST_REQ_H + +#include "dm_device_profile_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetDeviceProfileInfoListReq : public IpcReq { + DECLARE_IPC_MODEL(IpcGetDeviceProfileInfoListReq); + +public: + /** + * @tc.name: IpcBindTargetReq::GetFirstParam + * @tc.desc: Ipc get first string parameter + * @tc.type: FUNC + */ + DmDeviceProfileInfoFilterOptions GetFilterOptions() const + { + return filterOptions_; + } + + /** + * @tc.name: IpcBindTargetReq::SetFirstParam + * @tc.desc: Ipc set first string parameter + * @tc.type: FUNC + */ + void SetFilterOptions(const DmDeviceProfileInfoFilterOptions &filterOptions) + { + filterOptions_ = filterOptions; + } + +private: + DmDeviceProfileInfoFilterOptions filterOptions_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GET_DEVICE_PROFILE_INFO_LIST_REQ_H diff --git a/common/include/ipc/model/ipc_notify_get_device_profile_info_list_req.h b/common/include/ipc/model/ipc_notify_get_device_profile_info_list_req.h new file mode 100644 index 0000000000000000000000000000000000000000..0231e3a624c76e4dc79dfd50efe429a435972916 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_get_device_profile_info_list_req.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_NOTIFY_GET_DEVICE_PROFILE_INFO_LIST_REQ_H +#define OHOS_DM_IPC_NOTIFY_GET_DEVICE_PROFILE_INFO_LIST_REQ_H + +#include "dm_device_profile_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyGetDeviceProfileInfoListReq : public IpcReq { + DECLARE_IPC_MODEL(IpcNotifyGetDeviceProfileInfoListReq); + +public: + std::vector GetDeviceProfileInfoList() const + { + return deviceProfileInfoList_; + } + + void SetDeviceProfileInfoList(const std::vector &deviceProfileInfoList) + { + deviceProfileInfoList_ = deviceProfileInfoList; + } + + /** + * @tc.desc: Ipc get result + * @tc.type: FUNC + */ + int32_t GetResult() const + { + return result_; + } + + /** + * @tc.desc: Ipc set result + * @tc.type: FUNC + */ + void SetResult(int32_t result) + { + result_ = result; + } + +private: + std::vector deviceProfileInfoList_ = {}; + int32_t result_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_NOTIFY_GET_DEVICE_PROFILE_INFO_LIST_REQ_H diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h new file mode 100644 index 0000000000000000000000000000000000000000..910f7c8dac559cc7560ad4ac7d1c31ae07964869 --- /dev/null +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_IPC_MODEL_CODEC_H +#define OHOS_DM_IPC_MODEL_CODEC_H + +#include "dm_device_profile_info.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcModelCodec { +public: + static int32_t DecodeDmDeviceProfileInfoFilterOptions(MessageParcel &parcel, + DmDeviceProfileInfoFilterOptions &filterOptions); + static bool EncodeDmDeviceProfileInfoFilterOptions(const DmDeviceProfileInfoFilterOptions &filterOptions, + MessageParcel &parcel); + static void DecodeDmProductInfo(MessageParcel &parcel, DmProductInfo &prodInfo); + static void DecodeDmServiceProfileInfo(MessageParcel &parcel, DmServiceProfileInfo &svrInfo); + static void DecodeDmServiceProfileInfos(MessageParcel &parcel, std::vector &svrInfos); + static void DecodeDmDeviceProfileInfo(MessageParcel &parcel, DmDeviceProfileInfo &devInfo); + static bool EncodeDmProductInfo(const DmProductInfo &prodInfo, MessageParcel &parcel); + static bool EncodeDmServiceProfileInfo(const DmServiceProfileInfo &svrInfo, MessageParcel &parcel); + static bool EncodeDmServiceProfileInfos(const std::vector &svrInfos, MessageParcel &parcel); + static bool EncodeDmDeviceProfileInfo(const DmDeviceProfileInfo &devInfo, MessageParcel &parcel); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_MODEL_CODEC_H diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48ea686d4ad0af3cc6eeff73d54fb8cefba23c8a --- /dev/null +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -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. + */ + +#include "ipc_model_codec.h" +#include "dm_constants.h" +#include "dm_log.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t IpcModelCodec::DecodeDmDeviceProfileInfoFilterOptions(MessageParcel &parcel, + DmDeviceProfileInfoFilterOptions &filterOptions) +{ + filterOptions.isCloud = parcel.ReadBool(); + size_t size = parcel.ReadUint32(); + if (size > MAX_DEVICE_PROFILE_SIZE) { + LOGE("size more than %{public}d,", MAX_DEVICE_PROFILE_SIZE); + return ERR_DM_IPC_WRITE_FAILED; + } + if (size > 0) { + for (uint32_t i = 0; i < size; i++) { + std::string item = parcel.ReadString(); + filterOptions.deviceIdList.emplace_back(item); + } + } + return DM_OK; +} + +bool IpcModelCodec::EncodeDmDeviceProfileInfoFilterOptions(const DmDeviceProfileInfoFilterOptions &filterOptions, + MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteBool(filterOptions.isCloud)); + uint32_t size = filterOptions.deviceIdList.size(); + bRet = (bRet && parcel.WriteUint32(size)); + if (bRet && size > 0) { + for (const auto& item : filterOptions.deviceIdList) { + bRet = (bRet && parcel.WriteString(item)); + } + } + return bRet; +} + +void IpcModelCodec::DecodeDmProductInfo(MessageParcel &parcel, DmProductInfo &prodInfo) +{ + prodInfo.prodId = parcel.ReadString(); + prodInfo.model = parcel.ReadString(); + prodInfo.prodName = parcel.ReadString(); + prodInfo.prodShortName = parcel.ReadString(); + prodInfo.imageVersion = parcel.ReadString(); +} + +void IpcModelCodec::DecodeDmServiceProfileInfo(MessageParcel &parcel, DmServiceProfileInfo &svrInfo) +{ + svrInfo.deviceId = parcel.ReadString(); + svrInfo.serviceId = parcel.ReadString(); + svrInfo.serviceType = parcel.ReadString(); + int32_t num = parcel.ReadInt32(); + if (num > 0 && num <= MAX_DEVICE_PROFILE_SIZE) { + for (int32_t i = 0; i < num; ++i) { + std::string key = parcel.ReadString(); + std::string value = parcel.ReadString(); + svrInfo.data[key] = value; + } + } +} + +void IpcModelCodec::DecodeDmServiceProfileInfos(MessageParcel &parcel, std::vector &svrInfos) +{ + int32_t svrNum = parcel.ReadInt32(); + if (svrNum > 0 && svrNum <= MAX_DEVICE_PROFILE_SIZE) { + for (int32_t i = 0; i < svrNum; ++i) { + DmServiceProfileInfo svrInfo; + DecodeDmServiceProfileInfo(parcel, svrInfo); + svrInfos.emplace_back(svrInfo); + } + } +} + +void IpcModelCodec::DecodeDmDeviceProfileInfo(MessageParcel &parcel, DmDeviceProfileInfo &devInfo) +{ + devInfo.deviceId = parcel.ReadString(); + devInfo.deviceSn = parcel.ReadString(); + devInfo.mac = parcel.ReadString(); + devInfo.model = parcel.ReadString(); + devInfo.innerModel = parcel.ReadString(); + devInfo.devType = parcel.ReadString(); + devInfo.manu = parcel.ReadString(); + devInfo.deviceName = parcel.ReadString(); + devInfo.prodId = parcel.ReadString(); + devInfo.subProdId = parcel.ReadString(); + devInfo.hiv = parcel.ReadString(); + devInfo.bleMac = parcel.ReadString(); + devInfo.sleMac = parcel.ReadString(); + devInfo.fwv = parcel.ReadString(); + devInfo.hwv = parcel.ReadString(); + devInfo.swv = parcel.ReadString(); + devInfo.protType = parcel.ReadInt32(); + devInfo.setupType = parcel.ReadInt32(); + devInfo.wiseDeviceId = parcel.ReadString(); + devInfo.wiseUserId = parcel.ReadString(); + devInfo.registerTime = parcel.ReadString(); + devInfo.modifyTime = parcel.ReadString(); + devInfo.shareTime = parcel.ReadString(); + devInfo.isLocalDevice = parcel.ReadBool(); + DecodeDmServiceProfileInfos(parcel, devInfo.services); +} + +bool IpcModelCodec::EncodeDmProductInfo(const DmProductInfo &prodInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(prodInfo.prodId)); + bRet = (bRet && parcel.WriteString(prodInfo.model)); + bRet = (bRet && parcel.WriteString(prodInfo.prodName)); + bRet = (bRet && parcel.WriteString(prodInfo.prodShortName)); + bRet = (bRet && parcel.WriteString(prodInfo.imageVersion)); + return bRet; +} + +bool IpcModelCodec::EncodeDmServiceProfileInfo(const DmServiceProfileInfo &svrInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(svrInfo.deviceId)); + bRet = (bRet && parcel.WriteString(svrInfo.serviceId)); + bRet = (bRet && parcel.WriteString(svrInfo.serviceType)); + if (bRet) { + if (!parcel.WriteInt32((int32_t)svrInfo.data.size())) { + return false; + } + for (const auto &[key, value] : svrInfo.data) { + if (!parcel.WriteString(key)) { + return false; + } + if (!parcel.WriteString(value)) { + return false; + } + } + } + return bRet; +} + +bool IpcModelCodec::EncodeDmServiceProfileInfos(const std::vector &svrInfos, + MessageParcel &parcel) +{ + if (!parcel.WriteInt32((int32_t)svrInfos.size())) { + return false; + } + for (const auto &svrInfo : svrInfos) { + if (!EncodeDmServiceProfileInfo(svrInfo, parcel)) { + LOGE("write dm service profile info failed"); + return false; + } + } + return true; +} + +bool IpcModelCodec::EncodeDmDeviceProfileInfo(const DmDeviceProfileInfo &devInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(devInfo.deviceId)); + bRet = (bRet && parcel.WriteString(devInfo.deviceSn)); + bRet = (bRet && parcel.WriteString(devInfo.mac)); + bRet = (bRet && parcel.WriteString(devInfo.model)); + bRet = (bRet && parcel.WriteString(devInfo.innerModel)); + bRet = (bRet && parcel.WriteString(devInfo.devType)); + bRet = (bRet && parcel.WriteString(devInfo.manu)); + bRet = (bRet && parcel.WriteString(devInfo.deviceName)); + bRet = (bRet && parcel.WriteString(devInfo.prodId)); + bRet = (bRet && parcel.WriteString(devInfo.subProdId)); + bRet = (bRet && parcel.WriteString(devInfo.hiv)); + bRet = (bRet && parcel.WriteString(devInfo.bleMac)); + bRet = (bRet && parcel.WriteString(devInfo.sleMac)); + bRet = (bRet && parcel.WriteString(devInfo.fwv)); + bRet = (bRet && parcel.WriteString(devInfo.hwv)); + bRet = (bRet && parcel.WriteString(devInfo.swv)); + bRet = (bRet && parcel.WriteInt32(devInfo.protType)); + bRet = (bRet && parcel.WriteInt32(devInfo.setupType)); + bRet = (bRet && parcel.WriteString(devInfo.wiseDeviceId)); + bRet = (bRet && parcel.WriteString(devInfo.wiseUserId)); + bRet = (bRet && parcel.WriteString(devInfo.registerTime)); + bRet = (bRet && parcel.WriteString(devInfo.modifyTime)); + bRet = (bRet && parcel.WriteString(devInfo.shareTime)); + bRet = (bRet && parcel.WriteBool(devInfo.isLocalDevice)); + bRet = (bRet && EncodeDmServiceProfileInfos(devInfo.services, parcel)); + return bRet; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 2a19130b756c757ee35fabad6f629beab58624ff..1012479bf39d16438545ab552484399dbeda43c7 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -166,6 +166,7 @@ if (defined(ohos_lite)) { "${common_path}/src/dfx/standard/dm_hitrace.cpp", "${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}/radar/src/dm_radar_helper.cpp", "src/device_manager.cpp", "src/device_manager_impl.cpp", diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 5dc128a3c0eadad9e93f592d607cb8994e170919..69f9e1968fd2c4f053b661da1d63943f9f6c52ef 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -23,6 +23,7 @@ #include "device_manager_callback.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_publish_info.h" #include "dm_subscribe_info.h" @@ -635,6 +636,16 @@ public: virtual int32_t UnRegisterSinkBindCallback(const std::string &pkgName) = 0; virtual int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) = 0; + + /** + * @brief Query the device list of same account. + * @param filterOptions query parameters. + * @param callback qeury result callback. + * @return Returns 0 if success. + */ + virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, + const DmDeviceProfileInfoFilterOptions &filterOptions, + std::shared_ptr callback) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 61989ccf34bfc9b969a1f17b7b2a52c16477d245..a24cff97aabdcac004618c7b54e0f3ca12df62a3 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -20,6 +20,7 @@ #include #include "dm_device_info.h" +#include "dm_device_profile_info.h" namespace OHOS { namespace DistributedHardware { @@ -113,6 +114,13 @@ public: virtual void OnCall(const std::string ¶mJson) = 0; }; +class GetDeviceProfileInfoListCallback { +public: + virtual ~GetDeviceProfileInfoListCallback() + {} + virtual void OnResult(const std::vector &deviceProfileInfos, int32_t code) = 0; +}; + class CredentialCallback { public: virtual ~CredentialCallback() diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index 324f721b93baddae7d768360d8135fc1889a057f..0219c265a66d16d9afa268fd61197910f4da0b7f 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -410,6 +410,10 @@ public: virtual int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam) override; + virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, + const DmDeviceProfileInfoFilterOptions &filterOptions, + std::shared_ptr callback) override; + private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; 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 new file mode 100644 index 0000000000000000000000000000000000000000..4d861b1984a726c0679c17d0f7fe722df861e387 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_DEVICE_PROFILE_INFO_H +#define OHOS_DM_DEVICE_PROFILE_INFO_H + +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +typedef struct DmProductInfo { + std::string prodId; + std::string model; + std::string prodName; + std::string prodShortName; + std::string imageVersion; +} DmProductInfo; + +typedef struct DmServiceProfileInfo { + std::string deviceId; + std::string serviceId; + std::string serviceType; + std::map data = {}; +} DmServiceProfileInfo; + +typedef struct DmDeviceProfileInfoFilterOptions { + bool isCloud; + std::vector deviceIdList = {}; +} DmDeviceProfileInfoFilterOptions; + +typedef struct DmDeviceProfileInfo { + std::string deviceId; + std::string deviceSn; + std::string mac; + std::string model; + std::string innerModel; + std::string devType; + std::string manu; + std::string deviceName; + std::string prodId; + std::string subProdId; + std::string hiv; + std::string bleMac; + std::string brMac; + std::string sleMac; + std::string fwv; + std::string hwv; + std::string swv; + int32_t protType; + int32_t setupType; + std::string wiseDeviceId; + std::string wiseUserId; + std::string registerTime; + std::string modifyTime; + std::string shareTime; + bool isLocalDevice; + std::vector services = {}; +} DmDeviceProfileInfo; + +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_DEVICE_PROFILE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h index 3ef077d6886f8ebe7f69fdc7a29b930fd8556285..51faf0bdd5ad9b9ef4f87c854b48e193a40d5ffc 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -22,6 +22,7 @@ #include "idevice_manager_service_listener.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "i_dm_bind_manager_ext_resident.h" namespace OHOS { @@ -103,6 +104,14 @@ public: virtual int32_t InitResident(std::shared_ptr residentCallback, const std::shared_ptr &listener) = 0; virtual void OnResidentBytesReceived(const int32_t sessionId, const std::string &message) = 0; + + /** + * @tc.name: IDMServiceImplExt::GetDeviceProfileInfos + * @tc.desc: GetDeviceProfileInfos + * @tc.type: FUNC + */ + virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, + const DmDeviceProfileInfoFilterOptions &filterOptions) = 0; }; using CreateDMServiceImplExtFuncPtr = IDMServiceImplExt *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index c07cc4a63c642c2168878565be5dc3969be694bd..5afdbc289fb19951e7c77d4a67c277f830656136 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -83,6 +83,14 @@ public: * @tc.type: FUNC */ virtual int32_t AccountUserSwitched(int32_t userId, const std::string &accountId) = 0; + + /** + * @tc.name: IDMServiceImplExt::GetDeviceProfileInfoList + * @tc.desc: GetDeviceProfileInfoList + * @tc.type: FUNC + */ + virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, + const DmDeviceProfileInfoFilterOptions &filterOptions) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h index 48f7c0fe52e7eb61de6cf769b5ed43057daaa9c7..fcacd4f2db00fa2e4308b8bf8d7c3c89ba348264 100644 --- a/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h +++ b/interfaces/inner_kits/native_cpp/include/idevice_manager_service_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -20,6 +20,7 @@ #include #include "dm_device_info.h" +#include "dm_device_profile_info.h" namespace OHOS { namespace DistributedHardware { @@ -165,6 +166,8 @@ public: virtual void OnProcessRemove(const ProcessInfo &processInfo) = 0; virtual void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) = 0; + virtual void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, + const std::vector &deviceProfileInfos, int32_t code) = 0; }; } // namespace DistributedHardware } // namespace OHOS 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 cf7be62ad40f1f50242fec1c1baecf8f62c573cc..98f1f8d269165a70c6706593e5a0a501b7956449 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -27,6 +27,7 @@ #include "device_manager_callback.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_subscribe_info.h" #include "dm_single_instance.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -77,6 +78,12 @@ public: void RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterSinkBindCallback(const std::string &pkgName); + int32_t RegisterGetDeviceProfileInfoListCallback(const std::string &pkgName, + std::shared_ptr callback); + int32_t UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName); + void OnGetDeviceProfileInfoListResult(const std::string &pkgName, + const std::vector &deviceProfileInfos, int32_t code); + public: static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); static void DeviceInfoOffline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); @@ -149,6 +156,7 @@ private: std::map> credentialAuthStatusCallback_; std::map> sinkBindTargetCallback_; std::mutex bindLock_; + std::map> getDeviceProfileInfoCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 3da3d1d080a49b119a0f051fc3f6d4e4d937b9d3..8f6e16dc4ec17b3319882f13f99a10f24444a355 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -38,6 +38,7 @@ #include "ipc_generate_encrypted_uuid_req.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_info_rsp.h" +#include "ipc_get_device_profile_info_list_req.h" #include "ipc_get_device_screen_status_req.h" #include "ipc_get_device_screen_status_rsp.h" #include "ipc_get_encrypted_uuid_req.h" @@ -62,6 +63,7 @@ #include "ipc_unpublish_req.h" #include "securec.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "ipc_model_codec.h" #include "iservice_registry.h" #include "system_ability_definition.h" #endif @@ -2583,5 +2585,34 @@ int32_t DeviceManagerImpl::RegisterAuthenticationType(const std::string &pkgName LOGI("Completed"); return DM_OK; } + +int32_t DeviceManagerImpl::GetDeviceProfileInfoList(const std::string &pkgName, + const DmDeviceProfileInfoFilterOptions &filterOptions, std::shared_ptr callback) +{ + LOGI("In pkgName:%{public}s, isCloud:%{public}d", pkgName.c_str(), filterOptions.isCloud); + int32_t ret = DeviceManagerNotify::GetInstance().RegisterGetDeviceProfileInfoListCallback(pkgName, callback); + if (ret != DM_OK) { + LOGE("register callback error, ret: %{public}d", ret); + return ret; + } + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetFilterOptions(filterOptions); + ret = ipcClientProxy_->SendRequest(GET_DEVICE_PROFILE_INFO_LIST, req, rsp); + if (ret != DM_OK) { + LOGE("error: Send Request failed ret: %{public}d", ret); + DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("error: Failed with ret %{public}d", ret); + DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); + return ret; + } + LOGI("Completed"); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index e5bbebb130c8d428878be5c4c4122056ddc03226..d6d58d5fdbd91750d1271310539a0ae97c649738 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -18,6 +18,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_log.h" #include "ipc_acl_profile_req.h" #include "ipc_authenticate_device_req.h" @@ -33,6 +34,7 @@ #include "ipc_generate_encrypted_uuid_req.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_info_rsp.h" +#include "ipc_get_device_profile_info_list_req.h" #include "ipc_get_device_screen_status_req.h" #include "ipc_get_device_screen_status_rsp.h" #include "ipc_get_encrypted_uuid_req.h" @@ -42,6 +44,7 @@ #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_import_auth_code_req.h" +#include "ipc_model_codec.h" #include "ipc_notify_event_req.h" #include "ipc_register_listener_req.h" #include "ipc_req.h" @@ -2066,7 +2069,6 @@ ON_IPC_READ_RESPONSE(SYNC_CALLBACK, MessageParcel &reply, std::shared_ptrSetErrCode(reply.ReadInt32()); return DM_OK; } - ON_IPC_SET_REQUEST(REG_AUTHENTICATION_TYPE, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -2096,5 +2098,54 @@ ON_IPC_READ_RESPONSE(REG_AUTHENTICATION_TYPE, MessageParcel &reply, std::shared_ pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pReq = + std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!IpcModelCodec::EncodeDmDeviceProfileInfoFilterOptions(pReq->GetFilterOptions(), data)) { + LOGE("write filterOptions failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST, 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(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; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file 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 ad9113f72f5e6cd7260edd92dbb5904081c456d8..5cec47532208891d2007d8997c44fa36a882d785 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -1242,5 +1242,51 @@ void DeviceManagerNotify::GetCallBack(std::map callback) +{ + LOGI("In, pkgName: %{public}s.", pkgName.c_str()); + std::lock_guard autoLock(bindLock_); + if (getDeviceProfileInfoCallback_.size() > MAX_CONTAINER_SIZE) { + LOGI("callback map size is more than max size"); + return ERR_DM_MAX_SIZE_FAIL; + } + getDeviceProfileInfoCallback_[pkgName] = callback; + return DM_OK; +} + +int32_t DeviceManagerNotify::UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName) +{ + LOGI("In, pkgName: %{public}s.", pkgName.c_str()); + std::lock_guard autoLock(bindLock_); + getDeviceProfileInfoCallback_.erase(pkgName); + return DM_OK; +} + +void DeviceManagerNotify::OnGetDeviceProfileInfoListResult(const std::string &pkgName, + const std::vector &deviceProfileInfos, int32_t code) +{ + if (pkgName.empty()) { + LOGE("Invalid para, pkgName: %{public}s.", pkgName.c_str()); + return; + } + LOGI("In, pkgName:%{public}s, code:%{public}d", pkgName.c_str(), code); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(bindLock_); + if (getDeviceProfileInfoCallback_.count(pkgName) == 0) { + LOGE("error, callback not register for pkgName %{public}s.", pkgName.c_str()); + return; + } + tempCbk = getDeviceProfileInfoCallback_[pkgName]; + getDeviceProfileInfoCallback_.erase(pkgName); + } + if (tempCbk == nullptr) { + LOGE("error, registered GetDeviceProfileInfoList callback is nullptr."); + return; + } + tempCbk->OnResult(deviceProfileInfos, code); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js4.0/include/dm_native_util.h b/interfaces/kits/js4.0/include/dm_native_util.h index 5ddde1ede626cbfba3906031dd4a727a1fc7e085..83eec5e75670a3d1582be3b73704e6f10493ec7f 100644 --- a/interfaces/kits/js4.0/include/dm_native_util.h +++ b/interfaces/kits/js4.0/include/dm_native_util.h @@ -22,6 +22,7 @@ #include #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_publish_info.h" #include "napi/native_api.h" #include "napi/native_node_api.h" @@ -46,6 +47,10 @@ enum DMBussinessErrorCode { DM_ERR_DISCOVERY_INVALID = 11600104, // Publish invalid. DM_ERR_PUBLISH_INVALID = 11600105, + // Get data from cloud failed. + DM_ERR_FROM_CLOUD_FAILED = 11600106, + // Need Login. + DM_ERR_NEED_LOGIN = 11600107, }; void DeviceBasicInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, @@ -67,6 +72,18 @@ bool CheckArgsType(napi_env env, bool assertion, const std::string ¶mName, c bool IsFunctionType(napi_env env, napi_value value); void DmDeviceBasicToJsObject(napi_env env, const DmDeviceBasicInfo &vecDevInfo, napi_value &result); bool JsToStringAndCheck(napi_env env, napi_value value, const std::string &valueName, std::string &strValue); + +void JsObjectToStrVector(const napi_env &env, const napi_value &object, const std::string &fieldStr, + std::vector &fieldRef); +void JsToDmDeviceProfileInfoFilterOptions(const napi_env &env, const napi_value &object, + DmDeviceProfileInfoFilterOptions &info); +void DmServiceProfileInfoToJsArray(const napi_env &env, const std::vector &svrInfos, + napi_value &arrayResult); +void DmProductInfoToJs(const napi_env &env, const DmProductInfo &prodInfos, napi_value &jsObj); +void DmDeviceProfileInfoToJs(const napi_env &env, const DmDeviceProfileInfo &devInfo, napi_value &jsObj); +void DmDeviceProfileInfoToJsArray(const napi_env &env, const std::vector &devInfos, + napi_value &arrayResult); + } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_NATIVE_UTIL_H diff --git a/interfaces/kits/js4.0/include/native_devicemanager_js.h b/interfaces/kits/js4.0/include/native_devicemanager_js.h index 4e2e12e1e4e469824b92f1757a93872318514fad..0bf3d53f482d8383e9444215e29a4173dd9ed97f 100644 --- a/interfaces/kits/js4.0/include/native_devicemanager_js.h +++ b/interfaces/kits/js4.0/include/native_devicemanager_js.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -23,6 +23,7 @@ #include "device_manager_callback.h" #include "dm_app_image_info.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_native_event.h" #include "dm_subscribe_info.h" #include "dm_publish_info.h" @@ -61,6 +62,16 @@ struct DeviceBasicInfoListAsyncCallbackInfo { int32_t ret = 0; }; +struct DeviceProfileInfosAsyncCallbackInfo { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + std::string bundleName; + napi_deferred deferred = nullptr; + int32_t code = -1; + OHOS::DistributedHardware::DmDeviceProfileInfoFilterOptions filterOptions; + std::vector deviceProfileInfos; +}; + struct AuthAsyncCallbackInfo { napi_env env = nullptr; @@ -212,6 +223,23 @@ private: std::string bundleName_; }; +class DmNapiGetDeviceProfileInfoListCallback : public OHOS::DistributedHardware::GetDeviceProfileInfoListCallback { +public: + explicit DmNapiGetDeviceProfileInfoListCallback(napi_env env, const std::string &bundleName, + const napi_deferred &deferred) : env_(env), bundleName_(bundleName), deferred_(deferred) + { + } + ~DmNapiGetDeviceProfileInfoListCallback() override {}; + + void OnResult(const std::vector &deviceProfileInfos, + int32_t code) override; + +private: + napi_env env_; + std::string bundleName_; + napi_deferred deferred_ = nullptr; +}; + class DeviceManagerNapi : public DmNativeEvent { public: explicit DeviceManagerNapi(napi_env env, napi_value thisVar); @@ -239,6 +267,7 @@ public: static napi_value UnBindTarget(napi_env env, napi_callback_info info); static napi_value JsOn(napi_env env, napi_callback_info info); static napi_value JsOff(napi_env env, napi_callback_info info); + static napi_value JsGetDeviceProfileInfoList(napi_env env, napi_callback_info info); static DeviceManagerNapi *GetDeviceManagerNapi(std::string &bundleName); static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType); static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType, std::string &extra); @@ -250,6 +279,7 @@ public: void OnPublishResult(int32_t publishId, int32_t publishResult); void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason); void OnDmUiCall(const std::string ¶mJson); + void OnGetDeviceProfileInfoListCallbackResult(DeviceProfileInfosAsyncCallbackInfo *jsCallback); private: static void ReleasePublishCallback(std::string &bundleName); @@ -272,6 +302,7 @@ private: const std::string &bindParam, std::shared_ptr callback); static void RegisterDevStatusCallback(napi_env env, std::string &bundleName); static int32_t DumpDeviceInfo(DeviceBasicInfoListAsyncCallbackInfo *deviceBasicInfoListAsyncCallbackInfo); + static napi_value GetDeviceProfileInfoListPromise(napi_env env, DeviceProfileInfosAsyncCallbackInfo *jsCallback); private: napi_env env_; diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 189d4b49d31a794ed2cacb5f2ee84e1dfa5d10fa..3b3cd8041cf88010657658247702a9238850c2fe 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -35,6 +35,8 @@ const std::string ERR_MESSAGE_OBTAIN_SERVICE = "Failed to obtain the service."; const std::string ERR_MESSAGE_AUTHENTICALTION_INVALID = "Authentication invalid."; const std::string ERR_MESSAGE_DISCOVERY_INVALID = "Discovery invalid."; const std::string ERR_MESSAGE_PUBLISH_INVALID = "Publish invalid."; +const std::string ERR_MESSAGE_FROM_CLOUD_FAILED = "Get data from cloud failed."; +const std::string ERR_MESSAGE_NEED_LOGIN = "A login account is required."; const int32_t DM_NAPI_DISCOVER_EXTRA_INIT_ONE = -1; const int32_t DM_NAPI_DISCOVER_EXTRA_INIT_TWO = -2; @@ -83,6 +85,8 @@ void JsObjectToBool(const napi_env &env, const napi_value &object, const std::st napi_get_value_bool(env, field, &fieldRef); } else { LOGE("devicemanager napi js to bool no property: %{public}s", fieldStr.c_str()); + std::string errMsg = ERR_MESSAGE_INVALID_PARAMS + " no property " + fieldStr; + napi_throw_error(env, std::to_string(ERR_INVALID_PARAMS).c_str(), errMsg.c_str()); } } @@ -205,6 +209,7 @@ napi_value CreateBusinessError(napi_env env, int32_t errCode, bool isAsync) break; case ERR_DM_INPUT_PARA_INVALID: case ERR_DM_UNSUPPORTED_AUTH_TYPE: + case ERR_DM_MAX_SIZE_FAIL: error = CreateErrorForCall(env, ERR_INVALID_PARAMS, ERR_MESSAGE_INVALID_PARAMS, isAsync); break; case ERR_DM_INIT_FAILED: @@ -213,6 +218,15 @@ napi_value CreateBusinessError(napi_env env, int32_t errCode, bool isAsync) case ERR_NOT_SYSTEM_APP: error = CreateErrorForCall(env, ERR_NOT_SYSTEM_APP, ERR_MESSAGE_NOT_SYSTEM_APP, isAsync); break; + case ERR_DM_HILINKSVC_RSP_PARSE_FAILD: + case ERR_DM_HILINKSVC_REPLY_FAILED: + case ERR_DM_HILINKSVC_ICON_URL_EMPTY: + case ERR_DM_HILINKSVC_DISCONNECT: + error = CreateErrorForCall(env, DM_ERR_FROM_CLOUD_FAILED, ERR_MESSAGE_FROM_CLOUD_FAILED, isAsync); + break; + case ERR_DM_WISE_NEED_LOGIN: + error = CreateErrorForCall(env, DM_ERR_NEED_LOGIN, ERR_MESSAGE_NEED_LOGIN, isAsync); + break; default: error = CreateErrorForCall(env, DM_ERR_FAILED, ERR_MESSAGE_FAILED, isAsync); break; @@ -473,5 +487,141 @@ bool JsToStringAndCheck(napi_env env, napi_value value, const std::string &value strValue = temp; return true; } + +void JsObjectToStrVector(const napi_env &env, const napi_value &object, const std::string &fieldStr, + std::vector &fieldRef) +{ + bool hasProperty = false; + NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); + if (!hasProperty) { + LOGE("no property: %{public}s", fieldStr.c_str()); + return; + } + + napi_value field = nullptr; + napi_get_named_property(env, object, fieldStr.c_str(), &field); + bool isArr = false; + napi_is_array(env, field, &isArr); + if (!isArr) { + LOGE("property: %{public}s is not array", fieldStr.c_str()); + return; + } + uint32_t length = 0; + napi_get_array_length(env, field, &length); + for (size_t i = 0; i < length; i++) { + napi_value element; + napi_get_element(env, field, i, &element); + size_t strLen = 0; + napi_get_value_string_utf8(env, element, nullptr, 0, &strLen); + if (strLen == 0) { + continue; + } + char buf[DEVICE_UUID_LENGTH] = {0}; + napi_get_value_string_utf8(env, element, buf, strLen + 1, &strLen); + fieldRef.emplace_back(buf); + } +} + +void JsToDmDeviceProfileInfoFilterOptions(const napi_env &env, const napi_value &object, + DmDeviceProfileInfoFilterOptions &info) +{ + napi_valuetype filterOptionsType; + napi_typeof(env, object, &filterOptionsType); + if (filterOptionsType != napi_object) { + LOGE("filterOptions is not object"); + std::string errMsg = ERR_MESSAGE_INVALID_PARAMS + " The type of filterOptions must be object"; + napi_throw_error(env, std::to_string(ERR_INVALID_PARAMS).c_str(), errMsg.c_str()); + return; + } + bool isCloud = false; + JsObjectToBool(env, object, "isCloud", isCloud); + info.isCloud = isCloud; + std::vector deviceIdList; + JsObjectToStrVector(env, object, "deviceIdList", deviceIdList); + info.deviceIdList = deviceIdList; +} + +void DmServiceProfileInfoToJsArray(const napi_env &env, const std::vector &svrInfos, + napi_value &arrayResult) +{ + for (unsigned int i = 0; i < svrInfos.size(); i++) { + napi_value item = nullptr; + napi_create_object(env, &item); + SetValueUtf8String(env, "deviceId", svrInfos[i].deviceId, item); + SetValueUtf8String(env, "serviceId", svrInfos[i].serviceId, item); + SetValueUtf8String(env, "serviceType", svrInfos[i].serviceType, item); + napi_value data = nullptr; + napi_create_object(env, &data); + for (const auto& [key, value] : svrInfos[i].data) { + SetValueUtf8String(env, key, value, data); + } + napi_set_named_property(env, item, "data", data); + napi_status status = napi_set_element(env, arrayResult, i, item); + if (status != napi_ok) { + LOGE("DmServiceProfileInfoToJsArray To JsArray set element error: %{public}d", status); + } + } +} + +void DmProductInfoToJs(const napi_env &env, const DmProductInfo &prodInfo, napi_value &jsObj) +{ + SetValueUtf8String(env, "prodId", prodInfo.prodId, jsObj); + SetValueUtf8String(env, "model", prodInfo.model, jsObj); + SetValueUtf8String(env, "prodName", prodInfo.prodName, jsObj); + SetValueUtf8String(env, "prodShortName", prodInfo.prodShortName, jsObj); +} + +void DmDeviceProfileInfoToJs(const napi_env &env, const DmDeviceProfileInfo &devInfo, napi_value &jsObj) +{ + SetValueUtf8String(env, "deviceId", devInfo.deviceId, jsObj); + SetValueUtf8String(env, "deviceSn", devInfo.deviceSn, jsObj); + SetValueUtf8String(env, "mac", devInfo.mac, jsObj); + SetValueUtf8String(env, "model", devInfo.model, jsObj); + SetValueUtf8String(env, "devType", devInfo.devType, jsObj); + SetValueUtf8String(env, "manu", devInfo.manu, jsObj); + SetValueUtf8String(env, "deviceName", devInfo.deviceName, jsObj); + SetValueUtf8String(env, "prodId", devInfo.prodId, jsObj); + SetValueUtf8String(env, "subProdId", devInfo.subProdId, jsObj); + SetValueUtf8String(env, "hiv", devInfo.hiv, jsObj); + SetValueUtf8String(env, "bleMac", devInfo.bleMac, jsObj); + SetValueUtf8String(env, "brMac", devInfo.brMac, jsObj); + SetValueUtf8String(env, "sleMac", devInfo.sleMac, jsObj); + SetValueUtf8String(env, "fwv", devInfo.fwv, jsObj); + SetValueUtf8String(env, "hwv", devInfo.hwv, jsObj); + SetValueUtf8String(env, "swv", devInfo.swv, jsObj); + SetValueInt32(env, "protType", devInfo.protType, jsObj); + SetValueInt32(env, "setupType", devInfo.setupType, jsObj); + SetValueUtf8String(env, "wiseDeviceId", devInfo.wiseDeviceId, jsObj); + SetValueUtf8String(env, "wiseUserId", devInfo.wiseUserId, jsObj); + SetValueUtf8String(env, "registerTime", devInfo.registerTime, jsObj); + SetValueUtf8String(env, "modifyTime", devInfo.modifyTime, jsObj); + SetValueUtf8String(env, "shareTime", devInfo.shareTime, jsObj); + SetValueInt32(env, "isLocalDevice", devInfo.isLocalDevice ? 1 : 0, jsObj); +} + +void DmDeviceProfileInfoToJsArray(const napi_env &env, const std::vector &devInfos, + napi_value &arrayResult) +{ + for (unsigned int i = 0; i < devInfos.size(); i++) { + napi_value item = nullptr; + napi_create_object(env, &item); + DmDeviceProfileInfoToJs(env, devInfos[i], item); + if (!devInfos[i].services.empty()) { + napi_value services = nullptr; + napi_create_array(env, &services); + bool isArray = false; + napi_is_array(env, services, &isArray); + if (!isArray) { + LOGE("napi_create_array failed"); + } + DmServiceProfileInfoToJsArray(env, devInfos[i].services, services); + napi_set_named_property(env, item, "services", services); + } + napi_status status = napi_set_element(env, arrayResult, i, item); + if (status != napi_ok) { + LOGE("DmDeviceProfileInfo To JsArray set element error: %{public}d", status); + } + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 88e602eb947f32da7ec4f3b223e23f8d8510e0bc..e01c6dc53ee850462365f33233851e2f5fd56aa8 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -23,6 +23,7 @@ #include "device_manager.h" #include "dm_constants.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_log.h" #include "dm_native_util.h" #include "ipc_skeleton.h" @@ -112,7 +113,7 @@ bool IsDeviceManagerNapiNull(napi_env env, napi_value thisVar, DeviceManagerNapi return false; } CreateBusinessError(env, ERR_DM_POINT_NULL); - LOGE(" DeviceManagerNapi object is nullptr!"); + LOGE("DeviceManagerNapi object is nullptr!"); return true; } } // namespace @@ -540,6 +541,56 @@ void DmNapiAuthenticateCallback::OnAuthResult(const std::string &deviceId, const } } +void DmNapiGetDeviceProfileInfoListCallback::OnResult(const std::vector &deviceProfileInfos, + int32_t code) +{ + LOGI("In code:%{public}d, size:%{public}zu", code, deviceProfileInfos.size()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + LOGE("get loop fail"); + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + LOGE("OnResult, No memory"); + return; + } + auto *jsCallback = new DeviceProfileInfosAsyncCallbackInfo(); + if (jsCallback == nullptr) { + LOGE("create jsCallback fail"); + DeleteUvWork(work); + return; + } + jsCallback->env = env_; + jsCallback->bundleName = bundleName_; + jsCallback->deferred = deferred_; + jsCallback->deviceProfileInfos = deviceProfileInfos; + jsCallback->code = code; + work->data = reinterpret_cast(jsCallback); + int ret = uv_queue_work_with_qos(loop, work, [] (uv_work_t *work) { + LOGD("OnResult uv_queue_work_with_qos"); + }, [] (uv_work_t *work, int status) { + DeviceProfileInfosAsyncCallbackInfo *callback = + reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName); + if (deviceManagerNapi == nullptr) { + LOGE("deviceManagerNapi not find for bundleName %{public}s", callback->bundleName.c_str()); + } else { + deviceManagerNapi->OnGetDeviceProfileInfoListCallbackResult(callback); + } + delete callback; + callback = nullptr; + DeleteUvWork(work); + }, uv_qos_user_initiated); + if (ret != 0) { + LOGE("Failed to execute OnBindResult work queue"); + delete jsCallback; + jsCallback = nullptr; + DeleteUvWork(work); + } +} + DeviceManagerNapi::DeviceManagerNapi(napi_env env, napi_value thisVar) : DmNativeEvent(env, thisVar) { env_ = env; @@ -672,6 +723,34 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str napi_close_handle_scope(env_, scope); } +void DeviceManagerNapi::OnGetDeviceProfileInfoListCallbackResult(DeviceProfileInfosAsyncCallbackInfo *jsCallback) +{ + LOGI("In"); + napi_handle_scope scope; + napi_open_handle_scope(env_, &scope); + if (jsCallback->code != DM_OK) { + napi_value error = CreateBusinessError(env_, jsCallback->code, false); + napi_reject_deferred(env_, jsCallback->deferred, error); + LOGE("jsCallback->code(%{public}d) != DM_OK", jsCallback->code); + napi_close_handle_scope(env_, scope); + return; + } + napi_value devInfosJsObj; + napi_create_array(env_, &devInfosJsObj); + bool isArray = false; + napi_is_array(env_, devInfosJsObj, &isArray); + if (!isArray) { + LOGE("napi_create_array failed"); + napi_value error = CreateBusinessError(env_, ERR_DM_POINT_NULL, false); + napi_reject_deferred(env_, jsCallback->deferred, error); + napi_close_handle_scope(env_, scope); + return; + } + DmDeviceProfileInfoToJsArray(env_, jsCallback->deviceProfileInfos, devInfosJsObj); + napi_resolve_deferred(env_, jsCallback->deferred, devInfosJsObj); + napi_close_handle_scope(env_, scope); +} + void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType) { LOGI("CreateDmCallback for bundleName %{public}s eventType %{public}s", bundleName.c_str(), eventType.c_str()); @@ -1832,6 +1911,91 @@ napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info) } } +napi_value DeviceManagerNapi::GetDeviceProfileInfoListPromise(napi_env env, + DeviceProfileInfosAsyncCallbackInfo *asyncCallback) +{ + LOGI("In"); + napi_value promise = 0; + napi_deferred deferred; + napi_create_promise(env, &deferred, &promise); + asyncCallback->deferred = deferred; + napi_value workName; + napi_create_string_latin1(env, "GetDeviceProfileInfosPromise", NAPI_AUTO_LENGTH, &workName); + napi_create_async_work(env, nullptr, workName, + [](napi_env env, void *data) { + DeviceProfileInfosAsyncCallbackInfo *jsCallback = + reinterpret_cast(data); + std::shared_ptr callback = + std::make_shared(jsCallback->env, jsCallback->bundleName, + jsCallback->deferred); + int32_t ret = DeviceManager::GetInstance().GetDeviceProfileInfoList(jsCallback->bundleName, + jsCallback->filterOptions, callback); + jsCallback->code = ret; + if (ret != DM_OK) { + LOGE("GetDeviceProfileInfos failed, bundleName:%{public}s, ret=%{public}d", + jsCallback->bundleName.c_str(), ret); + } + }, + [](napi_env env, napi_status status, void *data) { + (void)status; + DeviceProfileInfosAsyncCallbackInfo *jsCallback = + reinterpret_cast(data); + if (jsCallback->code != DM_OK) { + napi_value error = CreateBusinessError(env, jsCallback->code, false); + napi_reject_deferred(env, jsCallback->deferred, error); + } + napi_delete_async_work(env, jsCallback->asyncWork); + delete jsCallback; + jsCallback = nullptr; + }, + (void *)asyncCallback, &asyncCallback->asyncWork); + napi_queue_async_work_with_qos(env, asyncCallback->asyncWork, napi_qos_user_initiated); + return promise; +} + +napi_value DeviceManagerNapi::JsGetDeviceProfileInfoList(napi_env env, napi_callback_info info) +{ + LOGI("In"); + if (!IsSystemApp()) { + LOGE("Caller is not systemApp"); + CreateBusinessError(env, static_cast(DMBussinessErrorCode::ERR_NOT_SYSTEM_APP)); + return nullptr; + } + int32_t ret = DeviceManager::GetInstance().CheckAPIAccessPermission(); + if (ret != DM_OK) { + CreateBusinessError(env, ret); + return nullptr; + } + + size_t argc = 0; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); + if (!CheckArgsCount(env, argc >= DM_NAPI_ARGS_ONE, "Wrong number of arguments, required 1")) { + return nullptr; + } + DeviceManagerNapi *deviceManagerWrapper = nullptr; + if (IsDeviceManagerNapiNull(env, thisVar, &deviceManagerWrapper)) { + LOGE("deviceManagerWrapper is NULL"); + CreateBusinessError(env, ERR_DM_POINT_NULL); + return nullptr; + } + napi_value argv[DM_NAPI_ARGS_ONE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); + DmDeviceProfileInfoFilterOptions filterOptions; + JsToDmDeviceProfileInfoFilterOptions(env, argv[0], filterOptions); + auto *jsCallback = new DeviceProfileInfosAsyncCallbackInfo(); + if (jsCallback == nullptr) { + LOGE("jsCallback is nullptr"); + CreateBusinessError(env, ERR_DM_POINT_NULL); + return nullptr; + } + + jsCallback->env = env; + jsCallback->bundleName = deviceManagerWrapper->bundleName_; + jsCallback->filterOptions = filterOptions; + return GetDeviceProfileInfoListPromise(env, jsCallback); +} + void DeviceManagerNapi::ClearBundleCallbacks(std::string &bundleName) { LOGI("ClearBundleCallbacks start for bundleName %{public}s", bundleName.c_str()); @@ -1992,7 +2156,8 @@ napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("bindTarget", BindTarget), DECLARE_NAPI_FUNCTION("replyUiAction", SetUserOperationSync), DECLARE_NAPI_FUNCTION("on", JsOn), - DECLARE_NAPI_FUNCTION("off", JsOff)}; + DECLARE_NAPI_FUNCTION("off", JsOff), + DECLARE_NAPI_FUNCTION("getDeviceProfileInfoList", JsGetDeviceProfileInfoList)}; napi_property_descriptor static_prop[] = { DECLARE_NAPI_STATIC_FUNCTION("createDeviceManager", CreateDeviceManager), diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index d9e22648c7686f23343ea5ba4a60bd195b03b751..18e144a9ee797bc32e13829fd79b3d554546fa70 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -178,6 +178,7 @@ if (defined(ohos_lite)) { "${common_path}/src/dfx/standard/dm_hidumper.cpp", "${common_path}/src/dm_anonymous.cpp", "${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_service.cpp", "src/device_manager_service_listener.cpp", diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 6b388fef51ed60fe4f3b16ecfc8db827c4ffb8a4..1f5898eb634f31ed8a9a376c03738d21c80cf921 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -26,6 +26,7 @@ #include "advertise_manager.h" #include "discovery_manager.h" +#include "dm_device_profile_info.h" #include "pin_holder.h" #include "device_manager_service_listener.h" #include "idevice_manager_service_impl.h" @@ -214,6 +215,7 @@ public: int32_t GetAnonyLocalUdid(const std::string &pkgName, std::string &anonyUdid); int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam); + int32_t GetDeviceProfileInfoList(const std::string &pkgName, DmDeviceProfileInfoFilterOptions &filterOptions); private: bool IsDMServiceImplReady(); diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index cc0fabaa85690a3b9da2c8e160e723c377a9bc51..c590a0fc98c7f57a5e8c4145b565c8dc4c2722a7 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -23,6 +23,7 @@ #include #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "idevice_manager_service_listener.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "kv_adapter_manager.h" @@ -80,6 +81,8 @@ public: int32_t status, std::string content) override; void OnProcessRemove(const ProcessInfo &processInfo) override; void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) override; + void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, + const std::vector &deviceProfileInfos, int32_t code) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 4ff9aaada7bffda1eecebaa8f31734386fa251d4..feaf025d5017342a4a819f6f33b158e15ccc9e3e 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -2577,5 +2577,20 @@ int32_t DeviceManagerService::RegisterAuthenticationType(const std::string &pkgN } return dmServiceImpl_->RegisterAuthenticationType(authenticationType); } + +int32_t DeviceManagerService::GetDeviceProfileInfoList(const std::string &pkgName, + DmDeviceProfileInfoFilterOptions &filterOptions) +{ + if (!PermissionManager::GetInstance().CheckPermission()) { + LOGE("The caller does not have permission to call"); + return ERR_DM_NO_PERMISSION; + } + LOGI("Start for pkgName = %{public}s", pkgName.c_str()); + if (!IsDMServiceAdapterResidentLoad()) { + LOGE("GetDeviceProfileInfoList failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->GetDeviceProfileInfoList(pkgName, filterOptions); +} } // namespace DistributedHardware } // namespace OHOS \ 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 68216fea2c6b43972a969cd8ae4e6a8b7ebbdaa5..6cb519cced6fb5036ffc565fece0b9d7c5c57ae7 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -36,6 +36,7 @@ #include "ipc_notify_device_discovery_req.h" #include "ipc_notify_device_state_req.h" #include "ipc_notify_discover_result_req.h" +#include "ipc_notify_get_device_profile_info_list_req.h" #include "ipc_notify_pin_holder_event_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_server_stub.h" @@ -900,5 +901,19 @@ 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); + pReq->SetResult(code); + pReq->SetProcessInfo(processInfo); + ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 3877ee4d7734c661bc566cb192f00bbb697e4733..1e77d2a5db1465702b9579b19e00d70487e2ada1 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -23,6 +23,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_device_info.h" +#include "dm_device_profile_info.h" #include "dm_log.h" #include "dm_subscribe_info.h" #include "dm_publish_info.h" @@ -32,6 +33,7 @@ #include "ipc_create_pin_holder_req.h" #include "ipc_credential_auth_status_req.h" #include "ipc_destroy_pin_holder_req.h" +#include "ipc_model_codec.h" #include "ipc_notify_devicetrustchange_req.h" #include "ipc_notify_auth_result_req.h" #include "ipc_notify_bind_result_req.h" @@ -40,6 +42,7 @@ #include "ipc_notify_device_discovery_req.h" #include "ipc_notify_device_state_req.h" #include "ipc_notify_discover_result_req.h" +#include "ipc_notify_get_device_profile_info_list_req.h" #include "ipc_notify_publish_result_req.h" #include "ipc_notify_pin_holder_event_req.h" #include "ipc_server_client_proxy.h" @@ -1678,5 +1681,70 @@ ON_IPC_CMD(REG_AUTHENTICATION_TYPE, MessageParcel &data, MessageParcel &reply) } return DM_OK; } + +ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + DmDeviceProfileInfoFilterOptions filterOptions; + filterOptions.isCloud = data.ReadBool(); + size_t size = data.ReadUint32(); + if (size > MAX_DEVICE_PROFILE_SIZE) { + LOGE("size more than %{public}d,", MAX_DEVICE_PROFILE_SIZE); + return ERR_DM_IPC_WRITE_FAILED; + } + if (size > 0) { + for (uint32_t i = 0; i < size; i++) { + std::string item = data.ReadString(); + filterOptions.deviceIdList.emplace_back(item); + } + } + int32_t result = DeviceManagerService::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_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; + } + 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) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 5fcd67186ec31678065e9741333fa786adfc5e8e..9e5d23f834cab33240bd6a02abaa43abc6d073fa 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -222,6 +222,14 @@ public: (void)processInfo; (void)deviceList; } + + virtual void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, + const std::vector &deviceProfileInfos, int32_t code) override + { + (void)processInfo; + (void)deviceProfileInfos; + (void)code; + } }; } // namespace DistributedHardware } // namespace OHOS