blob: 3a04c271cab4d6a813f15cc0a6edeebcd4ecfb55 [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;
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070023import android.content.Context;
Robert Greenwalt42acef32009-08-12 16:08:25 -070024import android.os.Binder;
Jeff Sharkey3a844fc2011-08-16 14:37:57 -070025import android.os.Build.VERSION_CODES;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.RemoteException;
Jeff Sharkey961e3042011-08-29 16:02:57 -070027import android.provider.Settings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070029import java.net.InetAddress;
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031/**
32 * Class that answers queries about the state of network connectivity. It also
33 * notifies applications when network connectivity changes. Get an instance
34 * of this class by calling
35 * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
36 * <p>
37 * The primary responsibilities of this class are to:
38 * <ol>
39 * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
40 * <li>Send broadcast intents when network connectivity changes</li>
41 * <li>Attempt to "fail over" to another network when connectivity to a network
42 * is lost</li>
43 * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
44 * state of the available networks</li>
45 * </ol>
46 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070047public class ConnectivityManager {
48 private static final String TAG = "ConnectivityManager";
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 /**
51 * A change in network connectivity has occurred. A connection has either
52 * been established or lost. The NetworkInfo for the affected network is
53 * sent as an extra; it should be consulted to see what kind of
54 * connectivity event occurred.
55 * <p/>
56 * If this is a connection that was the result of failing over from a
57 * disconnected network, then the FAILOVER_CONNECTION boolean extra is
58 * set to true.
59 * <p/>
60 * For a loss of connectivity, if the connectivity manager is attempting
61 * to connect (or has already connected) to another network, the
62 * NetworkInfo for the new network is also passed as an extra. This lets
63 * any receivers of the broadcast know that they should not necessarily
64 * tell the user that no data traffic will be possible. Instead, the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -080065 * receiver should expect another broadcast soon, indicating either that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 * the failover attempt succeeded (and so there is still overall data
67 * connectivity), or that the failover attempt failed, meaning that all
68 * connectivity has been lost.
69 * <p/>
70 * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
71 * is set to {@code true} if there are no connected networks at all.
72 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -080073 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 /**
Jeff Sharkey961e3042011-08-29 16:02:57 -070077 * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
78 * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}.
79 *
80 * @hide
81 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -080082 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey961e3042011-08-29 16:02:57 -070083 public static final String CONNECTIVITY_ACTION_IMMEDIATE =
84 "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
85
86 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 * The lookup key for a {@link NetworkInfo} object. Retrieve with
88 * {@link android.content.Intent#getParcelableExtra(String)}.
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070089 *
90 * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
91 * should always obtain network information through
92 * {@link #getActiveNetworkInfo()} or
93 * {@link #getAllNetworkInfo()}.
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -070094 * @see #EXTRA_NETWORK_TYPE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 */
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070096 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 public static final String EXTRA_NETWORK_INFO = "networkInfo";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -0700100 * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast.
101 * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo}
102 * state based on the calling application.
103 *
104 * @see android.content.Intent#getIntExtra(String, int)
105 */
106 public static final String EXTRA_NETWORK_TYPE = "networkType";
107
108 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 * The lookup key for a boolean that indicates whether a connect event
110 * is for a network to which the connectivity manager was failing over
111 * following a disconnect on another network.
112 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
113 */
114 public static final String EXTRA_IS_FAILOVER = "isFailover";
115 /**
116 * The lookup key for a {@link NetworkInfo} object. This is supplied when
117 * there is another network that it may be possible to connect to. Retrieve with
118 * {@link android.content.Intent#getParcelableExtra(String)}.
119 */
120 public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
121 /**
122 * The lookup key for a boolean that indicates whether there is a
123 * complete lack of connectivity, i.e., no network is available.
124 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
125 */
126 public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
127 /**
128 * The lookup key for a string that indicates why an attempt to connect
129 * to a network failed. The string has no particular structure. It is
130 * intended to be used in notifications presented to users. Retrieve
131 * it with {@link android.content.Intent#getStringExtra(String)}.
132 */
133 public static final String EXTRA_REASON = "reason";
134 /**
135 * The lookup key for a string that provides optionally supplied
136 * extra information about the network state. The information
137 * may be passed up from the lower networking layers, and its
138 * meaning may be specific to a particular network type. Retrieve
139 * it with {@link android.content.Intent#getStringExtra(String)}.
140 */
141 public static final String EXTRA_EXTRA_INFO = "extraInfo";
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700142 /**
143 * The lookup key for an int that provides information about
144 * our connection to the internet at large. 0 indicates no connection,
145 * 100 indicates a great connection. Retrieve it with
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700146 * {@link android.content.Intent#getIntExtra(String, int)}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700147 * {@hide}
148 */
149 public static final String EXTRA_INET_CONDITION = "inetCondition";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150
151 /**
Haoyu Baidb3c8672012-06-20 14:29:57 -0700152 * Broadcast action to indicate the change of data activity status
153 * (idle or active) on a network in a recent period.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800154 * The network becomes active when data transmission is started, or
155 * idle if there is no data transmission for a period of time.
Haoyu Baidb3c8672012-06-20 14:29:57 -0700156 * {@hide}
157 */
158 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
159 public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
160 /**
161 * The lookup key for an enum that indicates the network device type on which this data activity
162 * change happens.
163 * {@hide}
164 */
165 public static final String EXTRA_DEVICE_TYPE = "deviceType";
166 /**
167 * The lookup key for a boolean that indicates the device is active or not. {@code true} means
168 * it is actively sending or receiving data and {@code false} means it is idle.
169 * {@hide}
170 */
171 public static final String EXTRA_IS_ACTIVE = "isActive";
172
173 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 * Broadcast Action: The setting for background data usage has changed
175 * values. Use {@link #getBackgroundDataSetting()} to get the current value.
176 * <p>
177 * If an application uses the network in the background, it should listen
178 * for this broadcast and stop using the background data if the value is
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700179 * {@code false}.
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800180 * <p>
181 *
182 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability
183 * of background data depends on several combined factors, and
184 * this broadcast is no longer sent. Instead, when background
185 * data is unavailable, {@link #getActiveNetworkInfo()} will now
186 * appear disconnected. During first boot after a platform
187 * upgrade, this broadcast will be sent once if
188 * {@link #getBackgroundDataSetting()} was {@code false} before
189 * the upgrade.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 */
191 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800192 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
194 "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
195
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700196 /**
197 * Broadcast Action: The network connection may not be good
198 * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
199 * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
200 * the network and it's condition.
201 * @hide
202 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800203 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700204 public static final String INET_CONDITION_ACTION =
205 "android.net.conn.INET_CONDITION_ACTION";
206
Robert Greenwalt42acef32009-08-12 16:08:25 -0700207 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800208 * Broadcast Action: A tetherable connection has come or gone.
209 * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER},
210 * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and
211 * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate
212 * the current state of tethering. Each include a list of
213 * interface names in that state (may be empty).
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800214 * @hide
215 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800216 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800217 public static final String ACTION_TETHER_STATE_CHANGED =
218 "android.net.conn.TETHER_STATE_CHANGED";
219
220 /**
221 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800222 * gives a String[] listing all the interfaces configured for
223 * tethering and currently available for tethering.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800224 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800225 public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800226
227 /**
228 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800229 * gives a String[] listing all the interfaces currently tethered
230 * (ie, has dhcp support and packets potentially forwarded/NATed)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800231 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800232 public static final String EXTRA_ACTIVE_TETHER = "activeArray";
233
234 /**
235 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800236 * gives a String[] listing all the interfaces we tried to tether and
237 * failed. Use {@link #getLastTetherError} to find the error code
238 * for any interfaces listed here.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800239 */
240 public static final String EXTRA_ERRORED_TETHER = "erroredArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800241
242 /**
Russell Brenner108da0c2013-02-12 10:03:14 -0800243 * Broadcast Action: The captive portal tracker has finished its test.
244 * Sent only while running Setup Wizard, in lieu of showing a user
245 * notification.
246 * @hide
247 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800248 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Russell Brenner108da0c2013-02-12 10:03:14 -0800249 public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED =
250 "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED";
251 /**
252 * The lookup key for a boolean that indicates whether a captive portal was detected.
253 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
254 * @hide
255 */
256 public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal";
257
258 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800259 * The absence of a connection type.
Robert Greenwaltccf83af12011-06-02 17:30:47 -0700260 * @hide
261 */
262 public static final int TYPE_NONE = -1;
263
264 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800265 * The Mobile data connection. When active, all data traffic
266 * will use this network type's interface by default
267 * (it has a default route)
Robert Greenwalt42acef32009-08-12 16:08:25 -0700268 */
269 public static final int TYPE_MOBILE = 0;
270 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800271 * The WIFI data connection. When active, all data traffic
272 * will use this network type's interface by default
273 * (it has a default route).
Robert Greenwalt42acef32009-08-12 16:08:25 -0700274 */
275 public static final int TYPE_WIFI = 1;
276 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800277 * An MMS-specific Mobile data connection. This network type may use the
278 * same network interface as {@link #TYPE_MOBILE} or it may use a different
279 * one. This is used by applications needing to talk to the carrier's
280 * Multimedia Messaging Service servers.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700281 */
282 public static final int TYPE_MOBILE_MMS = 2;
283 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800284 * A SUPL-specific Mobile data connection. This network type may use the
285 * same network interface as {@link #TYPE_MOBILE} or it may use a different
286 * one. This is used by applications needing to talk to the carrier's
287 * Secure User Plane Location servers for help locating the device.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700288 */
289 public static final int TYPE_MOBILE_SUPL = 3;
290 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800291 * A DUN-specific Mobile data connection. This network type may use the
292 * same network interface as {@link #TYPE_MOBILE} or it may use a different
293 * one. This is sometimes by the system when setting up an upstream connection
294 * for tethering so that the carrier is aware of DUN traffic.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700295 */
296 public static final int TYPE_MOBILE_DUN = 4;
297 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800298 * A High Priority Mobile data connection. This network type uses the
299 * same network interface as {@link #TYPE_MOBILE} but the routing setup
300 * is different. Only requesting processes will have access to the
301 * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost}
302 * will route over this interface if no default route exists.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700303 */
304 public static final int TYPE_MOBILE_HIPRI = 5;
jsh8214deb2010-03-11 15:04:43 -0800305 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800306 * The WiMAX data connection. When active, all data traffic
307 * will use this network type's interface by default
308 * (it has a default route).
jsh8214deb2010-03-11 15:04:43 -0800309 */
310 public static final int TYPE_WIMAX = 6;
Robert Greenwaltda3d5e62010-12-06 13:56:24 -0800311
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800312 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800313 * The Bluetooth data connection. When active, all data traffic
314 * will use this network type's interface by default
315 * (it has a default route).
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800316 */
317 public static final int TYPE_BLUETOOTH = 7;
318
Robert Greenwalt60810842011-04-22 15:28:18 -0700319 /**
320 * Dummy data connection. This should not be used on shipping devices.
321 */
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800322 public static final int TYPE_DUMMY = 8;
Wink Saville9d7d6282011-03-12 14:52:01 -0800323
Robert Greenwalt60810842011-04-22 15:28:18 -0700324 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800325 * The Ethernet data connection. When active, all data traffic
326 * will use this network type's interface by default
327 * (it has a default route).
Robert Greenwalt60810842011-04-22 15:28:18 -0700328 */
Robert Greenwalte12aec92011-01-28 14:48:37 -0800329 public static final int TYPE_ETHERNET = 9;
Robert Greenwalt60810842011-04-22 15:28:18 -0700330
Wink Saville9d7d6282011-03-12 14:52:01 -0800331 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800332 * Over the air Administration.
Wink Saville9d7d6282011-03-12 14:52:01 -0800333 * {@hide}
334 */
335 public static final int TYPE_MOBILE_FOTA = 10;
336
337 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800338 * IP Multimedia Subsystem.
Wink Saville9d7d6282011-03-12 14:52:01 -0800339 * {@hide}
340 */
341 public static final int TYPE_MOBILE_IMS = 11;
342
343 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800344 * Carrier Branded Services.
Wink Saville9d7d6282011-03-12 14:52:01 -0800345 * {@hide}
346 */
347 public static final int TYPE_MOBILE_CBS = 12;
348
repo syncaea743a2011-07-29 23:55:49 -0700349 /**
350 * A Wi-Fi p2p connection. Only requesting processes will have access to
351 * the peers connected.
352 * {@hide}
353 */
354 public static final int TYPE_WIFI_P2P = 13;
Wink Saville9d7d6282011-03-12 14:52:01 -0800355
356 /** {@hide} */
repo syncaea743a2011-07-29 23:55:49 -0700357 public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P;
358
359 /** {@hide} */
360 public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800362 /**
363 * If you want to set the default network preference,you can directly
364 * change the networkAttributes array in framework's config.xml.
365 *
366 * @deprecated Since we support so many more networks now, the single
367 * network default network preference can't really express
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800368 * the hierarchy. Instead, the default is defined by the
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800369 * networkAttributes in config.xml. You can determine
Robert Greenwalt4c8b7482012-12-07 09:56:50 -0800370 * the current value by calling {@link #getNetworkPreference()}
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800371 * from an App.
372 */
373 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
375
Jeff Sharkey625239a2012-09-26 22:03:49 -0700376 /**
377 * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800378 * milliseconds. This was introduced because IPv6 routes seem to take a
379 * moment to settle - trying network activity before the routes are adjusted
380 * can lead to packets using the wrong interface or having the wrong IP address.
381 * This delay is a bit crude, but in the future hopefully we will have kernel
382 * notifications letting us know when it's safe to use the new network.
Jeff Sharkey625239a2012-09-26 22:03:49 -0700383 *
384 * @hide
385 */
386 public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
387
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700388 private final IConnectivityManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800390 /**
391 * Tests if a given integer represents a valid network type.
392 * @param networkType the type to be tested
393 * @return a boolean. {@code true} if the type is valid, else {@code false}
394 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700395 public static boolean isNetworkTypeValid(int networkType) {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700396 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 }
398
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800399 /**
400 * Returns a non-localized string representing a given network type.
401 * ONLY used for debugging output.
402 * @param type the type needing naming
403 * @return a String for the given type, or a string version of the type ("87")
404 * if no name is known.
405 * {@hide}
406 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700407 public static String getNetworkTypeName(int type) {
408 switch (type) {
409 case TYPE_MOBILE:
410 return "MOBILE";
411 case TYPE_WIFI:
412 return "WIFI";
413 case TYPE_MOBILE_MMS:
414 return "MOBILE_MMS";
415 case TYPE_MOBILE_SUPL:
416 return "MOBILE_SUPL";
417 case TYPE_MOBILE_DUN:
418 return "MOBILE_DUN";
419 case TYPE_MOBILE_HIPRI:
420 return "MOBILE_HIPRI";
421 case TYPE_WIMAX:
422 return "WIMAX";
423 case TYPE_BLUETOOTH:
424 return "BLUETOOTH";
425 case TYPE_DUMMY:
426 return "DUMMY";
427 case TYPE_ETHERNET:
428 return "ETHERNET";
429 case TYPE_MOBILE_FOTA:
430 return "MOBILE_FOTA";
431 case TYPE_MOBILE_IMS:
432 return "MOBILE_IMS";
433 case TYPE_MOBILE_CBS:
434 return "MOBILE_CBS";
repo syncaea743a2011-07-29 23:55:49 -0700435 case TYPE_WIFI_P2P:
436 return "WIFI_P2P";
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700437 default:
438 return Integer.toString(type);
439 }
440 }
441
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800442 /**
443 * Checks if a given type uses the cellular data connection.
444 * This should be replaced in the future by a network property.
445 * @param networkType the type to check
446 * @return a boolean - {@code true} if uses cellular network, else {@code false}
447 * {@hide}
448 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700449 public static boolean isNetworkTypeMobile(int networkType) {
450 switch (networkType) {
451 case TYPE_MOBILE:
452 case TYPE_MOBILE_MMS:
453 case TYPE_MOBILE_SUPL:
454 case TYPE_MOBILE_DUN:
455 case TYPE_MOBILE_HIPRI:
456 case TYPE_MOBILE_FOTA:
457 case TYPE_MOBILE_IMS:
458 case TYPE_MOBILE_CBS:
459 return true;
460 default:
461 return false;
462 }
463 }
464
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800465 /**
466 * Specifies the preferred network type. When the device has more
467 * than one type available the preferred network type will be used.
468 * Note that this made sense when we only had 2 network types,
469 * but with more and more default networks we need an array to list
470 * their ordering. This will be deprecated soon.
471 *
472 * @param preference the network type to prefer over all others. It is
473 * unspecified what happens to the old preferred network in the
474 * overall ordering.
475 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 public void setNetworkPreference(int preference) {
477 try {
478 mService.setNetworkPreference(preference);
479 } catch (RemoteException e) {
480 }
481 }
482
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800483 /**
484 * Retrieves the current preferred network type.
485 * Note that this made sense when we only had 2 network types,
486 * but with more and more default networks we need an array to list
487 * their ordering. This will be deprecated soon.
488 *
489 * @return an integer representing the preferred network type
490 *
491 * <p>This method requires the caller to hold the permission
492 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
493 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 public int getNetworkPreference() {
495 try {
496 return mService.getNetworkPreference();
497 } catch (RemoteException e) {
498 return -1;
499 }
500 }
501
Scott Main671644c2011-10-06 19:02:28 -0700502 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800503 * Returns details about the currently active default data network. When
504 * connected, this network is the default route for outgoing connections.
505 * You should always check {@link NetworkInfo#isConnected()} before initiating
506 * network traffic. This may return {@code null} when there is no default
507 * network.
508 *
509 * @return a {@link NetworkInfo} object for the current default network
510 * or {@code null} if no network default network is currently active
511 *
512 * <p>This method requires the call to hold the permission
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700513 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -0700514 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 public NetworkInfo getActiveNetworkInfo() {
516 try {
517 return mService.getActiveNetworkInfo();
518 } catch (RemoteException e) {
519 return null;
520 }
521 }
522
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800523 /**
524 * Returns details about the currently active default data network
525 * for a given uid. This is for internal use only to avoid spying
526 * other apps.
527 *
528 * @return a {@link NetworkInfo} object for the current default network
529 * for the given uid or {@code null} if no default network is
530 * available for the specified uid.
531 *
532 * <p>This method requires the caller to hold the permission
533 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
534 * {@hide}
535 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700536 public NetworkInfo getActiveNetworkInfoForUid(int uid) {
537 try {
538 return mService.getActiveNetworkInfoForUid(uid);
539 } catch (RemoteException e) {
540 return null;
541 }
542 }
543
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800544 /**
545 * Returns connection status information about a particular
546 * network type.
547 *
548 * @param networkType integer specifying which networkType in
549 * which you're interested.
550 * @return a {@link NetworkInfo} object for the requested
551 * network type or {@code null} if the type is not
552 * supported by the device.
553 *
554 * <p>This method requires the call to hold the permission
555 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
556 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 public NetworkInfo getNetworkInfo(int networkType) {
558 try {
559 return mService.getNetworkInfo(networkType);
560 } catch (RemoteException e) {
561 return null;
562 }
563 }
564
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800565 /**
566 * Returns connection status information about all network
567 * types supported by the device.
568 *
569 * @return an array of {@link NetworkInfo} objects. Check each
570 * {@link NetworkInfo#getType} for which type each applies.
571 *
572 * <p>This method requires the call to hold the permission
573 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
574 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 public NetworkInfo[] getAllNetworkInfo() {
576 try {
577 return mService.getAllNetworkInfo();
578 } catch (RemoteException e) {
579 return null;
580 }
581 }
582
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800583 /**
584 * Returns the IP information for the current default network.
585 *
586 * @return a {@link LinkProperties} object describing the IP info
587 * for the current default network, or {@code null} if there
588 * is no current default network.
589 *
590 * <p>This method requires the call to hold the permission
591 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
592 * {@hide}
593 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700594 public LinkProperties getActiveLinkProperties() {
595 try {
596 return mService.getActiveLinkProperties();
597 } catch (RemoteException e) {
598 return null;
599 }
600 }
601
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800602 /**
603 * Returns the IP information for a given network type.
604 *
605 * @param networkType the network type of interest.
606 * @return a {@link LinkProperties} object describing the IP info
607 * for the given networkType, or {@code null} if there is
608 * no current default network.
609 *
610 * <p>This method requires the call to hold the permission
611 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
612 * {@hide}
613 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700614 public LinkProperties getLinkProperties(int networkType) {
615 try {
616 return mService.getLinkProperties(networkType);
617 } catch (RemoteException e) {
618 return null;
619 }
620 }
621
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800622 /**
623 * Tells each network type to set its radio power state as directed.
624 *
625 * @param turnOn a boolean, {@code true} to turn the radios on,
626 * {@code false} to turn them off.
627 * @return a boolean, {@code true} indicating success. All network types
628 * will be tried, even if some fail.
629 *
630 * <p>This method requires the call to hold the permission
631 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
632 * {@hide}
633 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 public boolean setRadios(boolean turnOn) {
635 try {
636 return mService.setRadios(turnOn);
637 } catch (RemoteException e) {
638 return false;
639 }
640 }
641
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800642 /**
643 * Tells a given networkType to set its radio power state as directed.
644 *
645 * @param networkType the int networkType of interest.
646 * @param turnOn a boolean, {@code true} to turn the radio on,
647 * {@code} false to turn it off.
648 * @return a boolean, {@code true} indicating success.
649 *
650 * <p>This method requires the call to hold the permission
651 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
652 * {@hide}
653 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654 public boolean setRadio(int networkType, boolean turnOn) {
655 try {
656 return mService.setRadio(networkType, turnOn);
657 } catch (RemoteException e) {
658 return false;
659 }
660 }
661
662 /**
663 * Tells the underlying networking system that the caller wants to
664 * begin using the named feature. The interpretation of {@code feature}
665 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700666 * <p>This method requires the caller to hold the permission
667 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 * @param networkType specifies which network the request pertains to
669 * @param feature the name of the feature to be used
670 * @return an integer value representing the outcome of the request.
671 * The interpretation of this value is specific to each networking
672 * implementation+feature combination, except that the value {@code -1}
673 * always indicates failure.
674 */
675 public int startUsingNetworkFeature(int networkType, String feature) {
676 try {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700677 return mService.startUsingNetworkFeature(networkType, feature,
678 new Binder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 } catch (RemoteException e) {
680 return -1;
681 }
682 }
683
684 /**
685 * Tells the underlying networking system that the caller is finished
686 * using the named feature. The interpretation of {@code feature}
687 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700688 * <p>This method requires the caller to hold the permission
689 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 * @param networkType specifies which network the request pertains to
691 * @param feature the name of the feature that is no longer needed
692 * @return an integer value representing the outcome of the request.
693 * The interpretation of this value is specific to each networking
694 * implementation+feature combination, except that the value {@code -1}
695 * always indicates failure.
696 */
697 public int stopUsingNetworkFeature(int networkType, String feature) {
698 try {
699 return mService.stopUsingNetworkFeature(networkType, feature);
700 } catch (RemoteException e) {
701 return -1;
702 }
703 }
704
705 /**
706 * Ensure that a network route exists to deliver traffic to the specified
707 * host via the specified network interface. An attempt to add a route that
708 * already exists is ignored, but treated as successful.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700709 * <p>This method requires the caller to hold the permission
710 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 * @param networkType the type of the network over which traffic to the specified
712 * host is to be routed
713 * @param hostAddress the IP address of the host to which the route is desired
714 * @return {@code true} on success, {@code false} on failure
715 */
716 public boolean requestRouteToHost(int networkType, int hostAddress) {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700717 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
718
719 if (inetAddress == null) {
720 return false;
721 }
722
723 return requestRouteToHostAddress(networkType, inetAddress);
724 }
725
726 /**
727 * Ensure that a network route exists to deliver traffic to the specified
728 * host via the specified network interface. An attempt to add a route that
729 * already exists is ignored, but treated as successful.
730 * @param networkType the type of the network over which traffic to the specified
731 * host is to be routed
732 * @param hostAddress the IP address of the host to which the route is desired
733 * @return {@code true} on success, {@code false} on failure
734 * @hide
735 */
736 public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
737 byte[] address = hostAddress.getAddress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 try {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700739 return mService.requestRouteToHostAddress(networkType, address);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 } catch (RemoteException e) {
741 return false;
742 }
743 }
744
745 /**
746 * Returns the value of the setting for background data usage. If false,
747 * applications should not use the network if the application is not in the
748 * foreground. Developers should respect this setting, and check the value
749 * of this before performing any background data operations.
750 * <p>
751 * All applications that have background services that use the network
752 * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700753 * <p>
Scott Main4cc53332011-10-06 18:32:43 -0700754 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700755 * background data depends on several combined factors, and this method will
756 * always return {@code true}. Instead, when background data is unavailable,
757 * {@link #getActiveNetworkInfo()} will now appear disconnected.
Danica Chang6fdd0c62010-08-11 14:54:43 -0700758 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * @return Whether background data usage is allowed.
760 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700761 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 public boolean getBackgroundDataSetting() {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700763 // assume that background data is allowed; final authority is
764 // NetworkInfo which may be blocked.
765 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 }
767
768 /**
769 * Sets the value of the setting for background data usage.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800770 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 * @param allowBackgroundData Whether an application should use data while
772 * it is in the background.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800773 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
775 * @see #getBackgroundDataSetting()
776 * @hide
777 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700778 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 public void setBackgroundDataSetting(boolean allowBackgroundData) {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700780 // ignored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 }
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800782
783 /**
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700784 * Return quota status for the current active network, or {@code null} if no
785 * network is active. Quota status can change rapidly, so these values
786 * shouldn't be cached.
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -0700787 *
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800788 * <p>This method requires the call to hold the permission
789 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
790 *
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -0700791 * @hide
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700792 */
793 public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
794 try {
795 return mService.getActiveNetworkQuotaInfo();
796 } catch (RemoteException e) {
797 return null;
798 }
799 }
800
801 /**
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800802 * Gets the value of the setting for enabling Mobile data.
803 *
804 * @return Whether mobile data is enabled.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800805 *
806 * <p>This method requires the call to hold the permission
807 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800808 * @hide
809 */
810 public boolean getMobileDataEnabled() {
811 try {
812 return mService.getMobileDataEnabled();
813 } catch (RemoteException e) {
814 return true;
815 }
816 }
817
818 /**
819 * Sets the persisted value for enabling/disabling Mobile data.
820 *
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800821 * @param enabled Whether the user wants the mobile data connection used
822 * or not.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800823 * @hide
824 */
825 public void setMobileDataEnabled(boolean enabled) {
826 try {
827 mService.setMobileDataEnabled(enabled);
828 } catch (RemoteException e) {
829 }
830 }
831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 * {@hide}
834 */
835 public ConnectivityManager(IConnectivityManager service) {
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700836 mService = checkNotNull(service, "missing IConnectivityManager");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 }
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800838
Jeff Sharkey8fc27e82012-04-04 20:40:58 -0700839 /** {@hide} */
840 public static ConnectivityManager from(Context context) {
841 return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
842 }
843
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800844 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800845 * Get the set of tetherable, available interfaces. This list is limited by
846 * device configuration and current interface existence.
847 *
848 * @return an array of 0 or more Strings of tetherable interface names.
849 *
850 * <p>This method requires the call to hold the permission
851 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800852 * {@hide}
853 */
854 public String[] getTetherableIfaces() {
855 try {
856 return mService.getTetherableIfaces();
857 } catch (RemoteException e) {
858 return new String[0];
859 }
860 }
861
862 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800863 * Get the set of tethered interfaces.
864 *
865 * @return an array of 0 or more String of currently tethered interface names.
866 *
867 * <p>This method requires the call to hold the permission
868 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800869 * {@hide}
870 */
871 public String[] getTetheredIfaces() {
872 try {
873 return mService.getTetheredIfaces();
874 } catch (RemoteException e) {
875 return new String[0];
876 }
877 }
878
879 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800880 * Get the set of interface names which attempted to tether but
881 * failed. Re-attempting to tether may cause them to reset to the Tethered
882 * state. Alternatively, causing the interface to be destroyed and recreated
883 * may cause them to reset to the available state.
884 * {@link ConnectivityManager#getLastTetherError} can be used to get more
885 * information on the cause of the errors.
886 *
887 * @return an array of 0 or more String indicating the interface names
888 * which failed to tether.
889 *
890 * <p>This method requires the call to hold the permission
891 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800892 * {@hide}
893 */
Robert Greenwalt5a735062010-03-02 17:25:02 -0800894 public String[] getTetheringErroredIfaces() {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800895 try {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800896 return mService.getTetheringErroredIfaces();
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800897 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800898 return new String[0];
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800899 }
900 }
901
902 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800903 * Attempt to tether the named interface. This will setup a dhcp server
904 * on the interface, forward and NAT IP packets and forward DNS requests
905 * to the best active upstream network interface. Note that if no upstream
906 * IP network interface is available, dhcp will still run and traffic will be
907 * allowed between the tethered devices and this device, though upstream net
908 * access will of course fail until an upstream network interface becomes
909 * active.
910 *
911 * @param iface the interface name to tether.
912 * @return error a {@code TETHER_ERROR} value indicating success or failure type
913 *
914 * <p>This method requires the call to hold the permission
915 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800916 * {@hide}
917 */
Robert Greenwalt5a735062010-03-02 17:25:02 -0800918 public int tether(String iface) {
919 try {
920 return mService.tether(iface);
921 } catch (RemoteException e) {
922 return TETHER_ERROR_SERVICE_UNAVAIL;
923 }
924 }
925
926 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800927 * Stop tethering the named interface.
928 *
929 * @param iface the interface name to untether.
930 * @return error a {@code TETHER_ERROR} value indicating success or failure type
931 *
932 * <p>This method requires the call to hold the permission
933 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -0800934 * {@hide}
935 */
936 public int untether(String iface) {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800937 try {
938 return mService.untether(iface);
939 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -0800940 return TETHER_ERROR_SERVICE_UNAVAIL;
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800941 }
942 }
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800943
944 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800945 * Check if the device allows for tethering. It may be disabled via
946 * {@code ro.tether.denied} system property, {@link Settings#TETHER_SUPPORTED} or
947 * due to device configuration.
948 *
949 * @return a boolean - {@code true} indicating Tethering is supported.
950 *
951 * <p>This method requires the call to hold the permission
952 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800953 * {@hide}
954 */
955 public boolean isTetheringSupported() {
956 try {
957 return mService.isTetheringSupported();
958 } catch (RemoteException e) {
959 return false;
960 }
961 }
962
963 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800964 * Get the list of regular expressions that define any tetherable
965 * USB network interfaces. If USB tethering is not supported by the
966 * device, this list should be empty.
967 *
968 * @return an array of 0 or more regular expression Strings defining
969 * what interfaces are considered tetherable usb interfaces.
970 *
971 * <p>This method requires the call to hold the permission
972 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800973 * {@hide}
974 */
975 public String[] getTetherableUsbRegexs() {
976 try {
977 return mService.getTetherableUsbRegexs();
978 } catch (RemoteException e) {
979 return new String[0];
980 }
981 }
982
983 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800984 * Get the list of regular expressions that define any tetherable
985 * Wifi network interfaces. If Wifi tethering is not supported by the
986 * device, this list should be empty.
987 *
988 * @return an array of 0 or more regular expression Strings defining
989 * what interfaces are considered tetherable wifi interfaces.
990 *
991 * <p>This method requires the call to hold the permission
992 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800993 * {@hide}
994 */
995 public String[] getTetherableWifiRegexs() {
996 try {
997 return mService.getTetherableWifiRegexs();
998 } catch (RemoteException e) {
999 return new String[0];
1000 }
1001 }
Robert Greenwalt5a735062010-03-02 17:25:02 -08001002
Danica Chang6fdd0c62010-08-11 14:54:43 -07001003 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001004 * Get the list of regular expressions that define any tetherable
1005 * Bluetooth network interfaces. If Bluetooth tethering is not supported by the
1006 * device, this list should be empty.
1007 *
1008 * @return an array of 0 or more regular expression Strings defining
1009 * what interfaces are considered tetherable bluetooth interfaces.
1010 *
1011 * <p>This method requires the call to hold the permission
1012 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Danica Chang6fdd0c62010-08-11 14:54:43 -07001013 * {@hide}
1014 */
1015 public String[] getTetherableBluetoothRegexs() {
1016 try {
1017 return mService.getTetherableBluetoothRegexs();
1018 } catch (RemoteException e) {
1019 return new String[0];
1020 }
1021 }
1022
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001023 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001024 * Attempt to both alter the mode of USB and Tethering of USB. A
1025 * utility method to deal with some of the complexity of USB - will
1026 * attempt to switch to Rndis and subsequently tether the resulting
1027 * interface on {@code true} or turn off tethering and switch off
1028 * Rndis on {@code false}.
1029 *
1030 * @param enable a boolean - {@code true} to enable tethering
1031 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1032 *
1033 * <p>This method requires the call to hold the permission
1034 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001035 * {@hide}
1036 */
1037 public int setUsbTethering(boolean enable) {
1038 try {
1039 return mService.setUsbTethering(enable);
1040 } catch (RemoteException e) {
1041 return TETHER_ERROR_SERVICE_UNAVAIL;
1042 }
1043 }
1044
Robert Greenwalt5a735062010-03-02 17:25:02 -08001045 /** {@hide} */
1046 public static final int TETHER_ERROR_NO_ERROR = 0;
1047 /** {@hide} */
1048 public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
1049 /** {@hide} */
1050 public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
1051 /** {@hide} */
1052 public static final int TETHER_ERROR_UNSUPPORTED = 3;
1053 /** {@hide} */
1054 public static final int TETHER_ERROR_UNAVAIL_IFACE = 4;
1055 /** {@hide} */
1056 public static final int TETHER_ERROR_MASTER_ERROR = 5;
1057 /** {@hide} */
1058 public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
1059 /** {@hide} */
1060 public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
1061 /** {@hide} */
1062 public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8;
1063 /** {@hide} */
1064 public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9;
1065 /** {@hide} */
1066 public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
1067
1068 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001069 * Get a more detailed error code after a Tethering or Untethering
1070 * request asynchronously failed.
1071 *
1072 * @param iface The name of the interface of interest
Robert Greenwalt5a735062010-03-02 17:25:02 -08001073 * @return error The error code of the last error tethering or untethering the named
1074 * interface
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001075 *
1076 * <p>This method requires the call to hold the permission
1077 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -08001078 * {@hide}
1079 */
1080 public int getLastTetherError(String iface) {
1081 try {
1082 return mService.getLastTetherError(iface);
1083 } catch (RemoteException e) {
1084 return TETHER_ERROR_SERVICE_UNAVAIL;
1085 }
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001086 }
1087
1088 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001089 * Try to ensure the device stays awake until we connect with the next network.
1090 * Actually just holds a wakelock for a number of seconds while we try to connect
1091 * to any default networks. This will expire if the timeout passes or if we connect
1092 * to a default after this is called. For internal use only.
1093 *
1094 * @param forWhom the name of the network going down for logging purposes
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001095 * @return {@code true} on success, {@code false} on failure
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001096 *
1097 * <p>This method requires the call to hold the permission
1098 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001099 * {@hide}
1100 */
1101 public boolean requestNetworkTransitionWakelock(String forWhom) {
1102 try {
1103 mService.requestNetworkTransitionWakelock(forWhom);
1104 return true;
1105 } catch (RemoteException e) {
1106 return false;
1107 }
1108 }
Robert Greenwaltca4306c2010-09-09 13:15:32 -07001109
Robert Greenwalt67fd6c92010-09-09 14:22:59 -07001110 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001111 * Report network connectivity status. This is currently used only
1112 * to alter status bar UI.
1113 *
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001114 * @param networkType The type of network you want to report on
1115 * @param percentage The quality of the connection 0 is bad, 100 is good
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001116 *
1117 * <p>This method requires the call to hold the permission
1118 * {@link android.Manifest.permission#STATUS_BAR}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001119 * {@hide}
1120 */
1121 public void reportInetCondition(int networkType, int percentage) {
1122 try {
1123 mService.reportInetCondition(networkType, percentage);
1124 } catch (RemoteException e) {
1125 }
1126 }
Robert Greenwalt434203a2010-10-11 16:00:27 -07001127
1128 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001129 * Set a network-independent global http proxy. This is not normally what you want
1130 * for typical HTTP proxies - they are general network dependent. However if you're
1131 * doing something unusual like general internal filtering this may be useful. On
1132 * a private network where the proxy is not accessible, you may break HTTP using this.
1133 *
1134 * @param proxyProperties The a {@link ProxyProperites} object defining the new global
1135 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1136 *
1137 * <p>This method requires the call to hold the permission
1138 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001139 * {@hide}
1140 */
1141 public void setGlobalProxy(ProxyProperties p) {
1142 try {
1143 mService.setGlobalProxy(p);
1144 } catch (RemoteException e) {
1145 }
1146 }
1147
1148 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001149 * Retrieve any network-independent global HTTP proxy.
1150 *
1151 * @return {@link ProxyProperties} for the current global HTTP proxy or {@code null}
1152 * if no global HTTP proxy is set.
1153 *
1154 * <p>This method requires the call to hold the permission
1155 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001156 * {@hide}
1157 */
1158 public ProxyProperties getGlobalProxy() {
1159 try {
1160 return mService.getGlobalProxy();
1161 } catch (RemoteException e) {
1162 return null;
1163 }
1164 }
1165
1166 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001167 * Get the HTTP proxy settings for the current default network. Note that
1168 * if a global proxy is set, it will override any per-network setting.
1169 *
1170 * @return the {@link ProxyProperties} for the current HTTP proxy, or {@code null} if no
1171 * HTTP proxy is active.
1172 *
1173 * <p>This method requires the call to hold the permission
1174 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001175 * {@hide}
1176 */
1177 public ProxyProperties getProxy() {
1178 try {
1179 return mService.getProxy();
1180 } catch (RemoteException e) {
1181 return null;
1182 }
1183 }
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001184
1185 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001186 * Sets a secondary requirement bit for the given networkType.
1187 * This requirement bit is generally under the control of the carrier
1188 * or its agents and is not directly controlled by the user.
1189 *
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001190 * @param networkType The network who's dependence has changed
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001191 * @param met Boolean - true if network use is OK, false if not
1192 *
1193 * <p>This method requires the call to hold the permission
1194 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001195 * {@hide}
1196 */
1197 public void setDataDependency(int networkType, boolean met) {
1198 try {
1199 mService.setDataDependency(networkType, met);
1200 } catch (RemoteException e) {
1201 }
1202 }
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001203
1204 /**
1205 * Returns true if the hardware supports the given network type
1206 * else it returns false. This doesn't indicate we have coverage
1207 * or are authorized onto a network, just whether or not the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001208 * hardware supports it. For example a GSM phone without a SIM
1209 * should still return {@code true} for mobile data, but a wifi only
1210 * tablet would return {@code false}.
1211 *
1212 * @param networkType The network type we'd like to check
1213 * @return {@code true} if supported, else {@code false}
1214 *
1215 * <p>This method requires the call to hold the permission
1216 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001217 * @hide
1218 */
1219 public boolean isNetworkSupported(int networkType) {
1220 try {
1221 return mService.isNetworkSupported(networkType);
1222 } catch (RemoteException e) {}
1223 return false;
1224 }
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001225
1226 /**
1227 * Returns if the currently active data network is metered. A network is
1228 * classified as metered when the user is sensitive to heavy data usage on
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001229 * that connection due to monetary costs, data limitations or
1230 * battery/performance issues. You should check this before doing large
1231 * data transfers, and warn the user or delay the operation until another
1232 * network is available.
1233 *
1234 * @return {@code true} if large transfers should be avoided, otherwise
1235 * {@code false}.
1236 *
1237 * <p>This method requires the call to hold the permission
1238 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001239 */
1240 public boolean isActiveNetworkMetered() {
1241 try {
1242 return mService.isActiveNetworkMetered();
1243 } catch (RemoteException e) {
1244 return false;
1245 }
1246 }
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001247
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001248 /**
1249 * If the LockdownVpn mechanism is enabled, updates the vpn
1250 * with a reload of its profile.
1251 *
1252 * @return a boolean with {@code} indicating success
1253 *
1254 * <p>This method can only be called by the system UID
1255 * {@hide}
1256 */
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001257 public boolean updateLockdownVpn() {
1258 try {
1259 return mService.updateLockdownVpn();
1260 } catch (RemoteException e) {
1261 return false;
1262 }
1263 }
Irfan Sheriffda6da092012-08-16 12:49:23 -07001264
1265 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001266 * Signal that the captive portal check on the indicated network
1267 * is complete and we can turn the network on for general use.
1268 *
1269 * @param info the {@link NetworkInfo} object for the networkType
1270 * in question.
1271 *
1272 * <p>This method requires the call to hold the permission
1273 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Irfan Sheriffda6da092012-08-16 12:49:23 -07001274 * {@hide}
1275 */
1276 public void captivePortalCheckComplete(NetworkInfo info) {
1277 try {
1278 mService.captivePortalCheckComplete(info);
1279 } catch (RemoteException e) {
1280 }
1281 }
1282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283}