sensorservice: ProximitySensor needs to report correct sensor state.
Calls to ProximitySensor::activate() may repeatedly set enabled=true.
The current logic doesn't account for that. In order to correctly
report the current sensor state, simply use
mSensorDevice.isSensorActive() instead.
Bug: 194878856
Test: 1) Reproduced problem and verified mIsProxActive in "dumpsys
display" contains the correct value and no more 60/90Hz
flicker.
2) Adding local debugs, then mixing making phone calls with
additional "sensor_test sample -s8 -n5" commands to create
several Prox clients, and verifying logged flags and
reference counts.
Change-Id: I2342844ff4e6301a6b9ac8a33dc3e6047fca83ad
diff --git a/services/sensorservice/SensorInterface.cpp b/services/sensorservice/SensorInterface.cpp
index 560834f..c285c00 100644
--- a/services/sensorservice/SensorInterface.cpp
+++ b/services/sensorservice/SensorInterface.cpp
@@ -92,14 +92,16 @@
}
status_t ProximitySensor::activate(void* ident, bool enabled) {
- bool wasActive = mActive;
+ bool lastState = mSensorDevice.isSensorActive(mSensor.getHandle());
+
status_t status = HardwareSensor::activate(ident, enabled);
if (status != NO_ERROR) {
return status;
}
- mActive = enabled;
- if (wasActive != enabled) {
- mSensorService.onProximityActiveLocked(enabled);
+
+ bool currentState = mSensorDevice.isSensorActive(mSensor.getHandle());
+ if (currentState != lastState) {
+ mSensorService.onProximityActiveLocked(currentState);
}
return NO_ERROR;
}