Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d70fc9a authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Added new SIM state related broadcasts.

Test: Basic telephony sanity and unit tests
Bug: 64131518
Merged-in: Ie3d157e79a7040c161b9038c875a4a4f49d535ff
Change-Id: Ie3d157e79a7040c161b9038c875a4a4f49d535ff
parent 277c7d24
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -727,7 +727,9 @@ package android.content {
    field public static final java.lang.String ACTION_QUERY_PACKAGE_RESTART = "android.intent.action.QUERY_PACKAGE_RESTART";
    field public static final java.lang.String ACTION_RESOLVE_INSTANT_APP_PACKAGE = "android.intent.action.RESOLVE_INSTANT_APP_PACKAGE";
    field public static final java.lang.String ACTION_REVIEW_PERMISSIONS = "android.intent.action.REVIEW_PERMISSIONS";
    field public static final java.lang.String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
    field public static final java.lang.String ACTION_SIM_APPLICATION_STATE_CHANGED = "android.intent.action.SIM_APPLICATION_STATE_CHANGED";
    field public static final java.lang.String ACTION_SIM_CARD_STATE_CHANGED = "android.intent.action.SIM_CARD_STATE_CHANGED";
    field public static final deprecated java.lang.String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
    field public static final java.lang.String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP";
    field public static final java.lang.String ACTION_USER_REMOVED = "android.intent.action.USER_REMOVED";
    field public static final java.lang.String ACTION_VOICE_ASSIST = "android.intent.action.VOICE_ASSIST";
@@ -4034,6 +4036,8 @@ package android.telephony {
    method public int getCurrentPhoneType(int);
    method public deprecated boolean getDataEnabled();
    method public deprecated boolean getDataEnabled(int);
    method public int getSimApplicationState();
    method public int getSimCardState();
    method public java.util.List<android.telephony.TelephonyHistogram> getTelephonyHistograms();
    method public android.os.Bundle getVisualVoicemailSettings();
    method public boolean handlePinMmi(java.lang.String);
@@ -4062,8 +4066,11 @@ package android.telephony {
    field public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; // 0x1
    field public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; // 0x0
    field public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; // 0xffffffff
    field public static final java.lang.String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE";
    field public static final java.lang.String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL";
    field public static final java.lang.String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING";
    field public static final int SIM_STATE_LOADED = 10; // 0xa
    field public static final int SIM_STATE_PRESENT = 11; // 0xb
  }

  public abstract class VisualVoicemailService extends android.app.Service {
+71 −0
Original line number Diff line number Diff line
@@ -3511,11 +3511,82 @@ public class Intent implements Parcelable, Cloneable {
     * For more details see TelephonyIntents.ACTION_SIM_STATE_CHANGED. This is here
     * because TelephonyIntents is an internal class.
     * @hide
     * @deprecated Use {@link #ACTION_SIM_CARD_STATE_CHANGED} or
     * {@link #ACTION_SIM_APPLICATION_STATE_CHANGED}
     */
    @Deprecated
    @SystemApi
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";

    /**
     * Broadcast Action: The sim card state has changed.
     * The intent will have the following extra values:</p>
     * <dl>
     *   <dt>{@link android.telephony.TelephonyManager.EXTRA_SIM_STATE}</dt>
     *   <dd>The sim card state. One of:
     *     <dl>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_ABSENT}</dt>
     *       <dd>SIM card not found</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_CARD_IO_ERROR}</dt>
     *       <dd>SIM card IO error</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_CARD_RESTRICTED}</dt>
     *       <dd>SIM card is restricted</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_PRESENT}</dt>
     *       <dd>SIM card is present</dd>
     *     </dl>
     *   </dd>
     * </dl>
     *
     * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission.
     *
     * <p class="note">The current state can also be queried using
     * {@link android.telephony.TelephonyManager.getSimCardState()}
     *
     * <p class="note">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:</p>
     * <dl>
     *   <dt>{@link android.telephony.TelephonyManager.EXTRA_SIM_STATE}</dt>
     *   <dd>The sim application state. One of:
     *     <dl>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_NOT_READY}</dt>
     *       <dd>SIM card applications not ready</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_PIN_REQUIRED}</dt>
     *       <dd>SIM card PIN locked</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_PUK_REQUIRED}</dt>
     *       <dd>SIM card PUK locked</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_NETWORK_LOCKED}</dt>
     *       <dd>SIM card network locked</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_PERM_DISABLED}</dt>
     *       <dd>SIM card permanently disabled due to PUK failures</dd>
     *       <dt>{@link android.telephony.TelephonyManager.SIM_STATE_LOADED}</dt>
     *       <dd>SIM card data loaded</dd>
     *     </dl>
     *   </dd>
     * </dl>
     *
     * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission.
     *
     * <p class="note">The current state can also be queried using
     * {@link android.telephony.TelephonyManager.getSimApplicationState()}
     *
     * <p class="note">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:</p>
+89 −1
Original line number Diff line number Diff line
@@ -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;
    }

+7 −7
Original line number Diff line number Diff line
@@ -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();
            }