blob: 42590160d99a415ecaf5ccb852313f141fcb0a0d [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
Robert Greenwalt0c4828c2010-01-26 11:40:34 -080046import com.android.server.connectivity.Tethering;
47
The Android Open Source Project28527d22009-03-03 19:31:44 -080048import java.io.FileDescriptor;
49import java.io.PrintWriter;
Robert Greenwalt2034b912009-08-12 16:08:25 -070050import java.util.ArrayList;
51import java.util.List;
The Android Open Source Project28527d22009-03-03 19:31:44 -080052
53/**
54 * @hide
55 */
56public class ConnectivityService extends IConnectivityManager.Stub {
57
Robert Greenwalta25fd712009-10-06 14:12:53 -070058 private static final boolean DBG = true;
The Android Open Source Project28527d22009-03-03 19:31:44 -080059 private static final String TAG = "ConnectivityService";
60
Robert Greenwalt2034b912009-08-12 16:08:25 -070061 // how long to wait before switching back to a radio's default network
62 private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
63 // system property that can override the above value
64 private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
65 "android.telephony.apn-restore";
66
Robert Greenwalt0c4828c2010-01-26 11:40:34 -080067
68 private Tethering mTethering;
69
The Android Open Source Project28527d22009-03-03 19:31:44 -080070 /**
71 * Sometimes we want to refer to the individual network state
72 * trackers separately, and sometimes we just want to treat them
73 * abstractly.
74 */
75 private NetworkStateTracker mNetTrackers[];
Robert Greenwalt2034b912009-08-12 16:08:25 -070076
77 /**
78 * A per Net list of the PID's that requested access to the net
79 * used both as a refcount and for per-PID DNS selection
80 */
81 private List mNetRequestersPids[];
82
The Android Open Source Project28527d22009-03-03 19:31:44 -080083 private WifiWatchdogService mWifiWatchdogService;
84
Robert Greenwalt2034b912009-08-12 16:08:25 -070085 // priority order of the nettrackers
86 // (excluding dynamically set mNetworkPreference)
87 // TODO - move mNetworkTypePreference into this
88 private int[] mPriorityList;
89
The Android Open Source Project28527d22009-03-03 19:31:44 -080090 private Context mContext;
91 private int mNetworkPreference;
Robert Greenwalt2034b912009-08-12 16:08:25 -070092 private int mActiveDefaultNetwork = -1;
The Android Open Source Project28527d22009-03-03 19:31:44 -080093
94 private int mNumDnsEntries;
The Android Open Source Project28527d22009-03-03 19:31:44 -080095
96 private boolean mTestMode;
97 private static ConnectivityService sServiceInstance;
98
Robert Greenwalt2034b912009-08-12 16:08:25 -070099 private Handler mHandler;
100
101 // list of DeathRecipients used to make sure features are turned off when
102 // a process dies
103 private List mFeatureUsers;
104
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400105 private boolean mSystemReady;
Dianne Hackborna417ff82009-12-08 19:45:14 -0800106 private Intent mInitialBroadcast;
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400107
Robert Greenwalt12c44552009-12-07 11:33:18 -0800108 private static class NetworkAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700109 /**
110 * Class for holding settings read from resources.
111 */
112 public String mName;
113 public int mType;
114 public int mRadio;
115 public int mPriority;
Robert Greenwalt12c44552009-12-07 11:33:18 -0800116 public NetworkInfo.State mLastState;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700117 public NetworkAttributes(String init) {
118 String fragments[] = init.split(",");
119 mName = fragments[0].toLowerCase();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700120 mType = Integer.parseInt(fragments[1]);
121 mRadio = Integer.parseInt(fragments[2]);
122 mPriority = Integer.parseInt(fragments[3]);
Robert Greenwalt12c44552009-12-07 11:33:18 -0800123 mLastState = NetworkInfo.State.UNKNOWN;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700124 }
125 public boolean isDefault() {
126 return (mType == mRadio);
127 }
128 }
129 NetworkAttributes[] mNetAttributes;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700130 int mNetworksDefined;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700131
Robert Greenwalt12c44552009-12-07 11:33:18 -0800132 private static class RadioAttributes {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700133 public int mSimultaneity;
134 public int mType;
135 public RadioAttributes(String init) {
136 String fragments[] = init.split(",");
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700137 mType = Integer.parseInt(fragments[0]);
138 mSimultaneity = Integer.parseInt(fragments[1]);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700139 }
140 }
141 RadioAttributes[] mRadioAttributes;
142
The Android Open Source Project28527d22009-03-03 19:31:44 -0800143 private static class ConnectivityThread extends Thread {
144 private Context mContext;
Robert Greenwalt0659da32009-07-16 17:21:39 -0700145
The Android Open Source Project28527d22009-03-03 19:31:44 -0800146 private ConnectivityThread(Context context) {
147 super("ConnectivityThread");
148 mContext = context;
149 }
150
151 @Override
152 public void run() {
153 Looper.prepare();
154 synchronized (this) {
155 sServiceInstance = new ConnectivityService(mContext);
156 notifyAll();
157 }
158 Looper.loop();
159 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700160
The Android Open Source Project28527d22009-03-03 19:31:44 -0800161 public static ConnectivityService getServiceInstance(Context context) {
162 ConnectivityThread thread = new ConnectivityThread(context);
163 thread.start();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700164
The Android Open Source Project28527d22009-03-03 19:31:44 -0800165 synchronized (thread) {
166 while (sServiceInstance == null) {
167 try {
168 // Wait until sServiceInstance has been initialized.
169 thread.wait();
170 } catch (InterruptedException ignore) {
171 Log.e(TAG,
Robert Greenwalt0659da32009-07-16 17:21:39 -0700172 "Unexpected InterruptedException while waiting"+
173 " for ConnectivityService thread");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800174 }
175 }
176 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700177
The Android Open Source Project28527d22009-03-03 19:31:44 -0800178 return sServiceInstance;
179 }
180 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700181
The Android Open Source Project28527d22009-03-03 19:31:44 -0800182 public static ConnectivityService getInstance(Context context) {
183 return ConnectivityThread.getServiceInstance(context);
184 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700185
The Android Open Source Project28527d22009-03-03 19:31:44 -0800186 private ConnectivityService(Context context) {
187 if (DBG) Log.v(TAG, "ConnectivityService starting up");
Robert Greenwaltd48f8ee2010-01-14 17:47:58 -0800188
189 // setup our unique device name
190 String id = Settings.Secure.getString(context.getContentResolver(),
191 Settings.Secure.ANDROID_ID);
192 if (id != null && id.length() > 0) {
193 String name = new String("android_").concat(id);
194 SystemProperties.set("net.hostname", name);
195 }
196
The Android Open Source Project28527d22009-03-03 19:31:44 -0800197 mContext = context;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700198 mNetTrackers = new NetworkStateTracker[
199 ConnectivityManager.MAX_NETWORK_TYPE+1];
200 mHandler = new MyHandler();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700201
The Android Open Source Project28527d22009-03-03 19:31:44 -0800202 mNetworkPreference = getPersistedNetworkPreference();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700203
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700204 mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
205 mNetAttributes = new NetworkAttributes[ConnectivityManager.MAX_NETWORK_TYPE+1];
206
Robert Greenwalt2034b912009-08-12 16:08:25 -0700207 // Load device network attributes from resources
Robert Greenwalt2034b912009-08-12 16:08:25 -0700208 String[] raStrings = context.getResources().getStringArray(
209 com.android.internal.R.array.radioAttributes);
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700210 for (String raString : raStrings) {
211 RadioAttributes r = new RadioAttributes(raString);
212 if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) {
213 Log.e(TAG, "Error in radioAttributes - ignoring attempt to define type " + r.mType);
214 continue;
215 }
216 if (mRadioAttributes[r.mType] != null) {
217 Log.e(TAG, "Error in radioAttributes - ignoring attempt to redefine type " +
218 r.mType);
219 continue;
220 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700221 mRadioAttributes[r.mType] = r;
222 }
223
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700224 String[] naStrings = context.getResources().getStringArray(
225 com.android.internal.R.array.networkAttributes);
226 for (String naString : naStrings) {
227 try {
228 NetworkAttributes n = new NetworkAttributes(naString);
229 if (n.mType > ConnectivityManager.MAX_NETWORK_TYPE) {
230 Log.e(TAG, "Error in networkAttributes - ignoring attempt to define type " +
231 n.mType);
232 continue;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700233 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700234 if (mNetAttributes[n.mType] != null) {
235 Log.e(TAG, "Error in networkAttributes - ignoring attempt to redefine type " +
236 n.mType);
237 continue;
238 }
239 if (mRadioAttributes[n.mRadio] == null) {
240 Log.e(TAG, "Error in networkAttributes - ignoring attempt to use undefined " +
241 "radio " + n.mRadio + " in network type " + n.mType);
242 continue;
243 }
244 mNetAttributes[n.mType] = n;
245 mNetworksDefined++;
246 } catch(Exception e) {
247 // ignore it - leave the entry null
Robert Greenwalt2034b912009-08-12 16:08:25 -0700248 }
249 }
250
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700251 // high priority first
252 mPriorityList = new int[mNetworksDefined];
253 {
254 int insertionPoint = mNetworksDefined-1;
255 int currentLowest = 0;
256 int nextLowest = 0;
257 while (insertionPoint > -1) {
258 for (NetworkAttributes na : mNetAttributes) {
259 if (na == null) continue;
260 if (na.mPriority < currentLowest) continue;
261 if (na.mPriority > currentLowest) {
262 if (na.mPriority < nextLowest || nextLowest == 0) {
263 nextLowest = na.mPriority;
264 }
265 continue;
266 }
267 mPriorityList[insertionPoint--] = na.mType;
268 }
269 currentLowest = nextLowest;
270 nextLowest = 0;
271 }
272 }
273
274 mNetRequestersPids = new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
275 for (int i : mPriorityList) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700276 mNetRequestersPids[i] = new ArrayList();
277 }
278
279 mFeatureUsers = new ArrayList();
280
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700281 mNumDnsEntries = 0;
282
283 mTestMode = SystemProperties.get("cm.test.mode").equals("true")
284 && SystemProperties.get("ro.build.type").equals("eng");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800285 /*
286 * Create the network state trackers for Wi-Fi and mobile
287 * data. Maybe this could be done with a factory class,
288 * but it's not clear that it's worth it, given that
289 * the number of different network types is not going
290 * to change very often.
291 */
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700292 for (int netType : mPriorityList) {
293 switch (mNetAttributes[netType].mRadio) {
294 case ConnectivityManager.TYPE_WIFI:
295 if (DBG) Log.v(TAG, "Starting Wifi Service.");
296 WifiStateTracker wst = new WifiStateTracker(context, mHandler);
297 WifiService wifiService = new WifiService(context, wst);
298 ServiceManager.addService(Context.WIFI_SERVICE, wifiService);
299 mNetTrackers[ConnectivityManager.TYPE_WIFI] = wst;
300 wst.startMonitoring();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800301
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700302 // Constructing this starts it too
303 mWifiWatchdogService = new WifiWatchdogService(context, wst);
304 break;
305 case ConnectivityManager.TYPE_MOBILE:
306 mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
307 netType, mNetAttributes[netType].mName);
308 mNetTrackers[netType].startMonitoring();
309 break;
310 default:
311 Log.e(TAG, "Trying to create a DataStateTracker for an unknown radio type " +
312 mNetAttributes[netType].mRadio);
313 continue;
314 }
315 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -0800316
317 mTethering = new Tethering(mContext);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800318 }
319
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700320
The Android Open Source Project28527d22009-03-03 19:31:44 -0800321 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700322 * Sets the preferred network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800323 * @param preference the new preference
324 */
325 public synchronized void setNetworkPreference(int preference) {
326 enforceChangePermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700327 if (ConnectivityManager.isNetworkTypeValid(preference) &&
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700328 mNetAttributes[preference] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700329 mNetAttributes[preference].isDefault()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800330 if (mNetworkPreference != preference) {
331 persistNetworkPreference(preference);
332 mNetworkPreference = preference;
333 enforcePreference();
334 }
335 }
336 }
337
338 public int getNetworkPreference() {
339 enforceAccessPermission();
340 return mNetworkPreference;
341 }
342
343 private void persistNetworkPreference(int networkPreference) {
344 final ContentResolver cr = mContext.getContentResolver();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700345 Settings.Secure.putInt(cr, Settings.Secure.NETWORK_PREFERENCE,
346 networkPreference);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800347 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700348
The Android Open Source Project28527d22009-03-03 19:31:44 -0800349 private int getPersistedNetworkPreference() {
350 final ContentResolver cr = mContext.getContentResolver();
351
352 final int networkPrefSetting = Settings.Secure
353 .getInt(cr, Settings.Secure.NETWORK_PREFERENCE, -1);
354 if (networkPrefSetting != -1) {
355 return networkPrefSetting;
356 }
357
358 return ConnectivityManager.DEFAULT_NETWORK_PREFERENCE;
359 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700360
The Android Open Source Project28527d22009-03-03 19:31:44 -0800361 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700362 * Make the state of network connectivity conform to the preference settings
The Android Open Source Project28527d22009-03-03 19:31:44 -0800363 * In this method, we only tear down a non-preferred network. Establishing
364 * a connection to the preferred network is taken care of when we handle
365 * the disconnect event from the non-preferred network
366 * (see {@link #handleDisconnect(NetworkInfo)}).
367 */
368 private void enforcePreference() {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700369 if (mNetTrackers[mNetworkPreference].getNetworkInfo().isConnected())
The Android Open Source Project28527d22009-03-03 19:31:44 -0800370 return;
371
Robert Greenwalt2034b912009-08-12 16:08:25 -0700372 if (!mNetTrackers[mNetworkPreference].isAvailable())
373 return;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800374
Robert Greenwalt2034b912009-08-12 16:08:25 -0700375 for (int t=0; t <= ConnectivityManager.MAX_RADIO_TYPE; t++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700376 if (t != mNetworkPreference && mNetTrackers[t] != null &&
Robert Greenwalt2034b912009-08-12 16:08:25 -0700377 mNetTrackers[t].getNetworkInfo().isConnected()) {
Robert Greenwaltf3f045b2009-08-20 15:25:14 -0700378 if (DBG) {
379 Log.d(TAG, "tearing down " +
380 mNetTrackers[t].getNetworkInfo() +
381 " in enforcePreference");
382 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700383 teardown(mNetTrackers[t]);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800384 }
385 }
386 }
387
388 private boolean teardown(NetworkStateTracker netTracker) {
389 if (netTracker.teardown()) {
390 netTracker.setTeardownRequested(true);
391 return true;
392 } else {
393 return false;
394 }
395 }
396
397 /**
398 * Return NetworkInfo for the active (i.e., connected) network interface.
399 * It is assumed that at most one network is active at a time. If more
400 * than one is active, it is indeterminate which will be returned.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700401 * @return the info for the active network, or {@code null} if none is
402 * active
The Android Open Source Project28527d22009-03-03 19:31:44 -0800403 */
404 public NetworkInfo getActiveNetworkInfo() {
405 enforceAccessPermission();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700406 for (int type=0; type <= ConnectivityManager.MAX_NETWORK_TYPE; type++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700407 if (mNetAttributes[type] == null || !mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700408 continue;
409 }
410 NetworkStateTracker t = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800411 NetworkInfo info = t.getNetworkInfo();
412 if (info.isConnected()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700413 if (DBG && type != mActiveDefaultNetwork) Log.e(TAG,
414 "connected default network is not " +
415 "mActiveDefaultNetwork!");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800416 return info;
417 }
418 }
419 return null;
420 }
421
422 public NetworkInfo getNetworkInfo(int networkType) {
423 enforceAccessPermission();
424 if (ConnectivityManager.isNetworkTypeValid(networkType)) {
425 NetworkStateTracker t = mNetTrackers[networkType];
426 if (t != null)
427 return t.getNetworkInfo();
428 }
429 return null;
430 }
431
432 public NetworkInfo[] getAllNetworkInfo() {
433 enforceAccessPermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700434 NetworkInfo[] result = new NetworkInfo[mNetworksDefined];
The Android Open Source Project28527d22009-03-03 19:31:44 -0800435 int i = 0;
436 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700437 if(t != null) result[i++] = t.getNetworkInfo();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800438 }
439 return result;
440 }
441
442 public boolean setRadios(boolean turnOn) {
443 boolean result = true;
444 enforceChangePermission();
445 for (NetworkStateTracker t : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700446 if (t != null) result = t.setRadio(turnOn) && result;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800447 }
448 return result;
449 }
450
451 public boolean setRadio(int netType, boolean turnOn) {
452 enforceChangePermission();
453 if (!ConnectivityManager.isNetworkTypeValid(netType)) {
454 return false;
455 }
456 NetworkStateTracker tracker = mNetTrackers[netType];
457 return tracker != null && tracker.setRadio(turnOn);
458 }
459
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700460 /**
461 * Used to notice when the calling process dies so we can self-expire
462 *
463 * Also used to know if the process has cleaned up after itself when
464 * our auto-expire timer goes off. The timer has a link to an object.
465 *
466 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700467 private class FeatureUser implements IBinder.DeathRecipient {
468 int mNetworkType;
469 String mFeature;
470 IBinder mBinder;
471 int mPid;
472 int mUid;
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800473 long mCreateTime;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700474
475 FeatureUser(int type, String feature, IBinder binder) {
476 super();
477 mNetworkType = type;
478 mFeature = feature;
479 mBinder = binder;
480 mPid = getCallingPid();
481 mUid = getCallingUid();
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800482 mCreateTime = System.currentTimeMillis();
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700483
Robert Greenwalt2034b912009-08-12 16:08:25 -0700484 try {
485 mBinder.linkToDeath(this, 0);
486 } catch (RemoteException e) {
487 binderDied();
488 }
489 }
490
491 void unlinkDeathRecipient() {
492 mBinder.unlinkToDeath(this, 0);
493 }
494
495 public void binderDied() {
496 Log.d(TAG, "ConnectivityService FeatureUser binderDied(" +
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);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700500 }
501
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700502 public void expire() {
503 Log.d(TAG, "ConnectivityService FeatureUser expire(" +
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800504 mNetworkType + ", " + mFeature + ", " + mBinder +"), created " +
505 (System.currentTimeMillis() - mCreateTime) + " mSec ago");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700506 stopUsingNetworkFeature(this, false);
507 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800508
509 public String toString() {
510 return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
511 (System.currentTimeMillis() - mCreateTime) + " mSec ago";
512 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700513 }
514
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700515 // javadoc from interface
Robert Greenwalt2034b912009-08-12 16:08:25 -0700516 public int startUsingNetworkFeature(int networkType, String feature,
517 IBinder binder) {
518 if (DBG) {
519 Log.d(TAG, "startUsingNetworkFeature for net " + networkType +
520 ": " + feature);
521 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800522 enforceChangePermission();
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700523 if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
524 mNetAttributes[networkType] == null) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700525 return Phone.APN_REQUEST_FAILED;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800526 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700527
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700528 FeatureUser f = new FeatureUser(networkType, feature, binder);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700529
530 // TODO - move this into the MobileDataStateTracker
531 int usedNetworkType = networkType;
532 if(networkType == ConnectivityManager.TYPE_MOBILE) {
533 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
534 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
535 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
536 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
537 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
538 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
539 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
540 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
541 }
542 }
543 NetworkStateTracker network = mNetTrackers[usedNetworkType];
544 if (network != null) {
545 if (usedNetworkType != networkType) {
546 Integer currentPid = new Integer(getCallingPid());
547
548 NetworkStateTracker radio = mNetTrackers[networkType];
549 NetworkInfo ni = network.getNetworkInfo();
550
551 if (ni.isAvailable() == false) {
552 if (DBG) Log.d(TAG, "special network not available");
553 return Phone.APN_TYPE_NOT_AVAILABLE;
554 }
555
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700556 synchronized(this) {
557 mFeatureUsers.add(f);
558 if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
559 // this gets used for per-pid dns when connected
560 mNetRequestersPids[usedNetworkType].add(currentPid);
561 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700562 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700563 mHandler.sendMessageDelayed(mHandler.obtainMessage(
564 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
565 f), getRestoreDefaultNetworkDelay());
566
Robert Greenwalt2034b912009-08-12 16:08:25 -0700567
Robert Greenwalta52c75a2009-08-19 20:19:33 -0700568 if ((ni.isConnectedOrConnecting() == true) &&
569 !network.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700570 if (ni.isConnected() == true) {
571 // add the pid-specific dns
572 handleDnsConfigurationChange();
573 if (DBG) Log.d(TAG, "special network already active");
574 return Phone.APN_ALREADY_ACTIVE;
575 }
576 if (DBG) Log.d(TAG, "special network already connecting");
577 return Phone.APN_REQUEST_STARTED;
578 }
579
580 // check if the radio in play can make another contact
581 // assume if cannot for now
582
Robert Greenwalt2034b912009-08-12 16:08:25 -0700583 if (DBG) Log.d(TAG, "reconnecting to special network");
584 network.reconnect();
585 return Phone.APN_REQUEST_STARTED;
586 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700587 synchronized(this) {
588 mFeatureUsers.add(f);
589 }
590 mHandler.sendMessageDelayed(mHandler.obtainMessage(
591 NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK,
592 f), getRestoreDefaultNetworkDelay());
593
Robert Greenwalt2034b912009-08-12 16:08:25 -0700594 return network.startUsingNetworkFeature(feature,
595 getCallingPid(), getCallingUid());
596 }
597 }
598 return Phone.APN_TYPE_NOT_AVAILABLE;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800599 }
600
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700601 // javadoc from interface
The Android Open Source Project28527d22009-03-03 19:31:44 -0800602 public int stopUsingNetworkFeature(int networkType, String feature) {
Robert Greenwalt28f43012009-10-06 17:52:40 -0700603 enforceChangePermission();
604
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700605 int pid = getCallingPid();
606 int uid = getCallingUid();
607
608 FeatureUser u = null;
609 boolean found = false;
610
611 synchronized(this) {
612 for (int i = 0; i < mFeatureUsers.size() ; i++) {
613 u = (FeatureUser)mFeatureUsers.get(i);
614 if (uid == u.mUid && pid == u.mPid &&
615 networkType == u.mNetworkType &&
616 TextUtils.equals(feature, u.mFeature)) {
617 found = true;
618 break;
619 }
620 }
621 }
622 if (found && u != null) {
623 // stop regardless of how many other time this proc had called start
624 return stopUsingNetworkFeature(u, true);
625 } else {
626 // none found!
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800627 if (DBG) Log.d(TAG, "ignoring stopUsingNetworkFeature - not a live request");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700628 return 1;
629 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700630 }
631
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700632 private int stopUsingNetworkFeature(FeatureUser u, boolean ignoreDups) {
633 int networkType = u.mNetworkType;
634 String feature = u.mFeature;
635 int pid = u.mPid;
636 int uid = u.mUid;
637
638 NetworkStateTracker tracker = null;
639 boolean callTeardown = false; // used to carry our decision outside of sync block
640
Robert Greenwalt2034b912009-08-12 16:08:25 -0700641 if (DBG) {
642 Log.d(TAG, "stopUsingNetworkFeature for net " + networkType +
643 ": " + feature);
644 }
Robert Greenwalt28f43012009-10-06 17:52:40 -0700645
The Android Open Source Project28527d22009-03-03 19:31:44 -0800646 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
647 return -1;
648 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700649
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700650 // need to link the mFeatureUsers list with the mNetRequestersPids state in this
651 // sync block
652 synchronized(this) {
653 // check if this process still has an outstanding start request
654 if (!mFeatureUsers.contains(u)) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700655 return 1;
656 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700657 u.unlinkDeathRecipient();
658 mFeatureUsers.remove(mFeatureUsers.indexOf(u));
659 // If we care about duplicate requests, check for that here.
660 //
661 // This is done to support the extension of a request - the app
662 // can request we start the network feature again and renew the
663 // auto-shutoff delay. Normal "stop" calls from the app though
664 // do not pay attention to duplicate requests - in effect the
665 // API does not refcount and a single stop will counter multiple starts.
666 if (ignoreDups == false) {
667 for (int i = 0; i < mFeatureUsers.size() ; i++) {
668 FeatureUser x = (FeatureUser)mFeatureUsers.get(i);
669 if (x.mUid == u.mUid && x.mPid == u.mPid &&
670 x.mNetworkType == u.mNetworkType &&
671 TextUtils.equals(x.mFeature, u.mFeature)) {
Robert Greenwalt3eeb6032009-12-21 18:24:07 -0800672 if (DBG) Log.d(TAG, "ignoring stopUsingNetworkFeature as dup is found");
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700673 return 1;
674 }
675 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700676 }
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700677
678 // TODO - move to MobileDataStateTracker
679 int usedNetworkType = networkType;
680 if (networkType == ConnectivityManager.TYPE_MOBILE) {
681 if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
682 usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
683 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
684 usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
685 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN)) {
686 usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
687 } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
688 usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
689 }
690 }
691 tracker = mNetTrackers[usedNetworkType];
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700692 if (tracker == null) {
693 return -1;
694 }
695 if (usedNetworkType != networkType) {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700696 Integer currentPid = new Integer(pid);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700697 mNetRequestersPids[usedNetworkType].remove(currentPid);
Robert Greenwalt0ca68a02009-12-17 14:54:59 -0800698 reassessPidDns(pid, true);
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700699 if (mNetRequestersPids[usedNetworkType].size() != 0) {
700 if (DBG) Log.d(TAG, "not tearing down special network - " +
701 "others still using it");
702 return 1;
703 }
704 callTeardown = true;
705 }
706 }
707
708 if (callTeardown) {
709 tracker.teardown();
Robert Greenwalt2034b912009-08-12 16:08:25 -0700710 return 1;
711 } else {
Robert Greenwaltaffc3a12009-09-27 17:27:04 -0700712 // do it the old fashioned way
Robert Greenwalt2034b912009-08-12 16:08:25 -0700713 return tracker.stopUsingNetworkFeature(feature, pid, uid);
714 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800715 }
716
717 /**
718 * Ensure that a network route exists to deliver traffic to the specified
719 * host via the specified network interface.
Robert Greenwalt0659da32009-07-16 17:21:39 -0700720 * @param networkType the type of the network over which traffic to the
721 * specified host is to be routed
722 * @param hostAddress the IP address of the host to which the route is
723 * desired
The Android Open Source Project28527d22009-03-03 19:31:44 -0800724 * @return {@code true} on success, {@code false} on failure
725 */
726 public boolean requestRouteToHost(int networkType, int hostAddress) {
727 enforceChangePermission();
728 if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
729 return false;
730 }
731 NetworkStateTracker tracker = mNetTrackers[networkType];
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700732
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700733 if (tracker == null || !tracker.getNetworkInfo().isConnected() ||
734 tracker.isTeardownRequested()) {
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700735 if (DBG) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700736 Log.d(TAG, "requestRouteToHost on down network (" + networkType + ") - dropped");
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700737 }
738 return false;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800739 }
Robert Greenwalt4666ed02009-09-10 15:06:20 -0700740 return tracker.requestRouteToHost(hostAddress);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800741 }
742
743 /**
744 * @see ConnectivityManager#getBackgroundDataSetting()
745 */
746 public boolean getBackgroundDataSetting() {
747 return Settings.Secure.getInt(mContext.getContentResolver(),
748 Settings.Secure.BACKGROUND_DATA, 1) == 1;
749 }
Robert Greenwalt0659da32009-07-16 17:21:39 -0700750
The Android Open Source Project28527d22009-03-03 19:31:44 -0800751 /**
752 * @see ConnectivityManager#setBackgroundDataSetting(boolean)
753 */
754 public void setBackgroundDataSetting(boolean allowBackgroundDataUsage) {
755 mContext.enforceCallingOrSelfPermission(
756 android.Manifest.permission.CHANGE_BACKGROUND_DATA_SETTING,
757 "ConnectivityService");
Robert Greenwalt0659da32009-07-16 17:21:39 -0700758
The Android Open Source Project28527d22009-03-03 19:31:44 -0800759 if (getBackgroundDataSetting() == allowBackgroundDataUsage) return;
760
761 Settings.Secure.putInt(mContext.getContentResolver(),
Robert Greenwalt0659da32009-07-16 17:21:39 -0700762 Settings.Secure.BACKGROUND_DATA,
763 allowBackgroundDataUsage ? 1 : 0);
764
The Android Open Source Project28527d22009-03-03 19:31:44 -0800765 Intent broadcast = new Intent(
766 ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
767 mContext.sendBroadcast(broadcast);
Robert Greenwalt0659da32009-07-16 17:21:39 -0700768 }
769
The Android Open Source Project28527d22009-03-03 19:31:44 -0800770 private int getNumConnectedNetworks() {
771 int numConnectedNets = 0;
772
773 for (NetworkStateTracker nt : mNetTrackers) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700774 if (nt != null && nt.getNetworkInfo().isConnected() &&
Robert Greenwalt0659da32009-07-16 17:21:39 -0700775 !nt.isTeardownRequested()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -0800776 ++numConnectedNets;
777 }
778 }
779 return numConnectedNets;
780 }
781
782 private void enforceAccessPermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700783 mContext.enforceCallingOrSelfPermission(
784 android.Manifest.permission.ACCESS_NETWORK_STATE,
785 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800786 }
787
788 private void enforceChangePermission() {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700789 mContext.enforceCallingOrSelfPermission(
790 android.Manifest.permission.CHANGE_NETWORK_STATE,
791 "ConnectivityService");
The Android Open Source Project28527d22009-03-03 19:31:44 -0800792 }
793
Robert Greenwalt0c4828c2010-01-26 11:40:34 -0800794 // TODO Make this a special check when it goes public
795 private void enforceTetherChangePermission() {
796 mContext.enforceCallingOrSelfPermission(
797 android.Manifest.permission.CHANGE_NETWORK_STATE,
798 "ConnectivityService");
799 }
800
The Android Open Source Project28527d22009-03-03 19:31:44 -0800801 /**
Robert Greenwalt0659da32009-07-16 17:21:39 -0700802 * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
803 * network, we ignore it. If it is for the active network, we send out a
804 * broadcast. But first, we check whether it might be possible to connect
805 * to a different network.
The Android Open Source Project28527d22009-03-03 19:31:44 -0800806 * @param info the {@code NetworkInfo} for the network
807 */
808 private void handleDisconnect(NetworkInfo info) {
809
Robert Greenwalt2034b912009-08-12 16:08:25 -0700810 int prevNetType = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -0800811
Robert Greenwalt2034b912009-08-12 16:08:25 -0700812 mNetTrackers[prevNetType].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800813 /*
814 * If the disconnected network is not the active one, then don't report
815 * this as a loss of connectivity. What probably happened is that we're
816 * getting the disconnect for a network that we explicitly disabled
817 * in accordance with network preference policies.
818 */
Robert Greenwalt2034b912009-08-12 16:08:25 -0700819 if (!mNetAttributes[prevNetType].isDefault()) {
820 List pids = mNetRequestersPids[prevNetType];
821 for (int i = 0; i<pids.size(); i++) {
822 Integer pid = (Integer)pids.get(i);
823 // will remove them because the net's no longer connected
824 // need to do this now as only now do we know the pids and
825 // can properly null things that are no longer referenced.
826 reassessPidDns(pid.intValue(), false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800827 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800828 }
829
The Android Open Source Project28527d22009-03-03 19:31:44 -0800830 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800831 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800832 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
833 if (info.isFailover()) {
834 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
835 info.setFailover(false);
836 }
837 if (info.getReason() != null) {
838 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
839 }
840 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700841 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
842 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -0800843 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700844
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800845 NetworkStateTracker newNet = null;
846 if (mNetAttributes[prevNetType].isDefault()) {
847 newNet = tryFailover(prevNetType);
848 if (newNet != null) {
849 NetworkInfo switchTo = newNet.getNetworkInfo();
850 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
851 } else {
852 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
853 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800854 }
855 // do this before we broadcast the change
856 handleConnectivityChange();
857
858 sendStickyBroadcast(intent);
859 /*
860 * If the failover network is already connected, then immediately send
861 * out a followup broadcast indicating successful failover
862 */
863 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
864 sendConnectedBroadcast(newNet.getNetworkInfo());
865 }
866 }
867
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800868 // returns null if no failover available
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800869 private NetworkStateTracker tryFailover(int prevNetType) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700870 /*
871 * If this is a default network, check if other defaults are available
872 * or active
873 */
874 NetworkStateTracker newNet = null;
875 if (mNetAttributes[prevNetType].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700876 if (mActiveDefaultNetwork == prevNetType) {
877 mActiveDefaultNetwork = -1;
878 }
879
880 int newType = -1;
881 int newPriority = -1;
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800882 for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700883 if (checkType == prevNetType) continue;
884 if (mNetAttributes[checkType] == null) continue;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700885 if (mNetAttributes[checkType].isDefault()) {
886 /* TODO - if we have multiple nets we could use
887 * we may want to put more thought into which we choose
888 */
889 if (checkType == mNetworkPreference) {
890 newType = checkType;
891 break;
892 }
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700893 if (mNetAttributes[checkType].mPriority > newPriority) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700894 newType = checkType;
Robert Greenwaltec05b3c2009-10-30 14:17:42 -0700895 newPriority = mNetAttributes[newType].mPriority;
Robert Greenwalt2034b912009-08-12 16:08:25 -0700896 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800897 }
898 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700899
900 if (newType != -1) {
901 newNet = mNetTrackers[newType];
902 /**
903 * See if the other network is available to fail over to.
904 * If is not available, we enable it anyway, so that it
905 * will be able to connect when it does become available,
906 * but we report a total loss of connectivity rather than
907 * report that we are attempting to fail over.
908 */
909 if (newNet.isAvailable()) {
910 NetworkInfo switchTo = newNet.getNetworkInfo();
911 switchTo.setFailover(true);
Robert Greenwalta52c75a2009-08-19 20:19:33 -0700912 if (!switchTo.isConnectedOrConnecting() ||
913 newNet.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -0700914 newNet.reconnect();
915 }
916 if (DBG) {
917 if (switchTo.isConnected()) {
918 Log.v(TAG, "Switching to already connected " +
919 switchTo.getTypeName());
920 } else {
921 Log.v(TAG, "Attempting to switch to " +
922 switchTo.getTypeName());
923 }
924 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700925 } else {
926 newNet.reconnect();
927 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700928 }
The Android Open Source Project28527d22009-03-03 19:31:44 -0800929 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700930
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800931 return newNet;
The Android Open Source Project28527d22009-03-03 19:31:44 -0800932 }
933
934 private void sendConnectedBroadcast(NetworkInfo info) {
935 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800936 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800937 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
938 if (info.isFailover()) {
939 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
940 info.setFailover(false);
941 }
942 if (info.getReason() != null) {
943 intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
944 }
945 if (info.getExtraInfo() != null) {
Robert Greenwalt0659da32009-07-16 17:21:39 -0700946 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
947 info.getExtraInfo());
The Android Open Source Project28527d22009-03-03 19:31:44 -0800948 }
Mike Lockwoodfde2b762009-08-14 14:18:49 -0400949 sendStickyBroadcast(intent);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800950 }
951
952 /**
953 * Called when an attempt to fail over to another network has failed.
954 * @param info the {@link NetworkInfo} for the failed network
955 */
956 private void handleConnectionFailure(NetworkInfo info) {
957 mNetTrackers[info.getType()].setTeardownRequested(false);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800958
Robert Greenwalt2034b912009-08-12 16:08:25 -0700959 String reason = info.getReason();
960 String extraInfo = info.getExtraInfo();
Robert Greenwalt0659da32009-07-16 17:21:39 -0700961
Robert Greenwalt2034b912009-08-12 16:08:25 -0700962 if (DBG) {
963 String reasonText;
964 if (reason == null) {
965 reasonText = ".";
966 } else {
967 reasonText = " (" + reason + ").";
The Android Open Source Project28527d22009-03-03 19:31:44 -0800968 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700969 Log.v(TAG, "Attempt to connect to " + info.getTypeName() +
970 " failed" + reasonText);
The Android Open Source Project28527d22009-03-03 19:31:44 -0800971 }
Robert Greenwalt2034b912009-08-12 16:08:25 -0700972
973 Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
Dianne Hackborna417ff82009-12-08 19:45:14 -0800974 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
Robert Greenwalt2034b912009-08-12 16:08:25 -0700975 intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
976 if (getActiveNetworkInfo() == null) {
977 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
978 }
979 if (reason != null) {
980 intent.putExtra(ConnectivityManager.EXTRA_REASON, reason);
981 }
982 if (extraInfo != null) {
983 intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, extraInfo);
984 }
985 if (info.isFailover()) {
986 intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
987 info.setFailover(false);
988 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800989
Robert Greenwalt3cc68d32010-01-25 17:54:29 -0800990 NetworkStateTracker newNet = null;
991 if (mNetAttributes[info.getType()].isDefault()) {
992 newNet = tryFailover(info.getType());
993 if (newNet != null) {
994 NetworkInfo switchTo = newNet.getNetworkInfo();
995 intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
996 } else {
997 intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
998 }
Robert Greenwaltf55ced92010-01-20 19:29:41 -0800999 }
Robert Greenwalt3cc68d32010-01-25 17:54:29 -08001000
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001001 // do this before we broadcast the change
1002 handleConnectivityChange();
1003
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001004 sendStickyBroadcast(intent);
Robert Greenwaltf55ced92010-01-20 19:29:41 -08001005 /*
1006 * If the failover network is already connected, then immediately send
1007 * out a followup broadcast indicating successful failover
1008 */
1009 if (newNet != null && newNet.getNetworkInfo().isConnected()) {
1010 sendConnectedBroadcast(newNet.getNetworkInfo());
1011 }
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001012 }
1013
1014 private void sendStickyBroadcast(Intent intent) {
1015 synchronized(this) {
Dianne Hackborna417ff82009-12-08 19:45:14 -08001016 if (!mSystemReady) {
1017 mInitialBroadcast = new Intent(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001018 }
Dianne Hackborna417ff82009-12-08 19:45:14 -08001019 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
1020 mContext.sendStickyBroadcast(intent);
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001021 }
1022 }
1023
1024 void systemReady() {
1025 synchronized(this) {
1026 mSystemReady = true;
Dianne Hackborna417ff82009-12-08 19:45:14 -08001027 if (mInitialBroadcast != null) {
1028 mContext.sendStickyBroadcast(mInitialBroadcast);
1029 mInitialBroadcast = null;
Mike Lockwoodfde2b762009-08-14 14:18:49 -04001030 }
1031 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001032 }
1033
1034 private void handleConnect(NetworkInfo info) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001035 int type = info.getType();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001036
1037 // snapshot isFailover, because sendConnectedBroadcast() resets it
1038 boolean isFailover = info.isFailover();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001039 NetworkStateTracker thisNet = mNetTrackers[type];
The Android Open Source Project28527d22009-03-03 19:31:44 -08001040
Robert Greenwalt2034b912009-08-12 16:08:25 -07001041 // if this is a default net and other default is running
1042 // kill the one not preferred
1043 if (mNetAttributes[type].isDefault()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001044 if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
1045 if ((type != mNetworkPreference &&
1046 mNetAttributes[mActiveDefaultNetwork].mPriority >
1047 mNetAttributes[type].mPriority) ||
1048 mNetworkPreference == mActiveDefaultNetwork) {
1049 // don't accept this one
1050 if (DBG) Log.v(TAG, "Not broadcasting CONNECT_ACTION " +
1051 "to torn down network " + info.getTypeName());
1052 teardown(thisNet);
1053 return;
1054 } else {
1055 // tear down the other
1056 NetworkStateTracker otherNet =
1057 mNetTrackers[mActiveDefaultNetwork];
1058 if (DBG) Log.v(TAG, "Policy requires " +
1059 otherNet.getNetworkInfo().getTypeName() +
1060 " teardown");
1061 if (!teardown(otherNet)) {
1062 Log.e(TAG, "Network declined teardown request");
1063 return;
1064 }
1065 if (isFailover) {
1066 otherNet.releaseWakeLock();
1067 }
1068 }
1069 }
1070 mActiveDefaultNetwork = type;
1071 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001072 thisNet.setTeardownRequested(false);
Robert Greenwalt2034b912009-08-12 16:08:25 -07001073 thisNet.updateNetworkSettings();
1074 handleConnectivityChange();
1075 sendConnectedBroadcast(info);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001076 }
1077
1078 private void handleScanResultsAvailable(NetworkInfo info) {
1079 int networkType = info.getType();
1080 if (networkType != ConnectivityManager.TYPE_WIFI) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001081 if (DBG) Log.v(TAG, "Got ScanResultsAvailable for " +
1082 info.getTypeName() + " network. Don't know how to handle.");
The Android Open Source Project28527d22009-03-03 19:31:44 -08001083 }
Robert Greenwalt0659da32009-07-16 17:21:39 -07001084
The Android Open Source Project28527d22009-03-03 19:31:44 -08001085 mNetTrackers[networkType].interpretScanResultsAvailable();
1086 }
1087
Robert Greenwalt0659da32009-07-16 17:21:39 -07001088 private void handleNotificationChange(boolean visible, int id,
1089 Notification notification) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001090 NotificationManager notificationManager = (NotificationManager) mContext
1091 .getSystemService(Context.NOTIFICATION_SERVICE);
Robert Greenwalt0659da32009-07-16 17:21:39 -07001092
The Android Open Source Project28527d22009-03-03 19:31:44 -08001093 if (visible) {
1094 notificationManager.notify(id, notification);
1095 } else {
1096 notificationManager.cancel(id);
1097 }
1098 }
1099
1100 /**
1101 * After any kind of change in the connectivity state of any network,
1102 * make sure that anything that depends on the connectivity state of
1103 * more than one network is set up correctly. We're mainly concerned
1104 * with making sure that the list of DNS servers is set up according
1105 * to which networks are connected, and ensuring that the right routing
1106 * table entries exist.
1107 */
1108 private void handleConnectivityChange() {
1109 /*
Robert Greenwalt2034b912009-08-12 16:08:25 -07001110 * If a non-default network is enabled, add the host routes that
Robert Greenwalt423dbbc2009-09-30 21:01:30 -07001111 * will allow it's DNS servers to be accessed. Only
The Android Open Source Project28527d22009-03-03 19:31:44 -08001112 * If both mobile and wifi are enabled, add the host routes that
1113 * will allow MMS traffic to pass on the mobile network. But
1114 * remove the default route for the mobile network, so that there
1115 * will be only one default route, to ensure that all traffic
1116 * except MMS will travel via Wi-Fi.
1117 */
Robert Greenwalt2034b912009-08-12 16:08:25 -07001118 handleDnsConfigurationChange();
1119
1120 for (int netType : mPriorityList) {
1121 if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
1122 if (mNetAttributes[netType].isDefault()) {
1123 mNetTrackers[netType].addDefaultRoute();
1124 } else {
1125 mNetTrackers[netType].addPrivateDnsRoutes();
1126 }
1127 } else {
1128 if (mNetAttributes[netType].isDefault()) {
1129 mNetTrackers[netType].removeDefaultRoute();
1130 } else {
1131 mNetTrackers[netType].removePrivateDnsRoutes();
1132 }
1133 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001134 }
1135 }
1136
Robert Greenwalt2034b912009-08-12 16:08:25 -07001137 /**
1138 * Adjust the per-process dns entries (net.dns<x>.<pid>) based
1139 * on the highest priority active net which this process requested.
1140 * If there aren't any, clear it out
1141 */
1142 private void reassessPidDns(int myPid, boolean doBump)
1143 {
1144 if (DBG) Log.d(TAG, "reassessPidDns for pid " + myPid);
1145 for(int i : mPriorityList) {
1146 if (mNetAttributes[i].isDefault()) {
1147 continue;
1148 }
1149 NetworkStateTracker nt = mNetTrackers[i];
Robert Greenwalt0659da32009-07-16 17:21:39 -07001150 if (nt.getNetworkInfo().isConnected() &&
1151 !nt.isTeardownRequested()) {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001152 List pids = mNetRequestersPids[i];
1153 for (int j=0; j<pids.size(); j++) {
1154 Integer pid = (Integer)pids.get(j);
1155 if (pid.intValue() == myPid) {
1156 String[] dnsList = nt.getNameServers();
1157 writePidDns(dnsList, myPid);
1158 if (doBump) {
1159 bumpDns();
1160 }
1161 return;
1162 }
1163 }
1164 }
1165 }
1166 // nothing found - delete
1167 for (int i = 1; ; i++) {
1168 String prop = "net.dns" + i + "." + myPid;
1169 if (SystemProperties.get(prop).length() == 0) {
1170 if (doBump) {
1171 bumpDns();
1172 }
1173 return;
1174 }
1175 SystemProperties.set(prop, "");
1176 }
1177 }
1178
1179 private void writePidDns(String[] dnsList, int pid) {
1180 int j = 1;
1181 for (String dns : dnsList) {
1182 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
1183 SystemProperties.set("net.dns" + j++ + "." + pid, dns);
1184 }
1185 }
1186 }
1187
1188 private void bumpDns() {
1189 /*
1190 * Bump the property that tells the name resolver library to reread
1191 * the DNS server list from the properties.
1192 */
1193 String propVal = SystemProperties.get("net.dnschange");
1194 int n = 0;
1195 if (propVal.length() != 0) {
1196 try {
1197 n = Integer.parseInt(propVal);
1198 } catch (NumberFormatException e) {}
1199 }
1200 SystemProperties.set("net.dnschange", "" + (n+1));
1201 }
1202
1203 private void handleDnsConfigurationChange() {
Robert Greenwalt2034b912009-08-12 16:08:25 -07001204 // add default net's dns entries
1205 for (int x = mPriorityList.length-1; x>= 0; x--) {
1206 int netType = mPriorityList[x];
1207 NetworkStateTracker nt = mNetTrackers[netType];
Robert Greenwalt2034b912009-08-12 16:08:25 -07001208 if (nt != null && nt.getNetworkInfo().isConnected() &&
1209 !nt.isTeardownRequested()) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001210 String[] dnsList = nt.getNameServers();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001211 if (mNetAttributes[netType].isDefault()) {
1212 int j = 1;
1213 for (String dns : dnsList) {
1214 if (dns != null && !TextUtils.equals(dns, "0.0.0.0")) {
Robert Greenwalt423dbbc2009-09-30 21:01:30 -07001215 if (DBG) {
1216 Log.d(TAG, "adding dns " + dns + " for " +
1217 nt.getNetworkInfo().getTypeName());
1218 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001219 SystemProperties.set("net.dns" + j++, dns);
1220 }
1221 }
1222 for (int k=j ; k<mNumDnsEntries; k++) {
Robert Greenwalt8e5b8532009-08-25 14:00:10 -07001223 if (DBG) Log.d(TAG, "erasing net.dns" + k);
1224 SystemProperties.set("net.dns" + k, "");
Robert Greenwalt2034b912009-08-12 16:08:25 -07001225 }
1226 mNumDnsEntries = j;
1227 } else {
1228 // set per-pid dns for attached secondary nets
1229 List pids = mNetRequestersPids[netType];
1230 for (int y=0; y< pids.size(); y++) {
1231 Integer pid = (Integer)pids.get(y);
1232 writePidDns(dnsList, pid.intValue());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001233 }
1234 }
1235 }
1236 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001237
1238 bumpDns();
1239 }
1240
1241 private int getRestoreDefaultNetworkDelay() {
1242 String restoreDefaultNetworkDelayStr = SystemProperties.get(
1243 NETWORK_RESTORE_DELAY_PROP_NAME);
1244 if(restoreDefaultNetworkDelayStr != null &&
1245 restoreDefaultNetworkDelayStr.length() != 0) {
1246 try {
1247 return Integer.valueOf(restoreDefaultNetworkDelayStr);
1248 } catch (NumberFormatException e) {
1249 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001250 }
Robert Greenwalt2034b912009-08-12 16:08:25 -07001251 return RESTORE_DEFAULT_NETWORK_DELAY;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001252 }
1253
1254 @Override
1255 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001256 if (mContext.checkCallingOrSelfPermission(
1257 android.Manifest.permission.DUMP)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001258 != PackageManager.PERMISSION_GRANTED) {
Robert Greenwalt0659da32009-07-16 17:21:39 -07001259 pw.println("Permission Denial: can't dump ConnectivityService " +
1260 "from from pid=" + Binder.getCallingPid() + ", uid=" +
1261 Binder.getCallingUid());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001262 return;
1263 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001264 pw.println();
1265 for (NetworkStateTracker nst : mNetTrackers) {
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001266 if (nst != null) {
1267 if (nst.getNetworkInfo().isConnected()) {
1268 pw.println("Active network: " + nst.getNetworkInfo().
1269 getTypeName());
1270 }
1271 pw.println(nst.getNetworkInfo());
1272 pw.println(nst);
1273 pw.println();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001274 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001275 }
Robert Greenwalt3eeb6032009-12-21 18:24:07 -08001276
1277 pw.println("Network Requester Pids:");
1278 for (int net : mPriorityList) {
1279 String pidString = net + ": ";
1280 for (Object pid : mNetRequestersPids[net]) {
1281 pidString = pidString + pid.toString() + ", ";
1282 }
1283 pw.println(pidString);
1284 }
1285 pw.println();
1286
1287 pw.println("FeatureUsers:");
1288 for (Object requester : mFeatureUsers) {
1289 pw.println(requester.toString());
1290 }
1291 pw.println();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001292 }
1293
Robert Greenwalt2034b912009-08-12 16:08:25 -07001294 // must be stateless - things change under us.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001295 private class MyHandler extends Handler {
1296 @Override
1297 public void handleMessage(Message msg) {
1298 NetworkInfo info;
1299 switch (msg.what) {
1300 case NetworkStateTracker.EVENT_STATE_CHANGED:
1301 info = (NetworkInfo) msg.obj;
Robert Greenwalt12c44552009-12-07 11:33:18 -08001302 int type = info.getType();
1303 NetworkInfo.State state = info.getState();
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001304 // only do this optimization for wifi. It going into scan mode for location
1305 // services generates alot of noise. Meanwhile the mms apn won't send out
1306 // subsequent notifications when on default cellular because it never
1307 // disconnects.. so only do this to wifi notifications. Fixed better when the
1308 // APN notifications are standardized.
1309 if (mNetAttributes[type].mLastState == state &&
1310 mNetAttributes[type].mRadio == ConnectivityManager.TYPE_WIFI) {
Robert Greenwalt12c44552009-12-07 11:33:18 -08001311 if (DBG) {
Robert Greenwalt24e2d2b2010-01-25 16:14:00 -08001312 // TODO - remove this after we validate the dropping doesn't break
1313 // anything
Robert Greenwalt12c44552009-12-07 11:33:18 -08001314 Log.d(TAG, "Dropping ConnectivityChange for " +
Robert Greenwalt2adbc7f2010-01-13 09:36:31 -08001315 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001316 state + "/" + info.getDetailedState());
1317 }
1318 return;
1319 }
1320 mNetAttributes[type].mLastState = state;
1321
Robert Greenwalt2034b912009-08-12 16:08:25 -07001322 if (DBG) Log.d(TAG, "ConnectivityChange for " +
Robert Greenwalt0659da32009-07-16 17:21:39 -07001323 info.getTypeName() + ": " +
Robert Greenwalt12c44552009-12-07 11:33:18 -08001324 state + "/" + info.getDetailedState());
The Android Open Source Project28527d22009-03-03 19:31:44 -08001325
1326 // Connectivity state changed:
1327 // [31-13] Reserved for future use
Robert Greenwalt0659da32009-07-16 17:21:39 -07001328 // [12-9] Network subtype (for mobile network, as defined
1329 // by TelephonyManager)
1330 // [8-3] Detailed state ordinal (as defined by
1331 // NetworkInfo.DetailedState)
The Android Open Source Project28527d22009-03-03 19:31:44 -08001332 // [2-0] Network type (as defined by ConnectivityManager)
1333 int eventLogParam = (info.getType() & 0x7) |
1334 ((info.getDetailedState().ordinal() & 0x3f) << 3) |
1335 (info.getSubtype() << 9);
Doug Zongker2fc96232009-12-04 10:31:43 -08001336 EventLog.writeEvent(EventLogTags.CONNECTIVITY_STATE_CHANGED,
Robert Greenwalt0659da32009-07-16 17:21:39 -07001337 eventLogParam);
1338
1339 if (info.getDetailedState() ==
1340 NetworkInfo.DetailedState.FAILED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001341 handleConnectionFailure(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001342 } else if (state == NetworkInfo.State.DISCONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001343 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001344 } else if (state == NetworkInfo.State.SUSPENDED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001345 // TODO: need to think this over.
Robert Greenwalt0659da32009-07-16 17:21:39 -07001346 // the logic here is, handle SUSPENDED the same as
1347 // DISCONNECTED. The only difference being we are
1348 // broadcasting an intent with NetworkInfo that's
1349 // suspended. This allows the applications an
1350 // opportunity to handle DISCONNECTED and SUSPENDED
1351 // differently, or not.
The Android Open Source Project28527d22009-03-03 19:31:44 -08001352 handleDisconnect(info);
Robert Greenwalt12c44552009-12-07 11:33:18 -08001353 } else if (state == NetworkInfo.State.CONNECTED) {
The Android Open Source Project28527d22009-03-03 19:31:44 -08001354 handleConnect(info);
1355 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001356 break;
1357
1358 case NetworkStateTracker.EVENT_SCAN_RESULTS_AVAILABLE:
1359 info = (NetworkInfo) msg.obj;
1360 handleScanResultsAvailable(info);
1361 break;
Robert Greenwalt0659da32009-07-16 17:21:39 -07001362
The Android Open Source Project28527d22009-03-03 19:31:44 -08001363 case NetworkStateTracker.EVENT_NOTIFICATION_CHANGED:
Robert Greenwalt0659da32009-07-16 17:21:39 -07001364 handleNotificationChange(msg.arg1 == 1, msg.arg2,
1365 (Notification) msg.obj);
The Android Open Source Project28527d22009-03-03 19:31:44 -08001366
1367 case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
Robert Greenwalt2034b912009-08-12 16:08:25 -07001368 handleDnsConfigurationChange();
The Android Open Source Project28527d22009-03-03 19:31:44 -08001369 break;
1370
1371 case NetworkStateTracker.EVENT_ROAMING_CHANGED:
1372 // fill me in
1373 break;
1374
1375 case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED:
1376 // fill me in
1377 break;
Robert Greenwalt2034b912009-08-12 16:08:25 -07001378 case NetworkStateTracker.EVENT_RESTORE_DEFAULT_NETWORK:
Robert Greenwaltaffc3a12009-09-27 17:27:04 -07001379 FeatureUser u = (FeatureUser)msg.obj;
1380 u.expire();
Robert Greenwalt2034b912009-08-12 16:08:25 -07001381 break;
The Android Open Source Project28527d22009-03-03 19:31:44 -08001382 }
1383 }
1384 }
Robert Greenwalt0c4828c2010-01-26 11:40:34 -08001385
1386 // javadoc from interface
1387 public boolean tether(String iface) {
1388 enforceTetherChangePermission();
1389 return mTethering.tether(iface);
1390 }
1391
1392 // javadoc from interface
1393 public boolean untether(String iface) {
1394 enforceTetherChangePermission();
1395 return mTethering.untether(iface);
1396 }
1397
1398 // TODO - move iface listing, queries, etc to new module
1399 // javadoc from interface
1400 public String[] getTetherableIfaces() {
1401 enforceAccessPermission();
1402 return mTethering.getTetherableIfaces();
1403 }
1404
1405 public String[] getTetheredIfaces() {
1406 enforceAccessPermission();
1407 return mTethering.getTetheredIfaces();
1408 }
The Android Open Source Project28527d22009-03-03 19:31:44 -08001409}