From 2a1f0b7418786599068ba2c77dbf70fb6f1ed0f9 Mon Sep 17 00:00:00 2001 From: Kweku Adams Date: Mon, 28 Feb 2022 20:45:38 +0000 Subject: [PATCH] Indicate min allowed bucket. Only show the buckets an app is allowed to be put in. With more and more exceptions, it'll be good to make it clear to developers who are testing what buckets they can put their app in using the developer options UI. Bug: 156509848 Test: manual Change-Id: Iebc6b706f274a4dd4be7e1c5c42a4b3b05b39777 --- .../settings/fuelgauge/InactiveApps.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/fuelgauge/InactiveApps.java b/src/com/android/settings/fuelgauge/InactiveApps.java index 36a97345f86..0d87ae73fe6 100644 --- a/src/com/android/settings/fuelgauge/InactiveApps.java +++ b/src/com/android/settings/fuelgauge/InactiveApps.java @@ -111,8 +111,8 @@ public class InactiveApps extends SettingsPreferenceFragment p.setTitle(app.loadLabel(pm)); p.setIcon(app.loadIcon(pm)); p.setKey(packageName); - p.setEntries(bucketNames); - p.setEntryValues(bucketValues); + p.setEntries(getAllowableBuckets(packageName, bucketNames)); + p.setEntryValues(getAllowableBuckets(packageName, bucketValues)); updateSummary(p); // Don't allow Settings to change its own standby bucket. if (TextUtils.equals(packageName, settingsPackage)) { @@ -124,6 +124,25 @@ public class InactiveApps extends SettingsPreferenceFragment } } + private CharSequence[] getAllowableBuckets(String packageName, CharSequence[] possibleBuckets) { + final int minBucket = mUsageStats.getAppMinStandbyBucket(packageName); + if (minBucket > STANDBY_BUCKET_RESTRICTED) { + return possibleBuckets; + } + if (minBucket < STANDBY_BUCKET_ACTIVE) { + return new CharSequence[]{}; + } + // Use FULL_SETTABLE_BUCKETS_VALUES since we're searching using the int value. The index + // should apply no matter which array we're going to copy from. + final int idx = + Arrays.binarySearch(FULL_SETTABLE_BUCKETS_VALUES, Integer.toString(minBucket)); + if (idx < 0) { + // Include everything + return possibleBuckets; + } + return Arrays.copyOfRange(possibleBuckets, 0, idx + 1); + } + static String bucketToName(int bucket) { switch (bucket) { case STANDBY_BUCKET_EXEMPTED: return "EXEMPTED";