Implement development UI for background check.

Allows you to toggle off full background access for
whatever apps you want.

Change-Id: I8542ecac1449ccd65dc18af3c0ca1fc18443f89c
This commit is contained in:
Dianne Hackborn
2015-12-07 16:36:09 -08:00
parent 70b49b1b70
commit f467c0acac
11 changed files with 253 additions and 16 deletions

View File

@@ -180,6 +180,7 @@ public class AppOpsState {
false,
false,
false,
false,
false }
);
@@ -206,9 +207,14 @@ public class AppOpsState {
false }
);
public static final OpsTemplate RUN_IN_BACKGROUND_TEMPLATE = new OpsTemplate(
new int[] { AppOpsManager.OP_RUN_IN_BACKGROUND },
new boolean[] { false }
);
public static final OpsTemplate[] ALL_TEMPLATES = new OpsTemplate[] {
LOCATION_TEMPLATE, PERSONAL_TEMPLATE, MESSAGING_TEMPLATE,
MEDIA_TEMPLATE, DEVICE_TEMPLATE
MEDIA_TEMPLATE, DEVICE_TEMPLATE, RUN_IN_BACKGROUND_TEMPLATE
};
/**
@@ -306,6 +312,7 @@ public class AppOpsState {
= new ArrayList<AppOpsManager.OpEntry>();
private final AppEntry mApp;
private final int mSwitchOrder;
private int mOverriddenPrimaryMode = -1;
public AppOpEntry(AppOpsManager.PackageOps pkg, AppOpsManager.OpEntry op, AppEntry app,
int switchOrder) {
@@ -363,6 +370,14 @@ public class AppOpsState {
return mOps.get(pos);
}
public int getPrimaryOpMode() {
return mOverriddenPrimaryMode >= 0 ? mOverriddenPrimaryMode : mOps.get(0).getMode();
}
public void overridePrimaryOpMode(int mode) {
mOverriddenPrimaryMode = mode;
}
private CharSequence getCombinedText(ArrayList<AppOpsManager.OpEntry> ops,
CharSequence[] items) {
if (ops.size() == 1) {
@@ -418,9 +433,9 @@ public class AppOpsState {
}
/**
* Perform alphabetical comparison of application entry objects.
* Perform app op state comparison of application entry objects.
*/
public static final Comparator<AppOpEntry> APP_OP_COMPARATOR = new Comparator<AppOpEntry>() {
public static final Comparator<AppOpEntry> RECENCY_COMPARATOR = new Comparator<AppOpEntry>() {
private final Collator sCollator = Collator.getInstance();
@Override
public int compare(AppOpEntry object1, AppOpEntry object2) {
@@ -440,6 +455,18 @@ public class AppOpsState {
}
};
/**
* Perform alphabetical comparison of application entry objects.
*/
public static final Comparator<AppOpEntry> LABEL_COMPARATOR = new Comparator<AppOpEntry>() {
private final Collator sCollator = Collator.getInstance();
@Override
public int compare(AppOpEntry object1, AppOpEntry object2) {
return sCollator.compare(object1.getAppEntry().getLabel(),
object2.getAppEntry().getLabel());
}
};
private void addOp(List<AppOpEntry> entries, AppOpsManager.PackageOps pkgOps,
AppEntry appEntry, AppOpsManager.OpEntry opEntry, boolean allowMerge, int switchOrder) {
if (allowMerge && entries.size() > 0) {
@@ -466,8 +493,12 @@ public class AppOpsState {
entries.add(entry);
}
public AppOpsManager getAppOpsManager() {
return mAppOps;
}
public List<AppOpEntry> buildState(OpsTemplate tpl) {
return buildState(tpl, 0, null);
return buildState(tpl, 0, null, RECENCY_COMPARATOR);
}
private AppEntry getAppEntry(final Context context, final HashMap<String, AppEntry> appEntries,
@@ -492,6 +523,11 @@ public class AppOpsState {
}
public List<AppOpEntry> buildState(OpsTemplate tpl, int uid, String packageName) {
return buildState(tpl, uid, packageName, RECENCY_COMPARATOR);
}
public List<AppOpEntry> buildState(OpsTemplate tpl, int uid, String packageName,
Comparator<AppOpEntry> comparator) {
final Context context = mContext;
final HashMap<String, AppEntry> appEntries = new HashMap<String, AppEntry>();
@@ -593,7 +629,7 @@ public class AppOpsState {
}
// Sort the list.
Collections.sort(entries, APP_OP_COMPARATOR);
Collections.sort(entries, comparator);
// Done!
return entries;