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     /* CARD_IO_ERROR means for three consecutive times there was SIM IO error */
34     static public final String INTENT_VALUE_ICC_CARD_IO_ERROR = "CARD_IO_ERROR";
35     /* LOCKED means ICC is locked by pin or by network */
36     public static final String INTENT_VALUE_ICC_LOCKED = "LOCKED";
37     //TODO: we can remove this state in the future if Bug 18489776 analysis
38     //#42's first race condition is resolved
39     /* INTERNAL LOCKED means ICC is locked by pin or by network */
40     public static final String INTENT_VALUE_ICC_INTERNAL_LOCKED = "INTERNAL_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 
isPinLocked()79         public boolean isPinLocked() {
80             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED));
81         }
82 
iccCardExist()83         public boolean iccCardExist() {
84             return ((this == PIN_REQUIRED) || (this == PUK_REQUIRED)
85                     || (this == NETWORK_LOCKED) || (this == READY)
86                     || (this == PERM_DISABLED) || (this == CARD_IO_ERROR));
87         }
88 
intToState(int state)89         public static State intToState(int state) throws IllegalArgumentException {
90             switch(state) {
91                 case 0: return UNKNOWN;
92                 case 1: return ABSENT;
93                 case 2: return PIN_REQUIRED;
94                 case 3: return PUK_REQUIRED;
95                 case 4: return NETWORK_LOCKED;
96                 case 5: return READY;
97                 case 6: return NOT_READY;
98                 case 7: return PERM_DISABLED;
99                 case 8: return CARD_IO_ERROR;
100                 default:
101                     throw new IllegalArgumentException();
102             }
103         }
104     }
105 }
106