diff options
Diffstat (limited to 'src/com/android/settings/applications/AppOpsState.java')
-rw-r--r-- | src/com/android/settings/applications/AppOpsState.java | 117 |
1 files changed, 89 insertions, 28 deletions
diff --git a/src/com/android/settings/applications/AppOpsState.java b/src/com/android/settings/applications/AppOpsState.java index ae58ddd..e46d94a 100644 --- a/src/com/android/settings/applications/AppOpsState.java +++ b/src/com/android/settings/applications/AppOpsState.java @@ -16,6 +16,7 @@ package com.android.settings.applications; +import android.app.Activity; import android.app.AppOpsManager; import android.content.Context; import android.content.pm.ApplicationInfo; @@ -23,6 +24,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; +import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Parcel; import android.os.Parcelable; @@ -52,12 +54,15 @@ public class AppOpsState { List<AppOpEntry> mApps; + private SharedPreferences mPreferences; + public AppOpsState(Context context) { mContext = context; mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); mPm = context.getPackageManager(); mOpSummaries = context.getResources().getTextArray(R.array.app_ops_summaries_cm); mOpLabels = context.getResources().getTextArray(R.array.app_ops_labels_cm); + mPreferences = context.getSharedPreferences("appops_manager", Activity.MODE_PRIVATE); } public static class OpsTemplate implements Parcelable { @@ -383,30 +388,59 @@ public class AppOpsState { } private CharSequence getCombinedText(ArrayList<AppOpsManager.OpEntry> ops, - CharSequence[] items) { - if (ops.size() == 1) { - return items[ops.get(0).getOp()]; - } else { - StringBuilder builder = new StringBuilder(); - for (int i=0; i<ops.size(); i++) { - if (i > 0) { - builder.append(", "); - } - builder.append(items[ops.get(i).getOp()]); + CharSequence[] items, Resources res, boolean withTerseCounts) { + StringBuilder builder = new StringBuilder(); + for (int i=0; i<ops.size(); i++) { + if (i > 0) { + builder.append(", "); } - return builder.toString(); + AppOpsManager.OpEntry op = ops.get(i); + int count = op.getAllowedCount() + op.getIgnoredCount(); + + if (withTerseCounts && count > 0) { + String quantity = res.getQuantityString(R.plurals.app_ops_count, + count, count); + builder.append(res.getString(R.string.app_ops_entry_summary, + items[op.getOp()], quantity)); + } else { + builder.append(items[op.getOp()]); + } + } + return builder.toString(); + } + + public CharSequence getCountsText(Resources res) { + AppOpsManager.OpEntry op = mOps.get(0); + int allowed = op.getAllowedCount(); + int denied = op.getIgnoredCount(); + + if (allowed == 0 && denied == 0) { + return null; } + + CharSequence allowedQuantity = res.getQuantityString(R.plurals.app_ops_count, + allowed, allowed); + CharSequence deniedQuantity = res.getQuantityString(R.plurals.app_ops_count, + denied, denied); + + if (denied == 0) { + return res.getString(R.string.app_ops_allowed_count, allowedQuantity); + } else if (allowed == 0) { + return res.getString(R.string.app_ops_ignored_count, deniedQuantity); + } + return res.getString(R.string.app_ops_both_count, allowedQuantity, deniedQuantity); } public CharSequence getSummaryText(AppOpsState state) { - return getCombinedText(mOps, state.mOpSummaries); + return getCombinedText(mOps, state.mOpSummaries, state.mContext.getResources(), true); } public CharSequence getSwitchText(AppOpsState state) { + final Resources res = state.mContext.getResources(); if (mSwitchOps.size() > 0) { - return getCombinedText(mSwitchOps, state.mOpLabels); + return getCombinedText(mSwitchOps, state.mOpLabels, res, false); } else { - return getCombinedText(mOps, state.mOpLabels); + return getCombinedText(mOps, state.mOpLabels, res, false); } } @@ -490,19 +524,34 @@ public class AppOpsState { } private AppEntry getAppEntry(final Context context, final HashMap<String, AppEntry> appEntries, - final String packageName, ApplicationInfo appInfo) { + final String packageName, ApplicationInfo appInfo, boolean applyFilters) { + + if (appInfo == null) { + try { + appInfo = mPm.getApplicationInfo(packageName, + PackageManager.GET_DISABLED_COMPONENTS + | PackageManager.GET_UNINSTALLED_PACKAGES); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, "Unable to find info for package " + packageName); + return null; + } + } + + if (applyFilters) { + // Hide user apps if needed + if (!shouldShowUserApps() && + (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { + return null; + } + // Hide system apps if needed + if (!shouldShowSystemApps() && + (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { + return null; + } + } + AppEntry appEntry = appEntries.get(packageName); if (appEntry == null) { - if (appInfo == null) { - try { - appInfo = mPm.getApplicationInfo(packageName, - PackageManager.GET_DISABLED_COMPONENTS - | PackageManager.GET_UNINSTALLED_PACKAGES); - } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, "Unable to find info for package " + packageName); - return null; - } - } appEntry = new AppEntry(this, appInfo); appEntry.loadLabel(context); appEntries.put(packageName, appEntry); @@ -510,6 +559,14 @@ public class AppOpsState { return appEntry; } + private boolean shouldShowUserApps() { + return mPreferences.getBoolean("show_user_apps", true); + } + + private boolean shouldShowSystemApps() { + return mPreferences.getBoolean("show_system_apps", true); + } + public List<AppOpEntry> buildState(OpsTemplate tpl, int uid, String packageName) { final Context context = mContext; @@ -530,6 +587,9 @@ public class AppOpsState { } } + // Whether to apply hide user / system app filters + final boolean applyFilters = (packageName == null); + List<AppOpsManager.PackageOps> pkgs; if (packageName != null) { pkgs = mAppOps.getOpsForPackage(uid, packageName, tpl.ops); @@ -540,7 +600,8 @@ public class AppOpsState { if (pkgs != null) { for (int i=0; i<pkgs.size(); i++) { AppOpsManager.PackageOps pkgOps = pkgs.get(i); - AppEntry appEntry = getAppEntry(context, appEntries, pkgOps.getPackageName(), null); + AppEntry appEntry = getAppEntry(context, appEntries, pkgOps.getPackageName(), null, + applyFilters); if (appEntry == null) { continue; } @@ -568,7 +629,7 @@ public class AppOpsState { for (int i=0; i<apps.size(); i++) { PackageInfo appInfo = apps.get(i); AppEntry appEntry = getAppEntry(context, appEntries, appInfo.packageName, - appInfo.applicationInfo); + appInfo.applicationInfo, applyFilters); if (appEntry == null) { continue; } @@ -602,7 +663,7 @@ public class AppOpsState { } AppOpsManager.OpEntry opEntry = new AppOpsManager.OpEntry( - permOps.get(k), AppOpsManager.MODE_ALLOWED, 0, 0, 0, -1, null); + permOps.get(k), AppOpsManager.MODE_ALLOWED, 0, 0, 0, -1, null, 0, 0); dummyOps.add(opEntry); addOp(entries, pkgOps, appEntry, opEntry, packageName == null, packageName == null ? 0 : opToOrder[opEntry.getOp()]); |