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

Commit 94434759 authored by Mike Ma's avatar Mike Ma Committed by Android (Google) Code Review
Browse files

Merge "Add AOD metrics in batterystats"

parents a437d577 c2f518a9
Loading
Loading
Loading
Loading
+114 −51
Original line number Diff line number Diff line
@@ -217,8 +217,10 @@ public abstract class BatteryStats implements Parcelable {
     *   - Package wakeup alarms are now on screen-off timebase
     * New in version 26:
     *   - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
     * New in version 27:
     *   - Always On Display (screen doze mode) time and power
     */
    static final String CHECKIN_VERSION = "26";
    static final String CHECKIN_VERSION = "27";

    /**
     * Old version, we hit 9 and ran out of room, need to remove.
@@ -1381,12 +1383,12 @@ public abstract class BatteryStats implements Parcelable {
        public static final int STATE_PHONE_SCANNING_FLAG = 1<<21;
        public static final int STATE_SCREEN_ON_FLAG = 1<<20;       // consider moving to states2
        public static final int STATE_BATTERY_PLUGGED_FLAG = 1<<19; // consider moving to states2
        // empty slot
        public static final int STATE_SCREEN_DOZE_FLAG = 1 << 18;
        // empty slot
        public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;

        public static final int MOST_INTERESTING_STATES =
            STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG;
                STATE_BATTERY_PLUGGED_FLAG | STATE_SCREEN_ON_FLAG | STATE_SCREEN_DOZE_FLAG;

        public static final int SETTLE_TO_ZERO_STATES = 0xffff0000 & ~MOST_INTERESTING_STATES;

@@ -1863,6 +1865,21 @@ public abstract class BatteryStats implements Parcelable {
     */
    public abstract int getScreenOnCount(int which);

    /**
     * Returns the time in microseconds that the screen has been dozing while the device was
     * running on battery.
     *
     * {@hide}
     */
    public abstract long getScreenDozeTime(long elapsedRealtimeUs, int which);

    /**
     * Returns the number of times the screen was turned dozing.
     *
     * {@hide}
     */
    public abstract int getScreenDozeCount(int which);

    public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);

    public static final int SCREEN_BRIGHTNESS_DARK = 0;
@@ -2116,8 +2133,7 @@ public abstract class BatteryStats implements Parcelable {
        "group", "compl", "dorm", "uninit"
    };

    public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
            = new BitDescription[] {
    public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
        new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
        new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
        new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
@@ -2131,6 +2147,7 @@ public abstract class BatteryStats implements Parcelable {
        new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio", "a"),
        new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
        new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
        new BitDescription(HistoryItem.STATE_SCREEN_DOZE_FLAG, "screen_doze", "Sd"),
        new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
                HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
                DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
@@ -2466,6 +2483,18 @@ public abstract class BatteryStats implements Parcelable {
     */
    public abstract int getDischargeAmountScreenOffSinceCharge();

    /**
     * Get the amount the battery has discharged while the screen was doze,
     * since the last time power was unplugged.
     */
    public abstract int getDischargeAmountScreenDoze();

    /**
     * Get the amount the battery has discharged while the screen was doze,
     * since the last time the device was charged.
     */
    public abstract int getDischargeAmountScreenDozeSinceCharge();

    /**
     * Returns the total, last, or current battery uptime in microseconds.
     *
@@ -2483,7 +2512,7 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long computeBatteryRealtime(long curTime, int which);

    /**
     * Returns the total, last, or current battery screen off uptime in microseconds.
     * Returns the total, last, or current battery screen off/doze uptime in microseconds.
     *
     * @param curTime the elapsed realtime in microseconds.
     * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
@@ -2491,7 +2520,7 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long computeBatteryScreenOffUptime(long curTime, int which);

    /**
     * Returns the total, last, or current battery screen off realtime in microseconds.
     * Returns the total, last, or current battery screen off/doze realtime in microseconds.
     *
     * @param curTime the current elapsed realtime in microseconds.
     * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
@@ -2590,18 +2619,24 @@ public abstract class BatteryStats implements Parcelable {
    };

    /**
     * Return the counter keeping track of the amount of battery discharge while the screen was off,
     * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
     * Return the amount of battery discharge while the screen was off, measured in
     * micro-Ampere-hours. This will be non-zero only if the device's battery has
     * a coulomb counter.
     */
    public abstract LongCounter getDischargeScreenOffCoulombCounter();
    public abstract long getMahDischargeScreenOff(int which);

    /**
     * Return the counter keeping track of the amount of battery discharge measured in
     * Return the amount of battery discharge while the screen was in doze mode, measured in
     * micro-Ampere-hours. This will be non-zero only if the device's battery has
     * a coulomb counter.
     */
    public abstract LongCounter getDischargeCoulombCounter();
    public abstract long getMahDischargeScreenDoze(int which);

    /**
     * Return the amount of battery discharge  measured in micro-Ampere-hours. This will be
     * non-zero only if the device's battery has a coulomb counter.
     */
    public abstract long getMahDischarge(int which);

    /**
     * Returns the estimated real battery capacity, which may be less than the capacity
@@ -3112,6 +3147,7 @@ public abstract class BatteryStats implements Parcelable {
        final long totalRealtime = computeRealtime(rawRealtime, which);
        final long totalUptime = computeUptime(rawUptime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
        final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
@@ -3124,9 +3160,9 @@ public abstract class BatteryStats implements Parcelable {
                rawRealtime, which);
        final int connChanges = getNumConnectivityChange(which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
        final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
                .getCountLocked(which);
        final long dischargeCount = getMahDischarge(which);
        final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
        final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which);

        final StringBuilder sb = new StringBuilder(128);

@@ -3143,7 +3179,8 @@ public abstract class BatteryStats implements Parcelable {
                getStartClockTime(),
                whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000,
                getEstimatedBatteryCapacity(),
                getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity());
                getMinLearnedBatteryCapacity(), getMaxLearnedBatteryCapacity(),
                screenDozeTime / 1000);


        // Calculate wakelock times across all uids.
@@ -3295,13 +3332,15 @@ public abstract class BatteryStats implements Parcelable {
                    getDischargeStartLevel()-getDischargeCurrentLevel(),
                    getDischargeStartLevel()-getDischargeCurrentLevel(),
                    getDischargeAmountScreenOn(), getDischargeAmountScreenOff(),
                    dischargeCount / 1000, dischargeScreenOffCount / 1000);
                    dischargeCount / 1000, dischargeScreenOffCount / 1000,
                    getDischargeAmountScreenDoze(), dischargeScreenDozeCount / 1000);
        } else {
            dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
                    getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
                    getDischargeAmountScreenOnSinceCharge(),
                    getDischargeAmountScreenOffSinceCharge(),
                    dischargeCount / 1000, dischargeScreenOffCount / 1000);
                    dischargeCount / 1000, dischargeScreenOffCount / 1000,
                    getDischargeAmountScreenDozeSinceCharge(), dischargeScreenDozeCount / 1000);
        }

        if (reqUid < 0) {
@@ -3831,6 +3870,7 @@ public abstract class BatteryStats implements Parcelable {
                which);
        final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime);
        final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime);
        final long screenDozeTime = getScreenDozeTime(rawRealtime, which);

        final StringBuilder sb = new StringBuilder(128);

@@ -3873,20 +3913,30 @@ public abstract class BatteryStats implements Parcelable {
        sb.append(formatRatioLocked(whichBatteryRealtime, totalRealtime));
        sb.append(") realtime, ");
        formatTimeMs(sb, whichBatteryUptime / 1000);
                sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, totalRealtime));
        sb.append("("); sb.append(formatRatioLocked(whichBatteryUptime, whichBatteryRealtime));
        sb.append(") uptime");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.append(prefix);
        sb.append("  Time on battery screen off: ");
        formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
                sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
        sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
        sb.append(") realtime, ");
        formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
        sb.append("(");
                sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
        sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
        sb.append(") uptime");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.append(prefix);
        sb.append("  Time on battery screen doze: ");
        formatTimeMs(sb, screenDozeTime / 1000); sb.append("(");
        sb.append(formatRatioLocked(screenDozeTime, whichBatteryRealtime));
        sb.append(")");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.append(prefix);
                sb.append("  Total run time: ");
@@ -3910,8 +3960,7 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
        }

        final LongCounter dischargeCounter = getDischargeCoulombCounter();
        final long dischargeCount = dischargeCounter.getCountLocked(which);
        final long dischargeCount = getMahDischarge(which);
        if (dischargeCount >= 0) {
            sb.setLength(0);
            sb.append(prefix);
@@ -3921,8 +3970,7 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
        }

        final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
        final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
        final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
        if (dischargeScreenOffCount >= 0) {
            sb.setLength(0);
            sb.append(prefix);
@@ -3932,7 +3980,18 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
        }

        final long dischargeScreenOnCount = dischargeCount - dischargeScreenOffCount;
        final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which);
        if (dischargeScreenDozeCount >= 0) {
            sb.setLength(0);
            sb.append(prefix);
            sb.append("  Screen doze discharge: ");
            sb.append(BatteryStatsHelper.makemAh(dischargeScreenDozeCount / 1000.0));
            sb.append(" mAh");
            pw.println(sb.toString());
        }

        final long dischargeScreenOnCount =
                dischargeCount - dischargeScreenOffCount - dischargeScreenDozeCount;
        if (dischargeScreenOnCount >= 0) {
            sb.setLength(0);
            sb.append(prefix);
@@ -4343,6 +4402,8 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(getDischargeAmountScreenOn());
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.println(getDischargeAmountScreenOff());
            pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
            pw.println(getDischargeAmountScreenDoze());
            pw.println(" ");
        } else {
            pw.print(prefix); pw.println("  Device battery use since last full charge");
@@ -4354,6 +4415,8 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(getDischargeAmountScreenOnSinceCharge());
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.println(getDischargeAmountScreenOffSinceCharge());
            pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
            pw.println(getDischargeAmountScreenDozeSinceCharge());
            pw.println();
        }

+204 −75

File changed.

Preview size limit exceeded, changes collapsed.

+19 −18
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.BatteryStats;
import android.os.WorkSource;
import android.support.test.filters.SmallTest;
import android.util.ArrayMap;
import android.view.Display;

import junit.framework.TestCase;

@@ -44,7 +45,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {
        // Off-battery, non-existent
        clocks.realtime = clocks.uptime = 10;
        cur = clocks.realtime * 1000;
        bi.updateTimeBasesLocked(false, false, cur, cur); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, cur, cur); // off battery
        assertFalse(bgtb.isRunning());
        assertEquals(0, bgtb.computeRealtime(cur, STATS_SINCE_CHARGED));

@@ -65,7 +66,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {
        // On-battery, background
        clocks.realtime = clocks.uptime = 303;
        cur = clocks.realtime * 1000;
        bi.updateTimeBasesLocked(true, false, cur, cur); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, cur, cur); // on battery
        // still in ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
        assertTrue(bgtb.isRunning());
        assertEquals(0, bgtb.computeRealtime(cur, STATS_SINCE_CHARGED));
@@ -73,7 +74,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {
        // On-battery, background - but change screen state
        clocks.realtime = clocks.uptime = 409;
        cur = clocks.realtime * 1000;
        bi.updateTimeBasesLocked(true, true, cur, cur); // on battery (again)
        bi.updateTimeBasesLocked(true, Display.STATE_OFF, cur, cur); // on battery (again)
        assertTrue(bgtb.isRunning());
        assertEquals(106_000, bgtb.computeRealtime(cur, STATS_SINCE_CHARGED));

@@ -87,7 +88,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {
        // Off-battery, foreground
        clocks.realtime = clocks.uptime = 530;
        cur = clocks.realtime * 1000;
        bi.updateTimeBasesLocked(false, false, cur, cur); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, cur, cur); // off battery
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
        assertFalse(bgtb.isRunning());
        assertEquals(227_000, bgtb.computeRealtime(cur, STATS_SINCE_CHARGED));
@@ -112,17 +113,17 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {
        // battery=off, screen=off, background=off
        cur = (clocks.realtime = clocks.uptime = 100) * 1000;
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
        bi.updateTimeBasesLocked(false, false, cur, cur);
        bi.updateTimeBasesLocked(false, Display.STATE_ON, cur, cur);
        assertFalse(bgtb.isRunning());

        // battery=on, screen=off, background=off
        cur = (clocks.realtime = clocks.uptime = 200) * 1000;
        bi.updateTimeBasesLocked(true, false, cur, cur);
        bi.updateTimeBasesLocked(true, Display.STATE_ON, cur, cur);
        assertFalse(bgtb.isRunning());

        // battery=on, screen=on, background=off
        cur = (clocks.realtime = clocks.uptime = 300) * 1000;
        bi.updateTimeBasesLocked(true, true, cur, cur);
        bi.updateTimeBasesLocked(true, Display.STATE_OFF, cur, cur);
        assertFalse(bgtb.isRunning());

        // battery=on, screen=on, background=on
@@ -133,12 +134,12 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // battery=on, screen=off, background=on
        cur = (clocks.realtime = clocks.uptime = 550) * 1000;
        bi.updateTimeBasesLocked(true, false, cur, cur);
        bi.updateTimeBasesLocked(true, Display.STATE_ON, cur, cur);
        assertFalse(bgtb.isRunning());

        // battery=off, screen=off, background=on
        cur = (clocks.realtime = clocks.uptime = 660) * 1000;
        bi.updateTimeBasesLocked(false, false, cur, cur);
        bi.updateTimeBasesLocked(false, Display.STATE_ON, cur, cur);
        assertFalse(bgtb.isRunning());

        // battery=off, screen=off, background=off
@@ -157,7 +158,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // On battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 100);
        bi.updateTimeBasesLocked(true, false, curr, curr); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery
        // App in foreground
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);

@@ -171,7 +172,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // Off battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 305);
        bi.updateTimeBasesLocked(false, false, curr, curr); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, curr, curr); // off battery

        // Stop timer
        curr = 1000 * (clocks.realtime = clocks.uptime = 409);
@@ -200,7 +201,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // On battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 100);
        bi.updateTimeBasesLocked(true, false, curr, curr); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery

        // App in foreground
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);
@@ -215,7 +216,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // Off battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 305);
        bi.updateTimeBasesLocked(false, false, curr, curr); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, curr, curr); // off battery

        // Start timer (unoptimized)
        curr = 1000 * (clocks.realtime = clocks.uptime = 1000);
@@ -223,7 +224,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // On battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 2001);
        bi.updateTimeBasesLocked(true, false, curr, curr); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery

        // Move to foreground
        curr = 1000 * (clocks.realtime = clocks.uptime = 3004);
@@ -270,7 +271,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // On battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 100);
        bi.updateTimeBasesLocked(true, false, curr, curr); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery
        // App in foreground
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);

@@ -292,7 +293,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // Off battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 305);
        bi.updateTimeBasesLocked(false, false, curr, curr); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, curr, curr); // off battery

        // Stop timer
        curr = 1000 * (clocks.realtime = clocks.uptime = 409);
@@ -331,7 +332,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // On battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 100);
        bi.updateTimeBasesLocked(true, false, curr, curr); // on battery
        bi.updateTimeBasesLocked(true, Display.STATE_ON, curr, curr); // on battery
        // App in foreground
        bi.noteUidProcessStateLocked(UID, ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND);

@@ -353,7 +354,7 @@ public class BatteryStatsBackgroundStatsTest extends TestCase {

        // Off battery
        curr = 1000 * (clocks.realtime = clocks.uptime = 305);
        bi.updateTimeBasesLocked(false, false, curr, curr); // off battery
        bi.updateTimeBasesLocked(false, Display.STATE_ON, curr, curr); // off battery

        // Stop timer
        curr = 1000 * (clocks.realtime = clocks.uptime = 409);
+17 −16
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.UserHandle;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.SparseLongArray;
import android.view.Display;

import com.android.internal.util.ArrayUtils;

@@ -179,7 +180,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testUpdateClusterSpeedTimes() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);
        final long[][] clusterSpeedTimesMs = {{20, 30}, {40, 50, 60}};
        initKernelCpuSpeedReaders(clusterSpeedTimesMs.length);
        for (int i = 0; i < clusterSpeedTimesMs.length; ++i) {
@@ -224,7 +225,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuTimesLocked() {
        //PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);
        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
        final int[] testUids = getUids(testUserId, new int[] {
@@ -295,7 +296,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuTimesLocked_isolatedUid() {
        //PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);
        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
        final int isolatedAppId = FIRST_ISOLATED_UID + 27;
@@ -382,7 +383,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuTimesLocked_invalidUid() {
        //PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);
        final int testUserId = 11;
        final int invalidUserId = 15;
        final int invalidUid = UserHandle.getUid(invalidUserId, FIRST_APPLICATION_UID + 99);
@@ -427,7 +428,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuTimesLocked_withPartialTimers() {
        //PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);
        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
        final int[] testUids = getUids(testUserId, new int[] {
@@ -509,7 +510,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuFreqTimesLocked() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
@@ -550,7 +551,7 @@ public class BatteryStatsCpuTimesTest {
        // Repeat the test when the screen is off.

        // PRECONDITIONS
        updateTimeBasesLocked(true, true, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_OFF, 0, 0);
        final long[][] deltasMs = {
                {3, 12, 55, 100, 32},
                {3248327490475l, 232349349845043l, 123, 2398, 0},
@@ -584,7 +585,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuFreqTimesLocked_perClusterTimesAvailable() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
@@ -644,7 +645,7 @@ public class BatteryStatsCpuTimesTest {
        // Repeat the test when the screen is off.

        // PRECONDITIONS
        updateTimeBasesLocked(true, true, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_OFF, 0, 0);
        final long[][] deltasMs = {
                {3, 12, 55, 100, 32},
                {3248327490475l, 232349349845043l, 123, 2398, 0},
@@ -688,7 +689,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuFreqTimesLocked_partialTimers() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
@@ -792,7 +793,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuFreqTimesLocked_freqsChanged() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
@@ -833,7 +834,7 @@ public class BatteryStatsCpuTimesTest {
        // Repeat the test with the freqs from proc file changed.

        // PRECONDITIONS
        updateTimeBasesLocked(true, true, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_OFF, 0, 0);
        final long[][] deltasMs = {
                {3, 12, 55, 100, 32, 34984, 27983},
                {3248327490475l, 232349349845043l, 123, 2398, 0, 398, 0},
@@ -867,7 +868,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUidCpuFreqTimesLocked_isolatedUid() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        when(mUserInfoProvider.exists(testUserId)).thenReturn(true);
@@ -961,7 +962,7 @@ public class BatteryStatsCpuTimesTest {
    @Test
    public void testReadKernelUiidCpuFreqTimesLocked_invalidUid() {
        // PRECONDITIONS
        updateTimeBasesLocked(true, false, 0, 0);
        updateTimeBasesLocked(true, Display.STATE_ON, 0, 0);

        final int testUserId = 11;
        final int invalidUserId = 15;
@@ -1008,12 +1009,12 @@ public class BatteryStatsCpuTimesTest {
        verify(mKernelUidCpuFreqTimeReader).removeUid(invalidUid);
    }

    private void updateTimeBasesLocked(boolean unplugged, boolean screenOff,
    private void updateTimeBasesLocked(boolean unplugged, int screenState,
            long upTime, long realTime) {
        // Set PowerProfile=null before calling updateTimeBasesLocked to avoid execution of
        // BatteryStatsImpl.updateCpuTimeLocked
        mBatteryStatsImpl.setPowerProfile(null);
        mBatteryStatsImpl.updateTimeBasesLocked(unplugged, screenOff, upTime, realTime);
        mBatteryStatsImpl.updateTimeBasesLocked(unplugged, screenState, upTime, realTime);
        mBatteryStatsImpl.setPowerProfile(mPowerProfile);
    }

+47 −3

File changed.

Preview size limit exceeded, changes collapsed.

Loading