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 Original line Diff line number Diff line
@@ -217,8 +217,10 @@ public abstract class BatteryStats implements Parcelable {
     *   - Package wakeup alarms are now on screen-off timebase
     *   - Package wakeup alarms are now on screen-off timebase
     * New in version 26:
     * New in version 26:
     *   - Resource power manager (rpm) states [but screenOffRpm is disabled from working properly]
     *   - 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.
     * 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_PHONE_SCANNING_FLAG = 1<<21;
        public static final int STATE_SCREEN_ON_FLAG = 1<<20;       // consider moving to states2
        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
        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
        // empty slot
        public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;
        public static final int STATE_WIFI_MULTICAST_ON_FLAG = 1<<16;


        public static final int MOST_INTERESTING_STATES =
        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;
        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);
    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 abstract long getInteractiveTime(long elapsedRealtimeUs, int which);


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


    public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS
    public static final BitDescription[] HISTORY_STATE_DESCRIPTIONS = new BitDescription[] {
            = new BitDescription[] {
        new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
        new BitDescription(HistoryItem.STATE_CPU_RUNNING_FLAG, "running", "r"),
        new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
        new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock", "w"),
        new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor", "s"),
        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_AUDIO_ON_FLAG, "audio", "a"),
        new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
        new BitDescription(HistoryItem.STATE_SCREEN_ON_FLAG, "screen", "S"),
        new BitDescription(HistoryItem.STATE_BATTERY_PLUGGED_FLAG, "plugged", "BP"),
        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,
        new BitDescription(HistoryItem.STATE_DATA_CONNECTION_MASK,
                HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
                HistoryItem.STATE_DATA_CONNECTION_SHIFT, "data_conn", "Pcn",
                DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
                DATA_CONNECTION_NAMES, DATA_CONNECTION_NAMES),
@@ -2466,6 +2483,18 @@ public abstract class BatteryStats implements Parcelable {
     */
     */
    public abstract int getDischargeAmountScreenOffSinceCharge();
    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.
     * 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);
    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 curTime the elapsed realtime in microseconds.
     * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
     * @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);
    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 curTime the current elapsed realtime in microseconds.
     * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT.
     * @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,
     * Return the amount of battery discharge while the screen was off, measured in
     * measured in micro-Ampere-hours. This will be non-zero only if the device's battery has
     * micro-Ampere-hours. This will be non-zero only if the device's battery has
     * a coulomb counter.
     * 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
     * micro-Ampere-hours. This will be non-zero only if the device's battery has
     * a coulomb counter.
     * 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
     * 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 totalRealtime = computeRealtime(rawRealtime, which);
        final long totalUptime = computeUptime(rawUptime, which);
        final long totalUptime = computeUptime(rawUptime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenDozeTime = getScreenDozeTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
        final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
        final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
        final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT,
@@ -3124,9 +3160,9 @@ public abstract class BatteryStats implements Parcelable {
                rawRealtime, which);
                rawRealtime, which);
        final int connChanges = getNumConnectivityChange(which);
        final int connChanges = getNumConnectivityChange(which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
        final long dischargeCount = getMahDischarge(which);
        final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter()
        final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
                .getCountLocked(which);
        final long dischargeScreenDozeCount = getMahDischargeScreenDoze(which);


        final StringBuilder sb = new StringBuilder(128);
        final StringBuilder sb = new StringBuilder(128);


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




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


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


        final StringBuilder sb = new StringBuilder(128);
        final StringBuilder sb = new StringBuilder(128);


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

        sb.setLength(0);
        sb.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
        sb.append("  Time on battery screen off: ");
        sb.append("  Time on battery screen off: ");
        formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
        formatTimeMs(sb, whichBatteryScreenOffRealtime / 1000); sb.append("(");
                sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, totalRealtime));
        sb.append(formatRatioLocked(whichBatteryScreenOffRealtime, whichBatteryRealtime));
        sb.append(") realtime, ");
        sb.append(") realtime, ");
        formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
        formatTimeMs(sb, whichBatteryScreenOffUptime / 1000);
        sb.append("(");
        sb.append("(");
                sb.append(formatRatioLocked(whichBatteryScreenOffUptime, totalRealtime));
        sb.append(formatRatioLocked(whichBatteryScreenOffUptime, whichBatteryRealtime));
        sb.append(") uptime");
        sb.append(") uptime");
        pw.println(sb.toString());
        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.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
                sb.append("  Total run time: ");
                sb.append("  Total run time: ");
@@ -3910,8 +3960,7 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
            pw.println(sb.toString());
        }
        }


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


        final LongCounter dischargeScreenOffCounter = getDischargeScreenOffCoulombCounter();
        final long dischargeScreenOffCount = getMahDischargeScreenOff(which);
        final long dischargeScreenOffCount = dischargeScreenOffCounter.getCountLocked(which);
        if (dischargeScreenOffCount >= 0) {
        if (dischargeScreenOffCount >= 0) {
            sb.setLength(0);
            sb.setLength(0);
            sb.append(prefix);
            sb.append(prefix);
@@ -3932,7 +3980,18 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(sb.toString());
            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) {
        if (dischargeScreenOnCount >= 0) {
            sb.setLength(0);
            sb.setLength(0);
            sb.append(prefix);
            sb.append(prefix);
@@ -4343,6 +4402,8 @@ public abstract class BatteryStats implements Parcelable {
            pw.println(getDischargeAmountScreenOn());
            pw.println(getDischargeAmountScreenOn());
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.println(getDischargeAmountScreenOff());
            pw.println(getDischargeAmountScreenOff());
            pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
            pw.println(getDischargeAmountScreenDoze());
            pw.println(" ");
            pw.println(" ");
        } else {
        } else {
            pw.print(prefix); pw.println("  Device battery use since last full charge");
            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.println(getDischargeAmountScreenOnSinceCharge());
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.print(prefix); pw.print("    Amount discharged while screen off: ");
            pw.println(getDischargeAmountScreenOffSinceCharge());
            pw.println(getDischargeAmountScreenOffSinceCharge());
            pw.print(prefix); pw.print("    Amount discharged while screen doze: ");
            pw.println(getDischargeAmountScreenDozeSinceCharge());
            pw.println();
            pw.println();
        }
        }


Loading