Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a1f0b74 authored by Kweku Adams's avatar Kweku Adams
Browse files

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
parent 72f84a96
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -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";