From 8f11cdc5034565424605f079d964a9d7cf18afc9 Mon Sep 17 00:00:00 2001 From: q30043944 Date: Mon, 10 Feb 2025 11:55:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30043944 --- .../native_cpp/src/device_manager_impl.cpp | 10 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 15 +- .../src/cryptomgr/crypto_mgr.cpp | 2 +- .../dependency/softbus/softbus_connector.cpp | 12 +- .../devicestate/dm_device_state_manager.cpp | 8 +- .../src/device_manager_service_listener.cpp | 10 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 193 ++++-------------- .../service/src/softbus/softbus_listener.cpp | 16 +- .../softbuscache/src/dm_softbus_cache.cpp | 10 +- .../UTTest_device_manager_service.cpp | 6 +- .../UTTest_device_manager_service_two.cpp | 6 +- 11 files changed, 88 insertions(+), 200 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 5ec3166ea..1a6241d84 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -197,23 +197,23 @@ void DeviceManagerImpl::ConvertDeviceInfoToDeviceBasicInfo(const DmDeviceInfo &i } if (memcpy_s(deviceBasicInfo.deviceName, sizeof(deviceBasicInfo.deviceName), info.deviceName, - std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } if (memcpy_s(deviceBasicInfo.networkId, sizeof(deviceBasicInfo.networkId), info.networkId, - std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return; } - + if (memcpy_s(deviceBasicInfo.deviceId, sizeof(deviceBasicInfo.deviceId), info.deviceId, - std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } - + deviceBasicInfo.deviceTypeId = info.deviceTypeId; } 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 71606ae4d..db851e355 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 @@ -971,10 +971,7 @@ ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); - if (pRsp == nullptr) { - LOGE("IpcExportAuthCodeRsp pRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pRsp, ERR_DM_FAILED); std::string authCode = reply.ReadString(); pRsp->SetAuthCode(authCode); pRsp->SetErrCode(reply.ReadInt32()); @@ -1467,10 +1464,7 @@ ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is nullptr"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); if (!data.WriteInt32(pReq->GetPermissionLevel())) { LOGE("write permissionLevel failed"); @@ -1481,10 +1475,7 @@ ON_IPC_SET_REQUEST(CHECK_API_PERMISSION, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is nullptr"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/services/implementation/src/cryptomgr/crypto_mgr.cpp b/services/implementation/src/cryptomgr/crypto_mgr.cpp index 8e4e82b95..441e9e606 100644 --- a/services/implementation/src/cryptomgr/crypto_mgr.cpp +++ b/services/implementation/src/cryptomgr/crypto_mgr.cpp @@ -148,7 +148,7 @@ int32_t CryptoMgr::MbedAesGcmEncrypt(const AesGcmCipherKey *cipherKey, const uns } if (memcpy_s(cipherText + GCM_IV_LEN + plainTextSize, cipherTextLen - GCM_IV_LEN - plainTextSize, tagBuf, - TAG_LEN) != 0) { + TAG_LEN) != 0) { mbedtls_gcm_free(&aesContext); return ERR_DM_CRYPTO_OPT_FAILED; } diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index cf4eeb5d3..d6debe90f 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -197,13 +197,13 @@ void SoftbusConnector::ConvertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, } if (memcpy_s(dmDeviceInfo.deviceId, sizeof(dmDeviceInfo.deviceId), deviceInfo.devId, - std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), deviceInfo.devName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } @@ -220,13 +220,13 @@ void SoftbusConnector::ConvertDeviceInfoToDmDevice(const DeviceInfo &deviceInfo, } if (memcpy_s(dmDeviceBasicInfo.deviceId, sizeof(dmDeviceBasicInfo.deviceId), deviceInfo.devId, - std::min(sizeof(dmDeviceBasicInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { + std::min(sizeof(dmDeviceBasicInfo.deviceId), sizeof(deviceInfo.devId))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceBasicInfo.deviceName, sizeof(dmDeviceBasicInfo.deviceName), deviceInfo.devName, - std::min(sizeof(dmDeviceBasicInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { + std::min(sizeof(dmDeviceBasicInfo.deviceName), sizeof(deviceInfo.devName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } @@ -485,13 +485,13 @@ void SoftbusConnector::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeB } if (memcpy_s(dmDeviceInfo.networkId, sizeof(dmDeviceInfo.networkId), nodeBasicInfo.networkId, - std::min(sizeof(dmDeviceInfo.networkId), sizeof(nodeBasicInfo.networkId))) != EOK) { + std::min(sizeof(dmDeviceInfo.networkId), sizeof(nodeBasicInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } if (memcpy_s(dmDeviceInfo.deviceName, sizeof(dmDeviceInfo.deviceName), nodeBasicInfo.deviceName, - std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != EOK) { + std::min(sizeof(dmDeviceInfo.deviceName), sizeof(nodeBasicInfo.deviceName))) != EOK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } diff --git a/services/implementation/src/devicestate/dm_device_state_manager.cpp b/services/implementation/src/devicestate/dm_device_state_manager.cpp index dad3d24d4..2bd4099db 100644 --- a/services/implementation/src/devicestate/dm_device_state_manager.cpp +++ b/services/implementation/src/devicestate/dm_device_state_manager.cpp @@ -418,12 +418,12 @@ void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info) for (auto iter : remoteDeviceInfos_) { if (std::string(iter.second.deviceId) == std::string(info.deviceId)) { if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName, - sizeof(info.deviceName)) != DM_OK) { + sizeof(info.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo remoteDeviceInfos copy deviceName failed"); return; } if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId, - sizeof(info.networkId)) != DM_OK) { + sizeof(info.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo remoteDeviceInfos copy networkId failed"); return; } @@ -435,12 +435,12 @@ void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info) for (auto iter : stateDeviceInfos_) { if (std::string(iter.second.deviceId) == std::string(info.deviceId)) { if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName, - sizeof(info.deviceName)) != DM_OK) { + sizeof(info.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo stateDeviceInfos copy deviceName failed"); return; } if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId, - sizeof(info.networkId)) != DM_OK) { + sizeof(info.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo stateDeviceInfos copy networkId failed"); return; } diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 97a788511..887a7d163 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -65,19 +65,19 @@ void DeviceManagerServiceListener::ConvertDeviceInfoToDeviceBasicInfo(const std: } if (memcpy_s(deviceBasicInfo.deviceName, sizeof(deviceBasicInfo.deviceName), info.deviceName, - std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceName), sizeof(info.deviceName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice copy deviceName data failed."); return; } if (memcpy_s(deviceBasicInfo.networkId, sizeof(deviceBasicInfo.networkId), info.networkId, - std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.networkId), sizeof(info.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return; } if (memcpy_s(deviceBasicInfo.deviceId, sizeof(deviceBasicInfo.deviceId), info.deviceId, - std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { + std::min(sizeof(deviceBasicInfo.deviceId), sizeof(info.deviceId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceId data failed."); return; } @@ -108,7 +108,7 @@ void DeviceManagerServiceListener::SetDeviceInfo(std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t deviceState = pReq->GetDeviceState(); @@ -158,20 +155,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -198,20 +189,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -233,19 +218,14 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); uint16_t subscribeId = pReq->GetSubscribeId(); @@ -267,19 +247,14 @@ ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, Mes ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t publishId = pReq->GetPublishId(); @@ -301,19 +276,14 @@ ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -346,20 +316,14 @@ ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } - + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string packagname = pReq->GetPkgName(); @@ -377,10 +341,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -769,9 +730,7 @@ ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t action = pReq->GetCredentialAction(); @@ -794,10 +753,7 @@ ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1062,9 +1018,7 @@ ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1097,19 +1051,14 @@ ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1142,19 +1091,14 @@ ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); PeerTargetId targetId = pReq->GetPeerTargetId(); @@ -1182,10 +1126,7 @@ ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1233,9 +1174,7 @@ ON_IPC_CMD(DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string deviceId = pReq->GetDeviceId(); @@ -1263,19 +1202,14 @@ ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t pinType = pReq->GetPinType(); @@ -1298,19 +1232,14 @@ ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t result = pReq->GetResult(); @@ -1328,19 +1257,14 @@ ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr pBas ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t result = pReq->GetResult(); @@ -1358,10 +1282,7 @@ ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr pBa ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1394,9 +1315,7 @@ ON_IPC_CMD(GET_SECURITY_LEVEL, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); int32_t pinHolderEvent = pReq->GetPinHolderEvent(); @@ -1424,10 +1343,7 @@ ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1521,9 +1437,7 @@ ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string udid = pReq->GetUdid(); @@ -1550,19 +1464,14 @@ ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(REMOTE_DEVICE_TRUST_CHANGE, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); @@ -1580,10 +1489,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr pB ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1637,9 +1543,7 @@ ON_IPC_CMD(GET_ANONY_LOCAL_UDID, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1668,10 +1572,7 @@ ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1727,9 +1628,7 @@ ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &rep ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1758,10 +1657,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } @@ -1801,9 +1697,7 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -1825,10 +1719,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr pBaseReq ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 3f7cf1343..295edf45b 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -747,13 +747,13 @@ int32_t SoftbusListener::ConvertScreenStatusToDmDevice(const NodeBasicInfo &node return ERR_DM_FAILED; } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -774,13 +774,13 @@ int32_t SoftbusListener::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nod return ERR_DM_FAILED; } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -800,13 +800,13 @@ int32_t SoftbusListener::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nod } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != EOK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } @@ -836,13 +836,13 @@ int32_t SoftbusListener::FillDeviceInfo(const DeviceInfo &device, DmDeviceInfo & } if (memcpy_s(dmDevice.deviceId, sizeof(dmDevice.deviceId), device.devId, - std::min(sizeof(dmDevice.deviceId), sizeof(device.devId))) != DM_OK) { + std::min(sizeof(dmDevice.deviceId), sizeof(device.devId))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice: copy device id failed."); return ERR_DM_FAILED; } if (memcpy_s(dmDevice.deviceName, sizeof(dmDevice.deviceName), device.devName, - std::min(sizeof(dmDevice.deviceName), sizeof(device.devName))) != DM_OK) { + std::min(sizeof(dmDevice.deviceName), sizeof(device.devName))) != DM_OK) { LOGE("ConvertDeviceInfoToDmDevice: copy device name failed."); return ERR_DM_FAILED; } diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index 574145824..35dd50a82 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -140,7 +140,7 @@ void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo) return; } if (memcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId), udidHash, - std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) { + std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) { LOGE("SaveDeviceInfo copy deviceId failed."); return; } @@ -178,12 +178,12 @@ void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo) std::lock_guard mutexLock(deviceInfosMutex_); if (deviceInfo_.find(udid) != deviceInfo_.end()) { if (memcpy_s(deviceInfo_[udid].second.deviceName, sizeof(deviceInfo_[udid].second.deviceName), - deviceInfo.deviceName, sizeof(deviceInfo.deviceName)) != DM_OK) { + deviceInfo.deviceName, sizeof(deviceInfo.deviceName)) != DM_OK) { LOGE("ChangeDeviceInfo deviceInfo copy deviceName failed"); return; } if (memcpy_s(deviceInfo_[udid].second.networkId, sizeof(deviceInfo_[udid].second.networkId), - deviceInfo.networkId, sizeof(deviceInfo.networkId)) != DM_OK) { + deviceInfo.networkId, sizeof(deviceInfo.networkId)) != DM_OK) { LOGE("ChangeDeviceInfo deviceInfo copy networkId failed"); return; } @@ -278,13 +278,13 @@ int32_t SoftbusCache::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeIn } if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId, - std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { + std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed."); return ERR_DM_FAILED; } if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName, - std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { + std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) { LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed."); return ERR_DM_FAILED; } diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 0eedc7414..5a5037b12 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1225,7 +1225,8 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_001, testing::ext::TestSize.Leve std::string pkgName = "com.ohos.test"; std::string deviceId = "1234"; EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(ERR_DM_FAILED)); - EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*softbusListenerMock_, GetUdidFromDp(_, _)).WillOnce(Return(ERR_DM_FAILED)); + DeviceManagerService::GetInstance().listener_ = std::make_shared(); int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -1261,7 +1262,8 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_005, testing::ext::TestSize.Leve std::string deviceId = "1234"; std::string extra = "extra"; EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(ERR_DM_FAILED)); - EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*softbusListenerMock_, GetUdidFromDp(_, _)).WillOnce(Return(ERR_DM_FAILED)); + DeviceManagerService::GetInstance().listener_ = std::make_shared(); int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); EXPECT_EQ(ret, ERR_DM_FAILED); } diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 99d210ac2..0756a7975 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -518,6 +518,7 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_201, testing::ext::TestSize.Leve EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceManagerServiceImplMock_, GetBindLevel(_, _, _, _)).WillOnce(Return(0)); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -529,6 +530,7 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_202, testing::ext::TestSize.Leve EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceManagerServiceImplMock_, GetBindLevel(_, _, _, _)).WillOnce(Return(0)); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); int32_t ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -956,7 +958,8 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_204, testing::ext::TestSize.Leve udidHash = "udidHash"; EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_CALL(*softbusListenerMock_, GetUdidFromDp(_, _)).WillOnce(Return(ERR_DM_FAILED)); + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); ret = DeviceManagerService::GetInstance().UnBindDevice(pkgName, udidHash, extra); EXPECT_EQ(ret, ERR_DM_FAILED); @@ -986,6 +989,7 @@ HWTEST_F(DeviceManagerServiceTest, UnBindDevice_205, testing::ext::TestSize.Leve std::string pkgName = "pkgName"; std::string udidHash = "udidHash"; std::string extra = "extra"; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); EXPECT_CALL(*kVAdapterManagerMock_, Get(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCacheMock_, GetUdidByUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*deviceManagerServiceImplMock_, GetBindLevel(_, _, _, _)).WillOnce(Return(1)); -- Gitee From 5d8531a256bd52bd124101541d3ce4b8e56110b0 Mon Sep 17 00:00:00 2001 From: q30043944 Date: Thu, 6 Mar 2025 22:01:59 +0800 Subject: [PATCH 2/2] delete 500ms Signed-off-by: q30043944 --- services/implementation/src/authentication/dm_auth_manager.cpp | 3 ++- .../src/dependency/softbus/softbus_connector.cpp | 1 + .../implementation/src/dependency/softbus/softbus_session.cpp | 3 ++- 3 files 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 1d284dab3..7ca10b921 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -543,6 +543,7 @@ void DmAuthManager::OnSessionOpened(int32_t sessionId, int32_t sessionSide, int3 void DmAuthManager::OnSessionClosed(const int32_t sessionId) { LOGI("DmAuthManager::OnSessionClosed sessionId = %{public}d", sessionId); + AuthenticateFinish(); } void DmAuthManager::ProcessSourceMsg() @@ -1348,7 +1349,7 @@ void DmAuthManager::SrcAuthenticateFinish() authResponseContext_->state == AuthState::AUTH_REQUEST_FINISH) && authPtr_ != nullptr) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); } - usleep(USLEEP_TIME_US_500000); // 500ms + int32_t sessionId = authRequestContext_->sessionId; auto taskFunc = [this, sessionId]() { CHECK_NULL_VOID(softbusConnector_); diff --git a/services/implementation/src/dependency/softbus/softbus_connector.cpp b/services/implementation/src/dependency/softbus/softbus_connector.cpp index d6debe90f..cc000c786 100644 --- a/services/implementation/src/dependency/softbus/softbus_connector.cpp +++ b/services/implementation/src/dependency/softbus/softbus_connector.cpp @@ -183,6 +183,7 @@ ConnectionAddr *SoftbusConnector::GetConnectAddr(const std::string &deviceId, st if (addr != nullptr) { jsonPara[BLE_MAC] = addr->info.ble.bleMac; connectAddr = SafetyDump(jsonPara); + addr->info.ble.priority = BLE_PRIORITY_HIGH; return addr; } LOGE("[SOFTBUS]failed to get ConnectionAddr for deviceId: %{public}s.", GetAnonyString(deviceId).c_str()); diff --git a/services/implementation/src/dependency/softbus/softbus_session.cpp b/services/implementation/src/dependency/softbus/softbus_session.cpp index 9e579ba80..fb1dad728 100644 --- a/services/implementation/src/dependency/softbus/softbus_session.cpp +++ b/services/implementation/src/dependency/softbus/softbus_session.cpp @@ -176,7 +176,8 @@ int SoftbusSession::OnSessionOpened(int sessionId, int result) void SoftbusSession::OnSessionClosed(int sessionId) { - LOGD("OnSessionClosed, sessionId: %{public}d.", sessionId); + LOGI("OnSessionClosed, sessionId: %{public}d.", sessionId); + sessionCallback_->OnSessionClosed(sessionId); } void SoftbusSession::OnBytesReceived(int sessionId, const void *data, unsigned int dataLen) -- Gitee