diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 9abaafaec8f94733f44b7a36f0bbefc7c61a79d8..d932e8c7c8081a6b02f3da7f5fa91078bdd31137 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -100,6 +100,8 @@ enum DMIpcCmdInterfaceCode { REG_AUTHENTICATION_TYPE, GET_DEVICE_PROFILE_INFO_LIST, GET_DEVICE_PROFILE_INFO_LIST_RESULT, + GET_DEVICE_ICON_INFO, + GET_DEVICE_ICON_INFO_RESULT, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index ca3b153024c0a39ae426a4333ed6e3de5b0f2e16..ece2184ff497c8f10dbde04f4ad388775a328f94 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -286,6 +286,7 @@ const std::string BIND_FOR_DEVICE_LEVEL = "BindForDeviceLevel"; // wise device constexpr int32_t MAX_DEVICE_PROFILE_SIZE = 500; +constexpr int32_t MAX_ICON_SIZE = 4 * 1024 * 1024; constexpr int32_t MAX_CONTAINER_SIZE = 500; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_get_device_icon_info_req.h b/common/include/ipc/model/ipc_get_device_icon_info_req.h new file mode 100644 index 0000000000000000000000000000000000000000..6cfd36d01de1397a6e74ad0818bb0925a47d81bf --- /dev/null +++ b/common/include/ipc/model/ipc_get_device_icon_info_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_ICON_INFO_REQ_H +#define OHOS_DM_IPC_GET_DEVICE_ICON_INFO_REQ_H + +#include "dm_device_profile_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetDeviceIconInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcGetDeviceIconInfoReq); + +public: + /** + * @tc.name: IpcBindTargetReq::GetFirstParam + * @tc.desc: Ipc get first string parameter + * @tc.type: FUNC + */ + const DmDeviceIconInfoFilterOptions &GetFilterOptions() const + { + return filterOptions_; + } + + /** + * @tc.name: IpcBindTargetReq::SetFirstParam + * @tc.desc: Ipc set first string parameter + * @tc.type: FUNC + */ + void SetFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions) + { + filterOptions_ = filterOptions; + } + +private: + DmDeviceIconInfoFilterOptions filterOptions_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GET_DEVICE_ICON_INFO_REQ_H diff --git a/common/include/ipc/model/ipc_notify_get_device_icon_info_req.h b/common/include/ipc/model/ipc_notify_get_device_icon_info_req.h new file mode 100644 index 0000000000000000000000000000000000000000..b348ca90219dc2bca12a204a81ca08659eb60d64 --- /dev/null +++ b/common/include/ipc/model/ipc_notify_get_device_icon_info_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_ICON_INFO_REQ_REQ_H +#define OHOS_DM_IPC_NOTIFY_GET_DEVICE_ICON_INFO_REQ_REQ_H + +#include "dm_device_profile_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcNotifyGetDeviceIconInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcNotifyGetDeviceIconInfoReq); + +public: + DmDeviceIconInfo GetDmDeviceIconInfo() const + { + return dmDeviceIconInfo_; + } + + void SetDmDeviceIconInfo(const DmDeviceIconInfo &dmDeviceIconInfo) + { + dmDeviceIconInfo_ = dmDeviceIconInfo; + } + + /** + * @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: + DmDeviceIconInfo dmDeviceIconInfo_; + int32_t result_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_NOTIFY_GET_DEVICE_ICON_INFO_REQ_REQ_H diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index 910f7c8dac559cc7560ad4ac7d1c31ae07964869..2e87617611089137d1762e4b22ad52a66e54a1af 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -16,6 +16,7 @@ #ifndef OHOS_DM_IPC_MODEL_CODEC_H #define OHOS_DM_IPC_MODEL_CODEC_H +#include "dm_device_info.h" #include "dm_device_profile_info.h" #include "message_parcel.h" @@ -35,6 +36,15 @@ public: 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); + static std::string GetDeviceIconInfoUniqueKey(const DmDeviceIconInfoFilterOptions &iconFiter); + static std::string GetDeviceIconInfoUniqueKey(const DmDeviceIconInfo &iconInfo); + static void DecodeDmDeviceIconInfo(MessageParcel &parcel, DmDeviceIconInfo &deviceIconInfo); + static bool EncodeDmDeviceIconInfo(const DmDeviceIconInfo &deviceIconInfo, MessageParcel &parcel); + static void DecodeDmDeviceIconInfoFilterOptions(MessageParcel &parcel, + DmDeviceIconInfoFilterOptions &filterOptions); + static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, + MessageParcel &parcel); + static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/src/ipc/standard/ipc_model_codec.cpp b/common/src/ipc/standard/ipc_model_codec.cpp index 270dd0a576bd4c6f9f1cc83b4c118eb242c4de42..fbabbd59d4e40691bf9e13cf3d52c11aa06b3e35 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -16,9 +16,14 @@ #include "ipc_model_codec.h" #include "dm_constants.h" #include "dm_log.h" +#include "securec.h" namespace OHOS { namespace DistributedHardware { +namespace { +const std::string UK_SEPARATOR = "#"; +} + int32_t IpcModelCodec::DecodeDmDeviceProfileInfoFilterOptions(MessageParcel &parcel, DmDeviceProfileInfoFilterOptions &filterOptions) { @@ -195,5 +200,99 @@ bool IpcModelCodec::EncodeDmDeviceProfileInfo(const DmDeviceProfileInfo &devInfo bRet = (bRet && EncodeDmServiceProfileInfos(devInfo.services, parcel)); return bRet; } + +std::string IpcModelCodec::GetDeviceIconInfoUniqueKey(const DmDeviceIconInfoFilterOptions &iconFiter) +{ + return iconFiter.productId + UK_SEPARATOR + iconFiter.subProductId + UK_SEPARATOR + + iconFiter.imageType + UK_SEPARATOR + iconFiter.specName; +} + +std::string IpcModelCodec::GetDeviceIconInfoUniqueKey(const DmDeviceIconInfo &iconInfo) +{ + return iconInfo.productId + UK_SEPARATOR + iconInfo.subProductId + UK_SEPARATOR + + iconInfo.imageType + UK_SEPARATOR + iconInfo.specName; +} + +void IpcModelCodec::DecodeDmDeviceIconInfo(MessageParcel &parcel, DmDeviceIconInfo &deviceIconInfo) +{ + deviceIconInfo.productId = parcel.ReadString(); + deviceIconInfo.subProductId = parcel.ReadString(); + deviceIconInfo.imageType = parcel.ReadString(); + deviceIconInfo.specName = parcel.ReadString(); + deviceIconInfo.version = parcel.ReadString(); + deviceIconInfo.url = parcel.ReadString(); + int32_t length = parcel.ReadInt32(); + if (length > 0 && length <= MAX_ICON_SIZE) { + const unsigned char *buffer = nullptr; + if ((buffer = reinterpret_cast(parcel.ReadRawData((size_t)length))) == nullptr) { + LOGE("read raw data failed, length = %{public}d", length); + return; + } + std::vector icon(buffer, buffer + length); + deviceIconInfo.icon = icon; + } +} + +bool IpcModelCodec::EncodeDmDeviceIconInfo(const DmDeviceIconInfo &deviceIconInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceIconInfo.productId)); + bRet = (bRet && parcel.WriteString(deviceIconInfo.subProductId)); + bRet = (bRet && parcel.WriteString(deviceIconInfo.imageType)); + bRet = (bRet && parcel.WriteString(deviceIconInfo.specName)); + bRet = (bRet && parcel.WriteString(deviceIconInfo.version)); + bRet = (bRet && parcel.WriteString(deviceIconInfo.url)); + int32_t length = static_cast(deviceIconInfo.icon.size()); + bRet = (bRet && parcel.WriteInt32(length)); + if (bRet && length > 0) { + const unsigned char *buffer = reinterpret_cast(deviceIconInfo.icon.data()); + bRet = (bRet && parcel.WriteRawData(buffer, length)); + } + return bRet; +} + +void IpcModelCodec::DecodeDmDeviceIconInfoFilterOptions(MessageParcel &parcel, + DmDeviceIconInfoFilterOptions &filterOptions) +{ + filterOptions.productId = parcel.ReadString(); + filterOptions.subProductId = parcel.ReadString(); + filterOptions.imageType = parcel.ReadString(); + filterOptions.specName = parcel.ReadString(); +} + +bool IpcModelCodec::EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, + MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(filterOptions.productId)); + bRet = (bRet && parcel.WriteString(filterOptions.subProductId)); + bRet = (bRet && parcel.WriteString(filterOptions.imageType)); + bRet = (bRet && parcel.WriteString(filterOptions.specName)); + return bRet; +} + +void IpcModelCodec::DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo) +{ + std::string deviceIdStr = parcel.ReadString(); + if (strcpy_s(devInfo.deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceId failed!"); + return; + } + std::string deviceNameStr = parcel.ReadString(); + if (strcpy_s(devInfo.deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceName failed!"); + return; + } + devInfo.deviceTypeId = parcel.ReadUint16(); + std::string networkIdStr = parcel.ReadString(); + if (strcpy_s(devInfo.networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s networkId failed!"); + return; + } + devInfo.range = parcel.ReadInt32(); + devInfo.networkType = parcel.ReadInt32(); + devInfo.authForm = static_cast(parcel.ReadInt32()); + devInfo.extraData = parcel.ReadString(); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 69f9e1968fd2c4f053b661da1d63943f9f6c52ef..d0550aa0e5f0de373f3df072b9fb30c1dff7eb57 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -646,6 +646,9 @@ public: virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, const DmDeviceProfileInfoFilterOptions &filterOptions, std::shared_ptr callback) = 0; + + virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &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 a24cff97aabdcac004618c7b54e0f3ca12df62a3..48f4d62098ed5860e4db6fb0cdc89a7a9afd0339 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -121,6 +121,13 @@ public: virtual void OnResult(const std::vector &deviceProfileInfos, int32_t code) = 0; }; +class GetDeviceIconInfoCallback { +public: + virtual ~GetDeviceIconInfoCallback() {} + virtual void OnResult(const DmDeviceIconInfo &deviceIconInfo, 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 0219c265a66d16d9afa268fd61197910f4da0b7f..ba274c1bfa0149724a11ca03178ca0fd10a4195e 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -414,6 +414,9 @@ public: const DmDeviceProfileInfoFilterOptions &filterOptions, std::shared_ptr callback) override; + virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &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 index ab2b60084a4fe685810b5c556d56c59fd6c642f4..aed31d3dfbf39e11b2c16986a1cad893462f29d5 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 @@ -31,6 +31,17 @@ typedef struct DmProductInfo { std::string imageVersion; } DmProductInfo; +typedef struct DmDeviceIconInfo { + std::string productId; + std::string subProductId; + std::string imageType; + std::string specName; + std::string wiseVersion; + std::string version; + std::string url; + std::vector icon = {}; +} DmDeviceIconInfo; + typedef struct DmServiceProfileInfo { std::string deviceId; std::string serviceId; @@ -43,6 +54,13 @@ typedef struct DmDeviceProfileInfoFilterOptions { std::vector deviceIdList = {}; } DmDeviceProfileInfoFilterOptions; +typedef struct DmDeviceIconInfoFilterOptions { + std::string productId; + std::string subProductId; + std::string imageType; + std::string specName; +} DmDeviceIconInfoFilterOptions; + typedef struct DmDeviceProfileInfo { std::string deviceId; std::string deviceSn; 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 5afdbc289fb19951e7c77d4a67c277f830656136..4d48378b148bb08db033fee8066a7a1df754988a 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -91,6 +91,13 @@ public: */ virtual int32_t GetDeviceProfileInfoList(const std::string &pkgName, const DmDeviceProfileInfoFilterOptions &filterOptions) = 0; + /** + * @tc.name: IDMServiceImplExt::GetDeviceIconInfo + * @tc.desc: GetDeviceIconInfo + * @tc.type: FUNC + */ + virtual int32_t GetDeviceIconInfo(const std::string &pkgName, + const DmDeviceIconInfoFilterOptions &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 fcacd4f2db00fa2e4308b8bf8d7c3c89ba348264..6dbf8d7f40e1797703381f1abef43752c370c475 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 @@ -168,6 +168,8 @@ public: const std::vector &deviceList) = 0; virtual void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) = 0; + virtual void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, + const DmDeviceIconInfo &dmDeviceIconInfo, 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 98f1f8d269165a70c6706593e5a0a501b7956449..7ecd975b3492bf714893bbb9a0c7383f46ed5e13 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 @@ -83,6 +83,10 @@ public: int32_t UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName); void OnGetDeviceProfileInfoListResult(const std::string &pkgName, const std::vector &deviceProfileInfos, int32_t code); + int32_t RegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk, + std::shared_ptr callback); + int32_t UnRegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk); + void OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, int32_t code); public: static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); @@ -157,6 +161,8 @@ private: std::map> sinkBindTargetCallback_; std::mutex bindLock_; std::map> getDeviceProfileInfoCallback_; + std::map>>> getDeviceIconInfoCallback_; }; } // 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 8f6e16dc4ec17b3319882f13f99a10f24444a355..61228cb0f8fb85a48507be051055081f31a6a3fa 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -37,6 +37,7 @@ #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" #include "ipc_get_anony_local_udid_rsp.h" +#include "ipc_get_device_icon_info_req.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" @@ -2614,5 +2615,37 @@ int32_t DeviceManagerImpl::GetDeviceProfileInfoList(const std::string &pkgName, LOGI("Completed"); return DM_OK; } + +int32_t DeviceManagerImpl::GetDeviceIconInfo(const std::string &pkgName, + const DmDeviceIconInfoFilterOptions &filterOptions, std::shared_ptr callback) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::string uk = IpcModelCodec::GetDeviceIconInfoUniqueKey(filterOptions); + LOGI("In pkgName:%{public}s, uk:%{public}s", pkgName.c_str(), uk.c_str()); + int32_t ret = DeviceManagerNotify::GetInstance().RegisterGetDeviceIconInfoCallback(pkgName, uk, callback); + if (ret != DM_OK) { + LOGE("Register Callback failed 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_ICON_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("error: Send Request failed ret: %{public}d", ret); + DeviceManagerNotify::GetInstance().UnRegisterGetDeviceIconInfoCallback(pkgName, uk); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("error: Failed with ret %{public}d", ret); + DeviceManagerNotify::GetInstance().UnRegisterGetDeviceIconInfoCallback(pkgName, uk); + return ret; + } + LOGI("Completed"); +#endif + 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 d6d58d5fdbd91750d1271310539a0ae97c649738..30a47da9206aedae9bc4de48106a141974dd8d63 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 @@ -33,6 +33,7 @@ #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" #include "ipc_get_anony_local_udid_rsp.h" +#include "ipc_get_device_icon_info_req.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" @@ -67,30 +68,6 @@ namespace { const int32_t DM_MAX_TRUST_DEVICE_NUM = 200; } -void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo) -{ - std::string deviceIdStr = parcel.ReadString(); - if (strcpy_s(devInfo.deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { - LOGE("strcpy_s deviceId failed!"); - return; - } - std::string deviceNameStr = parcel.ReadString(); - if (strcpy_s(devInfo.deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { - LOGE("strcpy_s deviceName failed!"); - return; - } - devInfo.deviceTypeId = parcel.ReadUint16(); - std::string networkIdStr = parcel.ReadString(); - if (strcpy_s(devInfo.networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { - LOGE("strcpy_s networkId failed!"); - return; - } - devInfo.range = parcel.ReadInt32(); - devInfo.networkType = parcel.ReadInt32(); - devInfo.authForm = static_cast(parcel.ReadInt32()); - devInfo.extraData = parcel.ReadString(); -} - void DecodeDmDeviceBasicInfo(MessageParcel &parcel, DmDeviceBasicInfo &devInfo) { std::string deviceIdStr = parcel.ReadString(); @@ -245,7 +222,7 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt std::vector deviceInfoVec; for (int32_t i = 0; i < deviceNum; ++i) { DmDeviceInfo deviceInfo; - DecodeDmDeviceInfo(reply, deviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo); deviceInfoVec.emplace_back(deviceInfo); } pRsp->SetDeviceVec(deviceInfoVec); @@ -276,7 +253,7 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_INFO, MessageParcel &reply, std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo deviceInfo; - DecodeDmDeviceInfo(reply, deviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo); pRsp->SetDeviceInfo(deviceInfo); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -304,7 +281,7 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_pt } std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo localDeviceInfo; - DecodeDmDeviceInfo(reply, localDeviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(reply, localDeviceInfo); pRsp->SetLocalDeviceInfo(localDeviceInfo); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -545,7 +522,7 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply std::string pkgName = data.ReadString(); DmDeviceState deviceState = static_cast(data.ReadInt32()); DmDeviceInfo dmDeviceInfo; - DecodeDmDeviceInfo(data, dmDeviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo); DmDeviceBasicInfo dmDeviceBasicInfo; size_t deviceBasicSize = sizeof(DmDeviceBasicInfo); @@ -585,7 +562,7 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) std::string pkgName = data.ReadString(); int16_t subscribeId = data.ReadInt16(); DmDeviceInfo dmDeviceInfo; - DecodeDmDeviceInfo(data, dmDeviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo); DmDeviceBasicInfo devBasicInfo; DecodeDmDeviceBasicInfo(data, devBasicInfo); DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo); @@ -1898,7 +1875,7 @@ ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &data, MessageParcel { std::string pkgName = data.ReadString(); DmDeviceInfo dmDeviceInfo; - DecodeDmDeviceInfo(data, dmDeviceInfo); + IpcModelCodec::DecodeDmDeviceInfo(data, dmDeviceInfo); DeviceManagerNotify::GetInstance().OnDeviceScreenStatus(pkgName, dmDeviceInfo); reply.WriteInt32(DM_OK); @@ -2147,5 +2124,45 @@ ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &data, MessageParc reply.WriteInt32(DM_OK); return DM_OK; } + +ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO, 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::EncodeDmDeviceIconInfoFilterOptions(pReq->GetFilterOptions(), data)) { + LOGE("write filterOptions failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO, 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_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; +} } // 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 0fd4b7bd18cb1d44ee170778a26ba0e9ec61fcf0..061125aaf048a85280e379a8fd961423c5c92963 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 @@ -23,8 +23,10 @@ namespace OHOS { namespace DistributedHardware { +namespace { +const std::string UK_SEPARATOR = "#"; +} DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerNotify); - #if (defined(__LITEOS_M__) || defined(LITE_DEVICE)) constexpr const char* DEVICE_ONLINE = "deviceOnline"; constexpr const char* DEVICE_OFFLINE = "deviceOffline"; @@ -1288,5 +1290,85 @@ void DeviceManagerNotify::OnGetDeviceProfileInfoListResult(const std::string &pk } tempCbk->OnResult(deviceProfileInfos, code); } + +int32_t DeviceManagerNotify::RegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk, + std::shared_ptr callback) +{ + LOGI("In, pkgName: %{public}s.", pkgName.c_str()); + std::lock_guard autoLock(bindLock_); + if (getDeviceIconInfoCallback_.size() > MAX_CONTAINER_SIZE) { + LOGE("callback map size is more than max size"); + return ERR_DM_MAX_SIZE_FAIL; + } + auto iter = getDeviceIconInfoCallback_.find(pkgName); + if (iter == getDeviceIconInfoCallback_.end()) { + getDeviceIconInfoCallback_[pkgName][uk] = {callback}; + return DM_OK; + } + if (iter->second.size() > MAX_CONTAINER_SIZE) { + LOGE("callback map size is more than max size"); + return ERR_DM_MAX_SIZE_FAIL; + } + if (iter->second[uk].size() > MAX_CONTAINER_SIZE) { + LOGE("callback set size is more than max size"); + return ERR_DM_MAX_SIZE_FAIL; + } + iter->second[uk].insert(callback); + return DM_OK; +} + +int32_t DeviceManagerNotify::UnRegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk) +{ + LOGI("In, pkgName: %{public}s", pkgName.c_str()); + std::lock_guard autoLock(bindLock_); + auto iter = getDeviceIconInfoCallback_.find(pkgName); + if (iter == getDeviceIconInfoCallback_.end()) { + return DM_OK; + } + iter->second.erase(uk); + if (iter->second.empty()) { + getDeviceIconInfoCallback_.erase(pkgName); + } + return DM_OK; +} + +void DeviceManagerNotify::OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, + 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::string uk = deviceIconInfo.productId + UK_SEPARATOR + deviceIconInfo.subProductId + UK_SEPARATOR + + deviceIconInfo.imageType + UK_SEPARATOR + deviceIconInfo.specName; + std::map>> tempCbks; + { + std::lock_guard autoLock(bindLock_); + auto iter = getDeviceIconInfoCallback_.find(pkgName); + if (iter == getDeviceIconInfoCallback_.end()) { + LOGE("error, callback not register for pkgName %{public}s.", pkgName.c_str()); + return; + } + if (ERR_DM_HILINKSVC_DISCONNECT == code) { + tempCbks = iter->second; + getDeviceIconInfoCallback_.erase(pkgName); + } else if (iter->second.count(uk) != 0) { + tempCbks[uk] = iter->second[uk]; + iter->second.erase(uk); + } + } + if (tempCbks.empty()) { + LOGE("error, registered GetDeviceIconInfoResult callback is nullptr."); + return; + } + for (const auto &[key, callbacks] : tempCbks) { + for (auto callback : callbacks) { + if (callback != nullptr) { + callback->OnResult(deviceIconInfo, 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 83eec5e75670a3d1582be3b73704e6f10493ec7f..51fefd5fa948ed1a6bcc2026130ad1759e8f9b72 100644 --- a/interfaces/kits/js4.0/include/dm_native_util.h +++ b/interfaces/kits/js4.0/include/dm_native_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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 @@ -77,10 +77,13 @@ void JsObjectToStrVector(const napi_env &env, const napi_value &object, const st std::vector &fieldRef); void JsToDmDeviceProfileInfoFilterOptions(const napi_env &env, const napi_value &object, DmDeviceProfileInfoFilterOptions &info); +void JsToDmDeviceIconInfoFilterOptions(const napi_env &env, const napi_value &object, + DmDeviceIconInfoFilterOptions &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 DmDeviceIconInfoToJs(const napi_env &env, const DmDeviceIconInfo &deviceIconInfo, napi_value &jsObj); void DmDeviceProfileInfoToJsArray(const napi_env &env, const std::vector &devInfos, napi_value &arrayResult); diff --git a/interfaces/kits/js4.0/include/native_devicemanager_js.h b/interfaces/kits/js4.0/include/native_devicemanager_js.h index 94d791810cdc731b7591245963bb3661eb45a0bc..2ec1d2d7637bb66f72c4e2b47d88690a0e2470e4 100644 --- a/interfaces/kits/js4.0/include/native_devicemanager_js.h +++ b/interfaces/kits/js4.0/include/native_devicemanager_js.h @@ -72,6 +72,16 @@ struct DeviceProfileInfosAsyncCallbackInfo { std::vector deviceProfileInfos; }; +struct DeviceIconInfoAsyncCallbackInfo { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + std::string bundleName; + napi_deferred deferred = nullptr; + int32_t code = -1; + OHOS::DistributedHardware::DmDeviceIconInfoFilterOptions filterOptions; + OHOS::DistributedHardware::DmDeviceIconInfo deviceIconInfo; +}; + struct AuthAsyncCallbackInfo { napi_env env = nullptr; @@ -239,6 +249,22 @@ private: napi_deferred deferred_ = nullptr; }; +class DmNapiGetDeviceIconInfoCallback : public OHOS::DistributedHardware::GetDeviceIconInfoCallback { +public: + explicit DmNapiGetDeviceIconInfoCallback(napi_env env, const std::string &bundleName, + const napi_deferred &deferred) : env_(env), bundleName_(bundleName), deferred_(deferred) + { + } + ~DmNapiGetDeviceIconInfoCallback() override {}; + + void OnResult(const OHOS::DistributedHardware::DmDeviceIconInfo &deviceIconInfo, 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); @@ -267,6 +293,7 @@ public: 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 napi_value JsGetDeviceIconInfo(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); @@ -279,6 +306,7 @@ public: 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); + void OnGetDeviceIconInfoCallbackResult(DeviceIconInfoAsyncCallbackInfo *jsCallback); private: static void ReleasePublishCallback(std::string &bundleName); @@ -302,6 +330,7 @@ private: static void RegisterDevStatusCallback(napi_env env, std::string &bundleName); static int32_t DumpDeviceInfo(DeviceBasicInfoListAsyncCallbackInfo *deviceBasicInfoListAsyncCallbackInfo); static napi_value GetDeviceProfileInfoListPromise(napi_env env, DeviceProfileInfosAsyncCallbackInfo *jsCallback); + static napi_value GetDeviceIconInfoPromise(napi_env env, DeviceIconInfoAsyncCallbackInfo *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 557012abaf7555928639e1c47d9bde1147b95e5a..1d8a814dd64b09682fed3524b6bd94fb21b33259 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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 @@ -623,5 +623,51 @@ void DmDeviceProfileInfoToJsArray(const napi_env &env, const std::vector 0) { + void *icon = nullptr; + napi_value iconBuffer = nullptr; + napi_create_arraybuffer(env, iconLen, &icon, &iconBuffer); + if (icon != nullptr && + memcpy_s(icon, iconLen, reinterpret_cast(deviceIconInfo.icon.data()), iconLen) == 0) { + napi_value iconArray = nullptr; + napi_create_typedarray(env, napi_uint8_array, iconLen, iconBuffer, 0, &iconArray); + napi_set_named_property(env, jsObj, "icon", iconArray); + } + } +} } // 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 e01c6dc53ee850462365f33233851e2f5fd56aa8..bb13e8d1397fbea933050be4157c04440508285b 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -751,6 +751,25 @@ void DeviceManagerNapi::OnGetDeviceProfileInfoListCallbackResult(DeviceProfileIn napi_close_handle_scope(env_, scope); } +void DeviceManagerNapi::OnGetDeviceIconInfoCallbackResult(DeviceIconInfoAsyncCallbackInfo *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 deviceIconInfoJsObj; + napi_create_object(env_, &deviceIconInfoJsObj); + DmDeviceIconInfoToJs(env_, jsCallback->deviceIconInfo, deviceIconInfoJsObj); + napi_resolve_deferred(env_, jsCallback->deferred, deviceIconInfoJsObj); + 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()); @@ -1996,6 +2015,90 @@ napi_value DeviceManagerNapi::JsGetDeviceProfileInfoList(napi_env env, napi_call return GetDeviceProfileInfoListPromise(env, jsCallback); } +napi_value DeviceManagerNapi::GetDeviceIconInfoPromise(napi_env env, DeviceIconInfoAsyncCallbackInfo *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, "GetDeviceIconInfoPromise", NAPI_AUTO_LENGTH, &workName); + napi_create_async_work(env, nullptr, workName, + [](napi_env env, void *data) { + DeviceIconInfoAsyncCallbackInfo *jsCallback = + reinterpret_cast(data); + std::shared_ptr callback = + std::make_shared(jsCallback->env, jsCallback->bundleName, + jsCallback->deferred); + int32_t ret = DeviceManager::GetInstance().GetDeviceIconInfo(jsCallback->bundleName, + jsCallback->filterOptions, callback); + jsCallback->code = ret; + if (ret != DM_OK) { + LOGE("GetDeviceIconInfoPromise failed, bundleName:%{public}s, ret=%{public}d", + jsCallback->bundleName.c_str(), ret); + } + }, + [](napi_env env, napi_status status, void *data) { + (void)status; + DeviceIconInfoAsyncCallbackInfo *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::JsGetDeviceIconInfo(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)); + DmDeviceIconInfoFilterOptions filterOptions; + JsToDmDeviceIconInfoFilterOptions(env, argv[0], filterOptions); + auto *jsCallback = new DeviceIconInfoAsyncCallbackInfo(); + 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 GetDeviceIconInfoPromise(env, jsCallback); +} + void DeviceManagerNapi::ClearBundleCallbacks(std::string &bundleName) { LOGI("ClearBundleCallbacks start for bundleName %{public}s", bundleName.c_str()); @@ -2157,7 +2260,8 @@ napi_value DeviceManagerNapi::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("replyUiAction", SetUserOperationSync), DECLARE_NAPI_FUNCTION("on", JsOn), DECLARE_NAPI_FUNCTION("off", JsOff), - DECLARE_NAPI_FUNCTION("getDeviceProfileInfoList", JsGetDeviceProfileInfoList)}; + DECLARE_NAPI_FUNCTION("getDeviceProfileInfoList", JsGetDeviceProfileInfoList), + DECLARE_NAPI_FUNCTION("getDeviceIconInfo", JsGetDeviceIconInfo)}; napi_property_descriptor static_prop[] = { DECLARE_NAPI_STATIC_FUNCTION("createDeviceManager", CreateDeviceManager), @@ -2270,3 +2374,53 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) LOGI("RegisterModule() is called!"); napi_module_register(&g_dmModule); } + +void DmNapiGetDeviceIconInfoCallback::OnResult(const OHOS::DistributedHardware::DmDeviceIconInfo &deviceIconInfo, + int32_t code) +{ + LOGI("In code:%{public}d", code); + 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 DeviceIconInfoAsyncCallbackInfo(); + if (jsCallback == nullptr) { + LOGE("create jsCallback fail"); + DeleteUvWork(work); + return; + } + jsCallback->env = env_; + jsCallback->bundleName = bundleName_; + jsCallback->deferred = deferred_; + jsCallback->deviceIconInfo = deviceIconInfo; + 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) { + DeviceIconInfoAsyncCallbackInfo *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->OnGetDeviceIconInfoCallbackResult(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); + } +} diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 1f5898eb634f31ed8a9a376c03738d21c80cf921..7a91f0a7e829f2400f3c79c7d1a6c12fb3028540 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -216,6 +216,7 @@ public: int32_t RegisterAuthenticationType(const std::string &pkgName, const std::map &authParam); int32_t GetDeviceProfileInfoList(const std::string &pkgName, DmDeviceProfileInfoFilterOptions &filterOptions); + int32_t GetDeviceIconInfo(const std::string &pkgName, DmDeviceIconInfoFilterOptions &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 c590a0fc98c7f57a5e8c4145b565c8dc4c2722a7..f2bf22690a00e1ba9bc25162742dc3b75245b282 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -83,6 +83,8 @@ public: void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector &deviceList) override; void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, const std::vector &deviceProfileInfos, int32_t code) override; + void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, + const DmDeviceIconInfo &dmDeviceIconInfo, 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 feaf025d5017342a4a819f6f33b158e15ccc9e3e..04795dd6a6c3c5c9b6a3963e42802a21b1d95dac 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -2592,5 +2592,20 @@ int32_t DeviceManagerService::GetDeviceProfileInfoList(const std::string &pkgNam } return dmServiceImplExtResident_->GetDeviceProfileInfoList(pkgName, filterOptions); } + +int32_t DeviceManagerService::GetDeviceIconInfo(const std::string &pkgName, + DmDeviceIconInfoFilterOptions &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("GetDeviceIconInfo failed, adapter instance not init or init failed."); + return ERR_DM_UNSUPPORTED_METHOD; + } + return dmServiceImplExtResident_->GetDeviceIconInfo(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 6cb519cced6fb5036ffc565fece0b9d7c5c57ae7..97a788511d04a4247257bee03e6bab73c92d8308 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -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_icon_info_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" @@ -915,5 +916,18 @@ void DeviceManagerServiceListener::OnGetDeviceProfileInfoListResult(const Proces pReq->SetProcessInfo(processInfo); ipcServerListener_.SendRequest(GET_DEVICE_PROFILE_INFO_LIST_RESULT, pReq, pRsp); } + +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); +} } // 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 1e77d2a5db1465702b9579b19e00d70487e2ada1..df9ff60cd52efba984d9bf82d641477b0d39130e 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -42,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_icon_info_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" @@ -1746,5 +1747,52 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &reply, pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_CMD(GET_DEVICE_ICON_INFO, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + DmDeviceIconInfoFilterOptions filterOptions; + IpcModelCodec::DecodeDmDeviceIconInfoFilterOptions(data, filterOptions); + int32_t result = DeviceManagerService::GetInstance().GetDeviceIconInfo(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_ICON_INFO_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; + } + 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) +{ + 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 9e5d23f834cab33240bd6a02abaa43abc6d073fa..7619cf8ab5c232b9a636998e2ff0a84a2f5e84c3 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.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 @@ -230,6 +230,14 @@ public: (void)deviceProfileInfos; (void)code; } + + virtual void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo, + const DmDeviceIconInfo &dmDeviceIconInfo, int32_t code) override + { + (void)processInfo; + (void)dmDeviceIconInfo; + (void)code; + } }; } // namespace DistributedHardware } // namespace OHOS