Commit f02e0409 authored by Gabriele M's avatar Gabriele M

Settings: Always show Privacy Guard permissions

Enabling Privacy Guard for an app simply means switching a set of
operations to MODE_ASK, independently on whether the application
actually declared those ops (though a permission) or not. The
framework keeps track only of the ops with a non-default value. As
consequence, all the ops set by Privacy Guard that aren't declared
by the app through its manifest are effectively lost when set to
their default value and the settings won't show them.

Never hide the Privacy Guard ops to provide a consistent UI.

Change-Id: Iafcf058f5e2074982bf45f8c82ef8d027b9358f0
parent a2f914c8
......@@ -181,7 +181,7 @@ public class AppOpsDetails extends SettingsPreferenceFragment {
continue;
}
List<AppOpsState.AppOpEntry> entries = mState.buildState(tpl,
mPackageInfo.applicationInfo.uid, mPackageInfo.packageName);
mPackageInfo.applicationInfo.uid, mPackageInfo.packageName, true);
for (final AppOpsState.AppOpEntry entry : entries) {
final AppOpsManager.OpEntry firstOp = entry.getOpEntry(0);
Drawable icon = null;
......
......@@ -598,12 +598,27 @@ public class AppOpsState {
return mPreferences.getBoolean("show_system_apps", true);
}
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,
boolean showPrivacyGuardOps) {
return buildState(tpl, uid, packageName, RECENCY_COMPARATOR, showPrivacyGuardOps);
}
public List<AppOpEntry> buildState(OpsTemplate tpl, int uid, String packageName,
Comparator<AppOpEntry> comparator) {
return buildState(tpl, uid, packageName, comparator, false);
}
private boolean isPrivacyGuardOp(int op) {
for (int privacyGuardOp : AppOpsManager.PRIVACY_GUARD_OP_STATES) {
if (privacyGuardOp == op) {
return true;
}
}
return false;
}
public List<AppOpEntry> buildState(OpsTemplate tpl, int uid, String packageName,
Comparator<AppOpEntry> comparator, boolean showPrivacyGuardOps) {
final Context context = mContext;
final HashMap<String, AppEntry> appEntries = new HashMap<String, AppEntry>();
......@@ -612,8 +627,16 @@ public class AppOpsState {
final ArrayList<String> perms = new ArrayList<String>();
final ArrayList<Integer> permOps = new ArrayList<Integer>();
final int[] opToOrder = new int[AppOpsManager._NUM_OP];
final List<Integer> privacyGuardsOps = new ArrayList<>();
for (int i=0; i<tpl.ops.length; i++) {
if (tpl.showPerms[i]) {
boolean showPermission = tpl.showPerms[i];
if (showPrivacyGuardOps && isPrivacyGuardOp(tpl.ops[i])) {
showPermission = true;
privacyGuardsOps.add(tpl.ops[i]);
}
if (showPermission) {
String perm = AppOpsManager.opToPermission(tpl.ops[i]);
if (perm != null && !perms.contains(perm)) {
perms.add(perm);
......@@ -706,6 +729,23 @@ public class AppOpsState {
}
}
}
if (showPrivacyGuardOps) {
if (dummyOps == null) {
dummyOps = new ArrayList<AppOpsManager.OpEntry>();
pkgOps = new AppOpsManager.PackageOps(
appInfo.packageName, appInfo.applicationInfo.uid, dummyOps);
}
for (int op : privacyGuardsOps) {
if (appEntry.hasOp(op)) {
continue;
}
AppOpsManager.OpEntry opEntry = new AppOpsManager.OpEntry(
op, AppOpsManager.MODE_ALLOWED, 0, 0, 0, -1, null, 0, 0);
dummyOps.add(opEntry);
addOp(entries, pkgOps, appEntry, opEntry, false, opToOrder[op]);
}
}
}
// Sort the list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment