OSDN Git Service

Remove redundent getCurrentCdmaDataConnectionState
[android-x86/frameworks-base.git] / telephony / java / com / android / internal / telephony / cdma / CDMALTEPhone.java
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.cdma;
18
19 import android.os.SystemProperties;
20 import android.content.Context;
21 import android.net.Uri;
22 import android.content.Context;
23 import android.provider.Telephony;
24 import android.content.ContentValues;
25 import android.database.SQLException;
26 import android.telephony.ServiceState;
27 import android.telephony.SignalStrength;
28
29 import com.android.internal.telephony.gsm.SIMRecords;
30 import com.android.internal.telephony.gsm.SimCard;
31 import com.android.internal.telephony.ServiceStateTracker;
32 import com.android.internal.telephony.DataConnectionTracker;
33 import com.android.internal.telephony.CommandsInterface;
34 import com.android.internal.telephony.Phone;
35 import com.android.internal.telephony.PhoneBase;
36 import com.android.internal.telephony.PhoneNotifier;
37 import com.android.internal.telephony.PhoneProxy;
38 import com.android.internal.telephony.IccCard;
39 import com.android.internal.telephony.gsm.GsmDataConnectionTracker;
40
41 import android.util.Log;
42
43 public class CDMALTEPhone extends CDMAPhone {
44     static final String LOG_TAG = "CDMA";
45
46     private static final boolean DBG = true;
47
48     // Constructors
49     public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) {
50         this(context, ci, notifier, false);
51     }
52
53     public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier,
54             boolean unitTestMode) {
55         super(context, ci, notifier, false);
56     }
57
58     @Override
59     protected void initSstIcc() {
60         mSST = new CdmaLteServiceStateTracker(this);
61         mIccRecords = new SIMRecords(this);
62         mIccCard = new SimCard(this, LOG_TAG, DBG);
63     }
64
65     @Override
66     public DataState getDataConnectionState(String apnType) {
67         // TODO: Remove instanceof if possible.
68         boolean isCdmaDataConnectionTracker = false;
69         if (mDataConnectionTracker instanceof CdmaDataConnectionTracker) {
70             log("getDataConnectionState isCdmaDataConnectionTracker");
71             isCdmaDataConnectionTracker = true;
72         } else {
73             log("getDataConnectionState NOT CdmaDataConnectionTracker");
74         }
75         DataState ret = DataState.DISCONNECTED;
76
77         if (!isCdmaDataConnectionTracker && (SystemProperties.get("adb.connected", "").length()
78                 > 0)) {
79             // We're connected to an ADB host and we have USB networking
80             // turned on. No matter what the radio state is,
81             // we report data connected
82
83             ret = DataState.CONNECTED;
84         } else if (mSST == null) {
85             // Radio Technology Change is ongoning, dispose() and
86             // removeReferences() have
87             // already been called
88
89             ret = DataState.DISCONNECTED;
90         } else if (mSST.getCurrentDataConnectionState() != ServiceState.STATE_IN_SERVICE) {
91             // If we're out of service, open TCP sockets may still work
92             // but no data will flow
93             ret = DataState.DISCONNECTED;
94         } else if (mDataConnectionTracker.isApnTypeEnabled(apnType) == false) {
95             ret = DataState.DISCONNECTED;
96         } else {
97             switch (mDataConnectionTracker.getState(apnType)) {
98                 case FAILED:
99                 case IDLE:
100                     ret = DataState.DISCONNECTED;
101                     break;
102
103                 case CONNECTED:
104                 case DISCONNECTING:
105                     if (mCT.state != Phone.State.IDLE && !mSST.isConcurrentVoiceAndDataAllowed()) {
106                         ret = DataState.SUSPENDED;
107                     } else {
108                         ret = DataState.CONNECTED;
109                     }
110                     break;
111
112                 case INITING:
113                 case CONNECTING:
114                 case SCANNING:
115                     ret = DataState.CONNECTING;
116                     break;
117             }
118         }
119
120         log("getDataConnectionState apnType=" + apnType + " ret=" + ret);
121         return ret;
122     }
123
124     public boolean updateCurrentCarrierInProvider() {
125         if (mIccRecords != null) {
126             try {
127                 Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current");
128                 ContentValues map = new ContentValues();
129                 map.put(Telephony.Carriers.NUMERIC, mIccRecords.getOperatorNumeric());
130                 log("updateCurrentCarrierInProvider insert uri=" + uri);
131                 mContext.getContentResolver().insert(uri, map);
132                 return true;
133             } catch (SQLException e) {
134                 Log.e(LOG_TAG, "[CDMALTEPhone] Can't store current operator ret false", e);
135             }
136         } else {
137             log("updateCurrentCarrierInProvider mIccRecords == null ret false");
138         }
139         return false;
140     }
141
142     @Override
143     protected void log(String s) {
144         if (DBG)
145             Log.d(LOG_TAG, "[CDMALTEPhone] " + s);
146     }
147 }