Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 543565f1 authored by Sam Mortimer's avatar Sam Mortimer Committed by Gerrit Code Review
Browse files

AppOps: Fix resetAllModes() in AppOpsService

  *) Array iteration with inline deletion was broken
     causing PrivacyGuard reset not to work properly.

  *) Kanged fixed code from Kitkat

Change-Id: If36d38f9199e6282fe52eabc32cd652d8aca86fe
parent 6f0c8b9d
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -440,12 +440,14 @@ public class AppOpsService extends IAppOpsService.Stub {
        HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks = null;
        synchronized (this) {
            boolean changed = false;
            for (int i=0; i<mUidOps.size(); i++) {
            for (int i=mUidOps.size()-1; i>=0; i--) {
                HashMap<String, Ops> packages = mUidOps.valueAt(i);
                for (Map.Entry<String, Ops> ent : packages.entrySet()) {
                Iterator<Map.Entry<String, Ops>> it = packages.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<String, Ops> ent = it.next();
                    String packageName = ent.getKey();
                    Ops pkgOps = ent.getValue();
                    for (int j=0; j<pkgOps.size(); j++) {
                    for (int j=pkgOps.size()-1; j>=0; j--) {
                        Op curOp = pkgOps.valueAt(j);
                        if (curOp.mode != curOp.defaultMode) {
                            curOp.mode = curOp.defaultMode;
@@ -454,9 +456,17 @@ public class AppOpsService extends IAppOpsService.Stub {
                                    mOpModeWatchers.get(curOp.op));
                            callbacks = addCallbacks(callbacks, packageName, curOp.op,
                                    mPackageModeWatchers.get(packageName));
                            pruneOp(curOp, mUidOps.keyAt(i), packageName);
                            if (curOp.time == 0 && curOp.rejectTime == 0) {
                                pkgOps.removeAt(j);
                            }
                        }
                    }
                    if (pkgOps.size() == 0) {
                        it.remove();
                    }
                }
                if (packages.size() == 0) {
                    mUidOps.removeAt(i);
                }
            }
            if (changed) {