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 /**
     20  * See also RIL_CardStatus in include/telephony/ril.h
     21  *
     22  * {@hide}
     23  */
     24 public class IccCardStatus {
     25     public static final int CARD_MAX_APPS = 8;
     26 
     27     public enum CardState {
     28         CARDSTATE_ABSENT,
     29         CARDSTATE_PRESENT,
     30         CARDSTATE_ERROR;
     31 
     32         boolean isCardPresent() {
     33             return this == CARDSTATE_PRESENT;
     34         }
     35     }
     36 
     37     public enum PinState {
     38         PINSTATE_UNKNOWN,
     39         PINSTATE_ENABLED_NOT_VERIFIED,
     40         PINSTATE_ENABLED_VERIFIED,
     41         PINSTATE_DISABLED,
     42         PINSTATE_ENABLED_BLOCKED,
     43         PINSTATE_ENABLED_PERM_BLOCKED;
     44 
     45         boolean isPermBlocked() {
     46             return this == PINSTATE_ENABLED_PERM_BLOCKED;
     47         }
     48 
     49         boolean isPinRequired() {
     50             return this == PINSTATE_ENABLED_NOT_VERIFIED;
     51         }
     52 
     53         boolean isPukRequired() {
     54             return this == PINSTATE_ENABLED_BLOCKED;
     55         }
     56     }
     57 
     58     public CardState  mCardState;
     59     public PinState   mUniversalPinState;
     60     public int        mGsmUmtsSubscriptionAppIndex;
     61     public int        mCdmaSubscriptionAppIndex;
     62     public int        mImsSubscriptionAppIndex;
     63 
     64     public IccCardApplicationStatus[] mApplications;
     65 
     66     public void setCardState(int state) {
     67         switch(state) {
     68         case 0:
     69             mCardState = CardState.CARDSTATE_ABSENT;
     70             break;
     71         case 1:
     72             mCardState = CardState.CARDSTATE_PRESENT;
     73             break;
     74         case 2:
     75             mCardState = CardState.CARDSTATE_ERROR;
     76             break;
     77         default:
     78             throw new RuntimeException("Unrecognized RIL_CardState: " + state);
     79         }
     80     }
     81 
     82     public void setUniversalPinState(int state) {
     83         switch(state) {
     84         case 0:
     85             mUniversalPinState = PinState.PINSTATE_UNKNOWN;
     86             break;
     87         case 1:
     88             mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
     89             break;
     90         case 2:
     91             mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
     92             break;
     93         case 3:
     94             mUniversalPinState = PinState.PINSTATE_DISABLED;
     95             break;
     96         case 4:
     97             mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
     98             break;
     99         case 5:
    100             mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
    101             break;
    102         default:
    103             throw new RuntimeException("Unrecognized RIL_PinState: " + state);
    104         }
    105     }
    106 
    107     @Override
    108     public String toString() {
    109         IccCardApplicationStatus app;
    110 
    111         StringBuilder sb = new StringBuilder();
    112         sb.append("IccCardState {").append(mCardState).append(",")
    113         .append(mUniversalPinState)
    114         .append(",num_apps=").append(mApplications.length)
    115         .append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
    116         if (mGsmUmtsSubscriptionAppIndex >=0
    117                 && mGsmUmtsSubscriptionAppIndex <CARD_MAX_APPS) {
    118             app = mApplications[mGsmUmtsSubscriptionAppIndex];
    119             sb.append(app == null ? "null" : app);
    120         }
    121 
    122         sb.append(",cmda_id=").append(mCdmaSubscriptionAppIndex);
    123         if (mCdmaSubscriptionAppIndex >=0
    124                 && mCdmaSubscriptionAppIndex <CARD_MAX_APPS) {
    125             app = mApplications[mCdmaSubscriptionAppIndex];
    126             sb.append(app == null ? "null" : app);
    127         }
    128 
    129         sb.append(",ims_id=").append(mImsSubscriptionAppIndex);
    130         if (mImsSubscriptionAppIndex >=0
    131                 && mImsSubscriptionAppIndex <CARD_MAX_APPS) {
    132             app = mApplications[mImsSubscriptionAppIndex];
    133             sb.append(app == null ? "null" : app);
    134         }
    135 
    136         sb.append("}");
    137 
    138         return sb.toString();
    139     }
    140 
    141 }
    142