From 24ab65b25e36e5d31d1a7e0f7b67740abc34b700 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sun, 12 Jan 2025 16:29:09 +0800 Subject: [PATCH 01/55] register service info in dp Signed-off-by: zhuzhihui7 Change-Id: Id4bd87752e9c13c521b27276cb4e5fefefd8993e --- .../device_manager_ipc_interface_code.h | 2 + .../ipc/model/ipc_register_serviceinfo_req.h | 43 +++++++++ .../include/deviceprofile_connector.h | 5 +- .../src/deviceprofile_connector.cpp | 36 ++++++++ .../native_cpp/include/device_manager.h | 2 + .../include/device_manager_callback.h | 5 +- .../native_cpp/include/device_manager_impl.h | 2 + .../native_cpp/include/dm_device_info.h | 15 ++++ .../native_cpp/src/device_manager_impl.cpp | 80 ++++++++++++++++- .../src/ipc/standard/ipc_cmd_parser.cpp | 88 +++++++++++++++++++ services/service/BUILD.gn | 2 + .../service/include/device_manager_service.h | 5 ++ .../service/src/device_manager_service.cpp | 65 ++++++++++++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 42 +++++++++ 14 files changed, 387 insertions(+), 5 deletions(-) create mode 100644 common/include/ipc/model/ipc_register_serviceinfo_req.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index d932e8c7c..619c25956 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -102,6 +102,8 @@ enum DMIpcCmdInterfaceCode { GET_DEVICE_PROFILE_INFO_LIST_RESULT, GET_DEVICE_ICON_INFO, GET_DEVICE_ICON_INFO_RESULT, + REG_SERVICE_INFO, + UNREG_SERVICE_INFO, // Add ipc msg here IPC_MSG_BUTT }; 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..a869907b1 --- /dev/null +++ b/common/include/ipc/model/ipc_register_serviceinfo_req.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_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/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index d0bb054ce..66b628464 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -21,6 +21,7 @@ #include "dm_device_info.h" #include "dm_single_instance.h" #include "i_dp_inited_callback.h" +#include "service_info_profile.h" #include "trusted_device_info.h" constexpr uint32_t ALLOW_AUTH_ONCE = 1; @@ -167,7 +168,9 @@ public: int32_t SubscribeDeviceProfileInited(sptr dpInitedCallback); int32_t UnSubscribeDeviceProfileInited(); int32_t PutAllTrustedDevices(const std::vector &deviceInfos); - + int32_t RegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); + int32_t UnregisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); + int32_t GetServiceInfoProfile(uint64_t tokenId, DistributedDeviceProfile::ServiceInfoProfile &profile); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string requestDeviceId, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index e0c6909c9..733b403a6 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1631,9 +1631,45 @@ int32_t DeviceProfileConnector::PutAllTrustedDevices( return DM_OK; } +int32_t DeviceProfileConnector::RegisterServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile& profile) +{ + LOGI("[rm003] DeviceProfileConnector::RegisterServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().RegisterServiceInfoProfile(profile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::UnregisterServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile& profile) +{ + LOGI("[rm003] DeviceProfileConnector::RegisterServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnregisterServiceInfoProfile(profile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfile(uint64_t tokenId, ServiceInfoProfile& profile) +{ + LOGI("[rm003] DeviceProfileConnector::GetServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfile(tokenId, profile); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; +} + IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); } + } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index d0550aa0e..bceef544c 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -649,6 +649,8 @@ public: virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &filterOptions, std::shared_ptr callback) = 0; + virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t UnregisterServiceInfo(const DMServiceInfo &info) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 48f4d6209..b8a8e2d74 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_CALLBACK_H -#define OHOS_DM_CALLBACK_H +#ifndef OHOS_DM_REGISTER_SERVICE_CALLBACK_H +#define OHOS_DM_REGISTER_SERVICE_CALLBACK_H #include #include @@ -171,6 +171,7 @@ public: } virtual void OnCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; }; + } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CALLBACK_H 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 ba274c1bf..5074ca7d2 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -417,6 +417,8 @@ public: virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &filterOptions, std::shared_ptr callback) override; + virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) override; + virtual int32_t UnregisterServiceInfo(const DMServiceInfo &info) override; private: DeviceManagerImpl() = default; ~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 00d087fcb..6dd7516f4 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -413,6 +413,21 @@ typedef struct DmNotifyKey { notifyUserId == other.notifyUserId && udid < other.udid); } } DmNotifyKey; + +typedef struct DMServiceInfo { + uint64_t serviceId; + std::string serviceType; + std::string serviceSubType; + std::string serviceName; + std::string serviceDisplayName; + std::string customData; + std::string authDescription; + std::string serviceDiscoveryScope; + std::string authType; + std::string pinExchangeType; + std::string pinCode; +} 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 61228cb0f..482b4437c 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -52,6 +52,7 @@ #include "ipc_notify_event_req.h" #include "ipc_permission_req.h" #include "ipc_publish_req.h" +#include "ipc_register_serviceinfo_req.h" #include "ipc_req.h" #include "ipc_rsp.h" #include "ipc_set_credential_req.h" @@ -1511,6 +1512,22 @@ int32_t DeviceManagerImpl::GetDeviceType(const std::string &pkgName, const std:: int32_t DeviceManagerImpl::BindDevice(const std::string &pkgName, int32_t bindType, const std::string &deviceId, const std::string &bindParam, std::shared_ptr callback) { + DMServiceInfo serviceInfo; + serviceInfo.serviceId = 1; + serviceInfo.serviceType = "profile.serviceType"; + serviceInfo.serviceSubType = "profile.serviceSubType"; + serviceInfo.serviceName = "profile.serviceName"; + serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; + serviceInfo.customData = "profile.customData"; + serviceInfo.authDescription = "profile.authDescription"; + serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; + serviceInfo.authType = "profile.authType"; + serviceInfo.pinExchangeType = "profile.pinExchangeType"; + serviceInfo.pinCode = "profile.pinCode"; + LOGI("[rm003] before RegisterServiceInfo"); + RegisterServiceInfo(serviceInfo); + LOGI("[rm003] after RegisterServiceInfo"); + return ERR_DM_INPUT_PARA_INVALID; if (pkgName.empty() || deviceId.empty()) { LOGE("BindDevice error: Invalid para. pkgName : %{public}s", pkgName.c_str()); return ERR_DM_INPUT_PARA_INVALID; @@ -1857,6 +1874,23 @@ int32_t DeviceManagerImpl::StopAdvertising(const std::string &pkgName, int32_t DeviceManagerImpl::BindTarget(const std::string &pkgName, const PeerTargetId &targetId, std::map &bindParam, std::shared_ptr callback) { + DMServiceInfo serviceInfo; + serviceInfo.serviceId = 1; + serviceInfo.serviceType = "profile.serviceType"; + serviceInfo.serviceSubType = "profile.serviceSubType"; + serviceInfo.serviceName = "profile.serviceName"; + serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; + serviceInfo.customData = "profile.customData"; + serviceInfo.authDescription = "profile.authDescription"; + serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; + serviceInfo.authType = "profile.authType"; + serviceInfo.pinExchangeType = "profile.pinExchangeType"; + serviceInfo.pinCode = "profile.pinCode"; + LOGI("[rm003] before RegisterServiceInfo"); + RegisterServiceInfo(serviceInfo); + LOGI("[rm003] after RegisterServiceInfo"); + + return ERR_DM_INPUT_PARA_INVALID; if (pkgName.empty() || IsInvalidPeerTargetId(targetId)) { LOGE("DeviceManagerImpl::BindTarget failed: input pkgName or targetId is empty."); return ERR_DM_INPUT_PARA_INVALID; @@ -2602,9 +2636,8 @@ int32_t DeviceManagerImpl::GetDeviceProfileInfoList(const std::string &pkgName, req->SetFilterOptions(filterOptions); ret = ipcClientProxy_->SendRequest(GET_DEVICE_PROFILE_INFO_LIST, req, rsp); if (ret != DM_OK) { - LOGE("error: Send Request failed ret: %{public}d", ret); + LOGE("error: Failed with ret %{public}d", ret); DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); - return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { @@ -2647,5 +2680,48 @@ int32_t DeviceManagerImpl::GetDeviceIconInfo(const std::string &pkgName, #endif return DM_OK; } + +int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) +{ + LOGI("Start"); + LOGI("[rm003] RegisterServiceInfo"); + 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(const DMServiceInfo &info) +{ + LOGI("Start"); + LOGI("[rm003] UnregisterServiceInfo"); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceInfo(info); + 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; +} + } // 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 30a47da92..3785255ae 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 @@ -48,6 +48,7 @@ #include "ipc_model_codec.h" #include "ipc_notify_event_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" @@ -131,6 +132,38 @@ bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) return bRet; } +bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceSubType)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); + bRet = (bRet && parcel.WriteString(serviceInfo.customData)); + bRet = (bRet && parcel.WriteString(serviceInfo.authDescription)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + bRet = (bRet && parcel.WriteString(serviceInfo.authType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + return bRet; +} + +void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = parcel.ReadUint64(); + serviceInfo.serviceType = parcel.ReadString(); + serviceInfo.serviceSubType = parcel.ReadString(); + serviceInfo.serviceName = parcel.ReadString(); + serviceInfo.serviceDisplayName = parcel.ReadString(); + serviceInfo.customData = parcel.ReadString(); + serviceInfo.authDescription = parcel.ReadString(); + serviceInfo.serviceDiscoveryScope = parcel.ReadString(); + serviceInfo.authType = parcel.ReadString(); + serviceInfo.pinExchangeType = parcel.ReadString(); + serviceInfo.pinCode = parcel.ReadString(); +} + ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -2164,5 +2197,60 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &repl reply.WriteInt32(DM_OK); 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; + } + LOGI("[rm003] ON_IPC_SET_REQUEST(REG_SERVICE_INFO"); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + const DMServiceInfo& info = pReq->GetServiceInfo(); + if (!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) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(REG_SERVICE_INFO"); + 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) +{ + LOGI("[rm003] ON_IPC_SET_REQUEST(UNREG_SERVICE_INFO"); + 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 (!EncodeServiceInfo(info, data)) { + LOGE("EncodeServiceInfo failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO"); + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index 18e144a9e..d376d792f 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -144,6 +144,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", @@ -219,6 +220,7 @@ if (defined(ohos_lite)) { deps = [ "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", + "${servicesimpl_path}:devicemanagerserviceimpl", "${softbuscache_parh}:dmdevicecache", "${utils_path}:devicemanagerutils", ] diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 7a91f0a7e..d9e5fdd65 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -184,6 +184,11 @@ public: int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &unbindParam); + void InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); + void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); + int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); + int32_t UnregisterServiceInfo(DMServiceInfo &serviceInfo); + int32_t DpAclAdd(const std::string &udid); int32_t GetDeviceSecurityLevel(const std::string &pkgName, const std::string &networkId, int32_t &networkType); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 04795dd6a..8db515a5a 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -20,6 +20,7 @@ #include "app_manager.h" #include "nlohmann/json.hpp" +#include "deviceprofile_connector.h" #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_crypto.h" @@ -34,6 +35,7 @@ #include "datetime_ex.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" @@ -1442,6 +1444,69 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee return dmServiceImplExtResident_->UnbindTargetExt(pkgName, targetId, unbindParam); } +void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile) +{ + profile.tokenId = IPCSkeleton::GetCallingTokenID(); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + profile.udid = localDeviceId; + profile.userId = IPCSkeleton::GetCallingUid(); + + profile.serviceId = serviceInfo.serviceId; + profile.serviceType = serviceInfo.serviceType; + profile.serviceSubType = serviceInfo.serviceSubType; + profile.serviceName = serviceInfo.serviceName; + profile.serviceDisplayName = serviceInfo.serviceDisplayName; + profile.customData = serviceInfo.customData; + profile.authDescription = serviceInfo.authDescription; + profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope; + profile.authType = serviceInfo.authType; + profile.pinExchangeType = serviceInfo.pinExchangeType; + profile.pinCode = serviceInfo.pinCode; +} + +void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = profile.serviceId; + serviceInfo.serviceType = profile.serviceType; + serviceInfo.serviceSubType = profile.serviceSubType; + serviceInfo.serviceName = profile.serviceName; + serviceInfo.serviceDisplayName = profile.serviceDisplayName; + serviceInfo.customData = profile.customData; + serviceInfo.authDescription = profile.authDescription; + serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope; + serviceInfo.authType = profile.authType; + serviceInfo.pinExchangeType = profile.pinExchangeType; + serviceInfo.pinCode = profile.pinCode; +} + + +int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) +{ + LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); + DistributedDeviceProfile::ServiceInfoProfile profile; + InitServiceInfoProfile(serviceInfo, profile); + LOGI("[rm003] udid %{public}s", profile.udid.c_str()); + LOGI("[rm003] %{public}llu, %{public}d, %{public}s", profile.tokenId, profile.userId, profile.udid.c_str()); + + int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); + + DistributedDeviceProfile::ServiceInfoProfile profileRet; + DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); + LOGI("[rm003] tokenId %{public}llu", profileRet.tokenId); + LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); + + return ret; +} + +int32_t DeviceManagerService::UnregisterServiceInfo(DMServiceInfo &serviceInfo) +{ + LOGI("[rm003] DeviceManagerService::UnregisterServiceInfo"); + DistributedDeviceProfile::ServiceInfoProfile profile; + InitServiceInfoProfile(serviceInfo, profile); + return DeviceProfileConnector::GetInstance().UnregisterServiceInfoProfile(profile); +} + 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 df9ff60cd..5dcd6490b 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -126,6 +126,21 @@ void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee) callee.extra = parcel.ReadString(); } +void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) +{ + serviceInfo.serviceId = parcel.ReadUint64(); + serviceInfo.serviceType = parcel.ReadString(); + serviceInfo.serviceSubType = parcel.ReadString(); + serviceInfo.serviceName = parcel.ReadString(); + serviceInfo.serviceDisplayName = parcel.ReadString(); + serviceInfo.customData = parcel.ReadString(); + serviceInfo.authDescription = parcel.ReadString(); + serviceInfo.serviceDiscoveryScope = parcel.ReadString(); + serviceInfo.authType = parcel.ReadString(); + serviceInfo.pinExchangeType = parcel.ReadString(); + serviceInfo.pinCode = parcel.ReadString(); +} + ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -1794,5 +1809,32 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::sha pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_CMD(REG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + LOGI("[rm003] ON_IPC_CMD(REG_SERVICE_INFO"); + DMServiceInfo serviceInfo; + 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) +{ + LOGI("[rm003] ON_IPC_CMD(UNREG_SERVICE_INFO"); + DMServiceInfo serviceInfo; + DecodeServiceInfo(data, serviceInfo); + int32_t result = DeviceManagerService::GetInstance().UnregisterServiceInfo(serviceInfo); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 2c021bd554361f94161a706484c5a4d0d8c5866d Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Wed, 15 Jan 2025 16:57:57 +0800 Subject: [PATCH 02/55] 504505 async Change-Id: I462770c6b8736275e53dece0be6f0d3e26709373 --- .../src/deviceprofile_connector.cpp | 1 - .../include/device_manager_callback.h | 4 +- .../native_cpp/include/dm_device_info.h | 26 +- .../native_cpp/src/device_manager_impl.cpp | 33 -- .../src/ipc/standard/ipc_cmd_parser.cpp | 22 +- .../js4.0/src/native_devicemanager_js.cpp | 45 +++ .../authentication/auth_request_state.h | 10 +- .../include/authentication/dm_auth_manager.h | 42 ++- .../authentication/auth_message_processor.cpp | 22 +- .../src/authentication/auth_request_state.cpp | 30 +- .../src/authentication/dm_auth_manager.cpp | 333 ++++++++++++++++-- .../hichain/hichain_auth_connector.cpp | 6 +- services/service/BUILD.gn | 1 - .../service/src/device_manager_service.cpp | 37 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 12 +- .../UTTest_auth_message_processor.cpp | 4 +- 16 files changed, 496 insertions(+), 132 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 733b403a6..fa79f76c0 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1670,6 +1670,5 @@ IDeviceProfileConnector *CreateDpConnectorInstance() { return &DeviceProfileConnector::GetInstance(); } - } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index b8a8e2d74..8ac88c852 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_DM_REGISTER_SERVICE_CALLBACK_H -#define OHOS_DM_REGISTER_SERVICE_CALLBACK_H +#ifndef OHOS_DM_CALLBACK_H +#define OHOS_DM_CALLBACK_H #include #include 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 6dd7516f4..d1e8eb371 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -414,18 +414,34 @@ typedef struct DmNotifyKey { } } DmNotifyKey; +typedef enum : int32_t { + DMAuthType_TrustOneTime = 0, + DMAuthType_TrustAlways = 6, + DMAuthType_Cancel = 1 +} DMAuthType; + +const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_PINBOX = "1"; +const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_ULTRASOUND = "2"; +const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP = "3"; +const std::string DM_SERVICEINFO_AUTHBOX_TYPE_3STATE = "1"; +const std::string DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM = "2"; +const std::string DM_SERVICEINFO_AUTHBOX_TYPE_2IN1 = "3"; + typedef struct DMServiceInfo { - uint64_t serviceId; + uint64_t serviceId = 0; std::string serviceType; - std::string serviceSubType; std::string serviceName; std::string serviceDisplayName; std::string customData; - std::string authDescription; - std::string serviceDiscoveryScope; - std::string authType; + std::string bundleName; + std::string moduleName; + std::string abilityName; + std::string authBoxType; + int32_t authType = 0; std::string pinExchangeType; std::string pinCode; + std::string description; + std::string serviceDiscoveryScope; } DMServiceInfo; } // namespace DistributedHardware 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 482b4437c..f10642238 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -1512,22 +1512,6 @@ int32_t DeviceManagerImpl::GetDeviceType(const std::string &pkgName, const std:: int32_t DeviceManagerImpl::BindDevice(const std::string &pkgName, int32_t bindType, const std::string &deviceId, const std::string &bindParam, std::shared_ptr callback) { - DMServiceInfo serviceInfo; - serviceInfo.serviceId = 1; - serviceInfo.serviceType = "profile.serviceType"; - serviceInfo.serviceSubType = "profile.serviceSubType"; - serviceInfo.serviceName = "profile.serviceName"; - serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; - serviceInfo.customData = "profile.customData"; - serviceInfo.authDescription = "profile.authDescription"; - serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; - serviceInfo.authType = "profile.authType"; - serviceInfo.pinExchangeType = "profile.pinExchangeType"; - serviceInfo.pinCode = "profile.pinCode"; - LOGI("[rm003] before RegisterServiceInfo"); - RegisterServiceInfo(serviceInfo); - LOGI("[rm003] after RegisterServiceInfo"); - return ERR_DM_INPUT_PARA_INVALID; if (pkgName.empty() || deviceId.empty()) { LOGE("BindDevice error: Invalid para. pkgName : %{public}s", pkgName.c_str()); return ERR_DM_INPUT_PARA_INVALID; @@ -1874,23 +1858,6 @@ int32_t DeviceManagerImpl::StopAdvertising(const std::string &pkgName, int32_t DeviceManagerImpl::BindTarget(const std::string &pkgName, const PeerTargetId &targetId, std::map &bindParam, std::shared_ptr callback) { - DMServiceInfo serviceInfo; - serviceInfo.serviceId = 1; - serviceInfo.serviceType = "profile.serviceType"; - serviceInfo.serviceSubType = "profile.serviceSubType"; - serviceInfo.serviceName = "profile.serviceName"; - serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; - serviceInfo.customData = "profile.customData"; - serviceInfo.authDescription = "profile.authDescription"; - serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; - serviceInfo.authType = "profile.authType"; - serviceInfo.pinExchangeType = "profile.pinExchangeType"; - serviceInfo.pinCode = "profile.pinCode"; - LOGI("[rm003] before RegisterServiceInfo"); - RegisterServiceInfo(serviceInfo); - LOGI("[rm003] after RegisterServiceInfo"); - - return ERR_DM_INPUT_PARA_INVALID; if (pkgName.empty() || IsInvalidPeerTargetId(targetId)) { LOGE("DeviceManagerImpl::BindTarget failed: input pkgName or targetId is empty."); return ERR_DM_INPUT_PARA_INVALID; 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 3785255ae..07077885c 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 @@ -137,15 +137,18 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) bool bRet = true; bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceSubType)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); bRet = (bRet && parcel.WriteString(serviceInfo.customData)); - bRet = (bRet && parcel.WriteString(serviceInfo.authDescription)); - bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); - bRet = (bRet && parcel.WriteString(serviceInfo.authType)); + bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); + bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); + bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); + bRet = (bRet && parcel.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + bRet = (bRet && parcel.WriteString(serviceInfo.description)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); return bRet; } @@ -153,15 +156,18 @@ void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { serviceInfo.serviceId = parcel.ReadUint64(); serviceInfo.serviceType = parcel.ReadString(); - serviceInfo.serviceSubType = parcel.ReadString(); serviceInfo.serviceName = parcel.ReadString(); serviceInfo.serviceDisplayName = parcel.ReadString(); serviceInfo.customData = parcel.ReadString(); - serviceInfo.authDescription = parcel.ReadString(); - serviceInfo.serviceDiscoveryScope = parcel.ReadString(); - serviceInfo.authType = parcel.ReadString(); + serviceInfo.bundleName = parcel.ReadString(); + serviceInfo.moduleName = parcel.ReadString(); + serviceInfo.abilityName = parcel.ReadString(); + serviceInfo.authBoxType = parcel.ReadString(); + serviceInfo.authType = parcel.ReadInt32(); serviceInfo.pinExchangeType = parcel.ReadString(); serviceInfo.pinCode = parcel.ReadString(); + serviceInfo.description = parcel.ReadString(); + serviceInfo.serviceDiscoveryScope = parcel.ReadString(); } ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index bb13e8d13..230feefb7 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1658,6 +1658,47 @@ napi_value DeviceManagerNapi::UnPublishDeviceDiscoverySync(napi_env env, napi_ca return result; } +bool xProcessRegisterServiceInfo(std::string bindParam) +{ + nlohmann::json bindParamObj = nlohmann::json::parse(bindParam, nullptr, false); + if (bindParamObj.is_discarded()) { + return false; + } + if (IsInt32(bindParamObj, AUTH_TYPE)) { + int32_t op = bindParamObj[AUTH_TYPE].get(); + if (op == 11) { + LOGI("[temp003] xProcessRegisterServiceInfo"); + std::string pincode; + if (IsString(bindParamObj, PARAM_KEY_PIN_CODE)) { + pincode = bindParamObj[PARAM_KEY_PIN_CODE].get(); + LOGI("[temp003] pincode = %{public}s", pincode.c_str()); + } + if (pincode.empty()) { + pincode = "100000"; + LOGI("[temp003] set pincode to 100000"); + } + DMServiceInfo serviceInfo; + serviceInfo.serviceType = "profile.serviceType"; + serviceInfo.serviceName = "profile.serviceName"; + serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; + serviceInfo.customData = "profile.customData"; + serviceInfo.bundleName = "profile.bundleName"; + serviceInfo.moduleName = "profile.moduleName"; + serviceInfo.abilityName = "profile.abilityName"; + serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; + serviceInfo.authType = DMAuthType_TrustOneTime; + serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; + serviceInfo.pinCode = pincode; + serviceInfo.description = "profile.description"; + serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; + + DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); + return true; + } + } + return false; +} + void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, const std::string &deviceId, napi_env env, napi_value &object) { @@ -1666,6 +1707,10 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, bool isMetaType = false; JsToBindParam(env, object, bindParam, authAsyncCallbackInfo_.authType, isMetaType); + bool processRet = xProcessRegisterServiceInfo(bindParam); + if (processRet) { + return; + } if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; { diff --git a/services/implementation/include/authentication/auth_request_state.h b/services/implementation/include/authentication/auth_request_state.h index d567bf18c..95b772d13 100644 --- a/services/implementation/include/authentication/auth_request_state.h +++ b/services/implementation/include/authentication/auth_request_state.h @@ -206,11 +206,11 @@ public: int32_t Enter() override; }; -class AuthRequestReCheckMsgDone : public AuthRequestState { -public: - int32_t GetStateType() override; - int32_t Enter() override; -}; +//class AuthRequestReCheckMsgDone : public AuthRequestState { +//public: +// int32_t GetStateType() override; +// int32_t Enter() override; +//}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_REQUEST_STATE_H diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 760000cb4..7dee5dbab 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -134,8 +134,23 @@ typedef struct DmAuthRequestContext { std::string addr; std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; + int32_t presetPinCode = 0; } DmAuthRequestContext; +typedef struct DMRecheckData { + std::string edition; + std::string localDeviceId; + int32_t localUserId; + std::string localAccountId; + int64_t tokenId; + std::string bundleName; + int32_t localBindLevel; + std::mutex recheckDataMutex; + bool isDataReceived = false; + bool isDataParsed = false; + bool isDataVerified = false; +} DMRecheckData; + typedef struct DmAuthResponseContext { int32_t authType; std::string deviceId; @@ -172,6 +187,7 @@ typedef struct DmAuthResponseContext { std::vector syncGroupList; std::string accountGroupIdHash; std::string publicKey; + std::string remotePublicKey; bool isOnline; int32_t bindLevel; bool haveCredential; @@ -191,6 +207,7 @@ typedef struct DmAuthResponseContext { bool isFinish = false; std::string edition; int32_t localBindLevel; + DMRecheckData recheckData; } DmAuthResponseContext; class AuthMessageProcessor; @@ -391,6 +408,13 @@ public: */ int32_t GeneratePincode(); + /** + * @tc.name: DmAuthManager::IsPinCodeValid + * @tc.desc: of the DeviceManager Authenticate Manager + * @tc.type: FUNC + */ + bool IsPinCodeValid(std::string strpin); + /** * @tc.name: DmAuthManager::ShowConfigDialog * @tc.desc: Show Config Dialog of the DeviceManager Authenticate Manager @@ -403,7 +427,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 @@ -508,6 +532,8 @@ public: void GenerateCredential(std::string &publicKey); void RequestCredentialDone(); void ResponseCredential(); + bool ResponseNewProcessCredential(); + void ResponseNewSendCredential(); bool AuthDeviceTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen); void AuthDeviceFinish(int64_t requestId); void AuthDeviceError(int64_t requestId, int32_t errorCode); @@ -519,9 +545,15 @@ public: int32_t DeleteGroup(const std::string &pkgName, const std::string &deviceId); int32_t DeleteGroup(const std::string &pkgName, int32_t userId, const std::string &deviceId); int32_t StopAuthenticateDevice(const std::string &pkgName); + bool RemoteSupportRecheck(); + bool IsRecheckDataReceived(); + bool IsRecheckDataParsed(); + bool IsRecheckDataVerified(); void RequestReCheckMsg(); void ResponseReCheckMsg(); void RequestReCheckMsgDone(); + void ResponseReCheckMsgDone(); + void ParseSavedFailedRecheckMsg(); private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); void GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, @@ -552,6 +584,7 @@ private: int32_t GetBindLevel(int32_t bindLevel); std::string GetBundleName(nlohmann::json &jsonObject); int32_t GetBinderInfo(); + int64_t GetBinderTokenId(); void SetProcessInfo(); int32_t GetCloseSessionDelaySeconds(std::string &delaySecondsStr); void ConverToFinish(); @@ -597,6 +630,13 @@ private: bool isNeedProcCachedSrcReqMsg_ = false; std::string srcReqMsg_ = ""; int32_t authenticationType_ = USER_OPERATION_TYPE_ALLOW_AUTH; + + std::mutex recheckMutex_; + std::string savedParseFailedRecheckMsg_; + std::mutex savedParseFailedRecheckMsgMutex_; + + DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile_; + bool pincodeDialogEverShown_ = false; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b67246a0b..8065574fb 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -167,6 +167,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(nlohmann::json &json) return; } else { nlohmann::json jsonTemp; + LOGI("temp003] TAG_PUBLICKEY %{public}s", authResponseContext_->publicKey.c_str()); jsonTemp[TAG_PUBLICKEY] = authResponseContext_->publicKey; std::string strTemp = SafetyDump(jsonTemp); std::string encryptStr = ""; @@ -306,7 +307,7 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) } int32_t msgType = jsonObject[TAG_MSG_TYPE].get(); authResponseContext_->msgType = msgType; - LOGI("AuthMessageProcessor::ParseMessage message type %{public}d", authResponseContext_->msgType); + LOGI("AuthMessageProcessor::ParseMessage msgType message type %{public}d", authResponseContext_->msgType); switch (msgType) { case MSG_TYPE_NEGOTIATE: ParseNegotiateMessage(jsonObject); @@ -348,13 +349,13 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(nlohmann::json &json) encryptFlag = encryptFlag_; } if (!encryptFlag && IsString(json, TAG_PUBLICKEY)) { - authResponseContext_->publicKey = json[TAG_PUBLICKEY].get(); + authResponseContext_->remotePublicKey = json[TAG_PUBLICKEY].get(); return; } if (encryptFlag && IsString(json, TAG_CRYPTIC_MSG)) { std::string encryptStr = json[TAG_CRYPTIC_MSG].get(); std::string decryptStr = ""; - authResponseContext_->publicKey = ""; + authResponseContext_->remotePublicKey = ""; CHECK_NULL_VOID(cryptoMgr_); if (cryptoMgr_->DecryptMessage(encryptStr, decryptStr) != DM_OK) { LOGE("DecryptMessage failed."); @@ -366,7 +367,7 @@ void AuthMessageProcessor::ParsePublicKeyMessageExt(nlohmann::json &json) return; } if (IsString(jsonObject, TAG_PUBLICKEY)) { - authResponseContext_->publicKey = jsonObject[TAG_PUBLICKEY].get(); + authResponseContext_->remotePublicKey = jsonObject[TAG_PUBLICKEY].get(); } return; } @@ -687,6 +688,9 @@ void AuthMessageProcessor::CreateReqReCheckMessage(nlohmann::json &jsonObj) void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) { + std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); + authResponseContext_->recheckData.isDataReceived = true; + LOGE("[temp003] isDataReceived = true"); std::string encryptStr = ""; if (IsString(json, TAG_CRYPTIC_MSG)) { encryptStr = json[TAG_CRYPTIC_MSG].get(); @@ -730,6 +734,16 @@ void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { authResponseContext_->localBindLevel = jsonObject[TAG_BIND_LEVEL].get(); } + + LOGE("[temp003] isDataParsed = true"); + authResponseContext_->recheckData.isDataParsed = true; + authResponseContext_->recheckData.edition = authResponseContext_->edition; + authResponseContext_->recheckData.localDeviceId = authResponseContext_->localDeviceId; + authResponseContext_->recheckData.localUserId = authResponseContext_->localUserId; + authResponseContext_->recheckData.localAccountId = authResponseContext_->localAccountId; + authResponseContext_->recheckData.tokenId = authResponseContext_->tokenId; + authResponseContext_->recheckData.bundleName = authResponseContext_->bundleName; + authResponseContext_->recheckData.localBindLevel = authResponseContext_->localBindLevel; } int32_t AuthMessageProcessor::SaveSessionKey(const uint8_t *sessionKey, const uint32_t keyLen) diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index 20bd1a993..d7c2b2eac 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -231,20 +231,20 @@ int32_t AuthRequestReCheckMsg::Enter() return DM_OK; } -int32_t AuthRequestReCheckMsgDone::GetStateType() -{ - return AuthState::AUTH_REQUEST_RECHECK_MSG_DONE; -} - -int32_t AuthRequestReCheckMsgDone::Enter() -{ - std::shared_ptr stateAuthManager = authManager_.lock(); - if (stateAuthManager == nullptr) { - LOGE("AuthRequestState::authManager_ null"); - return ERR_DM_FAILED; - } - stateAuthManager->RequestReCheckMsgDone(); - return DM_OK; -} +//int32_t AuthRequestReCheckMsgDone::GetStateType() +//{ +// return AuthState::AUTH_REQUEST_RECHECK_MSG_DONE; +//} + +//int32_t AuthRequestReCheckMsgDone::Enter() +//{ +// std::shared_ptr stateAuthManager = authManager_.lock(); +// if (stateAuthManager == nullptr) { +// LOGE("AuthRequestState::authManager_ null"); +// return ERR_DM_FAILED; +// } +// stateAuthManager->RequestReCheckMsgDone(); +// return DM_OK; +//} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index e5dba3c02..54e060293 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -65,7 +65,7 @@ const int32_t CLONE_WAIT_REQUEST_TIMEOUT = 10; const int32_t CLONE_SESSION_HEARTBEAT_TIMEOUT = 20; const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; -const int32_t MAX_AUTH_TIMES = 3; +const int32_t MAX_AUTH_TIMES = 3666666; const int32_t MIN_PIN_TOKEN = 10000000; const int32_t MAX_PIN_TOKEN = 90000000; const int32_t MIN_PIN_CODE = 100000; @@ -277,6 +277,14 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } else { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } + if (IsString(jsonObject, PARAM_KEY_PIN_CODE)) { + std::string strpin = jsonObject[PARAM_KEY_PIN_CODE].get(); + authRequestContext_->presetPinCode = std::stoi(strpin); + LOGI("[rm003-nopincode] input incode %{public}d", authRequestContext_->presetPinCode); + } else if(IsInt32(jsonObject, PARAM_KEY_PIN_CODE)) { + authRequestContext_->presetPinCode = jsonObject[PARAM_KEY_PIN_CODE].get(); + LOGI("[rm003-nopincode] 22 input incode %{public}d", authRequestContext_->presetPinCode); + } } authRequestContext_->bundleName = GetBundleName(jsonObject); } @@ -299,6 +307,7 @@ int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) void DmAuthManager::InitAuthState(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { + LOGI("[temp003] InitAuthState"); if (authenticationMap_.find(authType) != authenticationMap_.end()) { authPtr_ = authenticationMap_[authType]; } @@ -344,6 +353,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au LOGE("CheckAuthParamVaildExtra failed, param is invaild."); return ret; } + isAuthenticateDevice_ = true; if (authType == AUTH_TYPE_CRE) { LOGI("DmAuthManager::AuthenticateDevice for credential type, joinLNN directly."); @@ -567,15 +577,34 @@ void DmAuthManager::ProcessSourceMsg() } break; case MSG_TYPE_RESP_PUBLICKEY: - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_CREDENTIAL) { - authRequestState_->TransitionTo(std::make_shared()); + { + std::lock_guard guard(recheckMutex_); + if (RemoteSupportRecheck()) { + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { + authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGE("[temp003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); + } + } else { + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_CREDENTIAL) { + authRequestState_->TransitionTo(std::make_shared()); + } else { + LOGE("[temp003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); + } } break; + } case MSG_TYPE_RESP_RECHECK_MSG: - if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { - authRequestState_->TransitionTo(std::make_shared()); + { + std::lock_guard guard(recheckMutex_); + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || + authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { + RequestReCheckMsgDone(); + } else { + LOGE("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); } break; + } default: break; } @@ -614,15 +643,18 @@ void DmAuthManager::ProcessSinkMsg() ProcessReqPublicKey(); break; case MSG_TYPE_REQ_RECHECK_MSG: - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH) { - authResponseState_->TransitionTo(std::make_shared()); - break; + { + std::lock_guard guard(recheckMutex_); + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || + authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { + ResponseReCheckMsgDone(); } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); isNeedProcCachedSrcReqMsg_ = true; } break; + } default: break; } @@ -644,6 +676,18 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me return; } + if (authResponseContext_->msgType == MSG_TYPE_RESP_RECHECK_MSG || + authResponseContext_->msgType == MSG_TYPE_REQ_RECHECK_MSG) { + std::lock_guard guard(savedParseFailedRecheckMsgMutex_); + if (!IsRecheckDataParsed()) { + LOGE("[temp003] parse failed, save RECHECK_MSG"); + savedParseFailedRecheckMsg_ = message; + return; + } else { + LOGI("[temp003] savedParseFailedRecheckMsg_.clear"); + savedParseFailedRecheckMsg_.clear(); + } + } if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { // source device auth process ProcessSourceMsg(); @@ -697,6 +741,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); authResponseContext_->isFinish = true; authResponseState_->TransitionTo(std::make_shared()); + LOGI("[rm003] OnGroupCreated pincode %{public}d", authResponseContext_->code); } void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) @@ -1135,7 +1180,11 @@ 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 (serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + IsPinCodeValid(serviceInfoProfile_.pinCode)) { + authResponseContext_->code = std::stoi(serviceInfoProfile_.pinCode); + LOGI("[rm003-nopincode] import from dp, pin %{public}d", authResponseContext_->code); + } else if (!authResponseContext_->isShowDialog) { GetAuthCode(authResponseContext_->hostPkgName, authResponseContext_->code); } else { authResponseContext_->code = GeneratePincode(); @@ -1144,6 +1193,7 @@ int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) authResponseState_->TransitionTo(std::make_shared()); } authMessageProcessor_->SetResponseContext(authResponseContext_); + LOGI("[rm003-nopincode] authResponseContext_->code %{public}d", authResponseContext_->code); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH_EXT); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); return DM_OK; @@ -1370,7 +1420,12 @@ void DmAuthManager::AuthenticateFinish() std::lock_guard lock(srcReqMsgLock_); srcReqMsg_ = ""; isNeedProcCachedSrcReqMsg_ = false; + + pincodeDialogEverShown_ = false; + std::lock_guard guard(savedParseFailedRecheckMsgMutex_); + savedParseFailedRecheckMsg_.clear(); } + authType_ = AUTH_TYPE_UNKNOW; std::lock_guard autoLock(g_authFinishLock); if (authResponseContext_ == nullptr || authUiStateMgr_ == nullptr) { @@ -1435,6 +1490,15 @@ int32_t DmAuthManager::GeneratePincode() return GenRandInt(MIN_PIN_CODE, MAX_PIN_CODE); } +bool DmAuthManager::IsPinCodeValid(std::string strpin) +{ + int pinnum = std::stoi(strpin); + if (pinnum < MIN_PIN_CODE || pinnum > MAX_PIN_CODE) { + return false; + } + return true; +} + std::string DmAuthManager::GenerateGroupName() { if (authResponseContext_ == nullptr) { @@ -1505,6 +1569,7 @@ int32_t DmAuthManager::GetPinCode(int32_t &code) } LOGI("ShowConfigDialog start add member pin code."); code = authResponseContext_->code; + LOGI("[rm003] hichain get pin code %{public}d", code); return DM_OK; } @@ -1514,6 +1579,12 @@ void DmAuthManager::ShowConfigDialog() LOGE("failed to ShowConfigDialog because authResponseContext_ is nullptr"); return; } + + if (serviceInfoProfile_.authBoxType == DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM) { + LOGI("[rm003-nopincode] no need confirm dialog"); + StartAuthProcess(serviceInfoProfile_.authType); + return; + } if (!authResponseContext_->isShowDialog) { LOGI("start auth process"); StartAuthProcess(authenticationType_); @@ -1546,17 +1617,25 @@ 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 && serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + IsPinCodeValid(serviceInfoProfile_.pinCode)) { + LOGI("[rm003-nopincode] pin import from dp, not show dialog"); + return; + } if (!authResponseContext_->isShowDialog) { LOGI("not show dialog."); return; } + if (pincodeDialogEverShown_) { + return; + } struct RadarInfo info = { .funcName = "ShowAuthInfoDialog", .stageRes = static_cast(StageRes::STAGE_SUCC), @@ -1564,9 +1643,11 @@ void DmAuthManager::ShowAuthInfoDialog() if (!DmRadarHelper::GetInstance().ReportAuthPullPinBox(info)) { LOGE("ReportAuthPullPinBox failed"); } + nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = authResponseContext_->code; std::string authParam = SafetyDump(jsonObj); + pincodeDialogEverShown_ = true; DmDialogManager::GetInstance().ShowPinDialog(std::to_string(authResponseContext_->code)); } @@ -1601,7 +1682,14 @@ void DmAuthManager::ShowStartAuthDialog() return; } LOGI("DmAuthManager::ShowStartAuthDialog start"); - DmDialogManager::GetInstance().ShowInputDialog(authResponseContext_->targetDeviceName); + LOGI("[temp003] presetPinCode %{public}d", authRequestContext_->presetPinCode); + if (authRequestContext_->presetPinCode > 0) { + LOGI("[temp003] already has pin code"); + ProcessPincode(authRequestContext_->presetPinCode); + } else { + pincodeDialogEverShown_ = true; + DmDialogManager::GetInstance().ShowInputDialog(authResponseContext_->targetDeviceName); + } } int32_t DmAuthManager::ProcessPincode(int32_t pinCode) @@ -1613,6 +1701,7 @@ int32_t DmAuthManager::ProcessPincode(int32_t pinCode) if (timer_ != nullptr) { timer_->DeleteTimer(std::string(INPUT_TIMEOUT_TASK)); } + LOGI("[rm003] ProcessPincode %{public}d", pinCode); if (CompareVersion(remoteVersion_, std::string(DM_VERSION_4_1_5_1)) && (static_cast(authResponseContext_->bindLevel) >= DEVICE && static_cast(authResponseContext_->bindLevel) <= APP)) { @@ -1990,6 +2079,7 @@ void DmAuthManager::RequestCredential() LOGI("DmAuthManager::RequestCredential start."); std::string publicKey = ""; GenerateCredential(publicKey); + LOGI("[temp003] RequestCredential pk %{public}s", publicKey.c_str()); authResponseContext_->publicKey = publicKey; std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_PUBLICKEY); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -2012,8 +2102,8 @@ void DmAuthManager::RequestCredentialDone() { LOGI("DmAuthManager ExchangeCredentailDone start"); CHECK_NULL_VOID(authResponseContext_); - if (authResponseContext_->publicKey == "" || - ImportCredential(remoteDeviceId_, authResponseContext_->publicKey) != DM_OK) { + if (authResponseContext_->remotePublicKey == "" || + ImportCredential(remoteDeviceId_, authResponseContext_->remotePublicKey) != DM_OK) { LOGE("RequestCredentialDone import credential failed."); } if (timer_ != nullptr) { @@ -2029,6 +2119,7 @@ void DmAuthManager::RequestCredentialDone() int32_t DmAuthManager::ImportCredential(std::string &deviceId, std::string &publicKey) { LOGI("DmAuthManager::ImportCredential"); + LOGI("[temp003] ImportCredential, pk %{public}s", publicKey.c_str()); int32_t osAccountId = MultipleUserConnector::GetCurrentAccountUserID(); return hiChainAuthConnector_->ImportCredential(osAccountId, deviceId, publicKey); } @@ -2037,8 +2128,8 @@ void DmAuthManager::ResponseCredential() { LOGI("DmAuthManager::ResponseCredential start."); CHECK_NULL_VOID(authResponseContext_); - if (authResponseContext_->publicKey == "") { - LOGE("authResponseContext_->publicKey is empty."); + if (authResponseContext_->remotePublicKey == "") { + LOGE("authResponseContext_->remotePublicKey is empty."); authResponseContext_->isFinish = false; isFinishOfLocal_ = false; authMessageProcessor_->SetEncryptFlag(false); @@ -2047,9 +2138,11 @@ void DmAuthManager::ResponseCredential() } std::string publicKey = ""; GenerateCredential(publicKey); - if (ImportCredential(remoteDeviceId_, authResponseContext_->publicKey) != DM_OK) { + LOGI("temp003] ResponseCredential pk %{public}s", publicKey.c_str()); + if (ImportCredential(remoteDeviceId_, authResponseContext_->remotePublicKey) != DM_OK) { LOGE("ResponseCredential import credential failed."); authResponseState_->TransitionTo(std::make_shared()); + softbusConnector_->GetSoftbusSession()->CloseAuthSession(authResponseContext_->sessionId); return; } authResponseContext_->publicKey = publicKey; @@ -2057,6 +2150,40 @@ void DmAuthManager::ResponseCredential() softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); } +bool DmAuthManager::ResponseNewProcessCredential() +{ + LOGI("[temp003] ResponseNewProcessCredential, pk %{public}s", authResponseContext_->remotePublicKey.c_str()); + CHECK_NULL_RETURN(authResponseContext_, false); + if (authResponseContext_->remotePublicKey == "") { + LOGE("authResponseContext_->remotePublicKey is empty."); + authResponseContext_->isFinish = false; + isFinishOfLocal_ = false; + authMessageProcessor_->SetEncryptFlag(false); + authResponseState_->TransitionTo(std::make_shared()); + softbusConnector_->GetSoftbusSession()->CloseAuthSession(authResponseContext_->sessionId); + return false; + } + if (ImportCredential(remoteDeviceId_, authResponseContext_->remotePublicKey) != DM_OK) { + LOGE("ResponseCredential import credential failed."); + authResponseState_->TransitionTo(std::make_shared()); + softbusConnector_->GetSoftbusSession()->CloseAuthSession(authResponseContext_->sessionId); + return false; + } + return true; +} + +void DmAuthManager::ResponseNewSendCredential() +{ + LOGI("DmAuthManager::ResponseCredential start."); + CHECK_NULL_VOID(authResponseContext_); + std::string publicKey = ""; + GenerateCredential(publicKey); + LOGI("[temp003] ResponseNewSendCredential, pk %{public}s", publicKey.c_str()); + authResponseContext_->publicKey = publicKey; + std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_PUBLICKEY); + softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); +} + bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, uint32_t dataLen) { LOGI("DmAuthManager::onTransmit start."); @@ -2081,6 +2208,8 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { + LOGI("[temp003] SrcAuthDeviceFinish"); + std::lock_guard guard(recheckMutex_); CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->confirmOperation != USER_OPERATION_TYPE_ALLOW_AUTH && @@ -2099,6 +2228,7 @@ void DmAuthManager::SrcAuthDeviceFinish() ConverToFinish(); return; } + if (authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); if (!authResponseContext_->isIdenticalAccount && !authResponseContext_->hostPkgName.empty()) { @@ -2107,6 +2237,11 @@ void DmAuthManager::SrcAuthDeviceFinish() softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { authRequestState_->TransitionTo(std::make_shared()); + if (IsRecheckDataReceived()) { + ParseSavedFailedRecheckMsg(); + LOGI("[temp003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); + RequestReCheckMsgDone(); + } } else { authRequestState_->TransitionTo(std::make_shared()); } @@ -2122,6 +2257,11 @@ void DmAuthManager::SrcAuthDeviceFinish() authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { authRequestState_->TransitionTo(std::make_shared()); + if (IsRecheckDataReceived()) { + ParseSavedFailedRecheckMsg(); + LOGI("[temp003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); + RequestReCheckMsgDone(); + } } else { authRequestState_->TransitionTo(std::make_shared()); } @@ -2132,6 +2272,8 @@ void DmAuthManager::SrcAuthDeviceFinish() void DmAuthManager::SinkAuthDeviceFinish() { LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); + LOGI("[temp003] SinkAuthDeviceFinish"); + std::lock_guard guard(recheckMutex_); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { @@ -2142,6 +2284,17 @@ void DmAuthManager::SinkAuthDeviceFinish() SetProcessInfo(); softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); } + if (RemoteSupportRecheck()) { + LOGI("[temp003] SinkAuthDeviceFinish enter AuthResponseReCheckMsg"); + authResponseState_->TransitionTo(std::make_shared()); + if (IsRecheckDataReceived()) { + ParseSavedFailedRecheckMsg(); + LOGI("[temp003] IsRecheckDataReceived true, call ResponseReCheckMsgDone"); + ResponseReCheckMsgDone(); + } + return; + } + std::string srcReqMsg = ""; bool isNeedProcCachedSrcReqMsg = false; { @@ -2162,8 +2315,6 @@ void DmAuthManager::SinkAuthDeviceFinish() } if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { authResponseState_->TransitionTo(std::make_shared()); - } else { - authResponseState_->TransitionTo(std::make_shared()); } } @@ -2196,8 +2347,15 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) LOGI("AuthDeviceError start."); isAuthDevice_ = false; if (authRequestState_ == nullptr || authResponseState_ != nullptr) { - authTimes_++; LOGI("AuthDeviceError sink authTimes %{public}d.", authTimes_); + if (!pincodeDialogEverShown_ && + serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + IsPinCodeValid(serviceInfoProfile_.pinCode)) { + LOGI("[rm003-nopincode] AuthDeviceError, ShowAuthInfoDialog"); + ShowAuthInfoDialog(true); + return; + } + authTimes_++; if (authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->isFinish = false; authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT; @@ -2236,7 +2394,14 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) DmAuthManager::HandleAuthenticateTimeout(name); }); } - authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); + + authRequestContext_->presetPinCode = 0; + if (!pincodeDialogEverShown_) { + LOGI("[rm003] auth error, ShowStartAuthDialog"); + ShowStartAuthDialog(); + } else { + authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_PIN_CODE_ERROR); + } } } } @@ -2348,6 +2513,17 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) } std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); + + int64_t tokenId = GetBinderTokenId(); + int ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfile(tokenId, serviceInfoProfile_); + if (ret != DM_OK) { + LOGI("[rm003-nopincode] GetServiceInfoProfile failed"); + } else { + LOGI("[rm003-nopincode] GetServiceInfoProfile, tokenId %{public}" PRId64 ", ret %{public}d", tokenId, ret); + LOGI("[rm003] authBoxType %{public}s ", serviceInfoProfile_.authBoxType.c_str()); + LOGI("[rm003] authType %{public}d , pinExchangeType %{public}s", serviceInfoProfile_.authType, serviceInfoProfile_.pinExchangeType.c_str()); + LOGI("[rm003] pinCode %{public}s ", serviceInfoProfile_.pinCode.c_str()); + } } void DmAuthManager::ProcRespNegotiate(const int32_t &sessionId) @@ -2466,6 +2642,7 @@ int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, int32_t userId, c void DmAuthManager::PutAccessControlList() { + LOGI("[temp003] PutAccessControlList"); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); @@ -2782,6 +2959,32 @@ int32_t DmAuthManager::GetBinderInfo() return ret; } +int64_t DmAuthManager::GetBinderTokenId() +{ + LOGI("[rm003-nopincode] GetBinderTokenId bundleName is %{public}s", authResponseContext_->bundleName.c_str()); + CHECK_NULL_RETURN(authResponseContext_, 0); + if (authResponseContext_->bundleName.empty()) { + LOGI("[rm003-nopincode] bundleName is empty"); + return authResponseContext_->remoteTokenId; + + } + int32_t localUserId = MultipleUserConnector::GetFirstForegroundUserId(); + std::string localAccountId = MultipleUserConnector::GetOhosAccountIdByUserId(localUserId); + int32_t ret = AppManager::GetInstance(). + GetNativeTokenIdByName(authResponseContext_->bundleName, authResponseContext_->tokenId); + if (ret == DM_OK) { + LOGI("[rm003-nopincode] bundleName is sa"); + return authResponseContext_->tokenId; + } + ret = AppManager::GetInstance().GetHapTokenIdByName(localUserId, + authResponseContext_->peerBundleName, 0, authResponseContext_->tokenId); + if (ret != DM_OK) { + LOGI("[rm003-nopincode] get tokenId by bundleName failed %{public}s", GetAnonyString(authResponseContext_->bundleName).c_str()); + return authResponseContext_->remoteTokenId; + } + return authResponseContext_->tokenId; +} + void DmAuthManager::SetProcessInfo() { CHECK_NULL_VOID(authResponseContext_); @@ -2817,6 +3020,11 @@ void DmAuthManager::ConverToFinish() void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); + if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + LOGI("[temp003] remote version < 502, skip"); + return; + } + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); uint32_t tokenId = 0; @@ -2848,6 +3056,7 @@ void DmAuthManager::ResponseReCheckMsg() authResponseState_->TransitionTo(std::make_shared()); return; } + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->edition = DM_VERSION_5_0_3; @@ -2863,13 +3072,20 @@ void DmAuthManager::ResponseReCheckMsg() authMessageProcessor_->SetEncryptFlag(true); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_RECHECK_MSG); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); - PutAccessControlList(); } void DmAuthManager::RequestReCheckMsgDone() { LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); + LOGI("[temp003] RequestReCheckMsgDone"); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authMessageProcessor_); + CHECK_NULL_VOID(authRequestState_); + if (IsRecheckDataVerified()) { + LOGI("[temp003] recheckData already verified, return"); + return; + } if (!IsSourceMsgValid()) { LOGE("peer deviceId not trust."); authResponseContext_->isFinish = false; @@ -2879,16 +3095,44 @@ void DmAuthManager::RequestReCheckMsgDone() return; } PutAccessControlList(); - authRequestState_->TransitionTo(std::make_shared()); + RequestCredential(); +} + +void DmAuthManager::ResponseReCheckMsgDone() +{ + LOGI("[temp003] ResponseReCheckMsgDone"); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authMessageProcessor_); + if (IsRecheckDataVerified()) { + LOGI("[temp003] recheckData already verified, return"); + return; + } + if (!IsSinkMsgValid()) { + LOGE("peer deviceId not trust."); + authResponseContext_->isFinish = false; + isFinishOfLocal_ = false; + authMessageProcessor_->SetEncryptFlag(false); + int32_t sessionId = authResponseContext_->sessionId; + authResponseState_->TransitionTo(std::make_shared()); + CHECK_NULL_VOID(softbusConnector_->GetSoftbusSession()); + softbusConnector_->GetSoftbusSession()->CloseAuthSession(sessionId); + return; + } + ResponseNewSendCredential(); + PutAccessControlList(); } bool DmAuthManager::IsSinkMsgValid() { - if (authResponseContext_->edition != remoteVersion_ || - authResponseContext_->localDeviceId != remoteDeviceId_ || - authResponseContext_->localUserId != authResponseContext_->remoteUserId || - authResponseContext_->bundleName != authResponseContext_->hostPkgName || - authResponseContext_->localBindLevel != authResponseContext_->bindLevel) { + LOGI("[temp003] IsSinkMsgValid"); + std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); + CHECK_NULL_RETURN(authResponseContext_, false); + authResponseContext_->recheckData.isDataVerified = true; + if (authResponseContext_->recheckData.edition != remoteVersion_ || + authResponseContext_->recheckData.localDeviceId != remoteDeviceId_ || + authResponseContext_->recheckData.localUserId != authResponseContext_->remoteUserId || + authResponseContext_->recheckData.bundleName != authResponseContext_->hostPkgName || + authResponseContext_->recheckData.localBindLevel != authResponseContext_->bindLevel) { return false; } return true; @@ -2896,11 +3140,16 @@ bool DmAuthManager::IsSinkMsgValid() bool DmAuthManager::IsSourceMsgValid() { - if (authResponseContext_->edition != remoteVersion_ || - authResponseContext_->localDeviceId != remoteDeviceId_ || - authResponseContext_->localUserId != authRequestContext_->remoteUserId || - authResponseContext_->bundleName != authResponseContext_->peerBundleName || - authResponseContext_->localBindLevel != authResponseContext_->bindLevel) { + LOGI("[temp003] IsSourceMsgValid"); + std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); + CHECK_NULL_RETURN(authResponseContext_, false); + CHECK_NULL_RETURN(authRequestContext_, false); + authResponseContext_->recheckData.isDataVerified = true; + if (authResponseContext_->recheckData.edition != remoteVersion_ || + authResponseContext_->recheckData.localDeviceId != remoteDeviceId_ || + authResponseContext_->recheckData.localUserId != authRequestContext_->remoteUserId || + authResponseContext_->recheckData.bundleName != authResponseContext_->peerBundleName || + authResponseContext_->recheckData.localBindLevel != authResponseContext_->bindLevel) { return false; } authResponseContext_->localAccountId = authRequestContext_->localAccountId; @@ -2919,11 +3168,21 @@ int32_t DmAuthManager::RegisterAuthenticationType(int32_t authenticationType) } void DmAuthManager::ProcessReqPublicKey() -{ - if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || - authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { - authResponseState_->TransitionTo(std::make_shared()); - return; +{ + std::lock_guard guard(recheckMutex_); + if (RemoteSupportRecheck()) { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { + ResponseNewProcessCredential(); + } else { + LOGE("[temp003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); + } + } else { + if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || + authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { + authResponseState_->TransitionTo(std::make_shared()); + } else { + LOGE("[temp003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); + } } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { std::lock_guard lock(srcReqMsgLock_); diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 88fdf7478..a69205d5e 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -149,7 +149,11 @@ void HiChainAuthConnector::onError(int64_t requestId, int operationCode, int err LOGE("HiChainAuthConnector::onError dmDeviceAuthCallback_ is nullptr."); return; } - dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_FAILED); + if (errorCode == HC_ERR_TIME_OUT) { + dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_TIME_OUT); + } else { + dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_FAILED); + } } void HiChainAuthConnector::onSessionKeyReturned(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen) diff --git a/services/service/BUILD.gn b/services/service/BUILD.gn index d376d792f..c46b449f1 100644 --- a/services/service/BUILD.gn +++ b/services/service/BUILD.gn @@ -220,7 +220,6 @@ if (defined(ohos_lite)) { deps = [ "${devicemanager_path}/commondependency:devicemanagerdependency", "${devicemanager_path}/radar:devicemanagerradar", - "${servicesimpl_path}:devicemanagerserviceimpl", "${softbuscache_parh}:dmdevicecache", "${utils_path}:devicemanagerutils", ] diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 8db515a5a..b6c5d2afe 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -26,6 +26,7 @@ #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" @@ -1446,48 +1447,58 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile) { + DmDeviceInfo devInfo; + int32_t ret = GetLocalDeviceInfo(devInfo); + if (ret != DM_OK) { + LOGE("[rm003] GetLocalDeviceInfo failed"); + } + + profile.udid = devInfo.deviceId; + profile.netWorkId = devInfo.networkId; profile.tokenId = IPCSkeleton::GetCallingTokenID(); - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - profile.udid = localDeviceId; profile.userId = IPCSkeleton::GetCallingUid(); - profile.serviceId = serviceInfo.serviceId; + profile.serviceId = GenRandLongLong(1, 1000000); profile.serviceType = serviceInfo.serviceType; - profile.serviceSubType = serviceInfo.serviceSubType; profile.serviceName = serviceInfo.serviceName; profile.serviceDisplayName = serviceInfo.serviceDisplayName; profile.customData = serviceInfo.customData; - profile.authDescription = serviceInfo.authDescription; - profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope; + profile.bundleName = serviceInfo.bundleName; + profile.moduleName = serviceInfo.moduleName; + profile.abilityName = serviceInfo.abilityName; + profile.authBoxType = serviceInfo.authBoxType; profile.authType = serviceInfo.authType; profile.pinExchangeType = serviceInfo.pinExchangeType; profile.pinCode = serviceInfo.pinCode; + profile.description = serviceInfo.description; + profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope; } void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo) { serviceInfo.serviceId = profile.serviceId; serviceInfo.serviceType = profile.serviceType; - serviceInfo.serviceSubType = profile.serviceSubType; serviceInfo.serviceName = profile.serviceName; serviceInfo.serviceDisplayName = profile.serviceDisplayName; serviceInfo.customData = profile.customData; - serviceInfo.authDescription = profile.authDescription; - serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope; + serviceInfo.bundleName = profile.bundleName; + serviceInfo.moduleName = profile.moduleName; + serviceInfo.abilityName = profile.abilityName; + serviceInfo.authBoxType = profile.authBoxType; serviceInfo.authType = profile.authType; serviceInfo.pinExchangeType = profile.pinExchangeType; serviceInfo.pinCode = profile.pinCode; + serviceInfo.description = profile.description; + serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope; } - int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) { LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - LOGI("[rm003] udid %{public}s", profile.udid.c_str()); - LOGI("[rm003] %{public}llu, %{public}d, %{public}s", profile.tokenId, profile.userId, profile.udid.c_str()); + LOGI("[rm003] tokenId %{public}llu, udid %{public}s", profile.tokenId, profile.udid.c_str()); + LOGI("[rm003] pin %{public}s", profile.pinCode.c_str()); int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 5dcd6490b..c68628054 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -130,15 +130,18 @@ void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { serviceInfo.serviceId = parcel.ReadUint64(); serviceInfo.serviceType = parcel.ReadString(); - serviceInfo.serviceSubType = parcel.ReadString(); serviceInfo.serviceName = parcel.ReadString(); serviceInfo.serviceDisplayName = parcel.ReadString(); serviceInfo.customData = parcel.ReadString(); - serviceInfo.authDescription = parcel.ReadString(); - serviceInfo.serviceDiscoveryScope = parcel.ReadString(); - serviceInfo.authType = parcel.ReadString(); + serviceInfo.bundleName = parcel.ReadString(); + serviceInfo.moduleName = parcel.ReadString(); + serviceInfo.abilityName = parcel.ReadString(); + serviceInfo.authBoxType = parcel.ReadString(); + serviceInfo.authType = parcel.ReadInt32(); serviceInfo.pinExchangeType = parcel.ReadString(); serviceInfo.pinCode = parcel.ReadString(); + serviceInfo.description = parcel.ReadString(); + serviceInfo.serviceDiscoveryScope = parcel.ReadString(); } ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) @@ -835,6 +838,7 @@ ON_IPC_CMD(BIND_DEVICE, MessageParcel &data, MessageParcel &reply) std::string bindParam = data.ReadString(); std::string deviceId = data.ReadString(); int32_t bindType = data.ReadInt32(); + LOGE("[temp003] bindParam %{public}s", bindParam.c_str()); int32_t result = DM_OK; result = DeviceManagerService::GetInstance().BindDevice(pkgName, bindType, deviceId, bindParam); if (!reply.WriteInt32(result)) { diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index ecb4e0a70..74edd0999 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -1501,7 +1501,7 @@ HWTEST_F(AuthMessageProcessorTest, ParsePublicKeyMessageExt_001, testing::ext::T nlohmann::json jsonObj; jsonObj[TAG_PUBLICKEY] = 2121; authMessageProcessor->ParsePublicKeyMessageExt(jsonObj); - ASSERT_EQ(authMessageProcessor->authResponseContext_->publicKey.empty(), true); + ASSERT_EQ(authMessageProcessor->authResponseContext_->remotePublicKey.empty(), true); } HWTEST_F(AuthMessageProcessorTest, ParsePublicKeyMessageExt_002, testing::ext::TestSize.Level0) @@ -1515,7 +1515,7 @@ HWTEST_F(AuthMessageProcessorTest, ParsePublicKeyMessageExt_002, testing::ext::T nlohmann::json jsonObj; jsonObj[TAG_PUBLICKEY] = "2121"; authMessageProcessor->ParsePublicKeyMessageExt(jsonObj); - ASSERT_EQ(authMessageProcessor->authResponseContext_->publicKey.empty(), false); + ASSERT_EQ(authMessageProcessor->authResponseContext_->remotePublicKey.empty(), false); } HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessageExt_001, testing::ext::TestSize.Level0) -- Gitee From 7858d72ea04b141cad50ee991618028b9e129fde Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 17 Jan 2025 19:16:04 +0800 Subject: [PATCH 03/55] hml Change-Id: I4be802742914accee77f1a30edbb3a05fdd34b13 --- common/include/dm_constants.h | 5 +++ interfaces/kits/js4.0/src/dm_native_util.cpp | 14 ++++++++ .../include/authentication/dm_auth_manager.h | 4 +++ .../src/authentication/dm_auth_manager.cpp | 33 +++++++++++++++++-- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index ece2184ff..02309d700 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -261,6 +261,11 @@ 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_RELEASETIME = "hmlReleaseTime"; +constexpr const char* PARAM_KEY_HML_ENABLE_160M = "hmlEnable160M"; +constexpr const char* PARAM_KEY_HML_ACTIONID = "hmlActionId"; + // screen state constexpr int32_t DM_SCREEN_UNKNOWN = -1; constexpr int32_t DM_SCREEN_ON = 0; diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 1d8a814dd..1a5bc4ffd 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -336,6 +336,15 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b int32_t bindLevel = 0; JsObjectToInt(env, object, "bindLevel", bindLevel); + int32_t connSessionType = 0; + JsObjectToInt(env, object, "connSessionType", connSessionType); + int32_t hmlReleaseTime = 0; + JsObjectToInt(env, object, "hmlReleaseTime", hmlReleaseTime); + bool hmlEnable160M = -1; + JsObjectToBool(env, object, "hmlEnable160M", hmlEnable160M); + int32_t hmlActionId = 0; + JsObjectToInt(env, object, "hmlActionId", hmlActionId); + nlohmann::json jsonObj; jsonObj[AUTH_TYPE] = bindType; jsonObj[APP_OPERATION] = std::string(appOperation); @@ -351,6 +360,11 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[PARAM_KEY_WIFI_IP] = std::string(wifiIP); jsonObj[PARAM_KEY_WIFI_PORT] = wifiPort; jsonObj[BIND_LEVEL] = bindLevel; + + jsonObj[PARAM_KEY_CONN_SESSIONTYPE] = connSessionType; + jsonObj[PARAM_KEY_HML_RELEASETIME] = hmlReleaseTime; + jsonObj[PARAM_KEY_HML_ENABLE_160M] = hmlEnable160M; + jsonObj[PARAM_KEY_HML_ACTIONID] = hmlActionId; bindParam = SafetyDump(jsonObj); } diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 7dee5dbab..fc5c20d5e 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -135,6 +135,10 @@ typedef struct DmAuthRequestContext { std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; int32_t presetPinCode = 0; + int32_t connSessionType = 0; + int32_t hmlReleaseTime = 0; + bool hmlEnable160M = false; + int32_t hmlActionId = 0; } DmAuthRequestContext; typedef struct DMRecheckData { diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 54e060293..c639d4a1c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -280,10 +280,27 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) if (IsString(jsonObject, PARAM_KEY_PIN_CODE)) { std::string strpin = jsonObject[PARAM_KEY_PIN_CODE].get(); authRequestContext_->presetPinCode = std::stoi(strpin); - LOGI("[rm003-nopincode] input incode %{public}d", authRequestContext_->presetPinCode); + LOGI("[rm003-nopincode] input pincode %{public}d", authRequestContext_->presetPinCode); } else if(IsInt32(jsonObject, PARAM_KEY_PIN_CODE)) { authRequestContext_->presetPinCode = jsonObject[PARAM_KEY_PIN_CODE].get(); - LOGI("[rm003-nopincode] 22 input incode %{public}d", authRequestContext_->presetPinCode); + LOGI("[rm003-nopincode] 22 input pincode %{public}d", authRequestContext_->presetPinCode); + } + + if (IsInt32(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { + authRequestContext_->connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); + LOGI("[rm003-nopincode] input connSessionType %{public}d", authRequestContext_->connSessionType); + } + if (IsInt32(jsonObject, PARAM_KEY_HML_RELEASETIME)) { + authRequestContext_->hmlReleaseTime = jsonObject[PARAM_KEY_HML_RELEASETIME].get(); + LOGI("[rm003-nopincode] input hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); + } + if (IsBool(jsonObject, PARAM_KEY_HML_ENABLE_160M)) { + authRequestContext_->hmlEnable160M = jsonObject[PARAM_KEY_HML_ENABLE_160M].get(); + LOGI("[rm003-nopincode] input hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); + } + if (IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { + authRequestContext_->hmlActionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + LOGI("[rm003-nopincode] input hmlActionId %{public}d", authRequestContext_->hmlActionId); } } authRequestContext_->bundleName = GetBundleName(jsonObject); @@ -840,7 +857,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 (authRequestContext_->connSessionType == 1) { + LOGI("[temp003] EstablishAuthChannel, try OpenAuthSessionWithPara"); + LOGI("[temp003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); + LOGI("[temp003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); + LOGI("[temp003] hmlActionId %{public}d", authRequestContext_->hmlActionId); + } + + { + sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); + } struct RadarInfo info = { .funcName = "EstablishAuthChannel", .stageRes = (sessionId > 0) ? -- Gitee From 64a6424464fb75b37b63c80353f02193af796a05 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 17 Jan 2025 19:16:04 +0800 Subject: [PATCH 04/55] hml Change-Id: I4be802742914accee77f1a30edbb3a05fdd34b13 --- .../dependency/softbus/softbus_session.h | 7 ++++ .../src/authentication/dm_auth_manager.cpp | 39 ++++++++++++------- .../dependency/softbus/softbus_session.cpp | 26 +++++++++++++ .../service/src/device_manager_service.cpp | 5 ++- 4 files changed, 61 insertions(+), 16 deletions(-) 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/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index c639d4a1c..6a2f44114 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -247,6 +247,9 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) { + std::string debug = SafetyDump(jsonObject); + LOGI("[rm003] debug %{public}s", debug.c_str()); + if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { authRequestContext_->targetPkgName = jsonObject[TARGET_PKG_NAME_KEY].get(); @@ -279,11 +282,10 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } if (IsString(jsonObject, PARAM_KEY_PIN_CODE)) { std::string strpin = jsonObject[PARAM_KEY_PIN_CODE].get(); - authRequestContext_->presetPinCode = std::stoi(strpin); - LOGI("[rm003-nopincode] input pincode %{public}d", authRequestContext_->presetPinCode); - } else if(IsInt32(jsonObject, PARAM_KEY_PIN_CODE)) { - authRequestContext_->presetPinCode = jsonObject[PARAM_KEY_PIN_CODE].get(); - LOGI("[rm003-nopincode] 22 input pincode %{public}d", authRequestContext_->presetPinCode); + if (DmAuthManager::IsPinCodeValid(strpin)) { + authRequestContext_->presetPinCode = std::stoi(strpin); + LOGI("[rm003-nopincode] input pincode %{public}s", strpin.c_str()); + } } if (IsInt32(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { @@ -863,9 +865,8 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) LOGI("[temp003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); LOGI("[temp003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); LOGI("[temp003] hmlActionId %{public}d", authRequestContext_->hmlActionId); - } - - { + sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); + } else { sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); } struct RadarInfo info = { @@ -1208,7 +1209,8 @@ int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { if (serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - IsPinCodeValid(serviceInfoProfile_.pinCode)) { + DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode) && + authResponseContext_->isPincodeSetted) { authResponseContext_->code = std::stoi(serviceInfoProfile_.pinCode); LOGI("[rm003-nopincode] import from dp, pin %{public}d", authResponseContext_->code); } else if (!authResponseContext_->isShowDialog) { @@ -1526,6 +1528,14 @@ bool DmAuthManager::IsPinCodeValid(std::string strpin) return true; } +bool DmAuthManager::IsPinCodeValid(int32_t numpin) +{ + if (numpin < MIN_PIN_CODE || numpin > MAX_PIN_CODE) { + return false; + } + return true; +} + std::string DmAuthManager::GenerateGroupName() { if (authResponseContext_ == nullptr) { @@ -1652,15 +1662,15 @@ void DmAuthManager::ShowAuthInfoDialog(bool authDeviceError) } LOGI("DmAuthManager::ShowAuthInfoDialog start"); if (!authDeviceError && serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - IsPinCodeValid(serviceInfoProfile_.pinCode)) { + DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode) && authResponseContext_->isPincodeSetted) { LOGI("[rm003-nopincode] pin import from dp, not show dialog"); return; } - if (!authResponseContext_->isShowDialog) { - LOGI("not show dialog."); + if (pincodeDialogEverShown_) { return; } - if (pincodeDialogEverShown_) { + if (!authResponseContext_->isShowDialog) { + LOGI("not show dialog."); return; } struct RadarInfo info = { @@ -1670,7 +1680,6 @@ void DmAuthManager::ShowAuthInfoDialog(bool authDeviceError) if (!DmRadarHelper::GetInstance().ReportAuthPullPinBox(info)) { LOGE("ReportAuthPullPinBox failed"); } - nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = authResponseContext_->code; std::string authParam = SafetyDump(jsonObj); @@ -2377,7 +2386,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) LOGI("AuthDeviceError sink authTimes %{public}d.", authTimes_); if (!pincodeDialogEverShown_ && serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - IsPinCodeValid(serviceInfoProfile_.pinCode)) { + DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode)) { LOGI("[rm003-nopincode] AuthDeviceError, ShowAuthInfoDialog"); ShowAuthInfoDialog(true); return; diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 9e579ba80..a04f046be 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -28,6 +28,7 @@ namespace DistributedHardware { std::shared_ptr SoftbusSession::sessionCallback_ = nullptr; constexpr const char* DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; constexpr int32_t MAX_DATA_LEN = 65535; +typedef (*LP_OpenAuthSessionWithPara)(const std::string &deviceId, int32_t actionId, bool enable160m); static void OnShutdown(int32_t socket, ShutdownReason reason) { @@ -110,6 +111,31 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) return sessionId; } +int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool enable160m) +{ + DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); + static LP_OpenAuthSessionWithPara symOpen = dlsym(RTLD_NEXT, "OpenAuthSessionWithPara"); + if (symOpen == nullptr) { + LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); + return SOFTBUS_NOT_IMPLEMENT; + } + int32_t sessionId = -1; + std::string connectAddr; + ConnectionAddr *addrInfo = SoftbusConnector::GetConnectAddr(deviceId, connectAddr); + if (addrInfo == nullptr) { + LOGE("[SOFTBUS]addrInfo is nullptr. sessionId: %{public}d.", sessionId); + return sessionId; + } + //sessionId = (*symOpen)(DM_SESSION_NAME, addrInfo, 1, nullptr); + if (sessionId < 0) { + LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); + return sessionId; + } + DmTraceEnd(); + LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); + return sessionId; +} + int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) { LOGI("CloseAuthSession."); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b6c5d2afe..40c2bb804 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1458,7 +1458,7 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn profile.tokenId = IPCSkeleton::GetCallingTokenID(); profile.userId = IPCSkeleton::GetCallingUid(); - profile.serviceId = GenRandLongLong(1, 1000000); + profile.serviceId = GenRandLongLong(1, 1000000); //todo serviceId logic profile.serviceType = serviceInfo.serviceType; profile.serviceName = serviceInfo.serviceName; profile.serviceDisplayName = serviceInfo.serviceDisplayName; @@ -1494,6 +1494,7 @@ void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::Servi int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) { + //todo permission verifier LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); @@ -1512,6 +1513,8 @@ int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) int32_t DeviceManagerService::UnregisterServiceInfo(DMServiceInfo &serviceInfo) { + //todo permission verifier + //todo parameter LOGI("[rm003] DeviceManagerService::UnregisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); -- Gitee From 78e8031130ba7980e2d3610caf286c0f5087d2ae Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Tue, 21 Jan 2025 13:27:24 +0800 Subject: [PATCH 05/55] rebase Change-Id: Iffe007eec131177469a7e83efee11696bfc01c1f --- .../native_cpp/src/device_manager_impl.cpp | 3 +- .../authentication/auth_message_processor.h | 1 + .../include/authentication/dm_auth_manager.h | 4 +- .../authentication/auth_message_processor.cpp | 13 ++++++ .../src/authentication/dm_auth_manager.cpp | 45 ++++++++++++++++++- 5 files changed, 63 insertions(+), 3 deletions(-) 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 f10642238..aeac2facd 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2603,8 +2603,9 @@ int32_t DeviceManagerImpl::GetDeviceProfileInfoList(const std::string &pkgName, req->SetFilterOptions(filterOptions); ret = ipcClientProxy_->SendRequest(GET_DEVICE_PROFILE_INFO_LIST, req, rsp); if (ret != DM_OK) { - LOGE("error: Failed with ret %{public}d", ret); + LOGE("error: Send Request failed ret: %{public}d", ret); DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); + return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index d21279a34..b97818a49 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_PINCODE_SETTED = "TAG_PINCODE_SETTED"; constexpr const char* TAG_TOKEN = "TOKEN"; constexpr const char* TAG_CRYPTO_NAME = "CRYPTONAME"; constexpr const char* TAG_CRYPTO_VERSION = "CRYPTOVERSION"; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index fc5c20d5e..3adfe846e 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -212,6 +212,7 @@ typedef struct DmAuthResponseContext { std::string edition; int32_t localBindLevel; DMRecheckData recheckData; + bool isPincodeSetted = false; } DmAuthResponseContext; class AuthMessageProcessor; @@ -417,7 +418,8 @@ public: * @tc.desc: of the DeviceManager Authenticate Manager * @tc.type: FUNC */ - bool IsPinCodeValid(std::string strpin); + static bool IsPinCodeValid(std::string strpin); + static bool IsPinCodeValid(int32_t numpin); /** * @tc.name: DmAuthManager::ShowConfigDialog diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index 8065574fb..edca70baf 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -71,6 +71,13 @@ void AuthMessageProcessor::GetJsonObj(nlohmann::json &jsonObj) } else { jsonObj[TAG_IS_SHOW_DIALOG] = true; } + if (DmAuthManager::IsPinCodeValid(authRequestContext_->presetPinCode)) { + LOGI("[rm003-nopincode] TAG_PINCODE_SETTED"); + jsonObj[TAG_PINCODE_SETTED] = true; + } else { + LOGI("[rm003-nopincode] TAG_PINCODE_SETTED not set"); + jsonObj[TAG_PINCODE_SETTED] = false; + } jsonObj[TAG_APP_OPERATION] = authRequestContext_->appOperation; jsonObj[TAG_CUSTOM_DESCRIPTION] = authRequestContext_->customDesc; jsonObj[TAG_APP_NAME] = authRequestContext_->appName; @@ -458,6 +465,12 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) } else { authResponseContext_->isShowDialog = true; } + if (IsBool(json, TAG_PINCODE_SETTED)) { + authResponseContext_->isPincodeSetted = json[TAG_PINCODE_SETTED].get(); + } else { + authResponseContext_->isPincodeSetted = false; + } + LOGI("[rm003-nopincode] isPincodeSetted %{public}d", authResponseContext_->isPincodeSetted); if (IsInt32(json, TAG_BIND_TYPE_SIZE)) { int32_t bindTypeSize = json[TAG_BIND_TYPE_SIZE].get(); if (bindTypeSize > MAX_BINDTYPE_SIZE) { diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 6a2f44114..199d232f9 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -65,7 +65,7 @@ const int32_t CLONE_WAIT_REQUEST_TIMEOUT = 10; const int32_t CLONE_SESSION_HEARTBEAT_TIMEOUT = 20; const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; -const int32_t MAX_AUTH_TIMES = 3666666; +const int32_t MAX_AUTH_TIMES = 3; const int32_t MIN_PIN_TOKEN = 10000000; const int32_t MAX_PIN_TOKEN = 90000000; const int32_t MIN_PIN_CODE = 100000; @@ -3225,5 +3225,48 @@ void DmAuthManager::ProcessReqPublicKey() isNeedProcCachedSrcReqMsg_ = true; } } + +bool DmAuthManager::RemoteSupportRecheck() +{ + if (CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { + return true; + } + return false; +} + +bool DmAuthManager::IsRecheckDataReceived() +{ + LOGI("[temp003] IsRecheckDataReceived"); + CHECK_NULL_RETURN(authResponseContext_, false); + return authResponseContext_->recheckData.isDataReceived; +} + +bool DmAuthManager::IsRecheckDataParsed() +{ + LOGI("[temp003] IsRecheckDataParsed"); + CHECK_NULL_RETURN(authResponseContext_, false); + return authResponseContext_->recheckData.isDataParsed; +} + +bool DmAuthManager::IsRecheckDataVerified() +{ + LOGI("[temp003] IsRecheckDataVerified"); + CHECK_NULL_RETURN(authResponseContext_, false); + return authResponseContext_->recheckData.isDataVerified; +} + +void DmAuthManager::ParseSavedFailedRecheckMsg() +{ + std::lock_guard guard(savedParseFailedRecheckMsgMutex_); + if (savedParseFailedRecheckMsg_.empty()) { + return; + } + LOGI("[temp003] process savedParseFailedRecheckMsg_"); + CHECK_NULL_VOID(authResponseContext_); + CHECK_NULL_VOID(authMessageProcessor_); + authMessageProcessor_->SetResponseContext(authResponseContext_); + authMessageProcessor_->ParseMessage(savedParseFailedRecheckMsg_); + savedParseFailedRecheckMsg_.clear(); +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 7d07a74bd9739a451c469c58ea5bde965d8dfca5 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Tue, 21 Jan 2025 14:04:28 +0800 Subject: [PATCH 06/55] fix Change-Id: I455ae34d2e4bdc8e12617d29907cbb9869dde931 --- common/include/dm_constants.h | 2 ++ interfaces/kits/js4.0/src/dm_native_util.cpp | 7 ++-- .../include/authentication/dm_auth_manager.h | 3 +- .../dependency/softbus/softbus_connector.h | 7 ++++ .../src/authentication/dm_auth_manager.cpp | 34 ++++++++++++++----- .../dependency/softbus/softbus_connector.cpp | 12 +++++++ .../dependency/softbus/softbus_session.cpp | 29 ++++++++-------- 7 files changed, 67 insertions(+), 27 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 02309d700..6b14e6ef1 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -266,6 +266,8 @@ constexpr const char* PARAM_KEY_HML_RELEASETIME = "hmlReleaseTime"; 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/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 1a5bc4ffd..52839ecfb 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -42,6 +42,7 @@ const int32_t DM_NAPI_DISCOVER_EXTRA_INIT_ONE = -1; const int32_t DM_NAPI_DISCOVER_EXTRA_INIT_TWO = -2; const int32_t DM_NAPI_DESCRIPTION_BUF_LENGTH = 16384; const int32_t DM_NAPI_BUF_LENGTH = 256; +const int32_t DM_NAPI_CONN_SESSIONTYPE_LENGTH = 16; const int32_t MAX_OBJECT_LEN = 4096; void JsObjectToString(const napi_env &env, const napi_value &object, const std::string &fieldStr, @@ -336,8 +337,8 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b int32_t bindLevel = 0; JsObjectToInt(env, object, "bindLevel", bindLevel); - int32_t connSessionType = 0; - JsObjectToInt(env, object, "connSessionType", connSessionType); + char connSessionType[DM_NAPI_CONN_SESSIONTYPE_LENGTH] = ""; + JsObjectToString(env, object, "connSessionType", connSessionType, sizeof(connSessionType)); int32_t hmlReleaseTime = 0; JsObjectToInt(env, object, "hmlReleaseTime", hmlReleaseTime); bool hmlEnable160M = -1; @@ -361,7 +362,7 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[PARAM_KEY_WIFI_PORT] = wifiPort; jsonObj[BIND_LEVEL] = bindLevel; - jsonObj[PARAM_KEY_CONN_SESSIONTYPE] = connSessionType; + jsonObj[PARAM_KEY_CONN_SESSIONTYPE] = std::string(connSessionType); jsonObj[PARAM_KEY_HML_RELEASETIME] = hmlReleaseTime; jsonObj[PARAM_KEY_HML_ENABLE_160M] = hmlEnable160M; jsonObj[PARAM_KEY_HML_ACTIONID] = hmlActionId; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 3adfe846e..21ce290a1 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -135,7 +135,7 @@ typedef struct DmAuthRequestContext { std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; int32_t presetPinCode = 0; - int32_t connSessionType = 0; + std::string connSessionType; int32_t hmlReleaseTime = 0; bool hmlEnable160M = false; int32_t hmlActionId = 0; @@ -504,6 +504,7 @@ public: int32_t RegisterAuthenticationType(int32_t authenticationType); private: + bool IsHmlSessionType(); 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); diff --git a/services/implementation/include/dependency/softbus/softbus_connector.h b/services/implementation/include/dependency/softbus/softbus_connector.h index 2536eeacc..30d44b6b1 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(const int32_t sessionId); public: SoftbusConnector(); ~SoftbusConnector(); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 199d232f9..724e09dbd 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -127,6 +127,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) { @@ -288,9 +294,9 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } } - if (IsInt32(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { - authRequestContext_->connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); - LOGI("[rm003-nopincode] input connSessionType %{public}d", authRequestContext_->connSessionType); + if (IsString(jsonObject, PARAM_KEY_CONN_SESSIONTYPE)) { + authRequestContext_->connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); + LOGI("[rm003-nopincode] input connSessionType %{public}s", authRequestContext_->connSessionType.c_str()); } if (IsInt32(jsonObject, PARAM_KEY_HML_RELEASETIME)) { authRequestContext_->hmlReleaseTime = jsonObject[PARAM_KEY_HML_RELEASETIME].get(); @@ -860,7 +866,7 @@ void DmAuthManager::HandleAuthenticateTimeout(std::string name) int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { int32_t sessionId = 0; - if (authRequestContext_->connSessionType == 1) { + if (authRequestContext_->connSessionType == CONN_SESSION_TYPE_HML) { LOGI("[temp003] EstablishAuthChannel, try OpenAuthSessionWithPara"); LOGI("[temp003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); LOGI("[temp003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); @@ -1159,7 +1165,11 @@ bool DmAuthManager::IsAuthFinish() if ((authResponseContext_->isIdenticalAccount && !authResponseContext_->authed) || (authResponseContext_->authed && !authResponseContext_->isOnline)) { - softbusConnector_->JoinLnn(authRequestContext_->addr); + if (IsHmlSessionType()) { + softbusConnector_->JoinLnnByHml(authRequestContext_->sessionId); + } else { + softbusConnector_->JoinLnn(authRequestContext_->addr); + } authRequestContext_->reason = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authResponseContext_->reply = DM_OK; @@ -2145,7 +2155,11 @@ void DmAuthManager::RequestCredentialDone() if (timer_ != nullptr) { timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } - softbusConnector_->JoinLnn(authRequestContext_->addr); + if (IsHmlSessionType()) { + softbusConnector_->JoinLnnByHml(authRequestContext_->sessionId); + } else { + softbusConnector_->JoinLnn(authRequestContext_->addr); + } authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; authResponseContext_->reply = DM_OK; @@ -2284,7 +2298,11 @@ void DmAuthManager::SrcAuthDeviceFinish() return; } if (!authResponseContext_->isOnline && authResponseContext_->haveCredential) { - softbusConnector_->JoinLnn(authRequestContext_->addr); + if (IsHmlSessionType()) { + softbusConnector_->JoinLnnByHml(authRequestContext_->sessionId); + } else { + softbusConnector_->JoinLnn(authRequestContext_->addr); + } timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); ConverToFinish(); return; @@ -3130,8 +3148,8 @@ void DmAuthManager::RequestReCheckMsgDone() authRequestState_->TransitionTo(std::make_shared()); return; } - PutAccessControlList(); RequestCredential(); + PutAccessControlList(); } void DmAuthManager::ResponseReCheckMsgDone() diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index cf4eeb5d3..a65aab3bc 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -96,6 +96,18 @@ void SoftbusConnector::JoinLnn(const std::string &deviceId) return; } +void SoftbusConnector::JoinLnnByHml(const int32_t sessionId) +{ + LOGI("start, JoinLnnByHml sessionId: %{public}d.", sessionId); + ConnectionAddr addrInfo; + addrInfo.type = CONNECTION_ADDR_SESSION; + addrInfo.info.session.sessionId = sessionId; + int32_t ret = ::JoinLNN(DM_PKG_NAME, &addrInfo, OnSoftbusJoinLNNResult); + if (ret != DM_OK) { + LOGE("[SOFTBUS]JoinLNN failed, ret: %{public}d.", ret); + } +} + 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 a04f046be..1e953f9c5 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -22,13 +22,15 @@ #include "dm_log.h" #include "nlohmann/json.hpp" #include "softbus_connector.h" - +#include "softbus_error_code.h" +#ifdef SOFTBUS_ENHANCE_FLAG +#include "trans_auth_lane_pending_ctl.h" +#endif namespace OHOS { namespace DistributedHardware { std::shared_ptr SoftbusSession::sessionCallback_ = nullptr; constexpr const char* DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; constexpr int32_t MAX_DATA_LEN = 65535; -typedef (*LP_OpenAuthSessionWithPara)(const std::string &deviceId, int32_t actionId, bool enable160m); static void OnShutdown(int32_t socket, ShutdownReason reason) { @@ -113,20 +115,16 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool enable160m) { +#ifndef SOFTBUS_ENHANCE_FLAG + LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); + return SOFTBUS_NOT_IMPLEMENT; +#else DmTraceStart(std::string(DM_HITRACE_AUTH_TO_OPPEN_SESSION)); - static LP_OpenAuthSessionWithPara symOpen = dlsym(RTLD_NEXT, "OpenAuthSessionWithPara"); - if (symOpen == nullptr) { - LOGE("[SOFTBUS] OpenAuthSessionWithPara no implement"); - return SOFTBUS_NOT_IMPLEMENT; - } - int32_t sessionId = -1; - std::string connectAddr; - ConnectionAddr *addrInfo = SoftbusConnector::GetConnectAddr(deviceId, connectAddr); - if (addrInfo == nullptr) { - LOGE("[SOFTBUS]addrInfo is nullptr. sessionId: %{public}d.", sessionId); - return sessionId; - } - //sessionId = (*symOpen)(DM_SESSION_NAME, addrInfo, 1, nullptr); + LinkPara para; + para.type = PARA_ACTION; + para.action = actionId; + para.enable160M = enable160m; + int32_t sessionId = OpenAuthSessionWithPara(DM_SESSION_NAME, ¶); if (sessionId < 0) { LOGE("[SOFTBUS]open session error, sessionId: %{public}d.", sessionId); return sessionId; @@ -134,6 +132,7 @@ int32_t SoftbusSession::OpenAuthSessionWithPara(const std::string &deviceId, int DmTraceEnd(); LOGI("OpenAuthSessionWithPara success. sessionId: %{public}d.", sessionId); return sessionId; +#endif } int32_t SoftbusSession::CloseAuthSession(int32_t sessionId) -- Gitee From 99f88b6b79fe708e15d6915de9129225f5543ccf Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Tue, 21 Jan 2025 16:07:07 +0800 Subject: [PATCH 07/55] remove log Change-Id: I888c1b1e64d89edea4dc7e6b181ffb115ce17e1b --- interfaces/kits/js4.0/src/dm_native_util.cpp | 2 +- interfaces/kits/js4.0/src/native_devicemanager_js.cpp | 1 + services/service/src/device_manager_service.cpp | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 52839ecfb..6bfd4194f 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -341,7 +341,7 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b JsObjectToString(env, object, "connSessionType", connSessionType, sizeof(connSessionType)); int32_t hmlReleaseTime = 0; JsObjectToInt(env, object, "hmlReleaseTime", hmlReleaseTime); - bool hmlEnable160M = -1; + bool hmlEnable160M = false; JsObjectToBool(env, object, "hmlEnable160M", hmlEnable160M); int32_t hmlActionId = 0; JsObjectToInt(env, object, "hmlActionId", hmlActionId); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 230feefb7..7643d6a55 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1693,6 +1693,7 @@ bool xProcessRegisterServiceInfo(std::string bindParam) serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); + LOGI("[temp003] DeviceManager::GetInstance().RegisterServiceInfo complete"); return true; } } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 6a97d1106..84989c2d5 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1498,14 +1498,13 @@ int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - LOGI("[rm003] tokenId %{public}llu, udid %{public}s", profile.tokenId, profile.udid.c_str()); + LOGI("[rm003] udid %{public}s", profile.udid.c_str()); LOGI("[rm003] pin %{public}s", profile.pinCode.c_str()); int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); DistributedDeviceProfile::ServiceInfoProfile profileRet; DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); - LOGI("[rm003] tokenId %{public}llu", profileRet.tokenId); LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); return ret; -- Gitee From 681b348d7a6127a265d68a0a1b2666ff96825124 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Wed, 22 Jan 2025 18:35:43 +0800 Subject: [PATCH 08/55] fix Change-Id: I4c184a8da8d58472534cb8df59663679823ed533 --- .../src/authentication/dm_auth_manager.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 8aaa0a5a2..4e57cd48a 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -3105,16 +3105,6 @@ void DmAuthManager::ResponseReCheckMsg() { LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); - if (!IsSinkMsgValid()) { - LOGE("peer deviceId not trust."); - authResponseContext_->isFinish = false; - isFinishOfLocal_ = false; - authMessageProcessor_->SetEncryptFlag(false); - int32_t sessionId = authResponseContext_->sessionId; - authResponseState_->TransitionTo(std::make_shared()); - return; - } - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); authResponseContext_->edition = DM_VERSION_5_0_3; -- Gitee From 3a91ae92f4b036ded9b09f988116dcfb8acab0c6 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 09:22:43 +0800 Subject: [PATCH 09/55] fix bug Change-Id: I4d3692c283af37d5dbce5cb0898c3656f460339e --- common/include/dm_constants.h | 3 ++- .../implementation/src/authentication/dm_auth_manager.cpp | 7 +++++-- .../src/dependency/hichain/hichain_auth_connector.cpp | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 6b14e6ef1..732b12137 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -128,7 +128,8 @@ enum { ERR_DM_HILINKSVC_REPLY_FAILED = 96929827, ERR_DM_HILINKSVC_ICON_URL_EMPTY = 96929828, ERR_DM_HILINKSVC_DISCONNECT = 96929829, - ERR_DM_WISE_NEED_LOGIN = 96929830 + ERR_DM_WISE_NEED_LOGIN = 96929830, + ERR_DM_HICHAIN_PROOFMISMATCH = 96929831, }; constexpr const char* TAG_GROUP_ID = "groupId"; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 4e57cd48a..5f07a3591 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1535,6 +1535,9 @@ int32_t DmAuthManager::GeneratePincode() bool DmAuthManager::IsPinCodeValid(std::string strpin) { + if (strpin.empty()) { + return false; + } int pinnum = std::stoi(strpin); if (pinnum < MIN_PIN_CODE || pinnum > MAX_PIN_CODE) { return false; @@ -2406,7 +2409,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) isAuthDevice_ = false; if (authRequestState_ == nullptr || authResponseState_ != nullptr) { LOGI("AuthDeviceError sink authTimes %{public}d.", authTimes_); - if (!pincodeDialogEverShown_ && + if (errorCode == ERR_DM_HICHAIN_PROOFMISMATCH && !pincodeDialogEverShown_ && serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode)) { LOGI("[rm003-nopincode] AuthDeviceError, ShowAuthInfoDialog"); @@ -2454,7 +2457,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) } authRequestContext_->presetPinCode = 0; - if (!pincodeDialogEverShown_) { + if (!pincodeDialogEverShown_ && errorCode == ERR_DM_HICHAIN_PROOFMISMATCH) { LOGI("[rm003] auth error, ShowStartAuthDialog"); ShowStartAuthDialog(); } else { diff --git a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp index 9a15e6e3c..b0c3894ab 100644 --- a/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp +++ b/services/implementation/src/dependency/hichain/hichain_auth_connector.cpp @@ -145,8 +145,8 @@ void HiChainAuthConnector::onError(int64_t requestId, int operationCode, int err LOGE("HiChainAuthConnector::onError dmDeviceAuthCallback_ is nullptr."); return; } - if (errorCode == HC_ERR_TIME_OUT) { - dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_TIME_OUT); + if (errorCode == PROOF_MISMATCH) { + dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_HICHAIN_PROOFMISMATCH); } else { dmDeviceAuthCallback_->AuthDeviceError(requestId, ERR_DM_FAILED); } -- Gitee From 5a17e512b5e5563134e35135ca7653e860e91200 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 10:38:47 +0800 Subject: [PATCH 10/55] fix Change-Id: I9014551bcf2a0f2e32d12401f2fd4725bc0aad64 --- common/include/dm_constants.h | 2 + sa_profile/device_manager.cfg | 1 + .../service/include/device_manager_service.h | 2 + .../service/src/device_manager_service.cpp | 63 ++++++++++++++++--- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 732b12137..1c9e2b522 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -50,6 +50,8 @@ enum { ERR_DM_BIND_USER_CANCEL_PIN_CODE_DISPLAY = -20056, ERR_DM_SYNC_DELETE_DEVICE_REPEATED = -20058, ERR_DM_VERSION_INCOMPATIBLE = -20059, + ERR_DM_SERVICEINFO_NOTVALID = -20060, + ERR_DM_SERVICEINFO_GENSERVICEID_FAILED = -20061, ERR_DM_FAILED = 96929744, ERR_DM_NOT_INIT = 96929746, 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/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index d9e5fdd65..249147d62 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -184,6 +184,8 @@ public: int32_t UnbindTarget(const std::string &pkgName, const PeerTargetId &targetId, const std::map &unbindParam); + bool IsServiceInfoValid(const DMServiceInfo &serviceInfo); + int64_t GenerateSerivceId(std::string udid, int32_t userId); void InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 84989c2d5..3e9a00e7c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -41,6 +41,7 @@ #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 @@ -65,6 +66,9 @@ constexpr const char* LIB_IMPL_NAME = "libdevicemanagerserviceimpl.so"; constexpr const char* LIB_DM_ADAPTER_NAME = "libdevicemanageradapter.z.so"; constexpr const char* LIB_DM_RESIDENT_NAME = "libdevicemanagerresident.z.so"; +#define RANDOM_SERVICEID_MIN 10000 +#define RANDOM_SERVICEID_MAX 999999 + namespace OHOS { namespace DistributedHardware { DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService); @@ -1445,6 +1449,48 @@ int32_t DeviceManagerService::UnbindTarget(const std::string &pkgName, const Pee return dmServiceImplExtResident_->UnbindTargetExt(pkgName, targetId, unbindParam); } +bool DeviceManagerService::IsServiceInfoValid(const DMServiceInfo &serviceInfo) +{ + //todo + return true; +} + +int64_t DeviceManagerService::GenerateSerivceId(std::string udid, int32_t userId) +{ + if (udid.empty()) { + LOGI("[rm003] GenerateSeivceId udid empty"); + return 0; + } + const uint32_t dataLength = sizeof(int64_t) + sizeof(int32_t) + udid.length(); + std::unique_ptr data = std::make_unique(dataLength); + int64_t randomSeed = GenRandLongLong(RANDOM_SERVICEID_MIN, RANDOM_SERVICEID_MAX); + LOGI("[rm003] GenerateSeivceId randomSeed %{public}" PRId64, randomSeed); + unsigned char* dataPtr = data.get(); + *((int64_t*)dataPtr) = randomSeed; + dataPtr += sizeof(int64_t); + *((int32_t*)dataPtr) = userId; + dataPtr += sizeof(int32_t); + if (memcpy_s(dataPtr, udid.length(), udid.c_str(), udid.length()) != EOK) { + LOGI("[rm003] memcpy udid failed"); + return 0; + } + + unsigned char out[SHA256_DIGEST_LENGTH] = {0}; + SHA256_CTX ctx; + SHA256_Init(&ctx); + SHA256_Update(&ctx, data.get(), dataLength); + SHA256_Final(out, &ctx); + + int64_t serviceId = 0; + if (memcpy_s(&serviceId, sizeof(int64_t), out, sizeof(int64_t)) != EOK) { + serviceId = 0; + LOGI("[rm003] memcpy serviceId failed"); + } + serviceId = std::abs(serviceId); + LOGI("[rm003] GenerateSeivceId %{public}" PRId64, serviceId); + return serviceId; +} + void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile) { DmDeviceInfo devInfo; @@ -1458,7 +1504,6 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn profile.tokenId = IPCSkeleton::GetCallingTokenID(); profile.userId = IPCSkeleton::GetCallingUid(); - profile.serviceId = GenRandLongLong(1, 1000000); //todo serviceId logic profile.serviceType = serviceInfo.serviceType; profile.serviceName = serviceInfo.serviceName; profile.serviceDisplayName = serviceInfo.serviceDisplayName; @@ -1491,29 +1536,31 @@ void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::Servi serviceInfo.description = profile.description; serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope; } - + int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) { //todo permission verifier + if (!IsServiceInfoValid(serviceInfo)) { + LOGI("[rm003] IsServiceInfoValid failed"); + return ERR_DM_SERVICEINFO_NOTVALID; + } LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - LOGI("[rm003] udid %{public}s", profile.udid.c_str()); - LOGI("[rm003] pin %{public}s", profile.pinCode.c_str()); - + profile.serviceId = GenerateSerivceId(profile.udid, profile.userId); + if (profile.serviceId == 0) { + return ERR_DM_SERVICEINFO_GENSERVICEID_FAILED; + } int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); DistributedDeviceProfile::ServiceInfoProfile profileRet; DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); - return ret; } int32_t DeviceManagerService::UnregisterServiceInfo(DMServiceInfo &serviceInfo) { - //todo permission verifier - //todo parameter LOGI("[rm003] DeviceManagerService::UnregisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); -- Gitee From d40a6ee715ea1d36c818ced907eb002af1640f72 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 10:40:24 +0800 Subject: [PATCH 11/55] fix Change-Id: Ib5be838a27253c1a19ee4cfd51a502554aa01113 --- services/service/src/device_manager_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 3e9a00e7c..b01802172 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1464,7 +1464,6 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string udid, int32_t userId const uint32_t dataLength = sizeof(int64_t) + sizeof(int32_t) + udid.length(); std::unique_ptr data = std::make_unique(dataLength); int64_t randomSeed = GenRandLongLong(RANDOM_SERVICEID_MIN, RANDOM_SERVICEID_MAX); - LOGI("[rm003] GenerateSeivceId randomSeed %{public}" PRId64, randomSeed); unsigned char* dataPtr = data.get(); *((int64_t*)dataPtr) = randomSeed; dataPtr += sizeof(int64_t); -- Gitee From 000a7b75c5436c043c692446f1977e356f873734 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 11:47:58 +0800 Subject: [PATCH 12/55] fix Change-Id: Icd1d40b2d9f2f6a3f478eac56141b2128000921b --- .../include/deviceprofile_connector.h | 1 + .../include/device_manager_callback.h | 1 - .../authentication/auth_request_state.h | 10 +++---- .../src/authentication/auth_request_state.cpp | 30 +++++++++---------- .../src/authentication/dm_auth_manager.cpp | 1 - 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 66b628464..5ec890542 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -171,6 +171,7 @@ public: int32_t RegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); int32_t UnregisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); int32_t GetServiceInfoProfile(uint64_t tokenId, DistributedDeviceProfile::ServiceInfoProfile &profile); + private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string requestDeviceId, diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h index 8ac88c852..48f4d6209 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_callback.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_callback.h @@ -171,7 +171,6 @@ public: } virtual void OnCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode) = 0; }; - } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CALLBACK_H diff --git a/services/implementation/include/authentication/auth_request_state.h b/services/implementation/include/authentication/auth_request_state.h index 95b772d13..d567bf18c 100644 --- a/services/implementation/include/authentication/auth_request_state.h +++ b/services/implementation/include/authentication/auth_request_state.h @@ -206,11 +206,11 @@ public: int32_t Enter() override; }; -//class AuthRequestReCheckMsgDone : public AuthRequestState { -//public: -// int32_t GetStateType() override; -// int32_t Enter() override; -//}; +class AuthRequestReCheckMsgDone : public AuthRequestState { +public: + int32_t GetStateType() override; + int32_t Enter() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_AUTH_REQUEST_STATE_H diff --git a/services/implementation/src/authentication/auth_request_state.cpp b/services/implementation/src/authentication/auth_request_state.cpp index d7c2b2eac..20bd1a993 100644 --- a/services/implementation/src/authentication/auth_request_state.cpp +++ b/services/implementation/src/authentication/auth_request_state.cpp @@ -231,20 +231,20 @@ int32_t AuthRequestReCheckMsg::Enter() return DM_OK; } -//int32_t AuthRequestReCheckMsgDone::GetStateType() -//{ -// return AuthState::AUTH_REQUEST_RECHECK_MSG_DONE; -//} - -//int32_t AuthRequestReCheckMsgDone::Enter() -//{ -// std::shared_ptr stateAuthManager = authManager_.lock(); -// if (stateAuthManager == nullptr) { -// LOGE("AuthRequestState::authManager_ null"); -// return ERR_DM_FAILED; -// } -// stateAuthManager->RequestReCheckMsgDone(); -// return DM_OK; -//} +int32_t AuthRequestReCheckMsgDone::GetStateType() +{ + return AuthState::AUTH_REQUEST_RECHECK_MSG_DONE; +} + +int32_t AuthRequestReCheckMsgDone::Enter() +{ + std::shared_ptr stateAuthManager = authManager_.lock(); + if (stateAuthManager == nullptr) { + LOGE("AuthRequestState::authManager_ null"); + return ERR_DM_FAILED; + } + stateAuthManager->RequestReCheckMsgDone(); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5f07a3591..8fbb0841c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1468,7 +1468,6 @@ void DmAuthManager::AuthenticateFinish() std::lock_guard guard(savedParseFailedRecheckMsgMutex_); savedParseFailedRecheckMsg_.clear(); } - authType_ = AUTH_TYPE_UNKNOW; std::lock_guard autoLock(g_authFinishLock); if (authResponseContext_ == nullptr || authUiStateMgr_ == nullptr) { -- Gitee From ef570bcd06e106c9dc05a3ac5217a553ef5e7347 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 12:03:25 +0800 Subject: [PATCH 13/55] fix Change-Id: I14e06728ed5ece39028482ca7814d12526ee860d --- .../src/authentication/dm_auth_manager.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 8fbb0841c..389eb3e84 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -185,6 +185,23 @@ 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)) { + int32_t actionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + if (actionId == 0) { + LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0", authRequestContext_->hmlReleaseTime); + 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; @@ -199,6 +216,7 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) LOGE("not allowd device level bind bindlevel: %{public}d.", bindLevel); return ERR_DM_INPUT_PARA_INVALID; } + return DM_OK; } @@ -870,7 +888,7 @@ void DmAuthManager::HandleAuthenticateTimeout(std::string name) int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { int32_t sessionId = 0; - if (authRequestContext_->connSessionType == CONN_SESSION_TYPE_HML) { + if (IsHmlSessionType()) { LOGI("[temp003] EstablishAuthChannel, try OpenAuthSessionWithPara"); LOGI("[temp003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); LOGI("[temp003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); -- Gitee From 453ea5357d4496c9ead59c0da0d96322b0f9cb91 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 12:05:39 +0800 Subject: [PATCH 14/55] fix Change-Id: I5f1a4eed608b26ded94f5516d426dc6a43677d69 --- .../src/authentication/dm_auth_manager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 389eb3e84..eab78b297 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -193,12 +193,14 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) connSessionType = jsonObject[PARAM_KEY_CONN_SESSIONTYPE].get(); } if (connSessionType == CONN_SESSION_TYPE_HML) { - if (IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { - int32_t actionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); - if (actionId == 0) { - LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0", authRequestContext_->hmlReleaseTime); - return ERR_DM_INPUT_PARA_INVALID; - } + if (!IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { + LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is !Int32", authRequestContext_->hmlReleaseTime); + return ERR_DM_INPUT_PARA_INVALID; + } + int32_t actionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + if (actionId == 0) { + LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0", authRequestContext_->hmlReleaseTime); + return ERR_DM_INPUT_PARA_INVALID; } } -- Gitee From bcd7f7ae01f9c335a0a92becd51a920a94965a7c Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 12:07:47 +0800 Subject: [PATCH 15/55] fix Change-Id: I0254302caf02cdaa6b2a03157043f7de18e989c8 --- services/implementation/src/authentication/dm_auth_manager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index eab78b297..f0aa63f92 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -218,7 +218,6 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) LOGE("not allowd device level bind bindlevel: %{public}d.", bindLevel); return ERR_DM_INPUT_PARA_INVALID; } - return DM_OK; } -- Gitee From 7844e25fc021493a77c277e2d5d1bc14f9dee75e Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 12:10:18 +0800 Subject: [PATCH 16/55] fix Change-Id: Ica5b2a6ab5c4344cb86d2961d2b2cda6e8067d6c --- .../implementation/src/authentication/dm_auth_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index f0aa63f92..88dfde44d 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -194,12 +194,12 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) } if (connSessionType == CONN_SESSION_TYPE_HML) { if (!IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { - LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is !Int32", authRequestContext_->hmlReleaseTime); + LOGE("[rm003] 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("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0", authRequestContext_->hmlReleaseTime); + LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0"); return ERR_DM_INPUT_PARA_INVALID; } } -- Gitee From 5072b5364638158b008aa94e59444435ec7f0a5d Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 13:12:02 +0800 Subject: [PATCH 17/55] fix Change-Id: I1423c131f526d25f016d165ee72001b1b27dc317 --- .../implementation/src/authentication/dm_auth_manager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 88dfde44d..1cad185d7 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -198,8 +198,8 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra) return ERR_DM_INPUT_PARA_INVALID; } int32_t actionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); - if (actionId == 0) { - LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is 0"); + if (actionId <= 0) { + LOGE("[rm003] CONN_SESSION_TYPE_HML, input actionId is <=0"); return ERR_DM_INPUT_PARA_INVALID; } } @@ -331,6 +331,9 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } if (IsInt32(jsonObject, PARAM_KEY_HML_ACTIONID)) { authRequestContext_->hmlActionId = jsonObject[PARAM_KEY_HML_ACTIONID].get(); + if (authRequestContext_->hmlActionId <= 0) { + authRequestContext_->hmlActionId = 0; + } LOGI("[rm003-nopincode] input hmlActionId %{public}d", authRequestContext_->hmlActionId); } } -- Gitee From 95cc7935a8d4383191e503e2c2cd93bc49be9e00 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 13:57:40 +0800 Subject: [PATCH 18/55] fix Change-Id: I41355fa7eca1edc5cd18be62a6b7e3d47f21fc2e --- interfaces/kits/js4.0/src/dm_native_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index 6bfd4194f..e60d56435 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -341,10 +341,10 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b JsObjectToString(env, object, "connSessionType", connSessionType, sizeof(connSessionType)); int32_t hmlReleaseTime = 0; JsObjectToInt(env, object, "hmlReleaseTime", hmlReleaseTime); - bool hmlEnable160M = false; - JsObjectToBool(env, object, "hmlEnable160M", hmlEnable160M); int32_t hmlActionId = 0; JsObjectToInt(env, object, "hmlActionId", hmlActionId); + bool hmlEnable160M = false; + JsObjectToBool(env, object, "hmlEnable160M", hmlEnable160M); nlohmann::json jsonObj; jsonObj[AUTH_TYPE] = bindType; -- Gitee From e2d9de80ed1b85b0977eccec91044de2e817ebd6 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 14:34:46 +0800 Subject: [PATCH 19/55] fix Change-Id: I0fae3d11628ae9345d0c29c4afe5cf431438a52e --- .../implementation/src/authentication/dm_auth_manager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 1cad185d7..da73fbc9f 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -63,6 +63,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; @@ -336,6 +337,10 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } LOGI("[rm003-nopincode] input hmlActionId %{public}d", authRequestContext_->hmlActionId); } + if(IsHmlSessionType()) { + LOGI("[rm003] set closeSessionDelaySeconds = HML_SESSION_TIMEOUT"); + authRequestContext_->closeSessionDelaySeconds = HML_SESSION_TIMEOUT; + } } authRequestContext_->bundleName = GetBundleName(jsonObject); } -- Gitee From 4cb183c404817cd032f0407bb64f245418182273 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 14:52:12 +0800 Subject: [PATCH 20/55] fix Change-Id: Iadfe5226e0bd5d1904b804f9187ffebc62e6651d --- .../include/authentication/dm_auth_manager.h | 11 +++------ .../src/authentication/dm_auth_manager.cpp | 23 ++++++++----------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 21ce290a1..3976a7969 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -413,14 +413,6 @@ public: */ int32_t GeneratePincode(); - /** - * @tc.name: DmAuthManager::IsPinCodeValid - * @tc.desc: of the DeviceManager Authenticate Manager - * @tc.type: FUNC - */ - static bool IsPinCodeValid(std::string strpin); - static bool IsPinCodeValid(int32_t numpin); - /** * @tc.name: DmAuthManager::ShowConfigDialog * @tc.desc: Show Config Dialog of the DeviceManager Authenticate Manager @@ -502,9 +494,12 @@ public: void HandleSessionHeartbeat(std::string name); int32_t RegisterAuthenticationType(int32_t authenticationType); + static bool IsPinCodeValid(std::string strpin); + static bool IsPinCodeValid(int32_t numpin); private: bool IsHmlSessionType(); + bool IsUsePinFromDp(); 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); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index da73fbc9f..34f7a8d49 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -409,7 +409,6 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au LOGE("CheckAuthParamVaildExtra failed, param is invaild."); return ret; } - isAuthenticateDevice_ = true; if (authType == AUTH_TYPE_CRE) { LOGI("DmAuthManager::AuthenticateDevice for credential type, joinLNN directly."); @@ -1249,9 +1248,7 @@ 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 (serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode) && - authResponseContext_->isPincodeSetted) { + if (IsUsePinFromDp() && authResponseContext_->isPincodeSetted) { authResponseContext_->code = std::stoi(serviceInfoProfile_.pinCode); LOGI("[rm003-nopincode] import from dp, pin %{public}d", authResponseContext_->code); } else if (!authResponseContext_->isShowDialog) { @@ -1565,10 +1562,7 @@ bool DmAuthManager::IsPinCodeValid(std::string strpin) return false; } int pinnum = std::stoi(strpin); - if (pinnum < MIN_PIN_CODE || pinnum > MAX_PIN_CODE) { - return false; - } - return true; + return IsPinCodeValid(pinnum); } bool DmAuthManager::IsPinCodeValid(int32_t numpin) @@ -1579,6 +1573,12 @@ bool DmAuthManager::IsPinCodeValid(int32_t numpin) return true; } +bool DmAuthManager::IsUsePinFromDp() +{ + return (serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode)); +} + std::string DmAuthManager::GenerateGroupName() { if (authResponseContext_ == nullptr) { @@ -1704,8 +1704,7 @@ void DmAuthManager::ShowAuthInfoDialog(bool authDeviceError) return; } LOGI("DmAuthManager::ShowAuthInfoDialog start"); - if (!authDeviceError && serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode) && authResponseContext_->isPincodeSetted) { + if (!authDeviceError && IsUsePinFromDp() && authResponseContext_->isPincodeSetted) { LOGI("[rm003-nopincode] pin import from dp, not show dialog"); return; } @@ -2435,9 +2434,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) isAuthDevice_ = false; if (authRequestState_ == nullptr || authResponseState_ != nullptr) { LOGI("AuthDeviceError sink authTimes %{public}d.", authTimes_); - if (errorCode == ERR_DM_HICHAIN_PROOFMISMATCH && !pincodeDialogEverShown_ && - serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode)) { + if (errorCode == ERR_DM_HICHAIN_PROOFMISMATCH && !pincodeDialogEverShown_ && IsUsePinFromDp()) { LOGI("[rm003-nopincode] AuthDeviceError, ShowAuthInfoDialog"); ShowAuthInfoDialog(true); return; -- Gitee From 20f2a358cf451d41c07c6695971929173bf65258 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 14:53:36 +0800 Subject: [PATCH 21/55] fix Change-Id: If0b944306e8aea24b72b61eb4d6415de20e53f9d --- .../implementation/src/dependency/softbus/softbus_session.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 1e953f9c5..fcb81abf1 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -26,6 +26,7 @@ #ifdef SOFTBUS_ENHANCE_FLAG #include "trans_auth_lane_pending_ctl.h" #endif + namespace OHOS { namespace DistributedHardware { std::shared_ptr SoftbusSession::sessionCallback_ = nullptr; -- Gitee From 17e3ef711675dc722ef0f2735cb121290193338c Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 14:58:15 +0800 Subject: [PATCH 22/55] fix Change-Id: I7abae3860f3a3f73c55c00ce7b756b771c6ee5ba --- .../include/authentication/dm_auth_manager.h | 2 +- .../src/authentication/dm_auth_manager.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 3976a7969..b679066f9 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -633,7 +633,7 @@ private: std::string srcReqMsg_ = ""; int32_t authenticationType_ = USER_OPERATION_TYPE_ALLOW_AUTH; - std::mutex recheckMutex_; + std::mutex recheckPublicKeyProcessMutex_; std::string savedParseFailedRecheckMsg_; std::mutex savedParseFailedRecheckMsgMutex_; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 34f7a8d49..5a6491fb5 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -633,7 +633,7 @@ void DmAuthManager::ProcessSourceMsg() break; case MSG_TYPE_RESP_PUBLICKEY: { - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); if (RemoteSupportRecheck()) { if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { authRequestState_->TransitionTo(std::make_shared()); @@ -651,7 +651,7 @@ void DmAuthManager::ProcessSourceMsg() } case MSG_TYPE_RESP_RECHECK_MSG: { - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_AUTH_FINISH || authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { RequestReCheckMsgDone(); @@ -699,7 +699,7 @@ void DmAuthManager::ProcessSinkMsg() break; case MSG_TYPE_REQ_RECHECK_MSG: { - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { ResponseReCheckMsgDone(); @@ -2291,7 +2291,7 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { LOGI("[temp003] SrcAuthDeviceFinish"); - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); if (authResponseContext_->confirmOperation != USER_OPERATION_TYPE_ALLOW_AUTH && @@ -2359,7 +2359,7 @@ void DmAuthManager::SinkAuthDeviceFinish() { LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); LOGI("[temp003] SinkAuthDeviceFinish"); - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); if (!authResponseContext_->haveCredential) { @@ -3243,7 +3243,7 @@ int32_t DmAuthManager::RegisterAuthenticationType(int32_t authenticationType) void DmAuthManager::ProcessReqPublicKey() { - std::lock_guard guard(recheckMutex_); + std::lock_guard guard(recheckPublicKeyProcessMutex_); if (RemoteSupportRecheck()) { if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { ResponseNewProcessCredential(); -- Gitee From d67319d4814bbebd0281b55df9066693cbc9d341 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 17:07:55 +0800 Subject: [PATCH 23/55] add gen id Change-Id: Id58cfdc8c3d59a458565c4369a71e6fe8652e1f7 --- .../device_manager_ipc_interface_code.h | 4 ++ .../include/ipc/model/ipc_gen_serviceid_rsp.h | 43 +++++++++++++++++++ .../include/deviceprofile_connector.h | 2 +- .../src/deviceprofile_connector.cpp | 4 +- .../native_cpp/include/device_manager.h | 6 ++- .../native_cpp/include/device_manager_impl.h | 7 ++- .../native_cpp/src/device_manager_impl.cpp | 41 +++++++++++++++++- .../src/ipc/standard/ipc_cmd_parser.cpp | 25 ++++++----- .../service/include/device_manager_service.h | 6 +-- .../service/src/device_manager_service.cpp | 26 +++++++---- .../src/ipc/standard/ipc_cmd_parser.cpp | 21 ++++++++- 11 files changed, 155 insertions(+), 30 deletions(-) create mode 100644 common/include/ipc/model/ipc_gen_serviceid_rsp.h diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 619c25956..085cf4932 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -102,8 +102,12 @@ enum DMIpcCmdInterfaceCode { GET_DEVICE_PROFILE_INFO_LIST_RESULT, GET_DEVICE_ICON_INFO, GET_DEVICE_ICON_INFO_RESULT, + GEN_SERVICEID, REG_SERVICE_INFO, UNREG_SERVICE_INFO, + UPDATE_SERVICE_INFO, + GET_SERVICEINFO_BYID, + GET_SERVICEINFO_CALLER, // Add ipc msg here IPC_MSG_BUTT }; 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/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 5ec890542..d496d4303 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -169,7 +169,7 @@ public: int32_t UnSubscribeDeviceProfileInited(); int32_t PutAllTrustedDevices(const std::vector &deviceInfos); int32_t RegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); - int32_t UnregisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); + int32_t UnRegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); int32_t GetServiceInfoProfile(uint64_t tokenId, DistributedDeviceProfile::ServiceInfoProfile &profile); private: diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 17e71931f..348a40431 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1643,11 +1643,11 @@ int32_t DeviceProfileConnector::RegisterServiceInfoProfile( return DM_OK; } -int32_t DeviceProfileConnector::UnregisterServiceInfoProfile( +int32_t DeviceProfileConnector::UnRegisterServiceInfoProfile( const DistributedDeviceProfile::ServiceInfoProfile& profile) { LOGI("[rm003] DeviceProfileConnector::RegisterServiceInfoProfile"); - int32_t ret = DistributedDeviceProfileClient::GetInstance().UnregisterServiceInfoProfile(profile); + int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterServiceInfoProfile(profile); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index bceef544c..4aa89d353 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -649,8 +649,12 @@ public: virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &filterOptions, std::shared_ptr callback) = 0; + virtual int32_t GenerateServiceId(int64_t &serviceId) = 0; virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) = 0; - virtual int32_t UnregisterServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t UnRegisterServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) = 0; + virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) = 0; + virtual int32_t GetCallerServiceId(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 5074ca7d2..c1d67ab16 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -416,9 +416,12 @@ public: virtual int32_t GetDeviceIconInfo(const std::string &pkgName, const DmDeviceIconInfoFilterOptions &filterOptions, std::shared_ptr callback) override; - + virtual int32_t GenerateServiceId(int64_t &serviceId) override; virtual int32_t RegisterServiceInfo(const DMServiceInfo &info) override; - virtual int32_t UnregisterServiceInfo(const DMServiceInfo &info) override; + virtual int32_t UnRegisterServiceInfo(const DMServiceInfo &info) override; + virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) override; + virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) override; + virtual int32_t GetCallerServiceId(std::vector &serviceInfos) override; private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; 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 aeac2facd..ad77be421 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" @@ -2649,6 +2650,26 @@ int32_t DeviceManagerImpl::GetDeviceIconInfo(const std::string &pkgName, return DM_OK; } +int32_t DeviceManagerImpl::GenerateServiceId(int64_t &serviceId) +{ + LOGI("Start"); + LOGI("[rm003] GenerateServiceId"); + 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; + } + LOGI("Completed"); + return DM_OK; +} + int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) { LOGI("Start"); @@ -2670,10 +2691,10 @@ int32_t DeviceManagerImpl::RegisterServiceInfo(const DMServiceInfo &info) return DM_OK; } -int32_t DeviceManagerImpl::UnregisterServiceInfo(const DMServiceInfo &info) +int32_t DeviceManagerImpl::UnRegisterServiceInfo(const DMServiceInfo &info) { LOGI("Start"); - LOGI("[rm003] UnregisterServiceInfo"); + LOGI("[rm003] UnRegisterServiceInfo"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetServiceInfo(info); @@ -2691,5 +2712,21 @@ int32_t DeviceManagerImpl::UnregisterServiceInfo(const DMServiceInfo &info) return DM_OK; } +int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) +{ + return DM_OK; +} + +int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) +{ + return DM_OK; +} + +int32_t DeviceManagerImpl::GetCallerServiceId(std::vector &serviceInfos) +{ + 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 07077885c..34589aff9 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" @@ -2204,6 +2205,19 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &repl return DM_OK; } +ON_IPC_READ_RESPONSE(GEN_SERVICEID, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(GEN_SERVICEID"); + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + if (pRsp == nullptr) { + LOGE("pRsp is null"); + return ERR_DM_FAILED; + } + pRsp->SetErrCode(reply.ReadInt32()); + pRsp->SetServiceId(reply.ReadInt64()); + return DM_OK; +} + ON_IPC_SET_REQUEST(REG_SERVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { @@ -2247,16 +2261,7 @@ ON_IPC_SET_REQUEST(UNREG_SERVICE_INFO, std::shared_ptr pBaseReq, Message return DM_OK; } -ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) -{ - LOGI("[rm003] ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO"); - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } - pBaseRsp->SetErrCode(reply.ReadInt32()); - return DM_OK; -} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 249147d62..a9b3600e7 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -185,11 +185,11 @@ public: const std::map &unbindParam); bool IsServiceInfoValid(const DMServiceInfo &serviceInfo); - int64_t GenerateSerivceId(std::string udid, int32_t userId); + int64_t GenerateSerivceId(); void InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); - int32_t UnregisterServiceInfo(DMServiceInfo &serviceInfo); + int32_t UnRegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t DpAclAdd(const std::string &udid); @@ -300,7 +300,7 @@ private: void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI #endif - + int64_t GenerateSerivceId(std::string &udid, int32_t userId); private: bool isImplsoLoaded_ = false; bool isAdapterResidentSoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b01802172..7201a6b2f 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1455,7 +1455,21 @@ bool DeviceManagerService::IsServiceInfoValid(const DMServiceInfo &serviceInfo) return true; } -int64_t DeviceManagerService::GenerateSerivceId(std::string udid, int32_t userId) +int64_t DeviceManagerService::GenerateSerivceId() +{ + DmDeviceInfo devInfo; + int32_t ret = GetLocalDeviceInfo(devInfo); + if (ret != DM_OK) { + LOGE("[rm003] GetLocalDeviceInfo failed"); + return 0; + } + std::string udid = devInfo.deviceId; + int32_t userId = IPCSkeleton::GetCallingUid(); + int64_t serviceId = GenerateSerivceId(udid, userId); + return serviceId; +} + +int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userId) { if (udid.empty()) { LOGI("[rm003] GenerateSeivceId udid empty"); @@ -1546,10 +1560,6 @@ int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - profile.serviceId = GenerateSerivceId(profile.udid, profile.userId); - if (profile.serviceId == 0) { - return ERR_DM_SERVICEINFO_GENSERVICEID_FAILED; - } int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); DistributedDeviceProfile::ServiceInfoProfile profileRet; @@ -1558,12 +1568,12 @@ int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) return ret; } -int32_t DeviceManagerService::UnregisterServiceInfo(DMServiceInfo &serviceInfo) +int32_t DeviceManagerService::UnRegisterServiceInfo(DMServiceInfo &serviceInfo) { - LOGI("[rm003] DeviceManagerService::UnregisterServiceInfo"); + LOGI("[rm003] DeviceManagerService::UnRegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - return DeviceProfileConnector::GetInstance().UnregisterServiceInfoProfile(profile); + return DeviceProfileConnector::GetInstance().UnRegisterServiceInfoProfile(profile); } int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index c68628054..cf911e114 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1814,6 +1814,25 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::sha return DM_OK; } +ON_IPC_CMD(GEN_SERVICEID, MessageParcel &data, MessageParcel &reply) +{ + LOGI("[rm003] ON_IPC_CMD(GEN_SERVICEID"); + 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) { LOGI("[rm003] ON_IPC_CMD(REG_SERVICE_INFO"); @@ -1832,7 +1851,7 @@ ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) LOGI("[rm003] ON_IPC_CMD(UNREG_SERVICE_INFO"); DMServiceInfo serviceInfo; DecodeServiceInfo(data, serviceInfo); - int32_t result = DeviceManagerService::GetInstance().UnregisterServiceInfo(serviceInfo); + int32_t result = DeviceManagerService::GetInstance().UnRegisterServiceInfo(serviceInfo); if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; -- Gitee From 30df8340ab94de37e3490bbc9259930c65f26d25 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 18:10:09 +0800 Subject: [PATCH 24/55] fix Change-Id: I33cebb6a818fe436da20c624a9c5debd768fe1d8 --- .../model/ipc_get_serviceinfo_bycaller_rsp.h | 53 +++++++ .../ipc/model/ipc_get_serviceinfo_byid_req.h | 43 ++++++ .../ipc/model/ipc_get_serviceinfo_byid_rsp.h | 42 ++++++ .../native_cpp/src/device_manager_impl.cpp | 34 +++++ .../src/ipc/standard/ipc_cmd_parser.cpp | 142 ++++++++++++++++-- .../service/include/device_manager_service.h | 3 + .../service/src/device_manager_service.cpp | 18 +++ .../src/ipc/standard/ipc_cmd_parser.cpp | 26 ++++ 8 files changed, 347 insertions(+), 14 deletions(-) create mode 100644 common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h create mode 100644 common/include/ipc/model/ipc_get_serviceinfo_byid_req.h create mode 100644 common/include/ipc/model/ipc_get_serviceinfo_byid_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..9f8d46837 --- /dev/null +++ b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 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_LOCAL_DEVICE_INFO_RSP_H +#define OHOS_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H + +#include "dm_device_info.h" +#include "ipc_req.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetLocalDeviceInfoRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetLocalDeviceInfoRsp); + +public: + /** + * @tc.name: IpcGetLocalDeviceInfoRsp::GetLocalDeviceInfo + * @tc.desc: Ipc get local device information reply Get Local DeviceInfo + * @tc.type: FUNC + */ + const DmDeviceInfo &GetLocalDeviceInfo() const + { + return localDeviceInfo_; + } + + /** + * @tc.name: IpcGetLocalDeviceInfoRsp::SetLocalDeviceInfo + * @tc.desc: Ipc get local device information reply Set Local DeviceInfo + * @tc.type: FUNC + */ + void SetLocalDeviceInfo(const DmDeviceInfo &localDeviceInfo) + { + localDeviceInfo_ = localDeviceInfo; + } + +private: + DmDeviceInfo localDeviceInfo_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H diff --git a/common/include/ipc/model/ipc_get_serviceinfo_byid_req.h b/common/include/ipc/model/ipc_get_serviceinfo_byid_req.h new file mode 100644 index 000000000..a99e2490c --- /dev/null +++ b/common/include/ipc/model/ipc_get_serviceinfo_byid_req.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_GET_SERVICE_INFO_BYID_REQ_H +#define OHOS_DM_IPC_GET_SERVICE_INFO_BYID_REQ_H + +#include "ipc_req.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class IpcGetServiceInfoByIdReq : public IpcReq { + DECLARE_IPC_MODEL(IpcGetServiceInfoByIdReq); + +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_GET_SERVICE_INFO_BYID_REQ_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..c7d394353 --- /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 localDeviceInfo_; + } + + 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/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index ad77be421..ece9f7094 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_get_serviceinfo_byid_req.h" #include "ipc_gen_serviceid_rsp.h" #include "ipc_get_anony_local_udid_rsp.h" #include "ipc_get_device_icon_info_req.h" @@ -2714,11 +2715,44 @@ int32_t DeviceManagerImpl::UnRegisterServiceInfo(const DMServiceInfo &info) int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) { + LOGI("Start"); + LOGI("[rm003] UpdateServiceInfo"); + 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"); + LOGI("[rm003] GetServiceInfoByServiceId, %{public}" PRId64); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetServiceId(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; + } + LOGI("Completed"); + return DM_OK; return DM_OK; } 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 34589aff9..4496e9dfb 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 @@ -43,6 +43,8 @@ #include "ipc_get_info_by_network_rsp.h" #include "ipc_get_info_by_network_req.h" #include "ipc_get_local_device_info_rsp.h" +#include "ipc_get_serviceinfo_byid_req.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" @@ -70,6 +72,15 @@ namespace { const int32_t DM_MAX_TRUST_DEVICE_NUM = 200; } +#define READ_HELPER_RET(parcel, type, out, failRet) \ + do { \ + bool ret = (parcel).Read##type((out)); \ + if (!ret) { \ + HILOGE("read value failed!"); \ + return failRet; \ + } \ + } while (0) + void DecodeDmDeviceBasicInfo(MessageParcel &parcel, DmDeviceBasicInfo &devInfo) { std::string deviceIdStr = parcel.ReadString(); @@ -155,20 +166,51 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { - serviceInfo.serviceId = parcel.ReadUint64(); - serviceInfo.serviceType = parcel.ReadString(); - serviceInfo.serviceName = parcel.ReadString(); - serviceInfo.serviceDisplayName = parcel.ReadString(); - serviceInfo.customData = parcel.ReadString(); - serviceInfo.bundleName = parcel.ReadString(); - serviceInfo.moduleName = parcel.ReadString(); - serviceInfo.abilityName = parcel.ReadString(); - serviceInfo.authBoxType = parcel.ReadString(); - serviceInfo.authType = parcel.ReadInt32(); - serviceInfo.pinExchangeType = parcel.ReadString(); - serviceInfo.pinCode = parcel.ReadString(); - serviceInfo.description = parcel.ReadString(); - serviceInfo.serviceDiscoveryScope = parcel.ReadString(); + READ_HELPER_RET(parcel, Uint64, 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, String, serviceInfo.authBoxType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); + READ_HELPER_RET(parcel, String, 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 DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) +{ + const int32_t maxNum = 100; + uint32_t num = 0; + READ_HELPER_RET(parcel, Uint32, num, false); + if (num > maxNum) { + LOGE("[rm003] num %{public}d > maxNum", num); + return false; + } + for (int k = 0; k < num; k++) { + DMServiceInfo serviceInfo; + READ_HELPER_RET(parcel, Uint64, 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, String, serviceInfo.authBoxType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); + READ_HELPER_RET(parcel, String, 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); + serviceInfos.emplace(serviceInfo); + } + return true; } ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) @@ -2261,7 +2303,79 @@ ON_IPC_SET_REQUEST(UNREG_SERVICE_INFO, std::shared_ptr pBaseReq, Message return DM_OK; } +ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(UNREG_SERVICE_INFO"); + 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) +{ + LOGI("[rm003] ON_IPC_SET_REQUEST(UPDATE_SERVICE_INFO"); + 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 (!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) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(UPDATE_SERVICE_INFO"); + 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) +{ + LOGI("[rm003] ON_IPC_SET_REQUEST(GET_SERVICEINFO_BYID"); + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + int64_t serviceId = pReq->GetServiceId(); + 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) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID"); + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + if (pRsp->GetErrCode() == DM_OK) { + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + DMServiceInfo info; + bool ret = DecodeServiceInfo(reply, info); + if (!ret) { + LOGE("[rm003] DecodeServiceInfo failed"); + pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); + } + pRsp->SetServiceInfo(info); + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index a9b3600e7..3a97dd0be 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -190,6 +190,9 @@ public: void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t UnRegisterServiceInfo(DMServiceInfo &serviceInfo); + int32_t UpdateServiceInfo(DMServiceInfo &serviceInfo); + int32_t GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo); + int32_t GetCallerServiceInfos(std::vector &serviceInfos); int32_t DpAclAdd(const std::string &udid); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7201a6b2f..888a0d4ed 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1576,6 +1576,24 @@ int32_t DeviceManagerService::UnRegisterServiceInfo(DMServiceInfo &serviceInfo) return DeviceProfileConnector::GetInstance().UnRegisterServiceInfoProfile(profile); } +int32_t DeviceManagerService::UpdateServiceInfo(DMServiceInfo &serviceInfo) +{ + LOGI("[rm003] DeviceManagerService::UpdateServiceInfo"); + return DM_OK; +} + +int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) +{ + LOGI("[rm003] DeviceManagerService::GetServiceInfoById, %{public}" PRId64, serviceId); + return DM_OK; +} + +int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) +{ + LOGI("[rm003] DeviceManagerService::GetCallerServiceInfos"); + return DM_OK; +} + 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 cf911e114..2fd4ef7b5 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1859,5 +1859,31 @@ ON_IPC_CMD(UNREG_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) return DM_OK; } +ON_IPC_CMD(UPDATE_SERVICE_INFO, MessageParcel &data, MessageParcel &reply) +{ + LOGI("[rm003] ON_IPC_CMD(UPDATE_SERVICE_INFO"); + DMServiceInfo serviceInfo; + 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) +{ + LOGI("[rm003] ON_IPC_CMD(GET_SERVICEINFO_BYID"); + int64_t serviceId = data.ReadInt64(); + DMServiceInfo 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; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From e60a485e086dacd008430f73a16775320336ba91 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 18:35:39 +0800 Subject: [PATCH 25/55] fix Change-Id: I138d2a7c14f2b5e5f386583fcd368b1a714a095e --- .../model/ipc_get_serviceinfo_bycaller_rsp.h | 34 +++++------ .../native_cpp/src/device_manager_impl.cpp | 25 +++++++- .../service/src/device_manager_service.cpp | 4 ++ .../src/ipc/standard/ipc_cmd_parser.cpp | 57 ++++++++++++++++++- 4 files changed, 95 insertions(+), 25 deletions(-) diff --git a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h index 9f8d46837..b7b738a06 100644 --- a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h +++ b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,41 +13,33 @@ * limitations under the License. */ -#ifndef OHOS_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H -#define OHOS_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H +#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 IpcGetLocalDeviceInfoRsp : public IpcRsp { - DECLARE_IPC_MODEL(IpcGetLocalDeviceInfoRsp); +class IpcGetServiceInfoByCallerRsp : public IpcRsp { + DECLARE_IPC_MODEL(IpcGetServiceInfoByCallerRsp); public: - /** - * @tc.name: IpcGetLocalDeviceInfoRsp::GetLocalDeviceInfo - * @tc.desc: Ipc get local device information reply Get Local DeviceInfo - * @tc.type: FUNC - */ - const DmDeviceInfo &GetLocalDeviceInfo() const + std::vector& GetServiceInfos() const { - return localDeviceInfo_; + return serviceInfos; } - /** - * @tc.name: IpcGetLocalDeviceInfoRsp::SetLocalDeviceInfo - * @tc.desc: Ipc get local device information reply Set Local DeviceInfo - * @tc.type: FUNC - */ - void SetLocalDeviceInfo(const DmDeviceInfo &localDeviceInfo) + void SetServiceInfos(const std::vector &infos) { - localDeviceInfo_ = localDeviceInfo; + serviceInfos_ = infos; } private: - DmDeviceInfo localDeviceInfo_; + std::vector serviceInfos_; }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_IPC_GET_LOCAL_DEVICE_INFO_RSP_H +#endif // OHOS_DM_IPC_GET_SERVICEINFO_BYCALLER_RSP_H 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 ece9f7094..31ef4fa06 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -50,6 +50,8 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_trustdevice_req.h" #include "ipc_get_trustdevice_rsp.h" +#include "ipc_get_serviceinfo_bycaller_rsp.h" +#include "ipc_get_serviceinfo_byid_rsp.h" #include "ipc_import_auth_code_req.h" #include "ipc_notify_event_req.h" #include "ipc_permission_req.h" @@ -2667,7 +2669,8 @@ int32_t DeviceManagerImpl::GenerateServiceId(int64_t &serviceId) LOGE("Failed with ret %{public}d", ret); return ret; } - LOGI("Completed"); + serviceId = rsp->GetServiceId(); + LOGI("Completed, serviceId %{public}" PRId64); return DM_OK; } @@ -2739,7 +2742,7 @@ int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServic LOGI("Start"); LOGI("[rm003] GetServiceInfoByServiceId, %{public}" PRId64); std::shared_ptr req = std::make_shared(); - std::shared_ptr rsp = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); req->SetServiceId(serviceId); int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_BYID, req, rsp); if (ret != DM_OK) { @@ -2751,13 +2754,29 @@ int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServic LOGE("Failed with ret %{public}d", ret); return ret; } + info = rsp->GetServiceInfo(); LOGI("Completed"); return DM_OK; - return DM_OK; } int32_t DeviceManagerImpl::GetCallerServiceId(std::vector &serviceInfos) { + LOGI("Start"); + LOGI("[rm003] GenerateServiceId"); + 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; + } + serviceInfos = rsp->GetServiceInfos(); + LOGI("Completed"); return DM_OK; } diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 888a0d4ed..c268d4ae7 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1585,12 +1585,16 @@ int32_t DeviceManagerService::UpdateServiceInfo(DMServiceInfo &serviceInfo) int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) { LOGI("[rm003] DeviceManagerService::GetServiceInfoById, %{public}" PRId64, serviceId); + serviceInfo.abilityName = "kkkability"; return DM_OK; } int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) { LOGI("[rm003] DeviceManagerService::GetCallerServiceInfos"); + DMServiceInfo serviceInfo; + serviceInfo.abilityName = "kkkjjjjability"; + serviceInfos.emplace(serviceInfo); return DM_OK; } diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 2fd4ef7b5..035ec5bdc 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -126,6 +126,54 @@ void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee) callee.extra = parcel.ReadString(); } +bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) +{ + bool bRet = true; + bRet = (bRet && parcel.WriteUint64(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.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + bRet = (bRet && parcel.WriteString(serviceInfo.description)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + return bRet; +} + +bool EncodeServiceInfos(const std::vector& serviceInfos, MessageParcel &parcel) +{ + int32_t num = serviceInfos.size(); + if (!parcel.WriteInt32(num)){ + LOGE("[rm003] WriteInt32 num failed"); + return false; + } + for (int k = 0; k < num; k++) { + DMServiceInfo& serviceInfo = serviceInfos[k]; + bool bRet = true; + bRet = (bRet && parcel.WriteUint64(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.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); + bRet = (bRet && parcel.WriteString(serviceInfo.description)); + bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + } + return bRet; +} + void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { serviceInfo.serviceId = parcel.ReadUint64(); @@ -1877,11 +1925,18 @@ ON_IPC_CMD(GET_SERVICEINFO_BYID, MessageParcel &data, MessageParcel &reply) LOGI("[rm003] ON_IPC_CMD(GET_SERVICEINFO_BYID"); int64_t serviceId = data.ReadInt64(); DMServiceInfo serviceInfo; - int32_t result = DeviceManagerService::GetInstance().UpdateServiceInfo(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) { + return DM_OK; + } + if (!EncodeServiceInfo(serviceInfo, reply)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } return DM_OK; } -- Gitee From 74913c869858594a67af39edc657a404733154e0 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 18:40:39 +0800 Subject: [PATCH 26/55] fix Change-Id: I297ec23f312d8939cdf89d9bf7d63a951a327988 --- .../src/ipc/standard/ipc_cmd_parser.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 4496e9dfb..93fe9396e 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 @@ -45,6 +45,7 @@ #include "ipc_get_local_device_info_rsp.h" #include "ipc_get_serviceinfo_byid_req.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" @@ -2377,5 +2378,26 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID, MessageParcel &reply, std::shared_ptr return DM_OK; } +ON_IPC_READ_RESPONSE(GET_SERVICEINFO_CALLER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + LOGI("[rm003] ON_IPC_READ_RESPONSE(GET_SERVICEINFO_CALLER"); + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + if (pRsp->GetErrCode() == DM_OK) { + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + std::vector infos; + bool ret = DecodeServiceInfos(reply, infos); + if (!ret) { + LOGE("[rm003] DecodeServiceInfo failed"); + pBaseRsp->SetErrCode(ERR_DM_IPC_READ_FAILED); + } + pRsp->SetServiceInfos(infos); + } + return DM_OK; +} + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From afd0592a07af4b8dc6738bcf6c698525ab161ea7 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 18:53:27 +0800 Subject: [PATCH 27/55] fix Change-Id: Iaa549a44b544b897e376c294dd5360d542e322d4 --- .../ipc/model/ipc_get_serviceinfo_bycaller_rsp.h | 4 ++-- .../include/ipc/model/ipc_get_serviceinfo_byid_rsp.h | 2 +- .../native_cpp/src/device_manager_impl.cpp | 2 +- .../native_cpp/src/ipc/standard/ipc_cmd_parser.cpp | 12 ++++++------ services/service/src/device_manager_service.cpp | 2 +- services/service/src/ipc/standard/ipc_cmd_parser.cpp | 8 ++++++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h index b7b738a06..c0090a8a1 100644 --- a/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h +++ b/common/include/ipc/model/ipc_get_serviceinfo_bycaller_rsp.h @@ -27,9 +27,9 @@ class IpcGetServiceInfoByCallerRsp : public IpcRsp { DECLARE_IPC_MODEL(IpcGetServiceInfoByCallerRsp); public: - std::vector& GetServiceInfos() const + const std::vector& GetServiceInfos() const { - return serviceInfos; + return serviceInfos_; } void SetServiceInfos(const std::vector &infos) diff --git a/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h b/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h index c7d394353..cd3cd1396 100644 --- a/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h +++ b/common/include/ipc/model/ipc_get_serviceinfo_byid_rsp.h @@ -27,7 +27,7 @@ class IpcGetServiceInfoByIdRsp : public IpcRsp { public: const DMServiceInfo &GetServiceInfo() const { - return localDeviceInfo_; + return serviceInfo_; } void SetServiceInfo(const DMServiceInfo &info) 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 31ef4fa06..9075b46c4 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2670,7 +2670,7 @@ int32_t DeviceManagerImpl::GenerateServiceId(int64_t &serviceId) return ret; } serviceId = rsp->GetServiceId(); - LOGI("Completed, serviceId %{public}" PRId64); + LOGI("Completed, serviceId %{public}" PRId64, serviceId); return DM_OK; } 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 93fe9396e..c97bad301 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 @@ -77,7 +77,7 @@ const int32_t DM_MAX_TRUST_DEVICE_NUM = 200; do { \ bool ret = (parcel).Read##type((out)); \ if (!ret) { \ - HILOGE("read value failed!"); \ + LOGE("read value failed!"); \ return failRet; \ } \ } while (0) @@ -165,7 +165,7 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) return bRet; } -void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) +bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { READ_HELPER_RET(parcel, Uint64, serviceInfo.serviceId, false); READ_HELPER_RET(parcel, String, serviceInfo.serviceType, false); @@ -193,7 +193,7 @@ bool DecodeServiceInfos(MessageParcel &parcel, std::vector &servi LOGE("[rm003] num %{public}d > maxNum", num); return false; } - for (int k = 0; k < num; k++) { + for (uint32_t k = 0; k < num; k++) { DMServiceInfo serviceInfo; READ_HELPER_RET(parcel, Uint64, serviceInfo.serviceId, false); READ_HELPER_RET(parcel, String, serviceInfo.serviceType, false); @@ -209,7 +209,7 @@ bool DecodeServiceInfos(MessageParcel &parcel, std::vector &servi READ_HELPER_RET(parcel, String, serviceInfo.pinCode, false); READ_HELPER_RET(parcel, String, serviceInfo.description, false); READ_HELPER_RET(parcel, String, serviceInfo.serviceDiscoveryScope, false); - serviceInfos.emplace(serviceInfo); + serviceInfos.emplace_back(serviceInfo); } return true; } @@ -2365,7 +2365,7 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID, MessageParcel &reply, std::shared_ptr return ERR_DM_FAILED; } pBaseRsp->SetErrCode(reply.ReadInt32()); - if (pRsp->GetErrCode() == DM_OK) { + if (pBaseRsp->GetErrCode() == DM_OK) { std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DMServiceInfo info; bool ret = DecodeServiceInfo(reply, info); @@ -2386,7 +2386,7 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_CALLER, MessageParcel &reply, std::shared_p return ERR_DM_FAILED; } pBaseRsp->SetErrCode(reply.ReadInt32()); - if (pRsp->GetErrCode() == DM_OK) { + if (pBaseRsp->GetErrCode() == DM_OK) { std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); std::vector infos; bool ret = DecodeServiceInfos(reply, infos); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index c268d4ae7..55e1a143b 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1594,7 +1594,7 @@ int32_t DeviceManagerService::GetCallerServiceInfos(std::vector & LOGI("[rm003] DeviceManagerService::GetCallerServiceInfos"); DMServiceInfo serviceInfo; serviceInfo.abilityName = "kkkjjjjability"; - serviceInfos.emplace(serviceInfo); + serviceInfos.emplace_back(serviceInfo); return DM_OK; } diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 035ec5bdc..862fc45a0 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -153,8 +153,8 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP LOGE("[rm003] WriteInt32 num failed"); return false; } - for (int k = 0; k < num; k++) { - DMServiceInfo& serviceInfo = serviceInfos[k]; + for (uint32_t k = 0; k < num; k++) { + const DMServiceInfo& serviceInfo = serviceInfos[k]; bool bRet = true; bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); @@ -170,6 +170,10 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); bRet = (bRet && parcel.WriteString(serviceInfo.description)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); + if (!bRet) { + LOGE("[rm003] encode serviceinfo failed"); + break; + } } return bRet; } -- Gitee From 7890b8b0b50d0cd5049305835b8216dc6be0eb90 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 18:57:17 +0800 Subject: [PATCH 28/55] fix Change-Id: I097ebcc6f750ecab710b471cb8af14621482957c --- interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp | 2 +- interfaces/kits/js4.0/src/native_devicemanager_js.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 9075b46c4..21221b958 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2740,7 +2740,7 @@ int32_t DeviceManagerImpl::UpdateServiceInfo(const DMServiceInfo &info) int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) { LOGI("Start"); - LOGI("[rm003] GetServiceInfoByServiceId, %{public}" PRId64); + LOGI("[rm003] GetServiceInfoByServiceId, %{public}" PRId64, serviceId); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetServiceId(serviceId); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 7643d6a55..b39b97019 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1691,7 +1691,7 @@ bool xProcessRegisterServiceInfo(std::string bindParam) serviceInfo.pinCode = pincode; serviceInfo.description = "profile.description"; serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; - + serviceInfo.serviceId = DeviceManager::GetInstance().GenerateServiceId(); DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); LOGI("[temp003] DeviceManager::GetInstance().RegisterServiceInfo complete"); return true; -- Gitee From 1fd1e804933a9b27ab58dc288127546f2aebb4e3 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 19:03:12 +0800 Subject: [PATCH 29/55] fix Change-Id: If29e2b1712af554a4144a7780494190eb587f086 --- interfaces/inner_kits/native_cpp/include/dm_device_info.h | 2 +- .../native_cpp/src/ipc/standard/ipc_cmd_parser.cpp | 6 +++--- interfaces/kits/js4.0/src/native_devicemanager_js.cpp | 8 ++++++-- services/service/src/ipc/standard/ipc_cmd_parser.cpp | 6 +++--- 4 files changed, 13 insertions(+), 9 deletions(-) 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 d1e8eb371..e50d16efb 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -428,7 +428,7 @@ const std::string DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM = "2"; const std::string DM_SERVICEINFO_AUTHBOX_TYPE_2IN1 = "3"; typedef struct DMServiceInfo { - uint64_t serviceId = 0; + int64_t serviceId = 0; std::string serviceType; std::string serviceName; std::string serviceDisplayName; 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 c97bad301..fea2aebee 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 @@ -148,7 +148,7 @@ bool EncodeDmAccessCallee(const DmAccessCallee &callee, MessageParcel &parcel) bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) { bool bRet = true; - bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); @@ -167,7 +167,7 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { - READ_HELPER_RET(parcel, Uint64, serviceInfo.serviceId, false); + 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); @@ -195,7 +195,7 @@ bool DecodeServiceInfos(MessageParcel &parcel, std::vector &servi } for (uint32_t k = 0; k < num; k++) { DMServiceInfo serviceInfo; - READ_HELPER_RET(parcel, Uint64, serviceInfo.serviceId, false); + 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); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index b39b97019..ac086799c 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1691,8 +1691,12 @@ bool xProcessRegisterServiceInfo(std::string bindParam) serviceInfo.pinCode = pincode; serviceInfo.description = "profile.description"; serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; - serviceInfo.serviceId = DeviceManager::GetInstance().GenerateServiceId(); - DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); + int32_t err = DeviceManager::GetInstance().GenerateServiceId(serviceInfo.serviceId); + if (err == DM_OK) { + DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); + } else { + LOGI("[temp003] DeviceManager::GenerateServiceId failed"); + } LOGI("[temp003] DeviceManager::GetInstance().RegisterServiceInfo complete"); return true; } diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 862fc45a0..8cdc3ba7a 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -129,7 +129,7 @@ void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee) bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) { bool bRet = true; - bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); @@ -156,7 +156,7 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP for (uint32_t k = 0; k < num; k++) { const DMServiceInfo& serviceInfo = serviceInfos[k]; bool bRet = true; - bRet = (bRet && parcel.WriteUint64(serviceInfo.serviceId)); + bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDisplayName)); @@ -180,7 +180,7 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) { - serviceInfo.serviceId = parcel.ReadUint64(); + serviceInfo.serviceId = parcel.ReadInt64(); serviceInfo.serviceType = parcel.ReadString(); serviceInfo.serviceName = parcel.ReadString(); serviceInfo.serviceDisplayName = parcel.ReadString(); -- Gitee From 525c789ae3efc6daa1e3c5065fc81e86a0cf53c0 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 19:11:06 +0800 Subject: [PATCH 30/55] fix Change-Id: I6d92bff9a0370df805cb0d5e766eb5c32ce9f97a --- .../src/ipc/standard/ipc_cmd_parser.cpp | 6 +-- test/unittest/UTTest_device_manager_impl.cpp | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 8cdc3ba7a..0f3dce22a 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -148,14 +148,14 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) bool EncodeServiceInfos(const std::vector& serviceInfos, MessageParcel &parcel) { - int32_t num = serviceInfos.size(); - if (!parcel.WriteInt32(num)){ + uint32_t num = serviceInfos.size(); + if (!parcel.WriteUint32(num)){ LOGE("[rm003] WriteInt32 num failed"); return false; } + bool bRet = true; for (uint32_t k = 0; k < num; k++) { const DMServiceInfo& serviceInfo = serviceInfos[k]; - bool bRet = true; bRet = (bRet && parcel.WriteInt64(serviceInfo.serviceId)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceType)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceName)); diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index c846464ec..f738346fd 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2551,6 +2551,53 @@ HWTEST_F(DeviceManagerImplTest, GetDeviceSecurityLevel_001, testing::ext::TestSi ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, netWorkId, securityLevel); ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } + +HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Level0) +{ + std::string packName = "com.ohos.test"; + std::shared_ptr callback = std::make_shared(); + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); + ASSERT_EQ(ret, DM_OK); + int64_t serviceId = 0; + ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); + ASSERT_EQ(ret, DM_OK); + DMServiceInfo serviceInfo; + serviceInfo.serviceId = serviceId; + serviceInfo.serviceType = "profile.serviceType"; + serviceInfo.serviceName = "profile.serviceName"; + serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; + serviceInfo.customData = "profile.customData"; + serviceInfo.bundleName = "profile.bundleName"; + serviceInfo.moduleName = "profile.moduleName"; + serviceInfo.abilityName = "profile.abilityName"; + serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; + serviceInfo.authType = DMAuthType_TrustOneTime; + serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; + serviceInfo.pinCode = pincode; + serviceInfo.description = "profile.description"; + serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; + ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); + ASSERT_EQ(ret, DM_OK); + DMServiceInfo retInfo; + ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); + ASSERT_EQ(ret, DM_OK); + ASSERT_TRUE(retInfo.description == serviceInfo.description); + //ret = DeviceManager::GetInstance().UpdateServiceInfo(serviceInfo); + //ASSERT_EQ(ret, DM_OK); + DeviceManager::GetInstance().UnInitDeviceManager(packName); +} + +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_101, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(); + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManager::GetInstance().UnInitDeviceManager(packName); +} } // namespace } // namespace DistributedHardware } // namespace OHOS -- Gitee From 346f9b45968be90f55e38824a39e209e0ec371e8 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 19:19:35 +0800 Subject: [PATCH 31/55] fix Change-Id: I8ca411eec27cb70bcfc2fb67096a2adf930ff408 --- test/unittest/UTTest_device_manager_impl.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index f738346fd..804cb50b0 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2573,7 +2573,7 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; serviceInfo.authType = DMAuthType_TrustOneTime; serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; - serviceInfo.pinCode = pincode; + serviceInfo.pinCode = "123456"; serviceInfo.description = "profile.description"; serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); @@ -2587,17 +2587,6 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve DeviceManager::GetInstance().UnInitDeviceManager(packName); } -HWTEST_F(DeviceManagerImplTest, InitDeviceManager_101, testing::ext::TestSize.Level0) -{ - // 1. set packName not null - std::string packName = "com.ohos.test"; - // set dmInitCallback not null - std::shared_ptr callback = std::make_shared(); - int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); - // 3. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); - DeviceManager::GetInstance().UnInitDeviceManager(packName); -} } // namespace } // namespace DistributedHardware } // namespace OHOS -- Gitee From add30562fab5af1de1bae19e777ae1255fdc638d Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 19:25:41 +0800 Subject: [PATCH 32/55] fix Change-Id: Ia880d359cbe52fd06f5be08bb7b9c97c1afa07cd --- .../native_cpp/src/device_manager_impl.cpp | 2 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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 21221b958..8a8d5c5fd 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2765,7 +2765,7 @@ int32_t DeviceManagerImpl::GetCallerServiceId(std::vector &servic LOGI("[rm003] GenerateServiceId"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); - int32_t ret = ipcClientProxy_->SendRequest(GEN_SERVICEID, req, rsp); + int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_CALLER, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); return ERR_DM_IPC_SEND_REQUEST_FAILED; diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 0f3dce22a..41992f320 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1944,5 +1944,24 @@ ON_IPC_CMD(GET_SERVICEINFO_BYID, MessageParcel &data, MessageParcel &reply) return DM_OK; } +ON_IPC_CMD(GET_SERVICEINFO_CALLER, MessageParcel &data, MessageParcel &reply) +{ + LOGI("[rm003] ON_IPC_CMD(GET_SERVICEINFO_CALLER"); + 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) { + return DM_OK; + } + if (!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 -- Gitee From a04dca5bdf467b71b46a2af9aa6a7b0022ccd1f2 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Thu, 23 Jan 2025 19:29:09 +0800 Subject: [PATCH 33/55] fix Change-Id: Iba32061ba7d8f92af8ecd188ba19b515846520d2 --- interfaces/inner_kits/native_cpp/include/device_manager_impl.h | 1 + interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) 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 c1d67ab16..d9bd948bc 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,7 @@ public: virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) override; virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) override; virtual int32_t GetCallerServiceId(std::vector &serviceInfos) override; + private: DeviceManagerImpl() = default; ~DeviceManagerImpl() = default; 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 8a8d5c5fd..4b6c95b5d 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2780,6 +2780,5 @@ int32_t DeviceManagerImpl::GetCallerServiceId(std::vector &servic return DM_OK; } - } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From bba0215f1c757edd239054dd500a0940bd17bbb0 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 09:16:06 +0800 Subject: [PATCH 34/55] fix Change-Id: I13de03741c173f5052137cb7412f92f9833c88ca --- .../native_cpp/include/device_manager.h | 2 +- .../native_cpp/include/device_manager_impl.h | 2 +- .../native_cpp/src/device_manager_impl.cpp | 4 ++-- .../src/ipc/standard/ipc_cmd_parser.cpp | 20 +++++++++++++++++++ test/unittest/UTTest_device_manager_impl.cpp | 7 ++++--- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 4aa89d353..c8388fad4 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -654,7 +654,7 @@ public: virtual int32_t UnRegisterServiceInfo(const DMServiceInfo &info) = 0; virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) = 0; virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) = 0; - virtual int32_t GetCallerServiceId(std::vector &serviceInfos) = 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 d9bd948bc..eb6ddf6be 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -421,7 +421,7 @@ public: virtual int32_t UnRegisterServiceInfo(const DMServiceInfo &info) override; virtual int32_t UpdateServiceInfo(const DMServiceInfo &info) override; virtual int32_t GetServiceInfoByServiceId(int64_t serviceId, DMServiceInfo &info) override; - virtual int32_t GetCallerServiceId(std::vector &serviceInfos) override; + virtual int32_t GetCallerServiceInfos(std::vector &serviceInfos) override; private: DeviceManagerImpl() = default; 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 4b6c95b5d..ddeef1671 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2759,10 +2759,10 @@ int32_t DeviceManagerImpl::GetServiceInfoByServiceId(int64_t serviceId, DMServic return DM_OK; } -int32_t DeviceManagerImpl::GetCallerServiceId(std::vector &serviceInfos) +int32_t DeviceManagerImpl::GetCallerServiceInfos(std::vector &serviceInfos) { LOGI("Start"); - LOGI("[rm003] GenerateServiceId"); + LOGI("[rm003] GetCallerServiceInfos"); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); int32_t ret = ipcClientProxy_->SendRequest(GET_SERVICEINFO_CALLER, req, rsp); 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 fea2aebee..3a949313d 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 @@ -2248,6 +2248,16 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &repl return DM_OK; } +ON_IPC_SET_REQUEST(GEN_SERVICEID, std::shared_ptr pBaseReq, MessageParcel &data) +{ + LOGI("[rm003] ON_IPC_SET_REQUEST(GEN_SERVICEID"); + 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) { LOGI("[rm003] ON_IPC_READ_RESPONSE(GEN_SERVICEID"); @@ -2378,6 +2388,16 @@ ON_IPC_READ_RESPONSE(GET_SERVICEINFO_BYID, MessageParcel &reply, std::shared_ptr return DM_OK; } +ON_IPC_SET_REQUEST(GET_SERVICEINFO_CALLER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + LOGI("[rm003] ON_IPC_SET_REQUEST(GET_SERVICEINFO_CALLER"); + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } + return DM_OK; +} + ON_IPC_READ_RESPONSE(GET_SERVICEINFO_CALLER, MessageParcel &reply, std::shared_ptr pBaseRsp) { LOGI("[rm003] ON_IPC_READ_RESPONSE(GET_SERVICEINFO_CALLER"); diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 804cb50b0..76f55762b 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2581,9 +2581,10 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve DMServiceInfo retInfo; ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); ASSERT_EQ(ret, DM_OK); - ASSERT_TRUE(retInfo.description == serviceInfo.description); - //ret = DeviceManager::GetInstance().UpdateServiceInfo(serviceInfo); - //ASSERT_EQ(ret, DM_OK); + std::vector infos; + ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); + ASSERT_EQ(infos.size(), 1); + ASSERT_EQ(ret, DM_OK); DeviceManager::GetInstance().UnInitDeviceManager(packName); } -- Gitee From 0d42d342b3d123f6ae1ee173751c6cac74f46c27 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 09:36:48 +0800 Subject: [PATCH 35/55] fix Signed-off-by: zhuzhihui7 Change-Id: Ifbc37b8e281b0a79c0a2f5b42875158448831e4d --- .../native_cpp/src/ipc/standard/ipc_cmd_parser.cpp | 9 +++------ services/service/include/device_manager_service.h | 1 + services/service/src/device_manager_service.cpp | 5 +---- services/service/src/ipc/standard/ipc_cmd_parser.cpp | 10 ++-------- 4 files changed, 7 insertions(+), 18 deletions(-) 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 3a949313d..e42cd8ed3 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 @@ -186,13 +186,8 @@ bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) bool DecodeServiceInfos(MessageParcel &parcel, std::vector &serviceInfos) { - const int32_t maxNum = 100; uint32_t num = 0; READ_HELPER_RET(parcel, Uint32, num, false); - if (num > maxNum) { - LOGE("[rm003] num %{public}d > maxNum", num); - return false; - } for (uint32_t k = 0; k < num; k++) { DMServiceInfo serviceInfo; READ_HELPER_RET(parcel, Int64, serviceInfo.serviceId, false); @@ -2267,7 +2262,9 @@ ON_IPC_READ_RESPONSE(GEN_SERVICEID, MessageParcel &reply, std::shared_ptrSetErrCode(reply.ReadInt32()); - pRsp->SetServiceId(reply.ReadInt64()); + if (pRsp->GetErrCode() == DM_OK) { + pRsp->SetServiceId(reply.ReadInt64()); + } return DM_OK; } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 3a97dd0be..7ce52268a 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -304,6 +304,7 @@ private: #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI #endif int64_t GenerateSerivceId(std::string &udid, int32_t userId); + private: bool isImplsoLoaded_ = false; bool isAdapterResidentSoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 55e1a143b..cf003212b 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -66,9 +66,6 @@ constexpr const char* LIB_IMPL_NAME = "libdevicemanagerserviceimpl.so"; constexpr const char* LIB_DM_ADAPTER_NAME = "libdevicemanageradapter.z.so"; constexpr const char* LIB_DM_RESIDENT_NAME = "libdevicemanagerresident.z.so"; -#define RANDOM_SERVICEID_MIN 10000 -#define RANDOM_SERVICEID_MAX 999999 - namespace OHOS { namespace DistributedHardware { DM_IMPLEMENT_SINGLE_INSTANCE(DeviceManagerService); @@ -1477,7 +1474,7 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userI } const uint32_t dataLength = sizeof(int64_t) + sizeof(int32_t) + udid.length(); std::unique_ptr data = std::make_unique(dataLength); - int64_t randomSeed = GenRandLongLong(RANDOM_SERVICEID_MIN, RANDOM_SERVICEID_MAX); + int64_t randomSeed = GenRandLongLong(0, std::numeric_limits::max()); unsigned char* dataPtr = data.get(); *((int64_t*)dataPtr) = randomSeed; dataPtr += sizeof(int64_t); diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 41992f320..141206272 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1934,10 +1934,7 @@ ON_IPC_CMD(GET_SERVICEINFO_BYID, MessageParcel &data, MessageParcel &reply) LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } - if (result != DM_OK) { - return DM_OK; - } - if (!EncodeServiceInfo(serviceInfo, reply)) { + if (result == DM_OK && !EncodeServiceInfo(serviceInfo, reply)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } @@ -1953,10 +1950,7 @@ ON_IPC_CMD(GET_SERVICEINFO_CALLER, MessageParcel &data, MessageParcel &reply) LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } - if (result != DM_OK) { - return DM_OK; - } - if (!EncodeServiceInfos(serviceInfos, reply)) { + if (result == DM_OK && !EncodeServiceInfos(serviceInfos, reply)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; } -- Gitee From b4184a3c9241c78cc1be95891433e5dd6d283770 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 09:39:39 +0800 Subject: [PATCH 36/55] ut Change-Id: I0d803253cf77009d4528ecb24f17fbf6f74035fa --- test/unittest/UTTest_device_manager_impl.cpp | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 76f55762b..286734536 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -77,6 +77,23 @@ void DeviceManagerImplTest::TearDownTestCase() { } +void DeviceManagerImplTest::InitServiceInfo(DMServiceInfo &serviceInfo) +{ + serviceInfo.serviceType = "profile.serviceType"; + serviceInfo.serviceName = "profile.serviceName"; + serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; + serviceInfo.customData = "profile.customData"; + serviceInfo.bundleName = "profile.bundleName"; + serviceInfo.moduleName = "profile.moduleName"; + serviceInfo.abilityName = "profile.abilityName"; + serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; + serviceInfo.authType = DMAuthType_TrustOneTime; + serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; + serviceInfo.pinCode = "123456"; + serviceInfo.description = "profile.description"; + serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; +} + namespace { /** * @tc.name: InitDeviceManager_001 @@ -2562,20 +2579,8 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); ASSERT_EQ(ret, DM_OK); DMServiceInfo serviceInfo; + InitServiceInfo(serviceInfo); serviceInfo.serviceId = serviceId; - serviceInfo.serviceType = "profile.serviceType"; - serviceInfo.serviceName = "profile.serviceName"; - serviceInfo.serviceDisplayName = "profile.serviceDisplayName"; - serviceInfo.customData = "profile.customData"; - serviceInfo.bundleName = "profile.bundleName"; - serviceInfo.moduleName = "profile.moduleName"; - serviceInfo.abilityName = "profile.abilityName"; - serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; - serviceInfo.authType = DMAuthType_TrustOneTime; - serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; - serviceInfo.pinCode = "123456"; - serviceInfo.description = "profile.description"; - serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); ASSERT_EQ(ret, DM_OK); DMServiceInfo retInfo; -- Gitee From b2edf0d182305bf0feee02caa14b6600fdecdf52 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 09:40:52 +0800 Subject: [PATCH 37/55] ut Change-Id: I2b9a6d271e474feaf9b263e29b3e70fd7001242f --- common/include/dm_constants.h | 1 - 1 file changed, 1 deletion(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1c9e2b522..4eb915050 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -51,7 +51,6 @@ enum { ERR_DM_SYNC_DELETE_DEVICE_REPEATED = -20058, ERR_DM_VERSION_INCOMPATIBLE = -20059, ERR_DM_SERVICEINFO_NOTVALID = -20060, - ERR_DM_SERVICEINFO_GENSERVICEID_FAILED = -20061, ERR_DM_FAILED = 96929744, ERR_DM_NOT_INIT = 96929746, -- Gitee From 02c0d74874befbc58a9ba3b63af71f8ec6c32379 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 09:42:47 +0800 Subject: [PATCH 38/55] ut Change-Id: Idce1587e7e45af2ef2fe686d8d0d25ff26021239 --- interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ddeef1671..5c019499d 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2776,7 +2776,7 @@ int32_t DeviceManagerImpl::GetCallerServiceInfos(std::vector &ser return ret; } serviceInfos = rsp->GetServiceInfos(); - LOGI("Completed"); + LOGI("Completed, serviceInfos size %{public}zu", serviceInfos.size()); return DM_OK; } -- Gitee From aa3064af8eff343685151ffebd7ff4d1eddc5425 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 12:46:33 +0800 Subject: [PATCH 39/55] dm - dp Change-Id: I0868deea36ade3271c05662808bc1540aa74fd5b --- .../include/deviceprofile_connector.h | 11 ++- .../src/deviceprofile_connector.cpp | 54 ++++++++--- .../src/authentication/dm_auth_manager.cpp | 16 ++-- .../service/include/device_manager_service.h | 1 + .../service/src/device_manager_service.cpp | 89 ++++++++++++++----- 5 files changed, 125 insertions(+), 46 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index d496d4303..e1a1122fd 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -22,6 +22,7 @@ #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; @@ -168,9 +169,13 @@ public: int32_t SubscribeDeviceProfileInited(sptr dpInitedCallback); int32_t UnSubscribeDeviceProfileInited(); int32_t PutAllTrustedDevices(const std::vector &deviceInfos); - int32_t RegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); - int32_t UnRegisterServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoProfile &profile); - int32_t GetServiceInfoProfile(uint64_t tokenId, DistributedDeviceProfile::ServiceInfoProfile &profile); + 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); private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 348a40431..6f5309208 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1631,34 +1631,62 @@ int32_t DeviceProfileConnector::PutAllTrustedDevices( return DM_OK; } -int32_t DeviceProfileConnector::RegisterServiceInfoProfile( - const DistributedDeviceProfile::ServiceInfoProfile& profile) +int32_t DeviceProfileConnector::PutServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile& serviceInfoProfile) { - LOGI("[rm003] DeviceProfileConnector::RegisterServiceInfoProfile"); - int32_t ret = DistributedDeviceProfileClient::GetInstance().RegisterServiceInfoProfile(profile); + LOGI("[rm003] DeviceProfileConnector::PutServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().PutServiceInfoProfile(serviceInfoProfile); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; } - return DM_OK; + return DM_OK; +} + +int32_t DeviceProfileConnector::DeleteServiceInfoProfile(const DistributedDeviceProfile::ServiceInfoUniqueKey& key) +{ + LOGI("[rm003] DeviceProfileConnector::DeleteServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().DeleteServiceInfoProfile(key); + if (ret != DM_OK) { + LOGE("failed: %{public}d", ret); + return ret; + } + return DM_OK; } -int32_t DeviceProfileConnector::UnRegisterServiceInfoProfile( - const DistributedDeviceProfile::ServiceInfoProfile& profile) +int32_t DeviceProfileConnector::UpdateServiceInfoProfile( + const DistributedDeviceProfile::ServiceInfoProfile& serviceInfoProfile) { - LOGI("[rm003] DeviceProfileConnector::RegisterServiceInfoProfile"); - int32_t ret = DistributedDeviceProfileClient::GetInstance().UnRegisterServiceInfoProfile(profile); + LOGI("[rm003] DeviceProfileConnector::UpdateServiceInfoProfile"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; } - return DM_OK; + return DM_OK; +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileByUniqueKey( + const DistributedDeviceProfile::ServiceInfoUniqueKey& key, + DistributedDeviceProfile::ServiceInfoProfile& serviceInfoProfile) +{ + LOGI("[rm003] DeviceProfileConnector::GetServiceInfoProfileByUniqueKey"); + 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::GetServiceInfoProfile(uint64_t tokenId, ServiceInfoProfile& profile) +int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( + const DistributedDeviceProfile::ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) { - LOGI("[rm003] DeviceProfileConnector::GetServiceInfoProfile"); - int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfile(tokenId, profile); + LOGI("[rm003] DeviceProfileConnector::GetServiceInfoProfileListByTokenId"); + int32_t ret = DistributedDeviceProfileClient::GetInstance().GetServiceInfoProfileListByTokenId( + key, serviceInfoProfiles); if (ret != DM_OK) { LOGE("failed: %{public}d", ret); return ret; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5a6491fb5..f3070eb75 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1249,7 +1249,7 @@ int32_t DmAuthManager::ConfirmProcessExt(const int32_t &action) if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { if (IsUsePinFromDp() && authResponseContext_->isPincodeSetted) { - authResponseContext_->code = std::stoi(serviceInfoProfile_.pinCode); + authResponseContext_->code = std::stoi(serviceInfoProfile_.GetPinCode()); LOGI("[rm003-nopincode] import from dp, pin %{public}d", authResponseContext_->code); } else if (!authResponseContext_->isShowDialog) { GetAuthCode(authResponseContext_->hostPkgName, authResponseContext_->code); @@ -1575,8 +1575,8 @@ bool DmAuthManager::IsPinCodeValid(int32_t numpin) bool DmAuthManager::IsUsePinFromDp() { - return (serviceInfoProfile_.pinExchangeType == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && - DmAuthManager::IsPinCodeValid(serviceInfoProfile_.pinCode)); + return (serviceInfoProfile_.GetPinExchangeType() == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + DmAuthManager::IsPinCodeValid(serviceInfoProfile_.GetPinCode())); } std::string DmAuthManager::GenerateGroupName() @@ -1660,9 +1660,9 @@ void DmAuthManager::ShowConfigDialog() return; } - if (serviceInfoProfile_.authBoxType == DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM) { + if (serviceInfoProfile_.GetAuthBoxType() == DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM) { LOGI("[rm003-nopincode] no need confirm dialog"); - StartAuthProcess(serviceInfoProfile_.authType); + StartAuthProcess(serviceInfoProfile_.GetAuthType()); return; } if (!authResponseContext_->isShowDialog) { @@ -2604,9 +2604,9 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) LOGI("[rm003-nopincode] GetServiceInfoProfile failed"); } else { LOGI("[rm003-nopincode] GetServiceInfoProfile, tokenId %{public}" PRId64 ", ret %{public}d", tokenId, ret); - LOGI("[rm003] authBoxType %{public}s ", serviceInfoProfile_.authBoxType.c_str()); - LOGI("[rm003] authType %{public}d , pinExchangeType %{public}s", serviceInfoProfile_.authType, serviceInfoProfile_.pinExchangeType.c_str()); - LOGI("[rm003] pinCode %{public}s ", serviceInfoProfile_.pinCode.c_str()); + LOGI("[rm003] authBoxType %{public}d ", serviceInfoProfile_.GetAuthBoxType()); + LOGI("[rm003] authType %{public}d , pinExchangeType %{public}d", serviceInfoProfile_.GetAuthType(), serviceInfoProfile_.GetPinExchangeType()); + LOGI("[rm003] pinCode %{public}s ", serviceInfoProfile_.GetPinCode().c_str()); } } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 7ce52268a..ed4215f21 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -188,6 +188,7 @@ public: int64_t GenerateSerivceId(); void InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); + bool InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t UnRegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t UpdateServiceInfo(DMServiceInfo &serviceInfo); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index cf003212b..5da842e28 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1469,7 +1469,7 @@ int64_t DeviceManagerService::GenerateSerivceId() int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userId) { if (udid.empty()) { - LOGI("[rm003] GenerateSeivceId udid empty"); + LOGE("[rm003] GenerateSeivceId udid empty"); return 0; } const uint32_t dataLength = sizeof(int64_t) + sizeof(int32_t) + udid.length(); @@ -1481,7 +1481,7 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userI *((int32_t*)dataPtr) = userId; dataPtr += sizeof(int32_t); if (memcpy_s(dataPtr, udid.length(), udid.c_str(), udid.length()) != EOK) { - LOGI("[rm003] memcpy udid failed"); + LOGE("[rm003] memcpy udid failed"); return 0; } @@ -1494,7 +1494,7 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userI int64_t serviceId = 0; if (memcpy_s(&serviceId, sizeof(int64_t), out, sizeof(int64_t)) != EOK) { serviceId = 0; - LOGI("[rm003] memcpy serviceId failed"); + LOGE("[rm003] memcpy serviceId failed"); } serviceId = std::abs(serviceId); LOGI("[rm003] GenerateSeivceId %{public}" PRId64, serviceId); @@ -1508,8 +1508,11 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn if (ret != DM_OK) { LOGE("[rm003] GetLocalDeviceInfo failed"); } - - profile.udid = devInfo.deviceId; + + profile.SetDeviceId(devInfo.deviceId); + + + /*profile.udid = devInfo.deviceId; profile.netWorkId = devInfo.networkId; profile.tokenId = IPCSkeleton::GetCallingTokenID(); profile.userId = IPCSkeleton::GetCallingUid(); @@ -1526,12 +1529,12 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn profile.pinExchangeType = serviceInfo.pinExchangeType; profile.pinCode = serviceInfo.pinCode; profile.description = serviceInfo.description; - profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope; + profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope;*/ } void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo) { - serviceInfo.serviceId = profile.serviceId; + /*serviceInfo.serviceId = profile.serviceId; serviceInfo.serviceType = profile.serviceType; serviceInfo.serviceName = profile.serviceName; serviceInfo.serviceDisplayName = profile.serviceDisplayName; @@ -1544,25 +1547,39 @@ void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::Servi serviceInfo.pinExchangeType = profile.pinExchangeType; serviceInfo.pinCode = profile.pinCode; serviceInfo.description = profile.description; - serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope; + serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope;*/ } +bool DeviceManagerService::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) +{ + DmDeviceInfo devInfo; + int32_t ret = GetLocalDeviceInfo(devInfo); + if (ret != DM_OK) { + LOGE("[rm003] GetLocalDeviceInfo failed"); + return false; + } + key.SetDeviceId(devInfo.deviceId); + key.SetUserId(IPCSkeleton::GetCallingUid()); + key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); + return true; +} + int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) { //todo permission verifier if (!IsServiceInfoValid(serviceInfo)) { - LOGI("[rm003] IsServiceInfoValid failed"); + LOGE("[rm003] IsServiceInfoValid failed"); return ERR_DM_SERVICEINFO_NOTVALID; } LOGI("[rm003] DeviceManagerService::RegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - int32_t ret = DeviceProfileConnector::GetInstance().RegisterServiceInfoProfile(profile); + int32_t result = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); - DistributedDeviceProfile::ServiceInfoProfile profileRet; - DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); - LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); - return ret; + //DistributedDeviceProfile::ServiceInfoProfile profileRet; + //DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); + //LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); + return result; } int32_t DeviceManagerService::UnRegisterServiceInfo(DMServiceInfo &serviceInfo) @@ -1570,29 +1587,57 @@ int32_t DeviceManagerService::UnRegisterServiceInfo(DMServiceInfo &serviceInfo) LOGI("[rm003] DeviceManagerService::UnRegisterServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - return DeviceProfileConnector::GetInstance().UnRegisterServiceInfoProfile(profile); + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("[rm003] InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + key.SetServiceId(serviceInfo.serviceId); + return DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); } int32_t DeviceManagerService::UpdateServiceInfo(DMServiceInfo &serviceInfo) { LOGI("[rm003] DeviceManagerService::UpdateServiceInfo"); - return DM_OK; + DistributedDeviceProfile::ServiceInfoProfile profile; + InitServiceInfoProfile(serviceInfo, profile); + int32_t result = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); + return result; } int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInfo &serviceInfo) { LOGI("[rm003] DeviceManagerService::GetServiceInfoById, %{public}" PRId64, serviceId); - serviceInfo.abilityName = "kkkability"; - return DM_OK; + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("[rm003] InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + key.SetServiceId(serviceInfo.serviceId); + DistributedDeviceProfile::ServiceInfoProfile profile; + result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, profile); + if (!result) { + LOGE("[rm003] GetServiceInfoProfileByUniqueKey failed"); + return ERR_DM_FAILED; + } + InitServiceInfo(profile, serviceInfo); + return result; } int32_t DeviceManagerService::GetCallerServiceInfos(std::vector &serviceInfos) { LOGI("[rm003] DeviceManagerService::GetCallerServiceInfos"); - DMServiceInfo serviceInfo; - serviceInfo.abilityName = "kkkjjjjability"; - serviceInfos.emplace_back(serviceInfo); - return DM_OK; + DistributedDeviceProfile::ServiceInfoUniqueKey key; + bool result = InitServiceInfoUniqueKey(key); + if (!result) { + LOGE("[rm003] InitServiceInfoUniqueKey failed"); + return ERR_DM_FAILED; + } + std::vector profiles; + result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); + return result; } int32_t DeviceManagerService::RegisterPinHolderCallback(const std::string &pkgName) -- Gitee From e019fe83f3425b27066795b131ed60730168f119 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 13:08:56 +0800 Subject: [PATCH 40/55] dm - dp Change-Id: Ic755beba1a418aa794b211b07283568e486b42f8 --- .../native_cpp/include/dm_device_info.h | 24 ++++++++--- .../src/ipc/standard/ipc_cmd_parser.cpp | 12 +++--- .../js4.0/src/native_devicemanager_js.cpp | 6 +-- .../service/include/device_manager_service.h | 1 + .../service/src/device_manager_service.cpp | 42 +++++++++---------- .../src/ipc/standard/ipc_cmd_parser.cpp | 12 +++--- test/unittest/UTTest_device_manager_impl.cpp | 6 +-- 7 files changed, 57 insertions(+), 46 deletions(-) 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 e50d16efb..8e8bd074a 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -415,10 +415,22 @@ typedef struct DmNotifyKey { } DmNotifyKey; typedef enum : int32_t { - DMAuthType_TrustOneTime = 0, - DMAuthType_TrustAlways = 6, - DMAuthType_Cancel = 1 -} DMAuthType; + DMServiceInfoAuthType_TrustOneTime = 0, + DMServiceInfoAuthType_TrustAlways = 6, + DMServiceInfoAuthType_Cancel = 1 +} DMServiceInfoAuthType; + +typedef enum : int32_t { + DMServiceInfoPinExchangeType_PinBox = 1, + DMServiceInfoPinExchangeType_UltraSound = 2, + DMServiceInfoPinExchangeType_FromDp = 3 +} DMServiceInfoExchangeType; + +typedef enum : int32_t { + DMServiceInfoAuthBoxType_3State = 1, + DMServiceInfoAuthBoxType_SkipConfirm = 2, + DMServiceInfoAuthBoxType_2In1 = 3 +} DMServiceInfoAuthBoxType; const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_PINBOX = "1"; const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_ULTRASOUND = "2"; @@ -436,9 +448,9 @@ typedef struct DMServiceInfo { std::string bundleName; std::string moduleName; std::string abilityName; - std::string authBoxType; + int32_t authBoxType = 0; int32_t authType = 0; - std::string pinExchangeType; + int32_t pinExchangeType = 0; std::string pinCode; std::string description; std::string serviceDiscoveryScope; 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 e42cd8ed3..90fe9a2f8 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 @@ -156,9 +156,9 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); - bRet = (bRet && parcel.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authBoxType)); bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); - bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.pinExchangeType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); bRet = (bRet && parcel.WriteString(serviceInfo.description)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); @@ -175,9 +175,9 @@ bool DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) 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, String, serviceInfo.authBoxType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authBoxType, false); READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); - READ_HELPER_RET(parcel, String, serviceInfo.pinExchangeType, 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); @@ -198,9 +198,9 @@ bool DecodeServiceInfos(MessageParcel &parcel, std::vector &servi 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, String, serviceInfo.authBoxType, false); + READ_HELPER_RET(parcel, Int32, serviceInfo.authBoxType, false); READ_HELPER_RET(parcel, Int32, serviceInfo.authType, false); - READ_HELPER_RET(parcel, String, serviceInfo.pinExchangeType, 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); diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index ac086799c..0ca0774bd 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1685,9 +1685,9 @@ bool xProcessRegisterServiceInfo(std::string bindParam) serviceInfo.bundleName = "profile.bundleName"; serviceInfo.moduleName = "profile.moduleName"; serviceInfo.abilityName = "profile.abilityName"; - serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; - serviceInfo.authType = DMAuthType_TrustOneTime; - serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; + serviceInfo.authBoxType = DMServiceInfoAuthBoxType_SkipConfirm; + serviceInfo.authType = DMServiceInfoAuthType_TrustOneTime; + serviceInfo.pinExchangeType = DMServiceInfoPinExchangeType_FromDp; serviceInfo.pinCode = pincode; serviceInfo.description = "profile.description"; serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index ed4215f21..47e3a8537 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 { diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 5da842e28..28cd38747 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1501,35 +1501,33 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userI return serviceId; } -void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile) +void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceInfo, + DistributedDeviceProfile::ServiceInfoProfile &profile) { DmDeviceInfo devInfo; int32_t ret = GetLocalDeviceInfo(devInfo); if (ret != DM_OK) { LOGE("[rm003] GetLocalDeviceInfo failed"); } - profile.SetDeviceId(devInfo.deviceId); - - - /*profile.udid = devInfo.deviceId; - profile.netWorkId = devInfo.networkId; - profile.tokenId = IPCSkeleton::GetCallingTokenID(); - profile.userId = IPCSkeleton::GetCallingUid(); - - profile.serviceType = serviceInfo.serviceType; - profile.serviceName = serviceInfo.serviceName; - profile.serviceDisplayName = serviceInfo.serviceDisplayName; - profile.customData = serviceInfo.customData; - profile.bundleName = serviceInfo.bundleName; - profile.moduleName = serviceInfo.moduleName; - profile.abilityName = serviceInfo.abilityName; - profile.authBoxType = serviceInfo.authBoxType; - profile.authType = serviceInfo.authType; - profile.pinExchangeType = serviceInfo.pinExchangeType; - profile.pinCode = serviceInfo.pinCode; - profile.description = serviceInfo.description; - profile.serviceDiscoveryScope = serviceInfo.serviceDiscoveryScope;*/ + profile.SetNetworkId(devInfo.networkId); + profile.SetUserId(IPCSkeleton::GetCallingUid()); + 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.SetServiceDiscoveryScope(serviceInfo.serviceDiscoveryScope); } void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo) diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 141206272..151ede485 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -137,9 +137,9 @@ bool EncodeServiceInfo(const DMServiceInfo& serviceInfo, MessageParcel &parcel) bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); - bRet = (bRet && parcel.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authBoxType)); bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); - bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.pinExchangeType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); bRet = (bRet && parcel.WriteString(serviceInfo.description)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); @@ -164,9 +164,9 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP bRet = (bRet && parcel.WriteString(serviceInfo.bundleName)); bRet = (bRet && parcel.WriteString(serviceInfo.moduleName)); bRet = (bRet && parcel.WriteString(serviceInfo.abilityName)); - bRet = (bRet && parcel.WriteString(serviceInfo.authBoxType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.authBoxType)); bRet = (bRet && parcel.WriteInt32(serviceInfo.authType)); - bRet = (bRet && parcel.WriteString(serviceInfo.pinExchangeType)); + bRet = (bRet && parcel.WriteInt32(serviceInfo.pinExchangeType)); bRet = (bRet && parcel.WriteString(serviceInfo.pinCode)); bRet = (bRet && parcel.WriteString(serviceInfo.description)); bRet = (bRet && parcel.WriteString(serviceInfo.serviceDiscoveryScope)); @@ -188,9 +188,9 @@ void DecodeServiceInfo(MessageParcel &parcel, DMServiceInfo &serviceInfo) serviceInfo.bundleName = parcel.ReadString(); serviceInfo.moduleName = parcel.ReadString(); serviceInfo.abilityName = parcel.ReadString(); - serviceInfo.authBoxType = parcel.ReadString(); + serviceInfo.authBoxType = parcel.ReadInt32(); serviceInfo.authType = parcel.ReadInt32(); - serviceInfo.pinExchangeType = parcel.ReadString(); + serviceInfo.pinExchangeType = parcel.ReadInt32(); serviceInfo.pinCode = parcel.ReadString(); serviceInfo.description = parcel.ReadString(); serviceInfo.serviceDiscoveryScope = parcel.ReadString(); diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 286734536..b8ebab27a 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -86,9 +86,9 @@ void DeviceManagerImplTest::InitServiceInfo(DMServiceInfo &serviceInfo) serviceInfo.bundleName = "profile.bundleName"; serviceInfo.moduleName = "profile.moduleName"; serviceInfo.abilityName = "profile.abilityName"; - serviceInfo.authBoxType = DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM; - serviceInfo.authType = DMAuthType_TrustOneTime; - serviceInfo.pinExchangeType = DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP; + serviceInfo.authBoxType = DMServiceInfoAuthBoxType_SkipConfirm; + serviceInfo.authType = DMServiceInfoAuthType_TrustOneTime; + serviceInfo.pinExchangeType = DMServiceInfoPinExchangeType_FromDp; serviceInfo.pinCode = "123456"; serviceInfo.description = "profile.description"; serviceInfo.serviceDiscoveryScope = "profile.serviceDiscoveryScope"; -- Gitee From 30d77734a1d0d7656a4ea62df1d4559d4a39cbfe Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 13:25:34 +0800 Subject: [PATCH 41/55] dm - dp Change-Id: Id592a0870636ad2eca8cc2e7011f59a2089042fb --- .../native_cpp/include/dm_device_info.h | 7 --- .../src/authentication/dm_auth_manager.cpp | 5 +- .../service/include/device_manager_service.h | 2 + .../service/src/device_manager_service.cpp | 58 ++++++++++++------- 4 files changed, 41 insertions(+), 31 deletions(-) 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 8e8bd074a..7ac41782b 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -432,13 +432,6 @@ typedef enum : int32_t { DMServiceInfoAuthBoxType_2In1 = 3 } DMServiceInfoAuthBoxType; -const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_PINBOX = "1"; -const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_ULTRASOUND = "2"; -const std::string DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP = "3"; -const std::string DM_SERVICEINFO_AUTHBOX_TYPE_3STATE = "1"; -const std::string DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM = "2"; -const std::string DM_SERVICEINFO_AUTHBOX_TYPE_2IN1 = "3"; - typedef struct DMServiceInfo { int64_t serviceId = 0; std::string serviceType; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index f3070eb75..5b57939b3 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1575,7 +1575,7 @@ bool DmAuthManager::IsPinCodeValid(int32_t numpin) bool DmAuthManager::IsUsePinFromDp() { - return (serviceInfoProfile_.GetPinExchangeType() == DM_SERVICEINFO_PINEXCHANGE_TYPE_IMPORT_FROMDP && + return (serviceInfoProfile_.GetPinExchangeType() == DMServiceInfoPinExchangeType_FromDp && DmAuthManager::IsPinCodeValid(serviceInfoProfile_.GetPinCode())); } @@ -1659,8 +1659,7 @@ void DmAuthManager::ShowConfigDialog() LOGE("failed to ShowConfigDialog because authResponseContext_ is nullptr"); return; } - - if (serviceInfoProfile_.GetAuthBoxType() == DM_SERVICEINFO_AUTHBOX_TYPE_SKIPCONFIRM) { + if (serviceInfoProfile_.GetAuthBoxType() == DMServiceInfoAuthBoxType_SkipConfirm) { LOGI("[rm003-nopincode] no need confirm dialog"); StartAuthProcess(serviceInfoProfile_.GetAuthType()); return; diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 47e3a8537..7849d18ea 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -189,6 +189,8 @@ public: int64_t GenerateSerivceId(); void 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); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t UnRegisterServiceInfo(DMServiceInfo &serviceInfo); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 28cd38747..4ee916c9a 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1527,27 +1527,38 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn profile.SetPinExchangeType(serviceInfo.pinExchangeType); profile.SetPinCode(serviceInfo.pinCode); profile.SetDescription(serviceInfo.description); - profile.SetServiceDiscoveryScope(serviceInfo.serviceDiscoveryScope); -} - -void DeviceManagerService::InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo &serviceInfo) -{ - /*serviceInfo.serviceId = profile.serviceId; - serviceInfo.serviceType = profile.serviceType; - serviceInfo.serviceName = profile.serviceName; - serviceInfo.serviceDisplayName = profile.serviceDisplayName; - serviceInfo.customData = profile.customData; - serviceInfo.bundleName = profile.bundleName; - serviceInfo.moduleName = profile.moduleName; - serviceInfo.abilityName = profile.abilityName; - serviceInfo.authBoxType = profile.authBoxType; - serviceInfo.authType = profile.authType; - serviceInfo.pinExchangeType = profile.pinExchangeType; - serviceInfo.pinCode = profile.pinCode; - serviceInfo.description = profile.description; - serviceInfo.serviceDiscoveryScope = profile.serviceDiscoveryScope;*/ -} - + profile.SetServiceDicoveryScope(serviceInfo.serviceDiscoveryScope); +} + +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) { DmDeviceInfo devInfo; @@ -1635,6 +1646,11 @@ int32_t DeviceManagerService::GetCallerServiceInfos(std::vector & } std::vector profiles; result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); + if (!result) { + LOGE("[rm003] GetServiceInfoProfileListByTokenId failed"); + return ERR_DM_FAILED; + } + InitServiceInfos(profiles, serviceInfos); return result; } -- Gitee From 465a0767445527d7920da84a691692b0050fc68a Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 13:47:06 +0800 Subject: [PATCH 42/55] dm - dp Change-Id: I3f76031783f1a06850d8d310efca71b7e140b9f5 --- .../include/authentication/dm_auth_manager.h | 2 ++ .../src/authentication/dm_auth_manager.cpp | 22 +++++++++++++++---- .../service/include/device_manager_service.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index b679066f9..9a51c6a53 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" @@ -500,6 +501,7 @@ public: private: bool IsHmlSessionType(); bool IsUsePinFromDp(); + void InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); 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); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 5b57939b3..3ee9ae5a7 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1579,6 +1579,15 @@ bool DmAuthManager::IsUsePinFromDp() DmAuthManager::IsPinCodeValid(serviceInfoProfile_.GetPinCode())); } +void DmAuthManager::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key) +{ + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + int32_t localUserId = MultipleUserConnector::GetFirstForegroundUserId(); + key.SetDeviceId(std::string(localDeviceId)); + key.SetUserId(localUserId); +} + std::string DmAuthManager::GenerateGroupName() { if (authResponseContext_ == nullptr) { @@ -2598,11 +2607,16 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); int64_t tokenId = GetBinderTokenId(); - int ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfile(tokenId, serviceInfoProfile_); - if (ret != DM_OK) { + DistributedDeviceProfile::ServiceInfoUniqueKey key; + InitServiceInfoUniqueKey(key); + key.SetTokenId(std::to_string(tokenId)); + std::vector profiles; + int32_t result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); + if (result != DM_OK) { LOGI("[rm003-nopincode] GetServiceInfoProfile failed"); - } else { - LOGI("[rm003-nopincode] GetServiceInfoProfile, tokenId %{public}" PRId64 ", ret %{public}d", tokenId, ret); + } else if(profiles.size() > 0) { + serviceInfoProfile_ = profiles[0]; + LOGI("[rm003-nopincode] GetServiceInfoProfile, tokenId %{public}" PRId64, tokenId); LOGI("[rm003] authBoxType %{public}d ", serviceInfoProfile_.GetAuthBoxType()); LOGI("[rm003] authType %{public}d , pinExchangeType %{public}d", serviceInfoProfile_.GetAuthType(), serviceInfoProfile_.GetPinExchangeType()); LOGI("[rm003] pinCode %{public}s ", serviceInfoProfile_.GetPinCode().c_str()); diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 7849d18ea..fdb7773c4 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -190,7 +190,7 @@ public: void InitServiceInfoProfile(const DMServiceInfo &serviceInfo, DistributedDeviceProfile::ServiceInfoProfile &profile); void InitServiceInfo(const DistributedDeviceProfile::ServiceInfoProfile &profile, DMServiceInfo& serviceInfo); void InitServiceInfos(const std::vector &profiles, - std::vector &serviceInfos) + std::vector &serviceInfos); bool InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceInfoUniqueKey &key); int32_t RegisterServiceInfo(DMServiceInfo &serviceInfo); int32_t UnRegisterServiceInfo(DMServiceInfo &serviceInfo); -- Gitee From 88edf094f3d4d896db42034c5f3e354b5b71275a Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 13:57:57 +0800 Subject: [PATCH 43/55] dm - dp Change-Id: Ic9c73e3a66d3d87990bbebbc2419cff8d39f29f6 --- .../service/src/ipc/standard/ipc_cmd_parser.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 151ede485..7176035e5 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -156,22 +156,9 @@ bool EncodeServiceInfos(const std::vector& serviceInfos, MessageP bool bRet = true; for (uint32_t k = 0; k < num; k++) { const DMServiceInfo& serviceInfo = serviceInfos[k]; - 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)); + bRet = EncodeServiceInfo(serviceInfo, parcel); if (!bRet) { - LOGE("[rm003] encode serviceinfo failed"); + LOGE("[rm003] encode serviceinfos failed"); break; } } -- Gitee From 969a9c014614e44eae6701547beb03e27f03ab98 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 15:26:38 +0800 Subject: [PATCH 44/55] dm - dp Change-Id: I5f683711b660a38b6694a47dbefe20463a146f38 --- test/unittest/UTTest_device_manager_impl.cpp | 9 +++++++++ test/unittest/UTTest_device_manager_impl.h | 1 + 2 files changed, 10 insertions(+) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index b8ebab27a..81a018e14 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2575,6 +2575,10 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve std::shared_ptr callback = std::make_shared(); int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); ASSERT_EQ(ret, DM_OK); + + DMServiceInfo serviceInfoOld; + InitServiceInfo(serviceInfoOld); + int64_t serviceId = 0; ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); ASSERT_EQ(ret, DM_OK); @@ -2586,6 +2590,11 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve DMServiceInfo retInfo; ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); ASSERT_EQ(ret, DM_OK); + ASSERT_TRUE(serviceId == retInfo.serviceId); + ASSERT_TRUE(serviceInfoOld.serviceType == retInfo.serviceType); + ASSERT_TRUE(serviceInfoOld.abilityName == retInfo.abilityName); + ASSERT_TRUE(serviceInfoOld.serviceDiscoveryScope == retInfo.serviceDiscoveryScope); + std::vector infos; ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); ASSERT_EQ(infos.size(), 1); diff --git a/test/unittest/UTTest_device_manager_impl.h b/test/unittest/UTTest_device_manager_impl.h index bb1de8da2..2b1647745 100644 --- a/test/unittest/UTTest_device_manager_impl.h +++ b/test/unittest/UTTest_device_manager_impl.h @@ -35,6 +35,7 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); + void InitServiceInfo(DMServiceInfo &serviceInfo); }; class DeviceDiscoveryCallbackTest : public DiscoveryCallback { -- Gitee From 4f871f1d3d4eb80663e4384f4baf6c4022647f33 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 18:12:40 +0800 Subject: [PATCH 45/55] dp Change-Id: If7a532ca8797f57a7f4d64be149a7e6dcc2d936b --- .../native_cpp/src/device_manager_impl.cpp | 1 - .../service/src/device_manager_service.cpp | 21 +++++++------------ test/unittest/UTTest_device_manager_impl.cpp | 9 +++++++- 3 files changed, 15 insertions(+), 16 deletions(-) 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 5c019499d..21fc1289a 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2779,6 +2779,5 @@ int32_t DeviceManagerImpl::GetCallerServiceInfos(std::vector &ser LOGI("Completed, serviceInfos size %{public}zu", serviceInfos.size()); return DM_OK; } - } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 4ee916c9a..b518d3419 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1492,11 +1492,11 @@ int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userI SHA256_Final(out, &ctx); int64_t serviceId = 0; - if (memcpy_s(&serviceId, sizeof(int64_t), out, sizeof(int64_t)) != EOK) { + if (memcpy_s(&serviceId, sizeof(int32_t), out, sizeof(int32_t)) != EOK) { serviceId = 0; LOGE("[rm003] memcpy serviceId failed"); } - serviceId = std::abs(serviceId); + serviceId = std::abs((int32_t)serviceId); LOGI("[rm003] GenerateSeivceId %{public}" PRId64, serviceId); return serviceId; } @@ -1584,10 +1584,6 @@ int32_t DeviceManagerService::RegisterServiceInfo(DMServiceInfo &serviceInfo) DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); int32_t result = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); - - //DistributedDeviceProfile::ServiceInfoProfile profileRet; - //DeviceProfileConnector::GetInstance().GetServiceInfoProfile(IPCSkeleton::GetCallingTokenID(), profileRet); - //LOGI("[rm003] udid %{public}s userId %{public}d", profileRet.udid.c_str(), profileRet.userId); return result; } @@ -1624,14 +1620,12 @@ int32_t DeviceManagerService::GetServiceInfoById(int64_t serviceId, DMServiceInf LOGE("[rm003] InitServiceInfoUniqueKey failed"); return ERR_DM_FAILED; } - key.SetServiceId(serviceInfo.serviceId); + key.SetServiceId(serviceId); DistributedDeviceProfile::ServiceInfoProfile profile; result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, profile); - if (!result) { - LOGE("[rm003] GetServiceInfoProfileByUniqueKey failed"); - return ERR_DM_FAILED; + if (result == DM_OK) { + InitServiceInfo(profile, serviceInfo); } - InitServiceInfo(profile, serviceInfo); return result; } @@ -1646,9 +1640,8 @@ int32_t DeviceManagerService::GetCallerServiceInfos(std::vector & } std::vector profiles; result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); - if (!result) { - LOGE("[rm003] GetServiceInfoProfileListByTokenId failed"); - return ERR_DM_FAILED; + if (result == DM_OK) { + InitServiceInfos(profiles, serviceInfos); } InitServiceInfos(profiles, serviceInfos); return result; diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 81a018e14..7964a0f79 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2588,6 +2588,7 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); ASSERT_EQ(ret, DM_OK); DMServiceInfo retInfo; + LOGI("[rm003] serviceId %{public}lld", serviceId); ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); ASSERT_EQ(ret, DM_OK); ASSERT_TRUE(serviceId == retInfo.serviceId); @@ -2597,8 +2598,14 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve std::vector infos; ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); - ASSERT_EQ(infos.size(), 1); ASSERT_EQ(ret, DM_OK); + for (const auto &item : infos) { + DeviceManager::GetInstance().UnRegisterServiceInfo(item); + } + infos.clear(); + ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); + ASSERT_NE(ret, DM_OK); + ASSERT_EQ(infos.size(), 0); DeviceManager::GetInstance().UnInitDeviceManager(packName); } -- Gitee From ede3f319e51b8303dbd59e64f2ba11d4071d1fa4 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 18:22:14 +0800 Subject: [PATCH 46/55] dp Change-Id: I634925d5c4fbc25659ebcc494d923f5b8de1ac46 --- services/service/src/device_manager_service.cpp | 2 +- test/unittest/UTTest_device_manager_impl.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index b518d3419..eaa6eb2b0 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1607,7 +1607,7 @@ int32_t DeviceManagerService::UpdateServiceInfo(DMServiceInfo &serviceInfo) LOGI("[rm003] DeviceManagerService::UpdateServiceInfo"); DistributedDeviceProfile::ServiceInfoProfile profile; InitServiceInfoProfile(serviceInfo, profile); - int32_t result = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(profile); + int32_t result = DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(profile); return result; } diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 7964a0f79..deded35c4 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2596,6 +2596,14 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve ASSERT_TRUE(serviceInfoOld.abilityName == retInfo.abilityName); ASSERT_TRUE(serviceInfoOld.serviceDiscoveryScope == retInfo.serviceDiscoveryScope); + retInfo.abilityName = "kkk"; + ret = DeviceManager::GetInstance().UpdateServiceInfo(retInfo); + ASSERT_EQ(ret, DM_OK); + + ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); + ASSERT_EQ(ret, DM_OK); + ASSERT_TRUE(serviceInfoOld.abilityName == "kkk"); + std::vector infos; ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); ASSERT_EQ(ret, DM_OK); -- Gitee From f87b6523390f0a8b10802beca37930bcc0b04acb Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 18:31:14 +0800 Subject: [PATCH 47/55] dp Change-Id: If7ae062859ca4b136aab656279cd56f4230202dd --- test/unittest/UTTest_device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index deded35c4..eb0c46e0a 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2602,7 +2602,7 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); ASSERT_EQ(ret, DM_OK); - ASSERT_TRUE(serviceInfoOld.abilityName == "kkk"); + ASSERT_TRUE(retInfo.abilityName == "kkk"); std::vector infos; ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); -- Gitee From fe94e02dec29c5515109faa6ce7e8694d098b2a2 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 19:42:01 +0800 Subject: [PATCH 48/55] dp Change-Id: Ie6f3be6b7b61d030f800f03e01341e99f1723d5b --- test/unittest/UTTest_device_manager_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index eb0c46e0a..d0eda8bc8 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2588,7 +2588,7 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo); ASSERT_EQ(ret, DM_OK); DMServiceInfo retInfo; - LOGI("[rm003] serviceId %{public}lld", serviceId); + LOGI("[rm003] serviceId %{public}" PRId64, serviceId); ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, retInfo); ASSERT_EQ(ret, DM_OK); ASSERT_TRUE(serviceId == retInfo.serviceId); -- Gitee From 31780d94a533fed38e6163374d056ace5b746408 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 24 Jan 2025 20:41:49 +0800 Subject: [PATCH 49/55] dp Change-Id: I9ef923239e19b82d5d9ac24a1fa24bc385e805b0 --- .../implementation/src/authentication/dm_auth_manager.cpp | 2 -- services/service/src/device_manager_service.cpp | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 3ee9ae5a7..a89e25b1b 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1583,9 +1583,7 @@ void DmAuthManager::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceIn { char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - int32_t localUserId = MultipleUserConnector::GetFirstForegroundUserId(); key.SetDeviceId(std::string(localDeviceId)); - key.SetUserId(localUserId); } std::string DmAuthManager::GenerateGroupName() diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index eaa6eb2b0..99a95f10f 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1509,7 +1509,9 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn if (ret != DM_OK) { LOGE("[rm003] GetLocalDeviceInfo failed"); } - profile.SetDeviceId(devInfo.deviceId); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + profile.SetDeviceId(std::string(localDeviceId)); profile.SetNetworkId(devInfo.networkId); profile.SetUserId(IPCSkeleton::GetCallingUid()); profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); -- Gitee From e43bc9d3fc49d91f2a52e5568a5c694c77f2cc3b Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 11:31:41 +0800 Subject: [PATCH 50/55] dp Change-Id: Ia52890f82de0c557223d4b7028c5676a538f4546 --- .../src/authentication/dm_auth_manager.cpp | 21 +++++++++------- .../service/include/device_manager_service.h | 1 - .../service/src/device_manager_service.cpp | 24 +++++++------------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index a89e25b1b..d319e5a7b 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1583,7 +1583,14 @@ void DmAuthManager::InitServiceInfoUniqueKey(DistributedDeviceProfile::ServiceIn { char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - key.SetDeviceId(std::string(localDeviceId)); + char udidHash[DM_MAX_DEVICE_ID_LEN] = {0}; + Crypto::GetUdidHash(localDeviceId, reinterpret_cast(udidHash)); + key.SetDeviceId(std::string(udidHash)); + int64_t tokenId = GetBinderTokenId(); + key.SetTokenId(std::to_string(tokenId)); + int32_t userId = MultipleUserConnector::GetFirstForegroundUserId(); + key.SetUserId(userId); + LOGI("[rm003] localDeviceId %{public}s, userId %{public}d, tokenId %{public}" PRId64, udidHash, userId, tokenId); } std::string DmAuthManager::GenerateGroupName() @@ -2604,20 +2611,18 @@ void DmAuthManager::ProcRespNegotiateExt(const int32_t &sessionId) std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); - int64_t tokenId = GetBinderTokenId(); DistributedDeviceProfile::ServiceInfoUniqueKey key; InitServiceInfoUniqueKey(key); - key.SetTokenId(std::to_string(tokenId)); std::vector profiles; int32_t result = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, profiles); if (result != DM_OK) { - LOGI("[rm003-nopincode] GetServiceInfoProfile failed"); + LOGI("[rm003-nopincode] GetServiceInfoProfileListByTokenId failed"); } else if(profiles.size() > 0) { serviceInfoProfile_ = profiles[0]; - LOGI("[rm003-nopincode] GetServiceInfoProfile, tokenId %{public}" PRId64, tokenId); - LOGI("[rm003] authBoxType %{public}d ", serviceInfoProfile_.GetAuthBoxType()); - LOGI("[rm003] authType %{public}d , pinExchangeType %{public}d", serviceInfoProfile_.GetAuthType(), serviceInfoProfile_.GetPinExchangeType()); - LOGI("[rm003] pinCode %{public}s ", serviceInfoProfile_.GetPinCode().c_str()); + LOGI("[rm003] authBoxType %{public}d", serviceInfoProfile_.GetAuthBoxType()); + LOGI("[rm003] authType %{public}d", serviceInfoProfile_.GetAuthType()); + LOGI("[rm003] pinExchangeType %{public}d", serviceInfoProfile_.GetPinExchangeType()); + LOGI("[rm003] pinCode %{public}s", serviceInfoProfile_.GetPinCode().c_str()); } } diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index fdb7773c4..045bc66c1 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -307,7 +307,6 @@ private: void QueryDependsSwitchState(); #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI #endif - int64_t GenerateSerivceId(std::string &udid, int32_t userId); private: bool isImplsoLoaded_ = false; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 99a95f10f..00c1cbf5c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1461,25 +1461,19 @@ int64_t DeviceManagerService::GenerateSerivceId() return 0; } std::string udid = devInfo.deviceId; - int32_t userId = IPCSkeleton::GetCallingUid(); - int64_t serviceId = GenerateSerivceId(udid, userId); - return serviceId; -} - -int64_t DeviceManagerService::GenerateSerivceId(std::string &udid, int32_t userId) -{ if (udid.empty()) { - LOGE("[rm003] GenerateSeivceId udid empty"); + LOGE("[rm003] udid empty"); return 0; } - const uint32_t dataLength = sizeof(int64_t) + sizeof(int32_t) + udid.length(); + 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); - *((int32_t*)dataPtr) = userId; - dataPtr += sizeof(int32_t); + *((int64_t*)dataPtr) = tokenId; + dataPtr += sizeof(int64_t); if (memcpy_s(dataPtr, udid.length(), udid.c_str(), udid.length()) != EOK) { LOGE("[rm003] memcpy udid failed"); return 0; @@ -1509,11 +1503,9 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn if (ret != DM_OK) { LOGE("[rm003] GetLocalDeviceInfo failed"); } - char localDeviceId[DEVICE_UUID_LENGTH] = {0}; - GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); - profile.SetDeviceId(std::string(localDeviceId)); + profile.SetDeviceId(devInfo.deviceId); profile.SetNetworkId(devInfo.networkId); - profile.SetUserId(IPCSkeleton::GetCallingUid()); + profile.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); profile.SetServiceId(serviceInfo.serviceId); profile.SetServiceType(serviceInfo.serviceType); @@ -1570,7 +1562,7 @@ bool DeviceManagerService::InitServiceInfoUniqueKey(DistributedDeviceProfile::Se return false; } key.SetDeviceId(devInfo.deviceId); - key.SetUserId(IPCSkeleton::GetCallingUid()); + key.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); return true; } -- Gitee From 58102396de79ecb97071e441d144ac7763469ab5 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 11:37:54 +0800 Subject: [PATCH 51/55] dp Change-Id: I0c3970bebec719d8f75fc7bb371f981219f3d348 --- .../authentication/auth_message_processor.cpp | 6 +- .../src/authentication/dm_auth_manager.cpp | 72 +++++++++---------- .../src/ipc/standard/ipc_cmd_parser.cpp | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index edca70baf..a27cacd02 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -174,7 +174,7 @@ void AuthMessageProcessor::CreatePublicKeyMessageExt(nlohmann::json &json) return; } else { nlohmann::json jsonTemp; - LOGI("temp003] TAG_PUBLICKEY %{public}s", authResponseContext_->publicKey.c_str()); + LOGI("rm003] TAG_PUBLICKEY %{public}s", authResponseContext_->publicKey.c_str()); jsonTemp[TAG_PUBLICKEY] = authResponseContext_->publicKey; std::string strTemp = SafetyDump(jsonTemp); std::string encryptStr = ""; @@ -703,7 +703,7 @@ void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) { std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); authResponseContext_->recheckData.isDataReceived = true; - LOGE("[temp003] isDataReceived = true"); + LOGE("[rm003] isDataReceived = true"); std::string encryptStr = ""; if (IsString(json, TAG_CRYPTIC_MSG)) { encryptStr = json[TAG_CRYPTIC_MSG].get(); @@ -748,7 +748,7 @@ void AuthMessageProcessor::ParseReqReCheckMessage(nlohmann::json &json) authResponseContext_->localBindLevel = jsonObject[TAG_BIND_LEVEL].get(); } - LOGE("[temp003] isDataParsed = true"); + LOGE("[rm003] isDataParsed = true"); authResponseContext_->recheckData.isDataParsed = true; authResponseContext_->recheckData.edition = authResponseContext_->edition; authResponseContext_->recheckData.localDeviceId = authResponseContext_->localDeviceId; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index d319e5a7b..83cfee6bc 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -638,13 +638,13 @@ void DmAuthManager::ProcessSourceMsg() if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { authRequestState_->TransitionTo(std::make_shared()); } else { - LOGE("[temp003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); + LOGE("[rm003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); } } else { if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_CREDENTIAL) { authRequestState_->TransitionTo(std::make_shared()); } else { - LOGE("[temp003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); + LOGE("[rm003] not in state, skip MSG_TYPE_RESP_PUBLICKEY"); } } break; @@ -656,7 +656,7 @@ void DmAuthManager::ProcessSourceMsg() authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_RECHECK_MSG) { RequestReCheckMsgDone(); } else { - LOGE("[temp003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); + LOGE("[rm003] not in state, skip MSG_TYPE_RESP_RECHECK_MSG"); } break; } @@ -735,11 +735,11 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me authResponseContext_->msgType == MSG_TYPE_REQ_RECHECK_MSG) { std::lock_guard guard(savedParseFailedRecheckMsgMutex_); if (!IsRecheckDataParsed()) { - LOGE("[temp003] parse failed, save RECHECK_MSG"); + LOGE("[rm003] parse failed, save RECHECK_MSG"); savedParseFailedRecheckMsg_ = message; return; } else { - LOGI("[temp003] savedParseFailedRecheckMsg_.clear"); + LOGI("[rm003] savedParseFailedRecheckMsg_.clear"); savedParseFailedRecheckMsg_.clear(); } } @@ -897,10 +897,10 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) { int32_t sessionId = 0; if (IsHmlSessionType()) { - LOGI("[temp003] EstablishAuthChannel, try OpenAuthSessionWithPara"); - LOGI("[temp003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); - LOGI("[temp003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); - LOGI("[temp003] hmlActionId %{public}d", authRequestContext_->hmlActionId); + LOGI("[rm003] EstablishAuthChannel, try OpenAuthSessionWithPara"); + LOGI("[rm003] hmlReleaseTime %{public}d", authRequestContext_->hmlReleaseTime); + LOGI("[rm003] hmlEnable160M %{public}d", authRequestContext_->hmlEnable160M); + LOGI("[rm003] hmlActionId %{public}d", authRequestContext_->hmlActionId); sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSessionWithPara(deviceId, authRequestContext_->hmlActionId, authRequestContext_->hmlEnable160M); } else { sessionId = softbusConnector_->GetSoftbusSession()->OpenAuthSession(deviceId); @@ -1773,9 +1773,9 @@ void DmAuthManager::ShowStartAuthDialog() return; } LOGI("DmAuthManager::ShowStartAuthDialog start"); - LOGI("[temp003] presetPinCode %{public}d", authRequestContext_->presetPinCode); + LOGI("[rm003] presetPinCode %{public}d", authRequestContext_->presetPinCode); if (authRequestContext_->presetPinCode > 0) { - LOGI("[temp003] already has pin code"); + LOGI("[rm003] already has pin code"); ProcessPincode(authRequestContext_->presetPinCode); } else { pincodeDialogEverShown_ = true; @@ -2170,7 +2170,7 @@ void DmAuthManager::RequestCredential() LOGI("DmAuthManager::RequestCredential start."); std::string publicKey = ""; GenerateCredential(publicKey); - LOGI("[temp003] RequestCredential pk %{public}s", publicKey.c_str()); + LOGI("[rm003] RequestCredential pk %{public}s", publicKey.c_str()); authResponseContext_->publicKey = publicKey; std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_REQ_PUBLICKEY); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -2214,7 +2214,7 @@ void DmAuthManager::RequestCredentialDone() int32_t DmAuthManager::ImportCredential(std::string &deviceId, std::string &publicKey) { LOGI("DmAuthManager::ImportCredential"); - LOGI("[temp003] ImportCredential, pk %{public}s", publicKey.c_str()); + LOGI("[rm003] ImportCredential, pk %{public}s", publicKey.c_str()); int32_t osAccountId = MultipleUserConnector::GetCurrentAccountUserID(); return hiChainAuthConnector_->ImportCredential(osAccountId, deviceId, publicKey); } @@ -2233,7 +2233,7 @@ void DmAuthManager::ResponseCredential() } std::string publicKey = ""; GenerateCredential(publicKey); - LOGI("temp003] ResponseCredential pk %{public}s", publicKey.c_str()); + LOGI("rm003] ResponseCredential pk %{public}s", publicKey.c_str()); if (ImportCredential(remoteDeviceId_, authResponseContext_->remotePublicKey) != DM_OK) { LOGE("ResponseCredential import credential failed."); authResponseState_->TransitionTo(std::make_shared()); @@ -2247,7 +2247,7 @@ void DmAuthManager::ResponseCredential() bool DmAuthManager::ResponseNewProcessCredential() { - LOGI("[temp003] ResponseNewProcessCredential, pk %{public}s", authResponseContext_->remotePublicKey.c_str()); + LOGI("[rm003] ResponseNewProcessCredential, pk %{public}s", authResponseContext_->remotePublicKey.c_str()); CHECK_NULL_RETURN(authResponseContext_, false); if (authResponseContext_->remotePublicKey == "") { LOGE("authResponseContext_->remotePublicKey is empty."); @@ -2273,7 +2273,7 @@ void DmAuthManager::ResponseNewSendCredential() CHECK_NULL_VOID(authResponseContext_); std::string publicKey = ""; GenerateCredential(publicKey); - LOGI("[temp003] ResponseNewSendCredential, pk %{public}s", publicKey.c_str()); + LOGI("[rm003] ResponseNewSendCredential, pk %{public}s", publicKey.c_str()); authResponseContext_->publicKey = publicKey; std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_PUBLICKEY); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); @@ -2303,7 +2303,7 @@ bool DmAuthManager::AuthDeviceTransmit(int64_t requestId, const uint8_t *data, u void DmAuthManager::SrcAuthDeviceFinish() { - LOGI("[temp003] SrcAuthDeviceFinish"); + LOGI("[rm003] SrcAuthDeviceFinish"); std::lock_guard guard(recheckPublicKeyProcessMutex_); CHECK_NULL_VOID(authRequestState_); authRequestState_->TransitionTo(std::make_shared()); @@ -2334,7 +2334,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); if (IsRecheckDataReceived()) { ParseSavedFailedRecheckMsg(); - LOGI("[temp003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); + LOGI("[rm003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); RequestReCheckMsgDone(); } } else { @@ -2358,7 +2358,7 @@ void DmAuthManager::SrcAuthDeviceFinish() authRequestState_->TransitionTo(std::make_shared()); if (IsRecheckDataReceived()) { ParseSavedFailedRecheckMsg(); - LOGI("[temp003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); + LOGI("[rm003] IsRecheckDataReceived true, call RequestReCheckMsgDone"); RequestReCheckMsgDone(); } } else { @@ -2371,7 +2371,7 @@ void DmAuthManager::SrcAuthDeviceFinish() void DmAuthManager::SinkAuthDeviceFinish() { LOGI("isNeedProcCachedSrcReqMsg %{public}d.", isNeedProcCachedSrcReqMsg_); - LOGI("[temp003] SinkAuthDeviceFinish"); + LOGI("[rm003] SinkAuthDeviceFinish"); std::lock_guard guard(recheckPublicKeyProcessMutex_); CHECK_NULL_VOID(authResponseState_); authResponseState_->TransitionTo(std::make_shared()); @@ -2384,11 +2384,11 @@ void DmAuthManager::SinkAuthDeviceFinish() softbusConnector_->HandleDeviceOnline(remoteDeviceId_, authForm_); } if (RemoteSupportRecheck()) { - LOGI("[temp003] SinkAuthDeviceFinish enter AuthResponseReCheckMsg"); + LOGI("[rm003] SinkAuthDeviceFinish enter AuthResponseReCheckMsg"); authResponseState_->TransitionTo(std::make_shared()); if (IsRecheckDataReceived()) { ParseSavedFailedRecheckMsg(); - LOGI("[temp003] IsRecheckDataReceived true, call ResponseReCheckMsgDone"); + LOGI("[rm003] IsRecheckDataReceived true, call ResponseReCheckMsgDone"); ResponseReCheckMsgDone(); } return; @@ -2742,7 +2742,7 @@ int32_t DmAuthManager::DeleteGroup(const std::string &pkgName, int32_t userId, c void DmAuthManager::PutAccessControlList() { - LOGI("[temp003] PutAccessControlList"); + LOGI("[rm003] PutAccessControlList"); char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); @@ -3121,7 +3121,7 @@ void DmAuthManager::RequestReCheckMsg() { LOGI("dmVersion %{public}s.", DM_VERSION_5_0_3); if (!CompareVersion(remoteVersion_, std::string(DM_VERSION_5_0_2))) { - LOGI("[temp003] remote version < 502, skip"); + LOGI("[rm003] remote version < 502, skip"); return; } @@ -3168,12 +3168,12 @@ void DmAuthManager::RequestReCheckMsgDone() { LOGI("remoteVersion %{public}s, authResponseContext_->edition %{public}s.", remoteVersion_.c_str(), authResponseContext_->edition.c_str()); - LOGI("[temp003] RequestReCheckMsgDone"); + LOGI("[rm003] RequestReCheckMsgDone"); CHECK_NULL_VOID(authResponseContext_); CHECK_NULL_VOID(authMessageProcessor_); CHECK_NULL_VOID(authRequestState_); if (IsRecheckDataVerified()) { - LOGI("[temp003] recheckData already verified, return"); + LOGI("[rm003] recheckData already verified, return"); return; } if (!IsSourceMsgValid()) { @@ -3190,11 +3190,11 @@ void DmAuthManager::RequestReCheckMsgDone() void DmAuthManager::ResponseReCheckMsgDone() { - LOGI("[temp003] ResponseReCheckMsgDone"); + LOGI("[rm003] ResponseReCheckMsgDone"); CHECK_NULL_VOID(authResponseContext_); CHECK_NULL_VOID(authMessageProcessor_); if (IsRecheckDataVerified()) { - LOGI("[temp003] recheckData already verified, return"); + LOGI("[rm003] recheckData already verified, return"); return; } if (!IsSinkMsgValid()) { @@ -3214,7 +3214,7 @@ void DmAuthManager::ResponseReCheckMsgDone() bool DmAuthManager::IsSinkMsgValid() { - LOGI("[temp003] IsSinkMsgValid"); + LOGI("[rm003] IsSinkMsgValid"); std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); CHECK_NULL_RETURN(authResponseContext_, false); authResponseContext_->recheckData.isDataVerified = true; @@ -3230,7 +3230,7 @@ bool DmAuthManager::IsSinkMsgValid() bool DmAuthManager::IsSourceMsgValid() { - LOGI("[temp003] IsSourceMsgValid"); + LOGI("[rm003] IsSourceMsgValid"); std::lock_guard guard(authResponseContext_->recheckData.recheckDataMutex); CHECK_NULL_RETURN(authResponseContext_, false); CHECK_NULL_RETURN(authRequestContext_, false); @@ -3264,14 +3264,14 @@ void DmAuthManager::ProcessReqPublicKey() if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { ResponseNewProcessCredential(); } else { - LOGE("[temp003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); + LOGE("[rm003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); } } else { if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_AUTH_FINISH || authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_RECHECK_MSG) { authResponseState_->TransitionTo(std::make_shared()); } else { - LOGE("[temp003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); + LOGE("[rm003] not in state, skip MSG_TYPE_REQ_PUBLICKEY"); } } if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_SHOW) { @@ -3290,21 +3290,21 @@ bool DmAuthManager::RemoteSupportRecheck() bool DmAuthManager::IsRecheckDataReceived() { - LOGI("[temp003] IsRecheckDataReceived"); + LOGI("[rm003] IsRecheckDataReceived"); CHECK_NULL_RETURN(authResponseContext_, false); return authResponseContext_->recheckData.isDataReceived; } bool DmAuthManager::IsRecheckDataParsed() { - LOGI("[temp003] IsRecheckDataParsed"); + LOGI("[rm003] IsRecheckDataParsed"); CHECK_NULL_RETURN(authResponseContext_, false); return authResponseContext_->recheckData.isDataParsed; } bool DmAuthManager::IsRecheckDataVerified() { - LOGI("[temp003] IsRecheckDataVerified"); + LOGI("[rm003] IsRecheckDataVerified"); CHECK_NULL_RETURN(authResponseContext_, false); return authResponseContext_->recheckData.isDataVerified; } @@ -3315,7 +3315,7 @@ void DmAuthManager::ParseSavedFailedRecheckMsg() if (savedParseFailedRecheckMsg_.empty()) { return; } - LOGI("[temp003] process savedParseFailedRecheckMsg_"); + LOGI("[rm003] process savedParseFailedRecheckMsg_"); CHECK_NULL_VOID(authResponseContext_); CHECK_NULL_VOID(authMessageProcessor_); authMessageProcessor_->SetResponseContext(authResponseContext_); diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 7176035e5..7753a3ced 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -877,7 +877,7 @@ ON_IPC_CMD(BIND_DEVICE, MessageParcel &data, MessageParcel &reply) std::string bindParam = data.ReadString(); std::string deviceId = data.ReadString(); int32_t bindType = data.ReadInt32(); - LOGE("[temp003] bindParam %{public}s", bindParam.c_str()); + LOGE("[rm003] bindParam %{public}s", bindParam.c_str()); int32_t result = DM_OK; result = DeviceManagerService::GetInstance().BindDevice(pkgName, bindType, deviceId, bindParam); if (!reply.WriteInt32(result)) { -- Gitee From 7bac388aca8f1e2e5b926ec95e7abef76086b270 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 12:27:12 +0800 Subject: [PATCH 52/55] hwdp-fix-open Change-Id: I6263ccc31ae60f2678d7ef79a565d0ba9b4aced8 --- .../service/src/device_manager_service.cpp | 1 - test/unittest/UTTest_device_manager_impl.cpp | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 00c1cbf5c..685b8045e 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1637,7 +1637,6 @@ int32_t DeviceManagerService::GetCallerServiceInfos(std::vector & if (result == DM_OK) { InitServiceInfos(profiles, serviceInfos); } - InitServiceInfos(profiles, serviceInfos); return result; } diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index d0eda8bc8..5d84fe624 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2617,6 +2617,45 @@ HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_101, testing::ext::TestSize.Leve DeviceManager::GetInstance().UnInitDeviceManager(packName); } +HWTEST_F(DeviceManagerImplTest, REG_SERVICEINFO_102, testing::ext::TestSize.Level0) +{ + std::string packName = "com.ohos.test"; + std::shared_ptr callback = std::make_shared(); + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback); + ASSERT_EQ(ret, DM_OK); + + std::vector infos; + ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); + for (const auto &item : infos) { + DeviceManager::GetInstance().UnRegisterServiceInfo(item); + } + infos.clear(); + + DMServiceInfo serviceInfo1; + InitServiceInfo(serviceInfo1); + ret = DeviceManager::GetInstance().GenerateServiceId(serviceInfo1.serviceId); + ASSERT_EQ(ret, DM_OK); + ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo1); + ASSERT_EQ(ret, DM_OK); + + DMServiceInfo serviceInfo2; + InitServiceInfo(serviceInfo2); + ret = DeviceManager::GetInstance().GenerateServiceId(serviceInfo2.serviceId); + ASSERT_EQ(ret, DM_OK); + ret = DeviceManager::GetInstance().RegisterServiceInfo(serviceInfo2); + ASSERT_EQ(ret, DM_OK); + + ret = DeviceManager::GetInstance().GetCallerServiceInfos(infos); + ASSERT_EQ(ret, DM_OK); + ASSERT_TRUE(infos.size() >= 2); + for (const auto &item : infos) { + LOGI("[rm003] UnRegisterServiceInfo, serviceId %{public}" PRId64, item.serviceId); + DeviceManager::GetInstance().UnRegisterServiceInfo(item); + } + infos.clear(); + DeviceManager::GetInstance().UnInitDeviceManager(packName); +} + } // namespace } // namespace DistributedHardware } // namespace OHOS -- Gitee From f19069b9969edf4638da711cd2a553980fecb5a9 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 12:37:05 +0800 Subject: [PATCH 53/55] fix Change-Id: I1f71874442ccfcff4c310c8c093a847279ec50e1 --- services/implementation/src/authentication/dm_auth_manager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 83cfee6bc..0033b9e4f 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -2323,7 +2323,6 @@ void DmAuthManager::SrcAuthDeviceFinish() ConverToFinish(); return; } - if (authResponseContext_->isOnline && !authResponseContext_->haveCredential) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); if (!authResponseContext_->isIdenticalAccount && !authResponseContext_->hostPkgName.empty()) { -- Gitee From 237ecc40228df6268c9b50d4c5f75ee880a60c18 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 13:08:07 +0800 Subject: [PATCH 54/55] fix Change-Id: I0a0b00c0e38a7ad351f8074ac390112ef8d41888 --- .../service/src/device_manager_service.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 685b8045e..f306f63ce 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1503,7 +1503,11 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn if (ret != DM_OK) { LOGE("[rm003] GetLocalDeviceInfo failed"); } - profile.SetDeviceId(devInfo.deviceId); + char localDeviceId[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); + char udidHash[DM_MAX_DEVICE_ID_LEN] = {0}; + Crypto::GetUdidHash(localDeviceId, reinterpret_cast(udidHash)); + key.SetDeviceId(std::string(udidHash)); profile.SetNetworkId(devInfo.networkId); profile.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); @@ -1555,13 +1559,11 @@ void DeviceManagerService::InitServiceInfos(const std::vector(udidHash)); + key.SetDeviceId(std::string(udidHash)); key.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); key.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); return true; -- Gitee From 0b589e565569f77e3d9b5679220fbbd3ef50675b Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Sat, 25 Jan 2025 13:09:47 +0800 Subject: [PATCH 55/55] fix Change-Id: Idf8344e5b3a67b22547e0a74be2366888eeee9af --- services/service/src/device_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index f306f63ce..ce5507f8c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -1507,7 +1507,7 @@ void DeviceManagerService::InitServiceInfoProfile(const DMServiceInfo &serviceIn GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); char udidHash[DM_MAX_DEVICE_ID_LEN] = {0}; Crypto::GetUdidHash(localDeviceId, reinterpret_cast(udidHash)); - key.SetDeviceId(std::string(udidHash)); + profile.SetDeviceId(std::string(udidHash)); profile.SetNetworkId(devInfo.networkId); profile.SetUserId(MultipleUserConnector::GetFirstForegroundUserId()); profile.SetTokenId(std::to_string(IPCSkeleton::GetCallingTokenID())); -- Gitee