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 java.util.ArrayList;
     20 
     21 /**
     22  * See also RIL_CardStatus in include/telephony/ril.h
     23  *
     24  * {@hide}
     25  */
     26 public class IccCardStatus {
     27     static final int CARD_MAX_APPS = 8;
     28 
     29     public enum CardState {
     30         CARDSTATE_ABSENT,
     31         CARDSTATE_PRESENT,
     32         CARDSTATE_ERROR;
     33 
     34         boolean isCardPresent() {
     35             return this == CARDSTATE_PRESENT;
     36         }
     37     }
     38 
     39     public enum PinState {
     40         PINSTATE_UNKNOWN,
     41         PINSTATE_ENABLED_NOT_VERIFIED,
     42         PINSTATE_ENABLED_VERIFIED,
     43         PINSTATE_DISABLED,
     44         PINSTATE_ENABLED_BLOCKED,
     45         PINSTATE_ENABLED_PERM_BLOCKED;
     46 
     47         boolean isPermBlocked() {
     48             return this == PINSTATE_ENABLED_PERM_BLOCKED;
     49         }
     50 
     51         boolean isPinRequired() {
     52             return this == PINSTATE_ENABLED_NOT_VERIFIED;
     53         }
     54 
     55         boolean isPukRequired() {
     56             return this == PINSTATE_ENABLED_BLOCKED;
     57         }
     58     }
     59 
     60     private CardState  mCardState;
     61     private PinState   mUniversalPinState;
     62     private int        mGsmUmtsSubscriptionAppIndex;
     63     private int        mCdmaSubscriptionAppIndex;
     64     private int        mImsSubscriptionAppIndex;
     65     private int        mNumApplications;
     66 
     67     private ArrayList<IccCardApplication> mApplications =
     68             new ArrayList<IccCardApplication>(CARD_MAX_APPS);
     69 
     70     public CardState getCardState() {
     71         return mCardState;
     72     }
     73 
     74     public void setCardState(int state) {
     75         switch(state) {
     76         case 0:
     77             mCardState = CardState.CARDSTATE_ABSENT;
     78             break;
     79         case 1:
     80             mCardState = CardState.CARDSTATE_PRESENT;
     81             break;
     82         case 2:
     83             mCardState = CardState.CARDSTATE_ERROR;
     84             break;
     85         default:
     86             throw new RuntimeException("Unrecognized RIL_CardState: " + state);
     87         }
     88     }
     89 
     90     public PinState getUniversalPinState() {
     91         return mUniversalPinState;
     92     }
     93 
     94     public void setUniversalPinState(int state) {
     95         switch(state) {
     96         case 0:
     97             mUniversalPinState = PinState.PINSTATE_UNKNOWN;
     98             break;
     99         case 1:
    100             mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
    101             break;
    102         case 2:
    103             mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
    104             break;
    105         case 3:
    106             mUniversalPinState = PinState.PINSTATE_DISABLED;
    107             break;
    108         case 4:
    109             mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
    110             break;
    111         case 5:
    112             mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
    113             break;
    114         default:
    115             throw new RuntimeException("Unrecognized RIL_PinState: " + state);
    116         }
    117     }
    118 
    119     public int getGsmUmtsSubscriptionAppIndex() {
    120         return mGsmUmtsSubscriptionAppIndex;
    121     }
    122 
    123     public void setGsmUmtsSubscriptionAppIndex(int gsmUmtsSubscriptionAppIndex) {
    124         mGsmUmtsSubscriptionAppIndex = gsmUmtsSubscriptionAppIndex;
    125     }
    126 
    127     public int getCdmaSubscriptionAppIndex() {
    128         return mCdmaSubscriptionAppIndex;
    129     }
    130 
    131     public void setCdmaSubscriptionAppIndex(int cdmaSubscriptionAppIndex) {
    132         mCdmaSubscriptionAppIndex = cdmaSubscriptionAppIndex;
    133     }
    134 
    135     public int getImsSubscriptionAppIndex() {
    136         return mImsSubscriptionAppIndex;
    137     }
    138 
    139     public void setImsSubscriptionAppIndex(int imsSubscriptionAppIndex) {
    140         mImsSubscriptionAppIndex = imsSubscriptionAppIndex;
    141     }
    142 
    143     public int getNumApplications() {
    144         return mNumApplications;
    145     }
    146 
    147     public void setNumApplications(int numApplications) {
    148         mNumApplications = numApplications;
    149     }
    150 
    151     public void addApplication(IccCardApplication application) {
    152         mApplications.add(application);
    153     }
    154 
    155     public IccCardApplication getApplication(int index) {
    156         return mApplications.get(index);
    157     }
    158 
    159     @Override
    160     public String toString() {
    161         IccCardApplication app;
    162 
    163         StringBuilder sb = new StringBuilder();
    164         sb.append("IccCardState {").append(mCardState).append(",")
    165         .append(mUniversalPinState)
    166         .append(",num_apps=").append(mNumApplications)
    167         .append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
    168         if (mGsmUmtsSubscriptionAppIndex >=0
    169                 && mGsmUmtsSubscriptionAppIndex <CARD_MAX_APPS) {
    170             app = getApplication(mGsmUmtsSubscriptionAppIndex);
    171             sb.append(app == null ? "null" : app);
    172         }
    173 
    174         sb.append(",cmda_id=").append(mCdmaSubscriptionAppIndex);
    175         if (mCdmaSubscriptionAppIndex >=0
    176                 && mCdmaSubscriptionAppIndex <CARD_MAX_APPS) {
    177             app = getApplication(mCdmaSubscriptionAppIndex);
    178             sb.append(app == null ? "null" : app);
    179         }
    180 
    181         sb.append(",ism_id=").append(mImsSubscriptionAppIndex);
    182 
    183         sb.append("}");
    184 
    185         return sb.toString();
    186     }
    187 
    188 }
    189