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