sensorservice: Refactor tracking logic for the Proximity sensor.
This simplifies the code that tracks if the proximity sensor is
active by removing all counting of clients and simply checking the
sensor's isSensorActive() method and reporting changes to it.
Bug: b/202328704
Tests: See b/202328704#comment9 for tests done.
Change-Id: Idd72b82ed0fd5ee089e795ab4b233241350979c2
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index def6611..b059e61 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -103,8 +103,9 @@
void cleanupConnection(SensorDirectConnection* c);
// Call with mLock held.
- void onProximityActiveLocked(bool isActive);
- void notifyProximityStateLocked(const std::vector<sp<ProximityActiveListener>>& listeners);
+ void checkAndReportProxStateChangeLocked();
+ void notifyProximityStateLocked(const bool isActive,
+ const std::vector<sp<ProximityActiveListener>>& listeners);
status_t enable(const sp<SensorEventConnection>& connection, int handle,
nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs, int reservedFlags,
@@ -496,8 +497,11 @@
// Checks if the mic sensor privacy is enabled for the uid
bool isMicSensorPrivacyEnabledForUid(uid_t uid);
- // Counts how many proximity sensors are currently active.
- int mProximityActiveCount;
+ // Keeps track of the handles of all proximity sensors in the system.
+ std::vector<int32_t> mProxSensorHandles;
+ // The last proximity sensor active state reported to listeners.
+ bool mLastReportedProxIsActive;
+ // Listeners subscribed to receive updates on the proximity sensor active state.
std::vector<sp<ProximityActiveListener>> mProximityActiveListeners;
};