From bb0fb4824a8f8bc7134d7011b215c90a8b5be760 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sun, 23 Feb 2025 13:20:30 +0800 Subject: [PATCH 1/3] Signed-off-by: zhuzhihui7 Change-Id: I01c16a0ecaaf951390090b473c0be4a6a4b97c36 --- .../device_manager_ipc_interface_code.h | 6 + common/include/dm_constants.h | 9 +- .../include/ipc/model/ipc_common_param_req.h | 10 + .../include/ipc/model/ipc_gen_serviceid_rsp.h | 43 +++ .../model/ipc_get_serviceinfo_bycaller_rsp.h | 45 +++ .../ipc/model/ipc_get_serviceinfo_byid_rsp.h | 42 +++ .../ipc/model/ipc_register_serviceinfo_req.h | 42 +++ common/include/ipc/standard/ipc_model_codec.h | 4 + common/src/ipc/standard/ipc_model_codec.cpp | 84 +++++ commondependency/BUILD.gn | 1 + .../include/deviceprofile_connector.h | 12 + .../src/deviceprofile_connector.cpp | 93 ++++++ .../native_cpp/include/device_manager.h | 6 + .../native_cpp/include/device_manager_impl.h | 6 + .../native_cpp/include/dm_device_info.h | 35 +++ .../native_cpp/src/device_manager_impl.cpp | 125 ++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 165 ++++++++++ permission/dm_permission.json | 2 +- sa_profile/device_manager.cfg | 1 + services/implementation/BUILD.gn | 1 + .../authentication/auth_message_processor.h | 3 + .../include/authentication/dm_auth_manager.h | 26 +- .../dependency/softbus/softbus_connector.h | 7 + .../dependency/softbus/softbus_session.h | 7 + .../authentication/auth_message_processor.cpp | 24 ++ .../src/authentication/dm_auth_manager.cpp | 297 +++++++++++++++++- .../hichain/hichain_auth_connector.cpp | 6 +- .../dependency/softbus/softbus_connector.cpp | 4 + .../dependency/softbus/softbus_session.cpp | 27 ++ services/service/BUILD.gn | 1 + .../service/include/device_manager_service.h | 13 + .../service/src/device_manager_service.cpp | 189 +++++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 84 +++++ test/unittest/BUILD.gn | 1 + .../unittest/UTTest_ipc_cmd_parser_client.cpp | 276 ++++++++++++++++ utils/include/crypto/dm_crypto.h | 2 + utils/src/crypto/dm_crypto.cpp | 2 +- 37 files changed, 1679 insertions(+), 22 deletions(-) create mode 100644 common/include/ipc/model/ipc_gen_serviceid_rsp.h create mode 100644 common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h create mode 100644 common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h create mode 100644 common/include/ipc/model/ipc_register_serviceinfo_req.h mode change 100755 => 100644 services/service/src/device_manager_service.cpp diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index bc86a585c..cf417f0b0 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -109,6 +109,12 @@ enum DMIpcCmdInterfaceCode { SET_LOCAL_DEVICE_NAME, SET_LOCAL_DEVICE_NAME_RESULT, GET_ALL_TRUST_DEVICE_LIST, + GEN_SERVICEID, + REG_SERVICE_INFO, + UNREG_SERVICE_INFO, + UPDATE_SERVICE_INFO, + GET_SERVICEINFO_BYID, + GET_SERVICEINFOS_CALLER, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index d145695d0..c759db158 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -129,7 +129,8 @@ enum { ERR_DM_HILINKSVC_ICON_URL_EMPTY = 96929828, ERR_DM_HILINKSVC_DISCONNECT = 96929829, ERR_DM_WISE_NEED_LOGIN = 96929830, - ERR_DM_NAME_EMPTY = 96929831 + ERR_DM_NAME_EMPTY = 96929831, + ERR_DM_HICHAIN_PROOFMISMATCH = 96929832 }; constexpr const char* TAG_GROUP_ID = "groupId"; @@ -262,6 +263,12 @@ constexpr const char* PROCESS_NAME = "PROCESS_NAME"; constexpr const char* PARAM_CLOSE_SESSION_DELAY_SECONDS = "DM_CLOSE_SESSION_DELAY_SECONDS"; constexpr const char* DM_AUTHENTICATION_TYPE = "DM_AUTHENTICATION_TYPE"; +constexpr const char* PARAM_KEY_CONN_SESSIONTYPE = "connSessionType"; +constexpr const char* PARAM_KEY_HML_ENABLE_160M = "hmlEnable160M"; +constexpr const char* PARAM_KEY_HML_ACTIONID = "hmlActionId"; + +const std::string CONN_SESSION_TYPE_HML = "HML"; +const std::string CONN_SESSION_TYPE_BLE = "BLE"; // screen state constexpr int32_t DM_SCREEN_UNKNOWN = -1; constexpr int32_t DM_SCREEN_ON = 0; diff --git a/common/include/ipc/model/ipc_common_param_req.h b/common/include/ipc/model/ipc_common_param_req.h index 688e70670..135a23040 100644 --- a/common/include/ipc/model/ipc_common_param_req.h +++ b/common/include/ipc/model/ipc_common_param_req.h @@ -64,9 +64,19 @@ public: secondParam_ = secondParam; } + int64_t GetInt64Param() const + { + return int64Param_; + } + + void SetInt64Param(int64_t param) + { + int64Param_ = param; + } private: std::string firstParam_; std::string secondParam_; + int64_t int64Param_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/ipc/model/ipc_gen_serviceid_rsp.h b/common/include/ipc/model/ipc_gen_serviceid_rsp.h new file mode 100644 index 000000000..74840316c --- /dev/null +++ b/common/include/ipc/model/ipc_gen_serviceid_rsp.h @@ -0,0 +1,43 @@ +/* + * 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_GEN_SERVICEID_RSP_H +#define OHOS_DM_IPC_GEN_SERVICEID_RSP_H + +#include "ipc_rsp.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGenServiceIdRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGenServiceIdRsp); + +public: + int64_t GetServiceId() const + { + return serviceId_; + } + + void SetServiceId(const int64_t &serviceId) + { + serviceId_ = serviceId; + } + +private: + int64_t serviceId_ = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GEN_SERVICEID_RSP_H diff --git a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h new file mode 100644 index 000000000..c0090a8a1 --- /dev/null +++ b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h @@ -0,0 +1,45 @@ +/* + * 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_SERVICEINFO_BYCALLER_RSP_H +#define OHOS_DM_IPC_GET_SERVICEINFO_BYCALLER_RSP_H + +#include + +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetServiceInfoByCallerRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetServiceInfoByCallerRsp); + +public: + const std::vector& GetServiceInfos() const + { + return serviceInfos_; + } + + void SetServiceInfos(const std::vector &infos) + { + serviceInfos_ = infos; + } + +private: + std::vector serviceInfos_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GET_SERVICEINFO_BYCALLER_RSP_H diff --git a/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h new file mode 100644 index 000000000..cd3cd1396 --- /dev/null +++ b/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h @@ -0,0 +1,42 @@ +/* + * 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_SERVICEINFO_BYID_RSP_H +#define OHOS_DM_IPC_GET_SERVICEINFO_BYID_RSP_H + +#include "ipc_req.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetServiceInfoByIdRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetServiceInfoByIdRsp); + +public: + const DMServiceInfo &GetServiceInfo() const + { + return serviceInfo_; + } + + void SetServiceInfo(const DMServiceInfo &info) + { + serviceInfo_ = info; + } +private: + DMServiceInfo serviceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GET_SERVICEINFO_BYID_RSP_H diff --git a/common/include/ipc/model/ipc_register_serviceinfo_req.h b/common/include/ipc/model/ipc_register_serviceinfo_req.h new file mode 100644 index 000000000..02c68202a --- /dev/null +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.h @@ -0,0 +1,42 @@ +/* + * 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_REGISTER_SERVICE_INFO_REQ_H +#define OHOS_DM_IPC_REGISTER_SERVICE_INFO_REQ_H + +#include "ipc_req.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcRegServiceInfoReq : public IpcReq { + DECLARE_IPC_MODEL(IpcRegServiceInfoReq); + +public: + const DMServiceInfo &GetServiceInfo() const + { + return serviceInfo_; + } + + void SetServiceInfo(const DMServiceInfo &info) + { + serviceInfo_ = info; + } +private: + DMServiceInfo serviceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_REGISTER_SERVICE_INFO_REQ_H diff --git a/common/include/ipc/standard/ipc_model_codec.h b/common/include/ipc/standard/ipc_model_codec.h index 76e75969e..e608b4701 100644 --- a/common/include/ipc/standard/ipc_model_codec.h +++ b/common/include/ipc/standard/ipc_model_codec.h @@ -50,6 +50,10 @@ public: static bool EncodeDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions, MessageParcel &parcel); static void DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devInfo); + static bool EncodeServiceInfo(const DMServiceInfo &serviceInfo, MessageParcel &parcel); + static bool EncodeServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel); + static bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo); + static bool DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos); }; } // 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 0deff2a12..a411577b3 100644 --- a/common/src/ipc/standard/ipc_model_codec.cpp +++ b/common/src/ipc/standard/ipc_model_codec.cpp @@ -24,6 +24,15 @@ namespace { const std::string UK_SEPARATOR = "#"; } +#define READ_HELPER_RET(parcel, type, out, failRet) \ + do { \ + bool ret = (parcel).Read##type((out)); \ + if (!ret) { \ + LOGE("read value failed!"); \ + return failRet; \ + } \ + } while (0) + void IpcModelCodec::DecodeDmDeviceBasicInfo(MessageParcel &parcel, DmDeviceBasicInfo &devInfo) { std::string deviceIdStr = parcel.ReadString(); @@ -357,5 +366,80 @@ void IpcModelCodec::DecodeDmDeviceInfo(MessageParcel &parcel, DmDeviceInfo &devI devInfo.authForm = static_cast(parcel.ReadInt32()); devInfo.extraData = parcel.ReadString(); } + +bool IpcModelCodec::EncodeServiceInfo(const DMServiceInfo &serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); + bRet = (bRet && parcel.WriteString(serviceInfo.customData)); + bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); + bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); + bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + bRet = (bRet && parcel.WriteString(serviceInfo.description)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + return bRet; +} + +bool IpcModelCodec::EncodeServiceInfos(const std::vector &serviceInfos, MessageParcel &parcel) +{ + uint32_t num = static_cast(serviceInfos.size()); + if (!parcel.WriteUint32(num)) { + LOGE("WriteUint32 num failed"); + return false; + } + bool bRet = true; + for (uint32_t k = 0; k < num; k++) { + DMServiceInfo serviceInfo = serviceInfos[k]; + bRet = EncodeServiceInfo(serviceInfo, parcel); + if (!bRet) { + LOGE("EncodeServiceInfo failed"); + break; + } + } + return bRet; +} + +bool IpcModelCodec::DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) +{ + READ_HELPER_RET(parcel, Int64, serviceInfo.serviceId, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceType, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceName, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceDisplayName, false); + READ_HELPER_RET(parcel, String, serviceInfo.customData, false); + READ_HELPER_RET(parcel, String, serviceInfo.bundleName, false); + READ_HELPER_RET(parcel, String, serviceInfo.moduleName, false); + READ_HELPER_RET(parcel, String, serviceInfo.abilityName, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authBoxType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.pinExchangeType, false); + READ_HELPER_RET(parcel, String, serviceInfo.pinCode, false); + READ_HELPER_RET(parcel, String, serviceInfo.description, false); + READ_HELPER_RET(parcel, String, serviceInfo.serviceDiscoveryScope, false); + return true; +} + +bool IpcModelCodec::DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) +{ + uint32_t num = 0; + READ_HELPER_RET(parcel, Uint32, num, false); + bool bRet = true; + for (uint32_t k = 0; k < num; k++) { + DMServiceInfo serviceInfo; + bRet = DecodeServiceInfo(parcel, serviceInfo); + if (!bRet) { + LOGE("DecodeServiceInfo failed"); + break; + } + serviceInfos.emplace_back(serviceInfo); + } + return bRet; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/commondependency/BUILD.gn b/commondependency/BUILD.gn index 2426a6ecf..cf6fd5b50 100644 --- a/commondependency/BUILD.gn +++ b/commondependency/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("devicemanagerdependency") { "include", "${common_path}/include", "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/cryptomgr", "${utils_path}/include/crypto", ] diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index e4e5d7038..664c0ecfe 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -21,6 +21,8 @@ #include "dm_device_info.h" #include "dm_single_instance.h" #include "i_dp_inited_callback.h" +#include "service_info_profile.h" +#include "service_info_unique_key.h" #include "trusted_device_info.h" constexpr uint32_t ALLOW_AUTH_ONCE = 1; @@ -171,6 +173,16 @@ public: int32_t PutAllTrustedDevices(const std::vector &deviceInfos); int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName); + int32_t PutServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); + int32_t DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey &key); + int32_t UpdateServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); + int32_t GetServiceInfoProfileByUniqueKey(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile); + int32_t GetServiceInfoProfileListByTokenId(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles); + int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles); + int32_t PutSessionKey(const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index cd780f082..9dfe1985a 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -14,6 +14,7 @@ */ #include "deviceprofile_connector.h" +#include "crypto_mgr.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_crypto.h" @@ -1739,6 +1740,98 @@ int32_t DeviceProfileConnector::UpdateAclDeviceName(const std::string &udid, con return ERR_DM_FAILED; } +int32_t DeviceProfileConnector::PutServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey &key) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile(key); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::UpdateServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileByUniqueKey( + const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileByUniqueKey( + key, serviceInfoProfile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( + const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId( + key, serviceInfoProfiles); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileListByBundleName( + const DistributedDeviceProfile::ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByBundleName( + key, serviceInfoProfiles); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::PutSessionKey( + const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId) +{ + if (sessionKey == nullptr) { + LOGE("sessionKey nullptr"); + return ERR_DM_FAILED; + } + if (length > MAX_SESSION_KEY_LENGTH) { + LOGE("SessionKey too long, len: %{public}d", length); + return ERR_DM_FAILED; + } + uint32_t userId = static_cast(MultipleUserConnector::GetCurrentAccountUserID()); + std::vector sessionKeyArray(sessionKey, sessionKey + length); + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutSessionKey(userId, sessionKeyArray, sessionKeyId); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 61fbc54d6..8229dfa9a 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -655,6 +655,12 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; + virtual int32_t GenerateServiceId(int64_t &serviceId) = 0; + virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t UnRegisterServiceInfo(int64_t serviceId) = 0; + virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) = 0; + virtual int32_t GetCallerServiceInfos(std::vector &serviceInfos) = 0; }; } // namespace DistributedHardware } // namespace OHOS 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 755651ece..9664cd5a9 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -422,6 +422,12 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; + virtual int32_t GenerateServiceId(int64_t &serviceId) override; + virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) override; + virtual int32_t UnRegisterServiceInfo(int64_t serviceId) override; + virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) override; + virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) override; + virtual int32_t GetCallerServiceInfos(std::vector &serviceInfos) override; private: DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index e6d3c26ae..b98d58895 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -414,6 +414,41 @@ typedef struct DmNotifyKey { notifyUserId == other.notifyUserId && udid < other.udid); } } DmNotifyKey; + +enum class DMServiceInfoAuthType : int32_t { + TRUST_ONETIME = 0, + TRUST_ALWAYS = 6, + CANCEL = 1 +}; + +enum class DMServiceInfoPinExchangeType : int32_t { + PINBOX = 1, + ULTRASOUND = 2, + FROMDP = 3 +}; + +enum class DMServiceInfoAuthBoxType : int32_t { + STATE3 = 1, + SKIP_CONFIRM = 2, + TWO_IN1 = 3 +}; + +typedef struct DMServiceInfo { + int64_t serviceId = 0; + std::string serviceType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + std::string bundleName; + std::string moduleName; + std::string abilityName; + int32_t authBoxType = 0; + int32_t authType = 0; + int32_t pinExchangeType = 0; + std::string pinCode; + std::string description; + std::string serviceDiscoveryScope; +} DMServiceInfo; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file 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 1ae5013f3..5917a5cf0 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -36,6 +36,7 @@ #include "ipc_destroy_pin_holder_req.h" #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" +#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_icon_info_req.h" #include "ipc_get_device_info_rsp.h" @@ -48,6 +49,8 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_local_display_device_name_req.h" #include "ipc_get_local_display_device_name_rsp.h" +#include "ipc_get_serviceinfo_bycaller_rsp.h" +#include "ipc_get_serviceinfo_byid_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_import_auth_code_req.h" @@ -55,6 +58,7 @@ #include "ipc_permission_req.h" #include "ipc_publish_req.h" #include "ipc_put_device_profile_info_list_req.h" +#include "ipc_register_serviceinfo_req.h" #include "ipc_req.h" #include "ipc_rsp.h" #include "ipc_set_credential_req.h" @@ -2733,5 +2737,126 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, LOGI("Completed"); return DM_OK; } + +int32_t DeviceManagerImpl::GenerateServiceId(int64_t &serviceId) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + int32_t ret = ipcClientProxy_->SendRequest(GEN_SERVICEID, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + serviceId = rsp->GetServiceId(); + LOGI("Completed, serviceId %{public}" PRId64, serviceId); + return DM_OK; +} + +int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceInfo(info); + int32_t ret = ipcClientProxy_->SendRequest(REG_SERVICE_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::UnRegisterServiceInfo(int64_t serviceId) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetInt64Param(serviceId); + int32_t ret = ipcClientProxy_->SendRequest(UNREG_SERVICE_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceInfo(info); + int32_t ret = ipcClientProxy_->SendRequest(UPDATE_SERVICE_INFO, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) +{ + LOGI("Start GetServiceInfoByServiceId, %{public}" PRId64, serviceId); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetInt64Param(serviceId); + int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_BYID, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + info = rsp->GetServiceInfo(); + LOGI("Completed"); + return DM_OK; +} + +int32_t DeviceManagerImpl::GetCallerServiceInfos(std::vector &serviceInfos) +{ + LOGI("Start"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFOS_CALLER, req, rsp); + if (ret != DM_OK) { + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Failed with ret %{public}d", ret); + return ret; + } + serviceInfos = rsp->GetServiceInfos(); + LOGI("Completed, serviceInfos size %{public}zu", serviceInfos.size()); + 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 db851e355..408d8dc45 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 @@ -32,6 +32,7 @@ #include "ipc_def.h" #include "ipc_export_auth_code_rsp.h" #include "ipc_generate_encrypted_uuid_req.h" +#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_icon_info_req.h" #include "ipc_get_device_info_rsp.h" @@ -44,6 +45,8 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_local_display_device_name_req.h" #include "ipc_get_local_display_device_name_rsp.h" +#include "ipc_get_serviceinfo_byid_rsp.h" +#include "ipc_get_serviceinfo_bycaller_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" #include "ipc_import_auth_code_req.h" @@ -51,6 +54,7 @@ #include "ipc_notify_event_req.h" #include "ipc_put_device_profile_info_list_req.h" #include "ipc_register_listener_req.h" +#include "ipc_register_serviceinfo_req.h" #include "ipc_req.h" #include "ipc_rsp.h" #include "ipc_set_credential_req.h" @@ -1861,5 +1865,166 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &reply, std::s pRsp->SetDisplayName(reply.ReadString()); return DM_OK; } + +ON_IPC_SET_REQUEST(GEN_SERVICEID, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GEN_SERVICEID, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + if (pRsp == nullptr) { + LOGE("pRsp is null"); + return ERR_DM_FAILED; + } + pRsp->SetErrCode(reply.ReadInt32()); + if (pRsp->GetErrCode() == DM_OK) { + pRsp->SetServiceId(reply.ReadInt64()); + } + return DM_OK; +} + +ON_IPC_SET_REQUEST(REG_SERVICE_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); + const DMServiceInfo& info = pReq->GetServiceInfo(); + if (!IpcModelCodec::EncodeServiceInfo(info, data)) { + LOGE("EncodeServiceInfo failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(REG_SERVICE_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_SET_REQUEST(UNREG_SERVICE_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); + int64_t serviceId = pReq->GetInt64Param(); + if (!data.WriteInt64(serviceId)) { + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNREG_SERVICE_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_SET_REQUEST(UPDATE_SERVICE_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); + const DMServiceInfo& info = pReq->GetServiceInfo(); + if (!IpcModelCodec::EncodeServiceInfo(info, data)) { + LOGE("EncodeServiceInfo failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UPDATE_SERVICE_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_SET_REQUEST(GET_SERVICEINFO_BYID, 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); + int64_t serviceId = pReq->GetInt64Param(); + if (!data.WriteInt64(serviceId)) { + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + if (pBaseRsp->GetErrCode() == DM_OK) { + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + DMServiceInfo info; + bool ret = IpcModelCodec::DecodeServiceInfo(reply, info); + if (!ret) { + LOGE("DecodeServiceInfo failed"); + pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); + } + pRsp->SetServiceInfo(info); + } + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_SERVICEINFOS_CALLER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_SERVICEINFOS_CALLER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + if (pBaseRsp->GetErrCode() == DM_OK) { + std::shared_ptr pRsp = + std::static_pointer_cast(pBaseRsp); + std::vector infos; + bool ret = IpcModelCodec::DecodeServiceInfos(reply, infos); + if (!ret) { + LOGE("DecodeServiceInfo failed"); + pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); + } + pRsp->SetServiceInfos(infos); + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/permission/dm_permission.json b/permission/dm_permission.json index eeeab591a..5ca165167 100644 --- a/permission/dm_permission.json +++ b/permission/dm_permission.json @@ -1,5 +1,5 @@ { - "ImportAuthCode": ["com.huawei.msdp.hmringgenerator", "com.huawei.msdp.hmringdiscriminator", "CollaborationFwk", "wear_link_service", "watch_system_service"], + "ImportAuthCode": ["com.huawei.msdp.hmringgenerator", "com.huawei.msdp.hmringdiscriminator", "CollaborationFwk", "wear_link_service", "watch_system_service", "com.huawei.hmos.huaweicast"], "ExportAuthCode": ["com.huawei.msdp.hmringgenerator", "com.huawei.msdp.hmringdiscriminator", "CollaborationFwk", "wear_link_service", "watch_system_service"], "RegisterPinHolderCallback": ["CollaborationFwk"], "CreatePinHolder": ["CollaborationFwk"], diff --git a/sa_profile/device_manager.cfg b/sa_profile/device_manager.cfg index 4a495502f..de736fd0a 100644 --- a/sa_profile/device_manager.cfg +++ b/sa_profile/device_manager.cfg @@ -30,6 +30,7 @@ "ohos.permission.ACCESS_BLUETOOTH", "ohos.permission.MANAGE_BLUETOOTH", "ohos.permission.MANAGE_SETTINGS", + "ohos.permission.MANAGE_SOFTBUS_NETWORK", "ohos.permission.START_SYSTEM_DIALOG", "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS", "ohos.permission.GET_BUNDLE_RESOURCES", diff --git a/services/implementation/BUILD.gn b/services/implementation/BUILD.gn index e841ebcdc..3b442952c 100644 --- a/services/implementation/BUILD.gn +++ b/services/implementation/BUILD.gn @@ -230,6 +230,7 @@ if (defined(ohos_lite)) { "init:libbegetutil", "ipc:ipc_core", "mbedtls:mbedtls_shared", + "openssl:libcrypto_shared", "os_account:libaccountkits", "resource_management:resmgr_napi_core", "samgr:samgr_proxy", diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index 2d3994eaf..c388e8ab2 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -43,6 +43,7 @@ constexpr const char* TAG_INDEX = "INDEX"; constexpr const char* TAG_SLICE_NUM = "SLICE"; constexpr const char* TAG_IS_AUTH_CODE_READY = "IS_AUTH_CODE_READY"; constexpr const char* TAG_IS_SHOW_DIALOG = "IS_SHOW_DIALOG"; +constexpr const char* TAG_SRC_PINCODE_IMPORTED = "TAG_SRC_PINCODE_IMPORTED"; constexpr const char* TAG_TOKEN = "TOKEN"; constexpr const char* TAG_CRYPTO_NAME = "CRYPTONAME"; constexpr const char* TAG_CRYPTO_VERSION = "CRYPTOVERSION"; @@ -78,6 +79,7 @@ constexpr const char* TAG_BUNDLE_NAME = "bundleName"; constexpr const char* TAG_CRYPTIC_MSG = "encryptMsg"; constexpr const char* TAG_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME"; constexpr const char* TAG_REMOTE_DEVICE_NAME = "REMOTE_DEVICE_NAME"; +constexpr const char* TAG_SESSIONKEY_ID = "sessionKeyId"; class DmAuthManager; struct DmAuthRequestContext; @@ -119,6 +121,7 @@ private: void GetJsonObj(nlohmann::json &jsonObj); void CreateReqReCheckMessage(nlohmann::json &jsonObj); void ParseReqReCheckMessage(nlohmann::json &json); + bool IsPincodeImported(); private: std::weak_ptr authMgr_; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 4c21a9d25..3aa067a63 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -33,6 +33,7 @@ #include "dm_timer.h" #include "hichain_auth_connector.h" #include "hichain_connector.h" +#include "service_info_unique_key.h" #include "softbus_connector.h" #include "softbus_session.h" @@ -135,6 +136,9 @@ typedef struct DmAuthRequestContext { std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; std::string remoteDeviceName; + std::string connSessionType; + int32_t hmlActionId = 0; + bool hmlEnable160M = false; } DmAuthRequestContext; typedef struct DmAuthResponseContext { @@ -193,6 +197,9 @@ typedef struct DmAuthResponseContext { std::string edition; int32_t localBindLevel; std::string remoteDeviceName; + bool isSrcPincodeImported = false; + int32_t localSessionKeyId = 0; + int32_t remoteSessionKeyId = 0; } DmAuthResponseContext; class AuthMessageProcessor; @@ -405,7 +412,7 @@ public: * @tc.desc: Show AuthInfo Dialog of the DeviceManager Authenticate Manager * @tc.type: FUNC */ - void ShowAuthInfoDialog(); + void ShowAuthInfoDialog(bool authDeviceError = false); /** * @tc.name: DmAuthManager::ShowStartAuthDialog @@ -474,8 +481,22 @@ public: void HandleSessionHeartbeat(std::string name); int32_t RegisterAuthenticationType(int32_t authenticationType); + static bool IsPinCodeValid(const std::string strpin); + static bool IsPinCodeValid(int32_t numpin); + bool IsImportedAuthCodeValid(); private: + bool IsHmlSessionType(); + bool CanUsePincodeFromDp(); + void InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); + bool IsServiceInfoAuthTypeValid(int32_t authType); + bool IsServiceInfoAuthBoxTypeValid(int32_t authBoxType); + bool IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType); + bool IsServiceInfoProfileValid(const DistributedDeviceProfile::ServiceInfoProfile &profile); + void GetServiceInfoProfile(); + bool CheckNeedShowAuthInfoDialog(int32_t errorCode); + void UpdateInputPincodeDialog(int32_t errorCode); + void JoinLnn(const std::string &deviceId); int32_t CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); int32_t CheckAuthParamVaildExtra(const std::string &extra); @@ -529,6 +550,7 @@ private: void GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); void ParseJsonObject(nlohmann::json jsonObject); + void ParseHmlInfoInJsonObject(nlohmann::json jsonObject); int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, int32_t bindLevel, const std::string &extra); void ProcessAuthRequestExt(const int32_t &sessionId); @@ -599,6 +621,8 @@ private: bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; int32_t authenticationType_ = USER_OPERATION_TYPE_ALLOW_AUTH; + DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile_; + bool pincodeDialogEverShown_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/dependency/softbus/softbus_connector.h b/services/implementation/include/dependency/softbus/softbus_connector.h index 2536eeacc..a12651e1e 100644 --- a/services/implementation/include/dependency/softbus/softbus_connector.h +++ b/services/implementation/include/dependency/softbus/softbus_connector.h @@ -77,6 +77,13 @@ public: * @tc.type: FUNC */ static void JoinLnn(const std::string &deviceId); + + /** + * @tc.name: SoftbusConnector::JoinLnnByHml + * @tc.desc: join lnn by session id + * @tc.type: FUNC + */ + static void JoinLnnByHml(int32_t sessionId, int32_t sessionKeyId, int32_t remoteSessionKeyId); public: SoftbusConnector(); ~SoftbusConnector(); diff --git a/services/implementation/include/dependency/softbus/softbus_session.h b/services/implementation/include/dependency/softbus/softbus_session.h index 99387bb76..2e7be8f57 100644 --- a/services/implementation/include/dependency/softbus/softbus_session.h +++ b/services/implementation/include/dependency/softbus/softbus_session.h @@ -60,6 +60,13 @@ public: */ int32_t OpenAuthSession(const std::string &deviceId); + /** + * @tc.name: SoftbusSession::OpenAuthSessionWithPara + * @tc.desc: Open HML AuthSession of the Softbus Session + * @tc.type: FUNC + */ + int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool enable160m); + /** * @tc.name: SoftbusSession::CloseAuthSession * @tc.desc: Close AuthSession of the Softbus Session diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 617317b4d..4c37a6187 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -82,6 +82,15 @@ void AuthMessageProcessor::GetJsonObj(nlohmann::json &jsonObj) } } +bool AuthMessageProcessor::IsPincodeImported() +{ + auto sptrAuthMgr = authMgr_.lock(); + if (sptrAuthMgr == nullptr) { + return false; + } + return sptrAuthMgr->IsImportedAuthCodeValid(); +} + std::vector AuthMessageProcessor::CreateAuthRequestMessage() { LOGI("AuthMessageProcessor::CreateAuthRequestMessage start."); @@ -167,6 +176,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(nlohmann::json &json) return; } else { nlohmann::json jsonTemp; + jsonTemp[TAG_SESSIONKEY_ID] = authResponseContext_->localSessionKeyId; jsonTemp[TAG_PUBLICKEY] = authResponseContext_->publicKey; std::string strTemp = SafetyDump(jsonTemp); std::string encryptStr = ""; @@ -218,6 +228,13 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_HOST_PKGLABEL] = authResponseContext_->hostPkgLabel; json[TAG_EDITION] = authResponseContext_->edition; json[TAG_REMOTE_DEVICE_NAME] = authResponseContext_->remoteDeviceName; + if (authRequestContext_->authType != AUTH_TYPE_IMPORT_AUTH_CODE && IsPincodeImported()) { + LOGI("TAG_SRC_PINCODE_IMPORTED set"); + json[TAG_SRC_PINCODE_IMPORTED] = true; + } else { + LOGI("TAG_SRC_PINCODE_IMPORTED not set"); + json[TAG_SRC_PINCODE_IMPORTED] = false; + } } void AuthMessageProcessor::CreateRespNegotiateMessage(nlohmann::json &json) @@ -369,6 +386,10 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(nlohmann::json &json) if (IsString(jsonObject, TAG_PUBLICKEY)) { authResponseContext_->publicKey = jsonObject[TAG_PUBLICKEY].get(); } + if (IsInt32(jsonObject, TAG_SESSIONKEY_ID)) { + authResponseContext_->remoteSessionKeyId = jsonObject[TAG_SESSIONKEY_ID].get(); + LOGI("got remoteSessionKeyId"); + } return; } } @@ -606,6 +627,9 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) authResponseContext_->remoteDeviceName = json[TAG_REMOTE_DEVICE_NAME].get(); } ParsePkgNegotiateMessage(json); + if (IsBool(json, TAG_SRC_PINCODE_IMPORTED)) { + authResponseContext_->isSrcPincodeImported = json[TAG_SRC_PINCODE_IMPORTED].get(); + } } void AuthMessageProcessor::ParseRespNegotiateMessage(const nlohmann::json &json) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e55ccf02b..b2ec1b6dc 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -42,6 +42,7 @@ #include "dm_random.h" #include "multiple_user_connector.h" #include "nlohmann/json.hpp" +#include "openssl/sha.h" #include "parameter.h" #include "show_confirm.h" #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) @@ -64,6 +65,7 @@ const int32_t CLONE_ADD_TIMEOUT = 10; const int32_t CLONE_WAIT_NEGOTIATE_TIMEOUT = 10; const int32_t CLONE_WAIT_REQUEST_TIMEOUT = 10; const int32_t CLONE_SESSION_HEARTBEAT_TIMEOUT = 20; +const int32_t HML_SESSION_TIMEOUT = 10; const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; const int32_t MAX_AUTH_TIMES = 3; @@ -129,6 +131,12 @@ DmAuthManager::~DmAuthManager() LOGI("DmAuthManager destructor"); } +bool DmAuthManager::IsHmlSessionType() +{ + CHECK_NULL_RETURN(authRequestContext_, false); + return authRequestContext_->connSessionType == CONN_SESSION_TYPE_HML; +} + int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { @@ -181,6 +189,25 @@ int32_t DmAuthManager::CheckAuthParamVaild(const std::string &pkgName, int32_t a int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) { nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + return DM_OK; + } + std::string connSessionType; + if (IsString(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { + connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); + } + if (connSessionType == CONN_SESSION_TYPE_HML) { + if (!IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { + LOGE("CONN_SESSION_TYPE_HML, input actionId is !Int32"); + return ERR_DM_INPUT_PARA_INVALID; + } + int32_t actionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + if (actionId <= 0) { + LOGE("CONN_SESSION_TYPE_HML, input actionId is <=0"); + return ERR_DM_INPUT_PARA_INVALID; + } + } + if (jsonObject.is_discarded() || jsonObject.find(TAG_BIND_LEVEL) == jsonObject.end() || !IsInt32(jsonObject, TAG_BIND_LEVEL)) { return DM_OK; @@ -283,10 +310,34 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } else { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } + ParseHmlInfoInJsonObject(jsonObject); } authRequestContext_->bundleName = GetBundleName(jsonObject); } +void DmAuthManager::ParseHmlInfoInJsonObject(nlohmann::json jsonObject) +{ + if (IsString(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { + authRequestContext_->connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); + LOGI("connSessionType %{public}s", authRequestContext_->connSessionType.c_str()); + } + if (!IsHmlSessionType()) { + return; + } + authRequestContext_->closeSessionDelaySeconds = HML_SESSION_TIMEOUT; + if (IsBool(jsonObject, PARAM_KEY_HML_ENABLE_160M)) { + authRequestContext_->hmlEnable160M = jsonObject[PARAM_KEY_HML_ENABLE_160M].get(); + LOGI("hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); + } + if (IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { + authRequestContext_->hmlActionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + if (authRequestContext_->hmlActionId <= 0) { + authRequestContext_->hmlActionId = 0; + } + LOGI("hmlActionId %{public}d", authRequestContext_->hmlActionId); + } +} + int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) { if (!IsNumberString(delaySecondsStr)) { @@ -802,7 +853,17 @@ void DmAuthManager::HandleAuthenticateTimeout(std::string name) int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { - int32_t sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); + int32_t sessionId = 0; + if (IsHmlSessionType()) { + CHECK_NULL_RETURN(authRequestContext_, ERR_DM_FAILED); + LOGI("hmlActionId %{public}d, hmlReleaseTime %{public}d, hmlEnable160M %{public}d", + authRequestContext_->hmlActionId, authRequestContext_->closeSessionDelaySeconds, + authRequestContext_->hmlEnable160M); + sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, + authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); + } else { + sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); + } struct RadarInfo info = { .funcName = "EstablishAuthChannel", .stageRes = (sessionId > 0) ? @@ -1098,7 +1159,7 @@ bool DmAuthManager::IsAuthFinish() if ((authResponseContext_->isIdenticalAccount && !authResponseContext_->authed) || (authResponseContext_->authed && !authResponseContext_->isOnline)) { - softbusConnector_->JoinLnn(authRequestContext_->addr); + JoinLnn(authRequestContext_->addr); authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authResponseContext_->reply = DM_OK; @@ -1147,7 +1208,10 @@ int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) authMessageProcessor_->SetResponseContext(authResponseContext_); if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { - if (!authResponseContext_->isShowDialog) { + if (CanUsePincodeFromDp()) { + authResponseContext_->code = std::atoi(serviceInfoProfile_.GetPinCode().c_str()); + LOGI("import pincode from dp"); + } else if (!authResponseContext_->isShowDialog) { GetAuthCode(authResponseContext_->hostPkgName, authResponseContext_->code); } else { authResponseContext_->code = GeneratePincode(); @@ -1383,6 +1447,8 @@ void DmAuthManager::AuthenticateFinish() srcReqMsg_ = ""; isNeedProcCachedSrcReqMsg_ = false; } + pincodeDialogEverShown_ = false; + serviceInfoProfile_ = {}; authType_ = AUTH_TYPE_UNKNOW; std::lock_guard autoLock(g_authFinishLock); if (authResponseContext_ == nullptr || authUiStateMgr_ == nullptr) { @@ -1447,6 +1513,99 @@ int32_t DmAuthManager::GeneratePincode() return GenRandInt(MIN_PIN_CODE, MAX_PIN_CODE); } +bool DmAuthManager::IsPinCodeValid(const std::string strpin) +{ + if (strpin.empty()) { + return false; + } + for (size_t i = 0; i < strpin.length(); i++) { + if (!isdigit(strpin[i])) { + return false; + } + } + int32_t pinnum = std::atoi(strpin.c_str()); + return IsPinCodeValid(pinnum); +} + +bool DmAuthManager::IsPinCodeValid(int32_t numpin) +{ + if (numpin < MIN_PIN_CODE || numpin > MAX_PIN_CODE) { + return false; + } + return true; +} + +bool DmAuthManager::CanUsePincodeFromDp() +{ + CHECK_NULL_RETURN(authResponseContext_, false); + return (authResponseContext_->authType != AUTH_TYPE_IMPORT_AUTH_CODE && + authResponseContext_->isSrcPincodeImported && + IsPinCodeValid(serviceInfoProfile_.GetPinCode()) && + serviceInfoProfile_.GetPinExchangeType() == (int32_t)DMServiceInfoPinExchangeType::FROMDP); +} + +void DmAuthManager::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) +{ + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + key.SetDeviceId(std::string(localDeviceId)); + key.SetBundleName(authResponseContext_->hostPkgName); + int32_t userId = MultipleUserConnector::GetFirstForegroundUserId(); + key.SetUserId(userId); + LOGI("localDeviceId %{public}s, bundleName %{public}s", + GetAnonyString(std::string(localDeviceId)).c_str(), GetAnonyString(authResponseContext_->hostPkgName).c_str()); +} + +bool DmAuthManager::IsServiceInfoAuthTypeValid(int32_t authType) +{ + if (authType != (int32_t)DMServiceInfoAuthType::TRUST_ONETIME && + authType != (int32_t)DMServiceInfoAuthType::TRUST_ALWAYS && + authType != (int32_t)DMServiceInfoAuthType::CANCEL) { + return false; + } + return true; +} + +bool DmAuthManager::IsServiceInfoAuthBoxTypeValid(int32_t authBoxType) +{ + if (authBoxType != (int32_t)DMServiceInfoAuthBoxType::STATE3 && + authBoxType != (int32_t)DMServiceInfoAuthBoxType::SKIP_CONFIRM) { + return false; + } + return true; +} + +bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) +{ + if (pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::PINBOX && + pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::FROMDP && + pinExchangeType != (int32_t)DMServiceInfoPinExchangeType::ULTRASOUND) { + return false; + } + return true; +} + +bool DmAuthManager::IsServiceInfoProfileValid(const DistributedDeviceProfile::ServiceInfoProfile &profile) +{ + if (!IsServiceInfoAuthTypeValid(profile.GetAuthType())) { + LOGE("AuthType not valid, %{public}d", profile.GetAuthType()); + return false; + } + if (!IsServiceInfoAuthBoxTypeValid(profile.GetAuthBoxType())) { + LOGE("AuthBoxType not valid, %{public}d", profile.GetAuthBoxType()); + return false; + } + if (!IsServiceInfoPinExchangeTypeValid(profile.GetPinExchangeType())) { + LOGE("PinExchangeType not valid, %{public}d", profile.GetPinExchangeType()); + return false; + } + if (!IsPinCodeValid(profile.GetPinCode())) { + LOGE("pincode not valid"); + return false; + } + return true; +} + std::string DmAuthManager::GenerateGroupName() { if (authResponseContext_ == nullptr) { @@ -1526,6 +1685,12 @@ void DmAuthManager::ShowConfigDialog() LOGE("failed to ShowConfigDialog because authResponseContext_ is nullptr"); return; } + if (CanUsePincodeFromDp() && + serviceInfoProfile_.GetAuthBoxType() == (int32_t)DMServiceInfoAuthBoxType::SKIP_CONFIRM) { + LOGI("no need confirm dialog"); + StartAuthProcess(serviceInfoProfile_.GetAuthType()); + return; + } if (!authResponseContext_->isShowDialog) { LOGI("start auth process"); StartAuthProcess(authenticationType_); @@ -1558,13 +1723,20 @@ void DmAuthManager::ShowConfigDialog() LOGI("ShowConfigDialog end"); } -void DmAuthManager::ShowAuthInfoDialog() +void DmAuthManager::ShowAuthInfoDialog(bool authDeviceError) { if (authResponseContext_ == nullptr) { LOGE("failed to ShowAuthInfoDialog because authResponseContext_ is nullptr"); return; } LOGI("DmAuthManager::ShowAuthInfoDialog start"); + if (!authDeviceError && CanUsePincodeFromDp()) { + LOGI("pin import from dp, not show dialog"); + return; + } + if (pincodeDialogEverShown_) { + return; + } if (!authResponseContext_->isShowDialog) { LOGI("not show dialog."); return; @@ -1579,6 +1751,7 @@ void DmAuthManager::ShowAuthInfoDialog() nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = authResponseContext_->code; std::string authParam = SafetyDump(jsonObj); + pincodeDialogEverShown_ = true; DmDialogManager::GetInstance().ShowPinDialog(std::to_string(authResponseContext_->code)); } @@ -1613,7 +1786,14 @@ void DmAuthManager::ShowStartAuthDialog() return; } LOGI("DmAuthManager::ShowStartAuthDialog start"); - DmDialogManager::GetInstance().ShowInputDialog(authResponseContext_->targetDeviceName); + int32_t pincode = 0; + if (GetAuthCode(authResponseContext_->hostPkgName, pincode) == DM_OK) { + LOGI("already has pin code"); + ProcessPincode(pincode); + } else { + pincodeDialogEverShown_ = true; + DmDialogManager::GetInstance().ShowInputDialog(authResponseContext_->targetDeviceName); + } } int32_t DmAuthManager::ProcessPincode(int32_t pinCode) @@ -1952,10 +2132,8 @@ bool DmAuthManager::IsAuthCodeReady(const std::string &pkgName) int32_t DmAuthManager::DeleteAuthCode() { - if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE) { - importAuthCode_ = ""; - importPkgName_ = ""; - } + importAuthCode_ = ""; + importPkgName_ = ""; return DM_OK; } @@ -1973,6 +2151,15 @@ int32_t DmAuthManager::GetAuthCode(const std::string &pkgName, int32_t &pinCode) return DM_OK; } +bool DmAuthManager::IsImportedAuthCodeValid() +{ + int32_t pinCode = 0; + if (GetAuthCode(authRequestContext_->hostPkgName, pinCode) == DM_OK) { + return true; + } + return false; +} + bool DmAuthManager::IsAuthTypeSupported(const int32_t &authType) { if (authenticationMap_.find(authType) == authenticationMap_.end()) { @@ -2031,7 +2218,7 @@ void DmAuthManager::RequestCredentialDone() if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } - softbusConnector_->JoinLnn(authRequestContext_->addr); + JoinLnn(authRequestContext_->addr); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authResponseContext_->reply = DM_OK; @@ -2125,7 +2312,7 @@ void DmAuthManager::SrcAuthDeviceFinish() return; } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { - softbusConnector_->JoinLnn(authRequestContext_->addr); + JoinLnn(authRequestContext_->addr); timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); ConverToFinish(); return; @@ -2208,8 +2395,10 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) LOGI("AuthDeviceError start."); isAuthDevice_ = false; if (authRequestState_ == nullptr || authResponseState_ != nullptr) { + if (CheckNeedShowAuthInfoDialog(errorCode)) { + return; + } authTimes_++; - LOGI("AuthDeviceError sink authTimes %{public}d.", authTimes_); if (authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->isFinish = false; authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT; @@ -2234,7 +2423,6 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTH_DEVICE_TIMEOUT_TASK)); } - if (errorCode != DM_OK || requestId != authResponseContext_->requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; @@ -2248,7 +2436,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) DmAuthManager::HandleAuthenticateTimeout(name); }); } - authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); + UpdateInputPincodeDialog(errorCode); } } } @@ -2264,6 +2452,15 @@ void DmAuthManager::AuthDeviceSessionKey(int64_t requestId, const uint8_t *sessi int32_t ret = authMessageProcessor_->SaveSessionKey(sessionKey, sessionKeyLen); if (ret != DM_OK) { LOGE("Save session key err, ret: %{public}d", ret); + return; + } + authResponseContext_->localSessionKeyId = 0; + unsigned char hash[SHA256_DIGEST_LENGTH] = { 0 }; + Crypto::DmGenerateStrHash(sessionKey, sessionKeyLen, hash, SHA256_DIGEST_LENGTH, 0); + int32_t sessionKeyId = 0; + ret = DeviceProfileConnector::GetInstance().PutSessionKey(hash, SHA256_DIGEST_LENGTH, sessionKeyId); + if (ret == DM_OK && sessionKeyId > 0) { + authResponseContext_->localSessionKeyId = sessionKeyId; } } @@ -2360,6 +2557,10 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) } std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); + + if (authResponseContext_->isSrcPincodeImported) { + GetServiceInfoProfile(); + } } void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) @@ -2565,7 +2766,7 @@ int32_t DmAuthManager::CheckTrustState() } if (authResponseContext_->isIdenticalAccount) { if (IsIdenticalAccount()) { - softbusConnector_->JoinLnn(authResponseContext_->deviceId); + JoinLnn(authResponseContext_->deviceId); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authResponseContext_->reply = DM_OK; @@ -2578,7 +2779,7 @@ int32_t DmAuthManager::CheckTrustState() authResponseContext_->localDeviceId)) { CompatiblePutAcl(); } - softbusConnector_->JoinLnn(authResponseContext_->deviceId); + JoinLnn(authResponseContext_->deviceId); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); return ALREADY_BIND; @@ -2894,8 +3095,8 @@ void DmAuthManager::RequestReCheckMsgDone() authRequestState_->TransitionTo(std::make_shared()); return; } - PutAccessControlList(); authRequestState_->TransitionTo(std::make_shared()); + PutAccessControlList(); } bool DmAuthManager::IsSinkMsgValid() @@ -2946,5 +3147,67 @@ void DmAuthManager::ProcessReqPublicKey() isNeedProcCachedSrcReqMsg_ = true; } } + +void DmAuthManager::GetServiceInfoProfile() +{ + DistributedDeviceProfile::ServiceInfoUniqueKey key; + InitServiceInfoUniqueKey(key); + std::vector profiles; + int32_t result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, profiles); + if (result != DM_OK) { + return; + } + for (auto &item : profiles) { + if (IsServiceInfoProfileValid(item)) { + serviceInfoProfile_ = item; + LOGI("authBoxType %{public}d, authType %{public}d, pinExchangeType %{public}d", + serviceInfoProfile_.GetAuthBoxType(), serviceInfoProfile_.GetAuthType(), + serviceInfoProfile_.GetPinExchangeType()); + auto updateProfile = serviceInfoProfile_; + updateProfile.SetPinCode("######"); + DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(updateProfile); + break; + } + } +} + +bool DmAuthManager::CheckNeedShowAuthInfoDialog(int32_t errorCode) +{ + CHECK_NULL_RETURN(authResponseContext_, false); + if (errorCode == ERR_DM_HICHAIN_PROOFMISMATCH && !pincodeDialogEverShown_ && CanUsePincodeFromDp()) { + authResponseContext_->code = GeneratePincode(); + LOGI("AuthDeviceError, GeneratePincode, ShowAuthInfoDialog"); + authTimes_ = 0; + ShowAuthInfoDialog(true); + return true; + } + return false; +} + +void DmAuthManager::UpdateInputPincodeDialog(int32_t errorCode) +{ + if (authResponseContext_->authType != AUTH_TYPE_IMPORT_AUTH_CODE && !pincodeDialogEverShown_ && + IsImportedAuthCodeValid() && errorCode == ERR_DM_HICHAIN_PROOFMISMATCH) { + LOGI("AuthDeviceError, ShowStartAuthDialog"); + authTimes_ = 0; + DeleteAuthCode(); + ShowStartAuthDialog(); + } else { + authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); + } +} + +void DmAuthManager::JoinLnn(const std::string &deviceId) +{ + CHECK_NULL_VOID(authRequestContext_); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(softbusConnector_); + if (IsHmlSessionType()) { + softbusConnector_->JoinLnnByHml(authRequestContext_->sessionId, authResponseContext_->localSessionKeyId, + authResponseContext_->remoteSessionKeyId); + return; + } + softbusConnector_->JoinLnn(deviceId); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index a723bb322..2c22d3baf 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -145,7 +145,11 @@ void HiChainAuthConnector::onError(int64_t requestId, int operationCode, int err LOGE("HiChainAuthConnector::onError dmDeviceAuthCallback_ is nullptr."); return; } - dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_FAILED); + int32_t dmErrorCode = ERR_DM_FAILED; + if (errorCode == PROOF_MISMATCH) { + dmErrorCode = ERR_DM_HICHAIN_PROOFMISMATCH; + } + dmDeviceAuthCallback_->AuthDeviceError(requestId, dmErrorCode); } void HiChainAuthConnector::onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index d6debe90f..314a2e54e 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -96,6 +96,10 @@ void SoftbusConnector::JoinLnn(const std::string &deviceId) return; } +void SoftbusConnector::JoinLnnByHml(int32_t sessionId, int32_t sessionKeyId, int32_t remoteSessionKeyId) +{ +} + int32_t SoftbusConnector::GetUdidByNetworkId(const char *networkId, std::string &udid) { LOGI("start, networkId: %{public}s.", GetAnonyString(std::string(networkId)).c_str()); diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 9e579ba80..4c17ce3ae 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -22,6 +22,10 @@ #include "dm_log.h" #include "nlohmann/json.hpp" #include "softbus_connector.h" +#include "softbus_error_code.h" +#ifndef DEVICE_MANAGER_COMMON_FLAG +#include "session_ex.h" +#endif namespace OHOS { namespace DistributedHardware { @@ -110,6 +114,29 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) return sessionId; } +int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool enable160m) +{ +#ifdef DEVICE_MANAGER_COMMON_FLAG + LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); + return SOFTBUS_NOT_IMPLEMENT; +#else + DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); + LinkPara para; + para.type = PARA_ACTION; + para.action.actionId = actionId; + para.enable160M = enable160m; + para.accountInfo = false; + int32_t sessionId = ::OpenAuthSessionWithPara(DM_SESSION_NAME, ¶); + if (sessionId < 0) { + LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); + return sessionId; + } + DmTraceEnd(); + LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); + return sessionId; +#endif +} + int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) { LOGI("CloseAuthSession."); diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index 3bb498b3f..3816f0af1 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -147,6 +147,7 @@ if (defined(ohos_lite)) { "${devicemanager_path}/commondependency/include", "${devicemanager_path}/radar/include", "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/dependency/deviceprofile", "${softbuscache_parh}/include", "${utils_path}/include/appInfo/standard", "${utils_path}/include/crypto", diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index f57a29acb..a9232f54c 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -44,6 +44,7 @@ #include "dm_publish_common_event.h" #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI #endif +#include "service_info_profile.h" namespace OHOS { namespace DistributedHardware { @@ -223,6 +224,12 @@ public: std::vector &deviceProfileInfoList); int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName); std::vector GetDeviceNamePrefixs(); + int64_t GenerateSerivceId(); + int32_t RegisterServiceInfo(const DMServiceInfo &serviceInfo); + int32_t UnRegisterServiceInfo(int64_t serviceId); + int32_t UpdateServiceInfo(const DMServiceInfo &serviceInfo); + int32_t GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo); + int32_t GetCallerServiceInfos(std::vector &serviceInfos); private: bool IsDMServiceImplReady(); @@ -266,6 +273,12 @@ private: std::vector backgroundUserIds); void ProcessCheckSumByBT(std::string networkId, std::vector foregroundUserIds, std::vector backgroundUserIds); + bool InitServiceInfoProfile(const DMServiceInfo &serviceInfo, + DistributedDeviceProfile::ServiceInfoProfile &profile); + void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo); + void InitServiceInfos(const std::vector &profiles, + std::vector &serviceInfos); + bool InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void SubscribeAccountCommonEvent(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp old mode 100755 new mode 100644 index 9b78f1d5f..902bcf0e4 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -20,11 +20,13 @@ #include "app_manager.h" #include "nlohmann/json.hpp" +#include "deviceprofile_connector.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_crypto.h" #include "dm_hidumper.h" #include "dm_log.h" +#include "dm_random.h" #include "dm_softbus_cache.h" #include "dm_radar_helper.h" #include "parameter.h" @@ -35,10 +37,12 @@ #include "device_name_manager.h" #include "dm_comm_tool.h" #include "dm_transport_msg.h" +#include "ipc_skeleton.h" #include "iservice_registry.h" #include "kv_adapter_manager.h" #include "multiple_user_connector.h" #include "relationship_sync_mgr.h" +#include "openssl/sha.h" #if defined(SUPPORT_POWER_MANAGER) #include "power_mgr_client.h" #endif // SUPPORT_POWER_MANAGER @@ -1485,6 +1489,191 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee return dmServiceImplExtResident_->UnbindTargetExt(pkgName, targetId, unbindParam); } +int64_t DeviceManagerService::GenerateSerivceId() +{ + DmDeviceInfo devInfo; + int32_t ret = GetLocalDeviceInfo(devInfo); + if (ret != DM_OK) { + LOGE("GetLocalDeviceInfo failed"); + return 0; + } + std::string udid = devInfo.deviceId; + if (udid.empty()) { + LOGE("udid empty"); + return 0; + } + int64_t tokenId = IPCSkeleton::GetCallingTokenID(); + const uint32_t dataLength = sizeof(int64_t) + sizeof(int64_t) + udid.length(); + std::unique_ptr data = std::make_unique(dataLength); + int64_t randomSeed = GenRandLongLong(0, std::numeric_limits::max()); + unsigned char* dataPtr = data.get(); + *((int64_t*)dataPtr) = randomSeed; + dataPtr += sizeof(int64_t); + *((int64_t*)dataPtr) = tokenId; + dataPtr += sizeof(int64_t); + if (memcpy_s(dataPtr, udid.length(), udid.c_str(), udid.length()) != EOK) { + LOGE("memcpy udid failed"); + return 0; + } + unsigned char hash[SHA256_DIGEST_LENGTH] = {0}; + Crypto::DmGenerateStrHash(data.get(), dataLength, hash, SHA256_DIGEST_LENGTH, 0); + if (memset_s(data.get(), dataLength, 0, dataLength) != EOK) { + LOGW("memset_s failed."); + } + int64_t serviceId = 0; + if (memcpy_s(&serviceId, sizeof(int64_t), hash, sizeof(int64_t)) != EOK) { + serviceId = 0; + LOGE("memcpy serviceId failed"); + } + serviceId = std::abs(serviceId); + LOGI("GenerateSeivceId %{public}" PRId64, serviceId); + return serviceId; +} + +bool DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, + DistributedDeviceProfile::ServiceInfoProfile &profile) +{ + DmDeviceInfo devInfo; + int32_t ret = GetLocalDeviceInfo(devInfo); + if (ret != DM_OK) { + LOGE("GetLocalDeviceInfo failed"); + return false; + } + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + profile.SetDeviceId(std::string(localDeviceId)); + profile.SetNetworkId(devInfo.networkId); + profile.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); + profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); + profile.SetServiceId(serviceInfo.serviceId); + profile.SetServiceType(serviceInfo.serviceType); + profile.SetServiceName(serviceInfo.serviceName); + profile.SetServiceDisplayName(serviceInfo.serviceDisplayName); + profile.SetCustomData(serviceInfo.customData); + profile.SetCustomDataLen(serviceInfo.customData.size()); + profile.SetBundleName(serviceInfo.bundleName); + profile.SetModuleName(serviceInfo.moduleName); + profile.SetAbilityName(serviceInfo.abilityName); + profile.SetAuthBoxType(serviceInfo.authBoxType); + profile.SetAuthType(serviceInfo.authType); + profile.SetPinExchangeType(serviceInfo.pinExchangeType); + profile.SetPinCode(serviceInfo.pinCode); + profile.SetDescription(serviceInfo.description); + profile.SetServiceDicoveryScope(serviceInfo.serviceDiscoveryScope); + return true; +} + +void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, + DMServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = profile.GetServiceId(); + serviceInfo.serviceType = profile.GetServiceType(); + serviceInfo.serviceName = profile.GetServiceName(); + serviceInfo.serviceDisplayName = profile.GetServiceDisplayName(); + serviceInfo.customData = profile.GetCustomData(); + serviceInfo.bundleName = profile.GetBundleName(); + serviceInfo.moduleName = profile.GetModuleName(); + serviceInfo.abilityName = profile.GetAbilityName(); + serviceInfo.authBoxType = profile.GetAuthBoxType(); + serviceInfo.authType = profile.GetAuthType(); + serviceInfo.pinExchangeType = profile.GetPinExchangeType(); + serviceInfo.pinCode = profile.GetPinCode(); + serviceInfo.description = profile.GetDescription(); + serviceInfo.serviceDiscoveryScope = profile.GetServiceDicoveryScope(); +} + +void DeviceManagerService::InitServiceInfos(const std::vector &profiles, + std::vector &serviceInfos) +{ + for (const auto &profileItem : profiles) { + DMServiceInfo infoItem; + InitServiceInfo(profileItem, infoItem); + serviceInfos.emplace_back(infoItem); + } +} + +bool DeviceManagerService::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) +{ + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + key.SetDeviceId(std::string(localDeviceId)); + key.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); + key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); + return true; +} + +int32_t DeviceManagerService::RegisterServiceInfo(const DMServiceInfo &serviceInfo) +{ + LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); + DistributedDeviceProfile::ServiceInfoProfile profile; + bool success = InitServiceInfoProfile(serviceInfo, profile); + if (!success) { + LOGE("InitServiceInfoProfile failed"); + return ERR_DM_FAILED; + } + return DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); +} + +int32_t DeviceManagerService::UnRegisterServiceInfo(int64_t serviceId) +{ + LOGI("start, serviceId %{public}" PRId64, serviceId); + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + key.SetServiceId(serviceId); + return DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); +} + +int32_t DeviceManagerService::UpdateServiceInfo(const DMServiceInfo &serviceInfo) +{ + LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); + DistributedDeviceProfile::ServiceInfoProfile profile; + bool success = InitServiceInfoProfile(serviceInfo, profile); + if (!success) { + LOGE("InitServiceInfoProfile failed"); + return ERR_DM_FAILED; + } + return DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(profile); +} + +int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) +{ + LOGI("start, serviceId %{public}" PRId64, serviceId); + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + key.SetServiceId(serviceId); + DistributedDeviceProfile::ServiceInfoProfile profile; + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, profile); + if (ret == DM_OK) { + InitServiceInfo(profile, serviceInfo); + } + return ret; +} + +int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) +{ + LOGI("start"); + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + std::vector profiles; + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); + if (ret == DM_OK) { + InitServiceInfos(profiles, serviceInfos); + } + return ret; +} + int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) { if (!PermissionManager::GetInstance().CheckPermission()) { diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 7e1060799..ad0544c4d 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1740,5 +1740,89 @@ ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &re } return DM_OK; } + +ON_IPC_CMD(GEN_SERVICEID, MessageParcel &data, MessageParcel &reply) +{ + int64_t serviceId = DeviceManagerService::GetInstance().GenerateSerivceId(); + int32_t result = DM_OK; + if (serviceId == 0) { + result = ERR_DM_FAILED; + } + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!reply.WriteInt64(serviceId)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(REG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + DMServiceInfo serviceInfo; + IpcModelCodec::DecodeServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + int64_t serviceId = data.ReadInt64(); + int32_t result = DeviceManagerService::GetInstance().UnRegisterServiceInfo(serviceId); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(UPDATE_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + DMServiceInfo serviceInfo; + IpcModelCodec::DecodeServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(GET_SERVICEINFO_BYID, MessageParcel &data, MessageParcel &reply) +{ + int64_t serviceId = data.ReadInt64(); + DMServiceInfo serviceInfo; + int32_t result = DeviceManagerService::GetInstance().GetServiceInfoById(serviceId, serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (result == DM_OK && !IpcModelCodec::EncodeServiceInfo(serviceInfo, reply)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_CMD(GET_SERVICEINFOS_CALLER, MessageParcel &data, MessageParcel &reply) +{ + std::vector serviceInfos; + int32_t result = DeviceManagerService::GetInstance().GetCallerServiceInfos(serviceInfos); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (result == DM_OK && !IpcModelCodec::EncodeServiceInfos(serviceInfos, reply)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 258dc2528..22097e37c 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -149,6 +149,7 @@ ohos_unittest("UTTest_ipc_cmd_parser_client") { include_dirs = [ "${devicemanager_path}/commondependency/include" ] sources = [ + "${common_path}/src/ipc/standard/ipc_model_codec.cpp", "${innerkits_path}/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp", "UTTest_ipc_cmd_parser_client.cpp", ] diff --git a/test/unittest/UTTest_ipc_cmd_parser_client.cpp b/test/unittest/UTTest_ipc_cmd_parser_client.cpp index 75d7cc0bc..6b52ab63a 100644 --- a/test/unittest/UTTest_ipc_cmd_parser_client.cpp +++ b/test/unittest/UTTest_ipc_cmd_parser_client.cpp @@ -26,16 +26,21 @@ #include "ipc_create_pin_holder_req.h" #include "ipc_register_listener_req.h" #include "ipc_generate_encrypted_uuid_req.h" +#include "ipc_gen_serviceid_rsp.h" #include "ipc_get_device_screen_status_req.h" #include "ipc_get_device_screen_status_rsp.h" #include "ipc_get_info_by_network_req.h" #include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_serviceinfo_byid_rsp.h" +#include "ipc_get_serviceinfo_bycaller_rsp.h" #include "ipc_get_trustdevice_req.h" +#include "ipc_model_codec.h" #include "ipc_publish_req.h" #include "ipc_unpublish_req.h" #include "ipc_unauthenticate_device_req.h" #include "ipc_unbind_device_req.h" #include "ipc_authenticate_device_req.h" +#include "ipc_register_serviceinfo_req.h" #include "ipc_set_credential_req.h" #include "ipc_set_credential_rsp.h" #include "ipc_notify_event_req.h" @@ -46,6 +51,8 @@ #include "dm_constants.h" #include "nlohmann/json.hpp" +#define NUM_200 200 + namespace OHOS { namespace DistributedHardware { void IpcCmdParserClientTest::SetUp() @@ -328,6 +335,165 @@ HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_034, testing::ext::TestSize.Le ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); } +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_080, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GEN_SERVICEID; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_081, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = REG_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_082, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UNREG_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_083, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UPDATE_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_084, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFO_BYID; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_085, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFOS_CALLER; + ASSERT_EQ(TestReadResponseRspNull(cmdCode), ERR_DM_FAILED); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_086, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GEN_SERVICEID; + MessageParcel reply; + std::shared_ptr rsp = std::make_shared(); + int32_t retCode = 0; + reply.WriteInt32(retCode); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + ReadResponseFunc ptr = GetResponseFunc(cmdCode); + if (ptr) { + ret = ptr(reply, rsp); + } + ASSERT_EQ(ret, DM_OK); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_087, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = REG_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_088, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UNREG_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_089, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UPDATE_SERVICE_INFO; + ASSERT_EQ(TestReadResponseRspNotNull(cmdCode), DM_OK); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_090, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFO_BYID; + MessageParcel reply; + std::shared_ptr rsp = std::make_shared(); + int32_t retCode = 0; + reply.WriteInt32(retCode); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + ReadResponseFunc ptr = GetResponseFunc(cmdCode); + if (ptr) { + ret = ptr(reply, rsp); + } + ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(rsp->GetErrCode(), ERR_DM_IPC_READ_FAILED); + + MessageParcel reply2; + reply2.WriteInt32(DM_OK); + DMServiceInfo info; + info.abilityName = "debug"; + ASSERT_TRUE(IpcModelCodec::EncodeServiceInfo(info, reply2)); + if (ptr) { + ret = ptr(reply2, rsp); + } + ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(rsp->GetErrCode(), DM_OK); + ASSERT_TRUE(rsp->GetServiceInfo().abilityName == "debug"); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_091, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFOS_CALLER; + MessageParcel reply; + std::shared_ptr rsp = std::make_shared(); + int32_t retCode = 0; + reply.WriteInt32(retCode); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + ReadResponseFunc ptr = GetResponseFunc(cmdCode); + if (ptr) { + ret = ptr(reply, rsp); + } + ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(rsp->GetErrCode(), ERR_DM_IPC_READ_FAILED); + + MessageParcel reply2; + reply2.WriteInt32(DM_OK); + std::vector infos; + DMServiceInfo info1; + info1.abilityName = "debug0"; + DMServiceInfo info2; + info2.abilityName = "debug1"; + infos.emplace_back(info1); + infos.emplace_back(info2); + ASSERT_TRUE(IpcModelCodec::EncodeServiceInfos(infos, reply2)); + if (ptr) { + ret = ptr(reply2, rsp); + } + ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(rsp->GetErrCode(), DM_OK); + std::vector infos2 = rsp->GetServiceInfos(); + ASSERT_EQ(infos2.size(), infos.size()); + ASSERT_TRUE(infos2[0].abilityName == "debug0"); + ASSERT_TRUE(infos2[1].abilityName == "debug1"); +} + +HWTEST_F(IpcCmdParserClientTest, ReadResponseFunc_092, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFOS_CALLER; + ReadResponseFunc ptr = GetResponseFunc(cmdCode); + MessageParcel reply; + std::shared_ptr rsp = std::make_shared(); + reply.WriteInt32(DM_OK); + std::vector infos; + for (int k = 0; k < NUM_200; k++) { + DMServiceInfo info; + info.abilityName = std::string("debug") + std::to_string(k); + infos.emplace_back(info); + } + ASSERT_TRUE(IpcModelCodec::EncodeServiceInfos(infos, reply)); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + if (ptr) { + ret = ptr(reply, rsp); + } + ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(rsp->GetErrCode(), DM_OK); + std::vector infos2 = rsp->GetServiceInfos(); + ASSERT_EQ(infos2.size(), infos.size()); + ASSERT_TRUE(infos2[0].abilityName == "debug0"); + ASSERT_TRUE(infos2[1].abilityName == "debug1"); +} + HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_002, testing::ext::TestSize.Level0) { int32_t cmdCode = GET_NETWORKTYPE_BY_NETWORK; @@ -570,6 +736,96 @@ HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_015, testing::ext::TestSize.L ASSERT_EQ(DM_OK, ret); } +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_030, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GEN_SERVICEID; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_031, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = REG_SERVICE_INFO; + DMServiceInfo serviceInfo; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + req->SetServiceInfo(serviceInfo); + + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_032, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UNREG_SERVICE_INFO; + DMServiceInfo serviceInfo; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + req->SetInt64Param(100); + + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_033, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = UPDATE_SERVICE_INFO; + DMServiceInfo serviceInfo; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + req->SetServiceInfo(serviceInfo); + + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_034, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFO_BYID; + DMServiceInfo serviceInfo; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + req->SetInt64Param(100); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + +HWTEST_F(IpcCmdParserClientTest, SetIpcRequestFunc_035, testing::ext::TestSize.Level0) +{ + int32_t cmdCode = GET_SERVICEINFOS_CALLER; + DMServiceInfo serviceInfo; + MessageParcel data; + std::shared_ptr req = std::make_shared(); + int ret = ERR_DM_UNSUPPORTED_IPC_COMMAND; + SetIpcRequestFunc ptr = GetIpcRequestFunc(cmdCode); + if (ptr) { + ret = ptr(req, data); + } + ASSERT_EQ(DM_OK, ret); +} + HWTEST_F(IpcCmdParserClientTest, OnIpcCmdFunc_001, testing::ext::TestSize.Level0) { int32_t cmdCode = SERVER_DEVICE_DISCOVERY; @@ -1158,6 +1414,16 @@ HWTEST_F(IpcCmdParserClientTest, TEST_IPC_REQUEST_NULL_002, testing::ext::TestSi EXPECT_EQ(TestIpcRequestNull(SYNC_CALLBACK), ERR_DM_FAILED); } +HWTEST_F(IpcCmdParserClientTest, TEST_IPC_REQUEST_NULL_003, testing::ext::TestSize.Level2) +{ + EXPECT_EQ(TestIpcRequestNull(GEN_SERVICEID), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(REG_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(UNREG_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(UPDATE_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(GET_SERVICEINFO_BYID), ERR_DM_FAILED); + EXPECT_EQ(TestIpcRequestNull(GET_SERVICEINFOS_CALLER), ERR_DM_FAILED); +} + HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_001, testing::ext::TestSize.Level2) { EXPECT_EQ(TestReadResponseRspNull(UNREGISTER_DEVICE_MANAGER_LISTENER), ERR_DM_FAILED); @@ -1201,6 +1467,16 @@ HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_001, testing::ext::Test EXPECT_EQ(TestReadResponseRspNull(REGISTER_DEV_STATE_CALLBACK), ERR_DM_FAILED); EXPECT_EQ(TestReadResponseRspNull(SYNC_CALLBACK), ERR_DM_FAILED); } + +HWTEST_F(IpcCmdParserClientTest, TEST_READ_RESPONSE_NULL_002, testing::ext::TestSize.Level2) +{ + EXPECT_EQ(TestReadResponseRspNull(GEN_SERVICEID), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(REG_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(UNREG_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(UPDATE_SERVICE_INFO), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(GET_SERVICEINFO_BYID), ERR_DM_FAILED); + EXPECT_EQ(TestReadResponseRspNull(GET_SERVICEINFOS_CALLER), ERR_DM_FAILED); +} } // namespace } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/utils/include/crypto/dm_crypto.h b/utils/include/crypto/dm_crypto.h index c30eb32c7..6f766087a 100644 --- a/utils/include/crypto/dm_crypto.h +++ b/utils/include/crypto/dm_crypto.h @@ -24,6 +24,8 @@ namespace OHOS { namespace DistributedHardware { class Crypto { public: + static void DmGenerateStrHash(const void *data, size_t dataSize, unsigned char *outBuf, uint32_t outBufLen, + uint32_t startIndex); static std::string Sha256(const std::string &text, bool isUpper = false); static std::string Sha256(const void *data, size_t size, bool isUpper = false); static int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, diff --git a/utils/src/crypto/dm_crypto.cpp b/utils/src/crypto/dm_crypto.cpp index 473fd4ec2..6bb651eb7 100644 --- a/utils/src/crypto/dm_crypto.cpp +++ b/utils/src/crypto/dm_crypto.cpp @@ -50,7 +50,7 @@ uint32_t HexifyLen(uint32_t len) return len * HEX_TO_UINT8 + 1; } -void DmGenerateStrHash(const void *data, size_t dataSize, unsigned char *outBuf, uint32_t outBufLen, +void Crypto::DmGenerateStrHash(const void *data, size_t dataSize, unsigned char *outBuf, uint32_t outBufLen, uint32_t startIndex) { if (data == nullptr || outBuf == nullptr || startIndex > outBufLen) { -- Gitee From 0c76c8cbe6169bf2edde4569dd5b45c80cdcb474 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sun, 23 Feb 2025 15:14:48 +0800 Subject: [PATCH 2/3] patch5 Signed-off-by: zhuzhihui7 Change-Id: Ic376bc544d66da27cd622d1a31cb3c0f895b6121 --- .../service/include/device_manager_service.h | 6 ++-- .../service/src/device_manager_service.cpp | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a9232f54c..c318fff31 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -40,11 +40,11 @@ #include "dm_package_common_event.h" #include "dm_screen_common_event.h" #include "relationship_sync_mgr.h" +#include "service_info_profile.h" #if defined(SUPPORT_BLUETOOTH) || defined(SUPPORT_WIFI) #include "dm_publish_common_event.h" #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI #endif -#include "service_info_profile.h" namespace OHOS { namespace DistributedHardware { @@ -273,14 +273,14 @@ private: std::vector backgroundUserIds); void ProcessCheckSumByBT(std::string networkId, std::vector foregroundUserIds, std::vector backgroundUserIds); + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) bool InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo); void InitServiceInfos(const std::vector &profiles, std::vector &serviceInfos); bool InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); - -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) void SubscribeAccountCommonEvent(); void AccountCommonEventCallback(const std::string commonEventType, int32_t currentUserId, int32_t beforeUserId); void SubscribeScreenLockEvent(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 902bcf0e4..f19848a74 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1530,6 +1530,7 @@ int64_t DeviceManagerService::GenerateSerivceId() return serviceId; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) bool DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile) { @@ -1601,9 +1602,11 @@ bool DeviceManagerService::InitServiceInfoUniqueKey(DistributedDeviceProfile::Se key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); return true; } +#endif int32_t DeviceManagerService::RegisterServiceInfo(const DMServiceInfo &serviceInfo) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); DistributedDeviceProfile::ServiceInfoProfile profile; bool success = InitServiceInfoProfile(serviceInfo, profile); @@ -1612,10 +1615,15 @@ int32_t DeviceManagerService::RegisterServiceInfo(const DMServiceInfo &serviceIn return ERR_DM_FAILED; } return DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); +#else + (void)serviceInfo; + return ERR_DM_FAILED; +#endif } int32_t DeviceManagerService::UnRegisterServiceInfo(int64_t serviceId) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) LOGI("start, serviceId %{public}" PRId64, serviceId); DistributedDeviceProfile::ServiceInfoUniqueKey key; bool result = InitServiceInfoUniqueKey(key); @@ -1625,10 +1633,15 @@ int32_t DeviceManagerService::UnRegisterServiceInfo(int64_t serviceId) } key.SetServiceId(serviceId); return DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); +#else + (void)serviceId; + return ERR_DM_FAILED; +#endif } int32_t DeviceManagerService::UpdateServiceInfo(const DMServiceInfo &serviceInfo) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) LOGI("start, serviceId %{public}" PRId64, serviceInfo.serviceId); DistributedDeviceProfile::ServiceInfoProfile profile; bool success = InitServiceInfoProfile(serviceInfo, profile); @@ -1637,10 +1650,15 @@ int32_t DeviceManagerService::UpdateServiceInfo(const DMServiceInfo &serviceInfo return ERR_DM_FAILED; } return DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(profile); +#else + (void)serviceInfo; + return ERR_DM_FAILED; +#endif } int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) LOGI("start, serviceId %{public}" PRId64, serviceId); DistributedDeviceProfile::ServiceInfoUniqueKey key; bool result = InitServiceInfoUniqueKey(key); @@ -1655,10 +1673,16 @@ int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInf InitServiceInfo(profile, serviceInfo); } return ret; +#else + (void)serviceId; + (void)serviceInfo; + return ERR_DM_FAILED; +#endif } int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) LOGI("start"); DistributedDeviceProfile::ServiceInfoUniqueKey key; bool result = InitServiceInfoUniqueKey(key); @@ -1672,6 +1696,10 @@ int32_t DeviceManagerService::GetCallerServiceInfos(std::vector & InitServiceInfos(profiles, serviceInfos); } return ret; +#else + (void)serviceInfos; + return ERR_DM_FAILED; +#endif } int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) -- Gitee From 3ed049119cf5784e24d3204869692dca178cf863 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sun, 23 Feb 2025 16:08:47 +0800 Subject: [PATCH 3/3] patch6 Change-Id: I4c9d9c8b2962b97ed68d361d6f2f32600335c7be Signed-off-by: zhuzhihui7 --- services/service/src/device_manager_service.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f19848a74..3fd2b187d 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -20,13 +20,11 @@ #include "app_manager.h" #include "nlohmann/json.hpp" -#include "deviceprofile_connector.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_crypto.h" #include "dm_hidumper.h" #include "dm_log.h" -#include "dm_random.h" #include "dm_softbus_cache.h" #include "dm_radar_helper.h" #include "parameter.h" @@ -35,7 +33,9 @@ #include "common_event_support.h" #include "datetime_ex.h" #include "device_name_manager.h" +#include "deviceprofile_connector.h" #include "dm_comm_tool.h" +#include "dm_random.h" #include "dm_transport_msg.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -1491,6 +1491,7 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee int64_t DeviceManagerService::GenerateSerivceId() { +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) DmDeviceInfo devInfo; int32_t ret = GetLocalDeviceInfo(devInfo); if (ret != DM_OK) { @@ -1528,6 +1529,9 @@ int64_t DeviceManagerService::GenerateSerivceId() serviceId = std::abs(serviceId); LOGI("GenerateSeivceId %{public}" PRId64, serviceId); return serviceId; +#else + return 0; +#endif } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -- Gitee