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