import android.app.AppOpsManager;
import android.app.ListFragment;
import android.app.LoaderManager;
+import android.app.AppOpsManager.OpEntry;
import android.content.AsyncTaskLoader;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Loader;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
public AppOpsCategory() {
}
- public AppOpsCategory(int[] ops) {
+ public AppOpsCategory(int[] ops, String[] perms) {
Bundle args = new Bundle();
args.putIntArray("ops", ops);
+ args.putStringArray("perms", perms);
setArguments(args);
}
final AppOpsManager mAppOps;
final PackageManager mPm;
final int[] mOps;
+ final String[] mPerms;
final HashMap<String, AppEntry> mAppEntries = new HashMap<String, AppEntry>();
List<AppOpEntry> mApps;
PackageIntentReceiver mPackageObserver;
- public AppListLoader(Context context, int[] ops) {
+ public AppListLoader(Context context, int[] ops, String[] perms) {
super(context);
mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
mPm = context.getPackageManager();
mOps = ops;
+ mPerms = perms;
}
@Override public List<AppOpEntry> loadInBackground() {
}
}
+ if (mPerms != null) {
+ List<PackageInfo> apps = mPm.getPackagesHoldingPermissions(mPerms, 0);
+ for (int i=0; i<apps.size(); i++) {
+ PackageInfo appInfo = apps.get(i);
+ AppEntry appEntry = mAppEntries.get(appInfo.packageName);
+ if (appEntry == null) {
+ appEntry = new AppEntry(this, appInfo.applicationInfo);
+ appEntry.loadLabel(context);
+ mAppEntries.put(appInfo.packageName, appEntry);
+ List<AppOpsManager.OpEntry> dummyOps = new ArrayList<AppOpsManager.OpEntry>();
+ AppOpsManager.OpEntry opEntry = new AppOpsManager.OpEntry(0, 0, 0);
+ dummyOps.add(opEntry);
+ AppOpsManager.PackageOps pkgOps = new AppOpsManager.PackageOps(
+ appInfo.packageName, appInfo.applicationInfo.uid, dummyOps);
+ AppOpEntry entry = new AppOpEntry(pkgOps, opEntry, appEntry);
+ entries.add(entry);
+ }
+ }
+ }
+
// Sort the list.
Collections.sort(entries, APP_OP_COMPARATOR);
CharSequence opTimeToString(AppOpsManager.OpEntry op) {
if (op.isRunning()) {
- return "Running";
+ return mRunningStr;
}
return DateUtils.getRelativeTimeSpanString(op.getTime(),
System.currentTimeMillis(),
((ImageView)view.findViewById(R.id.app_icon)).setImageDrawable(
item.getAppEntry().getIcon());
((TextView)view.findViewById(R.id.app_name)).setText(item.getAppEntry().getLabel());
- ((TextView)view.findViewById(R.id.op_name)).setText(
- mOpNames[item.getOpEntry().getOp()]);
- ((TextView)view.findViewById(R.id.op_time)).setText(opTimeToString(item.getOpEntry()));
+ if (item.getOpEntry().getTime() != 0) {
+ ((TextView)view.findViewById(R.id.op_name)).setText(
+ mOpNames[item.getOpEntry().getOp()]);
+ ((TextView)view.findViewById(R.id.op_time)).setText(opTimeToString(item.getOpEntry()));
+ } else {
+ ((TextView)view.findViewById(R.id.op_name)).setText("");
+ ((TextView)view.findViewById(R.id.op_time)).setText("");
+ }
return view;
}
@Override public Loader<List<AppOpEntry>> onCreateLoader(int id, Bundle args) {
Bundle fargs = getArguments();
- return new AppListLoader(getActivity(), fargs != null ? fargs.getIntArray("ops") : null);
+ int[] ops = null;
+ String[] perms = null;
+ if (fargs != null) {
+ ops = fargs.getIntArray("ops");
+ perms = fargs.getStringArray("perms");
+ }
+ return new AppListLoader(getActivity(), ops, perms);
}
@Override public void onLoadFinished(Loader<List<AppOpEntry>> loader, List<AppOpEntry> data) {
static int[][] sPageOps = new int[][] {
// "Location" page.
new int[] { AppOpsManager.OP_COARSE_LOCATION, AppOpsManager.OP_FINE_LOCATION,
- AppOpsManager.OP_GPS},
+ AppOpsManager.OP_GPS },
// "Personal" page.
new int[] { AppOpsManager.OP_READ_CONTACTS, AppOpsManager.OP_WRITE_CONTACTS,
// "Device" page.
new int[] { AppOpsManager.OP_VIBRATE },
};
+ static String[][] sPagePerms = new String[][] {
+ // "Location" page.
+ new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION,
+ android.Manifest.permission.ACCESS_FINE_LOCATION },
+
+ // "Personal" page.
+ new String[] { android.Manifest.permission.READ_CONTACTS,
+ android.Manifest.permission.WRITE_CONTACTS,
+ android.Manifest.permission.READ_CALL_LOG,
+ android.Manifest.permission.WRITE_CALL_LOG },
+
+ // "Device" page.
+ new String[] { android.Manifest.permission.VIBRATE },
+ };
int mCurPos;
@Override
public Fragment getItem(int position) {
- return new AppOpsCategory(sPageOps[position]);
+ return new AppOpsCategory(sPageOps[position], sPagePerms[position]);
}
@Override