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

Commit 0a426db7 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov Committed by Android (Google) Code Review
Browse files

Merge "Drop per-app measured energy when an OTA changes the set of energy components"

parents d325dc82 9cb96030
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -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);
@@ -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);
@@ -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--;
+8 −3
Original line number Diff line number Diff line
@@ -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) {
    }

@@ -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;
            }
+4 −4
Original line number Diff line number Diff line
@@ -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);
@@ -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);
@@ -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));
@@ -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));