diff options
Diffstat (limited to 'services/core')
-rw-r--r-- | services/core/java/com/android/server/AppOpsService.java | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/services/core/java/com/android/server/AppOpsService.java b/services/core/java/com/android/server/AppOpsService.java index c3465d1..42a5195 100644 --- a/services/core/java/com/android/server/AppOpsService.java +++ b/services/core/java/com/android/server/AppOpsService.java @@ -29,6 +29,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import android.app.ActivityManager; import android.app.ActivityThread; import android.app.AppOpsManager; import android.content.Context; @@ -53,7 +54,6 @@ import android.util.Log; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; -import android.util.SparseIntArray; import android.util.TimeUtils; import android.util.Xml; @@ -78,10 +78,12 @@ public class AppOpsService extends IAppOpsService.Stub { final Handler mHandler; boolean mWriteScheduled; + boolean mFastWriteScheduled; final Runnable mWriteRunner = new Runnable() { public void run() { synchronized (AppOpsService.this) { mWriteScheduled = false; + mFastWriteScheduled = false; AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { writeState(); @@ -237,7 +239,7 @@ public class AppOpsService extends IAppOpsService.Stub { } } if (changed) { - scheduleWriteLocked(); + scheduleFastWriteLocked(); } } } @@ -250,7 +252,7 @@ public class AppOpsService extends IAppOpsService.Stub { if (pkgs.size() <= 0) { mUidOps.remove(uid); } - scheduleWriteLocked(); + scheduleFastWriteLocked(); } } } @@ -260,7 +262,7 @@ public class AppOpsService extends IAppOpsService.Stub { synchronized (this) { if (mUidOps.indexOfKey(uid) >= 0) { mUidOps.remove(uid); - scheduleWriteLocked(); + scheduleFastWriteLocked(); } } } @@ -400,7 +402,7 @@ public class AppOpsService extends IAppOpsService.Stub { // if there is nothing else interesting in it. pruneOp(op, uid, packageName); } - scheduleWriteNowLocked(); + scheduleFastWriteLocked(); } } } @@ -436,16 +438,20 @@ public class AppOpsService extends IAppOpsService.Stub { } @Override - public void resetAllModes() { - int callingUid = Binder.getCallingUid(); + public void resetAllModes(int reqUserId, String reqPackageName) { + final int callingPid = Binder.getCallingPid(); + final int callingUid = Binder.getCallingUid(); mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS, - Binder.getCallingPid(), callingUid, null); + callingPid, callingUid, null); + reqUserId = ActivityManager.handleIncomingUser(callingPid, callingUid, reqUserId, + true, true, "resetAllModes", null); HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks = null; synchronized (this) { boolean changed = false; for (int i=mUidOps.size()-1; i>=0; i--) { HashMap<String, Ops> packages = mUidOps.valueAt(i); - if (UserHandle.getUserId(callingUid) != UserHandle.getUserId(mUidOps.keyAt(i))) { + if (reqUserId != UserHandle.USER_ALL + && reqUserId != UserHandle.getUserId(mUidOps.keyAt(i))) { // Skip any ops for a different user continue; } @@ -453,6 +459,10 @@ public class AppOpsService extends IAppOpsService.Stub { while (it.hasNext()) { Map.Entry<String, Ops> ent = it.next(); String packageName = ent.getKey(); + if (reqPackageName != null && !reqPackageName.equals(packageName)) { + // Skip any ops for a different package + continue; + } Ops pkgOps = ent.getValue(); for (int j=pkgOps.size()-1; j>=0; j--) { Op curOp = pkgOps.valueAt(j); @@ -478,7 +488,7 @@ public class AppOpsService extends IAppOpsService.Stub { } } if (changed) { - scheduleWriteNowLocked(); + scheduleFastWriteLocked(); } } if (callbacks != null) { @@ -837,12 +847,13 @@ public class AppOpsService extends IAppOpsService.Stub { } } - private void scheduleWriteNowLocked() { - if (!mWriteScheduled) { + private void scheduleFastWriteLocked() { + if (!mFastWriteScheduled) { mWriteScheduled = true; + mFastWriteScheduled = true; + mHandler.removeCallbacks(mWriteRunner); + mHandler.postDelayed(mWriteRunner, 10*1000); } - mHandler.removeCallbacks(mWriteRunner); - mHandler.post(mWriteRunner); } private Op getOpLocked(int code, int uid, String packageName, boolean edit) { @@ -1236,12 +1247,11 @@ public class AppOpsService extends IAppOpsService.Stub { pw.print(" ago"); } if (op.duration == -1) { - pw.println(" (running)"); - } else { - pw.print("; duration="); - TimeUtils.formatDuration(op.duration, pw); - pw.println(); + pw.print(" (running)"); + } else if (op.duration != 0) { + pw.print("; duration="); TimeUtils.formatDuration(op.duration, pw); } + pw.println(); } } } |