OSDN Git Service

Fix issue #10422349: Limit/change the battery history data in batterystats
authorDianne Hackborn <hackbod@google.com>
Thu, 5 Sep 2013 01:03:40 +0000 (18:03 -0700)
committerDianne Hackborn <hackbod@google.com>
Thu, 5 Sep 2013 01:03:40 +0000 (18:03 -0700)
Don't include history in real checkins; have a new compact option
for bug reports.

Change-Id: I077f9218b365154f6bae9cc685c2c6b378e0283a

core/java/android/os/BatteryStats.java
services/java/com/android/server/am/BatteryStatsService.java

index 38ffb96..dbaa325 100644 (file)
@@ -2380,22 +2380,25 @@ public abstract class BatteryStats implements Parcelable {
     
     @SuppressWarnings("unused")
     public void dumpCheckinLocked(
-            PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly) {
+            PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly,
+            boolean includeHistory) {
         prepareForDumpLocked();
         
         long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
 
-        final HistoryItem rec = new HistoryItem();
-        if (startIteratingHistoryLocked()) {
-            HistoryPrinter hprinter = new HistoryPrinter();
-            while (getNextHistoryLocked(rec)) {
-                pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
-                pw.print(0); pw.print(',');
-                pw.print(HISTORY_DATA); pw.print(',');
-                hprinter.printNextItemCheckin(pw, rec, now);
-                pw.println();
+        if (includeHistory) {
+            final HistoryItem rec = new HistoryItem();
+            if (startIteratingHistoryLocked()) {
+                HistoryPrinter hprinter = new HistoryPrinter();
+                while (getNextHistoryLocked(rec)) {
+                    pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(',');
+                    pw.print(0); pw.print(',');
+                    pw.print(HISTORY_DATA); pw.print(',');
+                    hprinter.printNextItemCheckin(pw, rec, now);
+                    pw.println();
+                }
+                finishIteratingHistoryLocked();
             }
-            finishIteratingHistoryLocked();
         }
 
         if (apps != null) {
index 12cad7b..0dd950e 100644 (file)
@@ -481,7 +481,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
     
     private void dumpHelp(PrintWriter pw) {
         pw.println("Battery stats (batterystats) dump options:");
-        pw.println("  [--checkin] [--unplugged] [--reset] [--write] [-h] [<package.name>]");
+        pw.println("  [--checkin] [-c] [--unplugged] [--reset] [--write] [-h] [<package.name>]");
         pw.println("  --checkin: format output for a checkin report.");
         pw.println("  --unplugged: only output data since last unplugged.");
         pw.println("  --reset: reset the stats, clearing all current data.");
@@ -501,6 +501,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
         }
 
         boolean isCheckin = false;
+        boolean includeHistory = false;
         boolean isUnpluggedOnly = false;
         boolean noOutput = false;
         int reqUid = -1;
@@ -508,6 +509,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
             for (String arg : args) {
                 if ("--checkin".equals(arg)) {
                     isCheckin = true;
+                } else if ("-c".equals(arg)) {
+                    isCheckin = true;
+                    includeHistory = true;
                 } else if ("--unplugged".equals(arg)) {
                     isUnpluggedOnly = true;
                 } else if ("--reset".equals(arg)) {
@@ -550,7 +554,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
         if (isCheckin) {
             List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
             synchronized (mStats) {
-                mStats.dumpCheckinLocked(pw, apps, isUnpluggedOnly);
+                mStats.dumpCheckinLocked(pw, apps, isUnpluggedOnly, includeHistory);
             }
         } else {
             synchronized (mStats) {