From 337b5f7d3c8b82de2ea24e8c7e058b61b39ee2d7 Mon Sep 17 00:00:00 2001 From: taojuncun Date: Fri, 15 Nov 2024 11:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=9B=9E=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E9=87=8F=E4=B8=BA0=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8SetResult=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: taojuncun --- ...bility_element_operator_callback_proxy.cpp | 36 +++++++++-------- ...ibility_element_operator_callback_stub.cpp | 39 ++++++++++--------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/common/interface/src/accessibility_element_operator_callback_proxy.cpp b/common/interface/src/accessibility_element_operator_callback_proxy.cpp index ab1b86f0..21ca6fc3 100644 --- a/common/interface/src/accessibility_element_operator_callback_proxy.cpp +++ b/common/interface/src/accessibility_element_operator_callback_proxy.cpp @@ -81,25 +81,27 @@ void AccessibilityElementOperatorCallbackProxy::SetSearchElementInfoByAccessibil return; } - MessageParcel tmpParcel; - tmpParcel.SetMaxCapacity(MAX_RAWDATA_SIZE); - // when set pracel's max capacity, it won't alloc memory immediately - // MessageParcel will expand memory dynamiclly - for (const auto &info : infos) { - AccessibilityElementInfoParcel infoParcel(info); - if (!tmpParcel.WriteParcelable(&infoParcel)) { - HILOG_ERROR("write accessibilityElementInfoParcel failed"); + if (infos.size() != 0) { + MessageParcel tmpParcel; + tmpParcel.SetMaxCapacity(MAX_RAWDATA_SIZE); + // when set pracel's max capacity, it won't alloc memory immediately + // MessageParcel will expand memory dynamiclly + for (const auto &info : infos) { + AccessibilityElementInfoParcel infoParcel(info); + if (!tmpParcel.WriteParcelable(&infoParcel)) { + HILOG_ERROR("write accessibilityElementInfoParcel failed"); + return; + } + } + size_t tmpParcelSize = tmpParcel.GetDataSize(); + if (!data.WriteUint32(tmpParcelSize)) { + HILOG_ERROR("write rawData size failed"); + return; + } + if (!data.WriteRawData(reinterpret_cast(tmpParcel.GetData()), tmpParcelSize)) { + HILOG_ERROR("write rawData failed"); return; } - } - size_t tmpParcelSize = tmpParcel.GetDataSize(); - if (!data.WriteUint32(tmpParcelSize)) { - HILOG_ERROR("write rawData size failed"); - return; - } - if (!data.WriteRawData(reinterpret_cast(tmpParcel.GetData()), tmpParcelSize)) { - HILOG_ERROR("write rawData failed"); - return; } if (!SendTransactCmd(AccessibilityInterfaceCode::SET_RESULT_BY_ACCESSIBILITY_ID, data, reply, option)) { diff --git a/common/interface/src/accessibility_element_operator_callback_stub.cpp b/common/interface/src/accessibility_element_operator_callback_stub.cpp index 037e4e0d..c752c3d7 100644 --- a/common/interface/src/accessibility_element_operator_callback_stub.cpp +++ b/common/interface/src/accessibility_element_operator_callback_stub.cpp @@ -110,27 +110,30 @@ ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAc std::vector storeData; int32_t requestId = data.ReadInt32(); size_t infoSize = data.ReadUint32(); - size_t rawDataSize = data.ReadUint32(); - MessageParcel tmpParcel; - void *buffer = nullptr; - // memory alloced in GetData will be released when tmpParcel destruct - if (!GetData(rawDataSize, data.ReadRawData(rawDataSize), buffer)) { - reply.WriteInt32(RET_ERR_FAILED); - return TRANSACTION_ERR; - } - - if (!tmpParcel.ParseFrom(reinterpret_cast(buffer), rawDataSize)) { - reply.WriteInt32(RET_ERR_FAILED); - return TRANSACTION_ERR; - } - - for (size_t i = 0; i < infoSize; i++) { - sptr info = tmpParcel.ReadStrongParcelable(); - if (info == nullptr) { + if (infoSize != 0) { + size_t rawDataSize = data.ReadUint32(); + MessageParcel tmpParcel; + void *buffer = nullptr; + // memory alloced in GetData will be released when tmpParcel destruct + if (!GetData(rawDataSize, data.ReadRawData(rawDataSize), buffer)) { reply.WriteInt32(RET_ERR_FAILED); return TRANSACTION_ERR; } - storeData.emplace_back(*info); + + if (!tmpParcel.ParseFrom(reinterpret_cast(buffer), rawDataSize)) { + reply.WriteInt32(RET_ERR_FAILED); + return TRANSACTION_ERR; + } + + for (size_t i = 0; i < infoSize; i++) { + sptr info = + tmpParcel.ReadStrongParcelable(); + if (info == nullptr) { + reply.WriteInt32(RET_ERR_FAILED); + return TRANSACTION_ERR; + } + storeData.emplace_back(*info); + } } reply.WriteInt32(RET_OK); SetSearchElementInfoByAccessibilityIdResult(storeData, requestId);