diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index dd6198ccc7aa17384a29b945de7d123c462dd019..9a4ab6912255a6fc57ff5fa86ad9b4fca6a74abf 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -66,9 +66,9 @@ private: int32_t UpdateSensorInfo(SensorInfo* sensorInfo, const Sensor& sensor); int32_t UpdateSensorInfosCache(const std::vector& deviceSensorList); bool FindSensorInfo(int32_t deviceId, int32_t sensorIndex, int32_t sensorTypeId); - void UpdateSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info); - bool UpdateSensorInfo(SensorPlugData info); - void EraseCacheSensorInfos(SensorPlugData info); + void UpdateSensorStatusEvent(SensorStatusEvent &event, const SensorPlugData &info); + bool UpdateSensorInfo(const SensorPlugData &info); + void EraseCacheSensorInfos(const SensorPlugData &info); static std::recursive_mutex subscribeMutex_; static std::recursive_mutex subscribePlugMutex_; static std::mutex chanelMutex_; diff --git a/frameworks/native/include/sensor_client_proxy.h b/frameworks/native/include/sensor_client_proxy.h index 8f7674c028a042cbc34eff1dd627a4b871e1a0f8..234a96dce83180389f927fa6556f362fb0dac341 100755 --- a/frameworks/native/include/sensor_client_proxy.h +++ b/frameworks/native/include/sensor_client_proxy.h @@ -34,48 +34,51 @@ public: MessageParcel dataParcel; MessageParcel replyParcel; if (!dataParcel.WriteInterfaceToken(GetDescriptor())) { - SEN_HILOGD("Failed to write descriptor to parcelable"); + SEN_HILOGE("Failed to write descriptor to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.deviceId)) { - SEN_HILOGD("Failed to write deviceId to parcelable"); + SEN_HILOGE("Failed to write deviceId to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.sensorTypeId)) { - SEN_HILOGD("Failed to write sensorTypeId to parcelable"); + SEN_HILOGE("Failed to write sensorTypeId to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.sensorId)) { - SEN_HILOGD("Failed to write sensorId to parcelable"); + SEN_HILOGE("Failed to write sensorId to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.location)) { - SEN_HILOGD("Failed to write location to parcelable"); + SEN_HILOGE("Failed to write location to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteString(info.deviceName)) { - SEN_HILOGD("Failed to write deviceName to parcelable"); + SEN_HILOGE("Failed to write deviceName to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.status)) { - SEN_HILOGD("Failed to write status to parcelable"); + SEN_HILOGE("Failed to write status to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt32(info.reserved)) { - SEN_HILOGD("Failed to write reserved to parcelable"); + SEN_HILOGE("Failed to write reserved to parcelable"); return PARAMETER_ERROR; } if (!dataParcel.WriteInt64(info.timestamp)) { - SEN_HILOGD("Failed to write timestamp to parcelable"); + SEN_HILOGE("Failed to write timestamp to parcelable"); return PARAMETER_ERROR; } + if (Remote() == nullptr) { + SEN_HILOGE("Remote() is nullptr"); + return ERROR; + } int error = Remote()->SendRequest(PROCESS_PLUG_EVENT, dataParcel, replyParcel, option); if (error != ERR_NONE) { - SEN_HILOGD("failed, error code is: %{public}d", error); + SEN_HILOGE("failed, error code is: %{public}d", error); return PARAMETER_ERROR; } - int result = (error == ERR_NONE) ? replyParcel.ReadInt32() : -1; - return result; + return SUCCESS; } private: diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index 084c07977fa0333b877ebb98cc4c8f33bb3646c9..fcacdb838e390f02d72460e88477f30590a521cf 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -54,7 +54,7 @@ public: int32_t CreateClientRemoteObject(); int32_t TransferClientRemoteObject(); int32_t DestroyClientRemoteObject(); - bool EraseCacheSensorList(SensorPlugData info); + bool EraseCacheSensorList(const SensorPlugData &info); int32_t GetLocalDeviceId(int32_t &deviceId); private: diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 162ef71d9ce3427be4cf0f948c1896106f711554..af6b173e2c4b136386ae86c1b5ebc199718e8c54 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -565,7 +565,12 @@ int32_t SensorAgentProxy::UpdateSensorInfosCache(const std::vector& sing if (newSensorsCount == 0) { return SUCCESS; } - size_t newTotalCount = sensorInfoCount_ + newSensorsCount; + if (sensorInfoCount_ < 0 || sensorInfoCount_ > MAX_SENSOR_LIST_SIZE) { + SEN_HILOGE("sensorInfoCount_ invalid, sensorInfoCount_:%{public}d", sensorInfoCount_); + return ERROR; + } + size_t currentInfoCount = static_cast(sensorInfoCount_); + size_t newTotalCount = currentInfoCount + newSensorsCount; if (newTotalCount > MAX_SENSOR_LIST_SIZE) { SEN_HILOGE("The number of sensors exceeds the maximum value"); return ERROR; @@ -578,10 +583,9 @@ int32_t SensorAgentProxy::UpdateSensorInfosCache(const std::vector& sing if (sensorInfoCheck_.sensorInfos) { std::copy(sensorInfoCheck_.sensorInfos, sensorInfoCheck_.sensorInfos + sensorInfoCount_, newSensorInfos.get()); } - size_t currentIndex = sensorInfoCount_; for (const auto& sensor : singleDevSensors) { if (!FindSensorInfo(sensor.GetDeviceId(), sensor.GetSensorId(), sensor.GetSensorTypeId())) { - UpdateSensorInfo(&newSensorInfos[currentIndex++], sensor); + UpdateSensorInfo(&newSensorInfos[currentInfoCount++], sensor); } } sensorInfoCheck_.sensorInfos = newSensorInfos.release(); @@ -792,7 +796,7 @@ int32_t SensorAgentProxy::UnsubscribeSensorPlug(const SensorUser *user) return OHOS::Sensors::SUCCESS; } -void SensorAgentProxy::UpdateSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info) +void SensorAgentProxy::UpdateSensorStatusEvent(SensorStatusEvent &event, const SensorPlugData &info) { event.sensorType = info.sensorTypeId; event.sensorId = info.sensorId; @@ -809,7 +813,7 @@ void SensorAgentProxy::UpdateSensorStatusEvent(SensorStatusEvent &event, SensorP event.timestamp = info.timestamp; } -bool SensorAgentProxy::UpdateSensorInfo(SensorPlugData info) +bool SensorAgentProxy::UpdateSensorInfo(const SensorPlugData &info) { CALL_LOG_ENTER; if (info.status == SENSOR_ONLINE) { @@ -844,7 +848,7 @@ bool SensorAgentProxy::UpdateSensorInfo(SensorPlugData info) return true; } -void SensorAgentProxy::EraseCacheSensorInfos(SensorPlugData info) +void SensorAgentProxy::EraseCacheSensorInfos(const SensorPlugData &info) { std::lock_guard listLock(sensorInfoMutex_); for (int32_t i = 0; i < sensorInfoCount_; ++i) { diff --git a/frameworks/native/src/sensor_client_stub.cpp b/frameworks/native/src/sensor_client_stub.cpp index 630aa717b742ca705721416524f6cdccf18fb9af..5af014883e6962a997157d42d87b508d29101f3a 100644 --- a/frameworks/native/src/sensor_client_stub.cpp +++ b/frameworks/native/src/sensor_client_stub.cpp @@ -73,7 +73,9 @@ int32_t SensorClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Me return PARAMETER_ERROR; } int32_t result = ProcessPlugEvent(info); - reply.WriteInt32(result); + if (result != NO_ERROR) { + SEN_HILOGE("Process plug event failed"); + } return NO_ERROR; } diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 4f2f29cad9e9137e8ff2a882289ffb4ec2483d9c..ef54eb5738e677bdf505cce6a16d1e2fca457a98 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -852,7 +852,7 @@ void SensorServiceClient::SetDeviceStatus(uint32_t deviceStatus) #endif // HIVIEWDFX_HITRACE_ENABLE } -bool SensorServiceClient::EraseCacheSensorList(SensorPlugData info) +bool SensorServiceClient::EraseCacheSensorList(const SensorPlugData &info) { CALL_LOG_ENTER; std::lock_guard clientLock(clientMutex_); diff --git a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h index 2a45ac6e91728a561710708e26dbb52c40dfd667..76c51e0a1c2d5c2b7afdea9166a4f4bd93a15262 100644 --- a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h +++ b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h @@ -25,7 +25,7 @@ namespace OHOS { namespace Sensors { using OHOS::HDI::Sensor::V3_0::SensorPlugInfo; -using DevicePlugCallback = std::function; +using DevicePlugCallback = std::function; class ISensorHdiConnection { public: ISensorHdiConnection() = default; diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 9cb8a7b361b376b75fe92148c08268470d6c8110..59e002f22c287a45e2b8d95f18a1e514c61f7104 100644 --- a/services/include/sensor_service.h +++ b/services/include/sensor_service.h @@ -71,7 +71,7 @@ private: void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; ErrCode CheckAuthAndParameter(const SensorDescription &sensorDesc, int64_t samplingPeriodNs, int64_t maxReportDelayNs); - void ReportPlugEventCallback(const SensorPlugInfo sensorPlugInfo); + void ReportPlugEventCallback(const SensorPlugInfo &sensorPlugInfo); ErrCode SensorReportEvent(const SensorDescription &sensorDesc, int64_t samplingPeriodNs, int64_t maxReportDelayNs, int32_t pid); diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 23b9b5a38f0715dcd6d012f83361d191a5429d40..ccc4a74b47892dded3b7f974de7d786ee12c2dcc 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -1004,7 +1004,7 @@ ErrCode SensorService::DestroyClientRemoteObject(const sptr &sens return ERR_OK; } -void SensorService::ReportPlugEventCallback(const SensorPlugInfo info) +void SensorService::ReportPlugEventCallback(const SensorPlugInfo &info) { CALL_LOG_ENTER; if (info.status == SENSOR_ONLINE) { diff --git a/utils/common/src/sensor.cpp b/utils/common/src/sensor.cpp index f109145359bec9869166829606c7e836acffd4c3..c78a991021bfd85fbce1beefe8571e342b5be52d 100644 --- a/utils/common/src/sensor.cpp +++ b/utils/common/src/sensor.cpp @@ -291,6 +291,7 @@ bool Sensor::ReadFromParcel(Parcel &parcel) } SensorDescriptionIPC::SensorDescriptionIPC() + :deviceId(0), sensorType(0), sensorId(0), location(0) {} SensorDescriptionIPC::SensorDescriptionIPC(int32_t deviceId, int32_t sensorTypeId, int32_t sensorId, int32_t location) @@ -327,21 +328,25 @@ SensorDescriptionIPC* SensorDescriptionIPC::Unmarshalling(Parcel &data) } if (!(data.ReadInt32(sensorDesc->deviceId))) { SEN_HILOGE("Read deviceId failed"); + delete sensorDesc; sensorDesc = nullptr; return sensorDesc; } if (!(data.ReadInt32(sensorDesc->sensorType))) { SEN_HILOGE("Read sensorTypeId failed"); + delete sensorDesc; sensorDesc = nullptr; return sensorDesc; } if (!(data.ReadInt32(sensorDesc->sensorId))) { SEN_HILOGE("Read sensorId failed"); + delete sensorDesc; sensorDesc = nullptr; return sensorDesc; } if (!(data.ReadInt32(sensorDesc->location))) { SEN_HILOGE("Read location_ failed"); + delete sensorDesc; sensorDesc = nullptr; return sensorDesc; }