Merge "Fix background sensor usage counter"
This commit is contained in:
committed by
Android (Google) Code Review
commit
43b116d5fa
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user