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

Commit 4127267e authored by Adam Bookatz's avatar Adam Bookatz
Browse files

BatteryStats measured energy for Wifi & Bluetooth

Measured energy data for Wifi is received, processed, attributed
to uids, and delivered. Same for Bluetooth.

Since Wifi power analysis is done via two methods (ControllerActivity data
or packet data), depending on what is available on the device, the
measured energy method also takes into account these two methods for
attribution purposes.

For Bluetooth, the only raw data is ControllerActivity data, so it is
simpler.

In both cases, if that data already contains energy data from the
ControllerActivity, but the device also
has measured energy data, then the controller energy data is used for
normalization but is otherwise replaced by the measured energy data. In
other words, the measured energy data is treated preferentially.

Also fixes a minor bug in BSI.initMeasuredEnergyStatsLocked() which
had a stray early return line.

Test: atest BatteryStatsTests
Bug: 174818228
Change-Id: Id4728fcd5e6f226664e578a4c19c4aaa5246ff4b
parent cdb0369d
Loading
Loading
Loading
Loading
+43 −7
Original line number Diff line number Diff line
@@ -986,13 +986,13 @@ public abstract class BatteryStats implements Parcelable {
        public abstract void getDeferredJobsLineLocked(StringBuilder sb, int which);

        /**
         * Returns the battery consumption (in microcoulombs) of the screen while on and uid active,
         * Returns the battery consumption (in microcoulombs) of bluetooth for this uid,
         * derived from on device power measurement data.
         * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
         *
         * {@hide}
         */
        public abstract long getScreenOnMeasuredBatteryConsumptionUC();
        public abstract long getBluetoothMeasuredBatteryConsumptionUC();

        /**
         * Returns the battery consumption (in microcoulombs) of the uid's cpu usage, derived from
@@ -1003,6 +1003,24 @@ public abstract class BatteryStats implements Parcelable {
         */
        public abstract long getCpuMeasuredBatteryConsumptionUC();

        /**
         * Returns the battery consumption (in microcoulombs) of the screen while on and uid active,
         * derived from on device power measurement data.
         * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
         *
         * {@hide}
         */
        public abstract long getScreenOnMeasuredBatteryConsumptionUC();

        /**
         * Returns the battery consumption (in microcoulombs) of wifi for this uid,
         * derived from on device power measurement data.
         * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
         *
         * {@hide}
         */
        public abstract long getWifiMeasuredBatteryConsumptionUC();

        /**
         * Returns the battery consumption (in microcoulombs) used by this uid for each
         * {@link android.hardware.power.stats.EnergyConsumer.ordinal} of (custom) energy consumer
@@ -2505,11 +2523,29 @@ public abstract class BatteryStats implements Parcelable {
    };

    /**
     * Returned value if power data is unavailable
     * Returned value if power data is unavailable.
     *
     * {@hide}
     */
    public static final long POWER_DATA_UNAVAILABLE = -1L;

    /**
     * Returns the battery consumption (in microcoulombs) of bluetooth, derived from on
     * device power measurement data.
     * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
     *
     * {@hide}
     */
    public static final long POWER_DATA_UNAVAILABLE = -1;
    public abstract long getBluetoothMeasuredBatteryConsumptionUC();

    /**
     * Returns the battery consumption (in microcoulombs) of the cpu, derived from on device power
     * measurement data.
     * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
     *
     * {@hide}
     */
    public abstract long getCpuMeasuredBatteryConsumptionUC();

    /**
     * Returns the battery consumption (in microcoulombs) of the screen while on, derived from on
@@ -2530,13 +2566,13 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long getScreenDozeMeasuredBatteryConsumptionUC();

    /**
     * Returns the battery consumption (in microcoulombs) of the cpu, derived from on device power
     * measurement data.
     * Returns the battery consumption (in microcoulombs) of wifi, derived from on
     * device power measurement data.
     * Will return {@link #POWER_DATA_UNAVAILABLE} if data is unavailable.
     *
     * {@hide}
     */
    public abstract long getCpuMeasuredBatteryConsumptionUC();
    public abstract long getWifiMeasuredBatteryConsumptionUC();

    /**
     * Returns the battery consumption (in microcoulombs) that each
+2 −2
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public final class WifiActivityEnergyInfo implements Parcelable {
        }
        // Calculate energy used using PowerProfile.
        PowerProfile powerProfile = new PowerProfile(context);
        final double rxIdleCurrent = powerProfile.getAveragePower(
        final double idleCurrent = powerProfile.getAveragePower(
                PowerProfile.POWER_WIFI_CONTROLLER_IDLE);
        final double rxCurrent = powerProfile.getAveragePower(
                PowerProfile.POWER_WIFI_CONTROLLER_RX);
@@ -121,7 +121,7 @@ public final class WifiActivityEnergyInfo implements Parcelable {

        return (long) ((txDurationMillis * txCurrent
                + rxDurationMillis * rxCurrent
                + idleDurationMillis * rxIdleCurrent)
                + idleDurationMillis * idleCurrent)
                * voltage);
    }

Loading