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

Commit 9e19e96a authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Remove POWER_COMPONENT_USAGE and TIME_COMPONENT_USAGE

... and use specific power components, such as POWER_COMPONENT_SCREEN

Bug: 184397335
Test: atest FrameworksCoreTests:com.android.internal.os.BatteryStatsTests
Test: mp :BatteryStatsViewer && adb shell am start -n com.android.frameworks.core.batterystatsviewer/.BatteryStatsViewerActivity
Change-Id: I551b2d37d2da77e21e622961f5290b55fb24da61
parent 177de2ed
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public abstract class BatteryConsumer {
     * @hide
     */
    @IntDef(prefix = {"POWER_COMPONENT_"}, value = {
            POWER_COMPONENT_USAGE,
            POWER_COMPONENT_SCREEN,
            POWER_COMPONENT_CPU,
            POWER_COMPONENT_BLUETOOTH,
            POWER_COMPONENT_CAMERA,
@@ -49,14 +49,16 @@ public abstract class BatteryConsumer {
            POWER_COMPONENT_GNSS,
            POWER_COMPONENT_WIFI,
            POWER_COMPONENT_WAKELOCK,
            POWER_COMPONENT_SCREEN,
            POWER_COMPONENT_MEMORY,
            POWER_COMPONENT_PHONE,
            POWER_COMPONENT_IDLE,
            POWER_COMPONENT_REATTRIBUTED_TO_OTHER_CONSUMERS,
    })
    @Retention(RetentionPolicy.SOURCE)
    public static @interface PowerComponent {
    }

    public static final int POWER_COMPONENT_USAGE = 0;
    public static final int POWER_COMPONENT_SCREEN = 0;
    public static final int POWER_COMPONENT_CPU = 1;
    public static final int POWER_COMPONENT_BLUETOOTH = 2;
    public static final int POWER_COMPONENT_CAMERA = 3;
@@ -69,13 +71,15 @@ public abstract class BatteryConsumer {
    public static final int POWER_COMPONENT_GNSS = 10;
    public static final int POWER_COMPONENT_WIFI = 11;
    public static final int POWER_COMPONENT_WAKELOCK = 12;
    public static final int POWER_COMPONENT_SCREEN = 13;
    public static final int POWER_COMPONENT_MEMORY = 13;
    public static final int POWER_COMPONENT_PHONE = 13;
    public static final int POWER_COMPONENT_IDLE = 15;
    // Power that is re-attributed to other battery consumers. For example, for System Server
    // this represents the power attributed to apps requesting system services.
    // The value should be negative or zero.
    public static final int POWER_COMPONENT_REATTRIBUTED_TO_OTHER_CONSUMERS = 14;
    public static final int POWER_COMPONENT_REATTRIBUTED_TO_OTHER_CONSUMERS = 16;

    public static final int POWER_COMPONENT_COUNT = 15;
    public static final int POWER_COMPONENT_COUNT = 17;

    public static final int FIRST_CUSTOM_POWER_COMPONENT_ID = 1000;
    public static final int LAST_CUSTOM_POWER_COMPONENT_ID = 9999;
@@ -87,7 +91,7 @@ public abstract class BatteryConsumer {
     * @hide
     */
    @IntDef(prefix = {"TIME_COMPONENT_"}, value = {
            TIME_COMPONENT_USAGE,
            TIME_COMPONENT_SCREEN,
            TIME_COMPONENT_CPU,
            TIME_COMPONENT_CPU_FOREGROUND,
            TIME_COMPONENT_BLUETOOTH,
@@ -98,13 +102,15 @@ public abstract class BatteryConsumer {
            TIME_COMPONENT_GNSS,
            TIME_COMPONENT_WIFI,
            TIME_COMPONENT_WAKELOCK,
            TIME_COMPONENT_SCREEN,
            TIME_COMPONENT_MEMORY,
            TIME_COMPONENT_PHONE,
            TIME_COMPONENT_IDLE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public static @interface TimeComponent {
    }

    public static final int TIME_COMPONENT_USAGE = 0;
    public static final int TIME_COMPONENT_SCREEN = 0;
    public static final int TIME_COMPONENT_CPU = 1;
    public static final int TIME_COMPONENT_CPU_FOREGROUND = 2;
    public static final int TIME_COMPONENT_BLUETOOTH = 3;
@@ -117,9 +123,11 @@ public abstract class BatteryConsumer {
    public static final int TIME_COMPONENT_GNSS = 10;
    public static final int TIME_COMPONENT_WIFI = 11;
    public static final int TIME_COMPONENT_WAKELOCK = 12;
    public static final int TIME_COMPONENT_SCREEN = 13;
    public static final int TIME_COMPONENT_MEMORY = 13;
    public static final int TIME_COMPONENT_PHONE = 14;
    public static final int TIME_COMPONENT_IDLE = 15;

    public static final int TIME_COMPONENT_COUNT = 14;
    public static final int TIME_COMPONENT_COUNT = 16;

    public static final int FIRST_CUSTOM_TIME_COMPONENT_ID = 1000;
    public static final int LAST_CUSTOM_TIME_COMPONENT_ID = 9999;
@@ -148,8 +156,7 @@ public abstract class BatteryConsumer {
     */
    public static final int POWER_MODEL_MEASURED_ENERGY = 1;

    private final PowerComponents mPowerComponents;
    private String[] mCustomPowerComponentNames;
    protected final PowerComponents mPowerComponents;

    protected BatteryConsumer(@NonNull PowerComponents powerComponents) {
        mPowerComponents = powerComponents;
+15 −2
Original line number Diff line number Diff line
@@ -191,6 +191,19 @@ class PowerComponents {
        return mCustomPowerComponentCount;
    }

    /**
     * Returns the largest usage duration among all time components.
     */
    public long getMaxComponentUsageDurationMillis() {
        long max = 0;
        for (int i = mTimeComponentsMs.length - 1; i >= 0; i--) {
            if (mTimeComponentsMs[i] > max) {
                max = mTimeComponentsMs[i];
            }
        }
        return max;
    }

    /**
     * Builder for PowerComponents.
     */
@@ -312,10 +325,10 @@ class PowerComponents {
        }

        public void addPowerAndDuration(Builder other) {
            for (int i = 0; i < mPowerComponentsMah.length; i++) {
            for (int i = mPowerComponentsMah.length - 1; i >= 0; i--) {
                mPowerComponentsMah[i] += other.mPowerComponentsMah[i];
            }
            for (int i = 0; i < mTimeComponentsMs.length; i++) {
            for (int i = mTimeComponentsMs.length - 1; i >= 0; i--) {
                mTimeComponentsMs[i] += other.mTimeComponentsMs[i];
            }
        }
+7 −0
Original line number Diff line number Diff line
@@ -103,6 +103,13 @@ public class SystemBatteryConsumer extends BatteryConsumer implements Parcelable
        return mPowerConsumedByAppsMah;
    }

    /**
     * Returns the amount of time this consumer was operating.
     */
    public long getUsageDurationMillis() {
        return mPowerComponents.getMaxComponentUsageDurationMillis();
    }

    /**
     * Writes the contents into a Parcel.
     */
+2 −2
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ public class AmbientDisplayPowerCalculator extends PowerCalculator {
                measuredEnergyUC, mPowerEstimator, durationMs);
        builder.getOrCreateSystemBatteryConsumerBuilder(
                        SystemBatteryConsumer.DRAIN_TYPE_AMBIENT_DISPLAY)
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_USAGE, powerMah, powerModel)
                .setUsageDurationMillis(BatteryConsumer.TIME_COMPONENT_USAGE, durationMs);
                .setConsumedPower(BatteryConsumer.POWER_COMPONENT_SCREEN, powerMah, powerModel)
                .setUsageDurationMillis(BatteryConsumer.TIME_COMPONENT_SCREEN, durationMs);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ public class IdlePowerCalculator extends PowerCalculator {
                BatteryStats.STATS_SINCE_CHARGED);
        if (mPowerMah != 0) {
            builder.getOrCreateSystemBatteryConsumerBuilder(SystemBatteryConsumer.DRAIN_TYPE_IDLE)
                    .setConsumedPower(BatteryConsumer.POWER_COMPONENT_USAGE, mPowerMah)
                    .setUsageDurationMillis(BatteryConsumer.TIME_COMPONENT_USAGE, mDurationMs);
                    .setConsumedPower(BatteryConsumer.POWER_COMPONENT_IDLE, mPowerMah)
                    .setUsageDurationMillis(BatteryConsumer.TIME_COMPONENT_IDLE, mDurationMs);
        }
    }

Loading