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 
21 import com.android.internal.telephony.uicc.IccCardStatus.PinState;
22 import com.android.telephony.Rlog;
23 
24 /**
25  * See also RIL_AppStatus in include/telephony/ril.h
26  *
27  * {@hide}
28  */
29 public class IccCardApplicationStatus {
30     // TODO: Replace with constants from PhoneConstants.APPTYPE_xxx
31     @UnsupportedAppUsage(implicitMember =
32             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$AppType;")
33     public enum AppType{
34         @UnsupportedAppUsage
35         APPTYPE_UNKNOWN,
36         @UnsupportedAppUsage
37         APPTYPE_SIM,
38         @UnsupportedAppUsage
39         APPTYPE_USIM,
40         @UnsupportedAppUsage
41         APPTYPE_RUIM,
42         @UnsupportedAppUsage
43         APPTYPE_CSIM,
44         @UnsupportedAppUsage
45         APPTYPE_ISIM
46     }
47 
48     @UnsupportedAppUsage(implicitMember =
49             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$AppState;")
50     public enum AppState{
51         @UnsupportedAppUsage
52         APPSTATE_UNKNOWN,
53         @UnsupportedAppUsage
54         APPSTATE_DETECTED,
55         @UnsupportedAppUsage
56         APPSTATE_PIN,
57         @UnsupportedAppUsage
58         APPSTATE_PUK,
59         @UnsupportedAppUsage
60         APPSTATE_SUBSCRIPTION_PERSO,
61         @UnsupportedAppUsage
62         APPSTATE_READY;
63 
isPinRequired()64         boolean isPinRequired() {
65             return this == APPSTATE_PIN;
66         }
67 
isPukRequired()68         boolean isPukRequired() {
69             return this == APPSTATE_PUK;
70         }
71 
isSubscriptionPersoEnabled()72         boolean isSubscriptionPersoEnabled() {
73             return this == APPSTATE_SUBSCRIPTION_PERSO;
74         }
75 
isAppReady()76         boolean isAppReady() {
77             return this == APPSTATE_READY;
78         }
79 
isAppNotReady()80         boolean isAppNotReady() {
81             return this == APPSTATE_UNKNOWN  ||
82                    this == APPSTATE_DETECTED;
83         }
84     }
85 
86     @UnsupportedAppUsage(implicitMember =
87             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$PersoSubState;")
88     public enum PersoSubState {
89         @UnsupportedAppUsage
90         PERSOSUBSTATE_UNKNOWN,
91         PERSOSUBSTATE_IN_PROGRESS,
92         PERSOSUBSTATE_READY,
93         @UnsupportedAppUsage
94         PERSOSUBSTATE_SIM_NETWORK,
95         @UnsupportedAppUsage
96         PERSOSUBSTATE_SIM_NETWORK_SUBSET,
97         PERSOSUBSTATE_SIM_CORPORATE,
98         @UnsupportedAppUsage
99         PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
100         PERSOSUBSTATE_SIM_SIM,
101         PERSOSUBSTATE_SIM_NETWORK_PUK,
102         @UnsupportedAppUsage
103         PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK,
104         PERSOSUBSTATE_SIM_CORPORATE_PUK,
105         @UnsupportedAppUsage
106         PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
107         PERSOSUBSTATE_SIM_SIM_PUK,
108         PERSOSUBSTATE_RUIM_NETWORK1,
109         PERSOSUBSTATE_RUIM_NETWORK2,
110         PERSOSUBSTATE_RUIM_HRPD,
111         PERSOSUBSTATE_RUIM_CORPORATE,
112         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER,
113         PERSOSUBSTATE_RUIM_RUIM,
114         PERSOSUBSTATE_RUIM_NETWORK1_PUK,
115         PERSOSUBSTATE_RUIM_NETWORK2_PUK,
116         PERSOSUBSTATE_RUIM_HRPD_PUK,
117         PERSOSUBSTATE_RUIM_CORPORATE_PUK,
118         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK,
119         PERSOSUBSTATE_RUIM_RUIM_PUK,
120         PERSOSUBSTATE_SIM_SPN,
121         PERSOSUBSTATE_SIM_SPN_PUK,
122         PERSOSUBSTATE_SIM_SP_EHPLMN,
123         PERSOSUBSTATE_SIM_SP_EHPLMN_PUK,
124         PERSOSUBSTATE_SIM_ICCID,
125         PERSOSUBSTATE_SIM_ICCID_PUK,
126         PERSOSUBSTATE_SIM_IMPI,
127         PERSOSUBSTATE_SIM_IMPI_PUK,
128         PERSOSUBSTATE_SIM_NS_SP,
129         PERSOSUBSTATE_SIM_NS_SP_PUK;
130 
isPersoSubStateUnknown()131         boolean isPersoSubStateUnknown() {
132             return this == PERSOSUBSTATE_UNKNOWN;
133         }
134 
isPersoLocked(PersoSubState mState)135         public static boolean isPersoLocked(PersoSubState mState) {
136             switch (mState) {
137                 case PERSOSUBSTATE_UNKNOWN:
138                 case PERSOSUBSTATE_IN_PROGRESS:
139                 case PERSOSUBSTATE_READY:
140                     return false;
141                 default:
142                     return true;
143             }
144         }
145     }
146 
147     @UnsupportedAppUsage
148     public AppType        app_type;
149     public AppState       app_state;
150     // applicable only if app_state == RIL_APPSTATE_SUBSCRIPTION_PERSO
151     public PersoSubState  perso_substate;
152     // null terminated string, e.g., from 0xA0, 0x00 -> 0x41, 0x30, 0x30, 0x30 */
153     public String         aid;
154     // null terminated string
155     public String         app_label;
156     // applicable to USIM and CSIM
157     public int            pin1_replaced;
158     public PinState       pin1;
159     public PinState       pin2;
160 
161     @UnsupportedAppUsage
IccCardApplicationStatus()162     public IccCardApplicationStatus() {
163     }
164 
165     @UnsupportedAppUsage
AppTypeFromRILInt(int type)166     public AppType AppTypeFromRILInt(int type) {
167         AppType newType;
168         /* RIL_AppType ril.h */
169         switch(type) {
170             case 0: newType = AppType.APPTYPE_UNKNOWN; break;
171             case 1: newType = AppType.APPTYPE_SIM;     break;
172             case 2: newType = AppType.APPTYPE_USIM;    break;
173             case 3: newType = AppType.APPTYPE_RUIM;    break;
174             case 4: newType = AppType.APPTYPE_CSIM;    break;
175             case 5: newType = AppType.APPTYPE_ISIM;    break;
176             default:
177                 newType = AppType.APPTYPE_UNKNOWN;
178                 loge("AppTypeFromRILInt: bad RIL_AppType: " + type + " use APPTYPE_UNKNOWN");
179         }
180         return newType;
181     }
182 
AppStateFromRILInt(int state)183     public AppState AppStateFromRILInt(int state) {
184         AppState newState;
185         /* RIL_AppState ril.h */
186         switch(state) {
187             case 0: newState = AppState.APPSTATE_UNKNOWN;  break;
188             case 1: newState = AppState.APPSTATE_DETECTED; break;
189             case 2: newState = AppState.APPSTATE_PIN; break;
190             case 3: newState = AppState.APPSTATE_PUK; break;
191             case 4: newState = AppState.APPSTATE_SUBSCRIPTION_PERSO; break;
192             case 5: newState = AppState.APPSTATE_READY; break;
193             default:
194                 newState = AppState.APPSTATE_UNKNOWN;
195                 loge("AppStateFromRILInt: bad state: " + state + " use APPSTATE_UNKNOWN");
196         }
197         return newState;
198     }
199 
PersoSubstateFromRILInt(int substate)200     public PersoSubState PersoSubstateFromRILInt(int substate) {
201         PersoSubState newSubState;
202         /* RIL_PeroSubstate ril.h */
203         switch(substate) {
204             case 0:  newSubState = PersoSubState.PERSOSUBSTATE_UNKNOWN;  break;
205             case 1:  newSubState = PersoSubState.PERSOSUBSTATE_IN_PROGRESS; break;
206             case 2:  newSubState = PersoSubState.PERSOSUBSTATE_READY; break;
207             case 3:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK; break;
208             case 4:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_SUBSET; break;
209             case 5:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_CORPORATE; break;
210             case 6:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_SERVICE_PROVIDER; break;
211             case 7:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_SIM;  break;
212             case 8:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_PUK; break;
213             case 9:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK; break;
214             case 10: newSubState = PersoSubState.PERSOSUBSTATE_SIM_CORPORATE_PUK; break;
215             case 11: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK; break;
216             case 12: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SIM_PUK; break;
217             case 13: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK1; break;
218             case 14: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK2; break;
219             case 15: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_HRPD; break;
220             case 16: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_CORPORATE; break;
221             case 17: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_SERVICE_PROVIDER; break;
222             case 18: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_RUIM; break;
223             case 19: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK1_PUK; break;
224             case 20: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK2_PUK; break;
225             case 21: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_HRPD_PUK ; break;
226             case 22: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_CORPORATE_PUK; break;
227             case 23: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK; break;
228             case 24: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_RUIM_PUK; break;
229             case 25: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SPN; break;
230             case 26: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SPN_PUK; break;
231             case 27: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SP_EHPLMN; break;
232             case 28: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SP_EHPLMN_PUK; break;
233             case 29: newSubState = PersoSubState.PERSOSUBSTATE_SIM_ICCID; break;
234             case 30: newSubState = PersoSubState.PERSOSUBSTATE_SIM_ICCID_PUK; break;
235             case 31: newSubState = PersoSubState.PERSOSUBSTATE_SIM_IMPI; break;
236             case 32: newSubState = PersoSubState.PERSOSUBSTATE_SIM_IMPI_PUK; break;
237             case 33: newSubState = PersoSubState.PERSOSUBSTATE_SIM_NS_SP; break;
238             case 34: newSubState = PersoSubState.PERSOSUBSTATE_SIM_NS_SP_PUK; break;
239 
240             default:
241                 newSubState = PersoSubState.PERSOSUBSTATE_UNKNOWN;
242                 loge("PersoSubstateFromRILInt: bad substate: " + substate
243                         + " use PERSOSUBSTATE_UNKNOWN");
244         }
245         return newSubState;
246     }
247 
PinStateFromRILInt(int state)248     public PinState PinStateFromRILInt(int state) {
249         PinState newPinState;
250         switch(state) {
251             case 0:
252                 newPinState = PinState.PINSTATE_UNKNOWN;
253                 break;
254             case 1:
255                 newPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
256                 break;
257             case 2:
258                 newPinState = PinState.PINSTATE_ENABLED_VERIFIED;
259                 break;
260             case 3:
261                 newPinState = PinState.PINSTATE_DISABLED;
262                 break;
263             case 4:
264                 newPinState = PinState.PINSTATE_ENABLED_BLOCKED;
265                 break;
266             case 5:
267                 newPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
268                 break;
269             default:
270                 newPinState = PinState.PINSTATE_UNKNOWN;
271                 loge("PinStateFromRILInt: bad pin state: " + state + " use PINSTATE_UNKNOWN");
272         }
273         return newPinState;
274     }
275 
276     @Override
toString()277     public String toString() {
278         StringBuilder sb = new StringBuilder();
279 
280         sb.append("{").append(app_type).append(",").append(app_state);
281         if (app_state == AppState.APPSTATE_SUBSCRIPTION_PERSO) {
282             sb.append(",").append(perso_substate);
283         }
284         if (app_type == AppType.APPTYPE_CSIM ||
285                 app_type == AppType.APPTYPE_USIM ||
286                 app_type == AppType.APPTYPE_ISIM) {
287             sb.append(",pin1=").append(pin1);
288             sb.append(",pin2=").append(pin2);
289         }
290         sb.append("}");
291         return sb.toString();
292     }
293 
loge(String s)294     private void loge(String s) {
295         Rlog.e("IccCardApplicationStatus", s);
296     }
297 }
298