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.uicc;
18
19/**
20 * See also RIL_CardStatus in include/telephony/ril.h
21 *
22 * {@hide}
23 */
24public 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        CARDSTATE_RESTRICTED;
32
33        boolean isCardPresent() {
34            return this == CARDSTATE_PRESENT ||
35                this == CARDSTATE_RESTRICTED;
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    public CardState  mCardState;
61    public PinState   mUniversalPinState;
62    public int        mGsmUmtsSubscriptionAppIndex;
63    public int        mCdmaSubscriptionAppIndex;
64    public int        mImsSubscriptionAppIndex;
65
66    public IccCardApplicationStatus[] mApplications;
67
68    public void setCardState(int state) {
69        switch(state) {
70        case 0:
71            mCardState = CardState.CARDSTATE_ABSENT;
72            break;
73        case 1:
74            mCardState = CardState.CARDSTATE_PRESENT;
75            break;
76        case 2:
77            mCardState = CardState.CARDSTATE_ERROR;
78            break;
79        case 3:
80            mCardState = CardState.CARDSTATE_RESTRICTED;
81            break;
82        default:
83            throw new RuntimeException("Unrecognized RIL_CardState: " + state);
84        }
85    }
86
87    public void setUniversalPinState(int state) {
88        switch(state) {
89        case 0:
90            mUniversalPinState = PinState.PINSTATE_UNKNOWN;
91            break;
92        case 1:
93            mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
94            break;
95        case 2:
96            mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
97            break;
98        case 3:
99            mUniversalPinState = PinState.PINSTATE_DISABLED;
100            break;
101        case 4:
102            mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
103            break;
104        case 5:
105            mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
106            break;
107        default:
108            throw new RuntimeException("Unrecognized RIL_PinState: " + state);
109        }
110    }
111
112    @Override
113    public String toString() {
114        IccCardApplicationStatus app;
115
116        StringBuilder sb = new StringBuilder();
117        sb.append("IccCardState {").append(mCardState).append(",")
118        .append(mUniversalPinState)
119        .append(",num_apps=").append(mApplications.length)
120        .append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
121        if (mGsmUmtsSubscriptionAppIndex >=0
122                && mGsmUmtsSubscriptionAppIndex <CARD_MAX_APPS) {
123            app = mApplications[mGsmUmtsSubscriptionAppIndex];
124            sb.append(app == null ? "null" : app);
125        }
126
127        sb.append(",cdma_id=").append(mCdmaSubscriptionAppIndex);
128        if (mCdmaSubscriptionAppIndex >=0
129                && mCdmaSubscriptionAppIndex <CARD_MAX_APPS) {
130            app = mApplications[mCdmaSubscriptionAppIndex];
131            sb.append(app == null ? "null" : app);
132        }
133
134        sb.append(",ims_id=").append(mImsSubscriptionAppIndex);
135        if (mImsSubscriptionAppIndex >=0
136                && mImsSubscriptionAppIndex <CARD_MAX_APPS) {
137            app = mApplications[mImsSubscriptionAppIndex];
138            sb.append(app == null ? "null" : app);
139        }
140
141        sb.append("}");
142
143        return sb.toString();
144    }
145
146}
147