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

Commit eb831e34 authored by Dhavalkumar Chaudhary's avatar Dhavalkumar Chaudhary
Browse files

Add duration limit to battery stats checkin format

Bug: 403599628

Test: presubmit
Flag: com.android.server.power.optimization.checkin_history_start_time
Change-Id: I19945a07a06d1bf5a90029b26cb3264c8ee29a2a
parent 9ae9bad4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -8004,7 +8004,7 @@ public abstract class BatteryStats {
    // This is called from BatteryStatsService.
    @SuppressWarnings("unused")
    public void dumpCheckin(Context context, PrintWriter pw, List<ApplicationInfo> apps, int flags,
            long histStart, BatteryStatsDumpHelper dumpHelper) {
            long histStart, BatteryStatsDumpHelper dumpHelper, long monotonicCheckinStartTime) {
        synchronized (this) {
            prepareForDumpLocked();

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

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

        if ((flags & DUMP_HISTORY_ONLY) != 0) {
+5 −0
Original line number Diff line number Diff line
@@ -60,4 +60,9 @@
    It only affects the `dumpsys batterystats -a` command -->
    <integer name="config_batteryHistoryDumpWindowSize">86400000</integer>

    <!-- Time span of battery history dump, in milliseconds, default value is 0 milliseconds.
    It only affects the `dumpsys batterystats -c` command, The checkin Format -->
    <integer name="config_batteryHistoryDumpCheckinWindowSize">0</integer>


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

  <!--Dynamic Tokens-->
  <java-symbol name="system_accent1_0_light" type="color"/>
+21 −6
Original line number Diff line number Diff line
@@ -3143,6 +3143,18 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                } else if ("-c".equals(arg)) {
                    useCheckinFormat = true;
                    flags |= BatteryStats.DUMP_INCLUDE_HISTORY;
                    if (Flags.checkinHistoryStartTime()) {
                        long checkinDurationLimit = mContext.getResources().getInteger(
                                com.android.internal.R.integer
                                .config_batteryHistoryDumpCheckinWindowSize);
                        if (checkinDurationLimit > 0) {
                            monotonicClockStartTime =
                                mMonotonicClock.monotonicTime() - checkinDurationLimit;
                            if (monotonicClockStartTime < 0) {
                                monotonicClockStartTime = 0;
                            }
                        }
                    }
                } else if ("--proto".equals(arg)) {
                    toProto = true;
                } else if ("--charged".equals(arg)) {
@@ -3250,12 +3262,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                    return;
                } else if ("-a".equals(arg)) {
                    flags |= BatteryStats.DUMP_VERBOSE;
                    monotonicClockStartTime =
                        mMonotonicClock.monotonicTime() - mContext.getResources().getInteger(
                    long durationLimit = mContext.getResources().getInteger(
                            com.android.internal.R.integer.config_batteryHistoryDumpWindowSize);
                    if (durationLimit > 0) {
                        monotonicClockStartTime = mMonotonicClock.monotonicTime() - durationLimit;
                        if (monotonicClockStartTime < 0) {
                            monotonicClockStartTime = 0;
                        }
                    }
                } else if ("-v".equals(arg)) {
                    flags |= BatteryStats.DUMP_VERBOSE;
                } else if ("--sync".equals(arg)) {
@@ -3376,7 +3390,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                                checkinStats.readSummaryFromParcel(in);
                                in.recycle();
                                checkinStats.dumpCheckin(mContext, pw, apps, flags,
                                        historyStart, mDumpHelper);
                                        historyStart, mDumpHelper, monotonicClockStartTime);
                                mStats.mCheckinFile.delete();
                                return;
                            }
@@ -3389,7 +3403,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            }
            if (DBG) Slog.d(TAG, "begin dumpCheckin from UID " + Binder.getCallingUid());
            awaitCompletion();
            mStats.dumpCheckin(mContext, pw, apps, flags, historyStart, mDumpHelper);
            mStats.dumpCheckin(mContext, pw, apps, flags, historyStart, mDumpHelper,
                    monotonicClockStartTime);
            if (writeData) {
                mStats.writeAsyncLocked();
            }
+8 −0
Original line number Diff line number Diff line
@@ -38,3 +38,11 @@ flag {
    bug: "364350206"
    is_fixed_read_only: true
}

flag {
     namespace: "backstage_power"
     name: "checkin_history_start_time"
     description: "Add duration limit to battery stats check in (csv) format"
     bug: "403599628"
     is_fixed_read_only: true
}