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

Commit db6d624a authored by Bookatz's avatar Bookatz
Browse files

BatteryStats remove which - log warnings

In ag/6694908, BatteryStats is changed to only support the "which" of
STATS_SINCE_CHARGED. Here, we deal with BatteryStats calls that attempt
to use a different which, logging the event, exiting, and/or just using
STATS_SINCE_CHARGED as applicable.

Test: compiles
Bug: 70892428
Change-Id: Id0e9f863d8b1a5fb7baa770683c0c4ec5880e976
parent 1371b9ac
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -3661,6 +3661,14 @@ public abstract class BatteryStats implements Parcelable {
     */
    public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid,
            boolean wifiOnly) {

        if (which != BatteryStats.STATS_SINCE_CHARGED) {
            dumpLine(pw, 0, STAT_NAMES[which], "err",
                    "ERROR: BatteryStats.dumpCheckin called for which type " + which
                    + " but only STATS_SINCE_CHARGED is supported.");
            return;
        }

        final long rawUptime = SystemClock.uptimeMillis() * 1000;
        final long rawRealtimeMs = SystemClock.elapsedRealtime();
        final long rawRealtime = rawRealtimeMs * 1000;
@@ -4427,6 +4435,13 @@ public abstract class BatteryStats implements Parcelable {
    @SuppressWarnings("unused")
    public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which,
            int reqUid, boolean wifiOnly) {

        if (which != BatteryStats.STATS_SINCE_CHARGED) {
            pw.println("ERROR: BatteryStats.dump called for which type " + which
                    + " but only STATS_SINCE_CHARGED is supported");
            return;
        }

        final long rawUptime = SystemClock.uptimeMillis() * 1000;
        final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
        final long rawRealtimeMs = (rawRealtime + 500) / 1000;
+5 −0
Original line number Diff line number Diff line
@@ -368,6 +368,11 @@ public class BatteryStatsHelper {

    public void refreshStats(int statsType, SparseArray<UserHandle> asUsers, long rawRealtimeUs,
            long rawUptimeUs) {
        if (statsType != BatteryStats.STATS_SINCE_CHARGED) {
            Log.w(TAG, "refreshStats called for statsType " + statsType + " but only "
                    + "STATS_SINCE_CHARGED is supported. Using STATS_SINCE_CHARGED instead.");
        }

        // Initialize mStats if necessary.
        getStats();

+8 −6
Original line number Diff line number Diff line
@@ -27,9 +27,10 @@ public abstract class PowerCalculator {
     * @param u The recorded stats for the app.
     * @param rawRealtimeUs The raw system realtime in microseconds.
     * @param rawUptimeUs The raw system uptime in microseconds.
     * @param statsType The type of stats. Can be {@link BatteryStats#STATS_CURRENT},
     *                  {@link BatteryStats#STATS_SINCE_CHARGED}, or
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED}.
     * @param statsType The type of stats. As of {@link android.os.Build.VERSION_CODES#Q}, this can
     *                  only be {@link BatteryStats#STATS_SINCE_CHARGED}, since
     *                  {@link BatteryStats#STATS_CURRENT} and
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED} are deprecated.
     */
    public abstract void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
                                      long rawUptimeUs, int statsType);
@@ -40,9 +41,10 @@ public abstract class PowerCalculator {
     * @param stats The BatteryStats object from which to retrieve data.
     * @param rawRealtimeUs The raw system realtime in microseconds.
     * @param rawUptimeUs The raw system uptime in microseconds.
     * @param statsType The type of stats. Can be {@link BatteryStats#STATS_CURRENT},
     *                  {@link BatteryStats#STATS_SINCE_CHARGED}, or
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED}.
     * @param statsType The type of stats. As of {@link android.os.Build.VERSION_CODES#Q}, this can
     *                  only be {@link BatteryStats#STATS_SINCE_CHARGED}, since
     *                  {@link BatteryStats#STATS_CURRENT} and
     *                  {@link BatteryStats#STATS_SINCE_UNPLUGGED} are deprecated.
     */
    public void calculateRemaining(BatterySipper app, BatteryStats stats, long rawRealtimeUs,
                                   long rawUptimeUs, int statsType) {