From 155b8153784c149b9ba6a12eaecb4ab27e3d5fc2 Mon Sep 17 00:00:00 2001 From: wangbaidong Date: Mon, 30 Jun 2025 20:32:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGetLocalDeviceName=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangbaidong --- .../device_manager_ipc_interface_code.h | 1 + .../native_cpp/src/device_manager_impl.cpp | 16 ++++--- .../src/ipc/standard/ipc_cmd_parser.cpp | 16 +++++++ .../service/include/device_manager_service.h | 2 +- .../service/src/device_manager_service.cpp | 45 ++++++++++++------- .../src/ipc/standard/ipc_cmd_parser.cpp | 15 +++++++ 6 files changed, 72 insertions(+), 23 deletions(-) diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 87fd37a49..418684851 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -117,6 +117,7 @@ enum DMIpcCmdInterfaceCode { GET_DEVICE_NETWORK_ID_LIST, UNREGISTER_PIN_HOLDER_CALLBACK, GET_LOCAL_DEVICE_NAME, + GET_LOCAL_DEVICE_NAME_OLD, CHECK_SRC_ACCESS_CONTROL, CHECK_SINK_ACCESS_CONTROL, CHECK_SRC_SAME_ACCOUNT, 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 42aac4ed7..0b2bfebae 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -1442,16 +1442,20 @@ int32_t DeviceManagerImpl::GetLocalDeviceId(const std::string &pkgName, std::str int32_t DeviceManagerImpl::GetLocalDeviceName(const std::string &pkgName, std::string &deviceName) { LOGI("Start, pkgName: %{public}s", pkgName.c_str()); - DmDeviceInfo info; - int32_t ret = GetLocalDeviceInfo(pkgName, info); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + int32_t ret = ipcClientProxy_->SendRequest(GET_LOCAL_DEVICE_NAME_OLD, req, rsp); if (ret != DM_OK) { - DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceName", info, ret, anonyLocalUdid_); - LOGI("DeviceManagerImpl::GetLocalDeviceNetWorkId failed."); + LOGE("Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("Get local device name failed ret: %{public}d", ret); return ret; } - deviceName = std::string(info.deviceName); + deviceName = rsp->GetLocalDeviceName(); LOGI("End, deviceName : %{public}s", GetAnonyString(deviceName).c_str()); - DmRadarHelper::GetInstance().ReportGetLocalDevInfo(pkgName, "GetLocalDeviceName", info, DM_OK, anonyLocalUdid_); 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 a2e7cb3e1..a30e5493b 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 @@ -2162,6 +2162,22 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_NAME, MessageParcel &reply, std::shared_pt return DM_OK; } +ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_NAME_OLD, std::shared_ptr pBaseReq, MessageParcel &data) +{ + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_NAME_OLD, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + pRsp->SetErrCode(reply.ReadInt32()); + pRsp->SetLocalDeviceName(reply.ReadString()); + return DM_OK; +} + ON_IPC_SET_REQUEST(CHECK_SRC_ACCESS_CONTROL, std::shared_ptr pBaseReq, MessageParcel &data) { return SetRequest(CHECK_SRC_ACCESS_CONTROL, pBaseReq, data); diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index d082452f7..683229313 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -264,6 +264,7 @@ public: void ProcessCommonUserStatusEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid); int32_t GetLocalDeviceName(std::string &deviceName); + int32_t GetLocalDeviceNameOld(std::string &deviceName); bool CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const DmAccessCallee &callee); @@ -418,7 +419,6 @@ private: void HandleNetworkConnected(int32_t networkStatus); void NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId); - void CheckPermission(bool &isOnlyShowNetworkId); #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) && !defined(DEVICE_MANAGER_COMMON_FLAG) bool IsCallerInWhiteList(); bool IsDMAdapterCheckApiWhiteListLoaded(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 48ce215ea..611c2f806 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -470,7 +470,10 @@ int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) { LOGD("Begin."); bool isOnlyShowNetworkId = false; - CheckPermission(isOnlyShowNetworkId); + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call GetLocalDeviceInfo."); + isOnlyShowNetworkId = true; + } CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); int32_t ret = softbusListener_->GetLocalDeviceInfo(info); if (ret != DM_OK) { @@ -515,21 +518,6 @@ int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) return DM_OK; } -void DeviceManagerService::CheckPermission(bool &isOnlyShowNetworkId) -{ -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) && !defined(DEVICE_MANAGER_COMMON_FLAG) - if (!PermissionManager::GetInstance().CheckNewPermission() && !IsCallerInWhiteList()) { - LOGE("The caller does not have permission to call GetLocalDeviceInfo."); - isOnlyShowNetworkId = true; - } -#else - if (!PermissionManager::GetInstance().CheckNewPermission()) { - LOGE("The caller does not have permission to call GetLocalDeviceInfo."); - isOnlyShowNetworkId = true; - } -#endif -} - #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) && !defined(DEVICE_MANAGER_COMMON_FLAG) bool DeviceManagerService::IsCallerInWhiteList() { @@ -580,6 +568,31 @@ bool DeviceManagerService::IsDMAdapterCheckApiWhiteListLoaded() } #endif +int32_t DeviceManagerService::GetLocalDeviceNameOld(std::string &deviceName) +{ + LOGD("Begin."); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) && !defined(DEVICE_MANAGER_COMMON_FLAG) + if (!PermissionManager::GetInstance().CheckNewPermission() && !IsCallerInWhiteList()) { + LOGE("The caller does not have permission to call GetLocalDeviceName."); + return ERR_DM_NO_PERMISSION; + } +#else + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call GetLocalDeviceName."); + return ERR_DM_NO_PERMISSION; + } +#endif + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); + DmDeviceInfo info; + int32_t ret = softbusListener_->GetLocalDeviceInfo(info); + if (ret != DM_OK) { + LOGE("GetLocalDeviceInfo failed"); + return ret; + } + deviceName = info.deviceName; + return DM_OK; +} + int32_t DeviceManagerService::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) { diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 9a70e7077..7e757fea1 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1974,6 +1974,21 @@ ON_IPC_CMD(GET_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply) return DM_OK; } +ON_IPC_CMD(GET_LOCAL_DEVICE_NAME_OLD, MessageParcel &data, MessageParcel &reply) +{ + std::string deviceName = ""; + int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceNameOld(deviceName); + if (!reply.WriteInt32(result)) { + LOGE("write result failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!reply.WriteString(deviceName)) { + LOGE("write deviceName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + ON_IPC_CMD(CHECK_SRC_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply) { return OnIpcCmd(CHECK_SRC_ACCESS_CONTROL, data, reply); -- Gitee