Loading core/java/android/os/BatteryConsumer.java +20 −13 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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; Loading @@ -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; Loading @@ -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, Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading core/java/android/os/PowerComponents.java +15 −2 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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]; } } Loading core/java/android/os/SystemBatteryConsumer.java +7 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading core/java/com/android/internal/os/AmbientDisplayPowerCalculator.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading core/java/com/android/internal/os/IdlePowerCalculator.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading
core/java/android/os/BatteryConsumer.java +20 −13 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -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; Loading @@ -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; Loading @@ -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, Loading @@ -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; Loading @@ -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; Loading Loading @@ -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; Loading
core/java/android/os/PowerComponents.java +15 −2 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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]; } } Loading
core/java/android/os/SystemBatteryConsumer.java +7 −0 Original line number Diff line number Diff line Loading @@ -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. */ Loading
core/java/com/android/internal/os/AmbientDisplayPowerCalculator.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading
core/java/com/android/internal/os/IdlePowerCalculator.java +2 −2 Original line number Diff line number Diff line Loading @@ -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