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
This commit is contained in:
Amith Yamasani
2017-02-16 10:01:48 -08:00
parent b3f417ec3a
commit 154d124ace
2 changed files with 13 additions and 12 deletions

View File

@@ -7914,12 +7914,11 @@ public class BatteryStatsImpl extends BatteryStats {
}
public void noteStartSensor(int sensor, long elapsedRealtimeMs) {
StopwatchTimer t = getSensorTimerLocked(sensor, true);
if (t != null) {
t.startRunningLocked(elapsedRealtimeMs);
}
Counter c = getSensorBgCounterLocked(sensor, true);
if (c != null && mProcessState >= PROCESS_STATE_BACKGROUND) {
StopwatchTimer t = getSensorTimerLocked(sensor, /* create= */ true);
t.startRunningLocked(elapsedRealtimeMs);
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) {
t.startRunningLocked(elapsedRealtimeMs);
}
Counter c = getSensorBgCounterLocked(Sensor.GPS, true);
if (c != null && mProcessState >= PROCESS_STATE_BACKGROUND) {
StopwatchTimer t = getSensorTimerLocked(Sensor.GPS, /* create= */ true);
t.startRunningLocked(elapsedRealtimeMs);
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);

View File

@@ -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();