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.os.Build;
21 import android.telephony.SubscriptionInfo;
22 
23 import com.android.internal.telephony.uicc.IccSlotStatus.MultipleEnabledProfilesMode;
24 import com.android.internal.telephony.util.TelephonyUtils;
25 import com.android.telephony.Rlog;
26 
27 /**
28  * See also RIL_CardStatus in include/telephony/ril.h
29  *
30  * {@hide}
31  */
32 public class IccCardStatus {
33     public static final int CARD_MAX_APPS = 8;
34 
35     public enum CardState {
36         @UnsupportedAppUsage
37         CARDSTATE_ABSENT,
38         @UnsupportedAppUsage
39         CARDSTATE_PRESENT,
40         @UnsupportedAppUsage
41         CARDSTATE_ERROR,
42         CARDSTATE_RESTRICTED;
43 
44         @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
isCardPresent()45         public boolean isCardPresent() {
46             return this == CARDSTATE_PRESENT ||
47                 this == CARDSTATE_RESTRICTED;
48         }
49     }
50 
51     public enum PinState {
52         PINSTATE_UNKNOWN,
53         PINSTATE_ENABLED_NOT_VERIFIED,
54         PINSTATE_ENABLED_VERIFIED,
55         @UnsupportedAppUsage
56         PINSTATE_DISABLED,
57         @UnsupportedAppUsage
58         PINSTATE_ENABLED_BLOCKED,
59         @UnsupportedAppUsage
60         PINSTATE_ENABLED_PERM_BLOCKED;
61 
isPermBlocked()62         boolean isPermBlocked() {
63             return this == PINSTATE_ENABLED_PERM_BLOCKED;
64         }
65 
isPinRequired()66         boolean isPinRequired() {
67             return this == PINSTATE_ENABLED_NOT_VERIFIED;
68         }
69 
isPukRequired()70         boolean isPukRequired() {
71             return this == PINSTATE_ENABLED_BLOCKED;
72         }
73     }
74 
75     @UnsupportedAppUsage
76     public CardState  mCardState;
77     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
78     public PinState   mUniversalPinState;
79     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
80     public int        mGsmUmtsSubscriptionAppIndex;
81     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
82     public int        mCdmaSubscriptionAppIndex;
83     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
84     public int        mImsSubscriptionAppIndex;
85     public String     atr;
86     public String     iccid;
87     public String     eid;
88 
89     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
90     public IccCardApplicationStatus[] mApplications;
91 
92     public IccSlotPortMapping mSlotPortMapping;
93 
94     public MultipleEnabledProfilesMode mSupportedMepMode = MultipleEnabledProfilesMode.NONE;
95 
96     /**
97      * Set the MultipleEnabledProfilesMode according to the input mode.
98      */
setMultipleEnabledProfilesMode(int mode)99     public void setMultipleEnabledProfilesMode(int mode) {
100         switch(mode) {
101             case 0:
102                 mSupportedMepMode = MultipleEnabledProfilesMode.NONE;
103                 break;
104             case 1:
105                 mSupportedMepMode = MultipleEnabledProfilesMode.MEP_A1;
106                 break;
107             case 2:
108                 mSupportedMepMode = MultipleEnabledProfilesMode.MEP_A2;
109                 break;
110             case 3:
111                 mSupportedMepMode = MultipleEnabledProfilesMode.MEP_B;
112                 break;
113             default:
114                 throw new RuntimeException("Unrecognized RIL_MultipleEnabledProfilesMode: " + mode);
115         }
116     }
117 
setCardState(int state)118     public void setCardState(int state) {
119         switch(state) {
120         case 0:
121             mCardState = CardState.CARDSTATE_ABSENT;
122             break;
123         case 1:
124             mCardState = CardState.CARDSTATE_PRESENT;
125             break;
126         case 2:
127             mCardState = CardState.CARDSTATE_ERROR;
128             break;
129         case 3:
130             mCardState = CardState.CARDSTATE_RESTRICTED;
131             break;
132         default:
133             throw new RuntimeException("Unrecognized RIL_CardState: " + state);
134         }
135     }
136 
setUniversalPinState(int state)137     public void setUniversalPinState(int state) {
138         switch(state) {
139         case 0:
140             mUniversalPinState = PinState.PINSTATE_UNKNOWN;
141             break;
142         case 1:
143             mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
144             break;
145         case 2:
146             mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
147             break;
148         case 3:
149             mUniversalPinState = PinState.PINSTATE_DISABLED;
150             break;
151         case 4:
152             mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
153             break;
154         case 5:
155             mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
156             break;
157         default:
158             throw new RuntimeException("Unrecognized RIL_PinState: " + state);
159         }
160     }
161 
162     @Override
toString()163     public String toString() {
164         IccCardApplicationStatus app;
165 
166         StringBuilder sb = new StringBuilder();
167         sb.append("IccCardState {").append(mCardState).append(",")
168         .append(mUniversalPinState);
169         if (mApplications != null) {
170             sb.append(",num_apps=").append(mApplications.length);
171         } else {
172             sb.append(",mApplications=null");
173         }
174 
175         sb.append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
176         if (mApplications != null
177                 && mGsmUmtsSubscriptionAppIndex >= 0
178                 && mGsmUmtsSubscriptionAppIndex < mApplications.length) {
179             app = mApplications[mGsmUmtsSubscriptionAppIndex];
180             sb.append(app == null ? "null" : app);
181         }
182 
183         sb.append(",cdma_id=").append(mCdmaSubscriptionAppIndex);
184         if (mApplications != null
185                 && mCdmaSubscriptionAppIndex >= 0
186                 && mCdmaSubscriptionAppIndex < mApplications.length) {
187             app = mApplications[mCdmaSubscriptionAppIndex];
188             sb.append(app == null ? "null" : app);
189         }
190 
191         sb.append(",ims_id=").append(mImsSubscriptionAppIndex);
192         if (mApplications != null
193                 && mImsSubscriptionAppIndex >= 0
194                 && mImsSubscriptionAppIndex < mApplications.length) {
195             app = mApplications[mImsSubscriptionAppIndex];
196             sb.append(app == null ? "null" : app);
197         }
198 
199         sb.append(",atr=").append(atr);
200         sb.append(",iccid=").append(SubscriptionInfo.getPrintableId(iccid));
201         sb.append(",eid=").append(Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, eid));
202         sb.append(",SupportedMepMode=").append(mSupportedMepMode);
203         sb.append(",SlotPortMapping=").append(mSlotPortMapping);
204 
205         sb.append("}");
206         return sb.toString();
207     }
208 
209 }
210