From 55aedb8afdea7f7466ff9ae807eb9a7677e4e05e Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Wed, 14 Apr 2021 17:43:45 -0700 Subject: [PATCH] Use new bcast permission filter in telephonyregistry Use the new sendBroadcastMultiplePermissions method to send some legacy broadcasts exactly once to any apps holding either READ_PHONE or READ_PRIV. Bug: 183537857 Test: manual regression testing Change-Id: I9947155368ee2bb76d72321a42a8477a61babbbc --- .../java/com/android/server/TelephonyRegistry.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 611fe7ad8c788..046d297dfef15 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -2860,7 +2860,14 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId); intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, phoneId); intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, phoneId); + // Send the broadcast twice -- once for all apps with READ_PHONE_STATE, then again + // for all apps with READ_PRIV but not READ_PHONE_STATE. This ensures that any app holding + // either READ_PRIV or READ_PHONE get this broadcast exactly once. mContext.sendBroadcastAsUser(intent, UserHandle.ALL, Manifest.permission.READ_PHONE_STATE); + mContext.createContextAsUser(UserHandle.ALL, 0) + .sendBroadcastMultiplePermissions(intent, + new String[] { Manifest.permission.READ_PRIVILEGED_PHONE_STATE }, + new String[] { Manifest.permission.READ_PHONE_STATE }); } private void broadcastSignalStrengthChanged(SignalStrength signalStrength, int phoneId, @@ -2987,7 +2994,14 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { getApnTypesStringFromBitmask(pdcs.getApnSetting().getApnTypeBitmask())); intent.putExtra(PHONE_CONSTANTS_SLOT_KEY, slotIndex); intent.putExtra(PHONE_CONSTANTS_SUBSCRIPTION_KEY, subId); + // Send the broadcast twice -- once for all apps with READ_PHONE_STATE, then again + // for all apps with READ_PRIV but not READ_PHONE_STATE. This ensures that any app holding + // either READ_PRIV or READ_PHONE get this broadcast exactly once. mContext.sendBroadcastAsUser(intent, UserHandle.ALL, Manifest.permission.READ_PHONE_STATE); + mContext.createContextAsUser(UserHandle.ALL, 0) + .sendBroadcastMultiplePermissions(intent, + new String[] { Manifest.permission.READ_PRIVILEGED_PHONE_STATE }, + new String[] { Manifest.permission.READ_PHONE_STATE }); } /**