Loading core/java/android/os/AggregateBatteryConsumer.java +3 −2 Original line number Diff line number Diff line Loading @@ -116,8 +116,9 @@ public final class AggregateBatteryConsumer extends BatteryConsumer { * Builder for DeviceBatteryConsumer. */ public static final class Builder extends BaseBuilder<AggregateBatteryConsumer.Builder> { public Builder(BatteryConsumer.BatteryConsumerData data, int scope) { super(data, CONSUMER_TYPE_AGGREGATE); public Builder(BatteryConsumer.BatteryConsumerData data, int scope, double minConsumedPowerThreshold) { super(data, CONSUMER_TYPE_AGGREGATE, minConsumedPowerThreshold); data.putInt(COLUMN_INDEX_SCOPE, scope); } Loading core/java/android/os/BatteryConsumer.java +3 −2 Original line number Diff line number Diff line Loading @@ -795,11 +795,12 @@ public abstract class BatteryConsumer { protected final BatteryConsumer.BatteryConsumerData mData; protected final PowerComponents.Builder mPowerComponentsBuilder; public BaseBuilder(BatteryConsumer.BatteryConsumerData data, int consumerType) { public BaseBuilder(BatteryConsumer.BatteryConsumerData data, int consumerType, double minConsumedPowerThreshold) { mData = data; data.putLong(COLUMN_INDEX_BATTERY_CONSUMER_TYPE, consumerType); mPowerComponentsBuilder = new PowerComponents.Builder(data); mPowerComponentsBuilder = new PowerComponents.Builder(data, minConsumedPowerThreshold); } @Nullable Loading core/java/android/os/BatteryUsageStats.java +11 −7 Original line number Diff line number Diff line Loading @@ -707,7 +707,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { XML_ATTR_PREFIX_INCLUDES_PROC_STATE_DATA, false); builder = new Builder(customComponentNames.toArray(new String[0]), true, includesProcStateData); includesProcStateData, 0); builder.setStatsStartTimestamp( parser.getAttributeLong(null, XML_ATTR_START_TIMESTAMP)); Loading Loading @@ -782,6 +782,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { private final String[] mCustomPowerComponentNames; private final boolean mIncludePowerModels; private final boolean mIncludesProcessStateData; private final double mMinConsumedPowerThreshold; private final BatteryConsumer.BatteryConsumerDataLayout mBatteryConsumerDataLayout; private long mStatsStartTimestampMs; private long mStatsEndTimestampMs; Loading @@ -802,11 +803,11 @@ public final class BatteryUsageStats implements Parcelable, Closeable { private BatteryStatsHistory mBatteryStatsHistory; public Builder(@NonNull String[] customPowerComponentNames) { this(customPowerComponentNames, false, false); this(customPowerComponentNames, false, false, 0); } public Builder(@NonNull String[] customPowerComponentNames, boolean includePowerModels, boolean includeProcessStateData) { boolean includeProcessStateData, double minConsumedPowerThreshold) { mBatteryConsumersCursorWindow = new CursorWindow(null, BATTERY_CONSUMER_CURSOR_WINDOW_SIZE); mBatteryConsumerDataLayout = Loading @@ -817,12 +818,14 @@ public final class BatteryUsageStats implements Parcelable, Closeable { mCustomPowerComponentNames = customPowerComponentNames; mIncludePowerModels = includePowerModels; mIncludesProcessStateData = includeProcessStateData; mMinConsumedPowerThreshold = minConsumedPowerThreshold; for (int scope = 0; scope < AGGREGATE_BATTERY_CONSUMER_SCOPE_COUNT; scope++) { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); mAggregateBatteryConsumersBuilders[scope] = new AggregateBatteryConsumer.Builder(data, scope); new AggregateBatteryConsumer.Builder( data, scope, mMinConsumedPowerThreshold); } } Loading Loading @@ -961,7 +964,8 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UidBatteryConsumer.Builder(data, batteryStatsUid); builder = new UidBatteryConsumer.Builder(data, batteryStatsUid, mMinConsumedPowerThreshold); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -979,7 +983,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UidBatteryConsumer.Builder(data, uid); builder = new UidBatteryConsumer.Builder(data, uid, mMinConsumedPowerThreshold); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -996,7 +1000,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UserBatteryConsumer.Builder(data, userId); builder = new UserBatteryConsumer.Builder(data, userId, mMinConsumedPowerThreshold); mUserBatteryConsumerBuilders.put(userId, builder); } return builder; Loading core/java/android/os/BatteryUsageStatsQuery.java +22 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { private final long mMaxStatsAgeMs; private final long mFromTimestamp; private final long mToTimestamp; private final double mMinConsumedPowerThreshold; private final @BatteryConsumer.PowerComponent int[] mPowerComponents; private BatteryUsageStatsQuery(@NonNull Builder builder) { Loading @@ -87,6 +88,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { mUserIds = builder.mUserIds != null ? builder.mUserIds.toArray() : new int[]{UserHandle.USER_ALL}; mMaxStatsAgeMs = builder.mMaxStatsAgeMs; mMinConsumedPowerThreshold = builder.mMinConsumedPowerThreshold; mFromTimestamp = builder.mFromTimestamp; mToTimestamp = builder.mToTimestamp; mPowerComponents = builder.mPowerComponents; Loading Loading @@ -136,6 +138,14 @@ public final class BatteryUsageStatsQuery implements Parcelable { return mMaxStatsAgeMs; } /** * Returns the minimal power component consumed power threshold. The small power consuming * components will be reported as zero. */ public double getMinConsumedPowerThreshold() { return mMinConsumedPowerThreshold; } /** * Returns the exclusive lower bound of the stored snapshot timestamps that should be included * in the aggregation. Ignored if {@link #getToTimestamp()} is zero. Loading @@ -158,6 +168,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { mUserIds = new int[in.readInt()]; in.readIntArray(mUserIds); mMaxStatsAgeMs = in.readLong(); mMinConsumedPowerThreshold = in.readDouble(); mFromTimestamp = in.readLong(); mToTimestamp = in.readLong(); mPowerComponents = in.createIntArray(); Loading @@ -169,6 +180,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { dest.writeInt(mUserIds.length); dest.writeIntArray(mUserIds); dest.writeLong(mMaxStatsAgeMs); dest.writeDouble(mMinConsumedPowerThreshold); dest.writeLong(mFromTimestamp); dest.writeLong(mToTimestamp); dest.writeIntArray(mPowerComponents); Loading Loading @@ -202,6 +214,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { private long mMaxStatsAgeMs = DEFAULT_MAX_STATS_AGE_MS; private long mFromTimestamp; private long mToTimestamp; private double mMinConsumedPowerThreshold = 0; private @BatteryConsumer.PowerComponent int[] mPowerComponents; /** Loading Loading @@ -301,5 +314,14 @@ public final class BatteryUsageStatsQuery implements Parcelable { mMaxStatsAgeMs = maxStatsAgeMs; return this; } /** * Set the minimal power component consumed power threshold. The small power consuming * components will be reported as zero. */ public Builder setMinConsumedPowerThreshold(double minConsumedPowerThreshold) { mMinConsumedPowerThreshold = minConsumedPowerThreshold; return this; } } } core/java/android/os/PowerComponents.java +9 −1 Original line number Diff line number Diff line Loading @@ -461,9 +461,11 @@ class PowerComponents { private static final byte POWER_MODEL_UNINITIALIZED = -1; private final BatteryConsumer.BatteryConsumerData mData; private final double mMinConsumedPowerThreshold; Builder(BatteryConsumer.BatteryConsumerData data) { Builder(BatteryConsumer.BatteryConsumerData data, double minConsumedPowerThreshold) { mData = data; mMinConsumedPowerThreshold = minConsumedPowerThreshold; for (BatteryConsumer.Key[] keys : mData.layout.keys) { for (BatteryConsumer.Key key : keys) { if (key.mPowerModelColumnIndex != -1) { Loading @@ -476,6 +478,9 @@ class PowerComponents { @NonNull public Builder setConsumedPower(BatteryConsumer.Key key, double componentPower, int powerModel) { if (Math.abs(componentPower) < mMinConsumedPowerThreshold) { componentPower = 0; } mData.putDouble(key.mPowerColumnIndex, componentPower); if (key.mPowerModelColumnIndex != -1) { mData.putInt(key.mPowerModelColumnIndex, powerModel); Loading @@ -491,6 +496,9 @@ class PowerComponents { */ @NonNull public Builder setConsumedPowerForCustomComponent(int componentId, double componentPower) { if (Math.abs(componentPower) < mMinConsumedPowerThreshold) { componentPower = 0; } final int index = componentId - BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID; if (index < 0 || index >= mData.layout.customPowerComponentCount) { throw new IllegalArgumentException( Loading Loading
core/java/android/os/AggregateBatteryConsumer.java +3 −2 Original line number Diff line number Diff line Loading @@ -116,8 +116,9 @@ public final class AggregateBatteryConsumer extends BatteryConsumer { * Builder for DeviceBatteryConsumer. */ public static final class Builder extends BaseBuilder<AggregateBatteryConsumer.Builder> { public Builder(BatteryConsumer.BatteryConsumerData data, int scope) { super(data, CONSUMER_TYPE_AGGREGATE); public Builder(BatteryConsumer.BatteryConsumerData data, int scope, double minConsumedPowerThreshold) { super(data, CONSUMER_TYPE_AGGREGATE, minConsumedPowerThreshold); data.putInt(COLUMN_INDEX_SCOPE, scope); } Loading
core/java/android/os/BatteryConsumer.java +3 −2 Original line number Diff line number Diff line Loading @@ -795,11 +795,12 @@ public abstract class BatteryConsumer { protected final BatteryConsumer.BatteryConsumerData mData; protected final PowerComponents.Builder mPowerComponentsBuilder; public BaseBuilder(BatteryConsumer.BatteryConsumerData data, int consumerType) { public BaseBuilder(BatteryConsumer.BatteryConsumerData data, int consumerType, double minConsumedPowerThreshold) { mData = data; data.putLong(COLUMN_INDEX_BATTERY_CONSUMER_TYPE, consumerType); mPowerComponentsBuilder = new PowerComponents.Builder(data); mPowerComponentsBuilder = new PowerComponents.Builder(data, minConsumedPowerThreshold); } @Nullable Loading
core/java/android/os/BatteryUsageStats.java +11 −7 Original line number Diff line number Diff line Loading @@ -707,7 +707,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { XML_ATTR_PREFIX_INCLUDES_PROC_STATE_DATA, false); builder = new Builder(customComponentNames.toArray(new String[0]), true, includesProcStateData); includesProcStateData, 0); builder.setStatsStartTimestamp( parser.getAttributeLong(null, XML_ATTR_START_TIMESTAMP)); Loading Loading @@ -782,6 +782,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { private final String[] mCustomPowerComponentNames; private final boolean mIncludePowerModels; private final boolean mIncludesProcessStateData; private final double mMinConsumedPowerThreshold; private final BatteryConsumer.BatteryConsumerDataLayout mBatteryConsumerDataLayout; private long mStatsStartTimestampMs; private long mStatsEndTimestampMs; Loading @@ -802,11 +803,11 @@ public final class BatteryUsageStats implements Parcelable, Closeable { private BatteryStatsHistory mBatteryStatsHistory; public Builder(@NonNull String[] customPowerComponentNames) { this(customPowerComponentNames, false, false); this(customPowerComponentNames, false, false, 0); } public Builder(@NonNull String[] customPowerComponentNames, boolean includePowerModels, boolean includeProcessStateData) { boolean includeProcessStateData, double minConsumedPowerThreshold) { mBatteryConsumersCursorWindow = new CursorWindow(null, BATTERY_CONSUMER_CURSOR_WINDOW_SIZE); mBatteryConsumerDataLayout = Loading @@ -817,12 +818,14 @@ public final class BatteryUsageStats implements Parcelable, Closeable { mCustomPowerComponentNames = customPowerComponentNames; mIncludePowerModels = includePowerModels; mIncludesProcessStateData = includeProcessStateData; mMinConsumedPowerThreshold = minConsumedPowerThreshold; for (int scope = 0; scope < AGGREGATE_BATTERY_CONSUMER_SCOPE_COUNT; scope++) { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); mAggregateBatteryConsumersBuilders[scope] = new AggregateBatteryConsumer.Builder(data, scope); new AggregateBatteryConsumer.Builder( data, scope, mMinConsumedPowerThreshold); } } Loading Loading @@ -961,7 +964,8 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UidBatteryConsumer.Builder(data, batteryStatsUid); builder = new UidBatteryConsumer.Builder(data, batteryStatsUid, mMinConsumedPowerThreshold); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -979,7 +983,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UidBatteryConsumer.Builder(data, uid); builder = new UidBatteryConsumer.Builder(data, uid, mMinConsumedPowerThreshold); mUidBatteryConsumerBuilders.put(uid, builder); } return builder; Loading @@ -996,7 +1000,7 @@ public final class BatteryUsageStats implements Parcelable, Closeable { final BatteryConsumer.BatteryConsumerData data = BatteryConsumer.BatteryConsumerData.create(mBatteryConsumersCursorWindow, mBatteryConsumerDataLayout); builder = new UserBatteryConsumer.Builder(data, userId); builder = new UserBatteryConsumer.Builder(data, userId, mMinConsumedPowerThreshold); mUserBatteryConsumerBuilders.put(userId, builder); } return builder; Loading
core/java/android/os/BatteryUsageStatsQuery.java +22 −0 Original line number Diff line number Diff line Loading @@ -80,6 +80,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { private final long mMaxStatsAgeMs; private final long mFromTimestamp; private final long mToTimestamp; private final double mMinConsumedPowerThreshold; private final @BatteryConsumer.PowerComponent int[] mPowerComponents; private BatteryUsageStatsQuery(@NonNull Builder builder) { Loading @@ -87,6 +88,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { mUserIds = builder.mUserIds != null ? builder.mUserIds.toArray() : new int[]{UserHandle.USER_ALL}; mMaxStatsAgeMs = builder.mMaxStatsAgeMs; mMinConsumedPowerThreshold = builder.mMinConsumedPowerThreshold; mFromTimestamp = builder.mFromTimestamp; mToTimestamp = builder.mToTimestamp; mPowerComponents = builder.mPowerComponents; Loading Loading @@ -136,6 +138,14 @@ public final class BatteryUsageStatsQuery implements Parcelable { return mMaxStatsAgeMs; } /** * Returns the minimal power component consumed power threshold. The small power consuming * components will be reported as zero. */ public double getMinConsumedPowerThreshold() { return mMinConsumedPowerThreshold; } /** * Returns the exclusive lower bound of the stored snapshot timestamps that should be included * in the aggregation. Ignored if {@link #getToTimestamp()} is zero. Loading @@ -158,6 +168,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { mUserIds = new int[in.readInt()]; in.readIntArray(mUserIds); mMaxStatsAgeMs = in.readLong(); mMinConsumedPowerThreshold = in.readDouble(); mFromTimestamp = in.readLong(); mToTimestamp = in.readLong(); mPowerComponents = in.createIntArray(); Loading @@ -169,6 +180,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { dest.writeInt(mUserIds.length); dest.writeIntArray(mUserIds); dest.writeLong(mMaxStatsAgeMs); dest.writeDouble(mMinConsumedPowerThreshold); dest.writeLong(mFromTimestamp); dest.writeLong(mToTimestamp); dest.writeIntArray(mPowerComponents); Loading Loading @@ -202,6 +214,7 @@ public final class BatteryUsageStatsQuery implements Parcelable { private long mMaxStatsAgeMs = DEFAULT_MAX_STATS_AGE_MS; private long mFromTimestamp; private long mToTimestamp; private double mMinConsumedPowerThreshold = 0; private @BatteryConsumer.PowerComponent int[] mPowerComponents; /** Loading Loading @@ -301,5 +314,14 @@ public final class BatteryUsageStatsQuery implements Parcelable { mMaxStatsAgeMs = maxStatsAgeMs; return this; } /** * Set the minimal power component consumed power threshold. The small power consuming * components will be reported as zero. */ public Builder setMinConsumedPowerThreshold(double minConsumedPowerThreshold) { mMinConsumedPowerThreshold = minConsumedPowerThreshold; return this; } } }
core/java/android/os/PowerComponents.java +9 −1 Original line number Diff line number Diff line Loading @@ -461,9 +461,11 @@ class PowerComponents { private static final byte POWER_MODEL_UNINITIALIZED = -1; private final BatteryConsumer.BatteryConsumerData mData; private final double mMinConsumedPowerThreshold; Builder(BatteryConsumer.BatteryConsumerData data) { Builder(BatteryConsumer.BatteryConsumerData data, double minConsumedPowerThreshold) { mData = data; mMinConsumedPowerThreshold = minConsumedPowerThreshold; for (BatteryConsumer.Key[] keys : mData.layout.keys) { for (BatteryConsumer.Key key : keys) { if (key.mPowerModelColumnIndex != -1) { Loading @@ -476,6 +478,9 @@ class PowerComponents { @NonNull public Builder setConsumedPower(BatteryConsumer.Key key, double componentPower, int powerModel) { if (Math.abs(componentPower) < mMinConsumedPowerThreshold) { componentPower = 0; } mData.putDouble(key.mPowerColumnIndex, componentPower); if (key.mPowerModelColumnIndex != -1) { mData.putInt(key.mPowerModelColumnIndex, powerModel); Loading @@ -491,6 +496,9 @@ class PowerComponents { */ @NonNull public Builder setConsumedPowerForCustomComponent(int componentId, double componentPower) { if (Math.abs(componentPower) < mMinConsumedPowerThreshold) { componentPower = 0; } final int index = componentId - BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID; if (index < 0 || index >= mData.layout.customPowerComponentCount) { throw new IllegalArgumentException( Loading