• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 import com.android.internal.telephony.uicc.IccCardStatus.PinState;
23 import com.android.telephony.Rlog;
24 
25 /**
26  * See also RIL_AppStatus in include/telephony/ril.h
27  *
28  * {@hide}
29  */
30 public class IccCardApplicationStatus {
31     // TODO: Replace with constants from PhoneConstants.APPTYPE_xxx
32     @UnsupportedAppUsage(implicitMember =
33             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$AppType;")
34     public enum AppType{
35         @UnsupportedAppUsage
36         APPTYPE_UNKNOWN,
37         @UnsupportedAppUsage
38         APPTYPE_SIM,
39         @UnsupportedAppUsage
40         APPTYPE_USIM,
41         @UnsupportedAppUsage
42         APPTYPE_RUIM,
43         @UnsupportedAppUsage
44         APPTYPE_CSIM,
45         @UnsupportedAppUsage
46         APPTYPE_ISIM
47     }
48 
49     @UnsupportedAppUsage(implicitMember =
50             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$AppState;")
51     public enum AppState{
52         @UnsupportedAppUsage
53         APPSTATE_UNKNOWN,
54         @UnsupportedAppUsage
55         APPSTATE_DETECTED,
56         @UnsupportedAppUsage
57         APPSTATE_PIN,
58         @UnsupportedAppUsage
59         APPSTATE_PUK,
60         @UnsupportedAppUsage
61         APPSTATE_SUBSCRIPTION_PERSO,
62         @UnsupportedAppUsage
63         APPSTATE_READY;
64 
isPinRequired()65         boolean isPinRequired() {
66             return this == APPSTATE_PIN;
67         }
68 
isPukRequired()69         boolean isPukRequired() {
70             return this == APPSTATE_PUK;
71         }
72 
isSubscriptionPersoEnabled()73         boolean isSubscriptionPersoEnabled() {
74             return this == APPSTATE_SUBSCRIPTION_PERSO;
75         }
76 
isAppReady()77         boolean isAppReady() {
78             return this == APPSTATE_READY;
79         }
80 
isAppNotReady()81         boolean isAppNotReady() {
82             return this == APPSTATE_UNKNOWN  ||
83                    this == APPSTATE_DETECTED;
84         }
85     }
86 
87     @UnsupportedAppUsage(implicitMember =
88             "values()[Lcom/android/internal/telephony/uicc/IccCardApplicationStatus$PersoSubState;")
89     public enum PersoSubState {
90         @UnsupportedAppUsage
91         PERSOSUBSTATE_UNKNOWN,
92         PERSOSUBSTATE_IN_PROGRESS,
93         PERSOSUBSTATE_READY,
94         @UnsupportedAppUsage
95         PERSOSUBSTATE_SIM_NETWORK,
96         @UnsupportedAppUsage
97         PERSOSUBSTATE_SIM_NETWORK_SUBSET,
98         PERSOSUBSTATE_SIM_CORPORATE,
99         @UnsupportedAppUsage
100         PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
101         PERSOSUBSTATE_SIM_SIM,
102         PERSOSUBSTATE_SIM_NETWORK_PUK,
103         @UnsupportedAppUsage
104         PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK,
105         PERSOSUBSTATE_SIM_CORPORATE_PUK,
106         @UnsupportedAppUsage
107         PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
108         PERSOSUBSTATE_SIM_SIM_PUK,
109         PERSOSUBSTATE_RUIM_NETWORK1,
110         PERSOSUBSTATE_RUIM_NETWORK2,
111         PERSOSUBSTATE_RUIM_HRPD,
112         PERSOSUBSTATE_RUIM_CORPORATE,
113         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER,
114         PERSOSUBSTATE_RUIM_RUIM,
115         PERSOSUBSTATE_RUIM_NETWORK1_PUK,
116         PERSOSUBSTATE_RUIM_NETWORK2_PUK,
117         PERSOSUBSTATE_RUIM_HRPD_PUK,
118         PERSOSUBSTATE_RUIM_CORPORATE_PUK,
119         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK,
120         PERSOSUBSTATE_RUIM_RUIM_PUK,
121         PERSOSUBSTATE_SIM_SPN,
122         PERSOSUBSTATE_SIM_SPN_PUK,
123         PERSOSUBSTATE_SIM_SP_EHPLMN,
124         PERSOSUBSTATE_SIM_SP_EHPLMN_PUK,
125         PERSOSUBSTATE_SIM_ICCID,
126         PERSOSUBSTATE_SIM_ICCID_PUK,
127         PERSOSUBSTATE_SIM_IMPI,
128         PERSOSUBSTATE_SIM_IMPI_PUK,
129         PERSOSUBSTATE_SIM_NS_SP,
130         PERSOSUBSTATE_SIM_NS_SP_PUK;
131 
isPersoSubStateUnknown()132         boolean isPersoSubStateUnknown() {
133             return this == PERSOSUBSTATE_UNKNOWN;
134         }
135 
isPersoLocked(PersoSubState mState)136         public static boolean isPersoLocked(PersoSubState mState) {
137             switch (mState) {
138                 case PERSOSUBSTATE_UNKNOWN:
139                 case PERSOSUBSTATE_IN_PROGRESS:
140                 case PERSOSUBSTATE_READY:
141                     return false;
142                 default:
143                     return true;
144             }
145         }
146     }
147 
148     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
149     public AppType        app_type;
150     public AppState       app_state;
151     // applicable only if app_state == RIL_APPSTATE_SUBSCRIPTION_PERSO
152     public PersoSubState  perso_substate;
153     // null terminated string, e.g., from 0xA0, 0x00 -> 0x41, 0x30, 0x30, 0x30 */
154     public String         aid;
155     // null terminated string
156     public String         app_label;
157     // applicable to USIM and CSIM
158     public int            pin1_replaced;
159     public PinState       pin1;
160     public PinState       pin2;
161 
162     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
IccCardApplicationStatus()163     public IccCardApplicationStatus() {
164     }
165 
166     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
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