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

Commit 43b116d5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix background sensor usage counter"

parents d89cf81f 154d124a
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();