From 2e2f5f7e757845b9fb0351d01c038a0cb8c68ed5 Mon Sep 17 00:00:00 2001 From: yangwei_814916 Date: Sun, 9 Feb 2025 17:11:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E7=BB=91=E5=8F=AF=E4=BF=A1=E8=AE=BE?= =?UTF-8?q?=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangwei_814916 --- .../device_manager_ipc_interface_code.h | 1 + .../native_cpp/include/device_manager.h | 2 + .../native_cpp/include/device_manager_impl.h | 2 + .../native_cpp/src/device_manager_impl.cpp | 38 ++ .../src/ipc/standard/ipc_cmd_parser.cpp | 565 ++++-------------- .../service/include/device_manager_service.h | 2 + .../include/softbus/softbus_listener.h | 10 + .../service/src/device_manager_service.cpp | 28 +- .../src/ipc/standard/ipc_cmd_parser.cpp | 23 + .../service/src/softbus/softbus_listener.cpp | 99 +++ .../softbuscache/include/dm_softbus_cache.h | 1 + .../softbuscache/src/dm_softbus_cache.cpp | 15 + .../BUILD.gn | 2 + .../onsoftbusdeviceoffline_fuzzer/BUILD.gn | 2 + .../onsoftbusdeviceonline_fuzzer/BUILD.gn | 2 + .../BUILD.gn | 2 + .../publishsoftbuslnn_fuzzer/BUILD.gn | 2 + .../refreshsoftbuslnn_fuzzer/BUILD.gn | 2 + .../stoprefreshsoftbuslnn_fuzzer/BUILD.gn | 2 + 19 files changed, 346 insertions(+), 454 deletions(-) diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index ec42dc7a8..bc86a585c 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -108,6 +108,7 @@ enum DMIpcCmdInterfaceCode { SET_REMOTE_DEVICE_NAME_RESULT, SET_LOCAL_DEVICE_NAME, SET_LOCAL_DEVICE_NAME_RESULT, + GET_ALL_TRUST_DEVICE_LIST, // Add ipc msg here IPC_MSG_BUTT }; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 1723de345..67aa98284 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -653,6 +653,8 @@ public: const std::vector &deviceProfileInfoList) = 0; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) = 0; + virtual int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList) = 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 ee2c5ca87..cd5956945 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -420,6 +420,8 @@ public: const std::vector &deviceProfileInfoList) override; virtual int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName) override; + virtual int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList) 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 fffca73c3..1e3131e4d 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2693,5 +2693,43 @@ int32_t DeviceManagerImpl::GetLocalDisplayDeviceName(const std::string &pkgName, LOGI("Completed"); return DM_OK; } + +int32_t DeviceManagerImpl::GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList) +{ + if (pkgName.empty()) { + DmRadarHelper::GetInstance().ReportGetTrustDeviceList( + pkgName, "GetAllTrustedDeviceList", deviceList, ERR_DM_INPUT_PARA_INVALID, anonyLocalUdid_); + LOGE("Invalid parameter, pkgName is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGD("Start, pkgName: %{public}s, extra: %{public}s", GetAnonyString(pkgName).c_str(), extra.c_str()); + + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetExtra(extra); + int32_t ret = ipcClientProxy_->SendRequest(GET_ALL_TRUST_DEVICE_LIST, req, rsp); + if (ret != DM_OK) { + DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", + deviceList, ret, anonyLocalUdid_); + LOGE("DeviceManagerImpl::GetAllTrustedDeviceList error, Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", + deviceList, ret, anonyLocalUdid_); + LOGE("GetAllTrustedDeviceList error, failed ret: %{public}d", ret); + return ret; + } + + deviceList = rsp->GetDeviceVec(); + LOGI("Completed, device size %{public}zu", deviceList.size()); + DmRadarHelper::GetInstance().ReportGetTrustDeviceList(pkgName, "GetAllTrustedDeviceList", + deviceList, DM_OK, anonyLocalUdid_); + 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 c4744e673..6d7058f4c 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 @@ -73,10 +73,7 @@ const int32_t DM_MAX_TRUST_DEVICE_NUM = 200; ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); sptr listener = pReq->GetListener(); @@ -93,20 +90,14 @@ ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBa ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, 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(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::string pkgName = pBaseReq->GetPkgName(); if (!data.WriteString(pkgName)) { LOGE("write papam failed"); @@ -117,20 +108,14 @@ ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr p ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, 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(GET_TRUST_DEVICE_LIST, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 extra = pReq->GetExtra(); @@ -152,10 +137,7 @@ ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); int32_t deviceNum = reply.ReadInt32(); if (deviceNum > 0 && deviceNum <= DM_MAX_TRUST_DEVICE_NUM) { @@ -173,10 +155,7 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt ON_IPC_SET_REQUEST(GET_DEVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string networkId = pReq->GetNetWorkId(); if (!data.WriteString(networkId)) { @@ -187,10 +166,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_INFO, std::shared_ptr pBaseReq, MessagePar ON_IPC_READ_RESPONSE(GET_DEVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo deviceInfo; IpcModelCodec::DecodeDmDeviceInfo(reply, deviceInfo); @@ -201,10 +177,7 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -215,10 +188,7 @@ ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo localDeviceInfo; IpcModelCodec::DecodeDmDeviceInfo(reply, localDeviceInfo); @@ -229,10 +199,7 @@ ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_pt ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 netWorkId = pReq->GetNetWorkId(); @@ -247,10 +214,7 @@ ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetUdid(reply.ReadString()); @@ -259,10 +223,7 @@ ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr< ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 netWorkId = pReq->GetNetWorkId(); @@ -277,10 +238,7 @@ ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetUuid(reply.ReadString()); @@ -289,10 +247,7 @@ ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr< ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); const DmPublishInfo dmPublishInfo = pReq->GetPublishInfo(); @@ -309,20 +264,14 @@ ON_IPC_SET_REQUEST(PUBLISH_DEVICE_DISCOVER, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(PUBLISH_DEVICE_DISCOVER, 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(UNPUBLISH_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -339,20 +288,14 @@ ON_IPC_SET_REQUEST(UNPUBLISH_DEVICE_DISCOVER, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(UNPUBLISH_DEVICE_DISCOVER, 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(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 extra = pReq->GetExtra(); @@ -381,20 +324,14 @@ ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, Messag ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, 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(UNAUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -412,20 +349,14 @@ ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE, 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_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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->GetOperation(); @@ -449,10 +380,7 @@ ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, 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; } @@ -582,10 +510,7 @@ ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 requestJsonStr = pReq->GetCredentialParam(); @@ -603,10 +528,7 @@ ON_IPC_SET_REQUEST(REQUEST_CREDENTIAL, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); if (pRsp->GetErrCode() == DM_OK) { @@ -618,10 +540,7 @@ ON_IPC_READ_RESPONSE(REQUEST_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 reqJsonStr = pReq->GetCredentialParam(); @@ -638,10 +557,7 @@ ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); if (pRsp->GetErrCode() == DM_OK) { @@ -653,10 +569,7 @@ ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 credentialInfo = pReq->GetCredentialParam(); @@ -673,10 +586,7 @@ ON_IPC_SET_REQUEST(IMPORT_CREDENTIAL, std::shared_ptr pBaseReq, MessageP ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::string outParaStr = reply.ReadString(); std::map outputResult; ParseMapFromJsonString(outParaStr, outputResult); @@ -695,10 +605,7 @@ ON_IPC_READ_RESPONSE(IMPORT_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 deleteInfo = pReq->GetCredentialParam(); @@ -716,10 +623,7 @@ ON_IPC_SET_REQUEST(DELETE_CREDENTIAL, std::shared_ptr pBaseReq, MessageP ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::string outParaStr = reply.ReadString(); std::map outputResult; ParseMapFromJsonString(outParaStr, outputResult); @@ -738,10 +642,7 @@ ON_IPC_READ_RESPONSE(DELETE_CREDENTIAL, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -755,20 +656,14 @@ ON_IPC_SET_REQUEST(REGISTER_CREDENTIAL_CALLBACK, std::shared_ptr pBaseRe ON_IPC_READ_RESPONSE(REGISTER_CREDENTIAL_CALLBACK, 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(UNREGISTER_CREDENTIAL_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -782,10 +677,7 @@ ON_IPC_SET_REQUEST(UNREGISTER_CREDENTIAL_CALLBACK, std::shared_ptr pBase ON_IPC_READ_RESPONSE(UNREGISTER_CREDENTIAL_CALLBACK, 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; } @@ -803,10 +695,7 @@ ON_IPC_CMD(SERVER_CREDENTIAL_RESULT, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(NOTIFY_EVENT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 eventId = pReq->GetEventId(); @@ -828,20 +717,14 @@ ON_IPC_SET_REQUEST(NOTIFY_EVENT, std::shared_ptr pBaseReq, MessageParcel ON_IPC_READ_RESPONSE(NOTIFY_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; } ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 netWorkId = pReq->GetNetworkId(); @@ -858,10 +741,7 @@ ON_IPC_SET_REQUEST(GET_ENCRYPTED_UUID_BY_NETWOEKID, std::shared_ptr pBas ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetUuid(reply.ReadString()); @@ -870,10 +750,7 @@ ON_IPC_READ_RESPONSE(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &reply, std: ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 uuid = pReq->GetUuid(); @@ -895,10 +772,7 @@ ON_IPC_SET_REQUEST(GENERATE_ENCRYPTED_UUID, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetUuid(reply.ReadString()); @@ -907,10 +781,7 @@ ON_IPC_READ_RESPONSE(GENERATE_ENCRYPTED_UUID, MessageParcel &reply, std::shared_ ON_IPC_SET_REQUEST(BIND_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 bindParam = pReq->GetBindParam(); @@ -938,20 +809,14 @@ ON_IPC_SET_REQUEST(BIND_DEVICE, std::shared_ptr pBaseReq, MessageParcel ON_IPC_READ_RESPONSE(BIND_DEVICE, 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_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -973,20 +838,14 @@ ON_IPC_SET_REQUEST(UNBIND_DEVICE, std::shared_ptr pBaseReq, MessageParce ON_IPC_READ_RESPONSE(UNBIND_DEVICE, 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(GET_NETWORKTYPE_BY_NETWORK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 netWorkId = pReq->GetNetWorkId(); @@ -1001,10 +860,7 @@ ON_IPC_SET_REQUEST(GET_NETWORKTYPE_BY_NETWORK, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetNetworkType(reply.ReadInt32()); @@ -1013,10 +869,7 @@ ON_IPC_READ_RESPONSE(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &reply, std::shar ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1027,20 +880,14 @@ ON_IPC_SET_REQUEST(REGISTER_UI_STATE_CALLBACK, std::shared_ptr pBaseReq, ON_IPC_READ_RESPONSE(REGISTER_UI_STATE_CALLBACK, 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(UNREGISTER_UI_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1051,20 +898,14 @@ ON_IPC_SET_REQUEST(UNREGISTER_UI_STATE_CALLBACK, std::shared_ptr pBaseRe ON_IPC_READ_RESPONSE(UNREGISTER_UI_STATE_CALLBACK, 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(IMPORT_AUTH_CODE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 authCode = pReq->GetAuthCode(); @@ -1079,10 +920,7 @@ ON_IPC_SET_REQUEST(IMPORT_AUTH_CODE, std::shared_ptr pBaseReq, MessagePa ON_IPC_READ_RESPONSE(IMPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -1096,10 +934,7 @@ ON_IPC_SET_REQUEST(EXPORT_AUTH_CODE, std::shared_ptr pBaseReq, MessagePa ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); if (pRsp == nullptr) { LOGE("IpcExportAuthCodeRsp pRsp is null"); @@ -1113,10 +948,7 @@ ON_IPC_READ_RESPONSE(EXPORT_AUTH_CODE, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 discParaStr = pReq->GetFirstParam(); @@ -1138,20 +970,14 @@ ON_IPC_SET_REQUEST(REGISTER_DISCOVERY_CALLBACK, std::shared_ptr pBaseReq ON_IPC_READ_RESPONSE(REGISTER_DISCOVERY_CALLBACK, 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(UNREGISTER_DISCOVERY_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 extraParaStr = pReq->GetFirstParam(); @@ -1168,20 +994,14 @@ ON_IPC_SET_REQUEST(UNREGISTER_DISCOVERY_CALLBACK, std::shared_ptr pBaseR ON_IPC_READ_RESPONSE(UNREGISTER_DISCOVERY_CALLBACK, 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(START_DISCOVERING, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 discParaStr = pReq->GetFirstParam(); @@ -1203,20 +1023,14 @@ ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr pBaseReq, MessageP ON_IPC_READ_RESPONSE(START_DISCOVERING, 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(STOP_DISCOVERING, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 discParaStr = pReq->GetFirstParam(); @@ -1233,20 +1047,14 @@ ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr pBaseReq, MessagePa ON_IPC_READ_RESPONSE(STOP_DISCOVERING, 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(START_ADVERTISING, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 adverParaStr = pReq->GetFirstParam(); @@ -1263,20 +1071,14 @@ ON_IPC_SET_REQUEST(START_ADVERTISING, std::shared_ptr pBaseReq, MessageP ON_IPC_READ_RESPONSE(START_ADVERTISING, 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(STOP_ADVERTISING, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 adverParaStr = pReq->GetFirstParam(); @@ -1293,20 +1095,14 @@ ON_IPC_SET_REQUEST(STOP_ADVERTISING, std::shared_ptr pBaseReq, MessagePa ON_IPC_READ_RESPONSE(STOP_ADVERTISING, 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(BIND_TARGET, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -1329,20 +1125,14 @@ ON_IPC_SET_REQUEST(BIND_TARGET, std::shared_ptr pBaseReq, MessageParcel ON_IPC_READ_RESPONSE(BIND_TARGET, 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, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -1365,10 +1155,7 @@ ON_IPC_SET_REQUEST(UNBIND_TARGET, std::shared_ptr pBaseReq, MessageParce ON_IPC_READ_RESPONSE(UNBIND_TARGET, 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; } @@ -1402,10 +1189,7 @@ ON_IPC_CMD(UNBIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1416,10 +1200,7 @@ ON_IPC_SET_REQUEST(REGISTER_PIN_HOLDER_CALLBACK, std::shared_ptr pBaseRe ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -1427,10 +1208,7 @@ ON_IPC_READ_RESPONSE(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &reply, std::sh ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -1454,10 +1232,7 @@ ON_IPC_SET_REQUEST(CREATE_PIN_HOLDER, std::shared_ptr pBaseReq, MessageP ON_IPC_READ_RESPONSE(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); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -1465,10 +1240,7 @@ ON_IPC_READ_RESPONSE(CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -1492,10 +1264,7 @@ ON_IPC_SET_REQUEST(DESTROY_PIN_HOLDER, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(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); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); return DM_OK; @@ -1503,10 +1272,7 @@ ON_IPC_READ_RESPONSE(DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 policy = pReq->GetFirstParam(); @@ -1523,20 +1289,14 @@ ON_IPC_SET_REQUEST(SET_DN_POLICY, std::shared_ptr pBaseReq, MessageParce ON_IPC_READ_RESPONSE(SET_DN_POLICY, 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(STOP_AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1548,10 +1308,7 @@ ON_IPC_SET_REQUEST(STOP_AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(STOP_AUTHENTICATE_DEVICE, 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; } @@ -1601,10 +1358,7 @@ ON_IPC_CMD(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &data, MessageParcel ON_IPC_SET_REQUEST(DP_ACL_ADD, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string udid = pReq->GetStr(); if (!data.WriteString(udid)) { @@ -1616,20 +1370,14 @@ ON_IPC_SET_REQUEST(DP_ACL_ADD, std::shared_ptr pBaseReq, MessageParcel & ON_IPC_READ_RESPONSE(DP_ACL_ADD, 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(GET_SECURITY_LEVEL, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 networkId = pReq->GetNetWorkId(); @@ -1644,10 +1392,7 @@ ON_IPC_SET_REQUEST(GET_SECURITY_LEVEL, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(GET_SECURITY_LEVEL, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetSecurityLevel(reply.ReadInt32()); @@ -1668,10 +1413,7 @@ ON_IPC_CMD(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &data, MessageParcel &reply ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string netWorkId = pReq->GetStr(); if (!data.WriteString(netWorkId)) { @@ -1683,10 +1425,7 @@ ON_IPC_SET_REQUEST(IS_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessagePar ON_IPC_READ_RESPONSE(IS_SAME_ACCOUNT, 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; } @@ -1717,10 +1456,7 @@ ON_IPC_READ_RESPONSE(CHECK_API_PERMISSION, MessageParcel &reply, std::shared_ptr ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); DmAccessCaller caller = pReq->GetAccessCaller(); DmAccessCallee callee = pReq->GetAccessCallee(); @@ -1737,20 +1473,14 @@ ON_IPC_SET_REQUEST(CHECK_ACCESS_CONTROL, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(CHECK_ACCESS_CONTROL, 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(CHECK_SAME_ACCOUNT, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED); std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); DmAccessCaller caller = pReq->GetAccessCaller(); DmAccessCallee callee = pReq->GetAccessCallee(); @@ -1767,20 +1497,14 @@ ON_IPC_SET_REQUEST(CHECK_SAME_ACCOUNT, std::shared_ptr pBaseReq, Message ON_IPC_READ_RESPONSE(CHECK_SAME_ACCOUNT, 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(SHIFT_LNN_GEAR, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1792,10 +1516,7 @@ ON_IPC_SET_REQUEST(SHIFT_LNN_GEAR, std::shared_ptr pBaseReq, MessageParc ON_IPC_READ_RESPONSE(SHIFT_LNN_GEAR, 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; } @@ -1824,10 +1545,7 @@ ON_IPC_CMD(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &data, MessageParcel ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 networkId = pReq->GetNetWorkId(); @@ -1842,10 +1560,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_SCREEN_STATUS, std::shared_ptr pBaseReq, M ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetScreenStatus(reply.ReadInt32()); @@ -1854,10 +1569,7 @@ ON_IPC_READ_RESPONSE(GET_DEVICE_SCREEN_STATUS, MessageParcel &reply, std::shared ON_IPC_SET_REQUEST(GET_ANONY_LOCAL_UDID, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1868,10 +1580,7 @@ ON_IPC_SET_REQUEST(GET_ANONY_LOCAL_UDID, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(GET_ANONY_LOCAL_UDID, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetAnonyUdid(reply.ReadString()); @@ -1880,10 +1589,7 @@ ON_IPC_READ_RESPONSE(GET_ANONY_LOCAL_UDID, MessageParcel &reply, std::shared_ptr ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -1898,10 +1604,7 @@ ON_IPC_SET_REQUEST(GET_NETWORKID_BY_UDID, std::shared_ptr pBaseReq, Mess ON_IPC_READ_RESPONSE(GET_NETWORKID_BY_UDID, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); pRsp->SetNetWorkId(reply.ReadString()); @@ -1936,10 +1639,7 @@ ON_IPC_CMD(SINK_BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply) ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1950,20 +1650,14 @@ ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK, std::shared_ptr pBaseReq ON_IPC_READ_RESPONSE(REGISTER_DEV_STATE_CALLBACK, 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(SYNC_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -1979,19 +1673,13 @@ ON_IPC_SET_REQUEST(SYNC_CALLBACK, std::shared_ptr pBaseReq, MessageParce ON_IPC_READ_RESPONSE(SYNC_CALLBACK, 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(REG_AUTHENTICATION_TYPE, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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 authTypeStr = pReq->GetFirstParam(); @@ -2008,20 +1696,14 @@ ON_IPC_SET_REQUEST(REG_AUTHENTICATION_TYPE, std::shared_ptr pBaseReq, Me ON_IPC_READ_RESPONSE(REG_AUTHENTICATION_TYPE, 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(GET_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -2038,10 +1720,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseRe ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST, 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; } @@ -2067,10 +1746,7 @@ ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &data, MessageParc ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); if (!data.WriteString(pkgName)) { @@ -2086,10 +1762,7 @@ ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO, std::shared_ptr pBaseReq, Messa ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO, 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; } @@ -2107,10 +1780,7 @@ ON_IPC_CMD(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &data, MessageParcel &repl ON_IPC_SET_REQUEST(PUT_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -2134,20 +1804,14 @@ ON_IPC_SET_REQUEST(PUT_DEVICE_PROFILE_INFO_LIST, std::shared_ptr pBaseRe ON_IPC_READ_RESPONSE(PUT_DEVICE_PROFILE_INFO_LIST, 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(GET_LOCAL_DISPLAY_DEVICE_NAME, std::shared_ptr pBaseReq, MessageParcel &data) { - if (pBaseReq == nullptr) { - LOGE("pBaseReq is null"); - 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(); @@ -2164,10 +1828,7 @@ ON_IPC_SET_REQUEST(GET_LOCAL_DISPLAY_DEVICE_NAME, std::shared_ptr pBaseR ON_IPC_READ_RESPONSE(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &reply, std::shared_ptr pBaseRsp) { - if (pBaseRsp == nullptr) { - LOGE("pBaseRsp is null"); - return ERR_DM_FAILED; - } + CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED); std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); pRsp->SetErrCode(reply.ReadInt32()); diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 85b19822d..b88e09eaa 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -221,6 +221,8 @@ public: std::vector &deviceProfileInfoList); int32_t GetLocalDisplayDeviceName(const std::string &pkgName, int32_t maxNameLength, std::string &displayName); std::vector GetDeviceNamePrefixs(); + int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList); private: bool IsDMServiceImplReady(); diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index 23317352e..b8c8aa4b1 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -35,6 +35,9 @@ #include "session.h" #include "socket.h" #include "dm_anonymous.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "access_control_profile.h" +#endif namespace OHOS { namespace DistributedHardware { @@ -107,10 +110,17 @@ public: int32_t SetForegroundUserIdsToDSoftBus(const std::string &remoteUserId, const std::vector &userIds); void DeleteCacheDeviceInfo(); int32_t SetLocalDisplayName(const std::string &displayName); + static int32_t GetDeviceNameByUdid(const std::string &udid, std::string &deviceName); + int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList); + int32_t GetUdidFromDp(const std::string &udidHash, std::string &udid); private: static int32_t FillDeviceInfo(const DeviceInfo &device, DmDeviceInfo &dmDevice); static void ParseConnAddrInfo(const ConnectionAddr *addrInfo, nlohmann::json &jsonObj); int32_t InitSoftPublishLNN(); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + void ConvertAclToDeviceInfo(DistributedDeviceProfile::AccessControlProfile &profile, DmDeviceInfo &dmDevice); +#endif private: static std::string hostName_; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index fcf1de692..e702865ae 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -638,8 +638,9 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std realDeviceId = udidHashTemp; } #endif + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); std::string udid = ""; - if (SoftbusCache::GetInstance().GetUdidByUdidHash(realDeviceId, udid) != DM_OK) { + if (softbusListener_->GetUdidFromDp(realDeviceId, udid) != DM_OK) { LOGE("Get udid by udidhash failed."); return ERR_DM_FAILED; } @@ -687,8 +688,9 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std realDeviceId = udidHashTemp; } #endif + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); std::string udid = ""; - if (SoftbusCache::GetInstance().GetUdidByUdidHash(realDeviceId, udid) != DM_OK) { + if (softbusListener_->GetUdidFromDp(realDeviceId, udid) != DM_OK) { LOGE("Get udid by udidhash failed."); return ERR_DM_FAILED; } @@ -2650,5 +2652,27 @@ std::vector DeviceManagerService::GetDeviceNamePrefixs() } return dmServiceImplExtResident_->GetDeviceNamePrefixs(); } + +int32_t DeviceManagerService::GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList) +{ + (void)extra; + LOGI("Begin for pkgName = %{public}s.", pkgName.c_str()); + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName or extra is empty."); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller: %{public}s does not have permission to call GetAllTrustedDeviceList.", pkgName.c_str()); + return ERR_DM_NO_PERMISSION; + } + CHECK_NULL_RETURN(softbusListener_, ERR_DM_POINT_NULL); + int32_t ret = softbusListener_->GetAllTrustedDeviceList(pkgName, extra, deviceList); + if (ret != DM_OK) { + LOGE("GetAllTrustedDeviceList failed"); + return ret; + } + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 8061a40ee..28fec5416 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1826,5 +1826,28 @@ ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &re } return DM_OK; } + +ON_IPC_CMD(GET_ALL_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string extra = data.ReadString(); + std::vector deviceList; + int32_t result = DeviceManagerService::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); + if (!reply.WriteInt32((int32_t)deviceList.size())) { + LOGE("write device list size failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + for (const auto &devInfo : deviceList) { + if (!EncodeDmDeviceInfo(devInfo, reply)) { + LOGE("write dm device info failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + } + 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 diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 49c5d981c..6da2f1b7a 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -32,6 +32,7 @@ #include "dm_transport_msg.h" #include "ffrt.h" #endif +#include "ipc_skeleton.h" #include "parameter.h" #include "system_ability_definition.h" @@ -1185,5 +1186,103 @@ int32_t SoftbusListener::SetLocalDisplayName(const std::string &displayName) } return DM_OK; } + +int32_t SoftbusListener::GetDeviceNameByUdid(const std::string &udid, std::string &deviceName) +{ + return SoftbusCache::GetInstance().GetDeviceNameFromCache(udid, deviceName); +} + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +void SoftbusListener::ConvertAclToDeviceInfo(DistributedDeviceProfile::AccessControlProfile &profile, + DmDeviceInfo &deviceInfo) +{ + char udidHash[DM_MAX_DEVICE_ID_LEN] = {0}; + if (Crypto::GetUdidHash(profile.GetTrustDeviceId(), reinterpret_cast(udidHash)) != DM_OK) { + LOGE("get udidhash by udid: %{public}s failed.", GetAnonyString(profile.GetTrustDeviceId()).c_str()); + return; + } + + if (memcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId), udidHash, + std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) { + LOGE("GetAllTrustedDeviceList copy deviceId failed."); + return; + } + + std::string networkId = ""; + if (GetNetworkIdByUdid(profile.GetTrustDeviceId(), networkId) == DM_OK) { + if (memcpy_s(deviceInfo.networkId, sizeof(deviceInfo.networkId), networkId.c_str(), + std::min(sizeof(deviceInfo.networkId), networkId.size())) != DM_OK) { + LOGE("GetAllTrustedDeviceList copy networkId data failed."); + } + } + + std::string deviceName = ""; + if (GetDeviceNameByUdid(profile.GetTrustDeviceId(), deviceName) == DM_OK) { + if (memcpy_s(deviceInfo.deviceName, sizeof(deviceInfo.deviceName), deviceName.c_str(), + std::min(sizeof(deviceInfo.deviceName), deviceName.size())) != DM_OK) { + LOGE("GetAllTrustedDeviceList copy deviceName data failed."); + } + } else { + if (memcpy_s(deviceInfo.deviceName, sizeof(deviceInfo.deviceName), udidHash, + std::min(sizeof(deviceInfo.deviceName), sizeof(udidHash))) != DM_OK) { + LOGE("GetAllTrustedDeviceList copy deviceName data failed."); + } + } +} +#endif + +int32_t SoftbusListener::GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, + std::vector &deviceList) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + (void)extra; + uint32_t tokenId = static_cast(OHOS::IPCSkeleton::GetCallingTokenID()); + std::vector allProfile = + DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); + for (DistributedDeviceProfile::AccessControlProfile profile : allProfile) { + if (profile.GetBindType() == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP) { + continue; + } + DistributedDeviceProfile::Accesser acer = profile.GetAccesser(); + if (pkgName == acer.GetAccesserBundleName() && tokenId == acer.GetAccesserTokenId()) { + DmDeviceInfo deviceinfo; + ConvertAclToDeviceInfo(profile, deviceinfo); + deviceList.push_back(deviceinfo); + continue; + } + DistributedDeviceProfile::Accessee acee = profile.GetAccessee(); + if (pkgName == acee.GetAccesseeBundleName() && tokenId == acee.GetAccesseeTokenId()) { + DmDeviceInfo deviceinfo; + ConvertAclToDeviceInfo(profile, deviceinfo); + deviceList.push_back(deviceinfo); + continue; + } + } +#endif + return DM_OK; +} + +int32_t SoftbusListener::GetUdidFromDp(const std::string &udidHash, std::string &udid) +{ +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::vector allProfile = + DeviceProfileConnector::GetInstance().GetAllAccessControlProfile(); + for (DistributedDeviceProfile::AccessControlProfile profile : allProfile) { + if (profile.GetBindType() == GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP) { + continue; + } + char udidHashTemp[DM_MAX_DEVICE_ID_LEN] = {0}; + if (Crypto::GetUdidHash(profile.GetTrustDeviceId(), reinterpret_cast(udidHashTemp)) != DM_OK) { + LOGE("get udidHash by udid: %{public}s failed.", GetAnonyString(profile.GetTrustDeviceId()).c_str()); + continue; + } + if (udidHash == std::string(udidHashTemp)) { + udid = profile.GetTrustDeviceId(); + return DM_OK; + } + } +#endif + return ERR_DM_FAILED; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/softbuscache/include/dm_softbus_cache.h b/services/softbuscache/include/dm_softbus_cache.h index 5a174234d..965a72fd5 100644 --- a/services/softbuscache/include/dm_softbus_cache.h +++ b/services/softbuscache/include/dm_softbus_cache.h @@ -50,6 +50,7 @@ public: int32_t GetUuidByUdid(const std::string &udid, std::string &uuid); int32_t GetNetworkIdFromCache(const std::string &udid, std::string &networkId); bool CheckIsOnline(const std::string &udidHash); + int32_t GetDeviceNameFromCache(const std::string &udid, std::string &deviceName); private: int32_t GetUdidByNetworkId(const char *networkId, std::string &udid); int32_t GetUuidByNetworkId(const char *networkId, std::string &uuid); diff --git a/services/softbuscache/src/dm_softbus_cache.cpp b/services/softbuscache/src/dm_softbus_cache.cpp index a97bad57b..e9f6edd7a 100644 --- a/services/softbuscache/src/dm_softbus_cache.cpp +++ b/services/softbuscache/src/dm_softbus_cache.cpp @@ -460,5 +460,20 @@ bool SoftbusCache::CheckIsOnline(const std::string &deviceId) } return false; } + +int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::string &deviceName) +{ + LOGI("udid %{public}s.", GetAnonyString(udid).c_str()); + { + std::lock_guard mutexLock(deviceInfosMutex_); + if (deviceInfo_.find(udid) != deviceInfo_.end()) { + deviceName = deviceInfo_[udid].second.deviceName; + LOGI("GetDeviceNameFromCache success deviceName: %{public}s, udid: %{public}s.", + deviceName.c_str(), GetAnonyString(udid).c_str()); + return DM_OK; + } + } + return ERR_DM_FAILED; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn index 3c4b37a7c..0cb1e7b21 100644 --- a/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceinfochanged_fuzzer/BUILD.gn @@ -47,6 +47,8 @@ ohos_fuzztest("OnSoftbusDeviceInfoChangedFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn index b8a0621f5..ecf137944 100644 --- a/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceoffline_fuzzer/BUILD.gn @@ -48,6 +48,8 @@ ohos_fuzztest("OnSoftbusDeviceOfflineFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn index 9add164b1..049ffdb53 100644 --- a/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbusdeviceonline_fuzzer/BUILD.gn @@ -48,6 +48,8 @@ ohos_fuzztest("OnSoftbusDeviceOnlineFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn b/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn index c92b5a0c9..6bc275719 100644 --- a/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/onsoftbuslistenerdevicefound_fuzzer/BUILD.gn @@ -47,6 +47,8 @@ ohos_fuzztest("OnSoftbusListenerDeviceFoundFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn index 1045b6cc1..8a1a5e385 100644 --- a/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/publishsoftbuslnn_fuzzer/BUILD.gn @@ -48,6 +48,8 @@ ohos_fuzztest("PublishSoftbusLnnFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn index 30ef6b882..731f97cc5 100644 --- a/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/refreshsoftbuslnn_fuzzer/BUILD.gn @@ -48,6 +48,8 @@ ohos_fuzztest("RefreshSoftbusLnnFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] diff --git a/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn b/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn index e6357b91c..b69e49882 100644 --- a/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn +++ b/test/softbusfuzztest/stoprefreshsoftbuslnn_fuzzer/BUILD.gn @@ -48,6 +48,8 @@ ohos_fuzztest("StopRefreshSoftbusLnnFuzzTest") { external_deps = [ "c_utils:utils", "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", "dsoftbus:softbus_client", "safwk:system_ability_fwk", ] -- Gitee