blob: 4ab95e8ffa050408c813d53db688bd8baf048b0e [file] [log] [blame]
The Android Open Source Project28527d22009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
19import android.app.Notification;
20import android.app.NotificationManager;
21import android.content.ContentResolver;
22import android.content.Context;
23import android.content.Intent;
24import android.content.pm.PackageManager;
25import android.net.ConnectivityManager;
26import android.net.IConnectivityManager;
27import android.net.MobileDataStateTracker;
28import android.net.NetworkInfo;
29import android.net.NetworkStateTracker;
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +053030import android.net.NetworkUtils;
The Android Open Source Project28527d22009-03-03 19:31:44 -080031import android.net.wifi.WifiStateTracker;
32import android.os.Binder;
33import android.os.Handler;
Robert Greenwalt2034b912009-08-12 16:08:25 -070034import android.os.IBinder;
The Android Open Source Project28527d22009-03-03 19:31:44 -080035import android.os.Looper;
36import android.os.Message;
Robert Greenwalt2034b912009-08-12 16:08:25 -070037import android.os.RemoteException;
The Android Open Source Project28527d22009-03-03 19:31:44 -080038import android.os.ServiceManager;
39import android.os.SystemProperties;
40import android.provider.Settings;
Robert Greenwalt2034b912009-08-12 16:08:25 -070041import android.text.TextUtils;
The Android Open Source Project28527d22009-03-03 19:31:44 -080042import android.util.EventLog;
Joe Onoratoc2386bb2010-02-26 18:56:32 -080043import android.util.Slog;
The Android Open Source Project28527d22009-03-03 19:31:44 -080044
Robert Greenwalt2034b912009-08-12 16:08:25 -070045import com.android.internal.telephony.Phone;
46
Robert Greenwalt0c4828c2010-01-26 11:40:34 -080047import com.android.server.connectivity.Tethering;
48
The Android Open Source Project28527d22009-03-03 19:31:44 -080049import java.io.FileDescriptor;
50import java.io.PrintWriter;
Robert Greenwalt2034b912009-08-12 16:08:25 -070051import java.util.ArrayList;
Robert Greenwalt0e80be12010-09-20 14:35:25 -070052import java.util.GregorianCalendar;
Robert Greenwalt2034b912009-08-12 16:08:25 -070053import java.util.List;
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +053054import java.net.InetAddress;
55import java.net.UnknownHostException;
The Android Open Source Project28527d22009-03-03 19:31:44 -080056
57/**
58 * @hide
59 */
60public class ConnectivityService extends IConnectivityManager.Stub {
61
Robert Greenwalta25fd712009-10-06 14:12:53 -070062 private static final boolean DBG = true;
The Android Open Source Project28527d22009-03-03 19:31:44 -080063 private static final String TAG = "ConnectivityService";
64
Robert Greenwalt2034b912009-08-12 16:08:25 -070065 // how long to wait before switching back to a radio's default network
66 private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
67 // system property that can override the above value
68 private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
69 "android.telephony.apn-restore";
70
Robert Greenwalt0c4828c2010-01-26 11:40:34 -080071
72 private Tethering mTethering;
Robert Greenwaltf1b66e12010-02-25 12:29:30 -080073 private boolean mTetheringConfigValid = false;
Robert Greenwalt0c4828c2010-01-26 11:40:34 -080074
The Android Open Source Project28527d22009-03-03 19:31:44 -080075 /**
76 * Sometimes we want to refer to the individual network state
77 * trackers separately, and sometimes we just want to treat them
78 * abstractly.
79 */
80 private NetworkStateTracker mNetTrackers[];
Robert Greenwalt2034b912009-08-12 16:08:25 -070081
82 /**
83 * A per Net list of the PID's that requested access to the net
84 * used both as a refcount and for per-PID DNS selection
85 */
86 private List mNetRequestersPids[];
87
Robert Greenwalt2034b912009-08-12 16:08:25 -070088 // priority order of the nettrackers
89 // (excluding dynamically set mNetworkPreference)
90 // TODO - move mNetworkTypePreference into this
91 private int[] mPriorityList;
92
The Android Open Source Project28527d22009-03-03 19:31:44 -080093 private Context mContext;
94 private int mNetworkPreference;
Robert Greenwalt2034b912009-08-12 16:08:25 -070095 private int mActiveDefaultNetwork = -1;
Robert Greenwalt986c7412010-09-08 15:24:47 -070096 // 0 is full bad, 100 is full good
97 private int mDefaultInetCondition = 0;
98 private int mDefaultInetConditionPublished = 0;
99 private boolean mInetConditionChangeInFlight = false;
100 private int mDefaultConnectionSequence = 0;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800101
102 private int mNumDnsEntries;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800103
104 private boolean mTestMode;
105 private static ConnectivityService sServiceInstance;
106
Robert Greenwalt2034b912009-08-12 16:08:25 -0700107 private Handler mHandler;
108
109 // list of DeathRecipients used to make sure features are turned off when
110 // a process dies
111 private List mFeatureUsers;
112
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400113 private boolean mSystemReady;
Dianne Hackborna417ff82009-12-08 19:45:14 -0800114 private Intent mInitialBroadcast;
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400115
Robert Greenwalt0e80be12010-09-20 14:35:25 -0700116 // used in DBG mode to track inet condition reports
117 private static final int INET_CONDITION_LOG_MAX_SIZE = 15;
118 private ArrayList mInetLog;
119
Robert Greenwalt12c44552009-12-07 11:33:18 -0800120 private static class NetworkAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700121 /**
122 * Class for holding settings read from resources.
123 */
124 public String mName;
125 public int mType;
126 public int mRadio;
127 public int mPriority;
Robert Greenwalt12c44552009-12-07 11:33:18 -0800128 public NetworkInfo.State mLastState;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700129 public NetworkAttributes(String init) {
130 String fragments[] = init.split(",");
131 mName = fragments[0].toLowerCase();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700132 mType = Integer.parseInt(fragments[1]);
133 mRadio = Integer.parseInt(fragments[2]);
134 mPriority = Integer.parseInt(fragments[3]);
Robert Greenwalt12c44552009-12-07 11:33:18 -0800135 mLastState = NetworkInfo.State.UNKNOWN;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700136 }
137 public boolean isDefault() {
138 return (mType == mRadio);
139 }
140 }
141 NetworkAttributes[] mNetAttributes;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700142 int mNetworksDefined;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700143
Robert Greenwalt12c44552009-12-07 11:33:18 -0800144 private static class RadioAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700145 public int mSimultaneity;
146 public int mType;
147 public RadioAttributes(String init) {
148 String fragments[] = init.split(",");
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700149 mType = Integer.parseInt(fragments[0]);
150 mSimultaneity = Integer.parseInt(fragments[1]);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700151 }
152 }
153 RadioAttributes[] mRadioAttributes;
154
The Android Open Source Project28527d22009-03-03 19:31:44 -0800155 private static class ConnectivityThread extends Thread {
156 private Context mContext;
Robert Greenwalt0659da32009-07-16 17:21:39 -0700157
The Android Open Source Project28527d22009-03-03 19:31:44 -0800158 private ConnectivityThread(Context context) {
159 super("ConnectivityThread");
160 mContext = context;
161 }
162
163 @Override
164 public void run() {
165 Looper.prepare();
166 synchronized (this) {
167 sServiceInstance = new ConnectivityService(mContext);
168 notifyAll();
169 }
170 Looper.loop();
171 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700172
The Android Open Source Project28527d22009-03-03 19:31:44 -0800173 public static ConnectivityService getServiceInstance(Context context) {
174 ConnectivityThread thread = new ConnectivityThread(context);
175 thread.start();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700176
The Android Open Source Project28527d22009-03-03 19:31:44 -0800177 synchronized (thread) {
178 while (sServiceInstance == null) {
179 try {
180 // Wait until sServiceInstance has been initialized.
181 thread.wait();
182 } catch (InterruptedException ignore) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800183 Slog.e(TAG,
Robert Greenwalt0659da32009-07-16 17:21:39 -0700184 "Unexpected InterruptedException while waiting"+
185 " for ConnectivityService thread");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800186 }
187 }
188 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700189
The Android Open Source Project28527d22009-03-03 19:31:44 -0800190 return sServiceInstance;
191 }
192 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700193
The Android Open Source Project28527d22009-03-03 19:31:44 -0800194 public static ConnectivityService getInstance(Context context) {
195 return ConnectivityThread.getServiceInstance(context);
196 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700197
The Android Open Source Project28527d22009-03-03 19:31:44 -0800198 private ConnectivityService(Context context) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800199 if (DBG) Slog.v(TAG, "ConnectivityService starting up");
Robert Greenwaltd48f8ee2010-01-14 17:47:58 -0800200
201 // setup our unique device name
202 String id = Settings.Secure.getString(context.getContentResolver(),
203 Settings.Secure.ANDROID_ID);
204 if (id != null && id.length() > 0) {
205 String name = new String("android_").concat(id);
206 SystemProperties.set("net.hostname", name);
207 }
208
The Android Open Source Project28527d22009-03-03 19:31:44 -0800209 mContext = context;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700210 mNetTrackers = new NetworkStateTracker[
211 ConnectivityManager.MAX_NETWORK_TYPE+1];
212 mHandler = new MyHandler();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700213
The Android Open Source Project28527d22009-03-03 19:31:44 -0800214 mNetworkPreference = getPersistedNetworkPreference();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700215
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700216 mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
217 mNetAttributes = new NetworkAttributes[ConnectivityManager.MAX_NETWORK_TYPE+1];
218
Robert Greenwalt2034b912009-08-12 16:08:25 -0700219 // Load device network attributes from resources
Robert Greenwalt2034b912009-08-12 16:08:25 -0700220 String[] raStrings = context.getResources().getStringArray(
221 com.android.internal.R.array.radioAttributes);
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700222 for (String raString : raStrings) {
223 RadioAttributes r = new RadioAttributes(raString);
224 if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800225 Slog.e(TAG, "Error in radioAttributes - ignoring attempt to define type " + r.mType);
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700226 continue;
227 }
228 if (mRadioAttributes[r.mType] != null) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800229 Slog.e(TAG, "Error in radioAttributes - ignoring attempt to redefine type " +
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700230 r.mType);
231 continue;
232 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700233 mRadioAttributes[r.mType] = r;
234 }
235
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700236 String[] naStrings = context.getResources().getStringArray(
237 com.android.internal.R.array.networkAttributes);
238 for (String naString : naStrings) {
239 try {
240 NetworkAttributes n = new NetworkAttributes(naString);
241 if (n.mType > ConnectivityManager.MAX_NETWORK_TYPE) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800242 Slog.e(TAG, "Error in networkAttributes - ignoring attempt to define type " +
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700243 n.mType);
244 continue;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700245 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700246 if (mNetAttributes[n.mType] != null) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800247 Slog.e(TAG, "Error in networkAttributes - ignoring attempt to redefine type " +
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700248 n.mType);
249 continue;
250 }
251 if (mRadioAttributes[n.mRadio] == null) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800252 Slog.e(TAG, "Error in networkAttributes - ignoring attempt to use undefined " +
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700253 "radio " + n.mRadio + " in network type " + n.mType);
254 continue;
255 }
256 mNetAttributes[n.mType] = n;
257 mNetworksDefined++;
258 } catch(Exception e) {
259 // ignore it - leave the entry null
Robert Greenwalt2034b912009-08-12 16:08:25 -0700260 }
261 }
262
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700263 // high priority first
264 mPriorityList = new int[mNetworksDefined];
265 {
266 int insertionPoint = mNetworksDefined-1;
267 int currentLowest = 0;
268 int nextLowest = 0;
269 while (insertionPoint > -1) {
270 for (NetworkAttributes na : mNetAttributes) {
271 if (na == null) continue;
272 if (na.mPriority < currentLowest) continue;
273 if (na.mPriority > currentLowest) {
274 if (na.mPriority < nextLowest || nextLowest == 0) {
275 nextLowest = na.mPriority;
276 }
277 continue;
278 }
279 mPriorityList[insertionPoint--] = na.mType;
280 }
281 currentLowest = nextLowest;
282 nextLowest = 0;
283 }
284 }
285
286 mNetRequestersPids = new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
287 for (int i : mPriorityList) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700288 mNetRequestersPids[i] = new ArrayList();
289 }
290
291 mFeatureUsers = new ArrayList();
292
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700293 mNumDnsEntries = 0;
294
295 mTestMode = SystemProperties.get("cm.test.mode").equals("true")
296 && SystemProperties.get("ro.build.type").equals("eng");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800297 /*
298 * Create the network state trackers for Wi-Fi and mobile
299 * data. Maybe this could be done with a factory class,
300 * but it's not clear that it's worth it, given that
301 * the number of different network types is not going
302 * to change very often.
303 */
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800304 boolean noMobileData = !getMobileDataEnabled();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700305 for (int netType : mPriorityList) {
306 switch (mNetAttributes[netType].mRadio) {
307 case ConnectivityManager.TYPE_WIFI:
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800308 if (DBG) Slog.v(TAG, "Starting Wifi Service.");
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700309 WifiStateTracker wst = new WifiStateTracker(context, mHandler);
310 WifiService wifiService = new WifiService(context, wst);
311 ServiceManager.addService(Context.WIFI_SERVICE, wifiService);
Irfan Sheriff324ec572010-03-11 16:37:45 -0800312 wifiService.startWifi();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700313 mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
314 wst.startMonitoring();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800315
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700316 break;
317 case ConnectivityManager.TYPE_MOBILE:
318 mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
319 netType, mNetAttributes[netType].mName);
320 mNetTrackers[netType].startMonitoring();
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800321 if (noMobileData) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800322 if (DBG) Slog.d(TAG, "tearing down Mobile networks due to setting");
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800323 mNetTrackers[netType].teardown();
324 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700325 break;
326 default:
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800327 Slog.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700328 mNetAttributes[netType].mRadio);
329 continue;
330 }
331 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -0800332
Robert Greenwaltc0b6c602010-03-11 15:03:08 -0800333 mTethering = new Tethering(mContext, mHandler.getLooper());
Robert Greenwaltf1b66e12010-02-25 12:29:30 -0800334 mTetheringConfigValid = (((mNetTrackers[ConnectivityManager.TYPE_MOBILE_DUN] != null) ||
335 !mTethering.isDunRequired()) &&
336 (mTethering.getTetherableUsbRegexs().length != 0 ||
337 mTethering.getTetherableWifiRegexs().length != 0) &&
338 mTethering.getUpstreamIfaceRegexs().length != 0);
339
Robert Greenwalt0e80be12010-09-20 14:35:25 -0700340 if (DBG) {
341 mInetLog = new ArrayList();
342 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800343 }
344
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700345
The Android Open Source Project28527d22009-03-03 19:31:44 -0800346 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700347 * Sets the preferred network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800348 * @param preference the new preference
349 */
350 public synchronized void setNetworkPreference(int preference) {
351 enforceChangePermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700352 if (ConnectivityManager.isNetworkTypeValid(preference) &&
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700353 mNetAttributes[preference] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700354 mNetAttributes[preference].isDefault()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800355 if (mNetworkPreference != preference) {
356 persistNetworkPreference(preference);
357 mNetworkPreference = preference;
358 enforcePreference();
359 }
360 }
361 }
362
363 public int getNetworkPreference() {
364 enforceAccessPermission();
365 return mNetworkPreference;
366 }
367
368 private void persistNetworkPreference(int networkPreference) {
369 final ContentResolver cr = mContext.getContentResolver();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700370 Settings.Secure.putInt(cr, Settings.Secure.NETWORK_PREFERENCE,
371 networkPreference);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800372 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700373
The Android Open Source Project28527d22009-03-03 19:31:44 -0800374 private int getPersistedNetworkPreference() {
375 final ContentResolver cr = mContext.getContentResolver();
376
377 final int networkPrefSetting = Settings.Secure
378 .getInt(cr, Settings.Secure.NETWORK_PREFERENCE, -1);
379 if (networkPrefSetting != -1) {
380 return networkPrefSetting;
381 }
382
383 return ConnectivityManager.DEFAULT_NETWORK_PREFERENCE;
384 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700385
The Android Open Source Project28527d22009-03-03 19:31:44 -0800386 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700387 * Make the state of network connectivity conform to the preference settings
The Android Open Source Project28527d22009-03-03 19:31:44 -0800388 * In this method, we only tear down a non-preferred network. Establishing
389 * a connection to the preferred network is taken care of when we handle
390 * the disconnect event from the non-preferred network
391 * (see {@link #handleDisconnect(NetworkInfo)}).
392 */
393 private void enforcePreference() {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700394 if (mNetTrackers[mNetworkPreference].getNetworkInfo().isConnected())
The Android Open Source Project28527d22009-03-03 19:31:44 -0800395 return;
396
Robert Greenwalt2034b912009-08-12 16:08:25 -0700397 if (!mNetTrackers[mNetworkPreference].isAvailable())
398 return;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800399
Robert Greenwalt2034b912009-08-12 16:08:25 -0700400 for (int t=0; t <= ConnectivityManager.MAX_RADIO_TYPE; t++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700401 if (t != mNetworkPreference && mNetTrackers[t] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700402 mNetTrackers[t].getNetworkInfo().isConnected()) {
Robert Greenwaltf3f045b2009-08-20 15:25:14 -0700403 if (DBG) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800404 Slog.d(TAG, "tearing down " +
Robert Greenwaltf3f045b2009-08-20 15:25:14 -0700405 mNetTrackers[t].getNetworkInfo() +
406 " in enforcePreference");
407 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700408 teardown(mNetTrackers[t]);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800409 }
410 }
411 }
412
413 private boolean teardown(NetworkStateTracker netTracker) {
414 if (netTracker.teardown()) {
415 netTracker.setTeardownRequested(true);
416 return true;
417 } else {
418 return false;
419 }
420 }
421
422 /**
423 * Return NetworkInfo for the active (i.e., connected) network interface.
424 * It is assumed that at most one network is active at a time. If more
425 * than one is active, it is indeterminate which will be returned.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700426 * @return the info for the active network, or {@code null} if none is
427 * active
The Android Open Source Project28527d22009-03-03 19:31:44 -0800428 */
429 public NetworkInfo getActiveNetworkInfo() {
430 enforceAccessPermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700431 for (int type=0; type <= ConnectivityManager.MAX_NETWORK_TYPE; type++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700432 if (mNetAttributes[type] == null || !mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700433 continue;
434 }
435 NetworkStateTracker t = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800436 NetworkInfo info = t.getNetworkInfo();
437 if (info.isConnected()) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800438 if (DBG && type != mActiveDefaultNetwork) Slog.e(TAG,
Robert Greenwalt2034b912009-08-12 16:08:25 -0700439 "connected default network is not " +
440 "mActiveDefaultNetwork!");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800441 return info;
442 }
443 }
444 return null;
445 }
446
447 public NetworkInfo getNetworkInfo(int networkType) {
448 enforceAccessPermission();
449 if (ConnectivityManager.isNetworkTypeValid(networkType)) {
450 NetworkStateTracker t = mNetTrackers[networkType];
451 if (t != null)
452 return t.getNetworkInfo();
453 }
454 return null;
455 }
456
457 public NetworkInfo[] getAllNetworkInfo() {
458 enforceAccessPermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700459 NetworkInfo[] result = new NetworkInfo[mNetworksDefined];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800460 int i = 0;
461 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700462 if(t != null) result[i++] = t.getNetworkInfo();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800463 }
464 return result;
465 }
466
467 public boolean setRadios(boolean turnOn) {
468 boolean result = true;
469 enforceChangePermission();
470 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700471 if (t != null) result = t.setRadio(turnOn) && result;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800472 }
473 return result;
474 }
475
476 public boolean setRadio(int netType, boolean turnOn) {
477 enforceChangePermission();
478 if (!ConnectivityManager.isNetworkTypeValid(netType)) {
479 return false;
480 }
481 NetworkStateTracker tracker = mNetTrackers[netType];
482 return tracker != null && tracker.setRadio(turnOn);
483 }
484
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700485 /**
486 * Used to notice when the calling process dies so we can self-expire
487 *
488 * Also used to know if the process has cleaned up after itself when
489 * our auto-expire timer goes off. The timer has a link to an object.
490 *
491 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700492 private class FeatureUser implements IBinder.DeathRecipient {
493 int mNetworkType;
494 String mFeature;
495 IBinder mBinder;
496 int mPid;
497 int mUid;
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800498 long mCreateTime;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700499
500 FeatureUser(int type, String feature, IBinder binder) {
501 super();
502 mNetworkType = type;
503 mFeature = feature;
504 mBinder = binder;
505 mPid = getCallingPid();
506 mUid = getCallingUid();
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800507 mCreateTime = System.currentTimeMillis();
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700508
Robert Greenwalt2034b912009-08-12 16:08:25 -0700509 try {
510 mBinder.linkToDeath(this, 0);
511 } catch (RemoteException e) {
512 binderDied();
513 }
514 }
515
516 void unlinkDeathRecipient() {
517 mBinder.unlinkToDeath(this, 0);
518 }
519
520 public void binderDied() {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800521 Slog.d(TAG, "ConnectivityService FeatureUser binderDied(" +
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800522 mNetworkType + ", " + mFeature + ", " + mBinder + "), created " +
523 (System.currentTimeMillis() - mCreateTime) + " mSec ago");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700524 stopUsingNetworkFeature(this, false);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700525 }
526
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700527 public void expire() {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800528 Slog.d(TAG, "ConnectivityService FeatureUser expire(" +
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800529 mNetworkType + ", " + mFeature + ", " + mBinder +"), created " +
530 (System.currentTimeMillis() - mCreateTime) + " mSec ago");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700531 stopUsingNetworkFeature(this, false);
532 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800533
534 public String toString() {
535 return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
536 (System.currentTimeMillis() - mCreateTime) + " mSec ago";
537 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700538 }
539
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700540 // javadoc from interface
Robert Greenwalt2034b912009-08-12 16:08:25 -0700541 public int startUsingNetworkFeature(int networkType, String feature,
542 IBinder binder) {
543 if (DBG) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800544 Slog.d(TAG, "startUsingNetworkFeature for net " + networkType +
Robert Greenwalt2034b912009-08-12 16:08:25 -0700545 ": " + feature);
546 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800547 enforceChangePermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700548 if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
549 mNetAttributes[networkType] == null) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700550 return Phone.APN_REQUEST_FAILED;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800551 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700552
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700553 FeatureUser f = new FeatureUser(networkType, feature, binder);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700554
555 // TODO - move this into the MobileDataStateTracker
556 int usedNetworkType = networkType;
557 if(networkType == ConnectivityManager.TYPE_MOBILE) {
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800558 if (!getMobileDataEnabled()) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800559 if (DBG) Slog.d(TAG, "requested special network with data disabled - rejected");
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800560 return Phone.APN_TYPE_NOT_AVAILABLE;
561 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700562 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
563 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
564 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
565 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
566 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
567 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
568 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
569 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
570 }
571 }
572 NetworkStateTracker network = mNetTrackers[usedNetworkType];
573 if (network != null) {
574 if (usedNetworkType != networkType) {
575 Integer currentPid = new Integer(getCallingPid());
576
577 NetworkStateTracker radio = mNetTrackers[networkType];
578 NetworkInfo ni = network.getNetworkInfo();
579
580 if (ni.isAvailable() == false) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800581 if (DBG) Slog.d(TAG, "special network not available");
Robert Greenwalt2034b912009-08-12 16:08:25 -0700582 return Phone.APN_TYPE_NOT_AVAILABLE;
583 }
584
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700585 synchronized(this) {
586 mFeatureUsers.add(f);
587 if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
588 // this gets used for per-pid dns when connected
589 mNetRequestersPids[usedNetworkType].add(currentPid);
590 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700591 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700592 mHandler.sendMessageDelayed(mHandler.obtainMessage(
593 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
594 f), getRestoreDefaultNetworkDelay());
595
Robert Greenwalt2034b912009-08-12 16:08:25 -0700596
Robert Greenwalta52c75a2009-08-19 20:19:33 -0700597 if ((ni.isConnectedOrConnecting() == true) &&
598 !network.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700599 if (ni.isConnected() == true) {
600 // add the pid-specific dns
Robert Greenwalt0ef68752010-08-13 14:16:12 -0700601 handleDnsConfigurationChange(networkType);
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800602 if (DBG) Slog.d(TAG, "special network already active");
Robert Greenwalt2034b912009-08-12 16:08:25 -0700603 return Phone.APN_ALREADY_ACTIVE;
604 }
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800605 if (DBG) Slog.d(TAG, "special network already connecting");
Robert Greenwalt2034b912009-08-12 16:08:25 -0700606 return Phone.APN_REQUEST_STARTED;
607 }
608
609 // check if the radio in play can make another contact
610 // assume if cannot for now
611
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800612 if (DBG) Slog.d(TAG, "reconnecting to special network");
Robert Greenwalt2034b912009-08-12 16:08:25 -0700613 network.reconnect();
614 return Phone.APN_REQUEST_STARTED;
615 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700616 synchronized(this) {
617 mFeatureUsers.add(f);
618 }
619 mHandler.sendMessageDelayed(mHandler.obtainMessage(
620 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
621 f), getRestoreDefaultNetworkDelay());
622
Robert Greenwalt2034b912009-08-12 16:08:25 -0700623 return network.startUsingNetworkFeature(feature,
624 getCallingPid(), getCallingUid());
625 }
626 }
627 return Phone.APN_TYPE_NOT_AVAILABLE;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800628 }
629
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700630 // javadoc from interface
The Android Open Source Project28527d22009-03-03 19:31:44 -0800631 public int stopUsingNetworkFeature(int networkType, String feature) {
Robert Greenwalt28f43012009-10-06 17:52:40 -0700632 enforceChangePermission();
633
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700634 int pid = getCallingPid();
635 int uid = getCallingUid();
636
637 FeatureUser u = null;
638 boolean found = false;
639
640 synchronized(this) {
641 for (int i = 0; i < mFeatureUsers.size() ; i++) {
642 u = (FeatureUser)mFeatureUsers.get(i);
643 if (uid == u.mUid && pid == u.mPid &&
644 networkType == u.mNetworkType &&
645 TextUtils.equals(feature, u.mFeature)) {
646 found = true;
647 break;
648 }
649 }
650 }
651 if (found && u != null) {
652 // stop regardless of how many other time this proc had called start
653 return stopUsingNetworkFeature(u, true);
654 } else {
655 // none found!
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800656 if (DBG) Slog.d(TAG, "ignoring stopUsingNetworkFeature - not a live request");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700657 return 1;
658 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700659 }
660
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700661 private int stopUsingNetworkFeature(FeatureUser u, boolean ignoreDups) {
662 int networkType = u.mNetworkType;
663 String feature = u.mFeature;
664 int pid = u.mPid;
665 int uid = u.mUid;
666
667 NetworkStateTracker tracker = null;
668 boolean callTeardown = false; // used to carry our decision outside of sync block
669
Robert Greenwalt2034b912009-08-12 16:08:25 -0700670 if (DBG) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800671 Slog.d(TAG, "stopUsingNetworkFeature for net " + networkType +
Robert Greenwalt2034b912009-08-12 16:08:25 -0700672 ": " + feature);
673 }
Robert Greenwalt28f43012009-10-06 17:52:40 -0700674
The Android Open Source Project28527d22009-03-03 19:31:44 -0800675 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
676 return -1;
677 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700678
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700679 // need to link the mFeatureUsers list with the mNetRequestersPids state in this
680 // sync block
681 synchronized(this) {
682 // check if this process still has an outstanding start request
683 if (!mFeatureUsers.contains(u)) {
Robert Greenwalt46ceefa2010-03-10 16:10:43 -0800684 if (DBG) Slog.d(TAG, "ignoring - this process has no outstanding requests");
Robert Greenwalt2034b912009-08-12 16:08:25 -0700685 return 1;
686 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700687 u.unlinkDeathRecipient();
688 mFeatureUsers.remove(mFeatureUsers.indexOf(u));
689 // If we care about duplicate requests, check for that here.
690 //
691 // This is done to support the extension of a request - the app
692 // can request we start the network feature again and renew the
693 // auto-shutoff delay. Normal "stop" calls from the app though
694 // do not pay attention to duplicate requests - in effect the
695 // API does not refcount and a single stop will counter multiple starts.
696 if (ignoreDups == false) {
697 for (int i = 0; i < mFeatureUsers.size() ; i++) {
698 FeatureUser x = (FeatureUser)mFeatureUsers.get(i);
699 if (x.mUid == u.mUid && x.mPid == u.mPid &&
700 x.mNetworkType == u.mNetworkType &&
701 TextUtils.equals(x.mFeature, u.mFeature)) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800702 if (DBG) Slog.d(TAG, "ignoring stopUsingNetworkFeature as dup is found");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700703 return 1;
704 }
705 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700706 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700707
708 // TODO - move to MobileDataStateTracker
709 int usedNetworkType = networkType;
710 if (networkType == ConnectivityManager.TYPE_MOBILE) {
711 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
712 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
713 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
714 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
715 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
716 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
717 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
718 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
719 }
720 }
721 tracker = mNetTrackers[usedNetworkType];
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700722 if (tracker == null) {
Robert Greenwalt46ceefa2010-03-10 16:10:43 -0800723 if (DBG) Slog.d(TAG, "ignoring - no known tracker for net type " + usedNetworkType);
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700724 return -1;
725 }
726 if (usedNetworkType != networkType) {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700727 Integer currentPid = new Integer(pid);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700728 mNetRequestersPids[usedNetworkType].remove(currentPid);
Robert Greenwalt0ca68a02009-12-17 14:54:59 -0800729 reassessPidDns(pid, true);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700730 if (mNetRequestersPids[usedNetworkType].size() != 0) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800731 if (DBG) Slog.d(TAG, "not tearing down special network - " +
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700732 "others still using it");
733 return 1;
734 }
735 callTeardown = true;
736 }
737 }
Robert Greenwalt46ceefa2010-03-10 16:10:43 -0800738 if (DBG) Slog.d(TAG, "Doing network teardown");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700739 if (callTeardown) {
740 tracker.teardown();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700741 return 1;
742 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700743 // do it the old fashioned way
Robert Greenwalt2034b912009-08-12 16:08:25 -0700744 return tracker.stopUsingNetworkFeature(feature, pid, uid);
745 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800746 }
747
748 /**
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +0530749 * @deprecated use requestRouteToHostAddress instead
750 *
The Android Open Source Project28527d22009-03-03 19:31:44 -0800751 * Ensure that a network route exists to deliver traffic to the specified
752 * host via the specified network interface.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700753 * @param networkType the type of the network over which traffic to the
754 * specified host is to be routed
755 * @param hostAddress the IP address of the host to which the route is
756 * desired
The Android Open Source Project28527d22009-03-03 19:31:44 -0800757 * @return {@code true} on success, {@code false} on failure
758 */
759 public boolean requestRouteToHost(int networkType, int hostAddress) {
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +0530760 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
761
762 if (inetAddress == null) {
763 return false;
764 }
765
766 return requestRouteToHostAddress(networkType, inetAddress.getAddress());
767 }
768
769 /**
770 * Ensure that a network route exists to deliver traffic to the specified
771 * host via the specified network interface.
772 * @param networkType the type of the network over which traffic to the
773 * specified host is to be routed
774 * @param hostAddress the IP address of the host to which the route is
775 * desired
776 * @return {@code true} on success, {@code false} on failure
777 */
778 public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800779 enforceChangePermission();
780 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
781 return false;
782 }
783 NetworkStateTracker tracker = mNetTrackers[networkType];
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700784
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700785 if (tracker == null || !tracker.getNetworkInfo().isConnected() ||
786 tracker.isTeardownRequested()) {
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700787 if (DBG) {
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +0530788 Slog.d(TAG, "requestRouteToHostAddress on down network " +
789 "(" + networkType + ") - dropped");
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700790 }
791 return false;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800792 }
Banavathu, Srinivas Naik7601f572010-08-10 20:13:53 +0530793
794 try {
795 InetAddress inetAddress = InetAddress.getByAddress(hostAddress);
796 return tracker.requestRouteToHost(inetAddress);
797 } catch (UnknownHostException e) {
798 return false;
799 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800800 }
801
802 /**
803 * @see ConnectivityManager#getBackgroundDataSetting()
804 */
805 public boolean getBackgroundDataSetting() {
806 return Settings.Secure.getInt(mContext.getContentResolver(),
807 Settings.Secure.BACKGROUND_DATA, 1) == 1;
808 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700809
The Android Open Source Project28527d22009-03-03 19:31:44 -0800810 /**
811 * @see ConnectivityManager#setBackgroundDataSetting(boolean)
812 */
813 public void setBackgroundDataSetting(boolean allowBackgroundDataUsage) {
814 mContext.enforceCallingOrSelfPermission(
815 android.Manifest.permission.CHANGE_BACKGROUND_DATA_SETTING,
816 "ConnectivityService");
Robert Greenwalt0659da32009-07-16 17:21:39 -0700817
The Android Open Source Project28527d22009-03-03 19:31:44 -0800818 if (getBackgroundDataSetting() == allowBackgroundDataUsage) return;
819
820 Settings.Secure.putInt(mContext.getContentResolver(),
Robert Greenwalt0659da32009-07-16 17:21:39 -0700821 Settings.Secure.BACKGROUND_DATA,
822 allowBackgroundDataUsage ? 1 : 0);
823
The Android Open Source Project28527d22009-03-03 19:31:44 -0800824 Intent broadcast = new Intent(
825 ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
826 mContext.sendBroadcast(broadcast);
Robert Greenwalt0659da32009-07-16 17:21:39 -0700827 }
828
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800829 /**
830 * @see ConnectivityManager#getMobileDataEnabled()
831 */
832 public boolean getMobileDataEnabled() {
833 enforceAccessPermission();
834 boolean retVal = Settings.Secure.getInt(mContext.getContentResolver(),
835 Settings.Secure.MOBILE_DATA, 1) == 1;
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800836 if (DBG) Slog.d(TAG, "getMobileDataEnabled returning " + retVal);
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800837 return retVal;
838 }
839
840 /**
841 * @see ConnectivityManager#setMobileDataEnabled(boolean)
842 */
843 public synchronized void setMobileDataEnabled(boolean enabled) {
844 enforceChangePermission();
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800845 if (DBG) Slog.d(TAG, "setMobileDataEnabled(" + enabled + ")");
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800846
847 if (getMobileDataEnabled() == enabled) return;
848
849 Settings.Secure.putInt(mContext.getContentResolver(),
850 Settings.Secure.MOBILE_DATA, enabled ? 1 : 0);
851
852 if (enabled) {
853 if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800854 if (DBG) Slog.d(TAG, "starting up " + mNetTrackers[ConnectivityManager.TYPE_MOBILE]);
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800855 mNetTrackers[ConnectivityManager.TYPE_MOBILE].reconnect();
856 }
857 } else {
858 for (NetworkStateTracker nt : mNetTrackers) {
859 if (nt == null) continue;
860 int netType = nt.getNetworkInfo().getType();
861 if (mNetAttributes[netType].mRadio == ConnectivityManager.TYPE_MOBILE) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -0800862 if (DBG) Slog.d(TAG, "tearing down " + nt);
Robert Greenwalt1b21f6c2010-02-23 18:58:05 -0800863 nt.teardown();
864 }
865 }
866 }
867 }
868
The Android Open Source Project28527d22009-03-03 19:31:44 -0800869 private int getNumConnectedNetworks() {
870 int numConnectedNets = 0;
871
872 for (NetworkStateTracker nt : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700873 if (nt != null && nt.getNetworkInfo().isConnected() &&
Robert Greenwalt0659da32009-07-16 17:21:39 -0700874 !nt.isTeardownRequested()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800875 ++numConnectedNets;
876 }
877 }
878 return numConnectedNets;
879 }
880
881 private void enforceAccessPermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700882 mContext.enforceCallingOrSelfPermission(
883 android.Manifest.permission.ACCESS_NETWORK_STATE,
884 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800885 }
886
887 private void enforceChangePermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700888 mContext.enforceCallingOrSelfPermission(
889 android.Manifest.permission.CHANGE_NETWORK_STATE,
890 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800891 }
892
Robert Greenwalt0c4828c2010-01-26 11:40:34 -0800893 // TODO Make this a special check when it goes public
894 private void enforceTetherChangePermission() {
895 mContext.enforceCallingOrSelfPermission(
896 android.Manifest.permission.CHANGE_NETWORK_STATE,
897 "ConnectivityService");
898 }
899
Robert Greenwalt8e87f122010-02-11 18:18:40 -0800900 private void enforceTetherAccessPermission() {
901 mContext.enforceCallingOrSelfPermission(
902 android.Manifest.permission.ACCESS_NETWORK_STATE,
903 "ConnectivityService");
904 }
905
The Android Open Source Project28527d22009-03-03 19:31:44 -0800906 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700907 * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
908 * network, we ignore it. If it is for the active network, we send out a
909 * broadcast. But first, we check whether it might be possible to connect
910 * to a different network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800911 * @param info the {@code NetworkInfo} for the network
912 */
913 private void handleDisconnect(NetworkInfo info) {
914
Robert Greenwalt2034b912009-08-12 16:08:25 -0700915 int prevNetType = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800916
Robert Greenwalt2034b912009-08-12 16:08:25 -0700917 mNetTrackers[prevNetType].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800918 /*
919 * If the disconnected network is not the active one, then don't report
920 * this as a loss of connectivity. What probably happened is that we're
921 * getting the disconnect for a network that we explicitly disabled
922 * in accordance with network preference policies.
923 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700924 if (!mNetAttributes[prevNetType].isDefault()) {
925 List pids = mNetRequestersPids[prevNetType];
926 for (int i = 0; i<pids.size(); i++) {
927 Integer pid = (Integer)pids.get(i);
928 // will remove them because the net's no longer connected
929 // need to do this now as only now do we know the pids and
930 // can properly null things that are no longer referenced.
931 reassessPidDns(pid.intValue(), false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800932 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800933 }
934
The Android Open Source Project28527d22009-03-03 19:31:44 -0800935 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
936 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
937 if (info.isFailover()) {
938 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
939 info.setFailover(false);
940 }
941 if (info.getReason() != null) {
942 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
943 }
944 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700945 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
946 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -0800947 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700948
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800949 NetworkStateTracker newNet = null;
950 if (mNetAttributes[prevNetType].isDefault()) {
951 newNet = tryFailover(prevNetType);
952 if (newNet != null) {
953 NetworkInfo switchTo = newNet.getNetworkInfo();
Robert Greenwaltb2a9e492010-09-20 18:01:43 -0700954 if (!switchTo.isConnected()) {
955 // if the other net is connected they've already reset this and perhaps even gotten
956 // a positive report we don't want to overwrite, but if not we need to clear this now
957 // to turn our cellular sig strength white
958 mDefaultInetConditionPublished = 0;
959 }
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800960 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
961 } else {
Robert Greenwaltb2a9e492010-09-20 18:01:43 -0700962 mDefaultInetConditionPublished = 0; // we're not connected anymore
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800963 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
964 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800965 }
Robert Greenwaltb2a9e492010-09-20 18:01:43 -0700966 intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800967 // do this before we broadcast the change
Robert Greenwalt0ef68752010-08-13 14:16:12 -0700968 handleConnectivityChange(prevNetType);
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800969
970 sendStickyBroadcast(intent);
971 /*
972 * If the failover network is already connected, then immediately send
973 * out a followup broadcast indicating successful failover
974 */
975 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
976 sendConnectedBroadcast(newNet.getNetworkInfo());
977 }
978 }
979
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800980 // returns null if no failover available
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800981 private NetworkStateTracker tryFailover(int prevNetType) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700982 /*
983 * If this is a default network, check if other defaults are available
984 * or active
985 */
986 NetworkStateTracker newNet = null;
987 if (mNetAttributes[prevNetType].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700988 if (mActiveDefaultNetwork == prevNetType) {
989 mActiveDefaultNetwork = -1;
990 }
991
992 int newType = -1;
993 int newPriority = -1;
Robert Greenwalt72451bf2010-02-25 12:04:29 -0800994 boolean noMobileData = !getMobileDataEnabled();
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800995 for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700996 if (checkType == prevNetType) continue;
997 if (mNetAttributes[checkType] == null) continue;
Robert Greenwalt72451bf2010-02-25 12:04:29 -0800998 if (mNetAttributes[checkType].mRadio == ConnectivityManager.TYPE_MOBILE &&
999 noMobileData) {
1000 if (DBG) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001001 Slog.d(TAG, "not failing over to mobile type " + checkType +
Robert Greenwalt72451bf2010-02-25 12:04:29 -08001002 " because Mobile Data Disabled");
1003 }
1004 continue;
1005 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001006 if (mNetAttributes[checkType].isDefault()) {
1007 /* TODO - if we have multiple nets we could use
1008 * we may want to put more thought into which we choose
1009 */
1010 if (checkType == mNetworkPreference) {
1011 newType = checkType;
1012 break;
1013 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -07001014 if (mNetAttributes[checkType].mPriority > newPriority) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001015 newType = checkType;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -07001016 newPriority = mNetAttributes[newType].mPriority;
Robert Greenwalt2034b912009-08-12 16:08:25 -07001017 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001018 }
1019 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001020
1021 if (newType != -1) {
1022 newNet = mNetTrackers[newType];
1023 /**
1024 * See if the other network is available to fail over to.
1025 * If is not available, we enable it anyway, so that it
1026 * will be able to connect when it does become available,
1027 * but we report a total loss of connectivity rather than
1028 * report that we are attempting to fail over.
1029 */
1030 if (newNet.isAvailable()) {
1031 NetworkInfo switchTo = newNet.getNetworkInfo();
1032 switchTo.setFailover(true);
Robert Greenwalta52c75a2009-08-19 20:19:33 -07001033 if (!switchTo.isConnectedOrConnecting() ||
1034 newNet.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001035 newNet.reconnect();
1036 }
1037 if (DBG) {
1038 if (switchTo.isConnected()) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001039 Slog.v(TAG, "Switching to already connected " +
Robert Greenwalt2034b912009-08-12 16:08:25 -07001040 switchTo.getTypeName());
1041 } else {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001042 Slog.v(TAG, "Attempting to switch to " +
Robert Greenwalt2034b912009-08-12 16:08:25 -07001043 switchTo.getTypeName());
1044 }
1045 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001046 } else {
1047 newNet.reconnect();
Robert Greenwalt12984322010-03-09 14:55:08 -08001048 newNet = null; // not officially avail.. try anyway, but
1049 // report no failover
Robert Greenwalt2034b912009-08-12 16:08:25 -07001050 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001051 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001052 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001053
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001054 return newNet;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001055 }
1056
1057 private void sendConnectedBroadcast(NetworkInfo info) {
Robert Greenwaltd3401f92010-09-15 17:36:33 -07001058 sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
1059 }
1060
1061 private void sendInetConditionBroadcast(NetworkInfo info) {
1062 sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
1063 }
1064
1065 private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
1066 Intent intent = new Intent(bcastType);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001067 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
1068 if (info.isFailover()) {
1069 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
1070 info.setFailover(false);
1071 }
1072 if (info.getReason() != null) {
1073 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
1074 }
1075 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001076 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
1077 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001078 }
Robert Greenwalt986c7412010-09-08 15:24:47 -07001079 intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001080 sendStickyBroadcast(intent);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001081 }
1082
1083 /**
1084 * Called when an attempt to fail over to another network has failed.
1085 * @param info the {@link NetworkInfo} for the failed network
1086 */
1087 private void handleConnectionFailure(NetworkInfo info) {
1088 mNetTrackers[info.getType()].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001089
Robert Greenwalt2034b912009-08-12 16:08:25 -07001090 String reason = info.getReason();
1091 String extraInfo = info.getExtraInfo();
Robert Greenwalt0659da32009-07-16 17:21:39 -07001092
Robert Greenwalt2034b912009-08-12 16:08:25 -07001093 if (DBG) {
1094 String reasonText;
1095 if (reason == null) {
1096 reasonText = ".";
1097 } else {
1098 reasonText = " (" + reason + ").";
The Android Open Source Project28527d22009-03-03 19:31:44 -08001099 }
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001100 Slog.v(TAG, "Attempt to connect to " + info.getTypeName() +
Robert Greenwalt2034b912009-08-12 16:08:25 -07001101 " failed" + reasonText);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001102 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001103
1104 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
1105 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
1106 if (getActiveNetworkInfo() == null) {
1107 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
1108 }
1109 if (reason != null) {
1110 intent.putExtra(ConnectivityManager.EXTRA_REASON, reason);
1111 }
1112 if (extraInfo != null) {
1113 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, extraInfo);
1114 }
1115 if (info.isFailover()) {
1116 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
1117 info.setFailover(false);
1118 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001119
Robert Greenwalt3cc68d32010-01-25 17:54:29 -08001120 NetworkStateTracker newNet = null;
1121 if (mNetAttributes[info.getType()].isDefault()) {
1122 newNet = tryFailover(info.getType());
1123 if (newNet != null) {
1124 NetworkInfo switchTo = newNet.getNetworkInfo();
Robert Greenwaltb2a9e492010-09-20 18:01:43 -07001125 if (!switchTo.isConnected()) {
1126 // if the other net is connected they've already reset this and perhaps even gotten
1127 // a positive report we don't want to overwrite, but if not we need to clear this now
1128 // to turn our cellular sig strength white
1129 mDefaultInetConditionPublished = 0;
1130 }
Robert Greenwalt3cc68d32010-01-25 17:54:29 -08001131 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
1132 } else {
Robert Greenwaltb2a9e492010-09-20 18:01:43 -07001133 mDefaultInetConditionPublished = 0;
Robert Greenwalt3cc68d32010-01-25 17:54:29 -08001134 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
1135 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001136 }
Robert Greenwalt3cc68d32010-01-25 17:54:29 -08001137
Robert Greenwaltb2a9e492010-09-20 18:01:43 -07001138 intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001139 sendStickyBroadcast(intent);
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001140 /*
1141 * If the failover network is already connected, then immediately send
1142 * out a followup broadcast indicating successful failover
1143 */
1144 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
1145 sendConnectedBroadcast(newNet.getNetworkInfo());
1146 }
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001147 }
1148
1149 private void sendStickyBroadcast(Intent intent) {
1150 synchronized(this) {
Dianne Hackborna417ff82009-12-08 19:45:14 -08001151 if (!mSystemReady) {
1152 mInitialBroadcast = new Intent(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001153 }
Dianne Hackborna417ff82009-12-08 19:45:14 -08001154 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1155 mContext.sendStickyBroadcast(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001156 }
1157 }
1158
1159 void systemReady() {
1160 synchronized(this) {
1161 mSystemReady = true;
Dianne Hackborna417ff82009-12-08 19:45:14 -08001162 if (mInitialBroadcast != null) {
1163 mContext.sendStickyBroadcast(mInitialBroadcast);
1164 mInitialBroadcast = null;
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001165 }
1166 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001167 }
1168
1169 private void handleConnect(NetworkInfo info) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001170 int type = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001171
1172 // snapshot isFailover, because sendConnectedBroadcast() resets it
1173 boolean isFailover = info.isFailover();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001174 NetworkStateTracker thisNet = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -08001175
Robert Greenwalt2034b912009-08-12 16:08:25 -07001176 // if this is a default net and other default is running
1177 // kill the one not preferred
1178 if (mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001179 if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
1180 if ((type != mNetworkPreference &&
1181 mNetAttributes[mActiveDefaultNetwork].mPriority >
1182 mNetAttributes[type].mPriority) ||
1183 mNetworkPreference == mActiveDefaultNetwork) {
1184 // don't accept this one
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001185 if (DBG) Slog.v(TAG, "Not broadcasting CONNECT_ACTION " +
Robert Greenwalt2034b912009-08-12 16:08:25 -07001186 "to torn down network " + info.getTypeName());
1187 teardown(thisNet);
1188 return;
1189 } else {
1190 // tear down the other
1191 NetworkStateTracker otherNet =
1192 mNetTrackers[mActiveDefaultNetwork];
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001193 if (DBG) Slog.v(TAG, "Policy requires " +
Robert Greenwalt2034b912009-08-12 16:08:25 -07001194 otherNet.getNetworkInfo().getTypeName() +
1195 " teardown");
1196 if (!teardown(otherNet)) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001197 Slog.e(TAG, "Network declined teardown request");
Robert Greenwalt2034b912009-08-12 16:08:25 -07001198 return;
1199 }
1200 if (isFailover) {
1201 otherNet.releaseWakeLock();
1202 }
1203 }
1204 }
1205 mActiveDefaultNetwork = type;
Robert Greenwalt986c7412010-09-08 15:24:47 -07001206 // this will cause us to come up initially as unconnected and switching
1207 // to connected after our normal pause unless somebody reports us as reall
1208 // disconnected
1209 mDefaultInetConditionPublished = 0;
1210 mDefaultConnectionSequence++;
1211 mInetConditionChangeInFlight = false;
1212 // Don't do this - if we never sign in stay, grey
1213 //reportNetworkCondition(mActiveDefaultNetwork, 100);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001214 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001215 thisNet.setTeardownRequested(false);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001216 thisNet.updateNetworkSettings();
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001217 handleConnectivityChange(type);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001218 sendConnectedBroadcast(info);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001219 }
1220
1221 private void handleScanResultsAvailable(NetworkInfo info) {
1222 int networkType = info.getType();
1223 if (networkType != ConnectivityManager.TYPE_WIFI) {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001224 if (DBG) Slog.v(TAG, "Got ScanResultsAvailable for " +
Robert Greenwalt0659da32009-07-16 17:21:39 -07001225 info.getTypeName() + " network. Don't know how to handle.");
The Android Open Source Project28527d22009-03-03 19:31:44 -08001226 }
Robert Greenwalt0659da32009-07-16 17:21:39 -07001227
The Android Open Source Project28527d22009-03-03 19:31:44 -08001228 mNetTrackers[networkType].interpretScanResultsAvailable();
1229 }
1230
Robert Greenwalt0659da32009-07-16 17:21:39 -07001231 private void handleNotificationChange(boolean visible, int id,
1232 Notification notification) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001233 NotificationManager notificationManager = (NotificationManager) mContext
1234 .getSystemService(Context.NOTIFICATION_SERVICE);
Robert Greenwalt0659da32009-07-16 17:21:39 -07001235
The Android Open Source Project28527d22009-03-03 19:31:44 -08001236 if (visible) {
1237 notificationManager.notify(id, notification);
1238 } else {
1239 notificationManager.cancel(id);
1240 }
1241 }
1242
1243 /**
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001244 * After a change in the connectivity state of any network, We're mainly
1245 * concerned with making sure that the list of DNS servers is setupup
1246 * according to which networks are connected, and ensuring that the
1247 * right routing table entries exist.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001248 */
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001249 private void handleConnectivityChange(int netType) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001250 /*
Robert Greenwalt2034b912009-08-12 16:08:25 -07001251 * If a non-default network is enabled, add the host routes that
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001252 * will allow it's DNS servers to be accessed.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001253 */
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001254 handleDnsConfigurationChange(netType);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001255
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001256 if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
1257 if (mNetAttributes[netType].isDefault()) {
1258 mNetTrackers[netType].addDefaultRoute();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001259 } else {
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001260 mNetTrackers[netType].addPrivateDnsRoutes();
1261 }
1262 } else {
1263 if (mNetAttributes[netType].isDefault()) {
1264 mNetTrackers[netType].removeDefaultRoute();
1265 } else {
1266 mNetTrackers[netType].removePrivateDnsRoutes();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001267 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001268 }
1269 }
1270
Robert Greenwalt2034b912009-08-12 16:08:25 -07001271 /**
1272 * Adjust the per-process dns entries (net.dns<x>.<pid>) based
1273 * on the highest priority active net which this process requested.
1274 * If there aren't any, clear it out
1275 */
1276 private void reassessPidDns(int myPid, boolean doBump)
1277 {
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001278 if (DBG) Slog.d(TAG, "reassessPidDns for pid " + myPid);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001279 for(int i : mPriorityList) {
1280 if (mNetAttributes[i].isDefault()) {
1281 continue;
1282 }
1283 NetworkStateTracker nt = mNetTrackers[i];
Robert Greenwalt0659da32009-07-16 17:21:39 -07001284 if (nt.getNetworkInfo().isConnected() &&
1285 !nt.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001286 List pids = mNetRequestersPids[i];
1287 for (int j=0; j<pids.size(); j++) {
1288 Integer pid = (Integer)pids.get(j);
1289 if (pid.intValue() == myPid) {
1290 String[] dnsList = nt.getNameServers();
1291 writePidDns(dnsList, myPid);
1292 if (doBump) {
1293 bumpDns();
1294 }
1295 return;
1296 }
1297 }
1298 }
1299 }
1300 // nothing found - delete
1301 for (int i = 1; ; i++) {
1302 String prop = "net.dns" + i + "." + myPid;
1303 if (SystemProperties.get(prop).length() == 0) {
1304 if (doBump) {
1305 bumpDns();
1306 }
1307 return;
1308 }
1309 SystemProperties.set(prop, "");
1310 }
1311 }
1312
1313 private void writePidDns(String[] dnsList, int pid) {
1314 int j = 1;
1315 for (String dns : dnsList) {
1316 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
1317 SystemProperties.set("net.dns" + j++ + "." + pid, dns);
1318 }
1319 }
1320 }
1321
1322 private void bumpDns() {
1323 /*
1324 * Bump the property that tells the name resolver library to reread
1325 * the DNS server list from the properties.
1326 */
1327 String propVal = SystemProperties.get("net.dnschange");
1328 int n = 0;
1329 if (propVal.length() != 0) {
1330 try {
1331 n = Integer.parseInt(propVal);
1332 } catch (NumberFormatException e) {}
1333 }
1334 SystemProperties.set("net.dnschange", "" + (n+1));
1335 }
1336
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001337 private void handleDnsConfigurationChange(int netType) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001338 // add default net's dns entries
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001339 NetworkStateTracker nt = mNetTrackers[netType];
1340 if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
1341 String[] dnsList = nt.getNameServers();
1342 if (mNetAttributes[netType].isDefault()) {
1343 int j = 1;
1344 for (String dns : dnsList) {
1345 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
1346 if (DBG) {
1347 Slog.d(TAG, "adding dns " + dns + " for " +
1348 nt.getNetworkInfo().getTypeName());
Robert Greenwalt2034b912009-08-12 16:08:25 -07001349 }
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001350 SystemProperties.set("net.dns" + j++, dns);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001351 }
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001352 }
1353 for (int k=j ; k<mNumDnsEntries; k++) {
1354 if (DBG) Slog.d(TAG, "erasing net.dns" + k);
1355 SystemProperties.set("net.dns" + k, "");
1356 }
1357 mNumDnsEntries = j;
1358 } else {
1359 // set per-pid dns for attached secondary nets
1360 List pids = mNetRequestersPids[netType];
1361 for (int y=0; y< pids.size(); y++) {
1362 Integer pid = (Integer)pids.get(y);
1363 writePidDns(dnsList, pid.intValue());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001364 }
1365 }
1366 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001367 bumpDns();
1368 }
1369
1370 private int getRestoreDefaultNetworkDelay() {
1371 String restoreDefaultNetworkDelayStr = SystemProperties.get(
1372 NETWORK_RESTORE_DELAY_PROP_NAME);
1373 if(restoreDefaultNetworkDelayStr != null &&
1374 restoreDefaultNetworkDelayStr.length() != 0) {
1375 try {
1376 return Integer.valueOf(restoreDefaultNetworkDelayStr);
1377 } catch (NumberFormatException e) {
1378 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001379 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001380 return RESTORE_DEFAULT_NETWORK_DELAY;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001381 }
1382
1383 @Override
1384 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001385 if (mContext.checkCallingOrSelfPermission(
1386 android.Manifest.permission.DUMP)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001387 != PackageManager.PERMISSION_GRANTED) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001388 pw.println("Permission Denial: can't dump ConnectivityService " +
1389 "from from pid=" + Binder.getCallingPid() + ", uid=" +
1390 Binder.getCallingUid());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001391 return;
1392 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001393 pw.println();
1394 for (NetworkStateTracker nst : mNetTrackers) {
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001395 if (nst != null) {
1396 if (nst.getNetworkInfo().isConnected()) {
1397 pw.println("Active network: " + nst.getNetworkInfo().
1398 getTypeName());
1399 }
1400 pw.println(nst.getNetworkInfo());
1401 pw.println(nst);
1402 pw.println();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001403 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001404 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001405
1406 pw.println("Network Requester Pids:");
1407 for (int net : mPriorityList) {
1408 String pidString = net + ": ";
1409 for (Object pid : mNetRequestersPids[net]) {
1410 pidString = pidString + pid.toString() + ", ";
1411 }
1412 pw.println(pidString);
1413 }
1414 pw.println();
1415
1416 pw.println("FeatureUsers:");
1417 for (Object requester : mFeatureUsers) {
1418 pw.println(requester.toString());
1419 }
1420 pw.println();
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001421
1422 mTethering.dump(fd, pw, args);
Robert Greenwalt0e80be12010-09-20 14:35:25 -07001423
1424 if (mInetLog != null) {
1425 pw.println();
1426 pw.println("Inet condition reports:");
1427 for(int i = 0; i < mInetLog.size(); i++) {
1428 pw.println(mInetLog.get(i));
1429 }
1430 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001431 }
1432
Robert Greenwalt2034b912009-08-12 16:08:25 -07001433 // must be stateless - things change under us.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001434 private class MyHandler extends Handler {
1435 @Override
1436 public void handleMessage(Message msg) {
1437 NetworkInfo info;
1438 switch (msg.what) {
1439 case NetworkStateTracker.EVENT_STATE_CHANGED:
1440 info = (NetworkInfo) msg.obj;
Robert Greenwalt12c44552009-12-07 11:33:18 -08001441 int type = info.getType();
1442 NetworkInfo.State state = info.getState();
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001443 // only do this optimization for wifi. It going into scan mode for location
1444 // services generates alot of noise. Meanwhile the mms apn won't send out
1445 // subsequent notifications when on default cellular because it never
1446 // disconnects.. so only do this to wifi notifications. Fixed better when the
1447 // APN notifications are standardized.
1448 if (mNetAttributes[type].mLastState == state &&
1449 mNetAttributes[type].mRadio == ConnectivityManager.TYPE_WIFI) {
Robert Greenwalt12c44552009-12-07 11:33:18 -08001450 if (DBG) {
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001451 // TODO - remove this after we validate the dropping doesn't break
1452 // anything
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001453 Slog.d(TAG, "Dropping ConnectivityChange for " +
Robert Greenwalt2adbc7f2010-01-13 09:36:31 -08001454 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001455 state + "/" + info.getDetailedState());
1456 }
1457 return;
1458 }
1459 mNetAttributes[type].mLastState = state;
1460
Joe Onoratoc2386bb2010-02-26 18:56:32 -08001461 if (DBG) Slog.d(TAG, "ConnectivityChange for " +
Robert Greenwalt0659da32009-07-16 17:21:39 -07001462 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001463 state + "/" + info.getDetailedState());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001464
1465 // Connectivity state changed:
1466 // [31-13] Reserved for future use
Robert Greenwalt0659da32009-07-16 17:21:39 -07001467 // [12-9] Network subtype (for mobile network, as defined
1468 // by TelephonyManager)
1469 // [8-3] Detailed state ordinal (as defined by
1470 // NetworkInfo.DetailedState)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001471 // [2-0] Network type (as defined by ConnectivityManager)
1472 int eventLogParam = (info.getType() & 0x7) |
1473 ((info.getDetailedState().ordinal() & 0x3f) << 3) |
1474 (info.getSubtype() << 9);
Doug Zongker2fc96232009-12-04 10:31:43 -08001475 EventLog.writeEvent(EventLogTags.CONNECTIVITY_STATE_CHANGED,
Robert Greenwalt0659da32009-07-16 17:21:39 -07001476 eventLogParam);
1477
1478 if (info.getDetailedState() ==
1479 NetworkInfo.DetailedState.FAILED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001480 handleConnectionFailure(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001481 } else if (state == NetworkInfo.State.DISCONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001482 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001483 } else if (state == NetworkInfo.State.SUSPENDED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001484 // TODO: need to think this over.
Robert Greenwalt0659da32009-07-16 17:21:39 -07001485 // the logic here is, handle SUSPENDED the same as
1486 // DISCONNECTED. The only difference being we are
1487 // broadcasting an intent with NetworkInfo that's
1488 // suspended. This allows the applications an
1489 // opportunity to handle DISCONNECTED and SUSPENDED
1490 // differently, or not.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001491 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001492 } else if (state == NetworkInfo.State.CONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001493 handleConnect(info);
1494 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001495 break;
1496
1497 case NetworkStateTracker.EVENT_SCAN_RESULTS_AVAILABLE:
1498 info = (NetworkInfo) msg.obj;
1499 handleScanResultsAvailable(info);
1500 break;
Robert Greenwalt0659da32009-07-16 17:21:39 -07001501
The Android Open Source Project28527d22009-03-03 19:31:44 -08001502 case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
Robert Greenwalt0659da32009-07-16 17:21:39 -07001503 handleNotificationChange(msg.arg1 == 1, msg.arg2,
1504 (Notification) msg.obj);
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001505 break;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001506
1507 case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
Robert Greenwalt0ef68752010-08-13 14:16:12 -07001508 info = (NetworkInfo) msg.obj;
1509 type = info.getType();
1510 handleDnsConfigurationChange(type);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001511 break;
1512
1513 case NetworkStateTracker.EVENT_ROAMING_CHANGED:
1514 // fill me in
1515 break;
1516
1517 case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED:
1518 // fill me in
1519 break;
Robert Greenwalt2034b912009-08-12 16:08:25 -07001520 case NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK:
Robert Greenwaltaffc3a12009-09-27 17:27:04 -07001521 FeatureUser u = (FeatureUser)msg.obj;
1522 u.expire();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001523 break;
Robert Greenwalt986c7412010-09-08 15:24:47 -07001524 case NetworkStateTracker.EVENT_INET_CONDITION_CHANGE:
1525 if (DBG) {
1526 Slog.d(TAG, "Inet connectivity change, net=" +
1527 msg.arg1 + ", condition=" + msg.arg2 +
1528 ",mActiveDefaultNetwork=" + mActiveDefaultNetwork);
1529 }
1530 if (mActiveDefaultNetwork == -1) {
1531 if (DBG) Slog.d(TAG, "no active default network - aborting");
1532 break;
1533 }
1534 if (mActiveDefaultNetwork != msg.arg1) {
1535 if (DBG) Slog.d(TAG, "given net not default - aborting");
1536 break;
1537 }
1538 mDefaultInetCondition = msg.arg2;
1539 int delay;
1540 if (mInetConditionChangeInFlight == false) {
1541 if (DBG) Slog.d(TAG, "starting a change hold");
1542 // setup a new hold to debounce this
1543 if (mDefaultInetCondition > 50) {
1544 delay = Settings.Secure.getInt(mContext.getContentResolver(),
1545 Settings.Secure.INET_CONDITION_DEBOUNCE_UP_DELAY, 500);
1546 } else {
1547 delay = Settings.Secure.getInt(mContext.getContentResolver(),
1548 Settings.Secure.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 3000);
1549 }
1550 mInetConditionChangeInFlight = true;
1551 sendMessageDelayed(obtainMessage(
1552 NetworkStateTracker.EVENT_INET_CONDITION_HOLD_END,
1553 mActiveDefaultNetwork, mDefaultConnectionSequence), delay);
1554 } else {
1555 // we've set the new condition, when this hold ends that will get
1556 // picked up
1557 if (DBG) Slog.d(TAG, "currently in hold - not setting new end evt");
1558 }
1559 break;
1560 case NetworkStateTracker.EVENT_INET_CONDITION_HOLD_END:
1561 if (DBG) {
1562 Slog.d(TAG, "Inet hold end, net=" + msg.arg1 +
1563 ", condition =" + mDefaultInetCondition +
1564 ", published condition =" + mDefaultInetConditionPublished);
1565 }
1566 mInetConditionChangeInFlight = false;
1567
1568 if (mActiveDefaultNetwork == -1) {
1569 if (DBG) Slog.d(TAG, "no active default network - aborting");
1570 break;
1571 }
1572 if (mDefaultConnectionSequence != msg.arg2) {
1573 if (DBG) Slog.d(TAG, "event hold for obsolete network - aborting");
1574 break;
1575 }
1576 if (mDefaultInetConditionPublished == mDefaultInetCondition) {
1577 if (DBG) Slog.d(TAG, "no change in condition - aborting");
1578 break;
1579 }
1580 NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
1581 if (networkInfo.isConnected() == false) {
1582 if (DBG) Slog.d(TAG, "default network not connected - aborting");
1583 break;
1584 }
1585 mDefaultInetConditionPublished = mDefaultInetCondition;
Robert Greenwaltd3401f92010-09-15 17:36:33 -07001586 sendInetConditionBroadcast(networkInfo);
Robert Greenwalt986c7412010-09-08 15:24:47 -07001587 break;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001588 }
1589 }
1590 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001591
1592 // javadoc from interface
Robert Greenwalt4283ded2010-03-02 17:25:02 -08001593 public int tether(String iface) {
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001594 enforceTetherChangePermission();
Robert Greenwalt4283ded2010-03-02 17:25:02 -08001595
1596 if (isTetheringSupported()) {
1597 return mTethering.tether(iface);
1598 } else {
1599 return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
1600 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001601 }
1602
1603 // javadoc from interface
Robert Greenwalt4283ded2010-03-02 17:25:02 -08001604 public int untether(String iface) {
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001605 enforceTetherChangePermission();
Robert Greenwalt4283ded2010-03-02 17:25:02 -08001606
1607 if (isTetheringSupported()) {
1608 return mTethering.untether(iface);
1609 } else {
1610 return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
1611 }
1612 }
1613
1614 // javadoc from interface
1615 public int getLastTetherError(String iface) {
1616 enforceTetherAccessPermission();
1617
1618 if (isTetheringSupported()) {
1619 return mTethering.getLastTetherError(iface);
1620 } else {
1621 return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
1622 }
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001623 }
1624
1625 // TODO - proper iface API for selection by property, inspection, etc
1626 public String[] getTetherableUsbRegexs() {
1627 enforceTetherAccessPermission();
1628 if (isTetheringSupported()) {
1629 return mTethering.getTetherableUsbRegexs();
1630 } else {
1631 return new String[0];
1632 }
1633 }
1634
1635 public String[] getTetherableWifiRegexs() {
1636 enforceTetherAccessPermission();
1637 if (isTetheringSupported()) {
1638 return mTethering.getTetherableWifiRegexs();
1639 } else {
1640 return new String[0];
1641 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001642 }
1643
1644 // TODO - move iface listing, queries, etc to new module
1645 // javadoc from interface
1646 public String[] getTetherableIfaces() {
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001647 enforceTetherAccessPermission();
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001648 return mTethering.getTetherableIfaces();
1649 }
1650
1651 public String[] getTetheredIfaces() {
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001652 enforceTetherAccessPermission();
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001653 return mTethering.getTetheredIfaces();
1654 }
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001655
Robert Greenwalt4283ded2010-03-02 17:25:02 -08001656 public String[] getTetheringErroredIfaces() {
1657 enforceTetherAccessPermission();
1658 return mTethering.getErroredIfaces();
1659 }
1660
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001661 // if ro.tether.denied = true we default to no tethering
1662 // gservices could set the secure setting to 1 though to enable it on a build where it
1663 // had previously been turned off.
1664 public boolean isTetheringSupported() {
1665 enforceTetherAccessPermission();
1666 int defaultVal = (SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1);
Robert Greenwaltf1b66e12010-02-25 12:29:30 -08001667 boolean tetherEnabledInSettings = (Settings.Secure.getInt(mContext.getContentResolver(),
1668 Settings.Secure.TETHER_SUPPORTED, defaultVal) != 0);
1669 return tetherEnabledInSettings && mTetheringConfigValid;
Robert Greenwalt8e87f122010-02-11 18:18:40 -08001670 }
Robert Greenwalt986c7412010-09-08 15:24:47 -07001671
1672 // 100 percent is full good, 0 is full bad.
1673 public void reportInetCondition(int networkType, int percentage) {
1674 if (DBG) Slog.d(TAG, "reportNetworkCondition(" + networkType + ", " + percentage + ")");
1675 mContext.enforceCallingOrSelfPermission(
1676 android.Manifest.permission.STATUS_BAR,
1677 "ConnectivityService");
1678
Robert Greenwalt0e80be12010-09-20 14:35:25 -07001679 if (DBG) {
1680 int pid = getCallingPid();
1681 int uid = getCallingUid();
1682 String s = pid + "(" + uid + ") reports inet is " +
1683 (percentage > 50 ? "connected" : "disconnected") + " (" + percentage + ") on " +
1684 "network Type " + networkType + " at " + GregorianCalendar.getInstance().getTime();
1685 mInetLog.add(s);
1686 while(mInetLog.size() > INET_CONDITION_LOG_MAX_SIZE) {
1687 mInetLog.remove(0);
1688 }
1689 }
Robert Greenwalt986c7412010-09-08 15:24:47 -07001690 mHandler.sendMessage(mHandler.obtainMessage(
1691 NetworkStateTracker.EVENT_INET_CONDITION_CHANGE, networkType, percentage));
1692 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001693}