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

Commit eb0d8a7b authored by Mike Ma's avatar Mike Ma
Browse files

Power profile improvement: support ambient display

Add ambient display power to power usage calculation.
Corresponding field in power_profile is "ambient.on"

Bug: 70531652
Test: PowerProfileTest
Test: BatteryStatsHelperTest
Change-Id: I4dfad12875af42de9d517c917b6c1e99323c9fbf
parent c5ad6526
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -113,19 +113,20 @@ public class BatterySipper implements Comparable<BatterySipper> {
    public double bluetoothPowerMah;

    public enum DrainType {
        IDLE,
        CELL,
        PHONE,
        WIFI,
        AMBIENT_DISPLAY,
        APP,
        BLUETOOTH,
        CAMERA,
        CELL,
        FLASHLIGHT,
        IDLE,
        MEMORY,
        OVERCOUNTED,
        PHONE,
        SCREEN,
        APP,
        USER,
        UNACCOUNTED,
        OVERCOUNTED,
        CAMERA,
        MEMORY
        USER,
        WIFI,
    }

    public BatterySipper(DrainType drainType, Uid uid, double value) {
+31 −13
Original line number Diff line number Diff line
@@ -643,6 +643,21 @@ public class BatteryStatsHelper {
        }
    }

    /**
     * Ambient display power is the additional power the screen takes while in ambient display/
     * screen doze/ always-on display (interchangeable terms) mode. Ambient display power should
     * be hidden {@link #shouldHideSipper(BatterySipper)}, but should not be included in smearing
     * {@link #removeHiddenBatterySippers(List)}.
     */
    private void addAmbientDisplayUsage() {
        long ambientDisplayMs = mStats.getScreenDozeTime(mRawRealtimeUs, mStatsType);
        double power = mPowerProfile.getAveragePower(PowerProfile.POWER_AMBIENT_DISPLAY)
                * ambientDisplayMs / (60 * 60 * 1000);
        if (power > 0) {
            addEntry(DrainType.AMBIENT_DISPLAY, ambientDisplayMs, power);
        }
    }

    private void addRadioUsage() {
        BatterySipper radio = new BatterySipper(BatterySipper.DrainType.CELL, null, 0);
        mMobileRadioPowerCalculator.calculateRemaining(radio, mStats, mRawRealtimeUs, mRawUptimeUs,
@@ -741,6 +756,7 @@ public class BatteryStatsHelper {
        addUserUsage();
        addPhoneUsage();
        addScreenUsage();
        addAmbientDisplayUsage();
        addWiFiUsage();
        addBluetoothUsage();
        addMemoryUsage();
@@ -841,12 +857,13 @@ public class BatteryStatsHelper {
            final BatterySipper sipper = sippers.get(i);
            sipper.shouldHide = shouldHideSipper(sipper);
            if (sipper.shouldHide) {
                if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED
                        && sipper.drainType != BatterySipper.DrainType.SCREEN
                        && sipper.drainType != BatterySipper.DrainType.UNACCOUNTED
                        && sipper.drainType != BatterySipper.DrainType.BLUETOOTH
                        && sipper.drainType != BatterySipper.DrainType.WIFI
                        && sipper.drainType != BatterySipper.DrainType.IDLE) {
                if (sipper.drainType != DrainType.OVERCOUNTED
                        && sipper.drainType != DrainType.SCREEN
                        && sipper.drainType != DrainType.AMBIENT_DISPLAY
                        && sipper.drainType != DrainType.UNACCOUNTED
                        && sipper.drainType != DrainType.BLUETOOTH
                        && sipper.drainType != DrainType.WIFI
                        && sipper.drainType != DrainType.IDLE) {
                    // Don't add it if it is overcounted, unaccounted or screen
                    proportionalSmearPowerMah += sipper.totalPowerMah;
                }
@@ -893,13 +910,14 @@ public class BatteryStatsHelper {
     * Check whether we should hide the battery sipper.
     */
    public boolean shouldHideSipper(BatterySipper sipper) {
        final BatterySipper.DrainType drainType = sipper.drainType;

        return drainType == BatterySipper.DrainType.IDLE
                || drainType == BatterySipper.DrainType.CELL
                || drainType == BatterySipper.DrainType.SCREEN
                || drainType == BatterySipper.DrainType.UNACCOUNTED
                || drainType == BatterySipper.DrainType.OVERCOUNTED
        final DrainType drainType = sipper.drainType;

        return drainType == DrainType.IDLE
                || drainType == DrainType.CELL
                || drainType == DrainType.SCREEN
                || drainType == DrainType.AMBIENT_DISPLAY
                || drainType == DrainType.UNACCOUNTED
                || drainType == DrainType.OVERCOUNTED
                || isTypeService(sipper)
                || isTypeSystem(sipper);
    }
+5 −1
Original line number Diff line number Diff line
@@ -136,6 +136,10 @@ public class PowerProfile {
    @Deprecated
    public static final String POWER_BLUETOOTH_AT_CMD = "bluetooth.at";

    /**
     * Power consumption when screen is in doze/ambient/always-on mode, including backlight power.
     */
    public static final String POWER_AMBIENT_DISPLAY = "ambient.on";

    /**
     * Power consumption when screen is on, not including the backlight power.
+3 −2
Original line number Diff line number Diff line
@@ -28,8 +28,9 @@
       significantly, so should be measured on the shipping platform
       with a power meter. -->
  <item name="none">0</item>
  <item name="screen.on">0.1</item>  <!-- ~200mA -->
  <item name="screen.full">0.1</item>  <!-- ~300mA -->
  <item name="ambient.on">0.1</item>  <!-- ~100mA -->
  <item name="screen.on">0.1</item>  <!-- ~100mA -->
  <item name="screen.full">0.1</item>  <!-- ~100mA -->
  <item name="bluetooth.active">0.1</item> <!-- Bluetooth data transfer, ~10mA -->
  <item name="bluetooth.on">0.1</item>  <!-- Bluetooth on & connectable, but not connected, ~0.1mA -->
  <item name="wifi.on">0.1</item>  <!-- ~3mA -->
+2 −0
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@
        <value>60</value> <!-- 3000 MHz CPU speed -->
    </array>

    <!-- Power used by display unit in ambient display mode, including back lighting-->
    <item name="ambient.on">0.5</item>
    <!-- Additional power used when screen is turned on at minimum brightness -->
    <item name="screen.on">100</item>
    <!-- Additional power used when screen is at maximum brightness, compared to
Loading