diff options
| author | Dmitri Plotnikov <dplotnikov@google.com> | 2021-01-29 14:11:27 -0800 |
|---|---|---|
| committer | Dmitri Plotnikov <dplotnikov@google.com> | 2021-02-09 12:57:15 -0800 |
| commit | be9d9eb47a525d966c70cb9f9c1c2bc2e3e2d4ec (patch) | |
| tree | 83f84fe8369977dfdff0f44c813bca24e14e21eb /core/java/android/os/BatteryUsageStatsQuery.java | |
| parent | 94d2b53e6204c223133ccc037f114be5acc046f8 (diff) | |
Convert UserPowerCalculator to work with BatteryUsageStats
Test: atest FrameworksCoreTests:com.android.internal.os.UserPowerCalculatorTest
Bug: 158137862
Change-Id: Ibfd0138a2e455e2242750518d89c620901326d11
Diffstat (limited to 'core/java/android/os/BatteryUsageStatsQuery.java')
| -rw-r--r-- | core/java/android/os/BatteryUsageStatsQuery.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/java/android/os/BatteryUsageStatsQuery.java b/core/java/android/os/BatteryUsageStatsQuery.java index 48e7389e5ff2..5b5fe1d15a82 100644 --- a/core/java/android/os/BatteryUsageStatsQuery.java +++ b/core/java/android/os/BatteryUsageStatsQuery.java @@ -18,6 +18,7 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; +import android.util.IntArray; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -53,9 +54,13 @@ public final class BatteryUsageStatsQuery implements Parcelable { public static final int FLAG_BATTERY_USAGE_STATS_POWER_PROFILE_MODEL = 1; private final int mFlags; + @NonNull + private final int[] mUserIds; private BatteryUsageStatsQuery(@NonNull Builder builder) { mFlags = builder.mFlags; + mUserIds = builder.mUserIds != null ? builder.mUserIds.toArray() + : new int[]{UserHandle.USER_ALL}; } @BatteryUsageStatsFlags @@ -63,13 +68,28 @@ public final class BatteryUsageStatsQuery implements Parcelable { return mFlags; } + /** + * Returns an array of users for which the attribution is requested. It may + * contain {@link UserHandle#USER_ALL} to indicate that the attribution + * should be performed for all users. Battery consumed by users <b>not</b> included + * in this array will be returned in the aggregated form as {@link UserBatteryConsumer}'s. + */ + @NonNull + public int[] getUserIds() { + return mUserIds; + } + private BatteryUsageStatsQuery(Parcel in) { mFlags = in.readInt(); + mUserIds = new int[in.readInt()]; + in.readIntArray(mUserIds); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mFlags); + dest.writeInt(mUserIds.length); + dest.writeIntArray(mUserIds); } @Override @@ -96,6 +116,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { */ public static final class Builder { private int mFlags; + private IntArray mUserIds; /** * Builds a read-only BatteryUsageStatsQuery object. @@ -105,6 +126,18 @@ public final class BatteryUsageStatsQuery implements Parcelable { } /** + * Add a user whose battery stats should be included in the battery usage stats. + * {@link UserHandle#USER_ALL} will be used by default if no users are added explicitly. + */ + public Builder addUser(@NonNull UserHandle userHandle) { + if (mUserIds == null) { + mUserIds = new IntArray(1); + } + mUserIds.add(userHandle.getIdentifier()); + return this; + } + + /** * Sets flags to modify the behavior of {@link BatteryStatsManager#getBatteryUsageStats}. */ public Builder setFlags(@BatteryUsageStatsFlags int flags) { |
