Fix batterystats update on sensor connection cleanup
Previous code was stopping battery tracking for *all* sensors activated
by the UID, rather than only the sensors activated in the
SensorEventConnection being cleaned up, leading to under-counting of
sensor activation time.
Fixes: 210559152
Test: verify batterystats correctly updates when one connection is
closed and another remains open
Change-Id: Id6b96929c5534295334eeca3d56506d29bc75b29
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 8b81d48..88cf5ab 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1611,7 +1611,9 @@
} else {
ALOGE("sensor interface of handle=0x%08x is null!", handle);
}
- c->removeSensor(handle);
+ if (c->removeSensor(handle)) {
+ BatteryService::disableSensor(c->getUid(), handle);
+ }
}
SensorRecord* rec = mActiveSensors.valueAt(i);
ALOGE_IF(!rec, "mActiveSensors[%zu] is null (handle=0x%08x)!", i, handle);
@@ -1631,7 +1633,6 @@
}
c->updateLooperRegistration(mLooper);
mConnectionHolder.removeEventConnection(connection);
- BatteryService::cleanup(c->getUid());
if (c->needsWakeLock()) {
checkWakeLockStateLocked(&connLock);
}