1 /*
2  * Copyright (C) 2006 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 
17 package com.android.internal.telephony.uicc;
18 
19 import android.telephony.SubscriptionInfo;
20 
21 /**
22  * See also RIL_CardStatus in include/telephony/ril.h
23  *
24  * {@hide}
25  */
26 public class IccCardStatus {
27     public static final int CARD_MAX_APPS = 8;
28 
29     public enum CardState {
30         CARDSTATE_ABSENT,
31         CARDSTATE_PRESENT,
32         CARDSTATE_ERROR,
33         CARDSTATE_RESTRICTED;
34 
isCardPresent()35         boolean isCardPresent() {
36             return this == CARDSTATE_PRESENT ||
37                 this == CARDSTATE_RESTRICTED;
38         }
39     }
40 
41     public enum PinState {
42         PINSTATE_UNKNOWN,
43         PINSTATE_ENABLED_NOT_VERIFIED,
44         PINSTATE_ENABLED_VERIFIED,
45         PINSTATE_DISABLED,
46         PINSTATE_ENABLED_BLOCKED,
47         PINSTATE_ENABLED_PERM_BLOCKED;
48 
isPermBlocked()49         boolean isPermBlocked() {
50             return this == PINSTATE_ENABLED_PERM_BLOCKED;
51         }
52 
isPinRequired()53         boolean isPinRequired() {
54             return this == PINSTATE_ENABLED_NOT_VERIFIED;
55         }
56 
isPukRequired()57         boolean isPukRequired() {
58             return this == PINSTATE_ENABLED_BLOCKED;
59         }
60     }
61 
62     public CardState  mCardState;
63     public PinState   mUniversalPinState;
64     public int        mGsmUmtsSubscriptionAppIndex;
65     public int        mCdmaSubscriptionAppIndex;
66     public int        mImsSubscriptionAppIndex;
67     public int        physicalSlotIndex = UiccController.INVALID_SLOT_ID;
68     public String     atr;
69     public String     iccid;
70 
71     public IccCardApplicationStatus[] mApplications;
72 
setCardState(int state)73     public void setCardState(int state) {
74         switch(state) {
75         case 0:
76             mCardState = CardState.CARDSTATE_ABSENT;
77             break;
78         case 1:
79             mCardState = CardState.CARDSTATE_PRESENT;
80             break;
81         case 2:
82             mCardState = CardState.CARDSTATE_ERROR;
83             break;
84         case 3:
85             mCardState = CardState.CARDSTATE_RESTRICTED;
86             break;
87         default:
88             throw new RuntimeException("Unrecognized RIL_CardState: " + state);
89         }
90     }
91 
setUniversalPinState(int state)92     public void setUniversalPinState(int state) {
93         switch(state) {
94         case 0:
95             mUniversalPinState = PinState.PINSTATE_UNKNOWN;
96             break;
97         case 1:
98             mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
99             break;
100         case 2:
101             mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
102             break;
103         case 3:
104             mUniversalPinState = PinState.PINSTATE_DISABLED;
105             break;
106         case 4:
107             mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
108             break;
109         case 5:
110             mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
111             break;
112         default:
113             throw new RuntimeException("Unrecognized RIL_PinState: " + state);
114         }
115     }
116 
117     @Override
toString()118     public String toString() {
119         IccCardApplicationStatus app;
120 
121         StringBuilder sb = new StringBuilder();
122         sb.append("IccCardState {").append(mCardState).append(",")
123         .append(mUniversalPinState)
124         .append(",num_apps=").append(mApplications.length);
125 
126         sb.append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
127         if (mApplications != null
128                 && mGsmUmtsSubscriptionAppIndex >= 0
129                 && mGsmUmtsSubscriptionAppIndex < mApplications.length) {
130             app = mApplications[mGsmUmtsSubscriptionAppIndex];
131             sb.append(app == null ? "null" : app);
132         }
133 
134         sb.append(",cdma_id=").append(mCdmaSubscriptionAppIndex);
135         if (mApplications != null
136                 && mCdmaSubscriptionAppIndex >= 0
137                 && mCdmaSubscriptionAppIndex < mApplications.length) {
138             app = mApplications[mCdmaSubscriptionAppIndex];
139             sb.append(app == null ? "null" : app);
140         }
141 
142         sb.append(",ims_id=").append(mImsSubscriptionAppIndex);
143         if (mApplications != null
144                 && mImsSubscriptionAppIndex >= 0
145                 && mImsSubscriptionAppIndex < mApplications.length) {
146             app = mApplications[mImsSubscriptionAppIndex];
147             sb.append(app == null ? "null" : app);
148         }
149 
150         sb.append(",physical_slot_id=").append(physicalSlotIndex).append(",atr=").append(atr);
151         sb.append(",iccid=").append(SubscriptionInfo.givePrintableIccid(iccid));
152 
153         sb.append("}");
154         return sb.toString();
155     }
156 
157 }
158