diff options
| author | 2020-01-20 16:55:36 -0800 | |
|---|---|---|
| committer | 2020-01-22 14:12:41 -0800 | |
| commit | feed16dda7fc81f4b33efce12c7f83df26c3241a (patch) | |
| tree | 976bc7d7926803f50ef75388e17494a6b82ec787 | |
| parent | ad1c710e827ac392887c7b6e011832f76c9ff549 (diff) | |
Clear up permission READ_PRIVILEGED_PHONE_STATE.
- Group all events that need the permisson together
- Enforce the permission of the group mask instead of multiple individuals
- Clear up javadoc of APIs require the permission
Bug: 148021947
Test: make offline-sdk-docs
Test: atest com.android.internal.telephony.TelephonyRegistryTest
Test: atest android.telephony.cts.PhoneStateListenerTest
Test: atest com.android.internal.telephony.PhoneStateListenerTest
Change-Id: I6c801039e3eaf22bae052de6569cf1d9a5b28396
| -rwxr-xr-x | api/system-current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/telephony/PhoneStateListener.java | 13 | ||||
| -rw-r--r-- | services/core/java/com/android/server/TelephonyRegistry.java | 28 |
3 files changed, 20 insertions, 25 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index a9f977ecbbb4..c8f22f36cb9b 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -11465,9 +11465,9 @@ package android.telephony { field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_CALL = 268435456; // 0x10000000 field @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) public static final int LISTEN_OUTGOING_EMERGENCY_SMS = 536870912; // 0x20000000 field @RequiresPermission("android.permission.READ_PRECISE_PHONE_STATE") public static final int LISTEN_PRECISE_CALL_STATE = 2048; // 0x800 - field public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 8388608; // 0x800000 + field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 8388608; // 0x800000 field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_SRVCC_STATE_CHANGED = 16384; // 0x4000 - field public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000 + field @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_VOICE_ACTIVATION_STATE = 131072; // 0x20000 } public final class PinResult implements android.os.Parcelable { diff --git a/core/java/android/telephony/PhoneStateListener.java b/core/java/android/telephony/PhoneStateListener.java index 67cac0eb3b21..023f0005eac7 100644 --- a/core/java/android/telephony/PhoneStateListener.java +++ b/core/java/android/telephony/PhoneStateListener.java @@ -225,6 +225,9 @@ public class PhoneStateListener { /** * Listen for changes to the SRVCC state of the active call. + * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see #onServiceStateChanged(ServiceState) * @hide */ @@ -253,6 +256,9 @@ public class PhoneStateListener { /** * Listen for changes to the sim voice activation state + * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATING * @see TelephonyManager#SIM_ACTIVATION_STATE_ACTIVATED * @see TelephonyManager#SIM_ACTIVATION_STATE_DEACTIVATED @@ -266,6 +272,7 @@ public class PhoneStateListener { * @hide */ @SystemApi + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_VOICE_ACTIVATION_STATE = 0x00020000; /** @@ -312,10 +319,13 @@ public class PhoneStateListener { /** * Listen for changes to the radio power state. * + * <p>Requires permission {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} + * * @see #onRadioPowerStateChanged * @hide */ @SystemApi + @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public static final int LISTEN_RADIO_POWER_STATE_CHANGED = 0x00800000; /** @@ -904,7 +914,6 @@ public class PhoneStateListener { * Callback invoked when phone capability changes. * Note, this callback triggers regardless of registered subscription. * - * Requires the READ_PRIVILEGED_PHONE_STATE permission. * @param capability the new phone capability * @hide */ @@ -934,7 +943,7 @@ public class PhoneStateListener { * subId. Otherwise, this callback applies to * {@link SubscriptionManager#getDefaultSubscriptionId()}. * - * Requires the READ_PRIVILEGED_PHONE_STATE permission. + * Requires the READ_PRECISE_PHONE_STATE permission. * @param callAttributes the call attributes * @hide */ diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 68574f5fbc2c..36dd017d2c23 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -298,6 +298,12 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL | PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS; + static final int READ_PRIVILEGED_PHONE_STATE_PERMISSION_MASK = + PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT + | PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED + | PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED + | PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE; + private static final int MSG_USER_SWITCHED = 1; private static final int MSG_UPDATE_DEFAULT_SUB = 2; @@ -2536,27 +2542,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); } - if ((events & PhoneStateListener.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, null); - } - - if ((events & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) { - mContext.enforceCallingOrSelfPermission( - android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); - } - - if ((events & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) { + if ((events & READ_PRIVILEGED_PHONE_STATE_PERMISSION_MASK) != 0) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, null); } |