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

Commit 9adb9c3b authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Various battery info things:

- Now track wake locks in battery history.
- Now track sensors in battery history.
- Some filtering of sensory data.
- Fixes to some data that wasn't cleared when resetting battery stats.
- Print amount discharged since last charge.

And the big part -- keep track of wake locks held per process,
and kill processes that hold wake locks too much while they are in
the background.  This includes information in the battery stats
about the process being killed, which will be available to the
developer if the app is reported.

Change-Id: I97202e94d00aafe0526ba2db74a03212e7539c54
parent 3f442ece
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -365,7 +365,8 @@ public class ActivityManager {
        
        /**
         * The time when the service was first made active, either by someone
         * starting or binding to it.
         * starting or binding to it.  This
         * is in units of {@link android.os.SystemClock#elapsedRealtime()}.
         */
        public long activeSince;
        
@@ -387,7 +388,8 @@ public class ActivityManager {
        
        /**
         * The time when there was last activity in the service (either
         * explicit requests to start it or clients binding to it).
         * explicit requests to start it or clients binding to it).  This
         * is in units of {@link android.os.SystemClock#uptimeMillis()}.
         */
        public long lastActivityTime;
        
+45 −2
Original line number Diff line number Diff line
@@ -290,6 +290,11 @@ public abstract class BatteryStats implements Parcelable {
         */
        public static abstract class Proc {

            public static class ExcessiveWake {
                public long overTime;
                public long usedTime;
            }

            /**
             * Returns the total time (in 1/100 sec) spent executing in user code.
             *
@@ -326,6 +331,10 @@ public abstract class BatteryStats implements Parcelable {
             * @see BatteryStats#getCpuSpeedSteps()
             */
            public abstract long getTimeAtCpuSpeedStep(int speedStep, int which);

            public abstract int countExcessiveWakes();

            public abstract ExcessiveWake getExcessiveWake(int i);
        }

        /**
@@ -421,6 +430,8 @@ public abstract class BatteryStats implements Parcelable {
        public static final int STATE_BLUETOOTH_ON_FLAG = 1<<20;
        public static final int STATE_AUDIO_ON_FLAG = 1<<19;
        public static final int STATE_VIDEO_ON_FLAG = 1<<18;
        public static final int STATE_WAKE_LOCK_FLAG = 1<<17;
        public static final int STATE_SENSOR_ON_FLAG = 1<<16;
        
        public int states;

@@ -470,6 +481,16 @@ public abstract class BatteryStats implements Parcelable {
            batteryVoltage = o.batteryVoltage;
            states = o.states;
        }

        public boolean same(HistoryItem o) {
            return batteryLevel == o.batteryLevel
                    && batteryStatus == o.batteryStatus
                    && batteryHealth == o.batteryHealth
                    && batteryPlugType == o.batteryPlugType
                    && batteryTemperature == o.batteryTemperature
                    && batteryVoltage == o.batteryVoltage
                    && states == o.states;
        }
    }
    
    public static final class BitDescription {
@@ -633,6 +654,8 @@ public abstract class BatteryStats implements Parcelable {
        new BitDescription(HistoryItem.STATE_BLUETOOTH_ON_FLAG, "bluetooth"),
        new BitDescription(HistoryItem.STATE_AUDIO_ON_FLAG, "audio"),
        new BitDescription(HistoryItem.STATE_VIDEO_ON_FLAG, "video"),
        new BitDescription(HistoryItem.STATE_WAKE_LOCK_FLAG, "wake_lock"),
        new BitDescription(HistoryItem.STATE_SENSOR_ON_FLAG, "sensor"),
        new BitDescription(HistoryItem.STATE_BRIGHTNESS_MASK,
                HistoryItem.STATE_BRIGHTNESS_SHIFT, "brightness",
                SCREEN_BRIGHTNESS_NAMES),
@@ -1376,7 +1399,6 @@ public abstract class BatteryStats implements Parcelable {
                        pw.println(getDischargeStartLevel());
                pw.print(prefix); pw.print("    Discharge cycle current level: ");
                        pw.println(getDischargeCurrentLevel());
            } else {
                pw.print(prefix); pw.println("  Device is currently plugged into power");
                pw.print(prefix); pw.print("    Last discharge cycle start level: "); 
                        pw.println(getDischargeStartLevel());
@@ -1384,6 +1406,13 @@ public abstract class BatteryStats implements Parcelable {
                        pw.println(getDischargeCurrentLevel());
            }
            pw.println(" ");
        } else {
            pw.print(prefix); pw.println("  Device battery use since last full charge");
            pw.print(prefix); pw.print("    Amount discharged (lower bound): ");
                    pw.println(getLowDischargeAmountSinceCharge());
            pw.print(prefix); pw.print("    Amount discharged (upper bound): ");
                    pw.println(getHighDischargeAmountSinceCharge());
            pw.println(" ");
        }
        

@@ -1524,12 +1553,16 @@ public abstract class BatteryStats implements Parcelable {
                    long userTime;
                    long systemTime;
                    int starts;
                    int numExcessive;

                    userTime = ps.getUserTime(which);
                    systemTime = ps.getSystemTime(which);
                    starts = ps.getStarts(which);
                    numExcessive = which == STATS_SINCE_CHARGED
                            ? ps.countExcessiveWakes() : 0;

                    if (userTime != 0 || systemTime != 0 || starts != 0) {
                    if (userTime != 0 || systemTime != 0 || starts != 0
                            || numExcessive != 0) {
                        sb.setLength(0);
                        sb.append(prefix); sb.append("    Proc ");
                                sb.append(ent.getKey()); sb.append(":\n");
@@ -1539,6 +1572,16 @@ public abstract class BatteryStats implements Parcelable {
                        sb.append(prefix); sb.append("      "); sb.append(starts);
                                sb.append(" proc starts");
                        pw.println(sb.toString());
                        for (int e=0; e<numExcessive; e++) {
                            Uid.Proc.ExcessiveWake ew = ps.getExcessiveWake(e);
                            if (ew != null) {
                                pw.print(prefix); pw.print("      * Killed for wake lock use: ");
                                        pw.print(ew.usedTime); pw.print("ms over ");
                                        pw.print(ew.overTime); pw.print("ms (");
                                        pw.print((ew.usedTime*100)/ew.overTime);
                                        pw.println("%)");
                            }
                        }
                        uidActivity = true;
                    }
                }
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import android.telephony.SignalStrength;

interface IBatteryStats {
    byte[] getStatistics();
    void noteStartWakelock(int uid, String name, int type);
    void noteStopWakelock(int uid, String name, int type);
    void noteStartWakelock(int uid, int pid, String name, int type);
    void noteStopWakelock(int uid, int pid, String name, int type);
    
    /* DO NOT CHANGE the position of noteStartSensor without updating
       SensorService.cpp */
+254 −31

File changed.

Preview size limit exceeded, changes collapsed.

+17 −11

File changed.

Preview size limit exceeded, changes collapsed.

Loading