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
This commit is contained in:
Kweku Adams
2022-02-28 20:45:38 +00:00
parent 72f84a96d8
commit 2a1f0b7418

View File

@@ -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";