blob: aa4956f1573ee2d04ad9ffdf9ec92d8cce3e5e5a [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;
30import android.net.wifi.WifiStateTracker;
31import android.os.Binder;
32import android.os.Handler;
Robert Greenwalt2034b912009-08-12 16:08:25 -070033import android.os.IBinder;
The Android Open Source Project28527d22009-03-03 19:31:44 -080034import android.os.Looper;
35import android.os.Message;
Robert Greenwalt2034b912009-08-12 16:08:25 -070036import android.os.RemoteException;
The Android Open Source Project28527d22009-03-03 19:31:44 -080037import android.os.ServiceManager;
38import android.os.SystemProperties;
39import android.provider.Settings;
Robert Greenwalt2034b912009-08-12 16:08:25 -070040import android.text.TextUtils;
The Android Open Source Project28527d22009-03-03 19:31:44 -080041import android.util.EventLog;
42import android.util.Log;
43
Robert Greenwalt2034b912009-08-12 16:08:25 -070044import com.android.internal.telephony.Phone;
45
The Android Open Source Project28527d22009-03-03 19:31:44 -080046import java.io.FileDescriptor;
47import java.io.PrintWriter;
Robert Greenwalt2034b912009-08-12 16:08:25 -070048import java.util.ArrayList;
49import java.util.List;
The Android Open Source Project28527d22009-03-03 19:31:44 -080050
51/**
52 * @hide
53 */
54public class ConnectivityService extends IConnectivityManager.Stub {
55
Robert Greenwalta25fd712009-10-06 14:12:53 -070056 private static final boolean DBG = true;
The Android Open Source Project28527d22009-03-03 19:31:44 -080057 private static final String TAG = "ConnectivityService";
58
Robert Greenwalt2034b912009-08-12 16:08:25 -070059 // how long to wait before switching back to a radio's default network
60 private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
61 // system property that can override the above value
62 private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
63 "android.telephony.apn-restore";
64
The Android Open Source Project28527d22009-03-03 19:31:44 -080065 /**
66 * Sometimes we want to refer to the individual network state
67 * trackers separately, and sometimes we just want to treat them
68 * abstractly.
69 */
70 private NetworkStateTracker mNetTrackers[];
Robert Greenwalt2034b912009-08-12 16:08:25 -070071
72 /**
73 * A per Net list of the PID's that requested access to the net
74 * used both as a refcount and for per-PID DNS selection
75 */
76 private List mNetRequestersPids[];
77
The Android Open Source Project28527d22009-03-03 19:31:44 -080078 private WifiWatchdogService mWifiWatchdogService;
79
Robert Greenwalt2034b912009-08-12 16:08:25 -070080 // priority order of the nettrackers
81 // (excluding dynamically set mNetworkPreference)
82 // TODO - move mNetworkTypePreference into this
83 private int[] mPriorityList;
84
The Android Open Source Project28527d22009-03-03 19:31:44 -080085 private Context mContext;
86 private int mNetworkPreference;
Robert Greenwalt2034b912009-08-12 16:08:25 -070087 private int mActiveDefaultNetwork = -1;
The Android Open Source Project28527d22009-03-03 19:31:44 -080088
89 private int mNumDnsEntries;
The Android Open Source Project28527d22009-03-03 19:31:44 -080090
91 private boolean mTestMode;
92 private static ConnectivityService sServiceInstance;
93
Robert Greenwalt2034b912009-08-12 16:08:25 -070094 private Handler mHandler;
95
96 // list of DeathRecipients used to make sure features are turned off when
97 // a process dies
98 private List mFeatureUsers;
99
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400100 private boolean mSystemReady;
Dianne Hackborna417ff82009-12-08 19:45:14 -0800101 private Intent mInitialBroadcast;
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400102
Robert Greenwalt12c44552009-12-07 11:33:18 -0800103 private static class NetworkAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700104 /**
105 * Class for holding settings read from resources.
106 */
107 public String mName;
108 public int mType;
109 public int mRadio;
110 public int mPriority;
Robert Greenwalt12c44552009-12-07 11:33:18 -0800111 public NetworkInfo.State mLastState;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700112 public NetworkAttributes(String init) {
113 String fragments[] = init.split(",");
114 mName = fragments[0].toLowerCase();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700115 mType = Integer.parseInt(fragments[1]);
116 mRadio = Integer.parseInt(fragments[2]);
117 mPriority = Integer.parseInt(fragments[3]);
Robert Greenwalt12c44552009-12-07 11:33:18 -0800118 mLastState = NetworkInfo.State.UNKNOWN;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700119 }
120 public boolean isDefault() {
121 return (mType == mRadio);
122 }
123 }
124 NetworkAttributes[] mNetAttributes;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700125 int mNetworksDefined;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700126
Robert Greenwalt12c44552009-12-07 11:33:18 -0800127 private static class RadioAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700128 public int mSimultaneity;
129 public int mType;
130 public RadioAttributes(String init) {
131 String fragments[] = init.split(",");
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700132 mType = Integer.parseInt(fragments[0]);
133 mSimultaneity = Integer.parseInt(fragments[1]);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700134 }
135 }
136 RadioAttributes[] mRadioAttributes;
137
The Android Open Source Project28527d22009-03-03 19:31:44 -0800138 private static class ConnectivityThread extends Thread {
139 private Context mContext;
Robert Greenwalt0659da32009-07-16 17:21:39 -0700140
The Android Open Source Project28527d22009-03-03 19:31:44 -0800141 private ConnectivityThread(Context context) {
142 super("ConnectivityThread");
143 mContext = context;
144 }
145
146 @Override
147 public void run() {
148 Looper.prepare();
149 synchronized (this) {
150 sServiceInstance = new ConnectivityService(mContext);
151 notifyAll();
152 }
153 Looper.loop();
154 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700155
The Android Open Source Project28527d22009-03-03 19:31:44 -0800156 public static ConnectivityService getServiceInstance(Context context) {
157 ConnectivityThread thread = new ConnectivityThread(context);
158 thread.start();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700159
The Android Open Source Project28527d22009-03-03 19:31:44 -0800160 synchronized (thread) {
161 while (sServiceInstance == null) {
162 try {
163 // Wait until sServiceInstance has been initialized.
164 thread.wait();
165 } catch (InterruptedException ignore) {
166 Log.e(TAG,
Robert Greenwalt0659da32009-07-16 17:21:39 -0700167 "Unexpected InterruptedException while waiting"+
168 " for ConnectivityService thread");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800169 }
170 }
171 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700172
The Android Open Source Project28527d22009-03-03 19:31:44 -0800173 return sServiceInstance;
174 }
175 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700176
The Android Open Source Project28527d22009-03-03 19:31:44 -0800177 public static ConnectivityService getInstance(Context context) {
178 return ConnectivityThread.getServiceInstance(context);
179 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700180
The Android Open Source Project28527d22009-03-03 19:31:44 -0800181 private ConnectivityService(Context context) {
182 if (DBG) Log.v(TAG, "ConnectivityService starting up");
Robert Greenwaltd48f8ee2010-01-14 17:47:58 -0800183
184 // setup our unique device name
185 String id = Settings.Secure.getString(context.getContentResolver(),
186 Settings.Secure.ANDROID_ID);
187 if (id != null && id.length() > 0) {
188 String name = new String("android_").concat(id);
189 SystemProperties.set("net.hostname", name);
190 }
191
The Android Open Source Project28527d22009-03-03 19:31:44 -0800192 mContext = context;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700193 mNetTrackers = new NetworkStateTracker[
194 ConnectivityManager.MAX_NETWORK_TYPE+1];
195 mHandler = new MyHandler();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700196
The Android Open Source Project28527d22009-03-03 19:31:44 -0800197 mNetworkPreference = getPersistedNetworkPreference();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700198
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700199 mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
200 mNetAttributes = new NetworkAttributes[ConnectivityManager.MAX_NETWORK_TYPE+1];
201
Robert Greenwalt2034b912009-08-12 16:08:25 -0700202 // Load device network attributes from resources
Robert Greenwalt2034b912009-08-12 16:08:25 -0700203 String[] raStrings = context.getResources().getStringArray(
204 com.android.internal.R.array.radioAttributes);
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700205 for (String raString : raStrings) {
206 RadioAttributes r = new RadioAttributes(raString);
207 if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) {
208 Log.e(TAG, "Error in radioAttributes - ignoring attempt to define type " + r.mType);
209 continue;
210 }
211 if (mRadioAttributes[r.mType] != null) {
212 Log.e(TAG, "Error in radioAttributes - ignoring attempt to redefine type " +
213 r.mType);
214 continue;
215 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700216 mRadioAttributes[r.mType] = r;
217 }
218
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700219 String[] naStrings = context.getResources().getStringArray(
220 com.android.internal.R.array.networkAttributes);
221 for (String naString : naStrings) {
222 try {
223 NetworkAttributes n = new NetworkAttributes(naString);
224 if (n.mType > ConnectivityManager.MAX_NETWORK_TYPE) {
225 Log.e(TAG, "Error in networkAttributes - ignoring attempt to define type " +
226 n.mType);
227 continue;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700228 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700229 if (mNetAttributes[n.mType] != null) {
230 Log.e(TAG, "Error in networkAttributes - ignoring attempt to redefine type " +
231 n.mType);
232 continue;
233 }
234 if (mRadioAttributes[n.mRadio] == null) {
235 Log.e(TAG, "Error in networkAttributes - ignoring attempt to use undefined " +
236 "radio " + n.mRadio + " in network type " + n.mType);
237 continue;
238 }
239 mNetAttributes[n.mType] = n;
240 mNetworksDefined++;
241 } catch(Exception e) {
242 // ignore it - leave the entry null
Robert Greenwalt2034b912009-08-12 16:08:25 -0700243 }
244 }
245
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700246 // high priority first
247 mPriorityList = new int[mNetworksDefined];
248 {
249 int insertionPoint = mNetworksDefined-1;
250 int currentLowest = 0;
251 int nextLowest = 0;
252 while (insertionPoint > -1) {
253 for (NetworkAttributes na : mNetAttributes) {
254 if (na == null) continue;
255 if (na.mPriority < currentLowest) continue;
256 if (na.mPriority > currentLowest) {
257 if (na.mPriority < nextLowest || nextLowest == 0) {
258 nextLowest = na.mPriority;
259 }
260 continue;
261 }
262 mPriorityList[insertionPoint--] = na.mType;
263 }
264 currentLowest = nextLowest;
265 nextLowest = 0;
266 }
267 }
268
269 mNetRequestersPids = new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
270 for (int i : mPriorityList) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700271 mNetRequestersPids[i] = new ArrayList();
272 }
273
274 mFeatureUsers = new ArrayList();
275
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700276 mNumDnsEntries = 0;
277
278 mTestMode = SystemProperties.get("cm.test.mode").equals("true")
279 && SystemProperties.get("ro.build.type").equals("eng");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800280 /*
281 * Create the network state trackers for Wi-Fi and mobile
282 * data. Maybe this could be done with a factory class,
283 * but it's not clear that it's worth it, given that
284 * the number of different network types is not going
285 * to change very often.
286 */
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700287 for (int netType : mPriorityList) {
288 switch (mNetAttributes[netType].mRadio) {
289 case ConnectivityManager.TYPE_WIFI:
290 if (DBG) Log.v(TAG, "Starting Wifi Service.");
291 WifiStateTracker wst = new WifiStateTracker(context, mHandler);
292 WifiService wifiService = new WifiService(context, wst);
293 ServiceManager.addService(Context.WIFI_SERVICE, wifiService);
294 mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
295 wst.startMonitoring();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800296
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700297 // Constructing this starts it too
298 mWifiWatchdogService = new WifiWatchdogService(context, wst);
299 break;
300 case ConnectivityManager.TYPE_MOBILE:
301 mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
302 netType, mNetAttributes[netType].mName);
303 mNetTrackers[netType].startMonitoring();
304 break;
305 default:
306 Log.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
307 mNetAttributes[netType].mRadio);
308 continue;
309 }
310 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800311 }
312
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700313
The Android Open Source Project28527d22009-03-03 19:31:44 -0800314 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700315 * Sets the preferred network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800316 * @param preference the new preference
317 */
318 public synchronized void setNetworkPreference(int preference) {
319 enforceChangePermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700320 if (ConnectivityManager.isNetworkTypeValid(preference) &&
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700321 mNetAttributes[preference] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700322 mNetAttributes[preference].isDefault()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800323 if (mNetworkPreference != preference) {
324 persistNetworkPreference(preference);
325 mNetworkPreference = preference;
326 enforcePreference();
327 }
328 }
329 }
330
331 public int getNetworkPreference() {
332 enforceAccessPermission();
333 return mNetworkPreference;
334 }
335
336 private void persistNetworkPreference(int networkPreference) {
337 final ContentResolver cr = mContext.getContentResolver();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700338 Settings.Secure.putInt(cr, Settings.Secure.NETWORK_PREFERENCE,
339 networkPreference);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800340 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700341
The Android Open Source Project28527d22009-03-03 19:31:44 -0800342 private int getPersistedNetworkPreference() {
343 final ContentResolver cr = mContext.getContentResolver();
344
345 final int networkPrefSetting = Settings.Secure
346 .getInt(cr, Settings.Secure.NETWORK_PREFERENCE, -1);
347 if (networkPrefSetting != -1) {
348 return networkPrefSetting;
349 }
350
351 return ConnectivityManager.DEFAULT_NETWORK_PREFERENCE;
352 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700353
The Android Open Source Project28527d22009-03-03 19:31:44 -0800354 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700355 * Make the state of network connectivity conform to the preference settings
The Android Open Source Project28527d22009-03-03 19:31:44 -0800356 * In this method, we only tear down a non-preferred network. Establishing
357 * a connection to the preferred network is taken care of when we handle
358 * the disconnect event from the non-preferred network
359 * (see {@link #handleDisconnect(NetworkInfo)}).
360 */
361 private void enforcePreference() {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700362 if (mNetTrackers[mNetworkPreference].getNetworkInfo().isConnected())
The Android Open Source Project28527d22009-03-03 19:31:44 -0800363 return;
364
Robert Greenwalt2034b912009-08-12 16:08:25 -0700365 if (!mNetTrackers[mNetworkPreference].isAvailable())
366 return;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800367
Robert Greenwalt2034b912009-08-12 16:08:25 -0700368 for (int t=0; t <= ConnectivityManager.MAX_RADIO_TYPE; t++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700369 if (t != mNetworkPreference && mNetTrackers[t] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700370 mNetTrackers[t].getNetworkInfo().isConnected()) {
Robert Greenwaltf3f045b2009-08-20 15:25:14 -0700371 if (DBG) {
372 Log.d(TAG, "tearing down " +
373 mNetTrackers[t].getNetworkInfo() +
374 " in enforcePreference");
375 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700376 teardown(mNetTrackers[t]);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800377 }
378 }
379 }
380
381 private boolean teardown(NetworkStateTracker netTracker) {
382 if (netTracker.teardown()) {
383 netTracker.setTeardownRequested(true);
384 return true;
385 } else {
386 return false;
387 }
388 }
389
390 /**
391 * Return NetworkInfo for the active (i.e., connected) network interface.
392 * It is assumed that at most one network is active at a time. If more
393 * than one is active, it is indeterminate which will be returned.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700394 * @return the info for the active network, or {@code null} if none is
395 * active
The Android Open Source Project28527d22009-03-03 19:31:44 -0800396 */
397 public NetworkInfo getActiveNetworkInfo() {
398 enforceAccessPermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700399 for (int type=0; type <= ConnectivityManager.MAX_NETWORK_TYPE; type++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700400 if (mNetAttributes[type] == null || !mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700401 continue;
402 }
403 NetworkStateTracker t = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800404 NetworkInfo info = t.getNetworkInfo();
405 if (info.isConnected()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700406 if (DBG && type != mActiveDefaultNetwork) Log.e(TAG,
407 "connected default network is not " +
408 "mActiveDefaultNetwork!");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800409 return info;
410 }
411 }
412 return null;
413 }
414
415 public NetworkInfo getNetworkInfo(int networkType) {
416 enforceAccessPermission();
417 if (ConnectivityManager.isNetworkTypeValid(networkType)) {
418 NetworkStateTracker t = mNetTrackers[networkType];
419 if (t != null)
420 return t.getNetworkInfo();
421 }
422 return null;
423 }
424
425 public NetworkInfo[] getAllNetworkInfo() {
426 enforceAccessPermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700427 NetworkInfo[] result = new NetworkInfo[mNetworksDefined];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800428 int i = 0;
429 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700430 if(t != null) result[i++] = t.getNetworkInfo();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800431 }
432 return result;
433 }
434
435 public boolean setRadios(boolean turnOn) {
436 boolean result = true;
437 enforceChangePermission();
438 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700439 if (t != null) result = t.setRadio(turnOn) && result;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800440 }
441 return result;
442 }
443
444 public boolean setRadio(int netType, boolean turnOn) {
445 enforceChangePermission();
446 if (!ConnectivityManager.isNetworkTypeValid(netType)) {
447 return false;
448 }
449 NetworkStateTracker tracker = mNetTrackers[netType];
450 return tracker != null && tracker.setRadio(turnOn);
451 }
452
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700453 /**
454 * Used to notice when the calling process dies so we can self-expire
455 *
456 * Also used to know if the process has cleaned up after itself when
457 * our auto-expire timer goes off. The timer has a link to an object.
458 *
459 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700460 private class FeatureUser implements IBinder.DeathRecipient {
461 int mNetworkType;
462 String mFeature;
463 IBinder mBinder;
464 int mPid;
465 int mUid;
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800466 long mCreateTime;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700467
468 FeatureUser(int type, String feature, IBinder binder) {
469 super();
470 mNetworkType = type;
471 mFeature = feature;
472 mBinder = binder;
473 mPid = getCallingPid();
474 mUid = getCallingUid();
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800475 mCreateTime = System.currentTimeMillis();
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700476
Robert Greenwalt2034b912009-08-12 16:08:25 -0700477 try {
478 mBinder.linkToDeath(this, 0);
479 } catch (RemoteException e) {
480 binderDied();
481 }
482 }
483
484 void unlinkDeathRecipient() {
485 mBinder.unlinkToDeath(this, 0);
486 }
487
488 public void binderDied() {
489 Log.d(TAG, "ConnectivityService FeatureUser binderDied(" +
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800490 mNetworkType + ", " + mFeature + ", " + mBinder + "), created " +
491 (System.currentTimeMillis() - mCreateTime) + " mSec ago");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700492 stopUsingNetworkFeature(this, false);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700493 }
494
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700495 public void expire() {
496 Log.d(TAG, "ConnectivityService FeatureUser expire(" +
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800497 mNetworkType + ", " + mFeature + ", " + mBinder +"), created " +
498 (System.currentTimeMillis() - mCreateTime) + " mSec ago");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700499 stopUsingNetworkFeature(this, false);
500 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800501
502 public String toString() {
503 return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
504 (System.currentTimeMillis() - mCreateTime) + " mSec ago";
505 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700506 }
507
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700508 // javadoc from interface
Robert Greenwalt2034b912009-08-12 16:08:25 -0700509 public int startUsingNetworkFeature(int networkType, String feature,
510 IBinder binder) {
511 if (DBG) {
512 Log.d(TAG, "startUsingNetworkFeature for net " + networkType +
513 ": " + feature);
514 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800515 enforceChangePermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700516 if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
517 mNetAttributes[networkType] == null) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700518 return Phone.APN_REQUEST_FAILED;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800519 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700520
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700521 FeatureUser f = new FeatureUser(networkType, feature, binder);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700522
523 // TODO - move this into the MobileDataStateTracker
524 int usedNetworkType = networkType;
525 if(networkType == ConnectivityManager.TYPE_MOBILE) {
526 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
527 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
528 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
529 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
530 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
531 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
532 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
533 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
534 }
535 }
536 NetworkStateTracker network = mNetTrackers[usedNetworkType];
537 if (network != null) {
538 if (usedNetworkType != networkType) {
539 Integer currentPid = new Integer(getCallingPid());
540
541 NetworkStateTracker radio = mNetTrackers[networkType];
542 NetworkInfo ni = network.getNetworkInfo();
543
544 if (ni.isAvailable() == false) {
545 if (DBG) Log.d(TAG, "special network not available");
546 return Phone.APN_TYPE_NOT_AVAILABLE;
547 }
548
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700549 synchronized(this) {
550 mFeatureUsers.add(f);
551 if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
552 // this gets used for per-pid dns when connected
553 mNetRequestersPids[usedNetworkType].add(currentPid);
554 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700555 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700556 mHandler.sendMessageDelayed(mHandler.obtainMessage(
557 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
558 f), getRestoreDefaultNetworkDelay());
559
Robert Greenwalt2034b912009-08-12 16:08:25 -0700560
Robert Greenwalta52c75a2009-08-19 20:19:33 -0700561 if ((ni.isConnectedOrConnecting() == true) &&
562 !network.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700563 if (ni.isConnected() == true) {
564 // add the pid-specific dns
565 handleDnsConfigurationChange();
566 if (DBG) Log.d(TAG, "special network already active");
567 return Phone.APN_ALREADY_ACTIVE;
568 }
569 if (DBG) Log.d(TAG, "special network already connecting");
570 return Phone.APN_REQUEST_STARTED;
571 }
572
573 // check if the radio in play can make another contact
574 // assume if cannot for now
575
Robert Greenwalt2034b912009-08-12 16:08:25 -0700576 if (DBG) Log.d(TAG, "reconnecting to special network");
577 network.reconnect();
578 return Phone.APN_REQUEST_STARTED;
579 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700580 synchronized(this) {
581 mFeatureUsers.add(f);
582 }
583 mHandler.sendMessageDelayed(mHandler.obtainMessage(
584 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
585 f), getRestoreDefaultNetworkDelay());
586
Robert Greenwalt2034b912009-08-12 16:08:25 -0700587 return network.startUsingNetworkFeature(feature,
588 getCallingPid(), getCallingUid());
589 }
590 }
591 return Phone.APN_TYPE_NOT_AVAILABLE;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800592 }
593
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700594 // javadoc from interface
The Android Open Source Project28527d22009-03-03 19:31:44 -0800595 public int stopUsingNetworkFeature(int networkType, String feature) {
Robert Greenwalt28f43012009-10-06 17:52:40 -0700596 enforceChangePermission();
597
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700598 int pid = getCallingPid();
599 int uid = getCallingUid();
600
601 FeatureUser u = null;
602 boolean found = false;
603
604 synchronized(this) {
605 for (int i = 0; i < mFeatureUsers.size() ; i++) {
606 u = (FeatureUser)mFeatureUsers.get(i);
607 if (uid == u.mUid && pid == u.mPid &&
608 networkType == u.mNetworkType &&
609 TextUtils.equals(feature, u.mFeature)) {
610 found = true;
611 break;
612 }
613 }
614 }
615 if (found && u != null) {
616 // stop regardless of how many other time this proc had called start
617 return stopUsingNetworkFeature(u, true);
618 } else {
619 // none found!
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800620 if (DBG) Log.d(TAG, "ignoring stopUsingNetworkFeature - not a live request");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700621 return 1;
622 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700623 }
624
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700625 private int stopUsingNetworkFeature(FeatureUser u, boolean ignoreDups) {
626 int networkType = u.mNetworkType;
627 String feature = u.mFeature;
628 int pid = u.mPid;
629 int uid = u.mUid;
630
631 NetworkStateTracker tracker = null;
632 boolean callTeardown = false; // used to carry our decision outside of sync block
633
Robert Greenwalt2034b912009-08-12 16:08:25 -0700634 if (DBG) {
635 Log.d(TAG, "stopUsingNetworkFeature for net " + networkType +
636 ": " + feature);
637 }
Robert Greenwalt28f43012009-10-06 17:52:40 -0700638
The Android Open Source Project28527d22009-03-03 19:31:44 -0800639 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
640 return -1;
641 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700642
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700643 // need to link the mFeatureUsers list with the mNetRequestersPids state in this
644 // sync block
645 synchronized(this) {
646 // check if this process still has an outstanding start request
647 if (!mFeatureUsers.contains(u)) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700648 return 1;
649 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700650 u.unlinkDeathRecipient();
651 mFeatureUsers.remove(mFeatureUsers.indexOf(u));
652 // If we care about duplicate requests, check for that here.
653 //
654 // This is done to support the extension of a request - the app
655 // can request we start the network feature again and renew the
656 // auto-shutoff delay. Normal "stop" calls from the app though
657 // do not pay attention to duplicate requests - in effect the
658 // API does not refcount and a single stop will counter multiple starts.
659 if (ignoreDups == false) {
660 for (int i = 0; i < mFeatureUsers.size() ; i++) {
661 FeatureUser x = (FeatureUser)mFeatureUsers.get(i);
662 if (x.mUid == u.mUid && x.mPid == u.mPid &&
663 x.mNetworkType == u.mNetworkType &&
664 TextUtils.equals(x.mFeature, u.mFeature)) {
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800665 if (DBG) Log.d(TAG, "ignoring stopUsingNetworkFeature as dup is found");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700666 return 1;
667 }
668 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700669 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700670
671 // TODO - move to MobileDataStateTracker
672 int usedNetworkType = networkType;
673 if (networkType == ConnectivityManager.TYPE_MOBILE) {
674 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
675 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
676 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
677 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
678 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
679 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
680 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
681 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
682 }
683 }
684 tracker = mNetTrackers[usedNetworkType];
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700685 if (tracker == null) {
686 return -1;
687 }
688 if (usedNetworkType != networkType) {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700689 Integer currentPid = new Integer(pid);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700690 mNetRequestersPids[usedNetworkType].remove(currentPid);
Robert Greenwalt0ca68a02009-12-17 14:54:59 -0800691 reassessPidDns(pid, true);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700692 if (mNetRequestersPids[usedNetworkType].size() != 0) {
693 if (DBG) Log.d(TAG, "not tearing down special network - " +
694 "others still using it");
695 return 1;
696 }
697 callTeardown = true;
698 }
699 }
700
701 if (callTeardown) {
702 tracker.teardown();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700703 return 1;
704 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700705 // do it the old fashioned way
Robert Greenwalt2034b912009-08-12 16:08:25 -0700706 return tracker.stopUsingNetworkFeature(feature, pid, uid);
707 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800708 }
709
710 /**
711 * Ensure that a network route exists to deliver traffic to the specified
712 * host via the specified network interface.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700713 * @param networkType the type of the network over which traffic to the
714 * specified host is to be routed
715 * @param hostAddress the IP address of the host to which the route is
716 * desired
The Android Open Source Project28527d22009-03-03 19:31:44 -0800717 * @return {@code true} on success, {@code false} on failure
718 */
719 public boolean requestRouteToHost(int networkType, int hostAddress) {
720 enforceChangePermission();
721 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
722 return false;
723 }
724 NetworkStateTracker tracker = mNetTrackers[networkType];
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700725
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700726 if (tracker == null || !tracker.getNetworkInfo().isConnected() ||
727 tracker.isTeardownRequested()) {
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700728 if (DBG) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700729 Log.d(TAG, "requestRouteToHost on down network (" + networkType + ") - dropped");
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700730 }
731 return false;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800732 }
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700733 return tracker.requestRouteToHost(hostAddress);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800734 }
735
736 /**
737 * @see ConnectivityManager#getBackgroundDataSetting()
738 */
739 public boolean getBackgroundDataSetting() {
740 return Settings.Secure.getInt(mContext.getContentResolver(),
741 Settings.Secure.BACKGROUND_DATA, 1) == 1;
742 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700743
The Android Open Source Project28527d22009-03-03 19:31:44 -0800744 /**
745 * @see ConnectivityManager#setBackgroundDataSetting(boolean)
746 */
747 public void setBackgroundDataSetting(boolean allowBackgroundDataUsage) {
748 mContext.enforceCallingOrSelfPermission(
749 android.Manifest.permission.CHANGE_BACKGROUND_DATA_SETTING,
750 "ConnectivityService");
Robert Greenwalt0659da32009-07-16 17:21:39 -0700751
The Android Open Source Project28527d22009-03-03 19:31:44 -0800752 if (getBackgroundDataSetting() == allowBackgroundDataUsage) return;
753
754 Settings.Secure.putInt(mContext.getContentResolver(),
Robert Greenwalt0659da32009-07-16 17:21:39 -0700755 Settings.Secure.BACKGROUND_DATA,
756 allowBackgroundDataUsage ? 1 : 0);
757
The Android Open Source Project28527d22009-03-03 19:31:44 -0800758 Intent broadcast = new Intent(
759 ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
760 mContext.sendBroadcast(broadcast);
Robert Greenwalt0659da32009-07-16 17:21:39 -0700761 }
762
The Android Open Source Project28527d22009-03-03 19:31:44 -0800763 private int getNumConnectedNetworks() {
764 int numConnectedNets = 0;
765
766 for (NetworkStateTracker nt : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700767 if (nt != null && nt.getNetworkInfo().isConnected() &&
Robert Greenwalt0659da32009-07-16 17:21:39 -0700768 !nt.isTeardownRequested()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800769 ++numConnectedNets;
770 }
771 }
772 return numConnectedNets;
773 }
774
775 private void enforceAccessPermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700776 mContext.enforceCallingOrSelfPermission(
777 android.Manifest.permission.ACCESS_NETWORK_STATE,
778 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800779 }
780
781 private void enforceChangePermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700782 mContext.enforceCallingOrSelfPermission(
783 android.Manifest.permission.CHANGE_NETWORK_STATE,
784 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800785 }
786
787 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700788 * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
789 * network, we ignore it. If it is for the active network, we send out a
790 * broadcast. But first, we check whether it might be possible to connect
791 * to a different network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800792 * @param info the {@code NetworkInfo} for the network
793 */
794 private void handleDisconnect(NetworkInfo info) {
795
Robert Greenwalt2034b912009-08-12 16:08:25 -0700796 int prevNetType = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800797
Robert Greenwalt2034b912009-08-12 16:08:25 -0700798 mNetTrackers[prevNetType].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800799 /*
800 * If the disconnected network is not the active one, then don't report
801 * this as a loss of connectivity. What probably happened is that we're
802 * getting the disconnect for a network that we explicitly disabled
803 * in accordance with network preference policies.
804 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700805 if (!mNetAttributes[prevNetType].isDefault()) {
806 List pids = mNetRequestersPids[prevNetType];
807 for (int i = 0; i<pids.size(); i++) {
808 Integer pid = (Integer)pids.get(i);
809 // will remove them because the net's no longer connected
810 // need to do this now as only now do we know the pids and
811 // can properly null things that are no longer referenced.
812 reassessPidDns(pid.intValue(), false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800813 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800814 }
815
The Android Open Source Project28527d22009-03-03 19:31:44 -0800816 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800817 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800818 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
819 if (info.isFailover()) {
820 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
821 info.setFailover(false);
822 }
823 if (info.getReason() != null) {
824 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
825 }
826 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700827 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
828 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -0800829 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700830
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800831 NetworkStateTracker newNet = null;
832 if (mNetAttributes[prevNetType].isDefault()) {
833 newNet = tryFailover(prevNetType);
834 if (newNet != null) {
835 NetworkInfo switchTo = newNet.getNetworkInfo();
836 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
837 } else {
838 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
839 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800840 }
841 // do this before we broadcast the change
842 handleConnectivityChange();
843
844 sendStickyBroadcast(intent);
845 /*
846 * If the failover network is already connected, then immediately send
847 * out a followup broadcast indicating successful failover
848 */
849 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
850 sendConnectedBroadcast(newNet.getNetworkInfo());
851 }
852 }
853
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800854 // returns null if no failover available
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800855 private NetworkStateTracker tryFailover(int prevNetType) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700856 /*
857 * If this is a default network, check if other defaults are available
858 * or active
859 */
860 NetworkStateTracker newNet = null;
861 if (mNetAttributes[prevNetType].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700862 if (mActiveDefaultNetwork == prevNetType) {
863 mActiveDefaultNetwork = -1;
864 }
865
866 int newType = -1;
867 int newPriority = -1;
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800868 for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700869 if (checkType == prevNetType) continue;
870 if (mNetAttributes[checkType] == null) continue;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700871 if (mNetAttributes[checkType].isDefault()) {
872 /* TODO - if we have multiple nets we could use
873 * we may want to put more thought into which we choose
874 */
875 if (checkType == mNetworkPreference) {
876 newType = checkType;
877 break;
878 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700879 if (mNetAttributes[checkType].mPriority > newPriority) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700880 newType = checkType;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700881 newPriority = mNetAttributes[newType].mPriority;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700882 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800883 }
884 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700885
886 if (newType != -1) {
887 newNet = mNetTrackers[newType];
888 /**
889 * See if the other network is available to fail over to.
890 * If is not available, we enable it anyway, so that it
891 * will be able to connect when it does become available,
892 * but we report a total loss of connectivity rather than
893 * report that we are attempting to fail over.
894 */
895 if (newNet.isAvailable()) {
896 NetworkInfo switchTo = newNet.getNetworkInfo();
897 switchTo.setFailover(true);
Robert Greenwalta52c75a2009-08-19 20:19:33 -0700898 if (!switchTo.isConnectedOrConnecting() ||
899 newNet.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700900 newNet.reconnect();
901 }
902 if (DBG) {
903 if (switchTo.isConnected()) {
904 Log.v(TAG, "Switching to already connected " +
905 switchTo.getTypeName());
906 } else {
907 Log.v(TAG, "Attempting to switch to " +
908 switchTo.getTypeName());
909 }
910 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700911 } else {
912 newNet.reconnect();
913 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700914 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800915 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700916
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800917 return newNet;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800918 }
919
920 private void sendConnectedBroadcast(NetworkInfo info) {
921 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800922 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800923 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
924 if (info.isFailover()) {
925 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
926 info.setFailover(false);
927 }
928 if (info.getReason() != null) {
929 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
930 }
931 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700932 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
933 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -0800934 }
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400935 sendStickyBroadcast(intent);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800936 }
937
938 /**
939 * Called when an attempt to fail over to another network has failed.
940 * @param info the {@link NetworkInfo} for the failed network
941 */
942 private void handleConnectionFailure(NetworkInfo info) {
943 mNetTrackers[info.getType()].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800944
Robert Greenwalt2034b912009-08-12 16:08:25 -0700945 String reason = info.getReason();
946 String extraInfo = info.getExtraInfo();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700947
Robert Greenwalt2034b912009-08-12 16:08:25 -0700948 if (DBG) {
949 String reasonText;
950 if (reason == null) {
951 reasonText = ".";
952 } else {
953 reasonText = " (" + reason + ").";
The Android Open Source Project28527d22009-03-03 19:31:44 -0800954 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700955 Log.v(TAG, "Attempt to connect to " + info.getTypeName() +
956 " failed" + reasonText);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800957 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700958
959 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800960 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700961 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
962 if (getActiveNetworkInfo() == null) {
963 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
964 }
965 if (reason != null) {
966 intent.putExtra(ConnectivityManager.EXTRA_REASON, reason);
967 }
968 if (extraInfo != null) {
969 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, extraInfo);
970 }
971 if (info.isFailover()) {
972 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
973 info.setFailover(false);
974 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800975
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800976 NetworkStateTracker newNet = null;
977 if (mNetAttributes[info.getType()].isDefault()) {
978 newNet = tryFailover(info.getType());
979 if (newNet != null) {
980 NetworkInfo switchTo = newNet.getNetworkInfo();
981 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
982 } else {
983 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
984 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800985 }
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800986
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800987 // do this before we broadcast the change
988 handleConnectivityChange();
989
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400990 sendStickyBroadcast(intent);
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800991 /*
992 * If the failover network is already connected, then immediately send
993 * out a followup broadcast indicating successful failover
994 */
995 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
996 sendConnectedBroadcast(newNet.getNetworkInfo());
997 }
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400998 }
999
1000 private void sendStickyBroadcast(Intent intent) {
1001 synchronized(this) {
Dianne Hackborna417ff82009-12-08 19:45:14 -08001002 if (!mSystemReady) {
1003 mInitialBroadcast = new Intent(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001004 }
Dianne Hackborna417ff82009-12-08 19:45:14 -08001005 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1006 mContext.sendStickyBroadcast(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001007 }
1008 }
1009
1010 void systemReady() {
1011 synchronized(this) {
1012 mSystemReady = true;
Dianne Hackborna417ff82009-12-08 19:45:14 -08001013 if (mInitialBroadcast != null) {
1014 mContext.sendStickyBroadcast(mInitialBroadcast);
1015 mInitialBroadcast = null;
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001016 }
1017 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001018 }
1019
1020 private void handleConnect(NetworkInfo info) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001021 int type = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001022
1023 // snapshot isFailover, because sendConnectedBroadcast() resets it
1024 boolean isFailover = info.isFailover();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001025 NetworkStateTracker thisNet = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -08001026
Robert Greenwalt2034b912009-08-12 16:08:25 -07001027 // if this is a default net and other default is running
1028 // kill the one not preferred
1029 if (mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001030 if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
1031 if ((type != mNetworkPreference &&
1032 mNetAttributes[mActiveDefaultNetwork].mPriority >
1033 mNetAttributes[type].mPriority) ||
1034 mNetworkPreference == mActiveDefaultNetwork) {
1035 // don't accept this one
1036 if (DBG) Log.v(TAG, "Not broadcasting CONNECT_ACTION " +
1037 "to torn down network " + info.getTypeName());
1038 teardown(thisNet);
1039 return;
1040 } else {
1041 // tear down the other
1042 NetworkStateTracker otherNet =
1043 mNetTrackers[mActiveDefaultNetwork];
1044 if (DBG) Log.v(TAG, "Policy requires " +
1045 otherNet.getNetworkInfo().getTypeName() +
1046 " teardown");
1047 if (!teardown(otherNet)) {
1048 Log.e(TAG, "Network declined teardown request");
1049 return;
1050 }
1051 if (isFailover) {
1052 otherNet.releaseWakeLock();
1053 }
1054 }
1055 }
1056 mActiveDefaultNetwork = type;
1057 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001058 thisNet.setTeardownRequested(false);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001059 thisNet.updateNetworkSettings();
1060 handleConnectivityChange();
1061 sendConnectedBroadcast(info);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001062 }
1063
1064 private void handleScanResultsAvailable(NetworkInfo info) {
1065 int networkType = info.getType();
1066 if (networkType != ConnectivityManager.TYPE_WIFI) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001067 if (DBG) Log.v(TAG, "Got ScanResultsAvailable for " +
1068 info.getTypeName() + " network. Don't know how to handle.");
The Android Open Source Project28527d22009-03-03 19:31:44 -08001069 }
Robert Greenwalt0659da32009-07-16 17:21:39 -07001070
The Android Open Source Project28527d22009-03-03 19:31:44 -08001071 mNetTrackers[networkType].interpretScanResultsAvailable();
1072 }
1073
Robert Greenwalt0659da32009-07-16 17:21:39 -07001074 private void handleNotificationChange(boolean visible, int id,
1075 Notification notification) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001076 NotificationManager notificationManager = (NotificationManager) mContext
1077 .getSystemService(Context.NOTIFICATION_SERVICE);
Robert Greenwalt0659da32009-07-16 17:21:39 -07001078
The Android Open Source Project28527d22009-03-03 19:31:44 -08001079 if (visible) {
1080 notificationManager.notify(id, notification);
1081 } else {
1082 notificationManager.cancel(id);
1083 }
1084 }
1085
1086 /**
1087 * After any kind of change in the connectivity state of any network,
1088 * make sure that anything that depends on the connectivity state of
1089 * more than one network is set up correctly. We're mainly concerned
1090 * with making sure that the list of DNS servers is set up according
1091 * to which networks are connected, and ensuring that the right routing
1092 * table entries exist.
1093 */
1094 private void handleConnectivityChange() {
1095 /*
Robert Greenwalt2034b912009-08-12 16:08:25 -07001096 * If a non-default network is enabled, add the host routes that
Robert Greenwalt423dbbc2009-09-30 21:01:30 -07001097 * will allow it's DNS servers to be accessed. Only
The Android Open Source Project28527d22009-03-03 19:31:44 -08001098 * If both mobile and wifi are enabled, add the host routes that
1099 * will allow MMS traffic to pass on the mobile network. But
1100 * remove the default route for the mobile network, so that there
1101 * will be only one default route, to ensure that all traffic
1102 * except MMS will travel via Wi-Fi.
1103 */
Robert Greenwalt2034b912009-08-12 16:08:25 -07001104 handleDnsConfigurationChange();
1105
1106 for (int netType : mPriorityList) {
1107 if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
1108 if (mNetAttributes[netType].isDefault()) {
1109 mNetTrackers[netType].addDefaultRoute();
1110 } else {
1111 mNetTrackers[netType].addPrivateDnsRoutes();
1112 }
1113 } else {
1114 if (mNetAttributes[netType].isDefault()) {
1115 mNetTrackers[netType].removeDefaultRoute();
1116 } else {
1117 mNetTrackers[netType].removePrivateDnsRoutes();
1118 }
1119 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001120 }
1121 }
1122
Robert Greenwalt2034b912009-08-12 16:08:25 -07001123 /**
1124 * Adjust the per-process dns entries (net.dns<x>.<pid>) based
1125 * on the highest priority active net which this process requested.
1126 * If there aren't any, clear it out
1127 */
1128 private void reassessPidDns(int myPid, boolean doBump)
1129 {
1130 if (DBG) Log.d(TAG, "reassessPidDns for pid " + myPid);
1131 for(int i : mPriorityList) {
1132 if (mNetAttributes[i].isDefault()) {
1133 continue;
1134 }
1135 NetworkStateTracker nt = mNetTrackers[i];
Robert Greenwalt0659da32009-07-16 17:21:39 -07001136 if (nt.getNetworkInfo().isConnected() &&
1137 !nt.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001138 List pids = mNetRequestersPids[i];
1139 for (int j=0; j<pids.size(); j++) {
1140 Integer pid = (Integer)pids.get(j);
1141 if (pid.intValue() == myPid) {
1142 String[] dnsList = nt.getNameServers();
1143 writePidDns(dnsList, myPid);
1144 if (doBump) {
1145 bumpDns();
1146 }
1147 return;
1148 }
1149 }
1150 }
1151 }
1152 // nothing found - delete
1153 for (int i = 1; ; i++) {
1154 String prop = "net.dns" + i + "." + myPid;
1155 if (SystemProperties.get(prop).length() == 0) {
1156 if (doBump) {
1157 bumpDns();
1158 }
1159 return;
1160 }
1161 SystemProperties.set(prop, "");
1162 }
1163 }
1164
1165 private void writePidDns(String[] dnsList, int pid) {
1166 int j = 1;
1167 for (String dns : dnsList) {
1168 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
1169 SystemProperties.set("net.dns" + j++ + "." + pid, dns);
1170 }
1171 }
1172 }
1173
1174 private void bumpDns() {
1175 /*
1176 * Bump the property that tells the name resolver library to reread
1177 * the DNS server list from the properties.
1178 */
1179 String propVal = SystemProperties.get("net.dnschange");
1180 int n = 0;
1181 if (propVal.length() != 0) {
1182 try {
1183 n = Integer.parseInt(propVal);
1184 } catch (NumberFormatException e) {}
1185 }
1186 SystemProperties.set("net.dnschange", "" + (n+1));
1187 }
1188
1189 private void handleDnsConfigurationChange() {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001190 // add default net's dns entries
1191 for (int x = mPriorityList.length-1; x>= 0; x--) {
1192 int netType = mPriorityList[x];
1193 NetworkStateTracker nt = mNetTrackers[netType];
Robert Greenwalt2034b912009-08-12 16:08:25 -07001194 if (nt != null && nt.getNetworkInfo().isConnected() &&
1195 !nt.isTeardownRequested()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001196 String[] dnsList = nt.getNameServers();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001197 if (mNetAttributes[netType].isDefault()) {
1198 int j = 1;
1199 for (String dns : dnsList) {
1200 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
Robert Greenwalt423dbbc2009-09-30 21:01:30 -07001201 if (DBG) {
1202 Log.d(TAG, "adding dns " + dns + " for " +
1203 nt.getNetworkInfo().getTypeName());
1204 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001205 SystemProperties.set("net.dns" + j++, dns);
1206 }
1207 }
1208 for (int k=j ; k<mNumDnsEntries; k++) {
Robert Greenwalt8e5b8532009-08-25 14:00:10 -07001209 if (DBG) Log.d(TAG, "erasing net.dns" + k);
1210 SystemProperties.set("net.dns" + k, "");
Robert Greenwalt2034b912009-08-12 16:08:25 -07001211 }
1212 mNumDnsEntries = j;
1213 } else {
1214 // set per-pid dns for attached secondary nets
1215 List pids = mNetRequestersPids[netType];
1216 for (int y=0; y< pids.size(); y++) {
1217 Integer pid = (Integer)pids.get(y);
1218 writePidDns(dnsList, pid.intValue());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001219 }
1220 }
1221 }
1222 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001223
1224 bumpDns();
1225 }
1226
1227 private int getRestoreDefaultNetworkDelay() {
1228 String restoreDefaultNetworkDelayStr = SystemProperties.get(
1229 NETWORK_RESTORE_DELAY_PROP_NAME);
1230 if(restoreDefaultNetworkDelayStr != null &&
1231 restoreDefaultNetworkDelayStr.length() != 0) {
1232 try {
1233 return Integer.valueOf(restoreDefaultNetworkDelayStr);
1234 } catch (NumberFormatException e) {
1235 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001236 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001237 return RESTORE_DEFAULT_NETWORK_DELAY;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001238 }
1239
1240 @Override
1241 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001242 if (mContext.checkCallingOrSelfPermission(
1243 android.Manifest.permission.DUMP)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001244 != PackageManager.PERMISSION_GRANTED) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001245 pw.println("Permission Denial: can't dump ConnectivityService " +
1246 "from from pid=" + Binder.getCallingPid() + ", uid=" +
1247 Binder.getCallingUid());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001248 return;
1249 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001250 pw.println();
1251 for (NetworkStateTracker nst : mNetTrackers) {
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001252 if (nst != null) {
1253 if (nst.getNetworkInfo().isConnected()) {
1254 pw.println("Active network: " + nst.getNetworkInfo().
1255 getTypeName());
1256 }
1257 pw.println(nst.getNetworkInfo());
1258 pw.println(nst);
1259 pw.println();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001260 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001261 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001262
1263 pw.println("Network Requester Pids:");
1264 for (int net : mPriorityList) {
1265 String pidString = net + ": ";
1266 for (Object pid : mNetRequestersPids[net]) {
1267 pidString = pidString + pid.toString() + ", ";
1268 }
1269 pw.println(pidString);
1270 }
1271 pw.println();
1272
1273 pw.println("FeatureUsers:");
1274 for (Object requester : mFeatureUsers) {
1275 pw.println(requester.toString());
1276 }
1277 pw.println();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001278 }
1279
Robert Greenwalt2034b912009-08-12 16:08:25 -07001280 // must be stateless - things change under us.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001281 private class MyHandler extends Handler {
1282 @Override
1283 public void handleMessage(Message msg) {
1284 NetworkInfo info;
1285 switch (msg.what) {
1286 case NetworkStateTracker.EVENT_STATE_CHANGED:
1287 info = (NetworkInfo) msg.obj;
Robert Greenwalt12c44552009-12-07 11:33:18 -08001288 int type = info.getType();
1289 NetworkInfo.State state = info.getState();
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001290 // only do this optimization for wifi. It going into scan mode for location
1291 // services generates alot of noise. Meanwhile the mms apn won't send out
1292 // subsequent notifications when on default cellular because it never
1293 // disconnects.. so only do this to wifi notifications. Fixed better when the
1294 // APN notifications are standardized.
1295 if (mNetAttributes[type].mLastState == state &&
1296 mNetAttributes[type].mRadio == ConnectivityManager.TYPE_WIFI) {
Robert Greenwalt12c44552009-12-07 11:33:18 -08001297 if (DBG) {
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001298 // TODO - remove this after we validate the dropping doesn't break
1299 // anything
Robert Greenwalt12c44552009-12-07 11:33:18 -08001300 Log.d(TAG, "Dropping ConnectivityChange for " +
Robert Greenwalt2adbc7f2010-01-13 09:36:31 -08001301 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001302 state + "/" + info.getDetailedState());
1303 }
1304 return;
1305 }
1306 mNetAttributes[type].mLastState = state;
1307
Robert Greenwalt2034b912009-08-12 16:08:25 -07001308 if (DBG) Log.d(TAG, "ConnectivityChange for " +
Robert Greenwalt0659da32009-07-16 17:21:39 -07001309 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001310 state + "/" + info.getDetailedState());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001311
1312 // Connectivity state changed:
1313 // [31-13] Reserved for future use
Robert Greenwalt0659da32009-07-16 17:21:39 -07001314 // [12-9] Network subtype (for mobile network, as defined
1315 // by TelephonyManager)
1316 // [8-3] Detailed state ordinal (as defined by
1317 // NetworkInfo.DetailedState)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001318 // [2-0] Network type (as defined by ConnectivityManager)
1319 int eventLogParam = (info.getType() & 0x7) |
1320 ((info.getDetailedState().ordinal() & 0x3f) << 3) |
1321 (info.getSubtype() << 9);
Doug Zongker2fc96232009-12-04 10:31:43 -08001322 EventLog.writeEvent(EventLogTags.CONNECTIVITY_STATE_CHANGED,
Robert Greenwalt0659da32009-07-16 17:21:39 -07001323 eventLogParam);
1324
1325 if (info.getDetailedState() ==
1326 NetworkInfo.DetailedState.FAILED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001327 handleConnectionFailure(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001328 } else if (state == NetworkInfo.State.DISCONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001329 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001330 } else if (state == NetworkInfo.State.SUSPENDED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001331 // TODO: need to think this over.
Robert Greenwalt0659da32009-07-16 17:21:39 -07001332 // the logic here is, handle SUSPENDED the same as
1333 // DISCONNECTED. The only difference being we are
1334 // broadcasting an intent with NetworkInfo that's
1335 // suspended. This allows the applications an
1336 // opportunity to handle DISCONNECTED and SUSPENDED
1337 // differently, or not.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001338 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001339 } else if (state == NetworkInfo.State.CONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001340 handleConnect(info);
1341 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001342 break;
1343
1344 case NetworkStateTracker.EVENT_SCAN_RESULTS_AVAILABLE:
1345 info = (NetworkInfo) msg.obj;
1346 handleScanResultsAvailable(info);
1347 break;
Robert Greenwalt0659da32009-07-16 17:21:39 -07001348
The Android Open Source Project28527d22009-03-03 19:31:44 -08001349 case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
Robert Greenwalt0659da32009-07-16 17:21:39 -07001350 handleNotificationChange(msg.arg1 == 1, msg.arg2,
1351 (Notification) msg.obj);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001352
1353 case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
Robert Greenwalt2034b912009-08-12 16:08:25 -07001354 handleDnsConfigurationChange();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001355 break;
1356
1357 case NetworkStateTracker.EVENT_ROAMING_CHANGED:
1358 // fill me in
1359 break;
1360
1361 case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED:
1362 // fill me in
1363 break;
Robert Greenwalt2034b912009-08-12 16:08:25 -07001364 case NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK:
Robert Greenwaltaffc3a12009-09-27 17:27:04 -07001365 FeatureUser u = (FeatureUser)msg.obj;
1366 u.expire();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001367 break;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001368 }
1369 }
1370 }
1371}