Check if sensor is accessible on flush
In cases where halVersion is less than or equal to 1 or the sensor is
virtual the sensor service does not first check that the sensor is
accessible. This was causing failures for tests where a virtual sensor
was used because the flush command was not returning error. Now
INVALID_OPERATION is returned when flush is called on an idle sensor.
Test: set IGNORE_HARDWARE_FUSION to true and cts-tradefed && run cts -m
CtsSensorTestCases -t
android.hardware.cts.SensorTest#testBatchAndFlushUidIdle which fails
before this change, but passes now
Bug: 160282248
Change-Id: I6860bcdb9be341b5e2025caf7606d071779c9b39
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 26e37aa..60f9cd9 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1774,7 +1774,10 @@
if (halVersion <= SENSORS_DEVICE_API_VERSION_1_0 || isVirtualSensor(handle)) {
// For older devices just increment pending flush count which will send a trivial
// flush complete event.
- connection->incrementPendingFlushCount(handle);
+ if (!connection->incrementPendingFlushCountIfHasAccess(handle)) {
+ ALOGE("flush called on an inaccessible sensor");
+ err = INVALID_OPERATION;
+ }
} else {
if (!canAccessSensor(sensor->getSensor(), "Tried flushing", opPackageName)) {
err = INVALID_OPERATION;