From 4dd500d7e23d3e07ebfa1e30f44a4e8d547c8638 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Sat, 28 Jun 2025 16:45:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E7=BA=BF=E4=B8=8A=E6=8A=A5IP?= =?UTF-8?q?C=E4=BD=BF=E7=94=A8CHKCR=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 --- .../native/include/sensor_client_proxy.h | 50 ++++--------------- frameworks/native/src/sensor_agent_proxy.cpp | 3 +- frameworks/native/src/sensor_client_stub.cpp | 40 +++------------ 3 files changed, 20 insertions(+), 73 deletions(-) diff --git a/frameworks/native/include/sensor_client_proxy.h b/frameworks/native/include/sensor_client_proxy.h index 234a96dc..a2a5ca18 100755 --- a/frameworks/native/include/sensor_client_proxy.h +++ b/frameworks/native/include/sensor_client_proxy.h @@ -33,46 +33,16 @@ public: MessageOption option; MessageParcel dataParcel; MessageParcel replyParcel; - if (!dataParcel.WriteInterfaceToken(GetDescriptor())) { - SEN_HILOGE("Failed to write descriptor to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.deviceId)) { - SEN_HILOGE("Failed to write deviceId to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.sensorTypeId)) { - SEN_HILOGE("Failed to write sensorTypeId to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.sensorId)) { - SEN_HILOGE("Failed to write sensorId to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.location)) { - SEN_HILOGE("Failed to write location to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteString(info.deviceName)) { - SEN_HILOGE("Failed to write deviceName to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.status)) { - SEN_HILOGE("Failed to write status to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt32(info.reserved)) { - SEN_HILOGE("Failed to write reserved to parcelable"); - return PARAMETER_ERROR; - } - if (!dataParcel.WriteInt64(info.timestamp)) { - SEN_HILOGE("Failed to write timestamp to parcelable"); - return PARAMETER_ERROR; - } - if (Remote() == nullptr) { - SEN_HILOGE("Remote() is nullptr"); - return ERROR; - } + CHKCR(dataParcel.WriteInterfaceToken(GetDescriptor()), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.deviceId), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.sensorTypeId), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.sensorId), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.location), PARAMETER_ERROR); + CHKCR(dataParcel.WriteString(info.deviceName), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.status), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt32(info.reserved), PARAMETER_ERROR); + CHKCR(dataParcel.WriteInt64(info.timestamp), PARAMETER_ERROR); + CHKPR(Remote(), ERROR); int error = Remote()->SendRequest(PROCESS_PLUG_EVENT, dataParcel, replyParcel, option); if (error != ERR_NONE) { SEN_HILOGE("failed, error code is: %{public}d", error); diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index af6b173e..224c5f38 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -25,6 +25,7 @@ namespace OHOS { namespace Sensors { namespace { constexpr uint32_t MAX_SENSOR_LIST_SIZE = 0Xffff; +constexpr int32_t MAX_SENSOR_INFO_COUNT = 0Xffff; constexpr int32_t IS_LOCAL_DEVICE = 1; constexpr int32_t SENSOR_ONLINE = 1; std::mutex sensorInfoMutex_; @@ -565,7 +566,7 @@ int32_t SensorAgentProxy::UpdateSensorInfosCache(const std::vector& sing if (newSensorsCount == 0) { return SUCCESS; } - if (sensorInfoCount_ < 0 || sensorInfoCount_ > MAX_SENSOR_LIST_SIZE) { + if (sensorInfoCount_ < 0 || sensorInfoCount_ > MAX_SENSOR_INFO_COUNT) { SEN_HILOGE("sensorInfoCount_ invalid, sensorInfoCount_:%{public}d", sensorInfoCount_); return ERROR; } diff --git a/frameworks/native/src/sensor_client_stub.cpp b/frameworks/native/src/sensor_client_stub.cpp index 5af01488..81ac153f 100644 --- a/frameworks/native/src/sensor_client_stub.cpp +++ b/frameworks/native/src/sensor_client_stub.cpp @@ -40,38 +40,14 @@ int32_t SensorClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me return PARAMETER_ERROR; } SensorPlugData info; - if (!data.ReadInt32(info.deviceId)) { - SEN_HILOGE("Read deviceId failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt32(info.sensorTypeId)) { - SEN_HILOGE("Read sensorTypeId failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt32(info.sensorId)) { - SEN_HILOGE("Read sensorId failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt32(info.location)) { - SEN_HILOGE("Read location failed."); - return PARAMETER_ERROR; - } - if (!data.ReadString(info.deviceName)) { - SEN_HILOGE("Read deviceName failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt32(info.status)) { - SEN_HILOGE("Read status failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt32(info.reserved)) { - SEN_HILOGE("Read reserved failed."); - return PARAMETER_ERROR; - } - if (!data.ReadInt64(info.timestamp)) { - SEN_HILOGE("Read timestamp failed."); - return PARAMETER_ERROR; - } + CHKCR(data.ReadInt32(info.deviceId), PARAMETER_ERROR); + CHKCR(data.ReadInt32(info.sensorTypeId), PARAMETER_ERROR); + CHKCR(data.ReadInt32(info.sensorId), PARAMETER_ERROR); + CHKCR(data.ReadInt32(info.location), PARAMETER_ERROR); + CHKCR(data.ReadString(info.deviceName), PARAMETER_ERROR); + CHKCR(data.ReadInt32(info.status), PARAMETER_ERROR); + CHKCR(data.ReadInt32(info.reserved), PARAMETER_ERROR); + CHKCR(data.ReadInt64(info.timestamp), PARAMETER_ERROR); int32_t result = ProcessPlugEvent(info); if (result != NO_ERROR) { SEN_HILOGE("Process plug event failed"); -- Gitee