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

Commit 8576cf94 authored by Adam Lesinski's avatar Adam Lesinski
Browse files

Fix calculation of power drain from BT and WiFi

Unit issue (mV vs V).

Change-Id: I08843312339ccf35a3b55b1c2385c36fdbf61ead
parent e3fd6de9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -354,9 +354,9 @@ public final class BatteryStatsHelper {

        if (mBluetoothPowerCalculator == null) {
            if (checkHasBluetoothPowerReporting(mStats, mPowerProfile)) {
                mBluetoothPowerCalculator = new BluetoothPowerCalculator();
                mBluetoothPowerCalculator = new BluetoothPowerCalculator(mPowerProfile);
            } else {
                mBluetoothPowerCalculator = new BluetoothPowerCalculator();
                mBluetoothPowerCalculator = new BluetoothPowerCalculator(mPowerProfile);
            }
        }
        mBluetoothPowerCalculator.reset();
+12 −8
Original line number Diff line number Diff line
@@ -7814,11 +7814,13 @@ public final class BatteryStatsImpl extends BatteryStats {
            mWifiActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked(
                    info.getControllerIdleTimeMillis());

            final double opVoltage = mPowerProfile.getAveragePower(
                    PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE);
            if (opVoltage != 0) {
            // POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
            final double opVolt = mPowerProfile.getAveragePower(
                    PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
            if (opVolt != 0) {
                // We store the power drain as mAms.
                mWifiActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked(
                        (long)(info.getControllerEnergyUsed() / opVoltage));
                        (long)(info.getControllerEnergyUsed() / opVolt));
            }
        }
    }
@@ -7908,11 +7910,13 @@ public final class BatteryStatsImpl extends BatteryStats {
            mBluetoothActivityCounters[CONTROLLER_IDLE_TIME].addCountLocked(
                    info.getControllerIdleTimeMillis());

            final double opVoltage = mPowerProfile.getAveragePower(
                    PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE);
            if (opVoltage != 0) {
            // POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
            final double opVolt = mPowerProfile.getAveragePower(
                    PowerProfile.POWER_BLUETOOTH_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
            if (opVolt != 0) {
                // We store the power drain as mAms.
                mBluetoothActivityCounters[CONTROLLER_POWER_DRAIN].addCountLocked(
                        (long) (info.getControllerEnergyUsed() / opVoltage));
                        (long) (info.getControllerEnergyUsed() / opVolt));
            }
        }
    }
+17 −3
Original line number Diff line number Diff line
@@ -21,6 +21,15 @@ import android.util.Log;
public class BluetoothPowerCalculator extends PowerCalculator {
    private static final boolean DEBUG = BatteryStatsHelper.DEBUG;
    private static final String TAG = "BluetoothPowerCalculator";
    private final double mIdleMa;
    private final double mRxMa;
    private final double mTxMa;

    public BluetoothPowerCalculator(PowerProfile profile) {
        mIdleMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_IDLE);
        mRxMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_RX);
        mTxMa = profile.getAveragePower(PowerProfile.POWER_BLUETOOTH_CONTROLLER_TX);
    }

    @Override
    public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs,
@@ -37,10 +46,15 @@ public class BluetoothPowerCalculator extends PowerCalculator {
                BatteryStats.CONTROLLER_TX_TIME, statsType);
        final long rxTimeMs = stats.getBluetoothControllerActivity(
                BatteryStats.CONTROLLER_RX_TIME, statsType);
        final long powerMaMs = stats.getBluetoothControllerActivity(
                BatteryStats.CONTROLLER_POWER_DRAIN, statsType);
        final double powerMah = powerMaMs / (double)(1000*60*60);
        final long totalTimeMs = idleTimeMs + txTimeMs + rxTimeMs;
        double powerMah = stats.getBluetoothControllerActivity(
                BatteryStats.CONTROLLER_POWER_DRAIN, statsType) / (double)(1000*60*60);

        if (powerMah == 0) {
            // Some devices do not report the power, so calculate it.
            powerMah = ((idleTimeMs * mIdleMa) + (rxTimeMs * mRxMa) + (txTimeMs * mTxMa))
                    / (1000*60*60);
        }

        if (DEBUG && powerMah != 0) {
            Log.d(TAG, "Bluetooth active: time=" + (totalTimeMs)
+4 −4
Original line number Diff line number Diff line
@@ -70,14 +70,14 @@ public class WifiPowerCalculator extends PowerCalculator {
                statsType);
        app.wifiRunningTimeMs = idleTimeMs + rxTimeMs + txTimeMs;

        double powerDrain = stats.getWifiControllerActivity(BatteryStats.CONTROLLER_POWER_DRAIN,
        double powerDrainMah = stats.getWifiControllerActivity(BatteryStats.CONTROLLER_POWER_DRAIN,
                statsType) / (double)(1000*60*60);
        if (powerDrain == 0) {
        if (powerDrainMah == 0) {
            // Some controllers do not report power drain, so we can calculate it here.
            powerDrain = ((idleTimeMs * mIdleCurrentMa) + (txTimeMs * mTxCurrentMa)
            powerDrainMah = ((idleTimeMs * mIdleCurrentMa) + (txTimeMs * mTxCurrentMa)
                    + (rxTimeMs * mRxCurrentMa)) / (1000*60*60);
        }
        app.wifiPowerMah = Math.max(0, powerDrain - mTotalAppPowerDrain);
        app.wifiPowerMah = Math.max(0, powerDrainMah - mTotalAppPowerDrain);

        if (DEBUG) {
            Log.d(TAG, "left over WiFi power: " + BatteryStatsHelper.makemAh(app.wifiPowerMah));