Reset per-pkg app-ops for runtime permissions
... on every boot.
These should never have been set, but we allow settings them via the
shell.
- Also previously a bug set per-pkg app-ops.
- Also set the app-op correctly when a fg/bg permission looses it's bg
permission.
Test: Set per-pkg app-opp. Rebooted and saw log message.
atest --test-mapping frameworks/base/services/core/java/com/android/server/pm/permission/:presubmit
Change-Id: If3b56fc08783ea99b4dba70c5fa275b94411ce94
Fixes: 123177944
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 7ede6dc..26d2d17 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -16,8 +16,8 @@
package com.android.server.appop;
-import static android.app.AppOpsManager.OP_PLAY_AUDIO;
import static android.app.AppOpsManager.OP_NONE;
+import static android.app.AppOpsManager.OP_PLAY_AUDIO;
import static android.app.AppOpsManager.UID_STATE_BACKGROUND;
import static android.app.AppOpsManager.UID_STATE_CACHED;
import static android.app.AppOpsManager.UID_STATE_FOREGROUND;
@@ -94,9 +94,9 @@
import com.android.internal.util.Preconditions;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.function.pooled.PooledLambda;
-
import com.android.server.LocalServices;
import com.android.server.LockGuard;
+
import libcore.util.EmptyArray;
import org.xmlpull.v1.XmlPullParser;
@@ -1282,6 +1282,46 @@
}
}
+ /**
+ * Set all {@link #setMode (package) modes} for this uid to the default value.
+ *
+ * @param code The app-op
+ * @param uid The uid
+ */
+ private void setAllPkgModesToDefault(int code, int uid) {
+ synchronized (this) {
+ UidState uidState = getUidStateLocked(uid, false);
+ if (uidState == null) {
+ return;
+ }
+
+ ArrayMap<String, Ops> pkgOps = uidState.pkgOps;
+ if (pkgOps == null) {
+ return;
+ }
+
+ int numPkgs = pkgOps.size();
+ for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) {
+ Ops ops = pkgOps.valueAt(pkgNum);
+
+ Op op = ops.get(code);
+ if (op == null) {
+ continue;
+ }
+
+ int defaultMode = AppOpsManager.opToDefaultMode(code);
+ if (op.mode != defaultMode) {
+ Slog.w(TAG, "resetting app-op mode for " + AppOpsManager.opToName(code) + " of "
+ + pkgOps.keyAt(pkgNum));
+
+ op.mode = defaultMode;
+
+ scheduleWriteLocked();
+ }
+ }
+ }
+ }
+
@Override
public void setMode(int code, int uid, String packageName, int mode) {
setMode(code, uid, packageName, mode, true, false);
@@ -4387,5 +4427,10 @@
public void setUidMode(int code, int uid, int mode) {
AppOpsService.this.setUidMode(code, uid, mode);
}
+
+ @Override
+ public void setAllPkgModesToDefault(int code, int uid) {
+ AppOpsService.this.setAllPkgModesToDefault(code, uid);
+ }
}
}