Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.internal.telephony;
     17 
     18 import android.telephony.TelephonyManager;
     19 
     20 /**
     21  * {@hide}
     22  */
     23 public class IccCardConstants {
     24 
     25     /* The extra data for broadcasting intent INTENT_ICC_STATE_CHANGE */
     26     public static final String INTENT_KEY_ICC_STATE = "ss";
     27     /* UNKNOWN means the ICC state is unknown */
     28     public static final String INTENT_VALUE_ICC_UNKNOWN = "UNKNOWN";
     29     /* NOT_READY means the ICC interface is not ready (eg, radio is off or powering on) */
     30     public static final String INTENT_VALUE_ICC_NOT_READY = "NOT_READY";
     31     /* ABSENT means ICC is missing */
     32     public static final String INTENT_VALUE_ICC_ABSENT = "ABSENT";
     33     /* PRESENT means ICC is present */
     34     public static final String INTENT_VALUE_ICC_PRESENT = "PRESENT";
     35     /* CARD_IO_ERROR means for three consecutive times there was SIM IO error */
     36     static public final String INTENT_VALUE_ICC_CARD_IO_ERROR = "CARD_IO_ERROR";
     37     /* CARD_RESTRICTED means card is present but not usable due to carrier restrictions */
     38     static public final String INTENT_VALUE_ICC_CARD_RESTRICTED = "CARD_RESTRICTED";
     39     /* LOCKED means ICC is locked by pin or by network */
     40     public static final String INTENT_VALUE_ICC_LOCKED = "LOCKED";
     41     /* READY means ICC is ready to access */
     42     public static final String INTENT_VALUE_ICC_READY = "READY";
     43     /* IMSI means ICC IMSI is ready in property */
     44     public static final String INTENT_VALUE_ICC_IMSI = "IMSI";
     45     /* LOADED means all ICC records, including IMSI, are loaded */
     46     public static final String INTENT_VALUE_ICC_LOADED = "LOADED";
     47     /* The extra data for broadcasting intent INTENT_ICC_STATE_CHANGE */
     48     public static final String INTENT_KEY_LOCKED_REASON = "reason";
     49     /* PIN means ICC is locked on PIN1 */
     50     public static final String INTENT_VALUE_LOCKED_ON_PIN = "PIN";
     51     /* PUK means ICC is locked on PUK1 */
     52     public static final String INTENT_VALUE_LOCKED_ON_PUK = "PUK";
     53     /* NETWORK means ICC is locked on NETWORK PERSONALIZATION */
     54     public static final String INTENT_VALUE_LOCKED_NETWORK = "NETWORK";
     55     /* PERM_DISABLED means ICC is permanently disabled due to puk fails */
     56     public static final String INTENT_VALUE_ABSENT_ON_PERM_DISABLED = "PERM_DISABLED";
     57 
     58     /**
     59      * This is combination of IccCardStatus.CardState and IccCardApplicationStatus.AppState
     60      * for external apps (like PhoneApp) to use
     61      *
     62      * UNKNOWN is a transient state, for example, after user inputs ICC pin under
     63      * PIN_REQUIRED state, the query for ICC status returns UNKNOWN before it
     64      * turns to READY
     65      *
     66      * The ordinal values much match {@link TelephonyManager#SIM_STATE_UNKNOWN} ...
     67      */
     68     public enum State {
     69         UNKNOWN,        /** ordinal(0) == {@See TelephonyManager#SIM_STATE_UNKNOWN} */
     70         ABSENT,         /** ordinal(1) == {@See TelephonyManager#SIM_STATE_ABSENT} */
     71         PIN_REQUIRED,   /** ordinal(2) == {@See TelephonyManager#SIM_STATE_PIN_REQUIRED} */
     72         PUK_REQUIRED,   /** ordinal(3) == {@See TelephonyManager#SIM_STATE_PUK_REQUIRED} */
     73         NETWORK_LOCKED, /** ordinal(4) == {@See TelephonyManager#SIM_STATE_NETWORK_LOCKED} */
     74         READY,          /** ordinal(5) == {@See TelephonyManager#SIM_STATE_READY} */
     75         NOT_READY,      /** ordinal(6) == {@See TelephonyManager#SIM_STATE_NOT_READY} */
     76         PERM_DISABLED,  /** ordinal(7) == {@See TelephonyManager#SIM_STATE_PERM_DISABLED} */
     77         CARD_IO_ERROR,  /** ordinal(8) == {@See TelephonyManager#SIM_STATE_CARD_IO_ERROR} */
     78         CARD_RESTRICTED,/** ordinal(9) == {@See TelephonyManager#SIM_STATE_CARD_RESTRICTED} */
     79         LOADED;         /** ordinal(9) == {@See TelephonyManager#SIM_STATE_LOADED} */
     80 
     81         public boolean isPinLocked() {
     82             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED));
     83         }
     84 
     85         public boolean iccCardExist() {
     86             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED)
     87                     || (this == NETWORK_LOCKED) || (this == READY) || (this == NOT_READY)
     88                     || (this == PERM_DISABLED) || (this == CARD_IO_ERROR)
     89                     || (this == CARD_RESTRICTED) || (this == LOADED));
     90         }
     91 
     92         public static State intToState(int state) throws IllegalArgumentException {
     93             switch(state) {
     94                 case 0: return UNKNOWN;
     95                 case 1: return ABSENT;
     96                 case 2: return PIN_REQUIRED;
     97                 case 3: return PUK_REQUIRED;
     98                 case 4: return NETWORK_LOCKED;
     99                 case 5: return READY;
    100                 case 6: return NOT_READY;
    101                 case 7: return PERM_DISABLED;
    102                 case 8: return CARD_IO_ERROR;
    103                 case 9: return CARD_RESTRICTED;
    104                 case 10: return LOADED;
    105                 default:
    106                     throw new IllegalArgumentException();
    107             }
    108         }
    109     }
    110 }
    111