blob: 1ee4ec0990b34c808a9e4d7e5f1685e18e6ab435 [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;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080026import android.os.IBinder;
27import android.os.INetworkActivityListener;
28import android.os.INetworkManagementService;
Robert Greenwalt665e1ae2012-08-21 19:27:00 -070029import android.os.Messenger;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.os.RemoteException;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080031import android.os.ServiceManager;
Jeff Sharkey961e3042011-08-29 16:02:57 -070032import android.provider.Settings;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080033import android.util.ArrayMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070035import java.net.InetAddress;
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070036
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037/**
38 * Class that answers queries about the state of network connectivity. It also
39 * notifies applications when network connectivity changes. Get an instance
40 * of this class by calling
41 * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
42 * <p>
43 * The primary responsibilities of this class are to:
44 * <ol>
45 * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
46 * <li>Send broadcast intents when network connectivity changes</li>
47 * <li>Attempt to "fail over" to another network when connectivity to a network
48 * is lost</li>
49 * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
50 * state of the available networks</li>
51 * </ol>
52 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070053public class ConnectivityManager {
54 private static final String TAG = "ConnectivityManager";
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 /**
57 * A change in network connectivity has occurred. A connection has either
58 * been established or lost. The NetworkInfo for the affected network is
59 * sent as an extra; it should be consulted to see what kind of
60 * connectivity event occurred.
61 * <p/>
62 * If this is a connection that was the result of failing over from a
63 * disconnected network, then the FAILOVER_CONNECTION boolean extra is
64 * set to true.
65 * <p/>
66 * For a loss of connectivity, if the connectivity manager is attempting
67 * to connect (or has already connected) to another network, the
68 * NetworkInfo for the new network is also passed as an extra. This lets
69 * any receivers of the broadcast know that they should not necessarily
70 * tell the user that no data traffic will be possible. Instead, the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -080071 * receiver should expect another broadcast soon, indicating either that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 * the failover attempt succeeded (and so there is still overall data
73 * connectivity), or that the failover attempt failed, meaning that all
74 * connectivity has been lost.
75 * <p/>
76 * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
77 * is set to {@code true} if there are no connected networks at all.
78 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -080079 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 /**
Jeff Sharkey961e3042011-08-29 16:02:57 -070083 * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
Dianne Hackborn77b987f2014-02-26 16:20:52 -080084 * applicable {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY}.
Jeff Sharkey961e3042011-08-29 16:02:57 -070085 *
86 * @hide
87 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -080088 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey961e3042011-08-29 16:02:57 -070089 public static final String CONNECTIVITY_ACTION_IMMEDIATE =
90 "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
91
92 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 * The lookup key for a {@link NetworkInfo} object. Retrieve with
94 * {@link android.content.Intent#getParcelableExtra(String)}.
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070095 *
96 * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
97 * should always obtain network information through
98 * {@link #getActiveNetworkInfo()} or
99 * {@link #getAllNetworkInfo()}.
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -0700100 * @see #EXTRA_NETWORK_TYPE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 */
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700102 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 public static final String EXTRA_NETWORK_INFO = "networkInfo";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700104
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 /**
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -0700106 * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast.
107 * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo}
108 * state based on the calling application.
109 *
110 * @see android.content.Intent#getIntExtra(String, int)
111 */
112 public static final String EXTRA_NETWORK_TYPE = "networkType";
113
114 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 * The lookup key for a boolean that indicates whether a connect event
116 * is for a network to which the connectivity manager was failing over
117 * following a disconnect on another network.
118 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
119 */
120 public static final String EXTRA_IS_FAILOVER = "isFailover";
121 /**
122 * The lookup key for a {@link NetworkInfo} object. This is supplied when
123 * there is another network that it may be possible to connect to. Retrieve with
124 * {@link android.content.Intent#getParcelableExtra(String)}.
125 */
126 public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
127 /**
128 * The lookup key for a boolean that indicates whether there is a
129 * complete lack of connectivity, i.e., no network is available.
130 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
131 */
132 public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
133 /**
134 * The lookup key for a string that indicates why an attempt to connect
135 * to a network failed. The string has no particular structure. It is
136 * intended to be used in notifications presented to users. Retrieve
137 * it with {@link android.content.Intent#getStringExtra(String)}.
138 */
139 public static final String EXTRA_REASON = "reason";
140 /**
141 * The lookup key for a string that provides optionally supplied
142 * extra information about the network state. The information
143 * may be passed up from the lower networking layers, and its
144 * meaning may be specific to a particular network type. Retrieve
145 * it with {@link android.content.Intent#getStringExtra(String)}.
146 */
147 public static final String EXTRA_EXTRA_INFO = "extraInfo";
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700148 /**
149 * The lookup key for an int that provides information about
150 * our connection to the internet at large. 0 indicates no connection,
151 * 100 indicates a great connection. Retrieve it with
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700152 * {@link android.content.Intent#getIntExtra(String, int)}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700153 * {@hide}
154 */
155 public static final String EXTRA_INET_CONDITION = "inetCondition";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156
157 /**
Haoyu Baidb3c8672012-06-20 14:29:57 -0700158 * Broadcast action to indicate the change of data activity status
159 * (idle or active) on a network in a recent period.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800160 * The network becomes active when data transmission is started, or
161 * idle if there is no data transmission for a period of time.
Haoyu Baidb3c8672012-06-20 14:29:57 -0700162 * {@hide}
163 */
164 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
165 public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
166 /**
167 * The lookup key for an enum that indicates the network device type on which this data activity
168 * change happens.
169 * {@hide}
170 */
171 public static final String EXTRA_DEVICE_TYPE = "deviceType";
172 /**
173 * The lookup key for a boolean that indicates the device is active or not. {@code true} means
174 * it is actively sending or receiving data and {@code false} means it is idle.
175 * {@hide}
176 */
177 public static final String EXTRA_IS_ACTIVE = "isActive";
Ashish Sharma0535a9f2014-03-12 18:42:23 -0700178 /**
179 * The lookup key for a long that contains the timestamp (nanos) of the radio state change.
180 * {@hide}
181 */
182 public static final String EXTRA_REALTIME_NS = "tsNanos";
Haoyu Baidb3c8672012-06-20 14:29:57 -0700183
184 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 * Broadcast Action: The setting for background data usage has changed
186 * values. Use {@link #getBackgroundDataSetting()} to get the current value.
187 * <p>
188 * If an application uses the network in the background, it should listen
189 * for this broadcast and stop using the background data if the value is
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700190 * {@code false}.
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800191 * <p>
192 *
193 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability
194 * of background data depends on several combined factors, and
195 * this broadcast is no longer sent. Instead, when background
196 * data is unavailable, {@link #getActiveNetworkInfo()} will now
197 * appear disconnected. During first boot after a platform
198 * upgrade, this broadcast will be sent once if
199 * {@link #getBackgroundDataSetting()} was {@code false} before
200 * the upgrade.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 */
202 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800203 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
205 "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
206
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700207 /**
208 * Broadcast Action: The network connection may not be good
209 * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
210 * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
211 * the network and it's condition.
212 * @hide
213 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800214 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700215 public static final String INET_CONDITION_ACTION =
216 "android.net.conn.INET_CONDITION_ACTION";
217
Robert Greenwalt42acef32009-08-12 16:08:25 -0700218 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800219 * Broadcast Action: A tetherable connection has come or gone.
220 * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER},
221 * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and
222 * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate
223 * the current state of tethering. Each include a list of
224 * interface names in that state (may be empty).
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800225 * @hide
226 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800227 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800228 public static final String ACTION_TETHER_STATE_CHANGED =
229 "android.net.conn.TETHER_STATE_CHANGED";
230
231 /**
232 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800233 * gives a String[] listing all the interfaces configured for
234 * tethering and currently available for tethering.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800235 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800236 public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800237
238 /**
239 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800240 * gives a String[] listing all the interfaces currently tethered
241 * (ie, has dhcp support and packets potentially forwarded/NATed)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800242 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800243 public static final String EXTRA_ACTIVE_TETHER = "activeArray";
244
245 /**
246 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800247 * gives a String[] listing all the interfaces we tried to tether and
248 * failed. Use {@link #getLastTetherError} to find the error code
249 * for any interfaces listed here.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800250 */
251 public static final String EXTRA_ERRORED_TETHER = "erroredArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800252
253 /**
Russell Brenner108da0c2013-02-12 10:03:14 -0800254 * Broadcast Action: The captive portal tracker has finished its test.
255 * Sent only while running Setup Wizard, in lieu of showing a user
256 * notification.
257 * @hide
258 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800259 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Russell Brenner108da0c2013-02-12 10:03:14 -0800260 public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED =
261 "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED";
262 /**
263 * The lookup key for a boolean that indicates whether a captive portal was detected.
264 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
265 * @hide
266 */
267 public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal";
268
269 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800270 * The absence of a connection type.
Robert Greenwaltccf83af12011-06-02 17:30:47 -0700271 * @hide
272 */
273 public static final int TYPE_NONE = -1;
274
275 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800276 * The Mobile data connection. When active, all data traffic
277 * will use this network type's interface by default
278 * (it has a default route)
Robert Greenwalt42acef32009-08-12 16:08:25 -0700279 */
280 public static final int TYPE_MOBILE = 0;
281 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800282 * The WIFI data connection. When active, all data traffic
283 * will use this network type's interface by default
284 * (it has a default route).
Robert Greenwalt42acef32009-08-12 16:08:25 -0700285 */
286 public static final int TYPE_WIFI = 1;
287 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800288 * An MMS-specific Mobile data connection. This network type may use the
289 * same network interface as {@link #TYPE_MOBILE} or it may use a different
290 * one. This is used by applications needing to talk to the carrier's
291 * Multimedia Messaging Service servers.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700292 */
293 public static final int TYPE_MOBILE_MMS = 2;
294 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800295 * A SUPL-specific Mobile data connection. This network type may use the
296 * same network interface as {@link #TYPE_MOBILE} or it may use a different
297 * one. This is used by applications needing to talk to the carrier's
298 * Secure User Plane Location servers for help locating the device.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700299 */
300 public static final int TYPE_MOBILE_SUPL = 3;
301 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800302 * A DUN-specific Mobile data connection. This network type may use the
303 * same network interface as {@link #TYPE_MOBILE} or it may use a different
304 * one. This is sometimes by the system when setting up an upstream connection
305 * for tethering so that the carrier is aware of DUN traffic.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700306 */
307 public static final int TYPE_MOBILE_DUN = 4;
308 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800309 * A High Priority Mobile data connection. This network type uses the
310 * same network interface as {@link #TYPE_MOBILE} but the routing setup
311 * is different. Only requesting processes will have access to the
312 * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost}
313 * will route over this interface if no default route exists.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700314 */
315 public static final int TYPE_MOBILE_HIPRI = 5;
jsh8214deb2010-03-11 15:04:43 -0800316 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800317 * The WiMAX data connection. When active, all data traffic
318 * will use this network type's interface by default
319 * (it has a default route).
jsh8214deb2010-03-11 15:04:43 -0800320 */
321 public static final int TYPE_WIMAX = 6;
Robert Greenwaltda3d5e62010-12-06 13:56:24 -0800322
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800323 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800324 * The Bluetooth data connection. When active, all data traffic
325 * will use this network type's interface by default
326 * (it has a default route).
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800327 */
328 public static final int TYPE_BLUETOOTH = 7;
329
Robert Greenwalt60810842011-04-22 15:28:18 -0700330 /**
331 * Dummy data connection. This should not be used on shipping devices.
332 */
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800333 public static final int TYPE_DUMMY = 8;
Wink Saville9d7d6282011-03-12 14:52:01 -0800334
Robert Greenwalt60810842011-04-22 15:28:18 -0700335 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800336 * The Ethernet data connection. When active, all data traffic
337 * will use this network type's interface by default
338 * (it has a default route).
Robert Greenwalt60810842011-04-22 15:28:18 -0700339 */
Robert Greenwalte12aec92011-01-28 14:48:37 -0800340 public static final int TYPE_ETHERNET = 9;
Robert Greenwalt60810842011-04-22 15:28:18 -0700341
Wink Saville9d7d6282011-03-12 14:52:01 -0800342 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800343 * Over the air Administration.
Wink Saville9d7d6282011-03-12 14:52:01 -0800344 * {@hide}
345 */
346 public static final int TYPE_MOBILE_FOTA = 10;
347
348 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800349 * IP Multimedia Subsystem.
Wink Saville9d7d6282011-03-12 14:52:01 -0800350 * {@hide}
351 */
352 public static final int TYPE_MOBILE_IMS = 11;
353
354 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800355 * Carrier Branded Services.
Wink Saville9d7d6282011-03-12 14:52:01 -0800356 * {@hide}
357 */
358 public static final int TYPE_MOBILE_CBS = 12;
359
repo syncaea743a2011-07-29 23:55:49 -0700360 /**
361 * A Wi-Fi p2p connection. Only requesting processes will have access to
362 * the peers connected.
363 * {@hide}
364 */
365 public static final int TYPE_WIFI_P2P = 13;
Wink Saville9d7d6282011-03-12 14:52:01 -0800366
Wink Saville5e56bc52013-07-29 15:00:57 -0700367 /**
368 * The network to use for initially attaching to the network
369 * {@hide}
370 */
371 public static final int TYPE_MOBILE_IA = 14;
repo syncaea743a2011-07-29 23:55:49 -0700372
Hui Lu1c5624a2014-01-15 11:05:36 -0500373 /**
374 * The network that uses proxy to achieve connectivity.
375 * {@hide}
376 */
377 public static final int TYPE_PROXY = 16;
Wink Saville5e56bc52013-07-29 15:00:57 -0700378
379 /** {@hide} */
Hui Lu1c5624a2014-01-15 11:05:36 -0500380 public static final int MAX_RADIO_TYPE = TYPE_PROXY;
381
382 /** {@hide} */
383 public static final int MAX_NETWORK_TYPE = TYPE_PROXY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800385 /**
386 * If you want to set the default network preference,you can directly
387 * change the networkAttributes array in framework's config.xml.
388 *
389 * @deprecated Since we support so many more networks now, the single
390 * network default network preference can't really express
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800391 * the hierarchy. Instead, the default is defined by the
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800392 * networkAttributes in config.xml. You can determine
Robert Greenwalt4c8b7482012-12-07 09:56:50 -0800393 * the current value by calling {@link #getNetworkPreference()}
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800394 * from an App.
395 */
396 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
398
Jeff Sharkey625239a2012-09-26 22:03:49 -0700399 /**
400 * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800401 * milliseconds. This was introduced because IPv6 routes seem to take a
402 * moment to settle - trying network activity before the routes are adjusted
403 * can lead to packets using the wrong interface or having the wrong IP address.
404 * This delay is a bit crude, but in the future hopefully we will have kernel
405 * notifications letting us know when it's safe to use the new network.
Jeff Sharkey625239a2012-09-26 22:03:49 -0700406 *
407 * @hide
408 */
409 public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
410
Robert Greenwalt9ba9c582014-03-19 17:56:12 -0700411 /**
412 * @hide
413 */
414 public final static int INVALID_NET_ID = 0;
415
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700416 private final IConnectivityManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417
Chad Brubakerf81daa92014-02-14 13:22:34 -0800418 private final String mPackageName;
419
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800420 private INetworkManagementService mNMService;
421
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800422 /**
423 * Tests if a given integer represents a valid network type.
424 * @param networkType the type to be tested
425 * @return a boolean. {@code true} if the type is valid, else {@code false}
426 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700427 public static boolean isNetworkTypeValid(int networkType) {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700428 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800431 /**
432 * Returns a non-localized string representing a given network type.
433 * ONLY used for debugging output.
434 * @param type the type needing naming
435 * @return a String for the given type, or a string version of the type ("87")
436 * if no name is known.
437 * {@hide}
438 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700439 public static String getNetworkTypeName(int type) {
440 switch (type) {
441 case TYPE_MOBILE:
442 return "MOBILE";
443 case TYPE_WIFI:
444 return "WIFI";
445 case TYPE_MOBILE_MMS:
446 return "MOBILE_MMS";
447 case TYPE_MOBILE_SUPL:
448 return "MOBILE_SUPL";
449 case TYPE_MOBILE_DUN:
450 return "MOBILE_DUN";
451 case TYPE_MOBILE_HIPRI:
452 return "MOBILE_HIPRI";
453 case TYPE_WIMAX:
454 return "WIMAX";
455 case TYPE_BLUETOOTH:
456 return "BLUETOOTH";
457 case TYPE_DUMMY:
458 return "DUMMY";
459 case TYPE_ETHERNET:
460 return "ETHERNET";
461 case TYPE_MOBILE_FOTA:
462 return "MOBILE_FOTA";
463 case TYPE_MOBILE_IMS:
464 return "MOBILE_IMS";
465 case TYPE_MOBILE_CBS:
466 return "MOBILE_CBS";
repo syncaea743a2011-07-29 23:55:49 -0700467 case TYPE_WIFI_P2P:
468 return "WIFI_P2P";
Wink Saville5e56bc52013-07-29 15:00:57 -0700469 case TYPE_MOBILE_IA:
470 return "MOBILE_IA";
Hui Lu1c5624a2014-01-15 11:05:36 -0500471 case TYPE_PROXY:
472 return "PROXY";
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700473 default:
474 return Integer.toString(type);
475 }
476 }
477
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800478 /**
479 * Checks if a given type uses the cellular data connection.
480 * This should be replaced in the future by a network property.
481 * @param networkType the type to check
482 * @return a boolean - {@code true} if uses cellular network, else {@code false}
483 * {@hide}
484 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700485 public static boolean isNetworkTypeMobile(int networkType) {
486 switch (networkType) {
487 case TYPE_MOBILE:
488 case TYPE_MOBILE_MMS:
489 case TYPE_MOBILE_SUPL:
490 case TYPE_MOBILE_DUN:
491 case TYPE_MOBILE_HIPRI:
492 case TYPE_MOBILE_FOTA:
493 case TYPE_MOBILE_IMS:
494 case TYPE_MOBILE_CBS:
Wink Saville5e56bc52013-07-29 15:00:57 -0700495 case TYPE_MOBILE_IA:
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700496 return true;
497 default:
498 return false;
499 }
500 }
501
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800502 /**
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700503 * Checks if the given network type is backed by a Wi-Fi radio.
504 *
505 * @hide
506 */
507 public static boolean isNetworkTypeWifi(int networkType) {
508 switch (networkType) {
509 case TYPE_WIFI:
510 case TYPE_WIFI_P2P:
511 return true;
512 default:
513 return false;
514 }
515 }
516
517 /**
Chad Brubakerf336d722013-07-15 16:34:04 -0700518 * Checks if the given network type should be exempt from VPN routing rules
519 *
520 * @hide
521 */
522 public static boolean isNetworkTypeExempt(int networkType) {
523 switch (networkType) {
524 case TYPE_MOBILE_MMS:
525 case TYPE_MOBILE_SUPL:
526 case TYPE_MOBILE_HIPRI:
Wink Saville5e56bc52013-07-29 15:00:57 -0700527 case TYPE_MOBILE_IA:
Chad Brubakerf336d722013-07-15 16:34:04 -0700528 return true;
529 default:
530 return false;
531 }
532 }
533
534 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800535 * Specifies the preferred network type. When the device has more
536 * than one type available the preferred network type will be used.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800537 *
538 * @param preference the network type to prefer over all others. It is
539 * unspecified what happens to the old preferred network in the
540 * overall ordering.
Robert Greenwalt7b816022014-04-18 15:25:25 -0700541 * @Deprecated Functionality has been removed as it no longer makes sense,
542 * with many more than two networks - we'd need an array to express
543 * preference. Instead we use dynamic network properties of
544 * the networks to describe their precedence.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800545 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 public void setNetworkPreference(int preference) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 }
548
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800549 /**
550 * Retrieves the current preferred network type.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800551 *
552 * @return an integer representing the preferred network type
553 *
554 * <p>This method requires the caller to hold the permission
555 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt7b816022014-04-18 15:25:25 -0700556 * @Deprecated Functionality has been removed as it no longer makes sense,
557 * with many more than two networks - we'd need an array to express
558 * preference. Instead we use dynamic network properties of
559 * the networks to describe their precedence.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800560 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 public int getNetworkPreference() {
Robert Greenwalt7b816022014-04-18 15:25:25 -0700562 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
Scott Main671644c2011-10-06 19:02:28 -0700565 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800566 * Returns details about the currently active default data network. When
567 * connected, this network is the default route for outgoing connections.
568 * You should always check {@link NetworkInfo#isConnected()} before initiating
569 * network traffic. This may return {@code null} when there is no default
570 * network.
571 *
572 * @return a {@link NetworkInfo} object for the current default network
573 * or {@code null} if no network default network is currently active
574 *
575 * <p>This method requires the call to hold the permission
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700576 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -0700577 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 public NetworkInfo getActiveNetworkInfo() {
579 try {
580 return mService.getActiveNetworkInfo();
581 } catch (RemoteException e) {
582 return null;
583 }
584 }
585
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800586 /**
587 * Returns details about the currently active default data network
588 * for a given uid. This is for internal use only to avoid spying
589 * other apps.
590 *
591 * @return a {@link NetworkInfo} object for the current default network
592 * for the given uid or {@code null} if no default network is
593 * available for the specified uid.
594 *
595 * <p>This method requires the caller to hold the permission
596 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
597 * {@hide}
598 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700599 public NetworkInfo getActiveNetworkInfoForUid(int uid) {
600 try {
601 return mService.getActiveNetworkInfoForUid(uid);
602 } catch (RemoteException e) {
603 return null;
604 }
605 }
606
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800607 /**
608 * Returns connection status information about a particular
609 * network type.
610 *
611 * @param networkType integer specifying which networkType in
612 * which you're interested.
613 * @return a {@link NetworkInfo} object for the requested
614 * network type or {@code null} if the type is not
615 * supported by the device.
616 *
617 * <p>This method requires the call to hold the permission
618 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
619 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 public NetworkInfo getNetworkInfo(int networkType) {
621 try {
622 return mService.getNetworkInfo(networkType);
623 } catch (RemoteException e) {
624 return null;
625 }
626 }
627
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800628 /**
629 * Returns connection status information about all network
630 * types supported by the device.
631 *
632 * @return an array of {@link NetworkInfo} objects. Check each
633 * {@link NetworkInfo#getType} for which type each applies.
634 *
635 * <p>This method requires the call to hold the permission
636 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
637 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 public NetworkInfo[] getAllNetworkInfo() {
639 try {
640 return mService.getAllNetworkInfo();
641 } catch (RemoteException e) {
642 return null;
643 }
644 }
645
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800646 /**
Wink Saville948282b2013-08-29 08:55:16 -0700647 * Returns details about the Provisioning or currently active default data network. When
648 * connected, this network is the default route for outgoing connections.
649 * You should always check {@link NetworkInfo#isConnected()} before initiating
650 * network traffic. This may return {@code null} when there is no default
651 * network.
652 *
653 * @return a {@link NetworkInfo} object for the current default network
654 * or {@code null} if no network default network is currently active
655 *
656 * <p>This method requires the call to hold the permission
657 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
658 *
659 * {@hide}
660 */
661 public NetworkInfo getProvisioningOrActiveNetworkInfo() {
662 try {
663 return mService.getProvisioningOrActiveNetworkInfo();
664 } catch (RemoteException e) {
665 return null;
666 }
667 }
668
669 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800670 * Returns the IP information for the current default network.
671 *
672 * @return a {@link LinkProperties} object describing the IP info
673 * for the current default network, or {@code null} if there
674 * is no current default network.
675 *
676 * <p>This method requires the call to hold the permission
677 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
678 * {@hide}
679 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700680 public LinkProperties getActiveLinkProperties() {
681 try {
682 return mService.getActiveLinkProperties();
683 } catch (RemoteException e) {
684 return null;
685 }
686 }
687
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800688 /**
689 * Returns the IP information for a given network type.
690 *
691 * @param networkType the network type of interest.
692 * @return a {@link LinkProperties} object describing the IP info
693 * for the given networkType, or {@code null} if there is
694 * no current default network.
695 *
696 * <p>This method requires the call to hold the permission
697 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
698 * {@hide}
699 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700700 public LinkProperties getLinkProperties(int networkType) {
701 try {
702 return mService.getLinkProperties(networkType);
703 } catch (RemoteException e) {
704 return null;
705 }
706 }
707
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800708 /**
709 * Tells each network type to set its radio power state as directed.
710 *
711 * @param turnOn a boolean, {@code true} to turn the radios on,
712 * {@code false} to turn them off.
713 * @return a boolean, {@code true} indicating success. All network types
714 * will be tried, even if some fail.
715 *
716 * <p>This method requires the call to hold the permission
717 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
718 * {@hide}
719 */
Robert Greenwalt7b816022014-04-18 15:25:25 -0700720// TODO - check for any callers and remove
721// public boolean setRadios(boolean turnOn) {
722// try {
723// return mService.setRadios(turnOn);
724// } catch (RemoteException e) {
725// return false;
726// }
727// }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800729 /**
730 * Tells a given networkType to set its radio power state as directed.
731 *
732 * @param networkType the int networkType of interest.
733 * @param turnOn a boolean, {@code true} to turn the radio on,
734 * {@code} false to turn it off.
735 * @return a boolean, {@code true} indicating success.
736 *
737 * <p>This method requires the call to hold the permission
738 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
739 * {@hide}
740 */
Robert Greenwalt7b816022014-04-18 15:25:25 -0700741// TODO - check for any callers and remove
742// public boolean setRadio(int networkType, boolean turnOn) {
743// try {
744// return mService.setRadio(networkType, turnOn);
745// } catch (RemoteException e) {
746// return false;
747// }
748// }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749
750 /**
751 * Tells the underlying networking system that the caller wants to
752 * begin using the named feature. The interpretation of {@code feature}
753 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700754 * <p>This method requires the caller to hold the permission
755 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 * @param networkType specifies which network the request pertains to
757 * @param feature the name of the feature to be used
758 * @return an integer value representing the outcome of the request.
759 * The interpretation of this value is specific to each networking
760 * implementation+feature combination, except that the value {@code -1}
761 * always indicates failure.
762 */
763 public int startUsingNetworkFeature(int networkType, String feature) {
764 try {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700765 return mService.startUsingNetworkFeature(networkType, feature,
766 new Binder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 } catch (RemoteException e) {
768 return -1;
769 }
770 }
771
772 /**
773 * Tells the underlying networking system that the caller is finished
774 * using the named feature. The interpretation of {@code feature}
775 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700776 * <p>This method requires the caller to hold the permission
777 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 * @param networkType specifies which network the request pertains to
779 * @param feature the name of the feature that is no longer needed
780 * @return an integer value representing the outcome of the request.
781 * The interpretation of this value is specific to each networking
782 * implementation+feature combination, except that the value {@code -1}
783 * always indicates failure.
784 */
785 public int stopUsingNetworkFeature(int networkType, String feature) {
786 try {
787 return mService.stopUsingNetworkFeature(networkType, feature);
788 } catch (RemoteException e) {
789 return -1;
790 }
791 }
792
793 /**
794 * Ensure that a network route exists to deliver traffic to the specified
795 * host via the specified network interface. An attempt to add a route that
796 * already exists is ignored, but treated as successful.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700797 * <p>This method requires the caller to hold the permission
798 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 * @param networkType the type of the network over which traffic to the specified
800 * host is to be routed
801 * @param hostAddress the IP address of the host to which the route is desired
802 * @return {@code true} on success, {@code false} on failure
803 */
804 public boolean requestRouteToHost(int networkType, int hostAddress) {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700805 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
806
807 if (inetAddress == null) {
808 return false;
809 }
810
811 return requestRouteToHostAddress(networkType, inetAddress);
812 }
813
814 /**
815 * Ensure that a network route exists to deliver traffic to the specified
816 * host via the specified network interface. An attempt to add a route that
817 * already exists is ignored, but treated as successful.
Jake Hamby8f9b33e2014-01-15 13:08:03 -0800818 * <p>This method requires the caller to hold the permission
819 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt585ac0f2010-08-27 09:24:29 -0700820 * @param networkType the type of the network over which traffic to the specified
821 * host is to be routed
822 * @param hostAddress the IP address of the host to which the route is desired
823 * @return {@code true} on success, {@code false} on failure
824 * @hide
825 */
826 public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
827 byte[] address = hostAddress.getAddress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 try {
Chad Brubakerf81daa92014-02-14 13:22:34 -0800829 return mService.requestRouteToHostAddress(networkType, address, mPackageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 } catch (RemoteException e) {
831 return false;
832 }
833 }
834
835 /**
836 * Returns the value of the setting for background data usage. If false,
837 * applications should not use the network if the application is not in the
838 * foreground. Developers should respect this setting, and check the value
839 * of this before performing any background data operations.
840 * <p>
841 * All applications that have background services that use the network
842 * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700843 * <p>
Scott Main4cc53332011-10-06 18:32:43 -0700844 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700845 * background data depends on several combined factors, and this method will
846 * always return {@code true}. Instead, when background data is unavailable,
847 * {@link #getActiveNetworkInfo()} will now appear disconnected.
Danica Chang6fdd0c62010-08-11 14:54:43 -0700848 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 * @return Whether background data usage is allowed.
850 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700851 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 public boolean getBackgroundDataSetting() {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700853 // assume that background data is allowed; final authority is
854 // NetworkInfo which may be blocked.
855 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 }
857
858 /**
859 * Sets the value of the setting for background data usage.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800860 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 * @param allowBackgroundData Whether an application should use data while
862 * it is in the background.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800863 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
865 * @see #getBackgroundDataSetting()
866 * @hide
867 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700868 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 public void setBackgroundDataSetting(boolean allowBackgroundData) {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -0700870 // ignored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 }
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800872
873 /**
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700874 * Return quota status for the current active network, or {@code null} if no
875 * network is active. Quota status can change rapidly, so these values
876 * shouldn't be cached.
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -0700877 *
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800878 * <p>This method requires the call to hold the permission
879 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
880 *
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -0700881 * @hide
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700882 */
883 public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
884 try {
885 return mService.getActiveNetworkQuotaInfo();
886 } catch (RemoteException e) {
887 return null;
888 }
889 }
890
891 /**
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800892 * Gets the value of the setting for enabling Mobile data.
893 *
894 * @return Whether mobile data is enabled.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800895 *
896 * <p>This method requires the call to hold the permission
897 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800898 * @hide
899 */
900 public boolean getMobileDataEnabled() {
901 try {
902 return mService.getMobileDataEnabled();
903 } catch (RemoteException e) {
904 return true;
905 }
906 }
907
908 /**
909 * Sets the persisted value for enabling/disabling Mobile data.
910 *
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800911 * @param enabled Whether the user wants the mobile data connection used
912 * or not.
Robert Greenwaltc03fa502010-02-23 18:58:05 -0800913 * @hide
914 */
915 public void setMobileDataEnabled(boolean enabled) {
916 try {
917 mService.setMobileDataEnabled(enabled);
918 } catch (RemoteException e) {
919 }
920 }
921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800923 * Callback for use with {@link ConnectivityManager#registerNetworkActiveListener} to
924 * find out when the current network has gone in to a high power state.
925 */
926 public interface OnNetworkActiveListener {
927 /**
928 * Called on the main thread of the process to report that the current data network
929 * has become active, and it is now a good time to perform any pending network
930 * operations. Note that this listener only tells you when the network becomes
931 * active; if at any other time you want to know whether it is active (and thus okay
932 * to initiate network traffic), you can retrieve its instantaneous state with
933 * {@link ConnectivityManager#isNetworkActive}.
934 */
935 public void onNetworkActive();
936 }
937
938 private INetworkManagementService getNetworkManagementService() {
939 synchronized (this) {
940 if (mNMService != null) {
941 return mNMService;
942 }
943 IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
944 mNMService = INetworkManagementService.Stub.asInterface(b);
945 return mNMService;
946 }
947 }
948
949 private final ArrayMap<OnNetworkActiveListener, INetworkActivityListener>
950 mNetworkActivityListeners
951 = new ArrayMap<OnNetworkActiveListener, INetworkActivityListener>();
952
953 /**
954 * Start listening to reports when the data network is active, meaning it is
955 * a good time to perform network traffic. Use {@link #isNetworkActive()}
956 * to determine the current state of the network after registering the listener.
957 *
958 * @param l The listener to be told when the network is active.
959 */
960 public void registerNetworkActiveListener(final OnNetworkActiveListener l) {
961 INetworkActivityListener rl = new INetworkActivityListener.Stub() {
962 @Override
963 public void onNetworkActive() throws RemoteException {
964 l.onNetworkActive();
965 }
966 };
967
968 try {
969 getNetworkManagementService().registerNetworkActivityListener(rl);
970 mNetworkActivityListeners.put(l, rl);
971 } catch (RemoteException e) {
972 }
973 }
974
975 /**
976 * Remove network active listener previously registered with
977 * {@link #registerNetworkActiveListener}.
978 *
979 * @param l Previously registered listener.
980 */
981 public void unregisterNetworkActiveListener(OnNetworkActiveListener l) {
982 INetworkActivityListener rl = mNetworkActivityListeners.get(l);
983 if (rl == null) {
984 throw new IllegalArgumentException("Listener not registered: " + l);
985 }
986 try {
987 getNetworkManagementService().unregisterNetworkActivityListener(rl);
988 } catch (RemoteException e) {
989 }
990 }
991
992 /**
993 * Return whether the data network is currently active. An active network means that
994 * it is currently in a high power state for performing data transmission. On some
995 * types of networks, it may be expensive to move and stay in such a state, so it is
996 * more power efficient to batch network traffic together when the radio is already in
997 * this state. This method tells you whether right now is currently a good time to
998 * initiate network traffic, as the network is already active.
999 */
1000 public boolean isNetworkActive() {
1001 try {
1002 return getNetworkManagementService().isNetworkActive();
1003 } catch (RemoteException e) {
1004 }
1005 return false;
1006 }
1007
1008 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 * {@hide}
1010 */
Chad Brubakerf81daa92014-02-14 13:22:34 -08001011 public ConnectivityManager(IConnectivityManager service, String packageName) {
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -07001012 mService = checkNotNull(service, "missing IConnectivityManager");
Chad Brubakerf81daa92014-02-14 13:22:34 -08001013 mPackageName = checkNotNull(packageName, "missing package name");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 }
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001015
Jeff Sharkey8fc27e82012-04-04 20:40:58 -07001016 /** {@hide} */
1017 public static ConnectivityManager from(Context context) {
1018 return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
1019 }
1020
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001021 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001022 * Get the set of tetherable, available interfaces. This list is limited by
1023 * device configuration and current interface existence.
1024 *
1025 * @return an array of 0 or more Strings of tetherable interface names.
1026 *
1027 * <p>This method requires the call to hold the permission
1028 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001029 * {@hide}
1030 */
1031 public String[] getTetherableIfaces() {
1032 try {
1033 return mService.getTetherableIfaces();
1034 } catch (RemoteException e) {
1035 return new String[0];
1036 }
1037 }
1038
1039 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001040 * Get the set of tethered interfaces.
1041 *
1042 * @return an array of 0 or more String of currently tethered interface names.
1043 *
1044 * <p>This method requires the call to hold the permission
1045 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001046 * {@hide}
1047 */
1048 public String[] getTetheredIfaces() {
1049 try {
1050 return mService.getTetheredIfaces();
1051 } catch (RemoteException e) {
1052 return new String[0];
1053 }
1054 }
1055
1056 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001057 * Get the set of interface names which attempted to tether but
1058 * failed. Re-attempting to tether may cause them to reset to the Tethered
1059 * state. Alternatively, causing the interface to be destroyed and recreated
1060 * may cause them to reset to the available state.
1061 * {@link ConnectivityManager#getLastTetherError} can be used to get more
1062 * information on the cause of the errors.
1063 *
1064 * @return an array of 0 or more String indicating the interface names
1065 * which failed to tether.
1066 *
1067 * <p>This method requires the call to hold the permission
1068 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001069 * {@hide}
1070 */
Robert Greenwalt5a735062010-03-02 17:25:02 -08001071 public String[] getTetheringErroredIfaces() {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001072 try {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001073 return mService.getTetheringErroredIfaces();
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001074 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001075 return new String[0];
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001076 }
1077 }
1078
1079 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001080 * Attempt to tether the named interface. This will setup a dhcp server
1081 * on the interface, forward and NAT IP packets and forward DNS requests
1082 * to the best active upstream network interface. Note that if no upstream
1083 * IP network interface is available, dhcp will still run and traffic will be
1084 * allowed between the tethered devices and this device, though upstream net
1085 * access will of course fail until an upstream network interface becomes
1086 * active.
1087 *
1088 * @param iface the interface name to tether.
1089 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1090 *
1091 * <p>This method requires the call to hold the permission
1092 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001093 * {@hide}
1094 */
Robert Greenwalt5a735062010-03-02 17:25:02 -08001095 public int tether(String iface) {
1096 try {
1097 return mService.tether(iface);
1098 } catch (RemoteException e) {
1099 return TETHER_ERROR_SERVICE_UNAVAIL;
1100 }
1101 }
1102
1103 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001104 * Stop tethering the named interface.
1105 *
1106 * @param iface the interface name to untether.
1107 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1108 *
1109 * <p>This method requires the call to hold the permission
1110 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -08001111 * {@hide}
1112 */
1113 public int untether(String iface) {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001114 try {
1115 return mService.untether(iface);
1116 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001117 return TETHER_ERROR_SERVICE_UNAVAIL;
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001118 }
1119 }
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001120
1121 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001122 * Check if the device allows for tethering. It may be disabled via
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001123 * {@code ro.tether.denied} system property, Settings.TETHER_SUPPORTED or
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001124 * due to device configuration.
1125 *
1126 * @return a boolean - {@code true} indicating Tethering is supported.
1127 *
1128 * <p>This method requires the call to hold the permission
1129 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001130 * {@hide}
1131 */
1132 public boolean isTetheringSupported() {
1133 try {
1134 return mService.isTetheringSupported();
1135 } catch (RemoteException e) {
1136 return false;
1137 }
1138 }
1139
1140 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001141 * Get the list of regular expressions that define any tetherable
1142 * USB network interfaces. If USB tethering is not supported by the
1143 * device, this list should be empty.
1144 *
1145 * @return an array of 0 or more regular expression Strings defining
1146 * what interfaces are considered tetherable usb interfaces.
1147 *
1148 * <p>This method requires the call to hold the permission
1149 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001150 * {@hide}
1151 */
1152 public String[] getTetherableUsbRegexs() {
1153 try {
1154 return mService.getTetherableUsbRegexs();
1155 } catch (RemoteException e) {
1156 return new String[0];
1157 }
1158 }
1159
1160 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001161 * Get the list of regular expressions that define any tetherable
1162 * Wifi network interfaces. If Wifi tethering is not supported by the
1163 * device, this list should be empty.
1164 *
1165 * @return an array of 0 or more regular expression Strings defining
1166 * what interfaces are considered tetherable wifi interfaces.
1167 *
1168 * <p>This method requires the call to hold the permission
1169 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001170 * {@hide}
1171 */
1172 public String[] getTetherableWifiRegexs() {
1173 try {
1174 return mService.getTetherableWifiRegexs();
1175 } catch (RemoteException e) {
1176 return new String[0];
1177 }
1178 }
Robert Greenwalt5a735062010-03-02 17:25:02 -08001179
Danica Chang6fdd0c62010-08-11 14:54:43 -07001180 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001181 * Get the list of regular expressions that define any tetherable
1182 * Bluetooth network interfaces. If Bluetooth tethering is not supported by the
1183 * device, this list should be empty.
1184 *
1185 * @return an array of 0 or more regular expression Strings defining
1186 * what interfaces are considered tetherable bluetooth interfaces.
1187 *
1188 * <p>This method requires the call to hold the permission
1189 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Danica Chang6fdd0c62010-08-11 14:54:43 -07001190 * {@hide}
1191 */
1192 public String[] getTetherableBluetoothRegexs() {
1193 try {
1194 return mService.getTetherableBluetoothRegexs();
1195 } catch (RemoteException e) {
1196 return new String[0];
1197 }
1198 }
1199
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001200 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001201 * Attempt to both alter the mode of USB and Tethering of USB. A
1202 * utility method to deal with some of the complexity of USB - will
1203 * attempt to switch to Rndis and subsequently tether the resulting
1204 * interface on {@code true} or turn off tethering and switch off
1205 * Rndis on {@code false}.
1206 *
1207 * @param enable a boolean - {@code true} to enable tethering
1208 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1209 *
1210 * <p>This method requires the call to hold the permission
1211 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001212 * {@hide}
1213 */
1214 public int setUsbTethering(boolean enable) {
1215 try {
1216 return mService.setUsbTethering(enable);
1217 } catch (RemoteException e) {
1218 return TETHER_ERROR_SERVICE_UNAVAIL;
1219 }
1220 }
1221
Robert Greenwalt5a735062010-03-02 17:25:02 -08001222 /** {@hide} */
1223 public static final int TETHER_ERROR_NO_ERROR = 0;
1224 /** {@hide} */
1225 public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
1226 /** {@hide} */
1227 public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
1228 /** {@hide} */
1229 public static final int TETHER_ERROR_UNSUPPORTED = 3;
1230 /** {@hide} */
1231 public static final int TETHER_ERROR_UNAVAIL_IFACE = 4;
1232 /** {@hide} */
1233 public static final int TETHER_ERROR_MASTER_ERROR = 5;
1234 /** {@hide} */
1235 public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
1236 /** {@hide} */
1237 public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
1238 /** {@hide} */
1239 public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8;
1240 /** {@hide} */
1241 public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9;
1242 /** {@hide} */
1243 public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
1244
1245 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001246 * Get a more detailed error code after a Tethering or Untethering
1247 * request asynchronously failed.
1248 *
1249 * @param iface The name of the interface of interest
Robert Greenwalt5a735062010-03-02 17:25:02 -08001250 * @return error The error code of the last error tethering or untethering the named
1251 * interface
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001252 *
1253 * <p>This method requires the call to hold the permission
1254 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -08001255 * {@hide}
1256 */
1257 public int getLastTetherError(String iface) {
1258 try {
1259 return mService.getLastTetherError(iface);
1260 } catch (RemoteException e) {
1261 return TETHER_ERROR_SERVICE_UNAVAIL;
1262 }
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001263 }
1264
1265 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001266 * Try to ensure the device stays awake until we connect with the next network.
1267 * Actually just holds a wakelock for a number of seconds while we try to connect
1268 * to any default networks. This will expire if the timeout passes or if we connect
1269 * to a default after this is called. For internal use only.
1270 *
1271 * @param forWhom the name of the network going down for logging purposes
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001272 * @return {@code true} on success, {@code false} on failure
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001273 *
1274 * <p>This method requires the call to hold the permission
1275 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001276 * {@hide}
1277 */
1278 public boolean requestNetworkTransitionWakelock(String forWhom) {
1279 try {
1280 mService.requestNetworkTransitionWakelock(forWhom);
1281 return true;
1282 } catch (RemoteException e) {
1283 return false;
1284 }
1285 }
Robert Greenwaltca4306c2010-09-09 13:15:32 -07001286
Robert Greenwalt67fd6c92010-09-09 14:22:59 -07001287 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001288 * Report network connectivity status. This is currently used only
1289 * to alter status bar UI.
1290 *
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001291 * @param networkType The type of network you want to report on
1292 * @param percentage The quality of the connection 0 is bad, 100 is good
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001293 *
1294 * <p>This method requires the call to hold the permission
1295 * {@link android.Manifest.permission#STATUS_BAR}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001296 * {@hide}
1297 */
1298 public void reportInetCondition(int networkType, int percentage) {
1299 try {
1300 mService.reportInetCondition(networkType, percentage);
1301 } catch (RemoteException e) {
1302 }
1303 }
Robert Greenwalt434203a2010-10-11 16:00:27 -07001304
1305 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001306 * Set a network-independent global http proxy. This is not normally what you want
1307 * for typical HTTP proxies - they are general network dependent. However if you're
1308 * doing something unusual like general internal filtering this may be useful. On
1309 * a private network where the proxy is not accessible, you may break HTTP using this.
1310 *
Jason Monk207900c2014-04-25 15:00:09 -04001311 * @param p The a {@link ProxyInfo} object defining the new global
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001312 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1313 *
1314 * <p>This method requires the call to hold the permission
Jason Monkfaf3fd52014-05-07 18:41:13 -04001315 * android.Manifest.permission#CONNECTIVITY_INTERNAL.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001316 */
Jason Monk207900c2014-04-25 15:00:09 -04001317 public void setGlobalProxy(ProxyInfo p) {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001318 try {
1319 mService.setGlobalProxy(p);
1320 } catch (RemoteException e) {
1321 }
1322 }
1323
1324 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001325 * Retrieve any network-independent global HTTP proxy.
1326 *
Jason Monk207900c2014-04-25 15:00:09 -04001327 * @return {@link ProxyInfo} for the current global HTTP proxy or {@code null}
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001328 * if no global HTTP proxy is set.
1329 *
1330 * <p>This method requires the call to hold the permission
1331 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001332 */
Jason Monk207900c2014-04-25 15:00:09 -04001333 public ProxyInfo getGlobalProxy() {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001334 try {
1335 return mService.getGlobalProxy();
1336 } catch (RemoteException e) {
1337 return null;
1338 }
1339 }
1340
1341 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001342 * Get the HTTP proxy settings for the current default network. Note that
1343 * if a global proxy is set, it will override any per-network setting.
1344 *
Jason Monk207900c2014-04-25 15:00:09 -04001345 * @return the {@link ProxyInfo} for the current HTTP proxy, or {@code null} if no
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001346 * HTTP proxy is active.
1347 *
1348 * <p>This method requires the call to hold the permission
1349 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001350 * {@hide}
1351 */
Jason Monk207900c2014-04-25 15:00:09 -04001352 public ProxyInfo getProxy() {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001353 try {
1354 return mService.getProxy();
1355 } catch (RemoteException e) {
1356 return null;
1357 }
1358 }
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001359
1360 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001361 * Sets a secondary requirement bit for the given networkType.
1362 * This requirement bit is generally under the control of the carrier
1363 * or its agents and is not directly controlled by the user.
1364 *
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001365 * @param networkType The network who's dependence has changed
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001366 * @param met Boolean - true if network use is OK, false if not
1367 *
1368 * <p>This method requires the call to hold the permission
1369 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001370 * {@hide}
1371 */
1372 public void setDataDependency(int networkType, boolean met) {
1373 try {
1374 mService.setDataDependency(networkType, met);
1375 } catch (RemoteException e) {
1376 }
1377 }
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001378
1379 /**
1380 * Returns true if the hardware supports the given network type
1381 * else it returns false. This doesn't indicate we have coverage
1382 * or are authorized onto a network, just whether or not the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001383 * hardware supports it. For example a GSM phone without a SIM
1384 * should still return {@code true} for mobile data, but a wifi only
1385 * tablet would return {@code false}.
1386 *
1387 * @param networkType The network type we'd like to check
1388 * @return {@code true} if supported, else {@code false}
1389 *
1390 * <p>This method requires the call to hold the permission
1391 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001392 * @hide
1393 */
1394 public boolean isNetworkSupported(int networkType) {
1395 try {
1396 return mService.isNetworkSupported(networkType);
1397 } catch (RemoteException e) {}
1398 return false;
1399 }
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001400
1401 /**
1402 * Returns if the currently active data network is metered. A network is
1403 * classified as metered when the user is sensitive to heavy data usage on
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001404 * that connection due to monetary costs, data limitations or
1405 * battery/performance issues. You should check this before doing large
1406 * data transfers, and warn the user or delay the operation until another
1407 * network is available.
1408 *
1409 * @return {@code true} if large transfers should be avoided, otherwise
1410 * {@code false}.
1411 *
1412 * <p>This method requires the call to hold the permission
1413 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001414 */
1415 public boolean isActiveNetworkMetered() {
1416 try {
1417 return mService.isActiveNetworkMetered();
1418 } catch (RemoteException e) {
1419 return false;
1420 }
1421 }
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001422
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001423 /**
1424 * If the LockdownVpn mechanism is enabled, updates the vpn
1425 * with a reload of its profile.
1426 *
1427 * @return a boolean with {@code} indicating success
1428 *
1429 * <p>This method can only be called by the system UID
1430 * {@hide}
1431 */
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001432 public boolean updateLockdownVpn() {
1433 try {
1434 return mService.updateLockdownVpn();
1435 } catch (RemoteException e) {
1436 return false;
1437 }
1438 }
Irfan Sheriffda6da092012-08-16 12:49:23 -07001439
1440 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001441 * Signal that the captive portal check on the indicated network
Wink Savilled747cbc2013-08-07 16:22:47 -07001442 * is complete and whether its a captive portal or not.
1443 *
1444 * @param info the {@link NetworkInfo} object for the networkType
1445 * in question.
1446 * @param isCaptivePortal true/false.
1447 *
1448 * <p>This method requires the call to hold the permission
1449 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
1450 * {@hide}
1451 */
1452 public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
1453 try {
1454 mService.captivePortalCheckCompleted(info, isCaptivePortal);
1455 } catch (RemoteException e) {
1456 }
1457 }
1458
1459 /**
Robert Greenwalt665e1ae2012-08-21 19:27:00 -07001460 * Supply the backend messenger for a network tracker
1461 *
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001462 * @param networkType NetworkType to set
Robert Greenwalt665e1ae2012-08-21 19:27:00 -07001463 * @param messenger {@link Messenger}
1464 * {@hide}
1465 */
1466 public void supplyMessenger(int networkType, Messenger messenger) {
1467 try {
1468 mService.supplyMessenger(networkType, messenger);
1469 } catch (RemoteException e) {
1470 }
1471 }
Wink Savilleab9321d2013-06-29 21:10:57 -07001472
1473 /**
Wink Saville948282b2013-08-29 08:55:16 -07001474 * Check mobile provisioning.
Wink Savilleab9321d2013-06-29 21:10:57 -07001475 *
Wink Savilleab9321d2013-06-29 21:10:57 -07001476 * @param suggestedTimeOutMs, timeout in milliseconds
Wink Savilleab9321d2013-06-29 21:10:57 -07001477 *
1478 * @return time out that will be used, maybe less that suggestedTimeOutMs
1479 * -1 if an error.
1480 *
1481 * {@hide}
1482 */
Wink Saville948282b2013-08-29 08:55:16 -07001483 public int checkMobileProvisioning(int suggestedTimeOutMs) {
Wink Savilleab9321d2013-06-29 21:10:57 -07001484 int timeOutMs = -1;
1485 try {
Wink Saville948282b2013-08-29 08:55:16 -07001486 timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
Wink Savilleab9321d2013-06-29 21:10:57 -07001487 } catch (RemoteException e) {
1488 }
1489 return timeOutMs;
1490 }
Robert Greenwalte182bfe2013-07-16 12:06:09 -07001491
1492 /**
Wink Saville42d4f082013-07-20 20:31:59 -07001493 * Get the mobile provisioning url.
Robert Greenwalte182bfe2013-07-16 12:06:09 -07001494 * {@hide}
1495 */
1496 public String getMobileProvisioningUrl() {
1497 try {
1498 return mService.getMobileProvisioningUrl();
1499 } catch (RemoteException e) {
1500 }
1501 return null;
1502 }
Wink Saville42d4f082013-07-20 20:31:59 -07001503
1504 /**
1505 * Get the mobile redirected provisioning url.
1506 * {@hide}
1507 */
1508 public String getMobileRedirectedProvisioningUrl() {
1509 try {
1510 return mService.getMobileRedirectedProvisioningUrl();
1511 } catch (RemoteException e) {
1512 }
1513 return null;
1514 }
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001515
1516 /**
1517 * get the information about a specific network link
1518 * @hide
1519 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001520 public LinkQualityInfo getLinkQualityInfo(int networkType) {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001521 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001522 LinkQualityInfo li = mService.getLinkQualityInfo(networkType);
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001523 return li;
1524 } catch (RemoteException e) {
1525 return null;
1526 }
1527 }
1528
1529 /**
1530 * get the information of currently active network link
1531 * @hide
1532 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001533 public LinkQualityInfo getActiveLinkQualityInfo() {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001534 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001535 LinkQualityInfo li = mService.getActiveLinkQualityInfo();
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001536 return li;
1537 } catch (RemoteException e) {
1538 return null;
1539 }
1540 }
1541
1542 /**
1543 * get the information of all network links
1544 * @hide
1545 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001546 public LinkQualityInfo[] getAllLinkQualityInfo() {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001547 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001548 LinkQualityInfo[] li = mService.getAllLinkQualityInfo();
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001549 return li;
1550 } catch (RemoteException e) {
1551 return null;
1552 }
1553 }
Wink Saville7788c612013-08-29 14:57:08 -07001554
1555 /**
Wink Saville948282b2013-08-29 08:55:16 -07001556 * Set sign in error notification to visible or in visible
1557 *
1558 * @param visible
1559 * @param networkType
1560 *
1561 * {@hide}
1562 */
1563 public void setProvisioningNotificationVisible(boolean visible, int networkType,
1564 String extraInfo, String url) {
1565 try {
1566 mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url);
1567 } catch (RemoteException e) {
1568 }
1569 }
Yuhao Zheng5cd1a0e2013-09-09 17:00:04 -07001570
1571 /**
1572 * Set the value for enabling/disabling airplane mode
1573 *
1574 * @param enable whether to enable airplane mode or not
1575 *
1576 * <p>This method requires the call to hold the permission
1577 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
1578 * @hide
1579 */
1580 public void setAirplaneMode(boolean enable) {
1581 try {
1582 mService.setAirplaneMode(enable);
1583 } catch (RemoteException e) {
1584 }
1585 }
Robert Greenwalte049c232014-04-11 15:53:27 -07001586
1587 /** {@hide} */
1588 public void registerNetworkFactory(Messenger messenger) {
1589 try {
1590 mService.registerNetworkFactory(messenger);
1591 } catch (RemoteException e) { }
1592 }
Robert Greenwalt7b816022014-04-18 15:25:25 -07001593
1594 /** {@hide} */
1595 public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
1596 NetworkCapabilities nc, int score) {
1597 try {
1598 mService.registerNetworkAgent(messenger, ni, lp, nc, score);
1599 } catch (RemoteException e) { }
1600 }
1601
1602 /** Interface for NetworkRequest callbacks {@hide} */
1603 public static class NetworkCallbacks {
1604 public static final int PRECHECK = 1;
1605 public static final int AVAILABLE = 2;
1606 public static final int LOSING = 3;
1607 public static final int LOST = 4;
1608 public static final int UNAVAIL = 5;
1609 public static final int CAP_CHANGED = 6;
1610 public static final int PROP_CHANGED = 7;
1611 public static final int CANCELED = 8;
1612
1613 /**
1614 * @hide
1615 * Called whenever the framework connects to a network that it may use to
1616 * satisfy this request
1617 */
1618 public void onPreCheck(NetworkRequest networkRequest, Network network) {}
1619
1620 /**
1621 * Called when the framework connects and has validated the new network.
1622 */
1623 public void onAvailable(NetworkRequest networkRequest, Network network) {}
1624
1625 /**
1626 * Called when the framework is losing the network. Often paired with an
1627 * onAvailable call with the new replacement network for graceful handover.
1628 * This may not be called if we have a hard loss (loss without warning).
1629 * This may be followed by either an onLost call or an onAvailable call for this
1630 * network depending on if we lose or regain it.
1631 */
1632 public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {}
1633
1634 /**
1635 * Called when the framework has a hard loss of the network or when the
1636 * graceful failure ends. Note applications should only request this callback
1637 * if the application is willing to track the Available and Lost callbacks
1638 * together, else the application may think it has no network when it
1639 * really does (A Avail, B Avail, A Lost.. still have B).
1640 */
1641 public void onLost(NetworkRequest networkRequest, Network network) {}
1642
1643 /**
1644 * Called if no network is found in the given timeout time. If no timeout is given,
1645 * this will not be called.
1646 */
1647 public void onUnavailable(NetworkRequest networkRequest) {}
1648
1649 /**
1650 * Called when the network the framework connected to for this request
1651 * changes capabilities but still satisfies the stated need.
1652 */
1653 public void onCapabilitiesChanged(NetworkRequest networkRequest, Network network,
1654 NetworkCapabilities networkCapabilities) {}
1655
1656 /**
1657 * Called when the network the framework connected to for this request
1658 * changes properties.
1659 */
1660 public void onPropertiesChanged(NetworkRequest networkRequest, Network network,
1661 LinkProperties linkProperties) {}
1662
1663 /**
1664 * Called when a CancelRequest call concludes and the registered callbacks will
1665 * no longer be used.
1666 */
1667 public void onCanceled(NetworkRequest networkRequest) {}
1668 }
1669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670}