Merge "Add TelephonyManager APIs to take physical slotIndex - getSimCardState - getSimApplicationState"
diff --git a/api/system-current.txt b/api/system-current.txt
index 09737e8..8c222b6 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -8129,7 +8129,9 @@
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getPreferredNetworkTypeBitmask();
method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public int getRadioPowerState();
method public int getSimApplicationState();
+ method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getSimApplicationState(int);
method public int getSimCardState();
+ method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getSimCardState(int);
method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.Locale getSimLocale();
method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getSupportedRadioAccessFamily();
method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public java.util.List<android.telephony.TelephonyHistogram> getTelephonyHistograms();
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index b830860..74c6d5d 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -3083,19 +3083,62 @@
*/
@SystemApi
public int getSimCardState() {
- int simCardState = getSimState();
- switch (simCardState) {
+ int simState = getSimState();
+ return getSimCardStateFromSimState(simState);
+ }
+
+ /**
+ * Returns a constant indicating the state of the device SIM card in a physical slot.
+ *
+ * @param physicalSlotIndex physical slot index
+ *
+ * @see #SIM_STATE_UNKNOWN
+ * @see #SIM_STATE_ABSENT
+ * @see #SIM_STATE_CARD_IO_ERROR
+ * @see #SIM_STATE_CARD_RESTRICTED
+ * @see #SIM_STATE_PRESENT
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ public int getSimCardState(int physicalSlotIndex) {
+ int simState = getSimState(getLogicalSlotIndex(physicalSlotIndex));
+ return getSimCardStateFromSimState(simState);
+ }
+
+ /**
+ * Converts SIM state to SIM card state.
+ * @param simState
+ * @return SIM card state
+ */
+ private int getSimCardStateFromSimState(int simState) {
+ switch (simState) {
case SIM_STATE_UNKNOWN:
case SIM_STATE_ABSENT:
case SIM_STATE_CARD_IO_ERROR:
case SIM_STATE_CARD_RESTRICTED:
- return simCardState;
+ return simState;
default:
return SIM_STATE_PRESENT;
}
}
/**
+ * Converts a physical slot index to logical slot index.
+ * @param physicalSlotIndex physical slot index
+ * @return logical slot index
+ */
+ private int getLogicalSlotIndex(int physicalSlotIndex) {
+ UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
+ if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length) {
+ return slotInfos[physicalSlotIndex].getLogicalSlotIdx();
+ }
+
+ return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
+ }
+
+ /**
* Returns a constant indicating the state of the card applications on the default SIM card.
*
* @see #SIM_STATE_UNKNOWN
@@ -3110,8 +3153,41 @@
*/
@SystemApi
public int getSimApplicationState() {
- int simApplicationState = getSimStateIncludingLoaded();
- switch (simApplicationState) {
+ int simState = getSimStateIncludingLoaded();
+ return getSimApplicationStateFromSimState(simState);
+ }
+
+ /**
+ * Returns a constant indicating the state of the card applications on the device SIM card in
+ * a physical slot.
+ *
+ * @param physicalSlotIndex physical slot index
+ *
+ * @see #SIM_STATE_UNKNOWN
+ * @see #SIM_STATE_PIN_REQUIRED
+ * @see #SIM_STATE_PUK_REQUIRED
+ * @see #SIM_STATE_NETWORK_LOCKED
+ * @see #SIM_STATE_NOT_READY
+ * @see #SIM_STATE_PERM_DISABLED
+ * @see #SIM_STATE_LOADED
+ *
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+ public int getSimApplicationState(int physicalSlotIndex) {
+ int simState =
+ SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex));
+ return getSimApplicationStateFromSimState(simState);
+ }
+
+ /**
+ * Converts SIM state to SIM application state.
+ * @param simState
+ * @return SIM application state
+ */
+ private int getSimApplicationStateFromSimState(int simState) {
+ switch (simState) {
case SIM_STATE_UNKNOWN:
case SIM_STATE_ABSENT:
case SIM_STATE_CARD_IO_ERROR:
@@ -3122,14 +3198,14 @@
// NOT_READY to either LOCKED or LOADED.
return SIM_STATE_NOT_READY;
default:
- return simApplicationState;
+ return simState;
}
}
/**
- * Returns a constant indicating the state of the device SIM card in a slot.
+ * Returns a constant indicating the state of the device SIM card in a logical slot.
*
- * @param slotIndex
+ * @param slotIndex logical slot index
*
* @see #SIM_STATE_UNKNOWN
* @see #SIM_STATE_ABSENT