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