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

Commit ec43a6bc authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Better --unplugged support when dumping battery.

Also fixes logBatteryStatsLocked() to output valid dump data, instead
of just a usage message.

Bug: 8708665
Change-Id: Ie0d8d90e1a470b7e1e902643333309c2cf7bdb72
parent f1301d86
Loading
Loading
Loading
Loading
+11 −17
Original line number Original line Diff line number Diff line
@@ -2254,7 +2254,7 @@ public abstract class BatteryStats implements Parcelable {
     * @param pw a Printer to receive the dump output.
     * @param pw a Printer to receive the dump output.
     */
     */
    @SuppressWarnings("unused")
    @SuppressWarnings("unused")
    public void dumpLocked(PrintWriter pw) {
    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly) {
        prepareForDumpLocked();
        prepareForDumpLocked();


        long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
        long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
@@ -2307,28 +2307,22 @@ public abstract class BatteryStats implements Parcelable {
            pw.println("");
            pw.println("");
        }
        }


        if (!isUnpluggedOnly) {
            pw.println("Statistics since last charge:");
            pw.println("Statistics since last charge:");
            pw.println("  System starts: " + getStartCount()
            pw.println("  System starts: " + getStartCount()
                    + ", currently on battery: " + getIsOnBattery());
                    + ", currently on battery: " + getIsOnBattery());
            dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
            dumpLocked(pw, "", STATS_SINCE_CHARGED, -1);
            pw.println("");
            pw.println("");
        }
        pw.println("Statistics since last unplugged:");
        pw.println("Statistics since last unplugged:");
        dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
        dumpLocked(pw, "", STATS_SINCE_UNPLUGGED, -1);
    }
    }
    
    
    @SuppressWarnings("unused")
    @SuppressWarnings("unused")
    public void dumpCheckinLocked(PrintWriter pw, String[] args, List<ApplicationInfo> apps) {
    public void dumpCheckinLocked(
            PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly) {
        prepareForDumpLocked();
        prepareForDumpLocked();
        
        
        boolean isUnpluggedOnly = false;
        
        for (String arg : args) {
            if ("-u".equals(arg)) {
                if (LOCAL_LOGV) Log.v("BatteryStats", "Dumping unplugged data");
                isUnpluggedOnly = true;
            }
        }
        
        if (apps != null) {
        if (apps != null) {
            SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
            SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>();
            for (int i=0; i<apps.size(); i++) {
            for (int i=0; i<apps.size(); i++) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -5974,7 +5974,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        updateKernelWakelocksLocked();
        updateKernelWakelocksLocked();
    }
    }


    public void dumpLocked(PrintWriter pw) {
    public void dumpLocked(PrintWriter pw, boolean isUnpluggedOnly) {
        if (DEBUG) {
        if (DEBUG) {
            Printer pr = new PrintWriterPrinter(pw);
            Printer pr = new PrintWriterPrinter(pw);
            pr.println("*** Screen timer:");
            pr.println("*** Screen timer:");
@@ -6006,7 +6006,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            pr.println("*** Mobile ifaces:");
            pr.println("*** Mobile ifaces:");
            pr.println(mMobileIfaces.toString());
            pr.println(mMobileIfaces.toString());
        }
        }
        super.dumpLocked(pw);
        super.dumpLocked(pw, isUnpluggedOnly);
    }
    }


    private NetworkStats mNetworkSummaryCache;
    private NetworkStats mNetworkSummaryCache;
+1 −1
Original line number Original line Diff line number Diff line
@@ -88,7 +88,7 @@ public final class BatteryService extends Binder {
    private int mCriticalBatteryLevel;
    private int mCriticalBatteryLevel;


    private static final int DUMP_MAX_LENGTH = 24 * 1024;
    private static final int DUMP_MAX_LENGTH = 24 * 1024;
    private static final String[] DUMPSYS_ARGS = new String[] { "--checkin", "-u" };
    private static final String[] DUMPSYS_ARGS = new String[] { "--checkin", "--unplugged" };
    private static final String BATTERY_STATS_SERVICE_NAME = "batteryinfo";
    private static final String BATTERY_STATS_SERVICE_NAME = "batteryinfo";


    private static final String DUMPSYS_DATA_PATH = "/data/system/";
    private static final String DUMPSYS_DATA_PATH = "/data/system/";
+7 −3
Original line number Original line Diff line number Diff line
@@ -470,8 +470,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
    
    
    private void dumpHelp(PrintWriter pw) {
    private void dumpHelp(PrintWriter pw) {
        pw.println("Battery stats (batteryinfo) dump options:");
        pw.println("Battery stats (batteryinfo) dump options:");
        pw.println("  [--checkin] [--reset] [--write] [-h]");
        pw.println("  [--checkin] [--unplugged] [--reset] [--write] [-h]");
        pw.println("  --checkin: format output for a checkin report.");
        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.");
        pw.println("  --reset: reset the stats, clearing all current data.");
        pw.println("  --write: force write current collected stats to disk.");
        pw.println("  --write: force write current collected stats to disk.");
        pw.println("  -h: print this help text.");
        pw.println("  -h: print this help text.");
@@ -488,11 +489,14 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
        }
        }


        boolean isCheckin = false;
        boolean isCheckin = false;
        boolean isUnpluggedOnly = false;
        boolean noOutput = false;
        boolean noOutput = false;
        if (args != null) {
        if (args != null) {
            for (String arg : args) {
            for (String arg : args) {
                if ("--checkin".equals(arg)) {
                if ("--checkin".equals(arg)) {
                    isCheckin = true;
                    isCheckin = true;
                } else if ("--unplugged".equals(arg)) {
                    isUnpluggedOnly = true;
                } else if ("--reset".equals(arg)) {
                } else if ("--reset".equals(arg)) {
                    synchronized (mStats) {
                    synchronized (mStats) {
                        mStats.resetAllStatsLocked();
                        mStats.resetAllStatsLocked();
@@ -522,11 +526,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
        if (isCheckin) {
        if (isCheckin) {
            List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
            List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
            synchronized (mStats) {
            synchronized (mStats) {
                mStats.dumpCheckinLocked(pw, args, apps);
                mStats.dumpCheckinLocked(pw, apps, isUnpluggedOnly);
            }
            }
        } else {
        } else {
            synchronized (mStats) {
            synchronized (mStats) {
                mStats.dumpLocked(pw);
                mStats.dumpLocked(pw, isUnpluggedOnly);
            }
            }
        }
        }
    }
    }