Loading core/java/android/os/BatteryConsumer.java +8 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading @@ -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 { Loading @@ -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; Loading core/java/android/os/PowerComponents.java +9 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading core/java/android/os/SystemBatteryConsumer.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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) { Loading @@ -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); } } Loading core/java/android/os/UidBatteryConsumer.java +21 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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) { Loading Loading @@ -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; } } } core/java/com/android/internal/os/BatteryStatsImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
core/java/android/os/BatteryConsumer.java +8 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading @@ -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 { Loading @@ -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; Loading
core/java/android/os/PowerComponents.java +9 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading
core/java/android/os/SystemBatteryConsumer.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; /** Loading Loading @@ -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) { Loading @@ -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); } } Loading
core/java/android/os/UidBatteryConsumer.java +21 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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) { Loading Loading @@ -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; } } }
core/java/com/android/internal/os/BatteryStatsImpl.java +2 −1 Original line number Diff line number Diff line Loading @@ -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