Loading core/java/android/os/BatteryConsumer.java +14 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,17 @@ public abstract class BatteryConsumer { public static final int FIRST_CUSTOM_POWER_COMPONENT_ID = 1000; public static final int LAST_CUSTOM_POWER_COMPONENT_ID = 9999; /** * Modeled power components are used for testing only. They are returned if the * {@link BatteryUsageStatsQuery#FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED} is set. * The modeled power components are retrieved with {@link #getConsumedPowerForCustomComponent}. * The ID of a modeled power component is calculated as * (FIRST_MODELED_POWER_COMPONENT_ID + powerComponentId), e.g. * FIRST_MODELED_POWER_COMPONENT_ID + POWER_COMPONENT_CPU. */ public static final int FIRST_MODELED_POWER_COMPONENT_ID = 10000; public static final int LAST_MODELED_POWER_COMPONENT_ID = 19999; /** * Time usage component, describing the particular part of the system * that was used for the corresponding amount of time. Loading Loading @@ -137,9 +148,10 @@ public abstract class BatteryConsumer { protected abstract static class BaseBuilder<T extends BaseBuilder<?>> { final PowerComponents.Builder mPowerComponentsBuilder; public BaseBuilder(int customPowerComponentCount, int customTimeComponentCount) { public BaseBuilder(int customPowerComponentCount, int customTimeComponentCount, boolean includeModeledComponents) { mPowerComponentsBuilder = new PowerComponents.Builder(customPowerComponentCount, customTimeComponentCount); customTimeComponentCount, includeModeledComponents); } /** Loading core/java/android/os/BatteryStatsManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,7 @@ public final class BatteryStatsManager { mBatteryStats = batteryStats; } /** * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem * and per-UID basis. Loading @@ -169,8 +170,20 @@ public final class BatteryStatsManager { @RequiresPermission(android.Manifest.permission.BATTERY_STATS) @NonNull public BatteryUsageStats getBatteryUsageStats() { return getBatteryUsageStats(BatteryUsageStatsQuery.DEFAULT); } /** * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem * and per-UID basis. * * @hide */ @RequiresPermission(android.Manifest.permission.BATTERY_STATS) @NonNull public BatteryUsageStats getBatteryUsageStats(BatteryUsageStatsQuery query) { try { return mBatteryStats.getBatteryUsageStats(); return mBatteryStats.getBatteryUsageStats(query); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading core/java/android/os/BatteryUsageStats.java +6 −3 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ public final class BatteryUsageStats implements Parcelable { public static final class Builder { private final int mCustomPowerComponentCount; private final int mCustomTimeComponentCount; private final boolean mIncludeModeledComponents; private double mConsumedPower; private int mDischargePercentage; private final SparseArray<UidBatteryConsumer.Builder> mUidBatteryConsumerBuilders = Loading @@ -121,9 +122,11 @@ public final class BatteryUsageStats implements Parcelable { private final SparseArray<SystemBatteryConsumer.Builder> mSystemBatteryConsumerBuilders = new SparseArray<>(); public Builder(int customPowerComponentCount, int customTimeComponentCount) { public Builder(int customPowerComponentCount, int customTimeComponentCount, boolean includeModeledComponents) { mCustomPowerComponentCount = customPowerComponentCount; mCustomTimeComponentCount = customTimeComponentCount; mIncludeModeledComponents = includeModeledComponents; } /** Loading Loading @@ -166,7 +169,7 @@ public final class BatteryUsageStats implements Parcelable { UidBatteryConsumer.Builder builder = mUidBatteryConsumerBuilders.get(uid); if (builder == null) { builder = new UidBatteryConsumer.Builder(mCustomPowerComponentCount, mCustomTimeComponentCount, batteryStatsUid); mCustomTimeComponentCount, mIncludeModeledComponents, batteryStatsUid); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -182,7 +185,7 @@ public final class BatteryUsageStats implements Parcelable { SystemBatteryConsumer.Builder builder = mSystemBatteryConsumerBuilders.get(drainType); if (builder == null) { builder = new SystemBatteryConsumer.Builder(mCustomPowerComponentCount, mCustomTimeComponentCount, drainType); mCustomTimeComponentCount, mIncludeModeledComponents, drainType); mSystemBatteryConsumerBuilders.put(drainType, builder); } return builder; Loading core/java/android/os/BatteryUsageStatsQuery.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; parcelable BatteryUsageStatsQuery; core/java/android/os/BatteryUsageStatsQuery.java 0 → 100644 +123 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Query parameters for the {@link BatteryStatsManager#getBatteryUsageStats()} call. * * @hide */ public final class BatteryUsageStatsQuery implements Parcelable { @NonNull public static final BatteryUsageStatsQuery DEFAULT = new BatteryUsageStatsQuery.Builder().build(); /** * Flags for the {@link BatteryStatsManager#getBatteryUsageStats()} method. * @hide */ @IntDef(flag = true, prefix = { "FLAG_BATTERY_USAGE_STATS_" }, value = { FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED, }) @Retention(RetentionPolicy.SOURCE) public @interface BatteryUsageStatsFlags {} /** * Indicates that modeled battery usage stats should be returned along with * measured ones. * * @hide */ public static final int FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED = 1; private final int mFlags; private BatteryUsageStatsQuery(@NonNull Builder builder) { mFlags = builder.mFlags; } @BatteryUsageStatsFlags public int getFlags() { return mFlags; } private BatteryUsageStatsQuery(Parcel in) { mFlags = in.readInt(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mFlags); } @Override public int describeContents() { return 0; } @NonNull public static final Creator<BatteryUsageStatsQuery> CREATOR = new Creator<BatteryUsageStatsQuery>() { @Override public BatteryUsageStatsQuery createFromParcel(Parcel in) { return new BatteryUsageStatsQuery(in); } @Override public BatteryUsageStatsQuery[] newArray(int size) { return new BatteryUsageStatsQuery[size]; } }; /** * Builder for BatteryUsageStatsQuery. */ public static final class Builder { private int mFlags; /** * Builds a read-only BatteryUsageStatsQuery object. */ public BatteryUsageStatsQuery build() { return new BatteryUsageStatsQuery(this); } /** * Sets flags to modify the behavior of {@link BatteryStatsManager#getBatteryUsageStats}. */ public Builder setFlags(@BatteryUsageStatsFlags int flags) { mFlags = flags; return this; } /** * Requests to include modeled battery usage stats along with measured ones. * Should only be used for testing and debugging. */ public Builder includeModeled() { mFlags |= BatteryUsageStatsQuery.FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED; return this; } } } Loading
core/java/android/os/BatteryConsumer.java +14 −2 Original line number Diff line number Diff line Loading @@ -50,6 +50,17 @@ public abstract class BatteryConsumer { public static final int FIRST_CUSTOM_POWER_COMPONENT_ID = 1000; public static final int LAST_CUSTOM_POWER_COMPONENT_ID = 9999; /** * Modeled power components are used for testing only. They are returned if the * {@link BatteryUsageStatsQuery#FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED} is set. * The modeled power components are retrieved with {@link #getConsumedPowerForCustomComponent}. * The ID of a modeled power component is calculated as * (FIRST_MODELED_POWER_COMPONENT_ID + powerComponentId), e.g. * FIRST_MODELED_POWER_COMPONENT_ID + POWER_COMPONENT_CPU. */ public static final int FIRST_MODELED_POWER_COMPONENT_ID = 10000; public static final int LAST_MODELED_POWER_COMPONENT_ID = 19999; /** * Time usage component, describing the particular part of the system * that was used for the corresponding amount of time. Loading Loading @@ -137,9 +148,10 @@ public abstract class BatteryConsumer { protected abstract static class BaseBuilder<T extends BaseBuilder<?>> { final PowerComponents.Builder mPowerComponentsBuilder; public BaseBuilder(int customPowerComponentCount, int customTimeComponentCount) { public BaseBuilder(int customPowerComponentCount, int customTimeComponentCount, boolean includeModeledComponents) { mPowerComponentsBuilder = new PowerComponents.Builder(customPowerComponentCount, customTimeComponentCount); customTimeComponentCount, includeModeledComponents); } /** Loading
core/java/android/os/BatteryStatsManager.java +14 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,7 @@ public final class BatteryStatsManager { mBatteryStats = batteryStats; } /** * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem * and per-UID basis. Loading @@ -169,8 +170,20 @@ public final class BatteryStatsManager { @RequiresPermission(android.Manifest.permission.BATTERY_STATS) @NonNull public BatteryUsageStats getBatteryUsageStats() { return getBatteryUsageStats(BatteryUsageStatsQuery.DEFAULT); } /** * Returns BatteryUsageStats, which contains power attribution data on a per-subsystem * and per-UID basis. * * @hide */ @RequiresPermission(android.Manifest.permission.BATTERY_STATS) @NonNull public BatteryUsageStats getBatteryUsageStats(BatteryUsageStatsQuery query) { try { return mBatteryStats.getBatteryUsageStats(); return mBatteryStats.getBatteryUsageStats(query); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
core/java/android/os/BatteryUsageStats.java +6 −3 Original line number Diff line number Diff line Loading @@ -114,6 +114,7 @@ public final class BatteryUsageStats implements Parcelable { public static final class Builder { private final int mCustomPowerComponentCount; private final int mCustomTimeComponentCount; private final boolean mIncludeModeledComponents; private double mConsumedPower; private int mDischargePercentage; private final SparseArray<UidBatteryConsumer.Builder> mUidBatteryConsumerBuilders = Loading @@ -121,9 +122,11 @@ public final class BatteryUsageStats implements Parcelable { private final SparseArray<SystemBatteryConsumer.Builder> mSystemBatteryConsumerBuilders = new SparseArray<>(); public Builder(int customPowerComponentCount, int customTimeComponentCount) { public Builder(int customPowerComponentCount, int customTimeComponentCount, boolean includeModeledComponents) { mCustomPowerComponentCount = customPowerComponentCount; mCustomTimeComponentCount = customTimeComponentCount; mIncludeModeledComponents = includeModeledComponents; } /** Loading Loading @@ -166,7 +169,7 @@ public final class BatteryUsageStats implements Parcelable { UidBatteryConsumer.Builder builder = mUidBatteryConsumerBuilders.get(uid); if (builder == null) { builder = new UidBatteryConsumer.Builder(mCustomPowerComponentCount, mCustomTimeComponentCount, batteryStatsUid); mCustomTimeComponentCount, mIncludeModeledComponents, batteryStatsUid); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -182,7 +185,7 @@ public final class BatteryUsageStats implements Parcelable { SystemBatteryConsumer.Builder builder = mSystemBatteryConsumerBuilders.get(drainType); if (builder == null) { builder = new SystemBatteryConsumer.Builder(mCustomPowerComponentCount, mCustomTimeComponentCount, drainType); mCustomTimeComponentCount, mIncludeModeledComponents, drainType); mSystemBatteryConsumerBuilders.put(drainType, builder); } return builder; Loading
core/java/android/os/BatteryUsageStatsQuery.aidl 0 → 100644 +19 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; parcelable BatteryUsageStatsQuery;
core/java/android/os/BatteryUsageStatsQuery.java 0 → 100644 +123 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** * Query parameters for the {@link BatteryStatsManager#getBatteryUsageStats()} call. * * @hide */ public final class BatteryUsageStatsQuery implements Parcelable { @NonNull public static final BatteryUsageStatsQuery DEFAULT = new BatteryUsageStatsQuery.Builder().build(); /** * Flags for the {@link BatteryStatsManager#getBatteryUsageStats()} method. * @hide */ @IntDef(flag = true, prefix = { "FLAG_BATTERY_USAGE_STATS_" }, value = { FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED, }) @Retention(RetentionPolicy.SOURCE) public @interface BatteryUsageStatsFlags {} /** * Indicates that modeled battery usage stats should be returned along with * measured ones. * * @hide */ public static final int FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED = 1; private final int mFlags; private BatteryUsageStatsQuery(@NonNull Builder builder) { mFlags = builder.mFlags; } @BatteryUsageStatsFlags public int getFlags() { return mFlags; } private BatteryUsageStatsQuery(Parcel in) { mFlags = in.readInt(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mFlags); } @Override public int describeContents() { return 0; } @NonNull public static final Creator<BatteryUsageStatsQuery> CREATOR = new Creator<BatteryUsageStatsQuery>() { @Override public BatteryUsageStatsQuery createFromParcel(Parcel in) { return new BatteryUsageStatsQuery(in); } @Override public BatteryUsageStatsQuery[] newArray(int size) { return new BatteryUsageStatsQuery[size]; } }; /** * Builder for BatteryUsageStatsQuery. */ public static final class Builder { private int mFlags; /** * Builds a read-only BatteryUsageStatsQuery object. */ public BatteryUsageStatsQuery build() { return new BatteryUsageStatsQuery(this); } /** * Sets flags to modify the behavior of {@link BatteryStatsManager#getBatteryUsageStats}. */ public Builder setFlags(@BatteryUsageStatsFlags int flags) { mFlags = flags; return this; } /** * Requests to include modeled battery usage stats along with measured ones. * Should only be used for testing and debugging. */ public Builder includeModeled() { mFlags |= BatteryUsageStatsQuery.FLAG_BATTERY_USAGE_STATS_INCLUDE_MODELED; return this; } } }