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

Commit d865ccc2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refine optimize page log pattern" into udc-dev

parents 2aff060a 1f78ebd8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ message BatteryOptimizeHistoricalLogEntry {
  // The action to set optimize mode
  enum Action {
    UNKNOWN = 0;
    MANUAL = 1;
    LEAVE = 1;
    APPLY = 2;
    RESET = 3;
    RESTORE = 4;
@@ -24,4 +24,5 @@ message BatteryOptimizeHistoricalLogEntry {
  optional string package_name = 1;
  optional Action action = 2;
  optional string action_description = 3;
  optional int64 timestamp = 4;
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -291,7 +291,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements

        BatteryHistoricalLogUtil.writeLog(
                getContext().getApplicationContext(),
                Action.MANUAL,
                Action.LEAVE,
                BatteryHistoricalLogUtil.getPackageNameWithUserId(
                        mBatteryOptimizeUtils.getPackageName(), UserHandle.myUserId()),
                mLogStringBuilder.toString());
+6 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.SharedPreferences;
import android.util.Base64;

import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
import com.android.settings.fuelgauge.batteryusage.ConvertUtils;

import com.google.common.annotations.VisibleForTesting;

@@ -49,6 +50,7 @@ public final class BatteryHistoricalLogUtil {
                        .setPackageName(pkg)
                        .setAction(action)
                        .setActionDescription(actionDescription)
                        .setTimestamp(System.currentTimeMillis())
                        .build());
    }

@@ -89,6 +91,7 @@ public final class BatteryHistoricalLogUtil {
        if (logEntryList.isEmpty()) {
            writer.println("\tNo past logs.");
        } else {
            writer.println("0:RESTRICTED  1:UNRESTRICTED  2:OPTIMIZED  3:UNKNOWN");
            logEntryList.forEach(entry -> writer.println(toString(entry)));
        }
    }
@@ -101,8 +104,9 @@ public final class BatteryHistoricalLogUtil {
    }

    private static String toString(BatteryOptimizeHistoricalLogEntry entry) {
        return String.format("%s\tAction:%s\tEvent:%s",
                entry.getPackageName(), entry.getAction(), entry.getActionDescription());
        return String.format("%s\tAction:%s\tEvent:%s\tTimestamp:%s", entry.getPackageName(),
                entry.getAction(), entry.getActionDescription(),
                ConvertUtils.utcToLocalTimeForLogging(entry.getTimestamp()));
    }

    @VisibleForTesting
+4 −3
Original line number Diff line number Diff line
@@ -57,17 +57,18 @@ public final class BatteryHistoricalLogUtilTest {
        BatteryHistoricalLogUtil.writeLog(mContext, Action.APPLY, "pkg1", "logs");
        BatteryHistoricalLogUtil.printBatteryOptimizeHistoricalLog(mContext, mTestPrintWriter);

        assertThat(mTestStringWriter.toString()).contains("pkg1\tAction:APPLY\tEvent:logs");
        assertThat(mTestStringWriter.toString()).contains(
                "pkg1\tAction:APPLY\tEvent:logs\tTimestamp:");
    }

    @Test
    public void writeLog_multipleLogs_withCorrectCounts() {
        for (int i = 0; i < BatteryHistoricalLogUtil.MAX_ENTRIES; i++) {
            BatteryHistoricalLogUtil.writeLog(mContext, Action.MANUAL, "pkg" + i, "logs");
            BatteryHistoricalLogUtil.writeLog(mContext, Action.LEAVE, "pkg" + i, "logs");
        }
        BatteryHistoricalLogUtil.printBatteryOptimizeHistoricalLog(mContext, mTestPrintWriter);

        assertThat(mTestStringWriter.toString().split("MANUAL").length).isEqualTo(41);
        assertThat(mTestStringWriter.toString().split("LEAVE").length).isEqualTo(41);
    }

    @Test