improve sensor battery usage tracking
until now we were tracking when a sensors was
physically enabled or disabled and we were reporting
that to the BattaryService.
this wasn incorrect because we could have several different
apps enabling the same sensor, so the accounting by the
battery service would be incorrect in that case (depending
on the order in which these apps disabled said sensor).
BatteryService tracks sensors per uid, however SensorService
does this per binder connection, so we could have several
binder connections for the same uid, to solve this we keep
a list of sensor/uid -> count, which is the bulk of this
change.
Bug: 6661604
Change-Id: I561c198c42ba1736a8671bdacda4c76d72b9dd6f
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index cc2f745..e3dcd02 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -39,6 +39,7 @@
#include <hardware/sensors.h>
+#include "BatteryService.h"
#include "CorrectedGyroSensor.h"
#include "GravitySensor.h"
#include "LinearAccelerationSensor.h"
@@ -421,6 +422,7 @@
}
}
mActiveConnections.remove(connection);
+ BatteryService::cleanup(c->getUid());
}
status_t SensorService::enable(const sp<SensorEventConnection>& connection,
@@ -458,6 +460,7 @@
if (err == NO_ERROR) {
// connection now active
if (connection->addSensor(handle)) {
+ BatteryService::enableSensor(connection->getUid(), handle);
// the sensor was added (which means it wasn't already there)
// so, see if this connection becomes active
if (mActiveConnections.indexOf(connection) < 0) {
@@ -483,7 +486,9 @@
SensorRecord* rec = mActiveSensors.valueFor(handle);
if (rec) {
// see if this connection becomes inactive
- connection->removeSensor(handle);
+ if (connection->removeSensor(handle)) {
+ BatteryService::disableSensor(connection->getUid(), handle);
+ }
if (connection->hasAnySensor() == false) {
mActiveConnections.remove(connection);
}