Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 154d124a authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix background sensor usage counter

being out of sync with total count, due to nesting. Only update
the counter if nesting is 1.

Test: runtest -x
frameworks/base/core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java
Change-Id: Iabb153550a79afa9902569bbbbdb5815decdc613
Fixes: 34750473
parent b3f417ec
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -7914,12 +7914,11 @@ public class BatteryStatsImpl extends BatteryStats {
        }

        public void noteStartSensor(int sensor, long elapsedRealtimeMs) {
            StopwatchTimer t = getSensorTimerLocked(sensor, true);
            if (t != null) {
            StopwatchTimer t = getSensorTimerLocked(sensor, /* create= */ true);
            t.startRunningLocked(elapsedRealtimeMs);
            }
            Counter c = getSensorBgCounterLocked(sensor, true);
            if (c != null && mProcessState >= PROCESS_STATE_BACKGROUND) {

            Counter c = getSensorBgCounterLocked(sensor, /* create= */ true);
            if (mProcessState >= PROCESS_STATE_BACKGROUND && t.mNesting == 1) {
                c.stepAtomic();
            }
        }
@@ -7933,17 +7932,17 @@ public class BatteryStatsImpl extends BatteryStats {
        }

        public void noteStartGps(long elapsedRealtimeMs) {
            StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, true);
            if (t != null) {
            StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, /* create= */ true);
            t.startRunningLocked(elapsedRealtimeMs);
            }
            Counter c = getSensorBgCounterLocked(Sensor.GPS, true);
            if (c != null && mProcessState >= PROCESS_STATE_BACKGROUND) {

            Counter c = getSensorBgCounterLocked(Sensor.GPS, /* create= */ true);
            if (mProcessState >= PROCESS_STATE_BACKGROUND && t.mNesting == 1) {
                c.stepAtomic();
            }
        }

        public void noteStopGps(long elapsedRealtimeMs) {
            // Don't create a timer if one doesn't already exist
            StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, false);
            if (t != null) {
                t.stopRunningLocked(elapsedRealtimeMs);
+2 −0
Original line number Diff line number Diff line
@@ -48,9 +48,11 @@ public class BatteryStatsSensorTest extends TestCase {

        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_RECEIVER);
        bi.noteStartSensorLocked(UID, SENSOR_ID);
        bi.noteStartSensorLocked(UID, SENSOR_ID);
        clocks.realtime = 400;
        clocks.uptime = 400;
        bi.noteStopSensorLocked(UID, SENSOR_ID);
        bi.noteStopSensorLocked(UID, SENSOR_ID);

        BatteryStats.Timer sensorTimer = bi.getUidStats().get(UID).getSensorStats()
                .get(SENSOR_ID).getSensorTime();