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

Commit 6b1989c7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'wakelockTotalDuration' into oc-dev

* changes:
  Wakelock durations are 0 instead of -1 if unused
  Added actual (unpooled) partial wakelock times.
parents 2710490a 941d98fe
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -183,8 +183,10 @@ public abstract class BatteryStats implements Parcelable {
     *   - Wakelock data (wl) gets current and max times.
     * New in version 20:
     *   - Background timers and counters for: Sensor, BluetoothScan, WifiScan, Jobs, Syncs.
     * New in version 21:
     *   - Actual (not just apportioned) Wakelock time is also recorded.
     */
    static final String CHECKIN_VERSION = "20";
    static final String CHECKIN_VERSION = "21";

    /**
     * Old version, we hit 9 and ran out of room, need to remove.
@@ -205,6 +207,12 @@ public abstract class BatteryStats implements Parcelable {
    private static final String VIBRATOR_DATA = "vib";
    private static final String FOREGROUND_DATA = "fg";
    private static final String STATE_TIME_DATA = "st";
    // wl line is:
    // BATTERY_STATS_CHECKIN_VERSION, uid, which, "wl", name,
    // full totalTime,    'f', count, current duration, max duration, total duration,
    // partial totalTime, 'p', count, current duration, max duration, total duration,
    // window totalTime,  'w', count, current duration, max duration, total duration
    // [Currently, full and window wakelocks have durations current = max = total = -1]
    private static final String WAKELOCK_DATA = "wl";
    private static final String SYNC_DATA = "sy";
    private static final String JOB_DATA = "jb";
@@ -2659,6 +2667,12 @@ public abstract class BatteryStats implements Parcelable {
                    sb.append(" max=");
                    sb.append(maxDurationMs);
                }
                // Put actual time if it is available and different from totalTimeMillis.
                final long totalDurMs = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
                if (totalDurMs > totalTimeMillis) {
                    sb.append(" actual=");
                    sb.append(totalDurMs);
                }
                if (timer.isRunningLocked()) {
                    final long currentMs = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
                    if (currentMs >= 0) {
@@ -2742,13 +2756,15 @@ public abstract class BatteryStats implements Parcelable {
            long elapsedRealtimeUs, String name, int which, String linePrefix) {
        long totalTimeMicros = 0;
        int count = 0;
        long max = -1;
        long current = -1;
        long max = 0;
        long current = 0;
        long totalDuration = 0;
        if (timer != null) {
            totalTimeMicros = timer.getTotalTimeLocked(elapsedRealtimeUs, which);
            count = timer.getCountLocked(which);
            current = timer.getCurrentDurationMsLocked(elapsedRealtimeUs/1000);
            max = timer.getMaxDurationMsLocked(elapsedRealtimeUs/1000);
            totalDuration = timer.getTotalDurationMsLocked(elapsedRealtimeUs/1000);
        }
        sb.append(linePrefix);
        sb.append((totalTimeMicros + 500) / 1000); // microseconds to milliseconds with rounding
@@ -2759,6 +2775,13 @@ public abstract class BatteryStats implements Parcelable {
        sb.append(current);
        sb.append(',');
        sb.append(max);
        // Partial, full, and window wakelocks are pooled, so totalDuration is meaningful (albeit
        // not always tracked). Kernel wakelocks (which have name == null) have no notion of
        // totalDuration independent of totalTimeMicros (since they are not pooled).
        if (name != null) {
            sb.append(',');
            sb.append(totalDuration);
        }
        return ",";
    }