From 1ce47bf1294764ea23509d45ab015fbe196e34b6 Mon Sep 17 00:00:00 2001 From: Alex Stetson Date: Thu, 17 Feb 2022 15:28:22 -0800 Subject: [PATCH] DO NOT MERGE Restrict PHONE_CALL ops based on TelecomService PHONE_CALL ops should be restricted here under the conditions of the TelecomService not being started (which is not having FEATURE_TELEPHONY and FEATURE_MICROPHONE). Bug: 186518774 Test: manual, atest AppOpsTest#ensurePhoneCallOpsRestricted Change-Id: I252636af68973c3b7c3ee6bbb5d50d7a8ca2c14c --- .../java/com/android/server/policy/AppOpsPolicy.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/policy/AppOpsPolicy.java b/services/core/java/com/android/server/policy/AppOpsPolicy.java index 8b4690629ec5e..e5db2e4dab35e 100644 --- a/services/core/java/com/android/server/policy/AppOpsPolicy.java +++ b/services/core/java/com/android/server/policy/AppOpsPolicy.java @@ -185,8 +185,13 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat initializeActivityRecognizersTags(); - // If this device does not have telephony, restrict the phone call ops - if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { + // If this device does not have telephony or microphone features, the TelecomService will + // not be started (which sets phone call ops to allow only its package). Therefore, phone + // call ops need to be restricted here. + PackageManager pm = mContext.getPackageManager(); + if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) + && !pm.hasSystemFeature(PackageManager.FEATURE_MICROPHONE) + && !pm.hasSystemFeature(PackageManager.FEATURE_CONNECTION_SERVICE)) { AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class); appOps.setUserRestrictionForUser(AppOpsManager.OP_PHONE_CALL_MICROPHONE, true, mToken, null, UserHandle.USER_ALL);