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