diff --git a/frameworks/native/include/sensor_client_proxy.h b/frameworks/native/include/sensor_client_proxy.h index 234a96dce83180389f927fa6556f362fb0dac341..a2a5ca18d68c05fb9785b24dd0dcfad1037ec1ef 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 af6b173e2c4b136386ae86c1b5ebc199718e8c54..224c5f38da903d015a0d3e5802f69f993413cd78 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 5af014883e6962a997157d42d87b508d29101f3a..81ac153fe46c05c8dcf6ca5091ec08d72a4851be 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");