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
17package com.android.internal.telephony;
18
19import java.util.ArrayList;
20
21/**
22 * See also RIL_CardStatus in include/telephony/ril.h
23 *
24 * {@hide}
25 */
26public 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
48    private CardState  mCardState;
49    private PinState   mUniversalPinState;
50    private int        mGsmUmtsSubscriptionAppIndex;
51    private int        mCdmaSubscriptionAppIndex;
52    private int        mNumApplications;
53
54    private ArrayList<IccCardApplication> mApplications =
55            new ArrayList<IccCardApplication>(CARD_MAX_APPS);
56
57    public CardState getCardState() {
58        return mCardState;
59    }
60
61    public void setCardState(int state) {
62        switch(state) {
63        case 0:
64            mCardState = CardState.CARDSTATE_ABSENT;
65            break;
66        case 1:
67            mCardState = CardState.CARDSTATE_PRESENT;
68            break;
69        case 2:
70            mCardState = CardState.CARDSTATE_ERROR;
71            break;
72        default:
73            throw new RuntimeException("Unrecognized RIL_CardState: " + state);
74        }
75    }
76
77    public void setUniversalPinState(int state) {
78        switch(state) {
79        case 0:
80            mUniversalPinState = PinState.PINSTATE_UNKNOWN;
81            break;
82        case 1:
83            mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
84            break;
85        case 2:
86            mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
87            break;
88        case 3:
89            mUniversalPinState = PinState.PINSTATE_DISABLED;
90            break;
91        case 4:
92            mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
93            break;
94        case 5:
95            mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
96            break;
97        default:
98            throw new RuntimeException("Unrecognized RIL_PinState: " + state);
99        }
100    }
101
102    public int getGsmUmtsSubscriptionAppIndex() {
103        return mGsmUmtsSubscriptionAppIndex;
104    }
105
106    public void setGsmUmtsSubscriptionAppIndex(int gsmUmtsSubscriptionAppIndex) {
107        mGsmUmtsSubscriptionAppIndex = gsmUmtsSubscriptionAppIndex;
108    }
109
110    public int getCdmaSubscriptionAppIndex() {
111        return mCdmaSubscriptionAppIndex;
112    }
113
114    public void setCdmaSubscriptionAppIndex(int cdmaSubscriptionAppIndex) {
115        mCdmaSubscriptionAppIndex = cdmaSubscriptionAppIndex;
116    }
117
118    public int getNumApplications() {
119        return mNumApplications;
120    }
121
122    public void setNumApplications(int numApplications) {
123        mNumApplications = numApplications;
124    }
125
126    public void addApplication(IccCardApplication application) {
127        mApplications.add(application);
128    }
129
130    public IccCardApplication getApplication(int index) {
131        return mApplications.get(index);
132    }
133}
134