The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 android.net; |
| 18 | |
| 19 | import android.content.BroadcastReceiver; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.IntentFilter; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 23 | import android.net.NetworkInfo.DetailedState; |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 26 | import android.os.Looper; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 27 | import android.os.Message; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 28 | import android.os.Messenger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.os.RemoteException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.ServiceManager; |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 31 | import android.telephony.PhoneStateListener; |
| 32 | import android.telephony.SignalStrength; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 33 | import android.telephony.TelephonyManager; |
| 34 | import android.text.TextUtils; |
| 35 | import android.util.Slog; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 36 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 37 | import com.android.internal.telephony.DctConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import com.android.internal.telephony.ITelephony; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 39 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import com.android.internal.telephony.TelephonyIntents; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 41 | import com.android.internal.util.AsyncChannel; |
| 42 | |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 43 | import java.io.CharArrayWriter; |
| 44 | import java.io.PrintWriter; |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 45 | import java.util.concurrent.atomic.AtomicBoolean; |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Track the state of mobile data connectivity. This is done by |
| 49 | * receiving broadcast intents from the Phone process whenever |
| 50 | * the state of data connectivity changes. |
| 51 | * |
| 52 | * {@hide} |
| 53 | */ |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 54 | public class MobileDataStateTracker extends BaseNetworkStateTracker { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| 56 | private static final String TAG = "MobileDataStateTracker"; |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 57 | private static final boolean DBG = true; |
Wink Saville | 1aef7fc | 2013-07-31 15:49:04 -0700 | [diff] [blame] | 58 | private static final boolean VDBG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 60 | private PhoneConstants.DataState mMobileDataState; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | private ITelephony mPhoneService; |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 62 | |
| 63 | private String mApnType; |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 64 | private NetworkInfo mNetworkInfo; |
| 65 | private boolean mTeardownRequested = false; |
| 66 | private Handler mTarget; |
| 67 | private Context mContext; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 68 | private LinkProperties mLinkProperties; |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 69 | private LinkCapabilities mLinkCapabilities; |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 70 | private boolean mPrivateDnsRouteSet = false; |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 71 | private boolean mDefaultRouteSet = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 73 | // NOTE: these are only kept for debugging output; actual values are |
| 74 | // maintained in DataConnectionTracker. |
| 75 | protected boolean mUserDataEnabled = true; |
| 76 | protected boolean mPolicyDataEnabled = true; |
| 77 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 78 | private Handler mHandler; |
| 79 | private AsyncChannel mDataConnectionTrackerAc; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 80 | |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 81 | private AtomicBoolean mIsCaptivePortal = new AtomicBoolean(false); |
| 82 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 83 | private SignalStrength mSignalStrength; |
| 84 | |
| 85 | private SamplingDataTracker mSamplingDataTracker = new SamplingDataTracker(); |
| 86 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 87 | private static final int UNKNOWN = LinkQualityInfo.UNKNOWN_INT; |
| 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | /** |
| 90 | * Create a new MobileDataStateTracker |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 91 | * @param netType the ConnectivityManager network type |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 92 | * @param tag the name of this network |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | */ |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 94 | public MobileDataStateTracker(int netType, String tag) { |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 95 | mNetworkInfo = new NetworkInfo(netType, |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 96 | TelephonyManager.getDefault().getNetworkType(), tag, |
| 97 | TelephonyManager.getDefault().getNetworkTypeName()); |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 98 | mApnType = networkTypeToApnType(netType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 102 | * Begin monitoring data connectivity. |
| 103 | * |
| 104 | * @param context is the current Android context |
| 105 | * @param target is the Hander to which to return the events. |
| 106 | */ |
| 107 | public void startMonitoring(Context context, Handler target) { |
| 108 | mTarget = target; |
| 109 | mContext = context; |
| 110 | |
Robert Greenwalt | 5a8921f | 2011-07-29 16:33:16 -0700 | [diff] [blame] | 111 | mHandler = new MdstHandler(target.getLooper(), this); |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 112 | |
Wink Saville | 30bf654 | 2010-09-03 10:28:57 -0700 | [diff] [blame] | 113 | IntentFilter filter = new IntentFilter(); |
| 114 | filter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 115 | filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN); |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 116 | filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED); |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 117 | |
| 118 | mContext.registerReceiver(new MobileDataStateReceiver(), filter); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 119 | mMobileDataState = PhoneConstants.DataState.DISCONNECTED; |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 120 | |
| 121 | TelephonyManager tm = (TelephonyManager)mContext.getSystemService( |
| 122 | Context.TELEPHONY_SERVICE); |
| 123 | tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); |
Wink Saville | c7a9834 | 2010-08-13 16:11:42 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 126 | private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { |
| 127 | @Override |
| 128 | public void onSignalStrengthsChanged(SignalStrength signalStrength) { |
| 129 | mSignalStrength = signalStrength; |
| 130 | } |
| 131 | }; |
| 132 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 133 | static class MdstHandler extends Handler { |
| 134 | private MobileDataStateTracker mMdst; |
| 135 | |
| 136 | MdstHandler(Looper looper, MobileDataStateTracker mdst) { |
| 137 | super(looper); |
| 138 | mMdst = mdst; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void handleMessage(Message msg) { |
| 143 | switch (msg.what) { |
| 144 | case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: |
| 145 | if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 146 | if (VDBG) { |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 147 | mMdst.log("MdstHandler connected"); |
| 148 | } |
| 149 | mMdst.mDataConnectionTrackerAc = (AsyncChannel) msg.obj; |
| 150 | } else { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 151 | if (VDBG) { |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 152 | mMdst.log("MdstHandler %s NOT connected error=" + msg.arg1); |
| 153 | } |
| 154 | } |
| 155 | break; |
| 156 | case AsyncChannel.CMD_CHANNEL_DISCONNECTED: |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 157 | if (VDBG) mMdst.log("Disconnected from DataStateTracker"); |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 158 | mMdst.mDataConnectionTrackerAc = null; |
| 159 | break; |
| 160 | default: { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 161 | if (VDBG) mMdst.log("Ignorning unknown message=" + msg); |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 168 | public boolean isPrivateDnsRouteSet() { |
| 169 | return mPrivateDnsRouteSet; |
| 170 | } |
| 171 | |
| 172 | public void privateDnsRouteSet(boolean enabled) { |
| 173 | mPrivateDnsRouteSet = enabled; |
| 174 | } |
| 175 | |
| 176 | public NetworkInfo getNetworkInfo() { |
| 177 | return mNetworkInfo; |
| 178 | } |
| 179 | |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 180 | public boolean isDefaultRouteSet() { |
| 181 | return mDefaultRouteSet; |
| 182 | } |
| 183 | |
| 184 | public void defaultRouteSet(boolean enabled) { |
| 185 | mDefaultRouteSet = enabled; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * This is not implemented. |
| 190 | */ |
| 191 | public void releaseWakeLock() { |
| 192 | } |
| 193 | |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 194 | private void updateLinkProperitesAndCapatilities(Intent intent) { |
| 195 | mLinkProperties = intent.getParcelableExtra( |
| 196 | PhoneConstants.DATA_LINK_PROPERTIES_KEY); |
| 197 | if (mLinkProperties == null) { |
| 198 | loge("CONNECTED event did not supply link properties."); |
| 199 | mLinkProperties = new LinkProperties(); |
| 200 | } |
sy.yun | 9d9b74a | 2013-09-02 05:24:09 +0900 | [diff] [blame] | 201 | mLinkProperties.setMtu(mContext.getResources().getInteger( |
| 202 | com.android.internal.R.integer.config_mobile_mtu)); |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 203 | mLinkCapabilities = intent.getParcelableExtra( |
| 204 | PhoneConstants.DATA_LINK_CAPABILITIES_KEY); |
| 205 | if (mLinkCapabilities == null) { |
| 206 | loge("CONNECTED event did not supply link capabilities."); |
| 207 | mLinkCapabilities = new LinkCapabilities(); |
| 208 | } |
| 209 | } |
| 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | private class MobileDataStateReceiver extends BroadcastReceiver { |
Wink Saville | 26f5a38 | 2010-11-24 16:44:29 -0800 | [diff] [blame] | 212 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | public void onReceive(Context context, Intent intent) { |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 214 | if (intent.getAction().equals(TelephonyIntents. |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 215 | ACTION_DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN)) { |
| 216 | String apnName = intent.getStringExtra(PhoneConstants.DATA_APN_KEY); |
| 217 | String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY); |
| 218 | if (!TextUtils.equals(mApnType, apnType)) { |
| 219 | return; |
| 220 | } |
| 221 | if (DBG) { |
| 222 | log("Broadcast received: " + intent.getAction() + " apnType=" + apnType |
| 223 | + " apnName=" + apnName); |
| 224 | } |
| 225 | |
| 226 | // Make us in the connecting state until we make a new TYPE_MOBILE_PROVISIONING |
| 227 | mMobileDataState = PhoneConstants.DataState.CONNECTING; |
| 228 | updateLinkProperitesAndCapatilities(intent); |
Wink Saville | 67c3821 | 2013-09-05 12:02:25 -0700 | [diff] [blame] | 229 | mNetworkInfo.setIsConnectedToProvisioningNetwork(true); |
| 230 | |
| 231 | // Change state to SUSPENDED so setDetailedState |
| 232 | // sends EVENT_STATE_CHANGED to connectivityService |
| 233 | setDetailedState(DetailedState.SUSPENDED, "", apnName); |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 234 | } else if (intent.getAction().equals(TelephonyIntents. |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 235 | ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 236 | String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY); |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 237 | if (VDBG) { |
| 238 | log(String.format("Broadcast received: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED" |
| 239 | + "mApnType=%s %s received apnType=%s", mApnType, |
| 240 | TextUtils.equals(apnType, mApnType) ? "==" : "!=", apnType)); |
| 241 | } |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 242 | if (!TextUtils.equals(apnType, mApnType)) { |
| 243 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
Wink Saville | 1e4f461 | 2013-09-21 09:01:19 -0700 | [diff] [blame] | 245 | // Assume this isn't a provisioning network. |
| 246 | mNetworkInfo.setIsConnectedToProvisioningNetwork(false); |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 247 | if (DBG) { |
| 248 | log("Broadcast received: " + intent.getAction() + " apnType=" + apnType); |
| 249 | } |
Robert Greenwalt | d14e176 | 2012-08-20 11:15:39 -0700 | [diff] [blame] | 250 | |
| 251 | int oldSubtype = mNetworkInfo.getSubtype(); |
| 252 | int newSubType = TelephonyManager.getDefault().getNetworkType(); |
| 253 | String subTypeName = TelephonyManager.getDefault().getNetworkTypeName(); |
| 254 | mNetworkInfo.setSubtype(newSubType, subTypeName); |
| 255 | if (newSubType != oldSubtype && mNetworkInfo.isConnected()) { |
| 256 | Message msg = mTarget.obtainMessage(EVENT_NETWORK_SUBTYPE_CHANGED, |
| 257 | oldSubtype, 0, mNetworkInfo); |
| 258 | msg.sendToTarget(); |
| 259 | } |
| 260 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 261 | PhoneConstants.DataState state = Enum.valueOf(PhoneConstants.DataState.class, |
| 262 | intent.getStringExtra(PhoneConstants.STATE_KEY)); |
| 263 | String reason = intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY); |
| 264 | String apnName = intent.getStringExtra(PhoneConstants.DATA_APN_KEY); |
| 265 | mNetworkInfo.setRoaming(intent.getBooleanExtra( |
| 266 | PhoneConstants.DATA_NETWORK_ROAMING_KEY, false)); |
Robert Greenwalt | 12e24ae | 2011-10-17 22:10:03 -0700 | [diff] [blame] | 267 | if (VDBG) { |
| 268 | log(mApnType + " setting isAvailable to " + |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 269 | intent.getBooleanExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY,false)); |
Robert Greenwalt | 12e24ae | 2011-10-17 22:10:03 -0700 | [diff] [blame] | 270 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 271 | mNetworkInfo.setIsAvailable(!intent.getBooleanExtra( |
| 272 | PhoneConstants.NETWORK_UNAVAILABLE_KEY, false)); |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 273 | |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 274 | if (DBG) { |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 275 | log("Received state=" + state + ", old=" + mMobileDataState + |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 276 | ", reason=" + (reason == null ? "(unspecified)" : reason)); |
| 277 | } |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 278 | if (mMobileDataState != state) { |
| 279 | mMobileDataState = state; |
| 280 | switch (state) { |
| 281 | case DISCONNECTED: |
| 282 | if(isTeardownRequested()) { |
| 283 | setTeardownRequested(false); |
| 284 | } |
| 285 | |
| 286 | setDetailedState(DetailedState.DISCONNECTED, reason, apnName); |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 287 | // can't do this here - ConnectivityService needs it to clear stuff |
| 288 | // it's ok though - just leave it to be refreshed next time |
| 289 | // we connect. |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 290 | //if (DBG) log("clearing mInterfaceName for "+ mApnType + |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 291 | // " as it DISCONNECTED"); |
| 292 | //mInterfaceName = null; |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 293 | break; |
| 294 | case CONNECTING: |
| 295 | setDetailedState(DetailedState.CONNECTING, reason, apnName); |
| 296 | break; |
| 297 | case SUSPENDED: |
| 298 | setDetailedState(DetailedState.SUSPENDED, reason, apnName); |
| 299 | break; |
| 300 | case CONNECTED: |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 301 | updateLinkProperitesAndCapatilities(intent); |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 302 | setDetailedState(DetailedState.CONNECTED, reason, apnName); |
| 303 | break; |
| 304 | } |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 305 | |
| 306 | if (VDBG) { |
| 307 | Slog.d(TAG, "TelephonyMgr.DataConnectionStateChanged"); |
| 308 | if (mNetworkInfo != null) { |
Jake Hamby | 8f9b33e | 2014-01-15 13:08:03 -0800 | [diff] [blame] | 309 | Slog.d(TAG, "NetworkInfo = " + mNetworkInfo); |
| 310 | Slog.d(TAG, "subType = " + mNetworkInfo.getSubtype()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 311 | Slog.d(TAG, "subType = " + mNetworkInfo.getSubtypeName()); |
| 312 | } |
| 313 | if (mLinkProperties != null) { |
Jake Hamby | 8f9b33e | 2014-01-15 13:08:03 -0800 | [diff] [blame] | 314 | Slog.d(TAG, "LinkProperties = " + mLinkProperties); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 315 | } else { |
| 316 | Slog.d(TAG, "LinkProperties = " ); |
| 317 | } |
| 318 | |
| 319 | if (mLinkCapabilities != null) { |
Jake Hamby | 8f9b33e | 2014-01-15 13:08:03 -0800 | [diff] [blame] | 320 | Slog.d(TAG, "LinkCapabilities = " + mLinkCapabilities); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 321 | } else { |
| 322 | Slog.d(TAG, "LinkCapabilities = " ); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* lets not sample traffic data across state changes */ |
| 328 | mSamplingDataTracker.resetSamplingData(); |
Kazuhiro Ondo | 01758e8 | 2011-04-30 20:10:57 -0500 | [diff] [blame] | 329 | } else { |
| 330 | // There was no state change. Check if LinkProperties has been updated. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 331 | if (TextUtils.equals(reason, PhoneConstants.REASON_LINK_PROPERTIES_CHANGED)) { |
| 332 | mLinkProperties = intent.getParcelableExtra( |
| 333 | PhoneConstants.DATA_LINK_PROPERTIES_KEY); |
Kazuhiro Ondo | 01758e8 | 2011-04-30 20:10:57 -0500 | [diff] [blame] | 334 | if (mLinkProperties == null) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 335 | loge("No link property in LINK_PROPERTIES change event."); |
Kazuhiro Ondo | 01758e8 | 2011-04-30 20:10:57 -0500 | [diff] [blame] | 336 | mLinkProperties = new LinkProperties(); |
| 337 | } |
| 338 | // Just update reason field in this NetworkInfo |
| 339 | mNetworkInfo.setDetailedState(mNetworkInfo.getDetailedState(), reason, |
| 340 | mNetworkInfo.getExtraInfo()); |
| 341 | Message msg = mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, |
| 342 | mNetworkInfo); |
| 343 | msg.sendToTarget(); |
| 344 | } |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 345 | } |
| 346 | } else if (intent.getAction(). |
| 347 | equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 348 | String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY); |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 349 | if (!TextUtils.equals(apnType, mApnType)) { |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 350 | if (DBG) { |
| 351 | log(String.format( |
| 352 | "Broadcast received: ACTION_ANY_DATA_CONNECTION_FAILED ignore, " + |
| 353 | "mApnType=%s != received apnType=%s", mApnType, apnType)); |
| 354 | } |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 355 | return; |
| 356 | } |
Wink Saville | 1e4f461 | 2013-09-21 09:01:19 -0700 | [diff] [blame] | 357 | // Assume this isn't a provisioning network. |
| 358 | mNetworkInfo.setIsConnectedToProvisioningNetwork(false); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 359 | String reason = intent.getStringExtra(PhoneConstants.FAILURE_REASON_KEY); |
| 360 | String apnName = intent.getStringExtra(PhoneConstants.DATA_APN_KEY); |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 361 | if (DBG) { |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 362 | log("Broadcast received: " + intent.getAction() + |
| 363 | " reason=" + reason == null ? "null" : reason); |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 364 | } |
Robert Greenwalt | 153b437 | 2010-07-23 12:32:12 -0700 | [diff] [blame] | 365 | setDetailedState(DetailedState.FAILED, reason, apnName); |
Wink Saville | 26f5a38 | 2010-11-24 16:44:29 -0800 | [diff] [blame] | 366 | } else { |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 367 | if (DBG) log("Broadcast received: ignore " + intent.getAction()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | private void getPhoneService(boolean forceRefresh) { |
| 373 | if ((mPhoneService == null) || forceRefresh) { |
| 374 | mPhoneService = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Report whether data connectivity is possible. |
| 380 | */ |
| 381 | public boolean isAvailable() { |
Robert Greenwalt | cff25ff | 2010-08-30 15:39:36 -0700 | [diff] [blame] | 382 | return mNetworkInfo.isAvailable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | * Return the system properties name associated with the tcp buffer sizes |
| 387 | * for this network. |
| 388 | */ |
| 389 | public String getTcpBufferSizesPropName() { |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 390 | String networkTypeStr = "unknown"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | TelephonyManager tm = new TelephonyManager(mContext); |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 392 | //TODO We have to edit the parameter for getNetworkType regarding CDMA |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | switch(tm.getNetworkType()) { |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 394 | case TelephonyManager.NETWORK_TYPE_GPRS: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | networkTypeStr = "gprs"; |
| 396 | break; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 397 | case TelephonyManager.NETWORK_TYPE_EDGE: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | networkTypeStr = "edge"; |
| 399 | break; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 400 | case TelephonyManager.NETWORK_TYPE_UMTS: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | networkTypeStr = "umts"; |
| 402 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 403 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 404 | networkTypeStr = "hsdpa"; |
| 405 | break; |
| 406 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 407 | networkTypeStr = "hsupa"; |
| 408 | break; |
| 409 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 410 | networkTypeStr = "hspa"; |
| 411 | break; |
Naveen Kalla | 897b311 | 2012-03-31 10:09:49 -0700 | [diff] [blame] | 412 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 413 | networkTypeStr = "hspap"; |
| 414 | break; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 415 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 416 | networkTypeStr = "cdma"; |
| 417 | break; |
Li Zhe | ebe6634 | 2009-08-14 19:22:16 +0800 | [diff] [blame] | 418 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 419 | networkTypeStr = "1xrtt"; |
| 420 | break; |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 421 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 422 | networkTypeStr = "evdo"; |
| 423 | break; |
| 424 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 425 | networkTypeStr = "evdo"; |
| 426 | break; |
Naveen Kalla | 0a5174a | 2010-04-21 14:48:03 -0700 | [diff] [blame] | 427 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 428 | networkTypeStr = "evdo"; |
| 429 | break; |
Robert Greenwalt | 962a990 | 2010-11-02 11:10:25 -0700 | [diff] [blame] | 430 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 431 | networkTypeStr = "iden"; |
| 432 | break; |
| 433 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 434 | networkTypeStr = "lte"; |
| 435 | break; |
| 436 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 437 | networkTypeStr = "ehrpd"; |
| 438 | break; |
| 439 | default: |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 440 | loge("unknown network type: " + tm.getNetworkType()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | } |
| 442 | return "net.tcp.buffersize." + networkTypeStr; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Tear down mobile data connectivity, i.e., disable the ability to create |
| 447 | * mobile data connections. |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 448 | * TODO - make async and return nothing? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | public boolean teardown() { |
Robert Greenwalt | 25a5d3d | 2009-08-13 15:59:51 -0700 | [diff] [blame] | 451 | setTeardownRequested(true); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 452 | return (setEnableApn(mApnType, false) != PhoneConstants.APN_REQUEST_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Wink Saville | dce52cd | 2013-08-16 17:17:28 -0700 | [diff] [blame] | 455 | /** |
| 456 | * @return true if this is ready to operate |
| 457 | */ |
| 458 | public boolean isReady() { |
| 459 | return mDataConnectionTrackerAc != null; |
| 460 | } |
| 461 | |
Irfan Sheriff | da6da09 | 2012-08-16 12:49:23 -0700 | [diff] [blame] | 462 | @Override |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 463 | public void captivePortalCheckCompleted(boolean isCaptivePortal) { |
| 464 | if (mIsCaptivePortal.getAndSet(isCaptivePortal) != isCaptivePortal) { |
| 465 | // Captive portal change enable/disable failing fast |
| 466 | setEnableFailFastMobileData( |
| 467 | isCaptivePortal ? DctConstants.ENABLED : DctConstants.DISABLED); |
| 468 | } |
| 469 | } |
| 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | /** |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 472 | * Record the detailed state of a network, and if it is a |
| 473 | * change from the previous state, send a notification to |
| 474 | * any listeners. |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 475 | * @param state the new {@code DetailedState} |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 476 | * @param reason a {@code String} indicating a reason for the state change, |
| 477 | * if one was supplied. May be {@code null}. |
| 478 | * @param extraInfo optional {@code String} providing extra information about the state change |
| 479 | */ |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 480 | private void setDetailedState(NetworkInfo.DetailedState state, String reason, |
| 481 | String extraInfo) { |
| 482 | if (DBG) log("setDetailed state, old =" |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 483 | + mNetworkInfo.getDetailedState() + " and new state=" + state); |
| 484 | if (state != mNetworkInfo.getDetailedState()) { |
| 485 | boolean wasConnecting = (mNetworkInfo.getState() == NetworkInfo.State.CONNECTING); |
| 486 | String lastReason = mNetworkInfo.getReason(); |
| 487 | /* |
| 488 | * If a reason was supplied when the CONNECTING state was entered, and no |
| 489 | * reason was supplied for entering the CONNECTED state, then retain the |
| 490 | * reason that was supplied when going to CONNECTING. |
| 491 | */ |
| 492 | if (wasConnecting && state == NetworkInfo.DetailedState.CONNECTED && reason == null |
| 493 | && lastReason != null) |
| 494 | reason = lastReason; |
| 495 | mNetworkInfo.setDetailedState(state, reason, extraInfo); |
Robert Greenwalt | 6aecb98 | 2011-09-09 12:38:12 -0700 | [diff] [blame] | 496 | Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, new NetworkInfo(mNetworkInfo)); |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 497 | msg.sendToTarget(); |
| 498 | } |
| 499 | } |
| 500 | |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 501 | public void setTeardownRequested(boolean isRequested) { |
| 502 | mTeardownRequested = isRequested; |
| 503 | } |
| 504 | |
| 505 | public boolean isTeardownRequested() { |
| 506 | return mTeardownRequested; |
| 507 | } |
| 508 | |
| 509 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | * Re-enable mobile data connectivity after a {@link #teardown()}. |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 511 | * TODO - make async and always get a notification? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | */ |
| 513 | public boolean reconnect() { |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 514 | boolean retValue = false; //connected or expect to be? |
Robert Greenwalt | 25a5d3d | 2009-08-13 15:59:51 -0700 | [diff] [blame] | 515 | setTeardownRequested(false); |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 516 | switch (setEnableApn(mApnType, true)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 517 | case PhoneConstants.APN_ALREADY_ACTIVE: |
Robert Greenwalt | a64bf83 | 2009-08-19 20:19:33 -0700 | [diff] [blame] | 518 | // need to set self to CONNECTING so the below message is handled. |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 519 | retValue = true; |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 520 | break; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 521 | case PhoneConstants.APN_REQUEST_STARTED: |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 522 | // set IDLE here , avoid the following second FAILED not sent out |
| 523 | mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 524 | retValue = true; |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 525 | break; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 526 | case PhoneConstants.APN_REQUEST_FAILED: |
| 527 | case PhoneConstants.APN_TYPE_NOT_AVAILABLE: |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 528 | break; |
| 529 | default: |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 530 | loge("Error in reconnect - unexpected response."); |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 531 | break; |
| 532 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 533 | return retValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Turn on or off the mobile radio. No connectivity will be possible while the |
| 538 | * radio is off. The operation is a no-op if the radio is already in the desired state. |
| 539 | * @param turnOn {@code true} if the radio should be turned on, {@code false} if |
| 540 | */ |
| 541 | public boolean setRadio(boolean turnOn) { |
| 542 | getPhoneService(false); |
| 543 | /* |
| 544 | * If the phone process has crashed in the past, we'll get a |
| 545 | * RemoteException and need to re-reference the service. |
| 546 | */ |
| 547 | for (int retry = 0; retry < 2; retry++) { |
| 548 | if (mPhoneService == null) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 549 | loge("Ignoring mobile radio request because could not acquire PhoneService"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | break; |
| 551 | } |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | try { |
| 554 | return mPhoneService.setRadio(turnOn); |
| 555 | } catch (RemoteException e) { |
| 556 | if (retry == 0) getPhoneService(true); |
| 557 | } |
| 558 | } |
| 559 | |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 560 | loge("Could not set radio power to " + (turnOn ? "on" : "off")); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 564 | @Override |
| 565 | public void setUserDataEnable(boolean enabled) { |
| 566 | if (DBG) log("setUserDataEnable: E enabled=" + enabled); |
| 567 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 568 | if (channel != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 569 | channel.sendMessage(DctConstants.CMD_SET_USER_DATA_ENABLE, |
| 570 | enabled ? DctConstants.ENABLED : DctConstants.DISABLED); |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 571 | mUserDataEnabled = enabled; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 572 | } |
| 573 | if (VDBG) log("setUserDataEnable: X enabled=" + enabled); |
| 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void setPolicyDataEnable(boolean enabled) { |
| 578 | if (DBG) log("setPolicyDataEnable(enabled=" + enabled + ")"); |
| 579 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 580 | if (channel != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 581 | channel.sendMessage(DctConstants.CMD_SET_POLICY_DATA_ENABLE, |
| 582 | enabled ? DctConstants.ENABLED : DctConstants.DISABLED); |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 583 | mPolicyDataEnabled = enabled; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 587 | /** |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 588 | * Eanble/disable FailFast |
| 589 | * |
| 590 | * @param enabled is DctConstants.ENABLED/DISABLED |
| 591 | */ |
| 592 | public void setEnableFailFastMobileData(int enabled) { |
| 593 | if (DBG) log("setEnableFailFastMobileData(enabled=" + enabled + ")"); |
| 594 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 595 | if (channel != null) { |
| 596 | channel.sendMessage(DctConstants.CMD_SET_ENABLE_FAIL_FAST_MOBILE_DATA, enabled); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 601 | * carrier dependency is met/unmet |
| 602 | * @param met |
| 603 | */ |
| 604 | public void setDependencyMet(boolean met) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 605 | Bundle bundle = Bundle.forPair(DctConstants.APN_TYPE_KEY, mApnType); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 606 | try { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 607 | if (DBG) log("setDependencyMet: E met=" + met); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 608 | Message msg = Message.obtain(); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 609 | msg.what = DctConstants.CMD_SET_DEPENDENCY_MET; |
| 610 | msg.arg1 = (met ? DctConstants.ENABLED : DctConstants.DISABLED); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 611 | msg.setData(bundle); |
| 612 | mDataConnectionTrackerAc.sendMessage(msg); |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 613 | if (VDBG) log("setDependencyMet: X met=" + met); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 614 | } catch (NullPointerException e) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 615 | loge("setDependencyMet: X mAc was null" + e); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 619 | /** |
| 620 | * Inform DCT mobile provisioning has started, it ends when provisioning completes. |
| 621 | */ |
| 622 | public void enableMobileProvisioning(String url) { |
| 623 | if (DBG) log("enableMobileProvisioning(url=" + url + ")"); |
| 624 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 625 | if (channel != null) { |
| 626 | Message msg = Message.obtain(); |
| 627 | msg.what = DctConstants.CMD_ENABLE_MOBILE_PROVISIONING; |
| 628 | msg.setData(Bundle.forPair(DctConstants.PROVISIONING_URL_KEY, url)); |
| 629 | channel.sendMessage(msg); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Return if this network is the provisioning network. Valid only if connected. |
| 635 | * @param met |
| 636 | */ |
| 637 | public boolean isProvisioningNetwork() { |
| 638 | boolean retVal; |
| 639 | try { |
| 640 | Message msg = Message.obtain(); |
| 641 | msg.what = DctConstants.CMD_IS_PROVISIONING_APN; |
| 642 | msg.setData(Bundle.forPair(DctConstants.APN_TYPE_KEY, mApnType)); |
| 643 | Message result = mDataConnectionTrackerAc.sendMessageSynchronously(msg); |
| 644 | retVal = result.arg1 == DctConstants.ENABLED; |
| 645 | } catch (NullPointerException e) { |
| 646 | loge("isProvisioningNetwork: X " + e); |
| 647 | retVal = false; |
| 648 | } |
| 649 | if (DBG) log("isProvisioningNetwork: retVal=" + retVal); |
| 650 | return retVal; |
| 651 | } |
| 652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | @Override |
Lorenzo Colitti | 69edd64 | 2013-03-07 11:01:12 -0800 | [diff] [blame] | 654 | public void addStackedLink(LinkProperties link) { |
| 655 | mLinkProperties.addStackedLink(link); |
| 656 | } |
| 657 | |
| 658 | @Override |
| 659 | public void removeStackedLink(LinkProperties link) { |
| 660 | mLinkProperties.removeStackedLink(link); |
| 661 | } |
| 662 | |
| 663 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | public String toString() { |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 665 | final CharArrayWriter writer = new CharArrayWriter(); |
| 666 | final PrintWriter pw = new PrintWriter(writer); |
| 667 | pw.print("Mobile data state: "); pw.println(mMobileDataState); |
| 668 | pw.print("Data enabled: user="); pw.print(mUserDataEnabled); |
| 669 | pw.print(", policy="); pw.println(mPolicyDataEnabled); |
| 670 | return writer.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 673 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | * Internal method supporting the ENABLE_MMS feature. |
| 675 | * @param apnType the type of APN to be enabled or disabled (e.g., mms) |
| 676 | * @param enable {@code true} to enable the specified APN type, |
| 677 | * {@code false} to disable it. |
| 678 | * @return an integer value representing the outcome of the request. |
| 679 | */ |
| 680 | private int setEnableApn(String apnType, boolean enable) { |
| 681 | getPhoneService(false); |
| 682 | /* |
| 683 | * If the phone process has crashed in the past, we'll get a |
| 684 | * RemoteException and need to re-reference the service. |
| 685 | */ |
| 686 | for (int retry = 0; retry < 2; retry++) { |
| 687 | if (mPhoneService == null) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 688 | loge("Ignoring feature request because could not acquire PhoneService"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | break; |
| 690 | } |
| 691 | |
| 692 | try { |
| 693 | if (enable) { |
| 694 | return mPhoneService.enableApnType(apnType); |
| 695 | } else { |
| 696 | return mPhoneService.disableApnType(apnType); |
| 697 | } |
| 698 | } catch (RemoteException e) { |
| 699 | if (retry == 0) getPhoneService(true); |
| 700 | } |
| 701 | } |
| 702 | |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 703 | loge("Could not " + (enable ? "enable" : "disable") + " APN type \"" + apnType + "\""); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 704 | return PhoneConstants.APN_REQUEST_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | } |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 706 | |
| 707 | public static String networkTypeToApnType(int netType) { |
| 708 | switch(netType) { |
| 709 | case ConnectivityManager.TYPE_MOBILE: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 710 | return PhoneConstants.APN_TYPE_DEFAULT; // TODO - use just one of these |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 711 | case ConnectivityManager.TYPE_MOBILE_MMS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 712 | return PhoneConstants.APN_TYPE_MMS; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 713 | case ConnectivityManager.TYPE_MOBILE_SUPL: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 714 | return PhoneConstants.APN_TYPE_SUPL; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 715 | case ConnectivityManager.TYPE_MOBILE_DUN: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 716 | return PhoneConstants.APN_TYPE_DUN; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 717 | case ConnectivityManager.TYPE_MOBILE_HIPRI: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 718 | return PhoneConstants.APN_TYPE_HIPRI; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 719 | case ConnectivityManager.TYPE_MOBILE_FOTA: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 720 | return PhoneConstants.APN_TYPE_FOTA; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 721 | case ConnectivityManager.TYPE_MOBILE_IMS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 722 | return PhoneConstants.APN_TYPE_IMS; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 723 | case ConnectivityManager.TYPE_MOBILE_CBS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 724 | return PhoneConstants.APN_TYPE_CBS; |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 725 | case ConnectivityManager.TYPE_MOBILE_IA: |
| 726 | return PhoneConstants.APN_TYPE_IA; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 727 | default: |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 728 | sloge("Error mapping networkType " + netType + " to apnType."); |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 729 | return null; |
| 730 | } |
| 731 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 732 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 733 | |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 734 | /** |
| 735 | * @see android.net.NetworkStateTracker#getLinkProperties() |
| 736 | */ |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 737 | @Override |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 738 | public LinkProperties getLinkProperties() { |
| 739 | return new LinkProperties(mLinkProperties); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 740 | } |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 741 | |
| 742 | /** |
| 743 | * @see android.net.NetworkStateTracker#getLinkCapabilities() |
| 744 | */ |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 745 | @Override |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 746 | public LinkCapabilities getLinkCapabilities() { |
| 747 | return new LinkCapabilities(mLinkCapabilities); |
| 748 | } |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 749 | |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 750 | public void supplyMessenger(Messenger messenger) { |
| 751 | if (VDBG) log(mApnType + " got supplyMessenger"); |
| 752 | AsyncChannel ac = new AsyncChannel(); |
| 753 | ac.connect(mContext, MobileDataStateTracker.this.mHandler, messenger); |
| 754 | } |
| 755 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 756 | private void log(String s) { |
| 757 | Slog.d(TAG, mApnType + ": " + s); |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 760 | private void loge(String s) { |
| 761 | Slog.e(TAG, mApnType + ": " + s); |
| 762 | } |
| 763 | |
| 764 | static private void sloge(String s) { |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 765 | Slog.e(TAG, s); |
| 766 | } |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 767 | |
| 768 | @Override |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 769 | public LinkQualityInfo getLinkQualityInfo() { |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 770 | if (mNetworkInfo == null || mNetworkInfo.getType() == ConnectivityManager.TYPE_NONE) { |
| 771 | // no data available yet; just return |
| 772 | return null; |
| 773 | } |
| 774 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 775 | MobileLinkQualityInfo li = new MobileLinkQualityInfo(); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 776 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 777 | li.setNetworkType(mNetworkInfo.getType()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 778 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 779 | mSamplingDataTracker.setCommonLinkQualityInfoFields(li); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 780 | |
| 781 | if (mNetworkInfo.getSubtype() != TelephonyManager.NETWORK_TYPE_UNKNOWN) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 782 | li.setMobileNetworkType(mNetworkInfo.getSubtype()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 783 | |
| 784 | NetworkDataEntry entry = getNetworkDataEntry(mNetworkInfo.getSubtype()); |
| 785 | if (entry != null) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 786 | li.setTheoreticalRxBandwidth(entry.downloadBandwidth); |
| 787 | li.setTheoreticalRxBandwidth(entry.uploadBandwidth); |
| 788 | li.setTheoreticalLatency(entry.latency); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | if (mSignalStrength != null) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 792 | li.setNormalizedSignalStrength(getNormalizedSignalStrength( |
| 793 | li.getMobileNetworkType(), mSignalStrength)); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
| 797 | SignalStrength ss = mSignalStrength; |
| 798 | if (ss != null) { |
| 799 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 800 | li.setRssi(ss.getGsmSignalStrength()); |
| 801 | li.setGsmErrorRate(ss.getGsmBitErrorRate()); |
| 802 | li.setCdmaDbm(ss.getCdmaDbm()); |
| 803 | li.setCdmaEcio(ss.getCdmaEcio()); |
| 804 | li.setEvdoDbm(ss.getEvdoDbm()); |
| 805 | li.setEvdoEcio(ss.getEvdoEcio()); |
| 806 | li.setEvdoSnr(ss.getEvdoSnr()); |
| 807 | li.setLteSignalStrength(ss.getLteSignalStrength()); |
| 808 | li.setLteRsrp(ss.getLteRsrp()); |
| 809 | li.setLteRsrq(ss.getLteRsrq()); |
| 810 | li.setLteRssnr(ss.getLteRssnr()); |
| 811 | li.setLteCqi(ss.getLteCqi()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | if (VDBG) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 815 | Slog.d(TAG, "Returning LinkQualityInfo with" |
| 816 | + " MobileNetworkType = " + String.valueOf(li.getMobileNetworkType()) |
| 817 | + " Theoretical Rx BW = " + String.valueOf(li.getTheoreticalRxBandwidth()) |
| 818 | + " gsm Signal Strength = " + String.valueOf(li.getRssi()) |
| 819 | + " cdma Signal Strength = " + String.valueOf(li.getCdmaDbm()) |
| 820 | + " evdo Signal Strength = " + String.valueOf(li.getEvdoDbm()) |
| 821 | + " Lte Signal Strength = " + String.valueOf(li.getLteSignalStrength())); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | return li; |
| 825 | } |
| 826 | |
| 827 | static class NetworkDataEntry { |
| 828 | public int networkType; |
| 829 | public int downloadBandwidth; // in kbps |
| 830 | public int uploadBandwidth; // in kbps |
| 831 | public int latency; // in millisecond |
| 832 | |
| 833 | NetworkDataEntry(int i1, int i2, int i3, int i4) { |
| 834 | networkType = i1; |
| 835 | downloadBandwidth = i2; |
| 836 | uploadBandwidth = i3; |
| 837 | latency = i4; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | private static NetworkDataEntry [] mTheoreticalBWTable = new NetworkDataEntry[] { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 842 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EDGE, 237, 118, UNKNOWN), |
| 843 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_GPRS, 48, 40, UNKNOWN), |
| 844 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_UMTS, 384, 64, UNKNOWN), |
| 845 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSDPA, 14400, UNKNOWN, UNKNOWN), |
| 846 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSUPA, 14400, 5760, UNKNOWN), |
| 847 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSPA, 14400, 5760, UNKNOWN), |
| 848 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSPAP, 21000, 5760, UNKNOWN), |
| 849 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_CDMA, UNKNOWN, UNKNOWN, UNKNOWN), |
| 850 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_1xRTT, UNKNOWN, UNKNOWN, UNKNOWN), |
| 851 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_0, 2468, 153, UNKNOWN), |
| 852 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_A, 3072, 1800, UNKNOWN), |
| 853 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_B, 14700, 1800, UNKNOWN), |
| 854 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_IDEN, UNKNOWN, UNKNOWN, UNKNOWN), |
| 855 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_LTE, 100000, 50000, UNKNOWN), |
| 856 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EHRPD, UNKNOWN, UNKNOWN, UNKNOWN), |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 857 | }; |
| 858 | |
| 859 | private static NetworkDataEntry getNetworkDataEntry(int networkType) { |
| 860 | for (NetworkDataEntry entry : mTheoreticalBWTable) { |
| 861 | if (entry.networkType == networkType) { |
| 862 | return entry; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | Slog.e(TAG, "Could not find Theoretical BW entry for " + String.valueOf(networkType)); |
| 867 | return null; |
| 868 | } |
| 869 | |
| 870 | private static int getNormalizedSignalStrength(int networkType, SignalStrength ss) { |
| 871 | |
| 872 | int level; |
| 873 | |
| 874 | switch(networkType) { |
| 875 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 876 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 877 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 878 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 879 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 880 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 881 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 882 | level = ss.getGsmLevel(); |
| 883 | break; |
| 884 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 885 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 886 | level = ss.getCdmaLevel(); |
| 887 | break; |
| 888 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 889 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 890 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 891 | level = ss.getEvdoLevel(); |
| 892 | break; |
| 893 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 894 | level = ss.getLteLevel(); |
| 895 | break; |
| 896 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 897 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 898 | default: |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 899 | return UNKNOWN; |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 902 | return (level * LinkQualityInfo.NORMALIZED_SIGNAL_STRENGTH_RANGE) / |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 903 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS; |
| 904 | } |
| 905 | |
| 906 | @Override |
| 907 | public void startSampling(SamplingDataTracker.SamplingSnapshot s) { |
| 908 | mSamplingDataTracker.startSampling(s); |
| 909 | } |
| 910 | |
| 911 | @Override |
| 912 | public void stopSampling(SamplingDataTracker.SamplingSnapshot s) { |
| 913 | mSamplingDataTracker.stopSampling(s); |
| 914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |