Flip appops corresponding to default-granted permissions
Not that we're starting to change appops' default values
for sms/calllog permissions, default grants by DefaultPermissionGrantPolicy
must take care to also flip the appops, otherwise permission grants don't
take the desired effect.
This also fixes the `appops get` shell command to reflect both uid and
package mode, consistent with how appops are checked
Bug: 117623587
Test: - enable kill switch for sms access restriction
- adb install -g $ANDROID_BUILD_TOP/out/target/product/sailfish/data/app/CellBroadcastReceiverTests/CellBroadcastReceiverTests.apk
- launch the app and press any button
- ensure no "Appop denial" warning in logcat
----
- adb shell appops get com.android.cellbroadcastreceiver android:receive_sms
- ensure result reflects uid mode
Change-Id: I59bb0c89423d3636c310c21b7a1cbf0481c992eb
diff --git a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
index 32b2bf0..774134c 100644
--- a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
+++ b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
@@ -1205,6 +1205,21 @@
if (DEBUG) {
Log.i(TAG, "Granted " + (systemFixed ? "fixed " : "not fixed ")
+ permission + " to default handler " + pkg);
+
+ int appOp = AppOpsManager.permissionToOpCode(permission);
+ if (appOp != AppOpsManager.OP_NONE
+ && AppOpsManager.opToDefaultMode(appOp)
+ != AppOpsManager.MODE_ALLOWED) {
+ // Permission has a corresponding appop which is not allowed by default
+ // We must allow it as well, as it's usually checked alongside the
+ // permission
+ if (DEBUG) {
+ Log.i(TAG, "Granting OP_" + AppOpsManager.opToName(appOp)
+ + " to " + pkg.packageName);
+ }
+ mContext.getSystemService(AppOpsManager.class).setUidMode(
+ appOp, pkg.applicationInfo.uid, AppOpsManager.MODE_ALLOWED);
+ }
}
}