diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index 87fd37a49462a65baf4609c41adcfe6b40cc0339..418684851ef4e18d1ffd2b47eeff7818525a521e 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 42aac4ed71cbc01f7c487d73137aab519696c4f1..0b2bfebaeeaaacfb6e73813b8ddab509eb866af2 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 a2e7cb3e1d9bf52842b98f1cce37635edd855e0d..a30e5493b2b6ea81ff6113a7f7f820ed819f662a 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 d082452f7e2329f872f213d6e3f7dbf81b719fd6..68322931382288cd694ee92aad1ea6f4acb171f7 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 48ce215ea185a650a5ada4434a39216e0d8a59c8..611c2f806ee2aaf180eadc55d791e67c33bf0012 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 9a70e70779b6cec36ce7779fdd7b5a8e3a145876..7e757fea1ffbbd3fc9e90f29c23214245541802e 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);