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

Commit bcaffd05 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android Git Automerger
Browse files

am da4a186f: Merge "Some battery stats history fixes." into lmp-preview-dev

* commit 'da4a186f8bf49d8ea06d5ad6d402d9b073ee3841':
  Some battery stats history fixes.
parents 690d4515 0bec6388
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -931,6 +931,14 @@ public abstract class BatteryStats implements Parcelable {
        }
        }
    }
    }


    /**
     * Don't allow any more batching in to the current history event.  This
     * is called when printing partial histories, so to ensure that the next
     * history event will go in to a new batch after what was printed in the
     * last partial history.
     */
    public abstract void commitCurrentHistoryBatchLocked();

    public abstract int getHistoryTotalSize();
    public abstract int getHistoryTotalSize();


    public abstract int getHistoryUsedSize();
    public abstract int getHistoryUsedSize();
@@ -3366,6 +3374,7 @@ public abstract class BatteryStats implements Parcelable {
            }
            }
        }
        }
        if (histStart >= 0) {
        if (histStart >= 0) {
            commitCurrentHistoryBatchLocked();
            pw.print(checkin ? "NEXT: " : "  NEXT: "); pw.println(lastTime+1);
            pw.print(checkin ? "NEXT: " : "  NEXT: "); pw.println(lastTime+1);
        }
        }
    }
    }
+19 −6
Original line number Original line Diff line number Diff line
@@ -2006,6 +2006,11 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }
    }
    }


    @Override
    public void commitCurrentHistoryBatchLocked() {
        mHistoryLastWritten.cmd = HistoryItem.CMD_NULL;
    }

    void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) {
    void addHistoryBufferLocked(long elapsedRealtimeMs, long uptimeMs, HistoryItem cur) {
        if (!mHaveBatteryLevel || !mRecordingHistory) {
        if (!mHaveBatteryLevel || !mRecordingHistory) {
            return;
            return;
@@ -2342,13 +2347,16 @@ public final class BatteryStatsImpl extends BatteryStats {
            // Only care about partial wake locks, since full wake locks
            // Only care about partial wake locks, since full wake locks
            // will be canceled when the user puts the screen to sleep.
            // will be canceled when the user puts the screen to sleep.
            aggregateLastWakeupUptimeLocked(uptime);
            aggregateLastWakeupUptimeLocked(uptime);
            if (historyName == null) {
                historyName = name;
            }
            if (mRecordAllWakeLocks) {
            if (mRecordAllWakeLocks) {
                if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, name, uid, 0)) {
                if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_START, historyName,
                        uid, 0)) {
                    addHistoryEventLocked(elapsedRealtime, uptime,
                    addHistoryEventLocked(elapsedRealtime, uptime,
                            HistoryItem.EVENT_WAKE_LOCK_START, name, uid);
                            HistoryItem.EVENT_WAKE_LOCK_START, historyName, uid);
                }
                }
            }
            }
            historyName = historyName == null ? name : historyName;
            if (mWakeLockNesting == 0) {
            if (mWakeLockNesting == 0) {
                mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG;
                mHistoryCur.states |= HistoryItem.STATE_WAKE_LOCK_FLAG;
                if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: "
                if (DEBUG_HISTORY) Slog.v(TAG, "Start wake lock to: "
@@ -2358,7 +2366,8 @@ public final class BatteryStatsImpl extends BatteryStats {
                mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid;
                mHistoryCur.wakelockTag.uid = mInitialAcquireWakeUid = uid;
                mWakeLockImportant = !unimportantForLogging;
                mWakeLockImportant = !unimportantForLogging;
                addHistoryRecordLocked(elapsedRealtime, uptime);
                addHistoryRecordLocked(elapsedRealtime, uptime);
            } else if (!mWakeLockImportant && !unimportantForLogging) {
            } else if (!mWakeLockImportant && !unimportantForLogging
                    && mHistoryLastWritten.cmd == HistoryItem.CMD_UPDATE) {
                if (mHistoryLastWritten.wakelockTag != null) {
                if (mHistoryLastWritten.wakelockTag != null) {
                    // We'll try to update the last tag.
                    // We'll try to update the last tag.
                    mHistoryLastWritten.wakelockTag = null;
                    mHistoryLastWritten.wakelockTag = null;
@@ -2386,9 +2395,13 @@ public final class BatteryStatsImpl extends BatteryStats {
        if (type == WAKE_TYPE_PARTIAL) {
        if (type == WAKE_TYPE_PARTIAL) {
            mWakeLockNesting--;
            mWakeLockNesting--;
            if (mRecordAllWakeLocks) {
            if (mRecordAllWakeLocks) {
                if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, name, uid, 0)) {
                if (historyName == null) {
                    historyName = name;
                }
                if (mActiveEvents.updateState(HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName,
                        uid, 0)) {
                    addHistoryEventLocked(elapsedRealtime, uptime,
                    addHistoryEventLocked(elapsedRealtime, uptime,
                            HistoryItem.EVENT_WAKE_LOCK_FINISH, name, uid);
                            HistoryItem.EVENT_WAKE_LOCK_FINISH, historyName, uid);
                }
                }
            }
            }
            if (mWakeLockNesting == 0) {
            if (mWakeLockNesting == 0) {
+9 −5
Original line number Original line Diff line number Diff line
@@ -623,10 +623,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        pw.println("  --charged: only output data since last charged.");
        pw.println("  --charged: only output data since last charged.");
        pw.println("  --reset: reset the stats, clearing all current data.");
        pw.println("  --reset: reset the stats, clearing all current data.");
        pw.println("  --write: force write current collected stats to disk.");
        pw.println("  --write: force write current collected stats to disk.");
        pw.println("  --enable: enable an option: full-wake-history, no-auto-reset.");
        pw.println("  --disable: disable an option: full-wake-history, no-auto-reset.");
        pw.println("  -h: print this help text.");
        pw.println("  <package.name>: optional name of package to filter output by.");
        pw.println("  <package.name>: optional name of package to filter output by.");
        pw.println("  -h: print this help text.");
        pw.println("Battery stats (batterystats) commands:");
        pw.println("  enable|disable <option>");
        pw.println("    Enable or disable a running option.  Option state is not saved across boots.");
        pw.println("    Options are:");
        pw.println("      full-wake-history: include wake_lock_in battery history, full wake details.");
        pw.println("      no-auto-reset: don't automatically reset stats when unplugged");
    }
    }


    private int doEnableOrDisable(PrintWriter pw, int i, String[] args, boolean enable) {
    private int doEnableOrDisable(PrintWriter pw, int i, String[] args, boolean enable) {
@@ -702,14 +706,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                        pw.println("Battery stats written.");
                        pw.println("Battery stats written.");
                        noOutput = true;
                        noOutput = true;
                    }
                    }
                } else if ("--enable".equals(arg)) {
                } else if ("--enable".equals(arg) || "enable".equals(arg)) {
                    i = doEnableOrDisable(pw, i, args, true);
                    i = doEnableOrDisable(pw, i, args, true);
                    if (i < 0) {
                    if (i < 0) {
                        return;
                        return;
                    }
                    }
                    pw.println("Enabled: " + args[i]);
                    pw.println("Enabled: " + args[i]);
                    return;
                    return;
                } else if ("--disable".equals(arg)) {
                } else if ("--disable".equals(arg) || "disable".equals(arg)) {
                    i = doEnableOrDisable(pw, i, args, false);
                    i = doEnableOrDisable(pw, i, args, false);
                    if (i < 0) {
                    if (i < 0) {
                        return;
                        return;