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

Commit 25fd3371 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by The Android Automerger
Browse files

Battery stats more wake history, power save mode.

Add new option for battery stats to record the full wake
lock history, and recording the current power save mode.

Also add in some additional error constants when generating
Binder error exceptions.

And fix issue #14974572: Avoid repeating wakeup_reason at
the beginning of history

Change-Id: I7c1a2ab9569de216634f63d8ad69f1294ef1d235
parent f2e57216
Loading
Loading
Loading
Loading
+72 −38
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import android.telephony.SignalStrength;
import android.text.format.DateFormat;
import android.text.format.DateFormat;
import android.util.Printer;
import android.util.Printer;
import android.util.SparseArray;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
import android.util.TimeUtils;
import android.util.TimeUtils;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper;
@@ -601,6 +600,7 @@ public abstract class BatteryStats implements Parcelable {
        public int states;
        public int states;


        public static final int STATE2_VIDEO_ON_FLAG = 1<<0;
        public static final int STATE2_VIDEO_ON_FLAG = 1<<0;
        public static final int STATE2_LOW_POWER_FLAG = 1<<1;
        public int states2;
        public int states2;


        // The wake lock that was acquired at this point.
        // The wake lock that was acquired at this point.
@@ -622,8 +622,11 @@ public abstract class BatteryStats implements Parcelable {
        public static final int EVENT_TOP = 0x0003;
        public static final int EVENT_TOP = 0x0003;
        // Event is about an application package that is at the top of the screen.
        // Event is about an application package that is at the top of the screen.
        public static final int EVENT_SYNC = 0x0004;
        public static final int EVENT_SYNC = 0x0004;
        // Events for all additional wake locks aquired/release within a wake block.
        // These are not generated by default.
        public static final int EVENT_WAKE_LOCK = 0x0005;
        // Number of event types.
        // Number of event types.
        public static final int EVENT_COUNT = 0x0005;
        public static final int EVENT_COUNT = 0x0006;
        // Mask to extract out only the type part of the event.
        // Mask to extract out only the type part of the event.
        public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);
        public static final int EVENT_TYPE_MASK = ~(EVENT_FLAG_START|EVENT_FLAG_FINISH);


@@ -635,6 +638,8 @@ public abstract class BatteryStats implements Parcelable {
        public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
        public static final int EVENT_TOP_FINISH = EVENT_TOP | EVENT_FLAG_FINISH;
        public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
        public static final int EVENT_SYNC_START = EVENT_SYNC | EVENT_FLAG_START;
        public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
        public static final int EVENT_SYNC_FINISH = EVENT_SYNC | EVENT_FLAG_FINISH;
        public static final int EVENT_WAKE_LOCK_START = EVENT_WAKE_LOCK | EVENT_FLAG_START;
        public static final int EVENT_WAKE_LOCK_FINISH = EVENT_WAKE_LOCK | EVENT_FLAG_FINISH;


        // For CMD_EVENT.
        // For CMD_EVENT.
        public int eventCode;
        public int eventCode;
@@ -887,6 +892,11 @@ public abstract class BatteryStats implements Parcelable {
            return true;
            return true;
        }
        }


        public void removeEvents(int code) {
            int idx = code&HistoryItem.EVENT_TYPE_MASK;
            mActiveEvents[idx] = null;
        }

        public HashMap<String, SparseIntArray> getStateForEvent(int code) {
        public HashMap<String, SparseIntArray> getStateForEvent(int code) {
            return mActiveEvents[code];
            return mActiveEvents[code];
        }
        }
@@ -996,6 +1006,21 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long getScreenBrightnessTime(int brightnessBin,
    public abstract long getScreenBrightnessTime(int brightnessBin,
            long elapsedRealtimeUs, int which);
            long elapsedRealtimeUs, int which);


    /**
     * Returns the time in microseconds that low power mode has been enabled while the device was
     * running on battery.
     *
     * {@hide}
     */
    public abstract long getLowPowerModeEnabledTime(long elapsedRealtimeUs, int which);

    /**
     * Returns the number of times that low power mode was enabled.
     *
     * {@hide}
     */
    public abstract int getLowPowerModeEnabledCount(int which);

    /**
    /**
     * Returns the time in microseconds that the phone has been on while the device was
     * Returns the time in microseconds that the phone has been on while the device was
     * running on battery.
     * running on battery.
@@ -1157,14 +1182,15 @@ public abstract class BatteryStats implements Parcelable {
    public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
    public static final BitDescription[] HISTORY_STATE2_DESCRIPTIONS
            = new BitDescription[] {
            = new BitDescription[] {
        new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
        new BitDescription(HistoryItem.STATE2_VIDEO_ON_FLAG, "video", "v"),
        new BitDescription(HistoryItem.STATE2_LOW_POWER_FLAG, "low_power", "lp"),
    };
    };


    public static final String[] HISTORY_EVENT_NAMES = new String[] {
    public static final String[] HISTORY_EVENT_NAMES = new String[] {
            "null", "proc", "fg", "top", "sync"
            "null", "proc", "fg", "top", "sync", "wake_lock_in"
    };
    };


    public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
    public static final String[] HISTORY_EVENT_CHECKIN_NAMES = new String[] {
            "Enl", "Epr", "Efg", "Etp", "Esy"
            "Enl", "Epr", "Efg", "Etp", "Esy", "Ewl"
    };
    };


    /**
    /**
@@ -1630,6 +1656,7 @@ public abstract class BatteryStats implements Parcelable {
        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 interactiveTime = getInteractiveTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
@@ -1699,7 +1726,8 @@ public abstract class BatteryStats implements Parcelable {
                mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
                mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
                fullWakeLockTimeTotal, partialWakeLockTimeTotal,
                fullWakeLockTimeTotal, partialWakeLockTimeTotal,
                0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which),
                0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which),
                getMobileRadioActiveAdjustedTime(which), interactiveTime / 1000);
                getMobileRadioActiveAdjustedTime(which), interactiveTime / 1000,
                lowPowerModeEnabledTime / 1000);
        
        
        // Dump screen brightness stats
        // Dump screen brightness stats
        Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
        Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
@@ -2092,32 +2120,20 @@ public abstract class BatteryStats implements Parcelable {


        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long lowPowerModeEnabledTime = getLowPowerModeEnabledTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
        final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
        sb.setLength(0);
        sb.setLength(0);
        sb.append(prefix);
                sb.append("  Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
                sb.append(")");
        pw.println(sb.toString());
        sb.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
                sb.append("  Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
                sb.append("  Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
                sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
                sb.append(") "); sb.append(getScreenOnCount(which));
                sb.append(") "); sb.append(getScreenOnCount(which));
                sb.append("x, Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
                sb.append("x, Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
                sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
                sb.append(")");
                sb.append(")");
        pw.println(sb.toString());
        pw.println(sb.toString());
        if (phoneOnTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
                    sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
                    sb.append(") "); sb.append(getPhoneOnCount(which));
        }
        sb.setLength(0);
        sb.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
        sb.append("  Screen brightnesses:");
        sb.append("  Screen brightnesses:");
@@ -2139,6 +2155,23 @@ public abstract class BatteryStats implements Parcelable {
        }
        }
        if (!didOne) sb.append(" (no activity)");
        if (!didOne) sb.append(" (no activity)");
        pw.println(sb.toString());
        pw.println(sb.toString());
        if (lowPowerModeEnabledTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Low power mode enabled: ");
                    formatTimeMs(sb, lowPowerModeEnabledTime / 1000);
                    sb.append("(");
                    sb.append(formatRatioLocked(lowPowerModeEnabledTime, whichBatteryRealtime));
                    sb.append(")");
            pw.println(sb.toString());
        }
        if (phoneOnTime != 0) {
            sb.setLength(0);
            sb.append(prefix);
                    sb.append("  Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
                    sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
                    sb.append(") "); sb.append(getPhoneOnCount(which));
        }


        // Calculate wakelock times across all uids.
        // Calculate wakelock times across all uids.
        long fullWakeLockTimeTotalMicros = 0;
        long fullWakeLockTimeTotalMicros = 0;
@@ -3004,6 +3037,8 @@ public abstract class BatteryStats implements Parcelable {
                pw.print(rec.numReadInts);
                pw.print(rec.numReadInts);
                pw.print(") ");
                pw.print(") ");
            } else {
            } else {
                pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                pw.print(HISTORY_DATA); pw.print(',');
                if (lastTime < 0) {
                if (lastTime < 0) {
                    pw.print(rec.time - baseTime);
                    pw.print(rec.time - baseTime);
                } else {
                } else {
@@ -3190,6 +3225,7 @@ public abstract class BatteryStats implements Parcelable {
                }
                }
                pw.println();
                pw.println();
                oldState = rec.states;
                oldState = rec.states;
                oldState2 = rec.states2;
            }
            }
        }
        }
    }
    }
@@ -3266,21 +3302,25 @@ public abstract class BatteryStats implements Parcelable {
                    if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
                    if (rec.cmd == HistoryItem.CMD_CURRENT_TIME
                            || rec.cmd == HistoryItem.CMD_RESET) {
                            || rec.cmd == HistoryItem.CMD_RESET) {
                        printed = true;
                        printed = true;
                        hprinter.printNextItem(pw, rec, baseTime, checkin,
                                (flags&DUMP_VERBOSE) != 0);
                        rec.cmd = HistoryItem.CMD_UPDATE;
                    } else if (rec.currentTime != 0) {
                    } else if (rec.currentTime != 0) {
                        printed = true;
                        printed = true;
                        byte cmd = rec.cmd;
                        byte cmd = rec.cmd;
                        rec.cmd = HistoryItem.CMD_CURRENT_TIME;
                        rec.cmd = HistoryItem.CMD_CURRENT_TIME;
                        if (checkin) {
                            pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                            pw.print(HISTORY_DATA); pw.print(',');
                        }
                        hprinter.printNextItem(pw, rec, baseTime, checkin,
                        hprinter.printNextItem(pw, rec, baseTime, checkin,
                                (flags&DUMP_VERBOSE) != 0);
                                (flags&DUMP_VERBOSE) != 0);
                        rec.cmd = cmd;
                        rec.cmd = cmd;
                    }
                    }
                    if (tracker != null) {
                    if (tracker != null) {
                        int oldCode = rec.eventCode;
                        if (rec.cmd != HistoryItem.CMD_UPDATE) {
                        HistoryTag oldTag = rec.eventTag;
                            hprinter.printNextItem(pw, rec, baseTime, checkin,
                                    (flags&DUMP_VERBOSE) != 0);
                            rec.cmd = HistoryItem.CMD_UPDATE;
                        }
                        int oldEventCode = rec.eventCode;
                        HistoryTag oldEventTag = rec.eventTag;
                        rec.eventTag = new HistoryTag();
                        rec.eventTag = new HistoryTag();
                        for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
                        for (int i=0; i<HistoryItem.EVENT_COUNT; i++) {
                            HashMap<String, SparseIntArray> active
                            HashMap<String, SparseIntArray> active
@@ -3296,24 +3336,18 @@ public abstract class BatteryStats implements Parcelable {
                                    rec.eventTag.string = ent.getKey();
                                    rec.eventTag.string = ent.getKey();
                                    rec.eventTag.uid = uids.keyAt(j);
                                    rec.eventTag.uid = uids.keyAt(j);
                                    rec.eventTag.poolIdx = uids.valueAt(j);
                                    rec.eventTag.poolIdx = uids.valueAt(j);
                                    if (checkin) {
                                        pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                                        pw.print(HISTORY_DATA); pw.print(',');
                                    }
                                    hprinter.printNextItem(pw, rec, baseTime, checkin,
                                    hprinter.printNextItem(pw, rec, baseTime, checkin,
                                            (flags&DUMP_VERBOSE) != 0);
                                            (flags&DUMP_VERBOSE) != 0);
                                    rec.wakeReasonTag = null;
                                    rec.wakelockTag = null;
                                }
                                }
                            }
                            }
                        }
                        }
                        rec.eventCode = oldCode;
                        rec.eventCode = oldEventCode;
                        rec.eventTag = oldTag;
                        rec.eventTag = oldEventTag;
                        tracker = null;
                        tracker = null;
                    }
                    }
                }
                }
                if (checkin) {
                    pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
                    pw.print(HISTORY_DATA); pw.print(',');
                }
                hprinter.printNextItem(pw, rec, baseTime, checkin,
                hprinter.printNextItem(pw, rec, baseTime, checkin,
                        (flags&DUMP_VERBOSE) != 0);
                        (flags&DUMP_VERBOSE) != 0);
            } else if (rec.eventCode != HistoryItem.EVENT_NONE) {
            } else if (rec.eventCode != HistoryItem.EVENT_NONE) {
+8 −0
Original line number Original line Diff line number Diff line
@@ -55,6 +55,14 @@ public abstract class PowerManagerInternal {
     */
     */
    public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
    public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);


    public abstract boolean getLowPowerModeEnabled();

    public interface LowPowerModeListener {
        public void onLowPowerModeChanged(boolean enabled);
    }

    public abstract void registerLowPowerModeObserver(LowPowerModeListener listener);

    // TODO: Remove this and retrieve as a local service instead.
    // TODO: Remove this and retrieve as a local service instead.
    public abstract void setPolicy(WindowManagerPolicy policy);
    public abstract void setPolicy(WindowManagerPolicy policy);
}
}
+5 −4
Original line number Original line Diff line number Diff line
@@ -46,14 +46,15 @@ interface IBatteryStats {


    void noteStartWakelock(int uid, int pid, String name, String historyName,
    void noteStartWakelock(int uid, int pid, String name, String historyName,
            int type, boolean unimportantForLogging);
            int type, boolean unimportantForLogging);
    void noteStopWakelock(int uid, int pid, String name, int type);
    void noteStopWakelock(int uid, int pid, String name, String historyName, int type);


    void noteStartWakelockFromSource(in WorkSource ws, int pid, String name, String historyName,
    void noteStartWakelockFromSource(in WorkSource ws, int pid, String name, String historyName,
            int type, boolean unimportantForLogging);
            int type, boolean unimportantForLogging);
    void noteChangeWakelockFromSource(in WorkSource ws, int pid, String name, int type,
    void noteChangeWakelockFromSource(in WorkSource ws, int pid, String name, String histyoryName,
            in WorkSource newWs, int newPid, String newName,
            int type, in WorkSource newWs, int newPid, String newName,
            String newHistoryName, int newType, boolean newUnimportantForLogging);
            String newHistoryName, int newType, boolean newUnimportantForLogging);
    void noteStopWakelockFromSource(in WorkSource ws, int pid, String name, int type);
    void noteStopWakelockFromSource(in WorkSource ws, int pid, String name, String historyName,
            int type);


    void noteVibratorOn(int uid, long durationMillis);
    void noteVibratorOn(int uid, long durationMillis);
    void noteVibratorOff(int uid);
    void noteVibratorOff(int uid);
+94 −31

File changed.

Preview size limit exceeded, changes collapsed.

+32 −0
Original line number Original line Diff line number Diff line
@@ -697,6 +697,38 @@ void signalExceptionForError(JNIEnv* env, jobject obj, status_t err,
            jniThrowException(env, "java/lang/RuntimeException",
            jniThrowException(env, "java/lang/RuntimeException",
                    "Not allowed to write file descriptors here");
                    "Not allowed to write file descriptors here");
            break;
            break;
        case -EBADF:
            jniThrowException(env, "java/lang/RuntimeException",
                    "Bad file descriptor");
            break;
        case -ENFILE:
            jniThrowException(env, "java/lang/RuntimeException",
                    "File table overflow");
            break;
        case -EMFILE:
            jniThrowException(env, "java/lang/RuntimeException",
                    "Too many open files");
            break;
        case -EFBIG:
            jniThrowException(env, "java/lang/RuntimeException",
                    "File too large");
            break;
        case -ENOSPC:
            jniThrowException(env, "java/lang/RuntimeException",
                    "No space left on device");
            break;
        case -ESPIPE:
            jniThrowException(env, "java/lang/RuntimeException",
                    "Illegal seek");
            break;
        case -EROFS:
            jniThrowException(env, "java/lang/RuntimeException",
                    "Read-only file system");
            break;
        case -EMLINK:
            jniThrowException(env, "java/lang/RuntimeException",
                    "Too many links");
            break;
        default:
        default:
            ALOGE("Unknown binder error code. 0x%" PRIx32, err);
            ALOGE("Unknown binder error code. 0x%" PRIx32, err);
            String8 msg;
            String8 msg;
Loading