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    public 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    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        default:
80            throw new RuntimeException("Unrecognized RIL_CardState: " + state);
81        }
82    }
83
84    public void setUniversalPinState(int state) {
85        switch(state) {
86        case 0:
87            mUniversalPinState = PinState.PINSTATE_UNKNOWN;
88            break;
89        case 1:
90            mUniversalPinState = PinState.PINSTATE_ENABLED_NOT_VERIFIED;
91            break;
92        case 2:
93            mUniversalPinState = PinState.PINSTATE_ENABLED_VERIFIED;
94            break;
95        case 3:
96            mUniversalPinState = PinState.PINSTATE_DISABLED;
97            break;
98        case 4:
99            mUniversalPinState = PinState.PINSTATE_ENABLED_BLOCKED;
100            break;
101        case 5:
102            mUniversalPinState = PinState.PINSTATE_ENABLED_PERM_BLOCKED;
103            break;
104        default:
105            throw new RuntimeException("Unrecognized RIL_PinState: " + state);
106        }
107    }
108
109    @Override
110    public String toString() {
111        IccCardApplicationStatus app;
112
113        StringBuilder sb = new StringBuilder();
114        sb.append("IccCardState {").append(mCardState).append(",")
115        .append(mUniversalPinState)
116        .append(",num_apps=").append(mApplications.length)
117        .append(",gsm_id=").append(mGsmUmtsSubscriptionAppIndex);
118        if (mGsmUmtsSubscriptionAppIndex >=0
119                && mGsmUmtsSubscriptionAppIndex <CARD_MAX_APPS) {
120            app = mApplications[mGsmUmtsSubscriptionAppIndex];
121            sb.append(app == null ? "null" : app);
122        }
123
124        sb.append(",cmda_id=").append(mCdmaSubscriptionAppIndex);
125        if (mCdmaSubscriptionAppIndex >=0
126                && mCdmaSubscriptionAppIndex <CARD_MAX_APPS) {
127            app = mApplications[mCdmaSubscriptionAppIndex];
128            sb.append(app == null ? "null" : app);
129        }
130
131        sb.append(",ims_id=").append(mImsSubscriptionAppIndex);
132        if (mImsSubscriptionAppIndex >=0
133                && mImsSubscriptionAppIndex <CARD_MAX_APPS) {
134            app = mApplications[mImsSubscriptionAppIndex];
135            sb.append(app == null ? "null" : app);
136        }
137
138        sb.append("}");
139
140        return sb.toString();
141    }
142
143}
144