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

Commit 026102b5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add SystemBatteryConsumer for the Bluetooth drain type"

parents 36ca6d34 8677b4eb
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -36,7 +36,9 @@ public abstract class BatteryConsumer {
     * @hide
     */
    @IntDef(prefix = {"POWER_COMPONENT_"}, value = {
            POWER_COMPONENT_USAGE,
            POWER_COMPONENT_CPU,
            POWER_COMPONENT_BLUETOOTH,
    })
    @Retention(RetentionPolicy.SOURCE)
    public static @interface PowerComponent {
@@ -44,8 +46,9 @@ public abstract class BatteryConsumer {

    public static final int POWER_COMPONENT_USAGE = 0;
    public static final int POWER_COMPONENT_CPU = 1;
    public static final int POWER_COMPONENT_BLUETOOTH = 2;

    public static final int POWER_COMPONENT_COUNT = 2;
    public static final int POWER_COMPONENT_COUNT = 3;

    public static final int FIRST_CUSTOM_POWER_COMPONENT_ID = 1000;
    public static final int LAST_CUSTOM_POWER_COMPONENT_ID = 9999;
@@ -68,8 +71,10 @@ public abstract class BatteryConsumer {
     * @hide
     */
    @IntDef(prefix = {"TIME_COMPONENT_"}, value = {
            TIME_COMPONENT_USAGE,
            TIME_COMPONENT_CPU,
            TIME_COMPONENT_CPU_FOREGROUND,
            TIME_COMPONENT_BLUETOOTH,
    })
    @Retention(RetentionPolicy.SOURCE)
    public static @interface TimeComponent {
@@ -78,8 +83,9 @@ public abstract class BatteryConsumer {
    public static final int TIME_COMPONENT_USAGE = 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;

    public static final int TIME_COMPONENT_COUNT = 3;
    public static final int TIME_COMPONENT_COUNT = 4;

    public static final int FIRST_CUSTOM_TIME_COMPONENT_ID = 1000;
    public static final int LAST_CUSTOM_TIME_COMPONENT_ID = 9999;
+9 −0
Original line number Diff line number Diff line
@@ -289,6 +289,15 @@ class PowerComponents {
            return this;
        }

        public void addPowerAndDuration(Builder other) {
            for (int i = 0; i < mPowerComponents.length; i++) {
                mPowerComponents[i] += other.mPowerComponents[i];
            }
            for (int i = 0; i < mTimeComponents.length; i++) {
                mTimeComponents[i] += other.mTimeComponents[i];
            }
        }

        /**
         * Creates a read-only object out of the Builder values.
         */
+28 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;


/**
@@ -118,6 +120,7 @@ public class SystemBatteryConsumer extends BatteryConsumer implements Parcelable
    public static final class Builder extends BaseBuilder<Builder> {
        @DrainType
        private final int mDrainType;
        private List<UidBatteryConsumer.Builder> mUidBatteryConsumers;

        Builder(int customPowerComponentCount, int customTimeComponentCount,
                boolean includeModeledComponents, @DrainType int drainType) {
@@ -125,11 +128,36 @@ public class SystemBatteryConsumer extends BatteryConsumer implements Parcelable
            mDrainType = drainType;
        }

        /**
         * Add a UidBatteryConsumer to this SystemBatteryConsumer. For example,
         * the UidBatteryConsumer with the UID == {@link Process#BLUETOOTH_UID} should
         * be added to the SystemBatteryConsumer with the drain type == {@link
         * #DRAIN_TYPE_BLUETOOTH}.
         * <p>
         * Calculated power and duration components of the added battery consumers
         * are aggregated at the time the SystemBatteryConsumer is built by the {@link #build()}
         * method.
         * </p>
         */
        public void addUidBatteryConsumer(UidBatteryConsumer.Builder uidBatteryConsumerBuilder) {
            if (mUidBatteryConsumers == null) {
                mUidBatteryConsumers = new ArrayList<>();
            }
            mUidBatteryConsumers.add(uidBatteryConsumerBuilder);
        }

        /**
         * Creates a read-only object out of the Builder values.
         */
        @NonNull
        public SystemBatteryConsumer build() {
            if (mUidBatteryConsumers != null) {
                for (int i = mUidBatteryConsumers.size() - 1; i >= 0; i--) {
                    UidBatteryConsumer.Builder uidBatteryConsumer = mUidBatteryConsumers.get(i);
                    mPowerComponentsBuilder.addPowerAndDuration(
                            uidBatteryConsumer.mPowerComponentsBuilder);
                }
            }
            return new SystemBatteryConsumer(this);
        }
    }
+21 −0
Original line number Diff line number Diff line
@@ -29,11 +29,21 @@ public final class UidBatteryConsumer extends BatteryConsumer implements Parcela
    private final int mUid;
    @Nullable
    private final String mPackageWithHighestDrain;
    private boolean mSystemComponent;

    public int getUid() {
        return mUid;
    }

    /**
     * Returns true if this battery consumer is considered to be a part of the operating
     * system itself. For example, the UidBatteryConsumer with the UID {@link Process#BLUETOOTH_UID}
     * is a system component.
     */
    public boolean isSystemComponent() {
        return mSystemComponent;
    }

    @Nullable
    public String getPackageWithHighestDrain() {
        return mPackageWithHighestDrain;
@@ -42,6 +52,7 @@ public final class UidBatteryConsumer extends BatteryConsumer implements Parcela
    private UidBatteryConsumer(@NonNull Builder builder) {
        super(builder.mPowerComponentsBuilder.build());
        mUid = builder.mUid;
        mSystemComponent = builder.mSystemComponent;
        mPackageWithHighestDrain = builder.mPackageWithHighestDrain;
    }

@@ -84,6 +95,7 @@ public final class UidBatteryConsumer extends BatteryConsumer implements Parcela
        private final BatteryStats.Uid mBatteryStatsUid;
        private final int mUid;
        private String mPackageWithHighestDrain;
        private boolean mSystemComponent;

        public Builder(int customPowerComponentCount, int customTimeComponentCount,
                boolean includeModeledComponents, BatteryStats.Uid batteryStatsUid) {
@@ -117,5 +129,14 @@ public final class UidBatteryConsumer extends BatteryConsumer implements Parcela
            mPackageWithHighestDrain = packageName;
            return this;
        }

        /**
         * Marks the UidBatteryConsumer as part of the system. For example,
         * the UidBatteryConsumer with the UID {@link Process#BLUETOOTH_UID} is considered
         * as a system component.
         */
        public void setSystemComponent(boolean systemComponent) {
            mSystemComponent = systemComponent;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -953,7 +953,8 @@ public class BatteryStatsImpl extends BatteryStats {
    /**
     * The Bluetooth controller activity (time in tx, rx, idle, and power consumed) for the device.
     */
    ControllerActivityCounterImpl mBluetoothActivity;
    @VisibleForTesting
    protected ControllerActivityCounterImpl mBluetoothActivity;
    /**
     * The Modem controller activity (time in tx, rx, idle, and power consumed) for the device.
Loading