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

Commit 10d1b767 authored by Dhavalkumar Chaudhary's avatar Dhavalkumar Chaudhary
Browse files

Restricted the batteryStats human readable strings dumping to bugreport

- Value can be configured from config file and can be overlaid

Bug: 403599628

Test: presubmit
Flag: EXEMPT new feature
Change-Id: Ic88a89e9ef7ac68a1433e28c7fdea87556278530
parent 6025b7d0
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -7644,7 +7644,8 @@ public abstract class BatteryStats {
    public static final int DUMP_DEVICE_WIFI_ONLY = 1<<6;
    public static final int DUMP_DEBUG_PERF_BASELINE = 1 << 7;

    private void dumpHistory(PrintWriter pw, int flags, long histStart, boolean checkin) {
    private void dumpHistory(PrintWriter pw, int flags, long histStart, boolean checkin,
                              long monotonicClockStart) {
        final HistoryPrinter hprinter = new HistoryPrinter(flags);
        synchronized (this) {
            if (!checkin) {
@@ -7675,7 +7676,8 @@ public abstract class BatteryStats {
        boolean printed = false;
        HistoryEventTracker tracker = null;
        try (BatteryStatsHistoryIterator iterator =
                     iterateBatteryStatsHistory(0, MonotonicClock.UNDEFINED)) {
                     iterateBatteryStatsHistory(monotonicClockStart,
                         MonotonicClock.UNDEFINED)) {
            HistoryItem rec;
            while ((rec = iterator.next()) != null) {
                try {
@@ -7838,7 +7840,7 @@ public abstract class BatteryStats {
     */
    @SuppressWarnings("unused")
    public void dump(Context context, PrintWriter pw, int flags, int reqUid, long histStart,
            BatteryStatsDumpHelper dumpHelper) {
            BatteryStatsDumpHelper dumpHelper, long monotonicClockStart) {
        synchronized (this) {
            prepareForDumpLocked();
        }
@@ -7847,7 +7849,7 @@ public abstract class BatteryStats {
                & (DUMP_HISTORY_ONLY|DUMP_CHARGED_ONLY|DUMP_DAILY_ONLY)) != 0;

        if ((flags&DUMP_HISTORY_ONLY) != 0 || !filtering) {
            dumpHistory(pw, flags, histStart, false);
            dumpHistory(pw, flags, histStart, false, monotonicClockStart);
            pw.println();
        }

@@ -8014,7 +8016,7 @@ public abstract class BatteryStats {
        }

        if ((flags & (DUMP_INCLUDE_HISTORY | DUMP_HISTORY_ONLY)) != 0) {
            dumpHistory(pw, flags, histStart, true);
            dumpHistory(pw, flags, histStart, true, 0);
        }

        if ((flags & DUMP_HISTORY_ONLY) != 0) {
+5 −0
Original line number Diff line number Diff line
@@ -55,4 +55,9 @@

    <!-- Size of storage allocated to battery history, in bytes -->
    <integer name="config_batteryHistoryStorageSize">4194304</integer>

    <!-- Time span of battery history dump, in milliseconds, default value is 24 hours.
    It only affects the `dumpsys batterystats -a` command -->
    <integer name="config_batteryHistoryDumpWindowSize">86400000</integer>

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -5456,6 +5456,7 @@
  <java-symbol type="integer" name="config_aggregatedPowerStatsSpanDuration" />
  <java-symbol type="integer" name="config_accumulatedBatteryUsageStatsSpanSize" />
  <java-symbol type="integer" name="config_batteryHistoryStorageSize" />
  <java-symbol type="integer" name="config_batteryHistoryDumpWindowSize" />

  <!--Dynamic Tokens-->
  <java-symbol name="system_accent1_0_light" type="color"/>
+11 −2
Original line number Diff line number Diff line
@@ -3176,6 +3176,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        boolean noOutput = false;
        boolean writeData = false;
        long historyStart = -1;
        long monotonicClockStartTime = 0;
        int reqUid = -1;
        if (args != null) {
            for (int i=0; i<args.length; i++) {
@@ -3319,6 +3320,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    return;
                } else if ("-a".equals(arg)) {
                    flags |= BatteryStats.DUMP_VERBOSE;
                    monotonicClockStartTime =
                        mMonotonicClock.monotonicTime() - mContext.getResources().getInteger(
                            com.android.internal.R.integer.config_batteryHistoryDumpWindowSize);
                    if (monotonicClockStartTime < 0) {
                        monotonicClockStartTime = 0;
                    }
                } else if ("-v".equals(arg)) {
                    flags |= BatteryStats.DUMP_VERBOSE;
                } else if ("--sync".equals(arg)) {
                    finishDelayedOperations(pw);
                    return;
@@ -3458,8 +3467,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        } else {
            if (DBG) Slog.d(TAG, "begin dump from UID " + Binder.getCallingUid());
            awaitCompletion();

            mStats.dump(mContext, pw, flags, reqUid, historyStart, mDumpHelper);
            mStats.dump(mContext, pw, flags, reqUid, historyStart, mDumpHelper,
                    monotonicClockStartTime);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
+3 −2
Original line number Diff line number Diff line
@@ -17277,8 +17277,9 @@ public class BatteryStatsImpl extends BatteryStats {
    }
    @GuardedBy("this")
    @Override
    public void dump(Context context, PrintWriter pw, int flags, int reqUid, long histStart,
            BatteryStatsDumpHelper dumpHelper) {
            BatteryStatsDumpHelper dumpHelper, long monotonicClockStartTime) {
        if (DEBUG) {
            pw.println("mOnBatteryTimeBase:");
            mOnBatteryTimeBase.dump(pw, "  ");
@@ -17350,7 +17351,7 @@ public class BatteryStatsImpl extends BatteryStats {
            pr.println("*** Camera timer:");
            mCameraOnTimer.logState(pr, "  ");
        }
        super.dump(context, pw, flags, reqUid, histStart, dumpHelper);
        super.dump(context, pw, flags, reqUid, histStart, dumpHelper, monotonicClockStartTime);
        synchronized (this) {
            pw.print("Per process state tracking available: ");