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) { |
| 309 | Slog.d(TAG, "NetworkInfo = " + mNetworkInfo.toString()); |
| 310 | Slog.d(TAG, "subType = " + String.valueOf(mNetworkInfo.getSubtype())); |
| 311 | Slog.d(TAG, "subType = " + mNetworkInfo.getSubtypeName()); |
| 312 | } |
| 313 | if (mLinkProperties != null) { |
| 314 | Slog.d(TAG, "LinkProperties = " + mLinkProperties.toString()); |
| 315 | } else { |
| 316 | Slog.d(TAG, "LinkProperties = " ); |
| 317 | } |
| 318 | |
| 319 | if (mLinkCapabilities != null) { |
| 320 | Slog.d(TAG, "LinkCapabilities = " + mLinkCapabilities.toString()); |
| 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 |
| 463 | public void captivePortalCheckComplete() { |
| 464 | // not implemented |
| 465 | } |
| 466 | |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 467 | @Override |
| 468 | public void captivePortalCheckCompleted(boolean isCaptivePortal) { |
| 469 | if (mIsCaptivePortal.getAndSet(isCaptivePortal) != isCaptivePortal) { |
| 470 | // Captive portal change enable/disable failing fast |
| 471 | setEnableFailFastMobileData( |
| 472 | isCaptivePortal ? DctConstants.ENABLED : DctConstants.DISABLED); |
| 473 | } |
| 474 | } |
| 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | /** |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 477 | * Record the detailed state of a network, and if it is a |
| 478 | * change from the previous state, send a notification to |
| 479 | * any listeners. |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 480 | * @param state the new {@code DetailedState} |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 481 | * @param reason a {@code String} indicating a reason for the state change, |
| 482 | * if one was supplied. May be {@code null}. |
| 483 | * @param extraInfo optional {@code String} providing extra information about the state change |
| 484 | */ |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 485 | private void setDetailedState(NetworkInfo.DetailedState state, String reason, |
| 486 | String extraInfo) { |
| 487 | if (DBG) log("setDetailed state, old =" |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 488 | + mNetworkInfo.getDetailedState() + " and new state=" + state); |
| 489 | if (state != mNetworkInfo.getDetailedState()) { |
| 490 | boolean wasConnecting = (mNetworkInfo.getState() == NetworkInfo.State.CONNECTING); |
| 491 | String lastReason = mNetworkInfo.getReason(); |
| 492 | /* |
| 493 | * If a reason was supplied when the CONNECTING state was entered, and no |
| 494 | * reason was supplied for entering the CONNECTED state, then retain the |
| 495 | * reason that was supplied when going to CONNECTING. |
| 496 | */ |
| 497 | if (wasConnecting && state == NetworkInfo.DetailedState.CONNECTED && reason == null |
| 498 | && lastReason != null) |
| 499 | reason = lastReason; |
| 500 | mNetworkInfo.setDetailedState(state, reason, extraInfo); |
Robert Greenwalt | 6aecb98 | 2011-09-09 12:38:12 -0700 | [diff] [blame] | 501 | Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, new NetworkInfo(mNetworkInfo)); |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 502 | msg.sendToTarget(); |
| 503 | } |
| 504 | } |
| 505 | |
Irfan Sheriff | d649c12 | 2010-06-09 15:39:36 -0700 | [diff] [blame] | 506 | public void setTeardownRequested(boolean isRequested) { |
| 507 | mTeardownRequested = isRequested; |
| 508 | } |
| 509 | |
| 510 | public boolean isTeardownRequested() { |
| 511 | return mTeardownRequested; |
| 512 | } |
| 513 | |
| 514 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | * Re-enable mobile data connectivity after a {@link #teardown()}. |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 516 | * TODO - make async and always get a notification? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | */ |
| 518 | public boolean reconnect() { |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 519 | boolean retValue = false; //connected or expect to be? |
Robert Greenwalt | 25a5d3d | 2009-08-13 15:59:51 -0700 | [diff] [blame] | 520 | setTeardownRequested(false); |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 521 | switch (setEnableApn(mApnType, true)) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 522 | case PhoneConstants.APN_ALREADY_ACTIVE: |
Robert Greenwalt | a64bf83 | 2009-08-19 20:19:33 -0700 | [diff] [blame] | 523 | // need to set self to CONNECTING so the below message is handled. |
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_STARTED: |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 527 | // set IDLE here , avoid the following second FAILED not sent out |
| 528 | mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null); |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 529 | retValue = true; |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 530 | break; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 531 | case PhoneConstants.APN_REQUEST_FAILED: |
| 532 | case PhoneConstants.APN_TYPE_NOT_AVAILABLE: |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 533 | break; |
| 534 | default: |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 535 | loge("Error in reconnect - unexpected response."); |
Robert Greenwalt | c85675d | 2009-08-17 19:27:14 -0700 | [diff] [blame] | 536 | break; |
| 537 | } |
Robert Greenwalt | 02648a4 | 2010-05-18 10:52:51 -0700 | [diff] [blame] | 538 | return retValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Turn on or off the mobile radio. No connectivity will be possible while the |
| 543 | * radio is off. The operation is a no-op if the radio is already in the desired state. |
| 544 | * @param turnOn {@code true} if the radio should be turned on, {@code false} if |
| 545 | */ |
| 546 | public boolean setRadio(boolean turnOn) { |
| 547 | getPhoneService(false); |
| 548 | /* |
| 549 | * If the phone process has crashed in the past, we'll get a |
| 550 | * RemoteException and need to re-reference the service. |
| 551 | */ |
| 552 | for (int retry = 0; retry < 2; retry++) { |
| 553 | if (mPhoneService == null) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 554 | 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] | 555 | break; |
| 556 | } |
Wink Saville | 767a662 | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | try { |
| 559 | return mPhoneService.setRadio(turnOn); |
| 560 | } catch (RemoteException e) { |
| 561 | if (retry == 0) getPhoneService(true); |
| 562 | } |
| 563 | } |
| 564 | |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 565 | 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] | 566 | return false; |
| 567 | } |
| 568 | |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 569 | @Override |
| 570 | public void setUserDataEnable(boolean enabled) { |
| 571 | if (DBG) log("setUserDataEnable: E enabled=" + enabled); |
| 572 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 573 | if (channel != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 574 | channel.sendMessage(DctConstants.CMD_SET_USER_DATA_ENABLE, |
| 575 | enabled ? DctConstants.ENABLED : DctConstants.DISABLED); |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 576 | mUserDataEnabled = enabled; |
Jeff Sharkey | 8e28b7d | 2011-08-19 02:24:24 -0700 | [diff] [blame] | 577 | } |
| 578 | if (VDBG) log("setUserDataEnable: X enabled=" + enabled); |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | public void setPolicyDataEnable(boolean enabled) { |
| 583 | if (DBG) log("setPolicyDataEnable(enabled=" + enabled + ")"); |
| 584 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 585 | if (channel != null) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 586 | channel.sendMessage(DctConstants.CMD_SET_POLICY_DATA_ENABLE, |
| 587 | enabled ? DctConstants.ENABLED : DctConstants.DISABLED); |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 588 | mPolicyDataEnabled = enabled; |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 592 | /** |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 593 | * Eanble/disable FailFast |
| 594 | * |
| 595 | * @param enabled is DctConstants.ENABLED/DISABLED |
| 596 | */ |
| 597 | public void setEnableFailFastMobileData(int enabled) { |
| 598 | if (DBG) log("setEnableFailFastMobileData(enabled=" + enabled + ")"); |
| 599 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 600 | if (channel != null) { |
| 601 | channel.sendMessage(DctConstants.CMD_SET_ENABLE_FAIL_FAST_MOBILE_DATA, enabled); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | /** |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 606 | * carrier dependency is met/unmet |
| 607 | * @param met |
| 608 | */ |
| 609 | public void setDependencyMet(boolean met) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 610 | Bundle bundle = Bundle.forPair(DctConstants.APN_TYPE_KEY, mApnType); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 611 | try { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 612 | if (DBG) log("setDependencyMet: E met=" + met); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 613 | Message msg = Message.obtain(); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 614 | msg.what = DctConstants.CMD_SET_DEPENDENCY_MET; |
| 615 | msg.arg1 = (met ? DctConstants.ENABLED : DctConstants.DISABLED); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 616 | msg.setData(bundle); |
| 617 | mDataConnectionTrackerAc.sendMessage(msg); |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 618 | if (VDBG) log("setDependencyMet: X met=" + met); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 619 | } catch (NullPointerException e) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 620 | loge("setDependencyMet: X mAc was null" + e); |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 624 | /** |
| 625 | * Inform DCT mobile provisioning has started, it ends when provisioning completes. |
| 626 | */ |
| 627 | public void enableMobileProvisioning(String url) { |
| 628 | if (DBG) log("enableMobileProvisioning(url=" + url + ")"); |
| 629 | final AsyncChannel channel = mDataConnectionTrackerAc; |
| 630 | if (channel != null) { |
| 631 | Message msg = Message.obtain(); |
| 632 | msg.what = DctConstants.CMD_ENABLE_MOBILE_PROVISIONING; |
| 633 | msg.setData(Bundle.forPair(DctConstants.PROVISIONING_URL_KEY, url)); |
| 634 | channel.sendMessage(msg); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Return if this network is the provisioning network. Valid only if connected. |
| 640 | * @param met |
| 641 | */ |
| 642 | public boolean isProvisioningNetwork() { |
| 643 | boolean retVal; |
| 644 | try { |
| 645 | Message msg = Message.obtain(); |
| 646 | msg.what = DctConstants.CMD_IS_PROVISIONING_APN; |
| 647 | msg.setData(Bundle.forPair(DctConstants.APN_TYPE_KEY, mApnType)); |
| 648 | Message result = mDataConnectionTrackerAc.sendMessageSynchronously(msg); |
| 649 | retVal = result.arg1 == DctConstants.ENABLED; |
| 650 | } catch (NullPointerException e) { |
| 651 | loge("isProvisioningNetwork: X " + e); |
| 652 | retVal = false; |
| 653 | } |
| 654 | if (DBG) log("isProvisioningNetwork: retVal=" + retVal); |
| 655 | return retVal; |
| 656 | } |
| 657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | @Override |
Lorenzo Colitti | 69edd64 | 2013-03-07 11:01:12 -0800 | [diff] [blame] | 659 | public void addStackedLink(LinkProperties link) { |
| 660 | mLinkProperties.addStackedLink(link); |
| 661 | } |
| 662 | |
| 663 | @Override |
| 664 | public void removeStackedLink(LinkProperties link) { |
| 665 | mLinkProperties.removeStackedLink(link); |
| 666 | } |
| 667 | |
| 668 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | public String toString() { |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 670 | final CharArrayWriter writer = new CharArrayWriter(); |
| 671 | final PrintWriter pw = new PrintWriter(writer); |
| 672 | pw.print("Mobile data state: "); pw.println(mMobileDataState); |
| 673 | pw.print("Data enabled: user="); pw.print(mUserDataEnabled); |
| 674 | pw.print(", policy="); pw.println(mPolicyDataEnabled); |
| 675 | return writer.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 678 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | * Internal method supporting the ENABLE_MMS feature. |
| 680 | * @param apnType the type of APN to be enabled or disabled (e.g., mms) |
| 681 | * @param enable {@code true} to enable the specified APN type, |
| 682 | * {@code false} to disable it. |
| 683 | * @return an integer value representing the outcome of the request. |
| 684 | */ |
| 685 | private int setEnableApn(String apnType, boolean enable) { |
| 686 | getPhoneService(false); |
| 687 | /* |
| 688 | * If the phone process has crashed in the past, we'll get a |
| 689 | * RemoteException and need to re-reference the service. |
| 690 | */ |
| 691 | for (int retry = 0; retry < 2; retry++) { |
| 692 | if (mPhoneService == null) { |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 693 | loge("Ignoring feature request because could not acquire PhoneService"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | break; |
| 695 | } |
| 696 | |
| 697 | try { |
| 698 | if (enable) { |
| 699 | return mPhoneService.enableApnType(apnType); |
| 700 | } else { |
| 701 | return mPhoneService.disableApnType(apnType); |
| 702 | } |
| 703 | } catch (RemoteException e) { |
| 704 | if (retry == 0) getPhoneService(true); |
| 705 | } |
| 706 | } |
| 707 | |
Robert Greenwalt | 58d4c59 | 2011-08-02 17:18:41 -0700 | [diff] [blame] | 708 | loge("Could not " + (enable ? "enable" : "disable") + " APN type \"" + apnType + "\""); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 709 | return PhoneConstants.APN_REQUEST_FAILED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | } |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 711 | |
| 712 | public static String networkTypeToApnType(int netType) { |
| 713 | switch(netType) { |
| 714 | case ConnectivityManager.TYPE_MOBILE: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 715 | return PhoneConstants.APN_TYPE_DEFAULT; // TODO - use just one of these |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 716 | case ConnectivityManager.TYPE_MOBILE_MMS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 717 | return PhoneConstants.APN_TYPE_MMS; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 718 | case ConnectivityManager.TYPE_MOBILE_SUPL: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 719 | return PhoneConstants.APN_TYPE_SUPL; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 720 | case ConnectivityManager.TYPE_MOBILE_DUN: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 721 | return PhoneConstants.APN_TYPE_DUN; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 722 | case ConnectivityManager.TYPE_MOBILE_HIPRI: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 723 | return PhoneConstants.APN_TYPE_HIPRI; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 724 | case ConnectivityManager.TYPE_MOBILE_FOTA: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 725 | return PhoneConstants.APN_TYPE_FOTA; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 726 | case ConnectivityManager.TYPE_MOBILE_IMS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 727 | return PhoneConstants.APN_TYPE_IMS; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 728 | case ConnectivityManager.TYPE_MOBILE_CBS: |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 729 | return PhoneConstants.APN_TYPE_CBS; |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 730 | case ConnectivityManager.TYPE_MOBILE_IA: |
| 731 | return PhoneConstants.APN_TYPE_IA; |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 732 | default: |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 733 | sloge("Error mapping networkType " + netType + " to apnType."); |
Robert Greenwalt | 5154ae76 | 2009-10-30 14:17:42 -0700 | [diff] [blame] | 734 | return null; |
| 735 | } |
| 736 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 737 | |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 738 | |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 739 | /** |
| 740 | * @see android.net.NetworkStateTracker#getLinkProperties() |
| 741 | */ |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 742 | @Override |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 743 | public LinkProperties getLinkProperties() { |
| 744 | return new LinkProperties(mLinkProperties); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 745 | } |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 746 | |
| 747 | /** |
| 748 | * @see android.net.NetworkStateTracker#getLinkCapabilities() |
| 749 | */ |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 750 | @Override |
Wink Saville | f61101f | 2010-09-16 16:36:42 -0700 | [diff] [blame] | 751 | public LinkCapabilities getLinkCapabilities() { |
| 752 | return new LinkCapabilities(mLinkCapabilities); |
| 753 | } |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 754 | |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 755 | public void supplyMessenger(Messenger messenger) { |
| 756 | if (VDBG) log(mApnType + " got supplyMessenger"); |
| 757 | AsyncChannel ac = new AsyncChannel(); |
| 758 | ac.connect(mContext, MobileDataStateTracker.this.mHandler, messenger); |
| 759 | } |
| 760 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 761 | private void log(String s) { |
| 762 | Slog.d(TAG, mApnType + ": " + s); |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Wink Saville | e798268 | 2010-12-07 10:31:02 -0800 | [diff] [blame] | 765 | private void loge(String s) { |
| 766 | Slog.e(TAG, mApnType + ": " + s); |
| 767 | } |
| 768 | |
| 769 | static private void sloge(String s) { |
Wink Saville | ed9c02b | 2010-12-03 12:01:38 -0800 | [diff] [blame] | 770 | Slog.e(TAG, s); |
| 771 | } |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 772 | |
| 773 | @Override |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 774 | public LinkQualityInfo getLinkQualityInfo() { |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 775 | if (mNetworkInfo == null || mNetworkInfo.getType() == ConnectivityManager.TYPE_NONE) { |
| 776 | // no data available yet; just return |
| 777 | return null; |
| 778 | } |
| 779 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 780 | MobileLinkQualityInfo li = new MobileLinkQualityInfo(); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 781 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 782 | li.setNetworkType(mNetworkInfo.getType()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 783 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 784 | mSamplingDataTracker.setCommonLinkQualityInfoFields(li); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 785 | |
| 786 | if (mNetworkInfo.getSubtype() != TelephonyManager.NETWORK_TYPE_UNKNOWN) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 787 | li.setMobileNetworkType(mNetworkInfo.getSubtype()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 788 | |
| 789 | NetworkDataEntry entry = getNetworkDataEntry(mNetworkInfo.getSubtype()); |
| 790 | if (entry != null) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 791 | li.setTheoreticalRxBandwidth(entry.downloadBandwidth); |
| 792 | li.setTheoreticalRxBandwidth(entry.uploadBandwidth); |
| 793 | li.setTheoreticalLatency(entry.latency); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | if (mSignalStrength != null) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 797 | li.setNormalizedSignalStrength(getNormalizedSignalStrength( |
| 798 | li.getMobileNetworkType(), mSignalStrength)); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
| 802 | SignalStrength ss = mSignalStrength; |
| 803 | if (ss != null) { |
| 804 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 805 | li.setRssi(ss.getGsmSignalStrength()); |
| 806 | li.setGsmErrorRate(ss.getGsmBitErrorRate()); |
| 807 | li.setCdmaDbm(ss.getCdmaDbm()); |
| 808 | li.setCdmaEcio(ss.getCdmaEcio()); |
| 809 | li.setEvdoDbm(ss.getEvdoDbm()); |
| 810 | li.setEvdoEcio(ss.getEvdoEcio()); |
| 811 | li.setEvdoSnr(ss.getEvdoSnr()); |
| 812 | li.setLteSignalStrength(ss.getLteSignalStrength()); |
| 813 | li.setLteRsrp(ss.getLteRsrp()); |
| 814 | li.setLteRsrq(ss.getLteRsrq()); |
| 815 | li.setLteRssnr(ss.getLteRssnr()); |
| 816 | li.setLteCqi(ss.getLteCqi()); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | if (VDBG) { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 820 | Slog.d(TAG, "Returning LinkQualityInfo with" |
| 821 | + " MobileNetworkType = " + String.valueOf(li.getMobileNetworkType()) |
| 822 | + " Theoretical Rx BW = " + String.valueOf(li.getTheoreticalRxBandwidth()) |
| 823 | + " gsm Signal Strength = " + String.valueOf(li.getRssi()) |
| 824 | + " cdma Signal Strength = " + String.valueOf(li.getCdmaDbm()) |
| 825 | + " evdo Signal Strength = " + String.valueOf(li.getEvdoDbm()) |
| 826 | + " Lte Signal Strength = " + String.valueOf(li.getLteSignalStrength())); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | return li; |
| 830 | } |
| 831 | |
| 832 | static class NetworkDataEntry { |
| 833 | public int networkType; |
| 834 | public int downloadBandwidth; // in kbps |
| 835 | public int uploadBandwidth; // in kbps |
| 836 | public int latency; // in millisecond |
| 837 | |
| 838 | NetworkDataEntry(int i1, int i2, int i3, int i4) { |
| 839 | networkType = i1; |
| 840 | downloadBandwidth = i2; |
| 841 | uploadBandwidth = i3; |
| 842 | latency = i4; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | private static NetworkDataEntry [] mTheoreticalBWTable = new NetworkDataEntry[] { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 847 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EDGE, 237, 118, UNKNOWN), |
| 848 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_GPRS, 48, 40, UNKNOWN), |
| 849 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_UMTS, 384, 64, UNKNOWN), |
| 850 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSDPA, 14400, UNKNOWN, UNKNOWN), |
| 851 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSUPA, 14400, 5760, UNKNOWN), |
| 852 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSPA, 14400, 5760, UNKNOWN), |
| 853 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_HSPAP, 21000, 5760, UNKNOWN), |
| 854 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_CDMA, UNKNOWN, UNKNOWN, UNKNOWN), |
| 855 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_1xRTT, UNKNOWN, UNKNOWN, UNKNOWN), |
| 856 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_0, 2468, 153, UNKNOWN), |
| 857 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_A, 3072, 1800, UNKNOWN), |
| 858 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EVDO_B, 14700, 1800, UNKNOWN), |
| 859 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_IDEN, UNKNOWN, UNKNOWN, UNKNOWN), |
| 860 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_LTE, 100000, 50000, UNKNOWN), |
| 861 | new NetworkDataEntry(TelephonyManager.NETWORK_TYPE_EHRPD, UNKNOWN, UNKNOWN, UNKNOWN), |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 862 | }; |
| 863 | |
| 864 | private static NetworkDataEntry getNetworkDataEntry(int networkType) { |
| 865 | for (NetworkDataEntry entry : mTheoreticalBWTable) { |
| 866 | if (entry.networkType == networkType) { |
| 867 | return entry; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | Slog.e(TAG, "Could not find Theoretical BW entry for " + String.valueOf(networkType)); |
| 872 | return null; |
| 873 | } |
| 874 | |
| 875 | private static int getNormalizedSignalStrength(int networkType, SignalStrength ss) { |
| 876 | |
| 877 | int level; |
| 878 | |
| 879 | switch(networkType) { |
| 880 | case TelephonyManager.NETWORK_TYPE_EDGE: |
| 881 | case TelephonyManager.NETWORK_TYPE_GPRS: |
| 882 | case TelephonyManager.NETWORK_TYPE_UMTS: |
| 883 | case TelephonyManager.NETWORK_TYPE_HSDPA: |
| 884 | case TelephonyManager.NETWORK_TYPE_HSUPA: |
| 885 | case TelephonyManager.NETWORK_TYPE_HSPA: |
| 886 | case TelephonyManager.NETWORK_TYPE_HSPAP: |
| 887 | level = ss.getGsmLevel(); |
| 888 | break; |
| 889 | case TelephonyManager.NETWORK_TYPE_CDMA: |
| 890 | case TelephonyManager.NETWORK_TYPE_1xRTT: |
| 891 | level = ss.getCdmaLevel(); |
| 892 | break; |
| 893 | case TelephonyManager.NETWORK_TYPE_EVDO_0: |
| 894 | case TelephonyManager.NETWORK_TYPE_EVDO_A: |
| 895 | case TelephonyManager.NETWORK_TYPE_EVDO_B: |
| 896 | level = ss.getEvdoLevel(); |
| 897 | break; |
| 898 | case TelephonyManager.NETWORK_TYPE_LTE: |
| 899 | level = ss.getLteLevel(); |
| 900 | break; |
| 901 | case TelephonyManager.NETWORK_TYPE_IDEN: |
| 902 | case TelephonyManager.NETWORK_TYPE_EHRPD: |
| 903 | default: |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 904 | return UNKNOWN; |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 907 | return (level * LinkQualityInfo.NORMALIZED_SIGNAL_STRENGTH_RANGE) / |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 908 | SignalStrength.NUM_SIGNAL_STRENGTH_BINS; |
| 909 | } |
| 910 | |
| 911 | @Override |
| 912 | public void startSampling(SamplingDataTracker.SamplingSnapshot s) { |
| 913 | mSamplingDataTracker.startSampling(s); |
| 914 | } |
| 915 | |
| 916 | @Override |
| 917 | public void stopSampling(SamplingDataTracker.SamplingSnapshot s) { |
| 918 | mSamplingDataTracker.stopSampling(s); |
| 919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | } |