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