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

Commit 0dce2acb authored by Adam Lesinski's avatar Adam Lesinski Committed by Android (Google) Code Review
Browse files

Merge "Adding per UID WiFi power distribution."

parents 227d23d4 b943fabf
Loading
Loading
Loading
Loading
+56 −16
Original line number Diff line number Diff line
@@ -268,6 +268,15 @@ public abstract class BatteryStats implements Parcelable {
         */
        public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which);

        /**
         * Returns the total time in microseconds associated with this Timer since the
         * 'mark' was last set.
         *
         * @param elapsedRealtimeUs current elapsed realtime of system in microseconds
         * @return a time in microseconds
         */
        public abstract long getTimeSinceMarkLocked(long elapsedRealtimeUs);

        /**
         * Temporary for debugging.
         */
@@ -333,6 +342,16 @@ public abstract class BatteryStats implements Parcelable {
         */
        public abstract ArrayMap<String, ? extends Pkg> getPackageStats();

        /**
         * Returns the time in milliseconds that this app kept the WiFi controller in the
         * specified state <code>type</code>.
         * @param type one of {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, or
         *             {@link #CONTROLLER_TX_TIME}.
         * @param which one of {@link #STATS_CURRENT}, {@link #STATS_SINCE_CHARGED}, or
         *              {@link #STATS_SINCE_UNPLUGGED}.
         */
        public abstract long getWifiControllerActivity(int type, int which);

        /**
         * {@hide}
         */
@@ -1914,7 +1933,6 @@ public abstract class BatteryStats implements Parcelable {
    public static final int NETWORK_MOBILE_TX_DATA = 1;
    public static final int NETWORK_WIFI_RX_DATA = 2;
    public static final int NETWORK_WIFI_TX_DATA = 3;

    public static final int NUM_NETWORK_ACTIVITY_TYPES = NETWORK_WIFI_TX_DATA + 1;

    public abstract long getNetworkActivityBytes(int type, int which);
@@ -1923,10 +1941,25 @@ public abstract class BatteryStats implements Parcelable {
    public static final int CONTROLLER_IDLE_TIME = 0;
    public static final int CONTROLLER_RX_TIME = 1;
    public static final int CONTROLLER_TX_TIME = 2;
    public static final int CONTROLLER_ENERGY = 3;
    public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_ENERGY + 1;
    public static final int CONTROLLER_POWER_DRAIN = 3;
    public static final int NUM_CONTROLLER_ACTIVITY_TYPES = CONTROLLER_POWER_DRAIN + 1;

    /**
     * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
     * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
     * respective state.
     * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
     * milli-ampere-milliseconds (mAms).
     */
    public abstract long getBluetoothControllerActivity(int type, int which);

    /**
     * For {@link #CONTROLLER_IDLE_TIME}, {@link #CONTROLLER_RX_TIME}, and
     * {@link #CONTROLLER_TX_TIME}, returns the time spent (in milliseconds) in the
     * respective state.
     * For {@link #CONTROLLER_POWER_DRAIN}, returns the power used by the controller in
     * milli-ampere-milliseconds (mAms).
     */
    public abstract long getWifiControllerActivity(int type, int which);

    /**
@@ -2618,7 +2651,7 @@ public abstract class BatteryStats implements Parcelable {
                        label = "???";
                }
                dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label,
                        BatteryStatsHelper.makemAh(bs.value));
                        BatteryStatsHelper.makemAh(bs.totalPowerMah));
            }
        }

@@ -3262,6 +3295,13 @@ public abstract class BatteryStats implements Parcelable {
        sb.append(")");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.append(prefix);
        sb.append("  WiFi Energy use: ").append(BatteryStatsHelper.makemAh(
                getWifiControllerActivity(CONTROLLER_POWER_DRAIN, which) / (double)(1000*60*60)));
        sb.append(" mAh");
        pw.println(sb.toString());

        sb.setLength(0);
        sb.append(prefix);
                sb.append("  Bluetooth on: "); formatTimeMs(sb, bluetoothOnTime / 1000);
@@ -3376,48 +3416,48 @@ public abstract class BatteryStats implements Parcelable {
                final BatterySipper bs = sippers.get(i);
                switch (bs.drainType) {
                    case IDLE:
                        pw.print(prefix); pw.print("    Idle: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Idle: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case CELL:
                        pw.print(prefix); pw.print("    Cell standby: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Cell standby: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case PHONE:
                        pw.print(prefix); pw.print("    Phone calls: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Phone calls: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case WIFI:
                        pw.print(prefix); pw.print("    Wifi: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Wifi: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case BLUETOOTH:
                        pw.print(prefix); pw.print("    Bluetooth: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Bluetooth: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case SCREEN:
                        pw.print(prefix); pw.print("    Screen: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Screen: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case FLASHLIGHT:
                        pw.print(prefix); pw.print("    Flashlight: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Flashlight: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case APP:
                        pw.print(prefix); pw.print("    Uid ");
                        UserHandle.formatUid(pw, bs.uidObj.getUid());
                        pw.print(": "); printmAh(pw, bs.value); pw.println();
                        pw.print(": "); printmAh(pw, bs.totalPowerMah); pw.println();
                        break;
                    case USER:
                        pw.print(prefix); pw.print("    User "); pw.print(bs.userId);
                        pw.print(": "); printmAh(pw, bs.value); pw.println();
                        pw.print(": "); printmAh(pw, bs.totalPowerMah); pw.println();
                        break;
                    case UNACCOUNTED:
                        pw.print(prefix); pw.print("    Unaccounted: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Unaccounted: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                    case OVERCOUNTED:
                        pw.print(prefix); pw.print("    Over-counted: "); printmAh(pw, bs.value);
                        pw.print(prefix); pw.print("    Over-counted: "); printmAh(pw, bs.totalPowerMah);
                        pw.println();
                        break;
                }
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ interface IBatteryStats {
    void noteWifiBatchedScanStoppedFromSource(in WorkSource ws);
    void noteWifiMulticastEnabledFromSource(in WorkSource ws);
    void noteWifiMulticastDisabledFromSource(in WorkSource ws);
    void noteWifiRadioPowerState(int powerState, long timestampNs);
    void noteNetworkInterfaceType(String iface, int type);
    void noteNetworkStatsEnabled();
    void noteDeviceIdleMode(boolean enabled, boolean fromActive, boolean fromMotion);
+50 −34
Original line number Diff line number Diff line
@@ -23,17 +23,25 @@ import android.os.BatteryStats.Uid;
public class BatterySipper implements Comparable<BatterySipper> {
    public int userId;
    public Uid uidObj;
    public double value;
    public double[] values;
    public double totalPowerMah;
    public DrainType drainType;

    // Measured in milliseconds.
    public long usageTime;
    public long cpuTime;
    public long gpsTime;
    public long wifiRunningTime;
    public long cpuFgTime;
    public long wakeLockTime;
    /**
     * Generic usage time in milliseconds.
     */
    public long usageTimeMs;

    /**
     * Generic power usage in mAh.
     */
    public double usagePowerMah;

    // Subsystem usage times.
    public long cpuTimeMs;
    public long gpsTimeMs;
    public long wifiRunningTimeMs;
    public long cpuFgTimeMs;
    public long wakeLockTimeMs;

    public long mobileRxPackets;
    public long mobileTxPackets;
@@ -52,12 +60,13 @@ public class BatterySipper implements Comparable<BatterySipper> {
    public String packageWithHighestDrain;

    // Measured in mAh (milli-ampere per hour).
    public double wifiPower;
    public double cpuPower;
    public double wakeLockPower;
    public double mobileRadioPower;
    public double gpsPower;
    public double sensorPower;
    // These are included when summed.
    public double wifiPowerMah;
    public double cpuPowerMah;
    public double wakeLockPowerMah;
    public double mobileRadioPowerMah;
    public double gpsPowerMah;
    public double sensorPowerMah;

    public enum DrainType {
        IDLE,
@@ -73,17 +82,12 @@ public class BatterySipper implements Comparable<BatterySipper> {
        OVERCOUNTED
    }

    public BatterySipper(DrainType drainType, Uid uid, double[] values) {
        this.values = values;
        if (values != null) value = values[0];
    public BatterySipper(DrainType drainType, Uid uid, double value) {
        this.totalPowerMah = value;
        this.drainType = drainType;
        uidObj = uid;
    }

    public double[] getValues() {
        return values;
    }

    public void computeMobilemspp() {
        long packets = mobileRxPackets+mobileTxPackets;
        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
@@ -101,7 +105,7 @@ public class BatterySipper implements Comparable<BatterySipper> {
            }
        }
        // Return the flipped value because we want the items in descending order
        return Double.compare(other.value, value);
        return Double.compare(other.totalPowerMah, totalPowerMah);
    }

    /**
@@ -123,11 +127,14 @@ public class BatterySipper implements Comparable<BatterySipper> {
     * Add stats from other to this BatterySipper.
     */
    public void add(BatterySipper other) {
        cpuTime += other.cpuTime;
        gpsTime += other.gpsTime;
        wifiRunningTime += other.wifiRunningTime;
        cpuFgTime += other.cpuFgTime;
        wakeLockTime += other.wakeLockTime;
        totalPowerMah += other.totalPowerMah;
        usageTimeMs += other.usageTimeMs;
        usagePowerMah += other.usagePowerMah;
        cpuTimeMs += other.cpuTimeMs;
        gpsTimeMs += other.gpsTimeMs;
        wifiRunningTimeMs += other.wifiRunningTimeMs;
        cpuFgTimeMs += other.cpuFgTimeMs;
        wakeLockTimeMs += other.wakeLockTimeMs;
        mobileRxPackets += other.mobileRxPackets;
        mobileTxPackets += other.mobileTxPackets;
        mobileActive += other.mobileActive;
@@ -138,11 +145,20 @@ public class BatterySipper implements Comparable<BatterySipper> {
        mobileTxBytes += other.mobileTxBytes;
        wifiRxBytes += other.wifiRxBytes;
        wifiTxBytes += other.wifiTxBytes;
        wifiPower += other.wifiPower;
        gpsPower += other.gpsPower;
        cpuPower += other.cpuPower;
        sensorPower += other.sensorPower;
        mobileRadioPower += other.mobileRadioPower;
        wakeLockPower += other.wakeLockPower;
        wifiPowerMah += other.wifiPowerMah;
        gpsPowerMah += other.gpsPowerMah;
        cpuPowerMah += other.cpuPowerMah;
        sensorPowerMah += other.sensorPowerMah;
        mobileRadioPowerMah += other.mobileRadioPowerMah;
        wakeLockPowerMah += other.wakeLockPowerMah;
    }

    /**
     * Sum all the powers and store the value into `value`.
     * @return the sum of all the power in this BatterySipper.
     */
    public double sumPower() {
        return totalPowerMah = usagePowerMah + wifiPowerMah + gpsPowerMah + cpuPowerMah + sensorPowerMah
                + mobileRadioPowerMah + wakeLockPowerMah;
    }
}
+186 −537

File changed.

Preview size limit exceeded, changes collapsed.

+318 −54

File changed.

Preview size limit exceeded, changes collapsed.

Loading