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

Commit 172b29e8 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by The Android Automerger
Browse files

Fix issue #10226007: Reset apps restores most of the changed settings...

...to original but not all modified ones

Very stupid mistakes in messing up the iteration when pruning op
entries.

Change-Id: Ie536b9095f797fcd2b86c9a386a72746796430d1
parent 6037ec56
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -380,12 +380,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 != AppOpsManager.MODE_ALLOWED) {
                            curOp.mode = AppOpsManager.MODE_ALLOWED;
@@ -394,9 +396,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) {