From 284befaf686aa93ca9b4144488872903a631c6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Fri, 17 Jan 2025 15:31:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?L1=20=E6=8E=A5=E5=8F=A3=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../src/ipc/lite/ipc_client_manager.cpp | 10 ++- .../src/ipc/lite/ipc_cmd_parser.cpp | 66 +++++++++++++++++++ .../service/src/ipc/lite/ipc_cmd_parser.cpp | 34 ++++++++++ .../src/softbus/mine_softbus_listener.cpp | 2 +- 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index d8584b2b3..2c62215a9 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -88,6 +88,7 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r CHECK_NULL_RETURN(rsp, ERR_DM_POINT_NULL); std::string pkgName = req->GetPkgName(); if (!IsInit(pkgName)) { + LOGE("dm init failed."); return ERR_DM_INIT_FAILED; } return serverProxy_.SendCmd(cmdCode, req, rsp); @@ -95,7 +96,14 @@ int32_t IpcClientManager::SendRequest(int32_t cmdCode, std::shared_ptr r bool IpcClientManager::IsInit(const std::string &pkgName) { - return (packageInitSet_.count(pkgName) > 0); + for (auto &iter : packageInitSet_) { + size_t len = iter.size(); + std::string tmp = pkgName.substr(0, len); + if (tmp == iter) { + return true; + } + } + return false; } int32_t IpcClientManager::OnDmServiceDied() diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index e578e5413..eeec2eac1 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -21,6 +21,7 @@ #include "dm_log.h" #include "dm_subscribe_info.h" #include "ipc_cmd_register.h" +#include "ipc_common_param_req.h" #include "ipc_def.h" #include "ipc_get_device_info_rsp.h" #include "ipc_get_info_by_network_req.h" @@ -358,5 +359,70 @@ ON_IPC_READ_RESPONSE(SYNC_CALLBACK, IpcIo &reply, std::shared_ptr pBaseR { return SetRspErrCode(reply, pBaseRsp); } + +ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, + size_t buffLen) +{ + LOGI("start."); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string discParaStr = pReq->GetFirstParam(); + std::string filterOpStr = pReq->GetSecondParam(); + + IpcIoInit(&request, buffer, buffLen, 0); + WriteString(&request, pkgName.c_str()); + WriteString(&request, discParaStr.c_str()); + WriteString(&request, filterOpStr.c_str()); + return DM_OK; +} + +ON_IPC_READ_RESPONSE(START_DISCOVERING, IpcIo &reply, std::shared_ptr pBaseRsp) +{ + LOGI("start."); + return SetRspErrCode(reply, pBaseRsp); +} + +ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, + size_t buffLen) +{ + LOGI("start."); + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string discParaStr = pReq->GetFirstParam(); + + IpcIoInit(&request, buffer, buffLen, 0); + WriteString(&request, pkgName.c_str()); + WriteString(&request, discParaStr.c_str()); + return DM_OK; +} + +ON_IPC_READ_RESPONSE(STOP_DISCOVERING, IpcIo &reply, std::shared_ptr pBaseRsp) +{ + LOGI("start."); + return SetRspErrCode(reply, pBaseRsp); +} + +ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, + size_t buffLen) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + + IpcIoInit(&request, buffer, buffLen, 0); + WriteString(&request, pkgName.c_str()); + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, IpcIo &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + DmDeviceInfo deviceInfo; + DecodeDmDeviceInfo(reply, deviceInfo); + int32_t ret = 0; + ReadInt32(&reply, &ret); + pRsp->SetLocalDeviceInfo(deviceInfo); + pRsp->SetErrCode(ret); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/lite/ipc_cmd_parser.cpp b/services/service/src/ipc/lite/ipc_cmd_parser.cpp index 37bec133e..00d71d515 100644 --- a/services/service/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/lite/ipc_cmd_parser.cpp @@ -251,5 +251,39 @@ ON_IPC_SERVER_CMD(SYNC_CALLBACK, IpcIo &req, IpcIo &reply) int32_t ret = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfo); WriteInt32(&reply, ret); } + +ON_IPC_SERVER_CMD(START_DISCOVERING, IpcIo &req, IpcIo &reply) +{ + LOGI("start."); + std::string pkgName = (const char *)ReadString(&req, nullptr); + std::string discParaStr = (const char *)ReadString(&req, nullptr); + std::string filterOpStr = (const char *)ReadString(&req, nullptr); + std::map discoverParam; + ParseMapFromJsonString(discParaStr, discoverParam); + std::map filterOptions; + ParseMapFromJsonString(filterOpStr, filterOptions); + int32_t result = DeviceManagerService::GetInstance().StartDiscovering(pkgName, discoverParam, filterOptions); + WriteInt32(&reply, result); +} + +ON_IPC_SERVER_CMD(STOP_DISCOVERING, IpcIo &req, IpcIo &reply) +{ + LOGI("start."); + std::string pkgName = (const char *)ReadString(&req, nullptr); + std::string discParaStr = (const char *)ReadString(&req, nullptr); + std::map discoverParam; + ParseMapFromJsonString(discParaStr, discoverParam); + int32_t result = DeviceManagerService::GetInstance().StopDiscovering(pkgName, discoverParam); + WriteInt32(&reply, result); +} + +ON_IPC_SERVER_CMD(GET_LOCAL_DEVICE_INFO, IpcIo &req, IpcIo &reply) +{ + LOGI("start."); + DmDeviceInfo localDeviceInfo; + int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo); + EncodeDmDeviceInfo(localDeviceInfo, reply); + WriteInt32(&reply, result); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/softbus/mine_softbus_listener.cpp b/services/service/src/softbus/mine_softbus_listener.cpp index db86dab66..1cdce65e5 100644 --- a/services/service/src/softbus/mine_softbus_listener.cpp +++ b/services/service/src/softbus/mine_softbus_listener.cpp @@ -519,13 +519,13 @@ int32_t MineSoftbusListener::SendBroadcastInfo(const string &pkgName, SubscribeI #if (defined(MINE_HARMONY)) subscribeInfo.custData = base64Out; subscribeInfo.custDataLen = base64OutLen; -#endif IRefreshCallback softbusRefreshCallback_ = SoftbusListener::GetSoftbusRefreshCb(); retValue = RefreshLNN(DM_PKG_NAME, &subscribeInfo, &softbusRefreshCallback_); if (retValue != SOFTBUS_OK) { LOGE("failed to start to refresh quick discovery with ret: %{public}d.", retValue); return ERR_DM_FAILED; } +#endif LOGI("send search broadcast info by softbus successfully with dataLen: %{public}zu, pkgName: %{public}s.", base64OutLen, pkgName.c_str()); return DM_OK; -- Gitee From e64469a1e11672775172d50c7d22465c827e5960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 20 Jan 2025 14:55:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../src/ipc/lite/ipc_cmd_parser.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index eeec2eac1..f68969200 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -364,6 +364,10 @@ ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &r size_t buffLen) { LOGI("start."); + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string discParaStr = pReq->GetFirstParam(); @@ -379,6 +383,10 @@ ON_IPC_SET_REQUEST(START_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &r ON_IPC_READ_RESPONSE(START_DISCOVERING, IpcIo &reply, std::shared_ptr pBaseRsp) { LOGI("start."); + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } return SetRspErrCode(reply, pBaseRsp); } @@ -386,6 +394,10 @@ ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &re size_t buffLen) { LOGI("start."); + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string discParaStr = pReq->GetFirstParam(); @@ -399,12 +411,20 @@ ON_IPC_SET_REQUEST(STOP_DISCOVERING, std::shared_ptr pBaseReq, IpcIo &re ON_IPC_READ_RESPONSE(STOP_DISCOVERING, IpcIo &reply, std::shared_ptr pBaseRsp) { LOGI("start."); + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } return SetRspErrCode(reply, pBaseRsp); } ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen) { + if (pBaseReq == nullptr) { + LOGE("pBaseReq is null"); + return ERR_DM_FAILED; + } std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); @@ -415,6 +435,10 @@ ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr pBaseReq, IpcI ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, IpcIo &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); DmDeviceInfo deviceInfo; DecodeDmDeviceInfo(reply, deviceInfo); -- Gitee From 7d57fb70e94e4294e839bc314e87c941f4a25548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 20 Jan 2025 15:13:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B9=A0=E6=83=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index 2c62215a9..e092785e0 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -98,6 +98,10 @@ bool IpcClientManager::IsInit(const std::string &pkgName) { for (auto &iter : packageInitSet_) { size_t len = iter.size(); + if (len > pkgName.size()) { + LOGE("pkgName: %s not init.", pkgName.c_str()); + return false; + } std::string tmp = pkgName.substr(0, len); if (tmp == iter) { return true; -- Gitee From e8ce73becfb69381dafcdc74305a266575c8a71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Mon, 20 Jan 2025 15:21:17 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp index e092785e0..a9d19b2c6 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_manager.cpp @@ -99,8 +99,7 @@ bool IpcClientManager::IsInit(const std::string &pkgName) for (auto &iter : packageInitSet_) { size_t len = iter.size(); if (len > pkgName.size()) { - LOGE("pkgName: %s not init.", pkgName.c_str()); - return false; + continue; } std::string tmp = pkgName.substr(0, len); if (tmp == iter) { -- Gitee