Loading core/java/com/android/internal/os/BatteryStatsImpl.java +7 −3 Original line number Diff line number Diff line Loading @@ -8578,7 +8578,7 @@ public class BatteryStatsImpl extends BatteryStats { * inactive so can be dropped. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean reset(long uptimeUs, long realtimeUs) { public boolean reset(long uptimeUs, long realtimeUs, int resetReason) { boolean active = false; mOnBatteryBackgroundTimeBase.init(uptimeUs, realtimeUs); Loading Loading @@ -8648,7 +8648,11 @@ public class BatteryStatsImpl extends BatteryStats { resetIfNotNull(mBluetoothControllerActivity, false, realtimeUs); resetIfNotNull(mModemControllerActivity, false, realtimeUs); if (resetReason == RESET_REASON_MEASURED_ENERGY_BUCKETS_CHANGE) { mUidMeasuredEnergyStats = null; } else { MeasuredEnergyStats.resetIfNotNull(mUidMeasuredEnergyStats); } resetIfNotNull(mUserCpuTime, false, realtimeUs); resetIfNotNull(mSystemCpuTime, false, realtimeUs); Loading Loading @@ -11332,7 +11336,7 @@ public class BatteryStatsImpl extends BatteryStats { mNumConnectivityChange = 0; for (int i=0; i<mUidStats.size(); i++) { if (mUidStats.valueAt(i).reset(uptimeUs, elapsedRealtimeUs)) { if (mUidStats.valueAt(i).reset(uptimeUs, elapsedRealtimeUs, resetReason)) { mUidStats.valueAt(i).detachFromTimeBase(); mUidStats.remove(mUidStats.keyAt(i)); i--; Loading core/java/com/android/internal/os/CustomMeasuredPowerCalculator.java +8 −3 Original line number Diff line number Diff line Loading @@ -21,13 +21,18 @@ import android.os.BatteryStats; import android.os.BatteryUsageStats; import android.os.BatteryUsageStatsQuery; import android.os.UidBatteryConsumer; import android.util.Slog; import android.util.SparseArray; import java.util.Arrays; /** * Calculates the amount of power consumed by custom energy consumers (i.e. consumers of type * {@link android.hardware.power.stats.EnergyConsumerType#OTHER}). */ public class CustomMeasuredPowerCalculator extends PowerCalculator { private static final String TAG = "CustomMeasuredPowerCalc"; public CustomMeasuredPowerCalculator(PowerProfile powerProfile) { } Loading Loading @@ -76,9 +81,9 @@ public class CustomMeasuredPowerCalculator extends PowerCalculator { if (totalPowerMah == null) { newTotalPowerMah = new double[customMeasuredPowerMah.length]; } else if (totalPowerMah.length != customMeasuredPowerMah.length) { newTotalPowerMah = new double[customMeasuredPowerMah.length]; System.arraycopy(totalPowerMah, 0, newTotalPowerMah, 0, customMeasuredPowerMah.length); Slog.wtf(TAG, "Number of custom energy components is not the same for all apps: " + totalPowerMah.length + ", " + customMeasuredPowerMah.length); newTotalPowerMah = Arrays.copyOf(totalPowerMah, customMeasuredPowerMah.length); } else { newTotalPowerMah = totalPowerMah; } Loading core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -403,7 +403,7 @@ public class BatteryStatsSensorTest extends TestCase { assertNotNull(sensor.getSensorBackgroundTime()); // Reset the stats. Since the sensor is still running, we should still see the timer bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); sensor = uid.getSensorStats().get(SENSOR_ID); assertNotNull(sensor); Loading @@ -413,7 +413,7 @@ public class BatteryStatsSensorTest extends TestCase { bi.noteStopSensorLocked(UID, SENSOR_ID); // Now the sensor timer has stopped so this reset should also take out the sensor. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); sensor = uid.getSensorStats().get(SENSOR_ID); assertNull(sensor); Loading Loading @@ -465,7 +465,7 @@ public class BatteryStatsSensorTest extends TestCase { // Reset the stats. Since the sensor is still running, we should still see the timer // but still with 0 times. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); assertEquals(0, timer.getTotalTimeLocked(1000*clocks.realtime, which)); assertEquals(0, timer.getTotalDurationMsLocked(clocks.realtime)); assertEquals(0, bgTimer.getTotalTimeLocked(1000*clocks.realtime, which)); Loading Loading @@ -504,7 +504,7 @@ public class BatteryStatsSensorTest extends TestCase { // Reset the stats. Since the sensor is still running, we should still see the timer // but with 0 times. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); assertEquals(0, timer.getTotalTimeLocked(1000*clocks.realtime, which)); assertEquals(0, timer.getTotalDurationMsLocked(clocks.realtime)); assertEquals(0, bgTimer.getTotalTimeLocked(1000*clocks.realtime, which)); Loading Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +7 −3 Original line number Diff line number Diff line Loading @@ -8578,7 +8578,7 @@ public class BatteryStatsImpl extends BatteryStats { * inactive so can be dropped. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public boolean reset(long uptimeUs, long realtimeUs) { public boolean reset(long uptimeUs, long realtimeUs, int resetReason) { boolean active = false; mOnBatteryBackgroundTimeBase.init(uptimeUs, realtimeUs); Loading Loading @@ -8648,7 +8648,11 @@ public class BatteryStatsImpl extends BatteryStats { resetIfNotNull(mBluetoothControllerActivity, false, realtimeUs); resetIfNotNull(mModemControllerActivity, false, realtimeUs); if (resetReason == RESET_REASON_MEASURED_ENERGY_BUCKETS_CHANGE) { mUidMeasuredEnergyStats = null; } else { MeasuredEnergyStats.resetIfNotNull(mUidMeasuredEnergyStats); } resetIfNotNull(mUserCpuTime, false, realtimeUs); resetIfNotNull(mSystemCpuTime, false, realtimeUs); Loading Loading @@ -11332,7 +11336,7 @@ public class BatteryStatsImpl extends BatteryStats { mNumConnectivityChange = 0; for (int i=0; i<mUidStats.size(); i++) { if (mUidStats.valueAt(i).reset(uptimeUs, elapsedRealtimeUs)) { if (mUidStats.valueAt(i).reset(uptimeUs, elapsedRealtimeUs, resetReason)) { mUidStats.valueAt(i).detachFromTimeBase(); mUidStats.remove(mUidStats.keyAt(i)); i--; Loading
core/java/com/android/internal/os/CustomMeasuredPowerCalculator.java +8 −3 Original line number Diff line number Diff line Loading @@ -21,13 +21,18 @@ import android.os.BatteryStats; import android.os.BatteryUsageStats; import android.os.BatteryUsageStatsQuery; import android.os.UidBatteryConsumer; import android.util.Slog; import android.util.SparseArray; import java.util.Arrays; /** * Calculates the amount of power consumed by custom energy consumers (i.e. consumers of type * {@link android.hardware.power.stats.EnergyConsumerType#OTHER}). */ public class CustomMeasuredPowerCalculator extends PowerCalculator { private static final String TAG = "CustomMeasuredPowerCalc"; public CustomMeasuredPowerCalculator(PowerProfile powerProfile) { } Loading Loading @@ -76,9 +81,9 @@ public class CustomMeasuredPowerCalculator extends PowerCalculator { if (totalPowerMah == null) { newTotalPowerMah = new double[customMeasuredPowerMah.length]; } else if (totalPowerMah.length != customMeasuredPowerMah.length) { newTotalPowerMah = new double[customMeasuredPowerMah.length]; System.arraycopy(totalPowerMah, 0, newTotalPowerMah, 0, customMeasuredPowerMah.length); Slog.wtf(TAG, "Number of custom energy components is not the same for all apps: " + totalPowerMah.length + ", " + customMeasuredPowerMah.length); newTotalPowerMah = Arrays.copyOf(totalPowerMah, customMeasuredPowerMah.length); } else { newTotalPowerMah = totalPowerMah; } Loading
core/tests/coretests/src/com/android/internal/os/BatteryStatsSensorTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -403,7 +403,7 @@ public class BatteryStatsSensorTest extends TestCase { assertNotNull(sensor.getSensorBackgroundTime()); // Reset the stats. Since the sensor is still running, we should still see the timer bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); sensor = uid.getSensorStats().get(SENSOR_ID); assertNotNull(sensor); Loading @@ -413,7 +413,7 @@ public class BatteryStatsSensorTest extends TestCase { bi.noteStopSensorLocked(UID, SENSOR_ID); // Now the sensor timer has stopped so this reset should also take out the sensor. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); sensor = uid.getSensorStats().get(SENSOR_ID); assertNull(sensor); Loading Loading @@ -465,7 +465,7 @@ public class BatteryStatsSensorTest extends TestCase { // Reset the stats. Since the sensor is still running, we should still see the timer // but still with 0 times. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); assertEquals(0, timer.getTotalTimeLocked(1000*clocks.realtime, which)); assertEquals(0, timer.getTotalDurationMsLocked(clocks.realtime)); assertEquals(0, bgTimer.getTotalTimeLocked(1000*clocks.realtime, which)); Loading Loading @@ -504,7 +504,7 @@ public class BatteryStatsSensorTest extends TestCase { // Reset the stats. Since the sensor is still running, we should still see the timer // but with 0 times. bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000); bi.getUidStatsLocked(UID).reset(clocks.uptime * 1000, clocks.realtime * 1000, 0); assertEquals(0, timer.getTotalTimeLocked(1000*clocks.realtime, which)); assertEquals(0, timer.getTotalDurationMsLocked(clocks.realtime)); assertEquals(0, bgTimer.getTotalTimeLocked(1000*clocks.realtime, which)); Loading