blob: a569317e2500295ffceead8f5198d0fae7fa59af [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 android.net;
18
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070019import static com.android.internal.util.Preconditions.checkNotNull;
20
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
Robert Greenwalt42acef32009-08-12 16:08:25 -070023import android.os.Binder;
Jeff Sharkey3a844fc2011-08-16 14:37:57 -070024import android.os.Build.VERSION_CODES;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.RemoteException;
Jeff Sharkey961e3042011-08-29 16:02:57 -070026import android.provider.Settings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070028import java.net.InetAddress;
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070029
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030/**
31 * Class that answers queries about the state of network connectivity. It also
32 * notifies applications when network connectivity changes. Get an instance
33 * of this class by calling
34 * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
35 * <p>
36 * The primary responsibilities of this class are to:
37 * <ol>
38 * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
39 * <li>Send broadcast intents when network connectivity changes</li>
40 * <li>Attempt to "fail over" to another network when connectivity to a network
41 * is lost</li>
42 * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
43 * state of the available networks</li>
44 * </ol>
45 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070046public class ConnectivityManager {
47 private static final String TAG = "ConnectivityManager";
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 /**
50 * A change in network connectivity has occurred. A connection has either
51 * been established or lost. The NetworkInfo for the affected network is
52 * sent as an extra; it should be consulted to see what kind of
53 * connectivity event occurred.
54 * <p/>
55 * If this is a connection that was the result of failing over from a
56 * disconnected network, then the FAILOVER_CONNECTION boolean extra is
57 * set to true.
58 * <p/>
59 * For a loss of connectivity, if the connectivity manager is attempting
60 * to connect (or has already connected) to another network, the
61 * NetworkInfo for the new network is also passed as an extra. This lets
62 * any receivers of the broadcast know that they should not necessarily
63 * tell the user that no data traffic will be possible. Instead, the
64 * reciever should expect another broadcast soon, indicating either that
65 * the failover attempt succeeded (and so there is still overall data
66 * connectivity), or that the failover attempt failed, meaning that all
67 * connectivity has been lost.
68 * <p/>
69 * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
70 * is set to {@code true} if there are no connected networks at all.
71 */
72 public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070073
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 /**
Jeff Sharkey961e3042011-08-29 16:02:57 -070075 * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
76 * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}.
77 *
78 * @hide
79 */
80 public static final String CONNECTIVITY_ACTION_IMMEDIATE =
81 "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
82
83 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 * The lookup key for a {@link NetworkInfo} object. Retrieve with
85 * {@link android.content.Intent#getParcelableExtra(String)}.
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070086 *
87 * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
88 * should always obtain network information through
89 * {@link #getActiveNetworkInfo()} or
90 * {@link #getAllNetworkInfo()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 */
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070092 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 public static final String EXTRA_NETWORK_INFO = "networkInfo";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 /**
96 * The lookup key for a boolean that indicates whether a connect event
97 * is for a network to which the connectivity manager was failing over
98 * following a disconnect on another network.
99 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
100 */
101 public static final String EXTRA_IS_FAILOVER = "isFailover";
102 /**
103 * The lookup key for a {@link NetworkInfo} object. This is supplied when
104 * there is another network that it may be possible to connect to. Retrieve with
105 * {@link android.content.Intent#getParcelableExtra(String)}.
106 */
107 public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
108 /**
109 * The lookup key for a boolean that indicates whether there is a
110 * complete lack of connectivity, i.e., no network is available.
111 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
112 */
113 public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
114 /**
115 * The lookup key for a string that indicates why an attempt to connect
116 * to a network failed. The string has no particular structure. It is
117 * intended to be used in notifications presented to users. Retrieve
118 * it with {@link android.content.Intent#getStringExtra(String)}.
119 */
120 public static final String EXTRA_REASON = "reason";
121 /**
122 * The lookup key for a string that provides optionally supplied
123 * extra information about the network state. The information
124 * may be passed up from the lower networking layers, and its
125 * meaning may be specific to a particular network type. Retrieve
126 * it with {@link android.content.Intent#getStringExtra(String)}.
127 */
128 public static final String EXTRA_EXTRA_INFO = "extraInfo";
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700129 /**
130 * The lookup key for an int that provides information about
131 * our connection to the internet at large. 0 indicates no connection,
132 * 100 indicates a great connection. Retrieve it with
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700133 * {@link android.content.Intent#getIntExtra(String, int)}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700134 * {@hide}
135 */
136 public static final String EXTRA_INET_CONDITION = "inetCondition";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
138 /**
139 * Broadcast Action: The setting for background data usage has changed
140 * values. Use {@link #getBackgroundDataSetting()} to get the current value.
141 * <p>
142 * If an application uses the network in the background, it should listen
143 * for this broadcast and stop using the background data if the value is
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700144 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
146 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
147 public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
148 "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
149
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700150 /**
151 * Broadcast Action: The network connection may not be good
152 * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
153 * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
154 * the network and it's condition.
155 * @hide
156 */
157 public static final String INET_CONDITION_ACTION =
158 "android.net.conn.INET_CONDITION_ACTION";
159
Robert Greenwalt42acef32009-08-12 16:08:25 -0700160 /**
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800161 * Broadcast Action: A tetherable connection has come or gone
162 * TODO - finish the doc
163 * @hide
164 */
165 public static final String ACTION_TETHER_STATE_CHANGED =
166 "android.net.conn.TETHER_STATE_CHANGED";
167
168 /**
169 * @hide
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800170 * gives a String[]
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800171 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800172 public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800173
174 /**
175 * @hide
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800176 * gives a String[]
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800177 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800178 public static final String EXTRA_ACTIVE_TETHER = "activeArray";
179
180 /**
181 * @hide
182 * gives a String[]
183 */
184 public static final String EXTRA_ERRORED_TETHER = "erroredArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800185
186 /**
Robert Greenwaltccf83af12011-06-02 17:30:47 -0700187 * The absence of APN..
188 * @hide
189 */
190 public static final int TYPE_NONE = -1;
191
192 /**
Robert Greenwalt42acef32009-08-12 16:08:25 -0700193 * The Default Mobile data connection. When active, all data traffic
Robert Greenwalt97ab2d42011-05-27 11:29:13 -0700194 * will use this connection by default.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700195 */
196 public static final int TYPE_MOBILE = 0;
197 /**
198 * The Default WIFI data connection. When active, all data traffic
Robert Greenwalt97ab2d42011-05-27 11:29:13 -0700199 * will use this connection by default.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700200 */
201 public static final int TYPE_WIFI = 1;
202 /**
203 * An MMS-specific Mobile data connection. This connection may be the
Robert Greenwalt1bc3c372010-01-13 11:29:03 -0800204 * same as {@link #TYPE_MOBILE} but it may be different. This is used
Robert Greenwalt42acef32009-08-12 16:08:25 -0700205 * by applications needing to talk to the carrier's Multimedia Messaging
206 * Service servers. It may coexist with default data connections.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700207 */
208 public static final int TYPE_MOBILE_MMS = 2;
209 /**
210 * A SUPL-specific Mobile data connection. This connection may be the
Robert Greenwalt1bc3c372010-01-13 11:29:03 -0800211 * same as {@link #TYPE_MOBILE} but it may be different. This is used
Robert Greenwalt42acef32009-08-12 16:08:25 -0700212 * by applications needing to talk to the carrier's Secure User Plane
213 * Location servers for help locating the device. It may coexist with
214 * default data connections.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700215 */
216 public static final int TYPE_MOBILE_SUPL = 3;
217 /**
218 * A DUN-specific Mobile data connection. This connection may be the
Robert Greenwalt1bc3c372010-01-13 11:29:03 -0800219 * same as {@link #TYPE_MOBILE} but it may be different. This is used
Robert Greenwalt42acef32009-08-12 16:08:25 -0700220 * by applicaitons performing a Dial Up Networking bridge so that
221 * the carrier is aware of DUN traffic. It may coexist with default data
222 * connections.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700223 */
224 public static final int TYPE_MOBILE_DUN = 4;
225 /**
226 * A High Priority Mobile data connection. This connection is typically
Robert Greenwalt1bc3c372010-01-13 11:29:03 -0800227 * the same as {@link #TYPE_MOBILE} but the routing setup is different.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700228 * Only requesting processes will have access to the Mobile DNS servers
229 * and only IP's explicitly requested via {@link #requestRouteToHost}
Robert Greenwaltc849cdf2010-01-08 11:47:27 -0800230 * will route over this interface if a default route exists.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700231 */
232 public static final int TYPE_MOBILE_HIPRI = 5;
jsh8214deb2010-03-11 15:04:43 -0800233 /**
234 * The Default WiMAX data connection. When active, all data traffic
Robert Greenwalt97ab2d42011-05-27 11:29:13 -0700235 * will use this connection by default.
jsh8214deb2010-03-11 15:04:43 -0800236 */
237 public static final int TYPE_WIMAX = 6;
Robert Greenwaltda3d5e62010-12-06 13:56:24 -0800238
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800239 /**
Robert Greenwalt97ab2d42011-05-27 11:29:13 -0700240 * The Default Bluetooth data connection. When active, all data traffic
241 * will use this connection by default.
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800242 */
243 public static final int TYPE_BLUETOOTH = 7;
244
Robert Greenwalt60810842011-04-22 15:28:18 -0700245 /**
246 * Dummy data connection. This should not be used on shipping devices.
247 */
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800248 public static final int TYPE_DUMMY = 8;
Wink Saville9d7d6282011-03-12 14:52:01 -0800249
Robert Greenwalt60810842011-04-22 15:28:18 -0700250 /**
Robert Greenwalt97ab2d42011-05-27 11:29:13 -0700251 * The Default Ethernet data connection. When active, all data traffic
252 * will use this connection by default.
Robert Greenwalt60810842011-04-22 15:28:18 -0700253 */
Robert Greenwalte12aec92011-01-28 14:48:37 -0800254 public static final int TYPE_ETHERNET = 9;
Robert Greenwalt60810842011-04-22 15:28:18 -0700255
Wink Saville9d7d6282011-03-12 14:52:01 -0800256 /**
257 * Over the air Adminstration.
258 * {@hide}
259 */
260 public static final int TYPE_MOBILE_FOTA = 10;
261
262 /**
263 * IP Multimedia Subsystem
264 * {@hide}
265 */
266 public static final int TYPE_MOBILE_IMS = 11;
267
268 /**
269 * Carrier Branded Services
270 * {@hide}
271 */
272 public static final int TYPE_MOBILE_CBS = 12;
273
repo syncaea743a2011-07-29 23:55:49 -0700274 /**
275 * A Wi-Fi p2p connection. Only requesting processes will have access to
276 * the peers connected.
277 * {@hide}
278 */
279 public static final int TYPE_WIFI_P2P = 13;
Wink Saville9d7d6282011-03-12 14:52:01 -0800280
281 /** {@hide} */
repo syncaea743a2011-07-29 23:55:49 -0700282 public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P;
283
284 /** {@hide} */
285 public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286
287 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
288
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700289 private final IConnectivityManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700291 public static boolean isNetworkTypeValid(int networkType) {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700292 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 }
294
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700295 /** {@hide} */
296 public static String getNetworkTypeName(int type) {
297 switch (type) {
298 case TYPE_MOBILE:
299 return "MOBILE";
300 case TYPE_WIFI:
301 return "WIFI";
302 case TYPE_MOBILE_MMS:
303 return "MOBILE_MMS";
304 case TYPE_MOBILE_SUPL:
305 return "MOBILE_SUPL";
306 case TYPE_MOBILE_DUN:
307 return "MOBILE_DUN";
308 case TYPE_MOBILE_HIPRI:
309 return "MOBILE_HIPRI";
310 case TYPE_WIMAX:
311 return "WIMAX";
312 case TYPE_BLUETOOTH:
313 return "BLUETOOTH";
314 case TYPE_DUMMY:
315 return "DUMMY";
316 case TYPE_ETHERNET:
317 return "ETHERNET";
318 case TYPE_MOBILE_FOTA:
319 return "MOBILE_FOTA";
320 case TYPE_MOBILE_IMS:
321 return "MOBILE_IMS";
322 case TYPE_MOBILE_CBS:
323 return "MOBILE_CBS";
repo syncaea743a2011-07-29 23:55:49 -0700324 case TYPE_WIFI_P2P:
325 return "WIFI_P2P";
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700326 default:
327 return Integer.toString(type);
328 }
329 }
330
331 /** {@hide} */
332 public static boolean isNetworkTypeMobile(int networkType) {
333 switch (networkType) {
334 case TYPE_MOBILE:
335 case TYPE_MOBILE_MMS:
336 case TYPE_MOBILE_SUPL:
337 case TYPE_MOBILE_DUN:
338 case TYPE_MOBILE_HIPRI:
339 case TYPE_MOBILE_FOTA:
340 case TYPE_MOBILE_IMS:
341 case TYPE_MOBILE_CBS:
342 return true;
343 default:
344 return false;
345 }
346 }
347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 public void setNetworkPreference(int preference) {
349 try {
350 mService.setNetworkPreference(preference);
351 } catch (RemoteException e) {
352 }
353 }
354
355 public int getNetworkPreference() {
356 try {
357 return mService.getNetworkPreference();
358 } catch (RemoteException e) {
359 return -1;
360 }
361 }
362
Scott Main671644c2011-10-06 19:02:28 -0700363 /**
364 * Gets you info about the current data network.
365 * Call {@link NetworkInfo#isConnected()} on the returned {@link NetworkInfo}
366 * to check if the device has a data connection.
367 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 public NetworkInfo getActiveNetworkInfo() {
369 try {
370 return mService.getActiveNetworkInfo();
371 } catch (RemoteException e) {
372 return null;
373 }
374 }
375
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700376 /** {@hide} */
377 public NetworkInfo getActiveNetworkInfoForUid(int uid) {
378 try {
379 return mService.getActiveNetworkInfoForUid(uid);
380 } catch (RemoteException e) {
381 return null;
382 }
383 }
384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 public NetworkInfo getNetworkInfo(int networkType) {
386 try {
387 return mService.getNetworkInfo(networkType);
388 } catch (RemoteException e) {
389 return null;
390 }
391 }
392
393 public NetworkInfo[] getAllNetworkInfo() {
394 try {
395 return mService.getAllNetworkInfo();
396 } catch (RemoteException e) {
397 return null;
398 }
399 }
400
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700401 /** {@hide} */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700402 public LinkProperties getActiveLinkProperties() {
403 try {
404 return mService.getActiveLinkProperties();
405 } catch (RemoteException e) {
406 return null;
407 }
408 }
409
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700410 /** {@hide} */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700411 public LinkProperties getLinkProperties(int networkType) {
412 try {
413 return mService.getLinkProperties(networkType);
414 } catch (RemoteException e) {
415 return null;
416 }
417 }
418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 /** {@hide} */
420 public boolean setRadios(boolean turnOn) {
421 try {
422 return mService.setRadios(turnOn);
423 } catch (RemoteException e) {
424 return false;
425 }
426 }
427
428 /** {@hide} */
429 public boolean setRadio(int networkType, boolean turnOn) {
430 try {
431 return mService.setRadio(networkType, turnOn);
432 } catch (RemoteException e) {
433 return false;
434 }
435 }
436
437 /**
438 * Tells the underlying networking system that the caller wants to
439 * begin using the named feature. The interpretation of {@code feature}
440 * is completely up to each networking implementation.
441 * @param networkType specifies which network the request pertains to
442 * @param feature the name of the feature to be used
443 * @return an integer value representing the outcome of the request.
444 * The interpretation of this value is specific to each networking
445 * implementation+feature combination, except that the value {@code -1}
446 * always indicates failure.
447 */
448 public int startUsingNetworkFeature(int networkType, String feature) {
449 try {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700450 return mService.startUsingNetworkFeature(networkType, feature,
451 new Binder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 } catch (RemoteException e) {
453 return -1;
454 }
455 }
456
457 /**
458 * Tells the underlying networking system that the caller is finished
459 * using the named feature. The interpretation of {@code feature}
460 * is completely up to each networking implementation.
461 * @param networkType specifies which network the request pertains to
462 * @param feature the name of the feature that is no longer needed
463 * @return an integer value representing the outcome of the request.
464 * The interpretation of this value is specific to each networking
465 * implementation+feature combination, except that the value {@code -1}
466 * always indicates failure.
467 */
468 public int stopUsingNetworkFeature(int networkType, String feature) {
469 try {
470 return mService.stopUsingNetworkFeature(networkType, feature);
471 } catch (RemoteException e) {
472 return -1;
473 }
474 }
475
476 /**
477 * Ensure that a network route exists to deliver traffic to the specified
478 * host via the specified network interface. An attempt to add a route that
479 * already exists is ignored, but treated as successful.
480 * @param networkType the type of the network over which traffic to the specified
481 * host is to be routed
482 * @param hostAddress the IP address of the host to which the route is desired
483 * @return {@code true} on success, {@code false} on failure
484 */
485 public boolean requestRouteToHost(int networkType, int hostAddress) {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700486 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
487
488 if (inetAddress == null) {
489 return false;
490 }
491
492 return requestRouteToHostAddress(networkType, inetAddress);
493 }
494
495 /**
496 * Ensure that a network route exists to deliver traffic to the specified
497 * host via the specified network interface. An attempt to add a route that
498 * already exists is ignored, but treated as successful.
499 * @param networkType the type of the network over which traffic to the specified
500 * host is to be routed
501 * @param hostAddress the IP address of the host to which the route is desired
502 * @return {@code true} on success, {@code false} on failure
503 * @hide
504 */
505 public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
506 byte[] address = hostAddress.getAddress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 try {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700508 return mService.requestRouteToHostAddress(networkType, address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 } catch (RemoteException e) {
510 return false;
511 }
512 }
513
514 /**
515 * Returns the value of the setting for background data usage. If false,
516 * applications should not use the network if the application is not in the
517 * foreground. Developers should respect this setting, and check the value
518 * of this before performing any background data operations.
519 * <p>
520 * All applications that have background services that use the network
521 * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700522 * <p>
Scott Main4cc53332011-10-06 18:32:43 -0700523 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700524 * background data depends on several combined factors, and this method will
525 * always return {@code true}. Instead, when background data is unavailable,
526 * {@link #getActiveNetworkInfo()} will now appear disconnected.
Danica Chang6fdd0c62010-08-11 14:54:43 -0700527 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800528 * @return Whether background data usage is allowed.
529 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700530 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 public boolean getBackgroundDataSetting() {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700532 // assume that background data is allowed; final authority is
533 // NetworkInfo which may be blocked.
534 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 }
536
537 /**
538 * Sets the value of the setting for background data usage.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800539 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 * @param allowBackgroundData Whether an application should use data while
541 * it is in the background.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800542 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
544 * @see #getBackgroundDataSetting()
545 * @hide
546 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700547 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 public void setBackgroundDataSetting(boolean allowBackgroundData) {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700549 // ignored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 }
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800551
552 /**
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700553 * Return quota status for the current active network, or {@code null} if no
554 * network is active. Quota status can change rapidly, so these values
555 * shouldn't be cached.
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -0700556 *
557 * @hide
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700558 */
559 public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
560 try {
561 return mService.getActiveNetworkQuotaInfo();
562 } catch (RemoteException e) {
563 return null;
564 }
565 }
566
567 /**
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800568 * Gets the value of the setting for enabling Mobile data.
569 *
570 * @return Whether mobile data is enabled.
571 * @hide
572 */
573 public boolean getMobileDataEnabled() {
574 try {
575 return mService.getMobileDataEnabled();
576 } catch (RemoteException e) {
577 return true;
578 }
579 }
580
581 /**
582 * Sets the persisted value for enabling/disabling Mobile data.
583 *
Robert Greenwalt5a735062010-03-02 17:25:02 -0800584 * @param enabled Whether the mobile data connection should be
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800585 * used or not.
586 * @hide
587 */
588 public void setMobileDataEnabled(boolean enabled) {
589 try {
590 mService.setMobileDataEnabled(enabled);
591 } catch (RemoteException e) {
592 }
593 }
594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 * {@hide}
597 */
598 public ConnectivityManager(IConnectivityManager service) {
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700599 mService = checkNotNull(service, "missing IConnectivityManager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 }
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800601
602 /**
603 * {@hide}
604 */
605 public String[] getTetherableIfaces() {
606 try {
607 return mService.getTetherableIfaces();
608 } catch (RemoteException e) {
609 return new String[0];
610 }
611 }
612
613 /**
614 * {@hide}
615 */
616 public String[] getTetheredIfaces() {
617 try {
618 return mService.getTetheredIfaces();
619 } catch (RemoteException e) {
620 return new String[0];
621 }
622 }
623
624 /**
625 * {@hide}
626 */
Robert Greenwalt5a735062010-03-02 17:25:02 -0800627 public String[] getTetheringErroredIfaces() {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800628 try {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800629 return mService.getTetheringErroredIfaces();
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800630 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800631 return new String[0];
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800632 }
633 }
634
635 /**
Robert Greenwalt5a735062010-03-02 17:25:02 -0800636 * @return error A TETHER_ERROR value indicating success or failure type
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800637 * {@hide}
638 */
Robert Greenwalt5a735062010-03-02 17:25:02 -0800639 public int tether(String iface) {
640 try {
641 return mService.tether(iface);
642 } catch (RemoteException e) {
643 return TETHER_ERROR_SERVICE_UNAVAIL;
644 }
645 }
646
647 /**
648 * @return error A TETHER_ERROR value indicating success or failure type
649 * {@hide}
650 */
651 public int untether(String iface) {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800652 try {
653 return mService.untether(iface);
654 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800655 return TETHER_ERROR_SERVICE_UNAVAIL;
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800656 }
657 }
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800658
659 /**
660 * {@hide}
661 */
662 public boolean isTetheringSupported() {
663 try {
664 return mService.isTetheringSupported();
665 } catch (RemoteException e) {
666 return false;
667 }
668 }
669
670 /**
671 * {@hide}
672 */
673 public String[] getTetherableUsbRegexs() {
674 try {
675 return mService.getTetherableUsbRegexs();
676 } catch (RemoteException e) {
677 return new String[0];
678 }
679 }
680
681 /**
682 * {@hide}
683 */
684 public String[] getTetherableWifiRegexs() {
685 try {
686 return mService.getTetherableWifiRegexs();
687 } catch (RemoteException e) {
688 return new String[0];
689 }
690 }
Robert Greenwalt5a735062010-03-02 17:25:02 -0800691
Danica Chang6fdd0c62010-08-11 14:54:43 -0700692 /**
693 * {@hide}
694 */
695 public String[] getTetherableBluetoothRegexs() {
696 try {
697 return mService.getTetherableBluetoothRegexs();
698 } catch (RemoteException e) {
699 return new String[0];
700 }
701 }
702
Mike Lockwood6c2260b2011-07-19 13:04:47 -0700703 /**
704 * {@hide}
705 */
706 public int setUsbTethering(boolean enable) {
707 try {
708 return mService.setUsbTethering(enable);
709 } catch (RemoteException e) {
710 return TETHER_ERROR_SERVICE_UNAVAIL;
711 }
712 }
713
Robert Greenwalt5a735062010-03-02 17:25:02 -0800714 /** {@hide} */
715 public static final int TETHER_ERROR_NO_ERROR = 0;
716 /** {@hide} */
717 public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
718 /** {@hide} */
719 public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
720 /** {@hide} */
721 public static final int TETHER_ERROR_UNSUPPORTED = 3;
722 /** {@hide} */
723 public static final int TETHER_ERROR_UNAVAIL_IFACE = 4;
724 /** {@hide} */
725 public static final int TETHER_ERROR_MASTER_ERROR = 5;
726 /** {@hide} */
727 public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
728 /** {@hide} */
729 public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
730 /** {@hide} */
731 public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8;
732 /** {@hide} */
733 public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9;
734 /** {@hide} */
735 public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
736
737 /**
738 * @param iface The name of the interface we're interested in
739 * @return error The error code of the last error tethering or untethering the named
740 * interface
741 * {@hide}
742 */
743 public int getLastTetherError(String iface) {
744 try {
745 return mService.getLastTetherError(iface);
746 } catch (RemoteException e) {
747 return TETHER_ERROR_SERVICE_UNAVAIL;
748 }
Robert Greenwalt14f2ef42010-06-15 12:19:37 -0700749 }
750
751 /**
752 * Ensure the device stays awake until we connect with the next network
753 * @param forWhome The name of the network going down for logging purposes
754 * @return {@code true} on success, {@code false} on failure
755 * {@hide}
756 */
757 public boolean requestNetworkTransitionWakelock(String forWhom) {
758 try {
759 mService.requestNetworkTransitionWakelock(forWhom);
760 return true;
761 } catch (RemoteException e) {
762 return false;
763 }
764 }
Robert Greenwaltca4306c2010-09-09 13:15:32 -0700765
Robert Greenwalt67fd6c92010-09-09 14:22:59 -0700766 /**
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700767 * @param networkType The type of network you want to report on
768 * @param percentage The quality of the connection 0 is bad, 100 is good
769 * {@hide}
770 */
771 public void reportInetCondition(int networkType, int percentage) {
772 try {
773 mService.reportInetCondition(networkType, percentage);
774 } catch (RemoteException e) {
775 }
776 }
Robert Greenwalt434203a2010-10-11 16:00:27 -0700777
778 /**
779 * @param proxyProperties The definition for the new global http proxy
780 * {@hide}
781 */
782 public void setGlobalProxy(ProxyProperties p) {
783 try {
784 mService.setGlobalProxy(p);
785 } catch (RemoteException e) {
786 }
787 }
788
789 /**
790 * @return proxyProperties for the current global proxy
791 * {@hide}
792 */
793 public ProxyProperties getGlobalProxy() {
794 try {
795 return mService.getGlobalProxy();
796 } catch (RemoteException e) {
797 return null;
798 }
799 }
800
801 /**
802 * @return proxyProperties for the current proxy (global if set, network specific if not)
803 * {@hide}
804 */
805 public ProxyProperties getProxy() {
806 try {
807 return mService.getProxy();
808 } catch (RemoteException e) {
809 return null;
810 }
811 }
Robert Greenwaltd55a6b42011-03-25 13:09:25 -0700812
813 /**
814 * @param networkType The network who's dependence has changed
815 * @param met Boolean - true if network use is ok, false if not
816 * {@hide}
817 */
818 public void setDataDependency(int networkType, boolean met) {
819 try {
820 mService.setDataDependency(networkType, met);
821 } catch (RemoteException e) {
822 }
823 }
Robert Greenwalt9b2886e2011-08-31 11:46:42 -0700824
825 /**
826 * Returns true if the hardware supports the given network type
827 * else it returns false. This doesn't indicate we have coverage
828 * or are authorized onto a network, just whether or not the
829 * hardware supports it. For example a gsm phone without a sim
830 * should still return true for mobile data, but a wifi only tablet
831 * would return false.
832 * @param networkType The nework type we'd like to check
833 * @return true if supported, else false
834 * @hide
835 */
836 public boolean isNetworkSupported(int networkType) {
837 try {
838 return mService.isNetworkSupported(networkType);
839 } catch (RemoteException e) {}
840 return false;
841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842}