diff options
author | Roman Kiryanov <rkir@google.com> | 2020-07-23 17:02:28 -0700 |
---|---|---|
committer | Calvin Huang <calhuang@google.com> | 2020-09-24 00:04:20 -0700 |
commit | 9caf6786bc1b3c9a451aad1a028547ce3763858a (patch) | |
tree | f008131cbbda9e8c0d7cc800941cf08e8b90237d | |
parent | 79de5d7268ac08eb110fe25b8431f123232fd884 (diff) | |
download | device_generic_goldfish-9caf6786bc1b3c9a451aad1a028547ce3763858a.tar.gz device_generic_goldfish-9caf6786bc1b3c9a451aad1a028547ce3763858a.tar.bz2 device_generic_goldfish-9caf6786bc1b3c9a451aad1a028547ce3763858a.zip |
Check if sensorHandle refers to the sensor that is available
Bug: 159469598
Test: atest android.hardware.cts.SensorBatchingTests
Change-Id: I990e764337b8392da254d3b6bc861834290cd1e2
Merged-In: I990e764337b8392da254d3b6bc861834290cd1e2
Signed-off-by: Roman Kiryanov <rkir@google.com>
-rw-r--r-- | sensors/multihal_sensors.cpp | 37 | ||||
-rw-r--r-- | sensors/multihal_sensors.h | 1 |
2 files changed, 27 insertions, 11 deletions
diff --git a/sensors/multihal_sensors.cpp b/sensors/multihal_sensors.cpp index 292786e3..58fee622 100644 --- a/sensors/multihal_sensors.cpp +++ b/sensors/multihal_sensors.cpp @@ -150,24 +150,26 @@ Return<Result> MultihalSensors::batch(const int32_t sensorHandle, const int64_t maxReportLatencyNs) { (void)maxReportLatencyNs; + if (!isSensorHandleValid(sensorHandle)) { + return Result::BAD_VALUE; + } + const SensorInfo* sensor = getSensorInfoByHandle(sensorHandle); - if (sensor) { - if (samplingPeriodNs >= sensor->minDelay) { - return Result::OK; - } else { - return Result::BAD_VALUE; - } + LOG_ALWAYS_FATAL_IF(!sensor); + if (samplingPeriodNs >= sensor->minDelay) { + return Result::OK; } else { return Result::BAD_VALUE; } } Return<Result> MultihalSensors::flush(const int32_t sensorHandle) { - const SensorInfo* sensor = getSensorInfoByHandle(sensorHandle); - if (!sensor) { + if (!isSensorHandleValid(sensorHandle)) { return Result::BAD_VALUE; } + const SensorInfo* sensor = getSensorInfoByHandle(sensorHandle); + LOG_ALWAYS_FATAL_IF(!sensor); std::unique_lock<std::mutex> lock(m_apiMtx); if (!(m_activeSensorsMask & (1u << sensorHandle))) { return Result::BAD_VALUE; @@ -183,6 +185,9 @@ Return<Result> MultihalSensors::flush(const int32_t sensorHandle) { } Return<Result> MultihalSensors::injectSensorData_2_1(const Event& event) { + if (!isSensorHandleValid(event.sensorHandle)) { + return Result::BAD_VALUE; + } if (event.sensorType == SensorType::ADDITIONAL_INFO) { return Result::OK; } @@ -192,9 +197,7 @@ Return<Result> MultihalSensors::injectSensorData_2_1(const Event& event) { return Result::INVALID_OPERATION; } const SensorInfo* sensor = getSensorInfoByHandle(event.sensorHandle); - if (!sensor) { - return Result::BAD_VALUE; - } + LOG_ALWAYS_FATAL_IF(!sensor); if (sensor->type != event.sensorType) { return Result::BAD_VALUE; } @@ -230,6 +233,18 @@ bool MultihalSensors::qemuSensorThreadSendCommand(const char cmd) const { return TEMP_FAILURE_RETRY(write(m_callersFd.get(), &cmd, 1)) == 1; } +bool MultihalSensors::isSensorHandleValid(int32_t sensorHandle) const { + if (!goldfish::isSensorHandleValid(sensorHandle)) { + return false; + } + + if (!(m_availableSensorsMask & (1u << sensorHandle))) { + return false; + } + + return true; +} + /// not supported ////////////////////////////////////////////////////////////// Return<void> MultihalSensors::registerDirectChannel(const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) { diff --git a/sensors/multihal_sensors.h b/sensors/multihal_sensors.h index 80ed6a3b..b8fbf50b 100644 --- a/sensors/multihal_sensors.h +++ b/sensors/multihal_sensors.h @@ -81,6 +81,7 @@ private: float lastHingeAngle2Value = kSensorNoValue; }; + bool isSensorHandleValid(int sensorHandle) const; static bool activateQemuSensorImpl(int pipe, int sensorHandle, bool enabled); bool disableAllSensors(); void parseQemuSensorEvent(const int pipe, QemuSensorsProtocolState* state); |