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.telephony.Rlog;
20 
21 import com.android.internal.telephony.uicc.IccCardStatus.PinState;
22 
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     public enum AppType{
32         APPTYPE_UNKNOWN,
33         APPTYPE_SIM,
34         APPTYPE_USIM,
35         APPTYPE_RUIM,
36         APPTYPE_CSIM,
37         APPTYPE_ISIM
38     }
39 
40     public enum AppState{
41         APPSTATE_UNKNOWN,
42         APPSTATE_DETECTED,
43         APPSTATE_PIN,
44         APPSTATE_PUK,
45         APPSTATE_SUBSCRIPTION_PERSO,
46         APPSTATE_READY;
47 
isPinRequired()48         boolean isPinRequired() {
49             return this == APPSTATE_PIN;
50         }
51 
isPukRequired()52         boolean isPukRequired() {
53             return this == APPSTATE_PUK;
54         }
55 
isSubscriptionPersoEnabled()56         boolean isSubscriptionPersoEnabled() {
57             return this == APPSTATE_SUBSCRIPTION_PERSO;
58         }
59 
isAppReady()60         boolean isAppReady() {
61             return this == APPSTATE_READY;
62         }
63 
isAppNotReady()64         boolean isAppNotReady() {
65             return this == APPSTATE_UNKNOWN  ||
66                    this == APPSTATE_DETECTED;
67         }
68     }
69 
70     public enum PersoSubState{
71         PERSOSUBSTATE_UNKNOWN,
72         PERSOSUBSTATE_IN_PROGRESS,
73         PERSOSUBSTATE_READY,
74         PERSOSUBSTATE_SIM_NETWORK,
75         PERSOSUBSTATE_SIM_NETWORK_SUBSET,
76         PERSOSUBSTATE_SIM_CORPORATE,
77         PERSOSUBSTATE_SIM_SERVICE_PROVIDER,
78         PERSOSUBSTATE_SIM_SIM,
79         PERSOSUBSTATE_SIM_NETWORK_PUK,
80         PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK,
81         PERSOSUBSTATE_SIM_CORPORATE_PUK,
82         PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK,
83         PERSOSUBSTATE_SIM_SIM_PUK,
84         PERSOSUBSTATE_RUIM_NETWORK1,
85         PERSOSUBSTATE_RUIM_NETWORK2,
86         PERSOSUBSTATE_RUIM_HRPD,
87         PERSOSUBSTATE_RUIM_CORPORATE,
88         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER,
89         PERSOSUBSTATE_RUIM_RUIM,
90         PERSOSUBSTATE_RUIM_NETWORK1_PUK,
91         PERSOSUBSTATE_RUIM_NETWORK2_PUK,
92         PERSOSUBSTATE_RUIM_HRPD_PUK,
93         PERSOSUBSTATE_RUIM_CORPORATE_PUK,
94         PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK,
95         PERSOSUBSTATE_RUIM_RUIM_PUK;
96 
isPersoSubStateUnknown()97         boolean isPersoSubStateUnknown() {
98             return this == PERSOSUBSTATE_UNKNOWN;
99         }
100     }
101 
102     public AppType        app_type;
103     public AppState       app_state;
104     // applicable only if app_state == RIL_APPSTATE_SUBSCRIPTION_PERSO
105     public PersoSubState  perso_substate;
106     // null terminated string, e.g., from 0xA0, 0x00 -> 0x41, 0x30, 0x30, 0x30 */
107     public String         aid;
108     // null terminated string
109     public String         app_label;
110     // applicable to USIM and CSIM
111     public int            pin1_replaced;
112     public PinState       pin1;
113     public PinState       pin2;
114 
AppTypeFromRILInt(int type)115     public AppType AppTypeFromRILInt(int type) {
116         AppType newType;
117         /* RIL_AppType ril.h */
118         switch(type) {
119             case 0: newType = AppType.APPTYPE_UNKNOWN; break;
120             case 1: newType = AppType.APPTYPE_SIM;     break;
121             case 2: newType = AppType.APPTYPE_USIM;    break;
122             case 3: newType = AppType.APPTYPE_RUIM;    break;
123             case 4: newType = AppType.APPTYPE_CSIM;    break;
124             case 5: newType = AppType.APPTYPE_ISIM;    break;
125             default:
126                 newType = AppType.APPTYPE_UNKNOWN;
127                 loge("AppTypeFromRILInt: bad RIL_AppType: " + type + " use APPTYPE_UNKNOWN");
128         }
129         return newType;
130     }
131 
AppStateFromRILInt(int state)132     public AppState AppStateFromRILInt(int state) {
133         AppState newState;
134         /* RIL_AppState ril.h */
135         switch(state) {
136             case 0: newState = AppState.APPSTATE_UNKNOWN;  break;
137             case 1: newState = AppState.APPSTATE_DETECTED; break;
138             case 2: newState = AppState.APPSTATE_PIN; break;
139             case 3: newState = AppState.APPSTATE_PUK; break;
140             case 4: newState = AppState.APPSTATE_SUBSCRIPTION_PERSO; break;
141             case 5: newState = AppState.APPSTATE_READY; break;
142             default:
143                 newState = AppState.APPSTATE_UNKNOWN;
144                 loge("AppStateFromRILInt: bad state: " + state + " use APPSTATE_UNKNOWN");
145         }
146         return newState;
147     }
148 
PersoSubstateFromRILInt(int substate)149     public PersoSubState PersoSubstateFromRILInt(int substate) {
150         PersoSubState newSubState;
151         /* RIL_PeroSubstate ril.h */
152         switch(substate) {
153             case 0:  newSubState = PersoSubState.PERSOSUBSTATE_UNKNOWN;  break;
154             case 1:  newSubState = PersoSubState.PERSOSUBSTATE_IN_PROGRESS; break;
155             case 2:  newSubState = PersoSubState.PERSOSUBSTATE_READY; break;
156             case 3:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK; break;
157             case 4:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_SUBSET; break;
158             case 5:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_CORPORATE; break;
159             case 6:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_SERVICE_PROVIDER; break;
160             case 7:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_SIM;  break;
161             case 8:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_PUK; break;
162             case 9:  newSubState = PersoSubState.PERSOSUBSTATE_SIM_NETWORK_SUBSET_PUK; break;
163             case 10: newSubState = PersoSubState.PERSOSUBSTATE_SIM_CORPORATE_PUK; break;
164             case 11: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SERVICE_PROVIDER_PUK; break;
165             case 12: newSubState = PersoSubState.PERSOSUBSTATE_SIM_SIM_PUK; break;
166             case 13: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK1; break;
167             case 14: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK2; break;
168             case 15: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_HRPD; break;
169             case 16: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_CORPORATE; break;
170             case 17: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_SERVICE_PROVIDER; break;
171             case 18: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_RUIM; break;
172             case 19: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK1_PUK; break;
173             case 20: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_NETWORK2_PUK; break;
174             case 21: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_HRPD_PUK ; break;
175             case 22: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_CORPORATE_PUK; break;
176             case 23: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_SERVICE_PROVIDER_PUK; break;
177             case 24: newSubState = PersoSubState.PERSOSUBSTATE_RUIM_RUIM_PUK; break;
178             default:
179                 newSubState = PersoSubState.PERSOSUBSTATE_UNKNOWN;
180                 loge("PersoSubstateFromRILInt: bad substate: " + substate
181                         + " use PERSOSUBSTATE_UNKNOWN");
182         }
183         return newSubState;
184     }
185 
PinStateFromRILInt(int state)186     public PinState PinStateFromRILInt(int state) {
187         PinState newPinState;
188         switch(state) {
189             case 0:
190                 newPinState = PinState.PINSTATE_UNKNOWN;
191                 break;
192             case 1:
193                 newPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
194                 break;
195             case 2:
196                 newPinState = PinState.PINSTATE_ENABLED_VERIFIED;
197                 break;
198             case 3:
199                 newPinState = PinState.PINSTATE_DISABLED;
200                 break;
201             case 4:
202                 newPinState = PinState.PINSTATE_ENABLED_BLOCKED;
203                 break;
204             case 5:
205                 newPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
206                 break;
207             default:
208                 newPinState = PinState.PINSTATE_UNKNOWN;
209                 loge("PinStateFromRILInt: bad pin state: " + state + " use PINSTATE_UNKNOWN");
210         }
211         return newPinState;
212     }
213 
214     @Override
toString()215     public String toString() {
216         StringBuilder sb = new StringBuilder();
217 
218         sb.append("{").append(app_type).append(",").append(app_state);
219         if (app_state == AppState.APPSTATE_SUBSCRIPTION_PERSO) {
220             sb.append(",").append(perso_substate);
221         }
222         if (app_type == AppType.APPTYPE_CSIM ||
223                 app_type == AppType.APPTYPE_USIM ||
224                 app_type == AppType.APPTYPE_ISIM) {
225             sb.append(",pin1=").append(pin1);
226             sb.append(",pin2=").append(pin2);
227         }
228         sb.append("}");
229         return sb.toString();
230     }
231 
loge(String s)232     private void loge(String s) {
233         Rlog.e("IccCardApplicationStatus", s);
234     }
235 }
236