summaryrefslogtreecommitdiff
path: root/telephony/java
diff options
context:
space:
mode:
authorSarah Chin <sarahchin@google.com>2020-10-28 13:05:29 -0700
committerSarah Chin <sarahchin@google.com>2020-11-19 14:37:35 -0800
commitc315bf8c7db4465a601db7d8777fbc7467e8ffa6 (patch)
treefee98bf0043f50c907225e5bd10a2fab1895af63 /telephony/java
parent0b2d583b45ee80cb4a207276dee0965ef9d98be8 (diff)
Expose get/setCdmaRoamingMode and get/setCdmaSubscriptionMode as system API
Test: atest TelephonyManagerTest Fix: 171884158 Fix: 171883908 Change-Id: I5fe64d4bfb463af40b6e0ccfad1515266e40f7f6 Merged-In: I5fe64d4bfb463af40b6e0ccfad1515266e40f7f6
Diffstat (limited to 'telephony/java')
-rw-r--r--telephony/java/android/telephony/TelephonyManager.java111
-rw-r--r--telephony/java/com/android/internal/telephony/ITelephony.aidl8
2 files changed, 99 insertions, 20 deletions
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index f0274ca68cc1..92dc2fffe6e2 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -9334,11 +9334,22 @@ public class TelephonyManager {
* <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
* given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}
*
- * @return one of {@link #CDMA_ROAMING_MODE_RADIO_DEFAULT}, {@link #CDMA_ROAMING_MODE_HOME},
- * {@link #CDMA_ROAMING_MODE_AFFILIATED}, {@link #CDMA_ROAMING_MODE_ANY}.
+ * @return the CDMA roaming mode.
+ * @throws SecurityException if the caller does not have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
+ *
+ * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT
+ * @see #CDMA_ROAMING_MODE_HOME
+ * @see #CDMA_ROAMING_MODE_AFFILIATED
+ * @see #CDMA_ROAMING_MODE_ANY
+ *
+ * <p>Requires permission:
+ * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE}
+ * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
+ @SystemApi
@RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
public @CdmaRoamingMode int getCdmaRoamingMode() {
int mode = CDMA_ROAMING_MODE_RADIO_DEFAULT;
@@ -9346,9 +9357,12 @@ public class TelephonyManager {
ITelephony telephony = getITelephony();
if (telephony != null) {
mode = telephony.getCdmaRoamingMode(getSubId());
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException ex) {
Log.e(TAG, "Error calling ITelephony#getCdmaRoamingMode", ex);
+ ex.rethrowFromSystemServer();
}
return mode;
}
@@ -9359,25 +9373,36 @@ public class TelephonyManager {
* <p>If this object has been created with {@link #createForSubscriptionId}, applies to the
* given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}
*
- * @param mode should be one of {@link #CDMA_ROAMING_MODE_RADIO_DEFAULT},
- * {@link #CDMA_ROAMING_MODE_HOME}, {@link #CDMA_ROAMING_MODE_AFFILIATED},
- * {@link #CDMA_ROAMING_MODE_ANY}.
+ * @param mode CDMA roaming mode.
+ * @throws SecurityException if the caller does not have the permission.
+ * @throws IllegalStateException if the Telephony process or radio is not currently available.
*
- * @return {@code true} if successed.
+ * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT
+ * @see #CDMA_ROAMING_MODE_HOME
+ * @see #CDMA_ROAMING_MODE_AFFILIATED
+ * @see #CDMA_ROAMING_MODE_ANY
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
*
* @hide
*/
+ @SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public boolean setCdmaRoamingMode(@CdmaRoamingMode int mode) {
+ public void setCdmaRoamingMode(@CdmaRoamingMode int mode) {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
- return telephony.setCdmaRoamingMode(getSubId(), mode);
+ boolean result = telephony.setCdmaRoamingMode(getSubId(), mode);
+ if (!result) throw new IllegalStateException("radio is unavailable.");
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException ex) {
Log.e(TAG, "Error calling ITelephony#setCdmaRoamingMode", ex);
+ ex.rethrowFromSystemServer();
}
- return false;
}
/** @hide */
@@ -9389,48 +9414,94 @@ public class TelephonyManager {
@Retention(RetentionPolicy.SOURCE)
public @interface CdmaSubscription{}
- /** Used for CDMA subscription mode, it'll be UNKNOWN if there is no Subscription source.
+ /**
+ * Used for CDMA subscription mode, it'll be UNKNOWN if there is no Subscription source.
* @hide
*/
+ @SystemApi
public static final int CDMA_SUBSCRIPTION_UNKNOWN = -1;
- /** Used for CDMA subscription mode: RUIM/SIM (default)
+ /**
+ * Used for CDMA subscription mode: RUIM/SIM (default)
* @hide
*/
+ @SystemApi
public static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0;
- /** Used for CDMA subscription mode: NV -> non-volatile memory
+ /**
+ * Used for CDMA subscription mode: NV -> non-volatile memory
* @hide
*/
+ @SystemApi
public static final int CDMA_SUBSCRIPTION_NV = 1;
- /** @hide */
- public static final int PREFERRED_CDMA_SUBSCRIPTION = CDMA_SUBSCRIPTION_RUIM_SIM;
+ /**
+ * Gets the subscription mode for CDMA phone.
+ *
+ * @return the CDMA subscription mode.
+ * @throws SecurityException if the caller does not have the permission.
+ * @throws IllegalStateException if the Telephony process or radio is not currently available.
+ *
+ * @see #CDMA_SUBSCRIPTION_UNKNOWN
+ * @see #CDMA_SUBSCRIPTION_RUIM_SIM
+ * @see #CDMA_SUBSCRIPTION_NV
+ *
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE}
+ * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}).
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ public @CdmaSubscription int getCdmaSubscriptionMode() {
+ int mode = CDMA_SUBSCRIPTION_RUIM_SIM;
+ try {
+ ITelephony telephony = getITelephony();
+ if (telephony != null) {
+ mode = telephony.getCdmaSubscriptionMode(getSubId());
+ } else {
+ throw new IllegalStateException("telephony service is null.");
+ }
+ } catch (RemoteException ex) {
+ Log.e(TAG, "Error calling ITelephony#getCdmaSubscriptionMode", ex);
+ ex.rethrowFromSystemServer();
+ }
+ return mode;
+ }
/**
* Sets the subscription mode for CDMA phone to the given mode {@code mode}.
*
- * @param mode CDMA subscription mode
- *
- * @return {@code true} if successed.
+ * @param mode CDMA subscription mode.
+ * @throws SecurityException if the caller does not have the permission.
+ * @throws IllegalStateException if the Telephony process is not currently available.
*
* @see #CDMA_SUBSCRIPTION_UNKNOWN
* @see #CDMA_SUBSCRIPTION_RUIM_SIM
* @see #CDMA_SUBSCRIPTION_NV
*
+ * <p>Requires Permission:
+ * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling
+ * app has carrier privileges (see {@link #hasCarrierPrivileges}).
+ *
* @hide
*/
+ @SystemApi
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
- public boolean setCdmaSubscriptionMode(@CdmaSubscription int mode) {
+ public void setCdmaSubscriptionMode(@CdmaSubscription int mode) {
try {
ITelephony telephony = getITelephony();
if (telephony != null) {
- return telephony.setCdmaSubscriptionMode(getSubId(), mode);
+ boolean result = telephony.setCdmaSubscriptionMode(getSubId(), mode);
+ if (!result) throw new IllegalStateException("radio is unavailable.");
+ } else {
+ throw new IllegalStateException("telephony service is null.");
}
} catch (RemoteException ex) {
Log.e(TAG, "Error calling ITelephony#setCdmaSubscriptionMode", ex);
+ ex.rethrowFromSystemServer();
}
- return false;
}
/**
diff --git a/telephony/java/com/android/internal/telephony/ITelephony.aidl b/telephony/java/com/android/internal/telephony/ITelephony.aidl
index d16cb16a290c..4895fffa5849 100644
--- a/telephony/java/com/android/internal/telephony/ITelephony.aidl
+++ b/telephony/java/com/android/internal/telephony/ITelephony.aidl
@@ -1799,6 +1799,14 @@ interface ITelephony {
boolean setCdmaRoamingMode(int subId, int mode);
/**
+ * Gets the subscription mode for the CDMA phone with the subscription id {@code subId}.
+ *
+ * @param the subscription id.
+ * @return the subscription mode for CDMA phone.
+ */
+ int getCdmaSubscriptionMode(int subId);
+
+ /**
* Sets the subscription mode for CDMA phone with the subscription {@code subId} to the given
* subscription mode {@code mode}.
*