summaryrefslogtreecommitdiff
path: root/telephony/java
diff options
context:
space:
mode:
authorBrad Ebinger <breadley@google.com>2021-03-23 21:01:51 +0000
committerBrad Ebinger <breadley@google.com>2021-03-25 15:11:00 -0700
commita8366aeae40143a3d706de43772d4c7cde59b513 (patch)
tree21b909c3928099a9e4cdaef5e185ee828281c67a /telephony/java
parent1d70937fe795e7d879e496ee192f1621a7ce0cbb (diff)
Enforce READ_PHONE_STATE for APIs involving call state
For API version 31+, ensure that READ_PHONE_STATE is checked on APIs that retrieve/notify the call state of the device. Bug: 157233955 Test: atest CtsTelecomTestCases2 CtsTelephony2TestCases Change-Id: I9f8674a3075d3e0f75ee4f41eefce328c0fa6b91
Diffstat (limited to 'telephony/java')
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java62
-rw-r--r--telephony/java/com/android/internal/telephony/ITelephony.aidl4
2 files changed, 56 insertions, 10 deletions
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index d2da51a1faca..eed42d914cf3 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -5702,9 +5702,20 @@ public class TelephonyManager {
* Note: The call state returned via this method may differ from what is reported by
* {@link PhoneStateListener#onCallStateChanged(int, String)}, as that callback only considers
* Telephony (mobile) calls.
+ * <p>
+ * Requires Permission:
+ * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications
+ * targeting API level 31+.
*
* @return the current call state.
+ * @deprecated Use {@link #getCallStateForSubscription} to retrieve the call state for a
+ * specific telephony subscription (which allows carrier privileged apps),
+ * {@link TelephonyCallback.CallStateListener} for real-time call state updates, or
+ * {@link TelecomManager#isInCall()}, which supplies an aggregate "in call" state for the entire
+ * device.
*/
+ @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true)
+ @Deprecated
public @CallState int getCallState() {
if (mContext != null) {
TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class);
@@ -5716,19 +5727,48 @@ public class TelephonyManager {
}
/**
+ * Retrieve the call state for a specific subscription that was specified when this
+ * TelephonyManager instance was created.
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the calling
+ * application has carrier privileges (see {@link #hasCarrierPrivileges}).
+ * @see TelephonyManager#createForSubscriptionId(int)
+ * @see TelephonyManager#createForPhoneAccountHandle(PhoneAccountHandle)
+ * @return The call state of the subscription associated with this TelephonyManager instance.
+ */
+ @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
+ public @CallState int getCallStateForSubscription() {
+ return getCallState(getSubId());
+ }
+
+ /**
* Returns the Telephony call state for calls on a specific subscription.
* <p>
* Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()}
* considers the state of calls from other {@link android.telecom.ConnectionService}
* implementations.
+ * <p>
+ * Requires Permission:
+ * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications
+ * targeting API level 31+ or that the calling application has carrier privileges
+ * (see {@link #hasCarrierPrivileges()}).
*
* @param subId the subscription to check call state for.
* @hide
*/
@UnsupportedAppUsage
+ @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true)
public @CallState int getCallState(int subId) {
- int phoneId = SubscriptionManager.getPhoneId(subId);
- return getCallStateForSlot(phoneId);
+ ITelephony telephony = getITelephony();
+ if (telephony == null) {
+ return CALL_STATE_IDLE;
+ }
+ try {
+ return telephony.getCallStateForSubscription(subId, mContext.getPackageName(),
+ mContext.getAttributionTag());
+ } catch (RemoteException e) {
+ return CALL_STATE_IDLE;
+ }
}
/**
@@ -5745,22 +5785,28 @@ public class TelephonyManager {
* Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()}
* considers the state of calls from other {@link android.telecom.ConnectionService}
* implementations.
+ * <p>
+ * Requires Permission:
+ * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications
+ * targeting API level 31+ or that the calling application has carrier privileges
+ * (see {@link #hasCarrierPrivileges()}).
*
* @param slotIndex the SIM slot index to check call state for.
* @hide
*/
+ @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true)
public @CallState int getCallStateForSlot(int slotIndex) {
try {
+ int[] subId = SubscriptionManager.getSubId(slotIndex);
ITelephony telephony = getITelephony();
- if (telephony == null)
+ if (telephony == null || subId == null || subId.length == 0) {
return CALL_STATE_IDLE;
- return telephony.getCallStateForSlot(slotIndex);
- } catch (RemoteException ex) {
+ }
+ return telephony.getCallStateForSubscription(subId[0], mContext.getPackageName(),
+ mContext.getAttributionTag());
+ } catch (RemoteException | NullPointerException ex) {
// the phone process is restarting.
return CALL_STATE_IDLE;
- } catch (NullPointerException ex) {
- // the phone process is restarting.
- return CALL_STATE_IDLE;
}
}
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index 46752b7fe1ea..afc538d3bae3 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -298,9 +298,9 @@ interface ITelephony {
int getCallState();
/**
- * Returns the call state for a slot.
+ * Returns the call state for a specific subscriiption.
*/
- int getCallStateForSlot(int slotIndex);
+ int getCallStateForSubscription(int subId, String callingPackage, String featureId);
/**
* Replaced by getDataActivityForSubId.