summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Kuiper <ckuiper@google.com>2021-08-03 23:08:10 -0700
committerChris Kuiper <ckuiper@google.com>2021-08-04 15:48:47 -0700
commitcebf2e6cd693b0ad9cd9560c283e24f7e38aa0cf (patch)
tree89a7ee33d8c4d9f3dc821d2d024f18254d9951ed
parentc63880a5a946a23ceacb9a8b7bb9c7dcd38d93fa (diff)
downloadnative-cebf2e6cd693b0ad9cd9560c283e24f7e38aa0cf.tar.gz
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
-rw-r--r--services/sensorservice/SensorInterface.cpp10
-rw-r--r--services/sensorservice/SensorInterface.h1
2 files changed, 6 insertions, 5 deletions
diff --git a/services/sensorservice/SensorInterface.cpp b/services/sensorservice/SensorInterface.cpp
index 560834f5f3..c285c00623 100644
--- a/services/sensorservice/SensorInterface.cpp
+++ b/services/sensorservice/SensorInterface.cpp
@@ -92,14 +92,16 @@ ProximitySensor::ProximitySensor(const sensor_t& sensor, SensorService& service)
}
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;
}
diff --git a/services/sensorservice/SensorInterface.h b/services/sensorservice/SensorInterface.h
index ea181c9877..4e9f7bf9c8 100644
--- a/services/sensorservice/SensorInterface.h
+++ b/services/sensorservice/SensorInterface.h
@@ -119,7 +119,6 @@ public:
void didEnableAllSensors() override;
private:
SensorService& mSensorService;
- bool mActive;
};
// ---------------------------------------------------------------------------