From 5d70fc9ae34138f34d2dd69b93a8ca718f0b14fd Mon Sep 17 00:00:00 2001
From: Amit Mahajan
Requires the READ_PRIVILEGED_PHONE_STATE permission. + * + *
The current state can also be queried using + * {@link android.telephony.TelephonyManager.getSimCardState()} + * + *
This is a protected intent that can only be sent by the system. + * @hide + */ + @SystemApi + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_SIM_CARD_STATE_CHANGED = + "android.intent.action.SIM_CARD_STATE_CHANGED"; + + /** + * Broadcast Action: The sim application state has changed. + * The intent will have the following extra values:
+ *Requires the READ_PRIVILEGED_PHONE_STATE permission. + * + *
The current state can also be queried using + * {@link android.telephony.TelephonyManager.getSimApplicationState()} + * + *
This is a protected intent that can only be sent by the system. + * @hide + */ + @SystemApi + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = + "android.intent.action.SIM_APPLICATION_STATE_CHANGED"; + /** * Broadcast Action: indicate that the phone service state has changed. * The intent will have the following extra values:
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index f278d7c22e75..b75ee912af35 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -2025,6 +2025,27 @@ public class TelephonyManager { * carrier restrictions. */ public static final int SIM_STATE_CARD_RESTRICTED = 9; + /** + * SIM card state: Loaded: SIM card applications have been loaded + * @hide + */ + @SystemApi + public static final int SIM_STATE_LOADED = 10; + /** + * SIM card state: SIM Card is present + * @hide + */ + @SystemApi + public static final int SIM_STATE_PRESENT = 11; + + /** + * Extra included in {@link Intent.ACTION_SIM_CARD_STATE_CHANGED} and + * {@link Intent.ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state. + * + * @hide + */ + @SystemApi + public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; /** * @return true if a ICC card is present @@ -2071,6 +2092,14 @@ public class TelephonyManager { * @see #SIM_STATE_CARD_RESTRICTED */ public int getSimState() { + int simState = getSimStateIncludingLoaded(); + if (simState == SIM_STATE_LOADED) { + simState = SIM_STATE_READY; + } + return simState; + } + + private int getSimStateIncludingLoaded() { int slotIndex = getSlotIndex(); // slotIndex may be invalid due to sim being absent. In that case query all slots to get // sim state @@ -2089,7 +2118,63 @@ public class TelephonyManager { "state as absent"); return SIM_STATE_ABSENT; } - return getSimState(slotIndex); + return SubscriptionManager.getSimStateForSlotIndex(slotIndex); + } + + /** + * Returns a constant indicating the state of the default SIM card. + * + * @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 + public int getSimCardState() { + int simCardState = getSimState(); + switch (simCardState) { + case SIM_STATE_UNKNOWN: + case SIM_STATE_ABSENT: + case SIM_STATE_CARD_IO_ERROR: + case SIM_STATE_CARD_RESTRICTED: + return simCardState; + default: + return SIM_STATE_PRESENT; + } + } + + /** + * Returns a constant indicating the state of the card applications on the default SIM card. + * + * @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 + public int getSimApplicationState() { + int simApplicationState = getSimStateIncludingLoaded(); + switch (simApplicationState) { + case SIM_STATE_UNKNOWN: + case SIM_STATE_ABSENT: + case SIM_STATE_CARD_IO_ERROR: + case SIM_STATE_CARD_RESTRICTED: + return SIM_STATE_UNKNOWN; + case SIM_STATE_READY: + // Ready is not a valid state anymore. The state that is broadcast goes from + // NOT_READY to either LOCKED or LOADED. + return SIM_STATE_NOT_READY; + default: + return simApplicationState; + } } /** @@ -2110,6 +2195,9 @@ public class TelephonyManager { */ public int getSimState(int slotIndex) { int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); + if (simState == SIM_STATE_LOADED) { + simState = SIM_STATE_READY; + } return simState; } diff --git a/telephony/java/com/android/internal/telephony/IccCardConstants.java b/telephony/java/com/android/internal/telephony/IccCardConstants.java index f3d9335f4052..d57f9afa01e9 100644 --- a/telephony/java/com/android/internal/telephony/IccCardConstants.java +++ b/telephony/java/com/android/internal/telephony/IccCardConstants.java @@ -30,16 +30,14 @@ public class IccCardConstants { public static final String INTENT_VALUE_ICC_NOT_READY = "NOT_READY"; /* ABSENT means ICC is missing */ public static final String INTENT_VALUE_ICC_ABSENT = "ABSENT"; + /* PRESENT means ICC is present */ + public static final String INTENT_VALUE_ICC_PRESENT = "PRESENT"; /* CARD_IO_ERROR means for three consecutive times there was SIM IO error */ static public final String INTENT_VALUE_ICC_CARD_IO_ERROR = "CARD_IO_ERROR"; /* CARD_RESTRICTED means card is present but not usable due to carrier restrictions */ static public final String INTENT_VALUE_ICC_CARD_RESTRICTED = "CARD_RESTRICTED"; /* LOCKED means ICC is locked by pin or by network */ public static final String INTENT_VALUE_ICC_LOCKED = "LOCKED"; - //TODO: we can remove this state in the future if Bug 18489776 analysis - //#42's first race condition is resolved - /* INTERNAL LOCKED means ICC is locked by pin or by network */ - public static final String INTENT_VALUE_ICC_INTERNAL_LOCKED = "INTERNAL_LOCKED"; /* READY means ICC is ready to access */ public static final String INTENT_VALUE_ICC_READY = "READY"; /* IMSI means ICC IMSI is ready in property */ @@ -77,7 +75,8 @@ public class IccCardConstants { NOT_READY, /** ordinal(6) == {@See TelephonyManager#SIM_STATE_NOT_READY} */ PERM_DISABLED, /** ordinal(7) == {@See TelephonyManager#SIM_STATE_PERM_DISABLED} */ CARD_IO_ERROR, /** ordinal(8) == {@See TelephonyManager#SIM_STATE_CARD_IO_ERROR} */ - CARD_RESTRICTED;/** ordinal(9) == {@See TelephonyManager#SIM_STATE_CARD_RESTRICTED} */ + CARD_RESTRICTED,/** ordinal(9) == {@See TelephonyManager#SIM_STATE_CARD_RESTRICTED} */ + LOADED; /** ordinal(9) == {@See TelephonyManager#SIM_STATE_LOADED} */ public boolean isPinLocked() { return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED)); @@ -85,9 +84,9 @@ public class IccCardConstants { public boolean iccCardExist() { return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED) - || (this == NETWORK_LOCKED) || (this == READY) + || (this == NETWORK_LOCKED) || (this == READY) || (this == NOT_READY) || (this == PERM_DISABLED) || (this == CARD_IO_ERROR) - || (this == CARD_RESTRICTED)); + || (this == CARD_RESTRICTED) || (this == LOADED)); } public static State intToState(int state) throws IllegalArgumentException { @@ -102,6 +101,7 @@ public class IccCardConstants { case 7: return PERM_DISABLED; case 8: return CARD_IO_ERROR; case 9: return CARD_RESTRICTED; + case 10: return LOADED; default: throw new IllegalArgumentException(); } -- cgit v1.2.3-59-g8ed1b