UiccController.java revision 0825495a331bb44df395a0cdb79fab85e68db5d5
1/*
2 * Copyright (C) 2011 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
19import com.android.internal.telephony.IccCard;
20import com.android.internal.telephony.PhoneBase;
21import com.android.internal.telephony.cdma.CDMALTEPhone;
22import com.android.internal.telephony.cdma.CDMAPhone;
23import com.android.internal.telephony.gsm.GSMPhone;
24
25import android.util.Log;
26
27/* This class is responsible for keeping all knowledge about
28 * ICCs in the system. It is also used as API to get appropriate
29 * applications to pass them to phone and service trackers.
30 */
31public class UiccController {
32    private static final boolean DBG = true;
33    private static final String LOG_TAG = "RIL_UiccController";
34
35    private static UiccController mInstance;
36
37    private PhoneBase mCurrentPhone;
38    private boolean mIsCurrentCard3gpp;
39    private IccCard mIccCard;
40
41    public static synchronized UiccController getInstance(PhoneBase phone) {
42        if (mInstance == null) {
43            mInstance = new UiccController(phone);
44        } else {
45            mInstance.setNewPhone(phone);
46        }
47        return mInstance;
48    }
49
50    public IccCard getIccCard() {
51        return mIccCard;
52    }
53
54    private UiccController(PhoneBase phone) {
55        if (DBG) log("Creating UiccController");
56        setNewPhone(phone);
57    }
58
59    private void setNewPhone(PhoneBase phone) {
60        mCurrentPhone = phone;
61        if (phone instanceof GSMPhone) {
62            if (DBG) log("New phone is GSMPhone");
63            updateCurrentCard(IccCard.CARD_IS_3GPP);
64        } else if (phone instanceof CDMALTEPhone){
65            if (DBG) log("New phone type is CDMALTEPhone");
66            updateCurrentCard(IccCard.CARD_IS_3GPP);
67        } else if (phone instanceof CDMAPhone){
68            if (DBG) log("New phone type is CDMAPhone");
69            updateCurrentCard(IccCard.CARD_IS_NOT_3GPP);
70        } else {
71            Log.e(LOG_TAG, "Unhandled phone type. Critical error!");
72        }
73    }
74
75    private void updateCurrentCard(boolean isNewCard3gpp) {
76        if (mIsCurrentCard3gpp == isNewCard3gpp && mIccCard != null) {
77            return;
78        }
79
80        if (mIccCard != null) {
81            mIccCard.dispose();
82            mIccCard = null;
83        }
84
85        mIsCurrentCard3gpp = isNewCard3gpp;
86        mIccCard = new IccCard(mCurrentPhone, mCurrentPhone.getPhoneName(),
87                isNewCard3gpp, DBG);
88    }
89
90    private void log(String string) {
91        Log.d(LOG_TAG, string);
92    }
93}