blob: 24844ba46c2853906305d6f27d874876a908ba87 [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 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080016package android.net;
17
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070018import static com.android.internal.util.Preconditions.checkNotNull;
19
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
Robert Greenwalt9258c642014-03-26 16:47:06 -070022import android.app.PendingIntent;
Jeff Sharkey8fc27e82012-04-04 20:40:58 -070023import android.content.Context;
Robert Greenwaltd19c41c2014-05-18 23:07:25 -070024import android.content.Intent;
Robert Greenwalt42acef32009-08-12 16:08:25 -070025import android.os.Binder;
Jeff Sharkey3a844fc2011-08-16 14:37:57 -070026import android.os.Build.VERSION_CODES;
Robert Greenwalt9258c642014-03-26 16:47:06 -070027import android.os.Handler;
28import android.os.HandlerThread;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080029import android.os.IBinder;
30import android.os.INetworkActivityListener;
31import android.os.INetworkManagementService;
Robert Greenwalt9258c642014-03-26 16:47:06 -070032import android.os.Looper;
33import android.os.Message;
Robert Greenwalt665e1ae2012-08-21 19:27:00 -070034import android.os.Messenger;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.os.RemoteException;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080036import android.os.ServiceManager;
Jeff Sharkey961e3042011-08-29 16:02:57 -070037import android.provider.Settings;
Robert Greenwalt47eecf02014-05-21 20:04:36 -070038import android.telephony.TelephonyManager;
Dianne Hackborn77b987f2014-02-26 16:20:52 -080039import android.util.ArrayMap;
Robert Greenwalt9258c642014-03-26 16:47:06 -070040import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
Robert Greenwalt47eecf02014-05-21 20:04:36 -070042import com.android.internal.telephony.ITelephony;
Robert Greenwalt71bf33a2014-05-15 18:07:26 -070043import com.android.internal.telephony.PhoneConstants;
Robert Greenwalt47eecf02014-05-21 20:04:36 -070044import com.android.internal.util.Protocol;
45
Robert Greenwalt585ac0f2010-08-27 09:24:29 -070046import java.net.InetAddress;
Robert Greenwalt9258c642014-03-26 16:47:06 -070047import java.util.concurrent.atomic.AtomicInteger;
48import java.util.HashMap;
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050/**
51 * Class that answers queries about the state of network connectivity. It also
52 * notifies applications when network connectivity changes. Get an instance
53 * of this class by calling
54 * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
55 * <p>
56 * The primary responsibilities of this class are to:
57 * <ol>
58 * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
59 * <li>Send broadcast intents when network connectivity changes</li>
60 * <li>Attempt to "fail over" to another network when connectivity to a network
61 * is lost</li>
62 * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
63 * state of the available networks</li>
Robert Greenwaltd19c41c2014-05-18 23:07:25 -070064 * <li>Provide an API that allows applications to request and select networks for their data
65 * traffic</li>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 * </ol>
67 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -070068public class ConnectivityManager {
69 private static final String TAG = "ConnectivityManager";
70
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -070072 * A change in network connectivity has occurred. A default connection has either
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 * been established or lost. The NetworkInfo for the affected network is
74 * sent as an extra; it should be consulted to see what kind of
75 * connectivity event occurred.
76 * <p/>
77 * If this is a connection that was the result of failing over from a
78 * disconnected network, then the FAILOVER_CONNECTION boolean extra is
79 * set to true.
80 * <p/>
81 * For a loss of connectivity, if the connectivity manager is attempting
82 * to connect (or has already connected) to another network, the
83 * NetworkInfo for the new network is also passed as an extra. This lets
84 * any receivers of the broadcast know that they should not necessarily
85 * tell the user that no data traffic will be possible. Instead, the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -080086 * receiver should expect another broadcast soon, indicating either that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 * the failover attempt succeeded (and so there is still overall data
88 * connectivity), or that the failover attempt failed, meaning that all
89 * connectivity has been lost.
90 * <p/>
91 * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
92 * is set to {@code true} if there are no connected networks at all.
93 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -080094 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -070096
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 /**
Jeff Sharkey961e3042011-08-29 16:02:57 -070098 * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
Dianne Hackborn77b987f2014-02-26 16:20:52 -080099 * applicable {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY}.
Jeff Sharkey961e3042011-08-29 16:02:57 -0700100 *
101 * @hide
102 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800103 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey961e3042011-08-29 16:02:57 -0700104 public static final String CONNECTIVITY_ACTION_IMMEDIATE =
105 "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
106
107 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 * The lookup key for a {@link NetworkInfo} object. Retrieve with
109 * {@link android.content.Intent#getParcelableExtra(String)}.
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700110 *
111 * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
112 * should always obtain network information through
113 * {@link #getActiveNetworkInfo()} or
114 * {@link #getAllNetworkInfo()}.
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -0700115 * @see #EXTRA_NETWORK_TYPE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 */
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700117 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 public static final String EXTRA_NETWORK_INFO = "networkInfo";
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -0700119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 /**
Jeff Sharkey75fbb4b2012-08-06 11:41:50 -0700121 * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast.
122 * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo}
123 * state based on the calling application.
124 *
125 * @see android.content.Intent#getIntExtra(String, int)
126 */
127 public static final String EXTRA_NETWORK_TYPE = "networkType";
128
129 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 * The lookup key for a boolean that indicates whether a connect event
131 * is for a network to which the connectivity manager was failing over
132 * following a disconnect on another network.
133 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
134 */
135 public static final String EXTRA_IS_FAILOVER = "isFailover";
136 /**
137 * The lookup key for a {@link NetworkInfo} object. This is supplied when
138 * there is another network that it may be possible to connect to. Retrieve with
139 * {@link android.content.Intent#getParcelableExtra(String)}.
140 */
141 public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
142 /**
143 * The lookup key for a boolean that indicates whether there is a
144 * complete lack of connectivity, i.e., no network is available.
145 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
146 */
147 public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
148 /**
149 * The lookup key for a string that indicates why an attempt to connect
150 * to a network failed. The string has no particular structure. It is
151 * intended to be used in notifications presented to users. Retrieve
152 * it with {@link android.content.Intent#getStringExtra(String)}.
153 */
154 public static final String EXTRA_REASON = "reason";
155 /**
156 * The lookup key for a string that provides optionally supplied
157 * extra information about the network state. The information
158 * may be passed up from the lower networking layers, and its
159 * meaning may be specific to a particular network type. Retrieve
160 * it with {@link android.content.Intent#getStringExtra(String)}.
161 */
162 public static final String EXTRA_EXTRA_INFO = "extraInfo";
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700163 /**
164 * The lookup key for an int that provides information about
165 * our connection to the internet at large. 0 indicates no connection,
166 * 100 indicates a great connection. Retrieve it with
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700167 * {@link android.content.Intent#getIntExtra(String, int)}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -0700168 * {@hide}
169 */
170 public static final String EXTRA_INET_CONDITION = "inetCondition";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171
172 /**
Haoyu Baidb3c8672012-06-20 14:29:57 -0700173 * Broadcast action to indicate the change of data activity status
174 * (idle or active) on a network in a recent period.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800175 * The network becomes active when data transmission is started, or
176 * idle if there is no data transmission for a period of time.
Haoyu Baidb3c8672012-06-20 14:29:57 -0700177 * {@hide}
178 */
179 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
180 public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
181 /**
182 * The lookup key for an enum that indicates the network device type on which this data activity
183 * change happens.
184 * {@hide}
185 */
186 public static final String EXTRA_DEVICE_TYPE = "deviceType";
187 /**
188 * The lookup key for a boolean that indicates the device is active or not. {@code true} means
189 * it is actively sending or receiving data and {@code false} means it is idle.
190 * {@hide}
191 */
192 public static final String EXTRA_IS_ACTIVE = "isActive";
Ashish Sharma0535a9f2014-03-12 18:42:23 -0700193 /**
194 * The lookup key for a long that contains the timestamp (nanos) of the radio state change.
195 * {@hide}
196 */
197 public static final String EXTRA_REALTIME_NS = "tsNanos";
Haoyu Baidb3c8672012-06-20 14:29:57 -0700198
199 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 * Broadcast Action: The setting for background data usage has changed
201 * values. Use {@link #getBackgroundDataSetting()} to get the current value.
202 * <p>
203 * If an application uses the network in the background, it should listen
204 * for this broadcast and stop using the background data if the value is
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700205 * {@code false}.
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800206 * <p>
207 *
208 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability
209 * of background data depends on several combined factors, and
210 * this broadcast is no longer sent. Instead, when background
211 * data is unavailable, {@link #getActiveNetworkInfo()} will now
212 * appear disconnected. During first boot after a platform
213 * upgrade, this broadcast will be sent once if
214 * {@link #getBackgroundDataSetting()} was {@code false} before
215 * the upgrade.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 */
217 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Jeff Sharkey54ee2ad2012-01-30 16:29:24 -0800218 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
220 "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
221
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700222 /**
223 * Broadcast Action: The network connection may not be good
224 * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
225 * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
226 * the network and it's condition.
227 * @hide
228 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800229 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwalt1e9aac22010-09-15 17:36:33 -0700230 public static final String INET_CONDITION_ACTION =
231 "android.net.conn.INET_CONDITION_ACTION";
232
Robert Greenwalt42acef32009-08-12 16:08:25 -0700233 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800234 * Broadcast Action: A tetherable connection has come or gone.
235 * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER},
236 * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and
237 * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate
238 * the current state of tethering. Each include a list of
239 * interface names in that state (may be empty).
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800240 * @hide
241 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800242 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800243 public static final String ACTION_TETHER_STATE_CHANGED =
244 "android.net.conn.TETHER_STATE_CHANGED";
245
246 /**
247 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800248 * gives a String[] listing all the interfaces configured for
249 * tethering and currently available for tethering.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800250 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800251 public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800252
253 /**
254 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800255 * gives a String[] listing all the interfaces currently tethered
256 * (ie, has dhcp support and packets potentially forwarded/NATed)
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800257 */
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800258 public static final String EXTRA_ACTIVE_TETHER = "activeArray";
259
260 /**
261 * @hide
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800262 * gives a String[] listing all the interfaces we tried to tether and
263 * failed. Use {@link #getLastTetherError} to find the error code
264 * for any interfaces listed here.
Robert Greenwalt2a091d72010-02-11 18:18:40 -0800265 */
266 public static final String EXTRA_ERRORED_TETHER = "erroredArray";
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -0800267
268 /**
Russell Brenner108da0c2013-02-12 10:03:14 -0800269 * Broadcast Action: The captive portal tracker has finished its test.
270 * Sent only while running Setup Wizard, in lieu of showing a user
271 * notification.
272 * @hide
273 */
Jeff Sharkey4fa63b22013-02-20 18:21:19 -0800274 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
Russell Brenner108da0c2013-02-12 10:03:14 -0800275 public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED =
276 "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED";
277 /**
278 * The lookup key for a boolean that indicates whether a captive portal was detected.
279 * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
280 * @hide
281 */
282 public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal";
283
284 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800285 * The absence of a connection type.
Robert Greenwaltccf83af12011-06-02 17:30:47 -0700286 * @hide
287 */
288 public static final int TYPE_NONE = -1;
289
290 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800291 * The Mobile data connection. When active, all data traffic
292 * will use this network type's interface by default
293 * (it has a default route)
Robert Greenwalt42acef32009-08-12 16:08:25 -0700294 */
295 public static final int TYPE_MOBILE = 0;
296 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800297 * The WIFI data connection. When active, all data traffic
298 * will use this network type's interface by default
299 * (it has a default route).
Robert Greenwalt42acef32009-08-12 16:08:25 -0700300 */
301 public static final int TYPE_WIFI = 1;
302 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800303 * An MMS-specific Mobile data connection. This network type may use the
304 * same network interface as {@link #TYPE_MOBILE} or it may use a different
305 * one. This is used by applications needing to talk to the carrier's
306 * Multimedia Messaging Service servers.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700307 */
308 public static final int TYPE_MOBILE_MMS = 2;
309 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800310 * A SUPL-specific Mobile data connection. This network type may use the
311 * same network interface as {@link #TYPE_MOBILE} or it may use a different
312 * one. This is used by applications needing to talk to the carrier's
313 * Secure User Plane Location servers for help locating the device.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700314 */
315 public static final int TYPE_MOBILE_SUPL = 3;
316 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800317 * A DUN-specific Mobile data connection. This network type may use the
318 * same network interface as {@link #TYPE_MOBILE} or it may use a different
319 * one. This is sometimes by the system when setting up an upstream connection
320 * for tethering so that the carrier is aware of DUN traffic.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700321 */
322 public static final int TYPE_MOBILE_DUN = 4;
323 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800324 * A High Priority Mobile data connection. This network type uses the
325 * same network interface as {@link #TYPE_MOBILE} but the routing setup
326 * is different. Only requesting processes will have access to the
327 * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost}
328 * will route over this interface if no default route exists.
Robert Greenwalt42acef32009-08-12 16:08:25 -0700329 */
330 public static final int TYPE_MOBILE_HIPRI = 5;
jsh8214deb2010-03-11 15:04:43 -0800331 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800332 * The WiMAX data connection. When active, all data traffic
333 * will use this network type's interface by default
334 * (it has a default route).
jsh8214deb2010-03-11 15:04:43 -0800335 */
336 public static final int TYPE_WIMAX = 6;
Robert Greenwaltda3d5e62010-12-06 13:56:24 -0800337
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800338 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800339 * The Bluetooth data connection. When active, all data traffic
340 * will use this network type's interface by default
341 * (it has a default route).
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800342 */
343 public static final int TYPE_BLUETOOTH = 7;
344
Robert Greenwalt60810842011-04-22 15:28:18 -0700345 /**
346 * Dummy data connection. This should not be used on shipping devices.
347 */
Jaikumar Ganesh15c74392010-12-21 22:31:44 -0800348 public static final int TYPE_DUMMY = 8;
Wink Saville9d7d6282011-03-12 14:52:01 -0800349
Robert Greenwalt60810842011-04-22 15:28:18 -0700350 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800351 * The Ethernet data connection. When active, all data traffic
352 * will use this network type's interface by default
353 * (it has a default route).
Robert Greenwalt60810842011-04-22 15:28:18 -0700354 */
Robert Greenwalte12aec92011-01-28 14:48:37 -0800355 public static final int TYPE_ETHERNET = 9;
Robert Greenwalt60810842011-04-22 15:28:18 -0700356
Wink Saville9d7d6282011-03-12 14:52:01 -0800357 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800358 * Over the air Administration.
Wink Saville9d7d6282011-03-12 14:52:01 -0800359 * {@hide}
360 */
361 public static final int TYPE_MOBILE_FOTA = 10;
362
363 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800364 * IP Multimedia Subsystem.
Wink Saville9d7d6282011-03-12 14:52:01 -0800365 * {@hide}
366 */
367 public static final int TYPE_MOBILE_IMS = 11;
368
369 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800370 * Carrier Branded Services.
Wink Saville9d7d6282011-03-12 14:52:01 -0800371 * {@hide}
372 */
373 public static final int TYPE_MOBILE_CBS = 12;
374
repo syncaea743a2011-07-29 23:55:49 -0700375 /**
376 * A Wi-Fi p2p connection. Only requesting processes will have access to
377 * the peers connected.
378 * {@hide}
379 */
380 public static final int TYPE_WIFI_P2P = 13;
Wink Saville9d7d6282011-03-12 14:52:01 -0800381
Wink Saville5e56bc52013-07-29 15:00:57 -0700382 /**
383 * The network to use for initially attaching to the network
384 * {@hide}
385 */
386 public static final int TYPE_MOBILE_IA = 14;
repo syncaea743a2011-07-29 23:55:49 -0700387
Hui Lu1c5624a2014-01-15 11:05:36 -0500388 /**
389 * The network that uses proxy to achieve connectivity.
390 * {@hide}
391 */
392 public static final int TYPE_PROXY = 16;
Wink Saville5e56bc52013-07-29 15:00:57 -0700393
394 /** {@hide} */
Hui Lu1c5624a2014-01-15 11:05:36 -0500395 public static final int MAX_RADIO_TYPE = TYPE_PROXY;
396
397 /** {@hide} */
398 public static final int MAX_NETWORK_TYPE = TYPE_PROXY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800400 /**
401 * If you want to set the default network preference,you can directly
402 * change the networkAttributes array in framework's config.xml.
403 *
404 * @deprecated Since we support so many more networks now, the single
405 * network default network preference can't really express
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800406 * the hierarchy. Instead, the default is defined by the
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800407 * networkAttributes in config.xml. You can determine
Robert Greenwalt4c8b7482012-12-07 09:56:50 -0800408 * the current value by calling {@link #getNetworkPreference()}
Jianzheng Zhoudcf03f32012-11-16 13:45:20 +0800409 * from an App.
410 */
411 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
413
Jeff Sharkey625239a2012-09-26 22:03:49 -0700414 /**
415 * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800416 * milliseconds. This was introduced because IPv6 routes seem to take a
417 * moment to settle - trying network activity before the routes are adjusted
418 * can lead to packets using the wrong interface or having the wrong IP address.
419 * This delay is a bit crude, but in the future hopefully we will have kernel
420 * notifications letting us know when it's safe to use the new network.
Jeff Sharkey625239a2012-09-26 22:03:49 -0700421 *
422 * @hide
423 */
424 public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
425
Robert Greenwalt9ba9c582014-03-19 17:56:12 -0700426 /**
427 * @hide
428 */
429 public final static int INVALID_NET_ID = 0;
430
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700431 private final IConnectivityManager mService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432
Chad Brubakerf81daa92014-02-14 13:22:34 -0800433 private final String mPackageName;
434
Dianne Hackborn77b987f2014-02-26 16:20:52 -0800435 private INetworkManagementService mNMService;
436
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800437 /**
438 * Tests if a given integer represents a valid network type.
439 * @param networkType the type to be tested
440 * @return a boolean. {@code true} if the type is valid, else {@code false}
441 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700442 public static boolean isNetworkTypeValid(int networkType) {
Robert Greenwalt42acef32009-08-12 16:08:25 -0700443 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800446 /**
447 * Returns a non-localized string representing a given network type.
448 * ONLY used for debugging output.
449 * @param type the type needing naming
450 * @return a String for the given type, or a string version of the type ("87")
451 * if no name is known.
452 * {@hide}
453 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700454 public static String getNetworkTypeName(int type) {
455 switch (type) {
456 case TYPE_MOBILE:
457 return "MOBILE";
458 case TYPE_WIFI:
459 return "WIFI";
460 case TYPE_MOBILE_MMS:
461 return "MOBILE_MMS";
462 case TYPE_MOBILE_SUPL:
463 return "MOBILE_SUPL";
464 case TYPE_MOBILE_DUN:
465 return "MOBILE_DUN";
466 case TYPE_MOBILE_HIPRI:
467 return "MOBILE_HIPRI";
468 case TYPE_WIMAX:
469 return "WIMAX";
470 case TYPE_BLUETOOTH:
471 return "BLUETOOTH";
472 case TYPE_DUMMY:
473 return "DUMMY";
474 case TYPE_ETHERNET:
475 return "ETHERNET";
476 case TYPE_MOBILE_FOTA:
477 return "MOBILE_FOTA";
478 case TYPE_MOBILE_IMS:
479 return "MOBILE_IMS";
480 case TYPE_MOBILE_CBS:
481 return "MOBILE_CBS";
repo syncaea743a2011-07-29 23:55:49 -0700482 case TYPE_WIFI_P2P:
483 return "WIFI_P2P";
Wink Saville5e56bc52013-07-29 15:00:57 -0700484 case TYPE_MOBILE_IA:
485 return "MOBILE_IA";
Hui Lu1c5624a2014-01-15 11:05:36 -0500486 case TYPE_PROXY:
487 return "PROXY";
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700488 default:
489 return Integer.toString(type);
490 }
491 }
492
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800493 /**
494 * Checks if a given type uses the cellular data connection.
495 * This should be replaced in the future by a network property.
496 * @param networkType the type to check
497 * @return a boolean - {@code true} if uses cellular network, else {@code false}
498 * {@hide}
499 */
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700500 public static boolean isNetworkTypeMobile(int networkType) {
501 switch (networkType) {
502 case TYPE_MOBILE:
503 case TYPE_MOBILE_MMS:
504 case TYPE_MOBILE_SUPL:
505 case TYPE_MOBILE_DUN:
506 case TYPE_MOBILE_HIPRI:
507 case TYPE_MOBILE_FOTA:
508 case TYPE_MOBILE_IMS:
509 case TYPE_MOBILE_CBS:
Wink Saville5e56bc52013-07-29 15:00:57 -0700510 case TYPE_MOBILE_IA:
Jeff Sharkeyd2a45872011-05-28 20:56:34 -0700511 return true;
512 default:
513 return false;
514 }
515 }
516
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800517 /**
Jeff Sharkey7a1c3fc2013-06-04 12:29:00 -0700518 * Checks if the given network type is backed by a Wi-Fi radio.
519 *
520 * @hide
521 */
522 public static boolean isNetworkTypeWifi(int networkType) {
523 switch (networkType) {
524 case TYPE_WIFI:
525 case TYPE_WIFI_P2P:
526 return true;
527 default:
528 return false;
529 }
530 }
531
532 /**
Chad Brubakerf336d722013-07-15 16:34:04 -0700533 * Checks if the given network type should be exempt from VPN routing rules
534 *
535 * @hide
536 */
537 public static boolean isNetworkTypeExempt(int networkType) {
538 switch (networkType) {
539 case TYPE_MOBILE_MMS:
540 case TYPE_MOBILE_SUPL:
541 case TYPE_MOBILE_HIPRI:
Wink Saville5e56bc52013-07-29 15:00:57 -0700542 case TYPE_MOBILE_IA:
Chad Brubakerf336d722013-07-15 16:34:04 -0700543 return true;
544 default:
545 return false;
546 }
547 }
548
549 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800550 * Specifies the preferred network type. When the device has more
551 * than one type available the preferred network type will be used.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800552 *
553 * @param preference the network type to prefer over all others. It is
554 * unspecified what happens to the old preferred network in the
555 * overall ordering.
Robert Greenwaltd19c41c2014-05-18 23:07: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 void setNetworkPreference(int preference) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
563
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800564 /**
565 * Retrieves the current preferred network type.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800566 *
567 * @return an integer representing the preferred network type
568 *
569 * <p>This method requires the caller to hold the permission
570 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700571 * @deprecated Functionality has been removed as it no longer makes sense,
572 * with many more than two networks - we'd need an array to express
573 * preference. Instead we use dynamic network properties of
574 * the networks to describe their precedence.
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800575 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 public int getNetworkPreference() {
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700577 return TYPE_NONE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
Scott Main671644c2011-10-06 19:02:28 -0700580 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800581 * Returns details about the currently active default data network. When
582 * connected, this network is the default route for outgoing connections.
583 * You should always check {@link NetworkInfo#isConnected()} before initiating
584 * network traffic. This may return {@code null} when there is no default
585 * network.
586 *
587 * @return a {@link NetworkInfo} object for the current default network
588 * or {@code null} if no network default network is currently active
589 *
590 * <p>This method requires the call to hold the permission
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700591 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -0700592 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 public NetworkInfo getActiveNetworkInfo() {
594 try {
595 return mService.getActiveNetworkInfo();
596 } catch (RemoteException e) {
597 return null;
598 }
599 }
600
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800601 /**
602 * Returns details about the currently active default data network
603 * for a given uid. This is for internal use only to avoid spying
604 * other apps.
605 *
606 * @return a {@link NetworkInfo} object for the current default network
607 * for the given uid or {@code null} if no default network is
608 * available for the specified uid.
609 *
610 * <p>This method requires the caller to hold the permission
611 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
612 * {@hide}
613 */
Jeff Sharkeyc006f1a2011-05-19 17:12:49 -0700614 public NetworkInfo getActiveNetworkInfoForUid(int uid) {
615 try {
616 return mService.getActiveNetworkInfoForUid(uid);
617 } catch (RemoteException e) {
618 return null;
619 }
620 }
621
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800622 /**
623 * Returns connection status information about a particular
624 * network type.
625 *
626 * @param networkType integer specifying which networkType in
627 * which you're interested.
628 * @return a {@link NetworkInfo} object for the requested
629 * network type or {@code null} if the type is not
630 * supported by the device.
631 *
632 * <p>This method requires the call to hold the permission
633 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
634 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 public NetworkInfo getNetworkInfo(int networkType) {
636 try {
637 return mService.getNetworkInfo(networkType);
638 } catch (RemoteException e) {
639 return null;
640 }
641 }
642
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800643 /**
644 * Returns connection status information about all network
645 * types supported by the device.
646 *
647 * @return an array of {@link NetworkInfo} objects. Check each
648 * {@link NetworkInfo#getType} for which type each applies.
649 *
650 * <p>This method requires the call to hold the permission
651 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
652 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 public NetworkInfo[] getAllNetworkInfo() {
654 try {
655 return mService.getAllNetworkInfo();
656 } catch (RemoteException e) {
657 return null;
658 }
659 }
660
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800661 /**
Wink Saville948282b2013-08-29 08:55:16 -0700662 * Returns details about the Provisioning or currently active default data network. When
663 * connected, this network is the default route for outgoing connections.
664 * You should always check {@link NetworkInfo#isConnected()} before initiating
665 * network traffic. This may return {@code null} when there is no default
666 * network.
667 *
668 * @return a {@link NetworkInfo} object for the current default network
669 * or {@code null} if no network default network is currently active
670 *
671 * <p>This method requires the call to hold the permission
672 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
673 *
674 * {@hide}
675 */
676 public NetworkInfo getProvisioningOrActiveNetworkInfo() {
677 try {
678 return mService.getProvisioningOrActiveNetworkInfo();
679 } catch (RemoteException e) {
680 return null;
681 }
682 }
683
684 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800685 * Returns the IP information for the current default network.
686 *
687 * @return a {@link LinkProperties} object describing the IP info
688 * for the current default network, or {@code null} if there
689 * is no current default network.
690 *
691 * <p>This method requires the call to hold the permission
692 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
693 * {@hide}
694 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700695 public LinkProperties getActiveLinkProperties() {
696 try {
697 return mService.getActiveLinkProperties();
698 } catch (RemoteException e) {
699 return null;
700 }
701 }
702
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800703 /**
704 * Returns the IP information for a given network type.
705 *
706 * @param networkType the network type of interest.
707 * @return a {@link LinkProperties} object describing the IP info
708 * for the given networkType, or {@code null} if there is
709 * no current default network.
710 *
711 * <p>This method requires the call to hold the permission
712 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
713 * {@hide}
714 */
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700715 public LinkProperties getLinkProperties(int networkType) {
716 try {
Robert Greenwalt9258c642014-03-26 16:47:06 -0700717 return mService.getLinkPropertiesForType(networkType);
718 } catch (RemoteException e) {
719 return null;
720 }
721 }
722
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700723 /**
724 * Get the {@link LinkProperties} for the given {@link Network}. This
725 * will return {@code null} if the network is unknown.
726 *
727 * @param network The {@link Network} object identifying the network in question.
728 * @return The {@link LinkProperties} for the network, or {@code null}.
729 **/
Robert Greenwalt9258c642014-03-26 16:47:06 -0700730 public LinkProperties getLinkProperties(Network network) {
731 try {
732 return mService.getLinkProperties(network);
733 } catch (RemoteException e) {
734 return null;
735 }
736 }
737
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700738 /**
739 * Get the {@link NetworkCapabilities} for the given {@link Network}. This
740 * will return {@code null} if the network is unknown.
741 *
742 * @param network The {@link Network} object identifying the network in question.
743 * @return The {@link NetworkCapabilities} for the network, or {@code null}.
744 */
Robert Greenwalt9258c642014-03-26 16:47:06 -0700745 public NetworkCapabilities getNetworkCapabilities(Network network) {
746 try {
747 return mService.getNetworkCapabilities(network);
Robert Greenwaltd192dad2010-09-14 09:18:02 -0700748 } catch (RemoteException e) {
749 return null;
750 }
751 }
752
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800753 /**
754 * Tells each network type to set its radio power state as directed.
755 *
756 * @param turnOn a boolean, {@code true} to turn the radios on,
757 * {@code false} to turn them off.
758 * @return a boolean, {@code true} indicating success. All network types
759 * will be tried, even if some fail.
760 *
761 * <p>This method requires the call to hold the permission
762 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
763 * {@hide}
764 */
Robert Greenwalt7b816022014-04-18 15:25:25 -0700765// TODO - check for any callers and remove
766// public boolean setRadios(boolean turnOn) {
767// try {
768// return mService.setRadios(turnOn);
769// } catch (RemoteException e) {
770// return false;
771// }
772// }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -0800774 /**
775 * Tells a given networkType to set its radio power state as directed.
776 *
777 * @param networkType the int networkType of interest.
778 * @param turnOn a boolean, {@code true} to turn the radio on,
779 * {@code} false to turn it off.
780 * @return a boolean, {@code true} indicating success.
781 *
782 * <p>This method requires the call to hold the permission
783 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
784 * {@hide}
785 */
Robert Greenwalt7b816022014-04-18 15:25:25 -0700786// TODO - check for any callers and remove
787// public boolean setRadio(int networkType, boolean turnOn) {
788// try {
789// return mService.setRadio(networkType, turnOn);
790// } catch (RemoteException e) {
791// return false;
792// }
793// }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794
795 /**
796 * Tells the underlying networking system that the caller wants to
797 * begin using the named feature. The interpretation of {@code feature}
798 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700799 * <p>This method requires the caller to hold the permission
800 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 * @param networkType specifies which network the request pertains to
802 * @param feature the name of the feature to be used
803 * @return an integer value representing the outcome of the request.
804 * The interpretation of this value is specific to each networking
805 * implementation+feature combination, except that the value {@code -1}
806 * always indicates failure.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700807 *
808 * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 */
810 public int startUsingNetworkFeature(int networkType, String feature) {
Robert Greenwalt71bf33a2014-05-15 18:07:26 -0700811 NetworkCapabilities netCap = networkCapabilitiesForFeature(networkType, feature);
812 if (netCap == null) {
813 Log.d(TAG, "Can't satisfy startUsingNetworkFeature for " + networkType + ", " +
814 feature);
815 return PhoneConstants.APN_REQUEST_FAILED;
816 }
817
818 NetworkRequest request = null;
819 synchronized (sLegacyRequests) {
820 LegacyRequest l = sLegacyRequests.get(netCap);
821 if (l != null) {
822 Log.d(TAG, "renewing startUsingNetworkFeature request " + l.networkRequest);
823 renewRequestLocked(l);
824 if (l.currentNetwork != null) {
825 return PhoneConstants.APN_ALREADY_ACTIVE;
826 } else {
827 return PhoneConstants.APN_REQUEST_STARTED;
828 }
829 }
830
831 request = requestNetworkForFeatureLocked(netCap);
832 }
833 if (request != null) {
834 Log.d(TAG, "starting startUsingNeworkFeature for request " + request);
835 return PhoneConstants.APN_REQUEST_STARTED;
836 } else {
837 Log.d(TAG, " request Failed");
838 return PhoneConstants.APN_REQUEST_FAILED;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840 }
841
842 /**
843 * Tells the underlying networking system that the caller is finished
844 * using the named feature. The interpretation of {@code feature}
845 * is completely up to each networking implementation.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700846 * <p>This method requires the caller to hold the permission
847 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 * @param networkType specifies which network the request pertains to
849 * @param feature the name of the feature that is no longer needed
850 * @return an integer value representing the outcome of the request.
851 * The interpretation of this value is specific to each networking
852 * implementation+feature combination, except that the value {@code -1}
853 * always indicates failure.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -0700854 *
855 * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 */
857 public int stopUsingNetworkFeature(int networkType, String feature) {
Robert Greenwalt71bf33a2014-05-15 18:07:26 -0700858 NetworkCapabilities netCap = networkCapabilitiesForFeature(networkType, feature);
859 if (netCap == null) {
860 Log.d(TAG, "Can't satisfy stopUsingNetworkFeature for " + networkType + ", " +
861 feature);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 return -1;
863 }
Robert Greenwalt71bf33a2014-05-15 18:07:26 -0700864
865 NetworkRequest request = removeRequestForFeature(netCap);
866 if (request != null) {
867 Log.d(TAG, "stopUsingNetworkFeature for " + networkType + ", " + feature);
868 releaseNetworkRequest(request);
869 }
870 return 1;
871 }
872
873 private NetworkCapabilities networkCapabilitiesForFeature(int networkType, String feature) {
874 if (networkType == TYPE_MOBILE) {
875 int cap = -1;
876 if ("enableMMS".equals(feature)) {
877 cap = NetworkCapabilities.NET_CAPABILITY_MMS;
878 } else if ("enableSUPL".equals(feature)) {
879 cap = NetworkCapabilities.NET_CAPABILITY_SUPL;
880 } else if ("enableDUN".equals(feature) || "enableDUNAlways".equals(feature)) {
881 cap = NetworkCapabilities.NET_CAPABILITY_DUN;
882 } else if ("enableHIPRI".equals(feature)) {
883 cap = NetworkCapabilities.NET_CAPABILITY_INTERNET;
884 } else if ("enableFOTA".equals(feature)) {
885 cap = NetworkCapabilities.NET_CAPABILITY_FOTA;
886 } else if ("enableIMS".equals(feature)) {
887 cap = NetworkCapabilities.NET_CAPABILITY_IMS;
888 } else if ("enableCBS".equals(feature)) {
889 cap = NetworkCapabilities.NET_CAPABILITY_CBS;
890 } else {
891 return null;
892 }
893 NetworkCapabilities netCap = new NetworkCapabilities();
894 netCap.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
895 netCap.addNetworkCapability(cap);
896 return netCap;
897 } else if (networkType == TYPE_WIFI) {
898 if ("p2p".equals(feature)) {
899 NetworkCapabilities netCap = new NetworkCapabilities();
900 netCap.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
901 netCap.addNetworkCapability(NetworkCapabilities.NET_CAPABILITY_WIFI_P2P);
902 return netCap;
903 }
904 }
905 return null;
906 }
907
908 private int networkTypeForNetworkCapabilities(NetworkCapabilities netCap) {
909 if (netCap == null) return TYPE_NONE;
910 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_CBS)) {
911 return TYPE_MOBILE_CBS;
912 }
913 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)) {
914 return TYPE_MOBILE_IMS;
915 }
916 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOTA)) {
917 return TYPE_MOBILE_FOTA;
918 }
919 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) {
920 return TYPE_MOBILE_DUN;
921 }
922 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_SUPL)) {
923 return TYPE_MOBILE_SUPL;
924 }
925 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_MMS)) {
926 return TYPE_MOBILE_MMS;
927 }
928 if (netCap.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
929 return TYPE_MOBILE_HIPRI;
930 }
931 return TYPE_NONE;
932 }
933
934 private static class LegacyRequest {
935 NetworkCapabilities networkCapabilities;
936 NetworkRequest networkRequest;
937 int expireSequenceNumber;
938 Network currentNetwork;
939 int delay = -1;
940 NetworkCallbackListener networkCallbackListener = new NetworkCallbackListener() {
941 @Override
942 public void onAvailable(NetworkRequest request, Network network) {
943 currentNetwork = network;
944 Log.d(TAG, "startUsingNetworkFeature got Network:" + network);
945 network.bindProcessForHostResolution();
946 }
947 @Override
948 public void onLost(NetworkRequest request, Network network) {
949 if (network.equals(currentNetwork)) {
950 currentNetwork = null;
951 network.unbindProcessForHostResolution();
952 }
953 Log.d(TAG, "startUsingNetworkFeature lost Network:" + network);
954 }
955 };
956 }
957
958 private HashMap<NetworkCapabilities, LegacyRequest> sLegacyRequests =
959 new HashMap<NetworkCapabilities, LegacyRequest>();
960
961 private NetworkRequest findRequestForFeature(NetworkCapabilities netCap) {
962 synchronized (sLegacyRequests) {
963 LegacyRequest l = sLegacyRequests.get(netCap);
964 if (l != null) return l.networkRequest;
965 }
966 return null;
967 }
968
969 private void renewRequestLocked(LegacyRequest l) {
970 l.expireSequenceNumber++;
971 Log.d(TAG, "renewing request to seqNum " + l.expireSequenceNumber);
972 sendExpireMsgForFeature(l.networkCapabilities, l.expireSequenceNumber, l.delay);
973 }
974
975 private void expireRequest(NetworkCapabilities netCap, int sequenceNum) {
976 int ourSeqNum = -1;
977 synchronized (sLegacyRequests) {
978 LegacyRequest l = sLegacyRequests.get(netCap);
979 if (l == null) return;
980 ourSeqNum = l.expireSequenceNumber;
981 if (l.expireSequenceNumber == sequenceNum) {
982 releaseNetworkRequest(l.networkRequest);
983 sLegacyRequests.remove(netCap);
984 }
985 }
986 Log.d(TAG, "expireRequest with " + ourSeqNum + ", " + sequenceNum);
987 }
988
989 private NetworkRequest requestNetworkForFeatureLocked(NetworkCapabilities netCap) {
990 int delay = -1;
991 int type = networkTypeForNetworkCapabilities(netCap);
992 try {
993 delay = mService.getRestoreDefaultNetworkDelay(type);
994 } catch (RemoteException e) {}
995 LegacyRequest l = new LegacyRequest();
996 l.networkCapabilities = netCap;
997 l.delay = delay;
998 l.expireSequenceNumber = 0;
999 l.networkRequest = sendRequestForNetwork(netCap, l.networkCallbackListener, 0,
1000 REQUEST, true);
1001 if (l.networkRequest == null) return null;
1002 sLegacyRequests.put(netCap, l);
1003 sendExpireMsgForFeature(netCap, l.expireSequenceNumber, delay);
1004 return l.networkRequest;
1005 }
1006
1007 private void sendExpireMsgForFeature(NetworkCapabilities netCap, int seqNum, int delay) {
1008 if (delay >= 0) {
1009 Log.d(TAG, "sending expire msg with seqNum " + seqNum + " and delay " + delay);
1010 Message msg = sCallbackHandler.obtainMessage(EXPIRE_LEGACY_REQUEST, seqNum, 0, netCap);
1011 sCallbackHandler.sendMessageDelayed(msg, delay);
1012 }
1013 }
1014
1015 private NetworkRequest removeRequestForFeature(NetworkCapabilities netCap) {
1016 synchronized (sLegacyRequests) {
1017 LegacyRequest l = sLegacyRequests.remove(netCap);
1018 if (l == null) return null;
1019 return l.networkRequest;
1020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 }
1022
1023 /**
1024 * Ensure that a network route exists to deliver traffic to the specified
1025 * host via the specified network interface. An attempt to add a route that
1026 * already exists is ignored, but treated as successful.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001027 * <p>This method requires the caller to hold the permission
1028 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001029 * @param networkType the type of the network over which traffic to the specified
1030 * host is to be routed
1031 * @param hostAddress the IP address of the host to which the route is desired
1032 * @return {@code true} on success, {@code false} on failure
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001033 *
1034 * @deprecated Deprecated in favor of the {@link #requestNetwork},
1035 * {@link Network#bindProcess} and {@link Network#socketFactory} api.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 */
1037 public boolean requestRouteToHost(int networkType, int hostAddress) {
Robert Greenwalt585ac0f2010-08-27 09:24:29 -07001038 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
1039
1040 if (inetAddress == null) {
1041 return false;
1042 }
1043
1044 return requestRouteToHostAddress(networkType, inetAddress);
1045 }
1046
1047 /**
1048 * Ensure that a network route exists to deliver traffic to the specified
1049 * host via the specified network interface. An attempt to add a route that
1050 * already exists is ignored, but treated as successful.
Jake Hamby8f9b33e2014-01-15 13:08:03 -08001051 * <p>This method requires the caller to hold the permission
1052 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt585ac0f2010-08-27 09:24:29 -07001053 * @param networkType the type of the network over which traffic to the specified
1054 * host is to be routed
1055 * @param hostAddress the IP address of the host to which the route is desired
1056 * @return {@code true} on success, {@code false} on failure
1057 * @hide
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001058 * @deprecated Deprecated in favor of the {@link #requestNetwork} and
1059 * {@link Network#bindProcess} api.
Robert Greenwalt585ac0f2010-08-27 09:24:29 -07001060 */
1061 public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
1062 byte[] address = hostAddress.getAddress();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 try {
Chad Brubakerf81daa92014-02-14 13:22:34 -08001064 return mService.requestRouteToHostAddress(networkType, address, mPackageName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 } catch (RemoteException e) {
1066 return false;
1067 }
1068 }
1069
1070 /**
1071 * Returns the value of the setting for background data usage. If false,
1072 * applications should not use the network if the application is not in the
1073 * foreground. Developers should respect this setting, and check the value
1074 * of this before performing any background data operations.
1075 * <p>
1076 * All applications that have background services that use the network
1077 * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001078 * <p>
Scott Main4cc53332011-10-06 18:32:43 -07001079 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001080 * background data depends on several combined factors, and this method will
1081 * always return {@code true}. Instead, when background data is unavailable,
1082 * {@link #getActiveNetworkInfo()} will now appear disconnected.
Danica Chang6fdd0c62010-08-11 14:54:43 -07001083 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 * @return Whether background data usage is allowed.
1085 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001086 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 public boolean getBackgroundDataSetting() {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001088 // assume that background data is allowed; final authority is
1089 // NetworkInfo which may be blocked.
1090 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092
1093 /**
1094 * Sets the value of the setting for background data usage.
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001095 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 * @param allowBackgroundData Whether an application should use data while
1097 * it is in the background.
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001098 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
1100 * @see #getBackgroundDataSetting()
1101 * @hide
1102 */
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001103 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 public void setBackgroundDataSetting(boolean allowBackgroundData) {
Jeff Sharkey3a844fc2011-08-16 14:37:57 -07001105 // ignored
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001107
1108 /**
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -07001109 * Return quota status for the current active network, or {@code null} if no
1110 * network is active. Quota status can change rapidly, so these values
1111 * shouldn't be cached.
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -07001112 *
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001113 * <p>This method requires the call to hold the permission
1114 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
1115 *
Jeff Sharkey44a3e0d2011-10-06 10:50:09 -07001116 * @hide
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -07001117 */
1118 public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
1119 try {
1120 return mService.getActiveNetworkQuotaInfo();
1121 } catch (RemoteException e) {
1122 return null;
1123 }
1124 }
1125
1126 /**
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001127 * @hide
Robert Greenwalt47eecf02014-05-21 20:04:36 -07001128 * @deprecated Talk to TelephonyManager directly
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001129 */
1130 public boolean getMobileDataEnabled() {
Robert Greenwalt47eecf02014-05-21 20:04:36 -07001131 IBinder b = ServiceManager.getService(Context.TELEPHONY_SERVICE);
1132 if (b != null) {
1133 try {
1134 ITelephony it = ITelephony.Stub.asInterface(b);
1135 return it.getDataEnabled();
1136 } catch (RemoteException e) { }
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001137 }
Robert Greenwalt47eecf02014-05-21 20:04:36 -07001138 return false;
Robert Greenwaltc03fa502010-02-23 18:58:05 -08001139 }
1140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 /**
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001142 * Callback for use with {@link ConnectivityManager#registerNetworkActiveListener} to
1143 * find out when the current network has gone in to a high power state.
1144 */
1145 public interface OnNetworkActiveListener {
1146 /**
1147 * Called on the main thread of the process to report that the current data network
1148 * has become active, and it is now a good time to perform any pending network
1149 * operations. Note that this listener only tells you when the network becomes
1150 * active; if at any other time you want to know whether it is active (and thus okay
1151 * to initiate network traffic), you can retrieve its instantaneous state with
1152 * {@link ConnectivityManager#isNetworkActive}.
1153 */
1154 public void onNetworkActive();
1155 }
1156
1157 private INetworkManagementService getNetworkManagementService() {
1158 synchronized (this) {
1159 if (mNMService != null) {
1160 return mNMService;
1161 }
1162 IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
1163 mNMService = INetworkManagementService.Stub.asInterface(b);
1164 return mNMService;
1165 }
1166 }
1167
1168 private final ArrayMap<OnNetworkActiveListener, INetworkActivityListener>
1169 mNetworkActivityListeners
1170 = new ArrayMap<OnNetworkActiveListener, INetworkActivityListener>();
1171
1172 /**
1173 * Start listening to reports when the data network is active, meaning it is
1174 * a good time to perform network traffic. Use {@link #isNetworkActive()}
1175 * to determine the current state of the network after registering the listener.
1176 *
1177 * @param l The listener to be told when the network is active.
1178 */
1179 public void registerNetworkActiveListener(final OnNetworkActiveListener l) {
1180 INetworkActivityListener rl = new INetworkActivityListener.Stub() {
1181 @Override
1182 public void onNetworkActive() throws RemoteException {
1183 l.onNetworkActive();
1184 }
1185 };
1186
1187 try {
1188 getNetworkManagementService().registerNetworkActivityListener(rl);
1189 mNetworkActivityListeners.put(l, rl);
1190 } catch (RemoteException e) {
1191 }
1192 }
1193
1194 /**
1195 * Remove network active listener previously registered with
1196 * {@link #registerNetworkActiveListener}.
1197 *
1198 * @param l Previously registered listener.
1199 */
1200 public void unregisterNetworkActiveListener(OnNetworkActiveListener l) {
1201 INetworkActivityListener rl = mNetworkActivityListeners.get(l);
1202 if (rl == null) {
1203 throw new IllegalArgumentException("Listener not registered: " + l);
1204 }
1205 try {
1206 getNetworkManagementService().unregisterNetworkActivityListener(rl);
1207 } catch (RemoteException e) {
1208 }
1209 }
1210
1211 /**
1212 * Return whether the data network is currently active. An active network means that
1213 * it is currently in a high power state for performing data transmission. On some
1214 * types of networks, it may be expensive to move and stay in such a state, so it is
1215 * more power efficient to batch network traffic together when the radio is already in
1216 * this state. This method tells you whether right now is currently a good time to
1217 * initiate network traffic, as the network is already active.
1218 */
1219 public boolean isNetworkActive() {
1220 try {
1221 return getNetworkManagementService().isNetworkActive();
1222 } catch (RemoteException e) {
1223 }
1224 return false;
1225 }
1226
1227 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 * {@hide}
1229 */
Chad Brubakerf81daa92014-02-14 13:22:34 -08001230 public ConnectivityManager(IConnectivityManager service, String packageName) {
Jeff Sharkeyf0ceede2011-08-02 17:22:34 -07001231 mService = checkNotNull(service, "missing IConnectivityManager");
Chad Brubakerf81daa92014-02-14 13:22:34 -08001232 mPackageName = checkNotNull(packageName, "missing package name");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 }
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001234
Jeff Sharkey8fc27e82012-04-04 20:40:58 -07001235 /** {@hide} */
1236 public static ConnectivityManager from(Context context) {
1237 return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
1238 }
1239
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001240 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001241 * Get the set of tetherable, available interfaces. This list is limited by
1242 * device configuration and current interface existence.
1243 *
1244 * @return an array of 0 or more Strings of tetherable interface names.
1245 *
1246 * <p>This method requires the call to hold the permission
1247 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001248 * {@hide}
1249 */
1250 public String[] getTetherableIfaces() {
1251 try {
1252 return mService.getTetherableIfaces();
1253 } catch (RemoteException e) {
1254 return new String[0];
1255 }
1256 }
1257
1258 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001259 * Get the set of tethered interfaces.
1260 *
1261 * @return an array of 0 or more String of currently tethered interface names.
1262 *
1263 * <p>This method requires the call to hold the permission
1264 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001265 * {@hide}
1266 */
1267 public String[] getTetheredIfaces() {
1268 try {
1269 return mService.getTetheredIfaces();
1270 } catch (RemoteException e) {
1271 return new String[0];
1272 }
1273 }
1274
1275 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001276 * Get the set of interface names which attempted to tether but
1277 * failed. Re-attempting to tether may cause them to reset to the Tethered
1278 * state. Alternatively, causing the interface to be destroyed and recreated
1279 * may cause them to reset to the available state.
1280 * {@link ConnectivityManager#getLastTetherError} can be used to get more
1281 * information on the cause of the errors.
1282 *
1283 * @return an array of 0 or more String indicating the interface names
1284 * which failed to tether.
1285 *
1286 * <p>This method requires the call to hold the permission
1287 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001288 * {@hide}
1289 */
Robert Greenwalt5a735062010-03-02 17:25:02 -08001290 public String[] getTetheringErroredIfaces() {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001291 try {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001292 return mService.getTetheringErroredIfaces();
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001293 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001294 return new String[0];
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001295 }
1296 }
1297
1298 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001299 * Attempt to tether the named interface. This will setup a dhcp server
1300 * on the interface, forward and NAT IP packets and forward DNS requests
1301 * to the best active upstream network interface. Note that if no upstream
1302 * IP network interface is available, dhcp will still run and traffic will be
1303 * allowed between the tethered devices and this device, though upstream net
1304 * access will of course fail until an upstream network interface becomes
1305 * active.
1306 *
1307 * @param iface the interface name to tether.
1308 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1309 *
1310 * <p>This method requires the call to hold the permission
1311 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001312 * {@hide}
1313 */
Robert Greenwalt5a735062010-03-02 17:25:02 -08001314 public int tether(String iface) {
1315 try {
1316 return mService.tether(iface);
1317 } catch (RemoteException e) {
1318 return TETHER_ERROR_SERVICE_UNAVAIL;
1319 }
1320 }
1321
1322 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001323 * Stop tethering the named interface.
1324 *
1325 * @param iface the interface name to untether.
1326 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1327 *
1328 * <p>This method requires the call to hold the permission
1329 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -08001330 * {@hide}
1331 */
1332 public int untether(String iface) {
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001333 try {
1334 return mService.untether(iface);
1335 } catch (RemoteException e) {
Robert Greenwalt5a735062010-03-02 17:25:02 -08001336 return TETHER_ERROR_SERVICE_UNAVAIL;
Robert Greenwaltd0e18ff2010-01-26 11:40:34 -08001337 }
1338 }
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001339
1340 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001341 * Check if the device allows for tethering. It may be disabled via
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001342 * {@code ro.tether.denied} system property, Settings.TETHER_SUPPORTED or
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001343 * due to device configuration.
1344 *
1345 * @return a boolean - {@code true} indicating Tethering is supported.
1346 *
1347 * <p>This method requires the call to hold the permission
1348 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001349 * {@hide}
1350 */
1351 public boolean isTetheringSupported() {
1352 try {
1353 return mService.isTetheringSupported();
1354 } catch (RemoteException e) {
1355 return false;
1356 }
1357 }
1358
1359 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001360 * Get the list of regular expressions that define any tetherable
1361 * USB network interfaces. If USB tethering is not supported by the
1362 * device, this list should be empty.
1363 *
1364 * @return an array of 0 or more regular expression Strings defining
1365 * what interfaces are considered tetherable usb interfaces.
1366 *
1367 * <p>This method requires the call to hold the permission
1368 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001369 * {@hide}
1370 */
1371 public String[] getTetherableUsbRegexs() {
1372 try {
1373 return mService.getTetherableUsbRegexs();
1374 } catch (RemoteException e) {
1375 return new String[0];
1376 }
1377 }
1378
1379 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001380 * Get the list of regular expressions that define any tetherable
1381 * Wifi network interfaces. If Wifi tethering is not supported by the
1382 * device, this list should be empty.
1383 *
1384 * @return an array of 0 or more regular expression Strings defining
1385 * what interfaces are considered tetherable wifi interfaces.
1386 *
1387 * <p>This method requires the call to hold the permission
1388 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt2a091d72010-02-11 18:18:40 -08001389 * {@hide}
1390 */
1391 public String[] getTetherableWifiRegexs() {
1392 try {
1393 return mService.getTetherableWifiRegexs();
1394 } catch (RemoteException e) {
1395 return new String[0];
1396 }
1397 }
Robert Greenwalt5a735062010-03-02 17:25:02 -08001398
Danica Chang6fdd0c62010-08-11 14:54:43 -07001399 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001400 * Get the list of regular expressions that define any tetherable
1401 * Bluetooth network interfaces. If Bluetooth tethering is not supported by the
1402 * device, this list should be empty.
1403 *
1404 * @return an array of 0 or more regular expression Strings defining
1405 * what interfaces are considered tetherable bluetooth interfaces.
1406 *
1407 * <p>This method requires the call to hold the permission
1408 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Danica Chang6fdd0c62010-08-11 14:54:43 -07001409 * {@hide}
1410 */
1411 public String[] getTetherableBluetoothRegexs() {
1412 try {
1413 return mService.getTetherableBluetoothRegexs();
1414 } catch (RemoteException e) {
1415 return new String[0];
1416 }
1417 }
1418
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001419 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001420 * Attempt to both alter the mode of USB and Tethering of USB. A
1421 * utility method to deal with some of the complexity of USB - will
1422 * attempt to switch to Rndis and subsequently tether the resulting
1423 * interface on {@code true} or turn off tethering and switch off
1424 * Rndis on {@code false}.
1425 *
1426 * @param enable a boolean - {@code true} to enable tethering
1427 * @return error a {@code TETHER_ERROR} value indicating success or failure type
1428 *
1429 * <p>This method requires the call to hold the permission
1430 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
Mike Lockwood6c2260b2011-07-19 13:04:47 -07001431 * {@hide}
1432 */
1433 public int setUsbTethering(boolean enable) {
1434 try {
1435 return mService.setUsbTethering(enable);
1436 } catch (RemoteException e) {
1437 return TETHER_ERROR_SERVICE_UNAVAIL;
1438 }
1439 }
1440
Robert Greenwalt5a735062010-03-02 17:25:02 -08001441 /** {@hide} */
1442 public static final int TETHER_ERROR_NO_ERROR = 0;
1443 /** {@hide} */
1444 public static final int TETHER_ERROR_UNKNOWN_IFACE = 1;
1445 /** {@hide} */
1446 public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2;
1447 /** {@hide} */
1448 public static final int TETHER_ERROR_UNSUPPORTED = 3;
1449 /** {@hide} */
1450 public static final int TETHER_ERROR_UNAVAIL_IFACE = 4;
1451 /** {@hide} */
1452 public static final int TETHER_ERROR_MASTER_ERROR = 5;
1453 /** {@hide} */
1454 public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
1455 /** {@hide} */
1456 public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
1457 /** {@hide} */
1458 public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8;
1459 /** {@hide} */
1460 public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9;
1461 /** {@hide} */
1462 public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10;
1463
1464 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001465 * Get a more detailed error code after a Tethering or Untethering
1466 * request asynchronously failed.
1467 *
1468 * @param iface The name of the interface of interest
Robert Greenwalt5a735062010-03-02 17:25:02 -08001469 * @return error The error code of the last error tethering or untethering the named
1470 * interface
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001471 *
1472 * <p>This method requires the call to hold the permission
1473 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt5a735062010-03-02 17:25:02 -08001474 * {@hide}
1475 */
1476 public int getLastTetherError(String iface) {
1477 try {
1478 return mService.getLastTetherError(iface);
1479 } catch (RemoteException e) {
1480 return TETHER_ERROR_SERVICE_UNAVAIL;
1481 }
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001482 }
1483
1484 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001485 * Try to ensure the device stays awake until we connect with the next network.
1486 * Actually just holds a wakelock for a number of seconds while we try to connect
1487 * to any default networks. This will expire if the timeout passes or if we connect
1488 * to a default after this is called. For internal use only.
1489 *
1490 * @param forWhom the name of the network going down for logging purposes
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001491 * @return {@code true} on success, {@code false} on failure
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001492 *
1493 * <p>This method requires the call to hold the permission
1494 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwalt14f2ef42010-06-15 12:19:37 -07001495 * {@hide}
1496 */
1497 public boolean requestNetworkTransitionWakelock(String forWhom) {
1498 try {
1499 mService.requestNetworkTransitionWakelock(forWhom);
1500 return true;
1501 } catch (RemoteException e) {
1502 return false;
1503 }
1504 }
Robert Greenwaltca4306c2010-09-09 13:15:32 -07001505
Robert Greenwalt67fd6c92010-09-09 14:22:59 -07001506 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001507 * Report network connectivity status. This is currently used only
1508 * to alter status bar UI.
1509 *
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001510 * @param networkType The type of network you want to report on
1511 * @param percentage The quality of the connection 0 is bad, 100 is good
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001512 *
1513 * <p>This method requires the call to hold the permission
1514 * {@link android.Manifest.permission#STATUS_BAR}.
Robert Greenwaltd7085fc2010-09-08 15:24:47 -07001515 * {@hide}
1516 */
1517 public void reportInetCondition(int networkType, int percentage) {
1518 try {
1519 mService.reportInetCondition(networkType, percentage);
1520 } catch (RemoteException e) {
1521 }
1522 }
Robert Greenwalt434203a2010-10-11 16:00:27 -07001523
1524 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001525 * Report a problem network to the framework. This provides a hint to the system
1526 * that there might be connectivity problems on this network and may cause
1527 * the framework to re-evaluate network connectivity and/or switch to another
1528 * network.
Robert Greenwalt9258c642014-03-26 16:47:06 -07001529 *
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001530 * @param network The {@link Network} the application was attempting to use
1531 * or {@code null} to indicate the current default network.
Robert Greenwalt9258c642014-03-26 16:47:06 -07001532 */
1533 public void reportBadNetwork(Network network) {
1534 try {
1535 mService.reportBadNetwork(network);
1536 } catch (RemoteException e) {
1537 }
1538 }
1539
1540 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001541 * Set a network-independent global http proxy. This is not normally what you want
1542 * for typical HTTP proxies - they are general network dependent. However if you're
1543 * doing something unusual like general internal filtering this may be useful. On
1544 * a private network where the proxy is not accessible, you may break HTTP using this.
1545 *
Jason Monk207900c2014-04-25 15:00:09 -04001546 * @param p The a {@link ProxyInfo} object defining the new global
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001547 * HTTP proxy. A {@code null} value will clear the global HTTP proxy.
1548 *
1549 * <p>This method requires the call to hold the permission
Jason Monkfaf3fd52014-05-07 18:41:13 -04001550 * android.Manifest.permission#CONNECTIVITY_INTERNAL.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001551 * @hide
Robert Greenwalt434203a2010-10-11 16:00:27 -07001552 */
Jason Monk207900c2014-04-25 15:00:09 -04001553 public void setGlobalProxy(ProxyInfo p) {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001554 try {
1555 mService.setGlobalProxy(p);
1556 } catch (RemoteException e) {
1557 }
1558 }
1559
1560 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001561 * Retrieve any network-independent global HTTP proxy.
1562 *
Jason Monk207900c2014-04-25 15:00:09 -04001563 * @return {@link ProxyInfo} for the current global HTTP proxy or {@code null}
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001564 * if no global HTTP proxy is set.
1565 *
1566 * <p>This method requires the call to hold the permission
1567 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001568 * @hide
Robert Greenwalt434203a2010-10-11 16:00:27 -07001569 */
Jason Monk207900c2014-04-25 15:00:09 -04001570 public ProxyInfo getGlobalProxy() {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001571 try {
1572 return mService.getGlobalProxy();
1573 } catch (RemoteException e) {
1574 return null;
1575 }
1576 }
1577
1578 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001579 * Get the HTTP proxy settings for the current default network. Note that
1580 * if a global proxy is set, it will override any per-network setting.
1581 *
Jason Monk207900c2014-04-25 15:00:09 -04001582 * @return the {@link ProxyInfo} for the current HTTP proxy, or {@code null} if no
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001583 * HTTP proxy is active.
1584 *
1585 * <p>This method requires the call to hold the permission
1586 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt434203a2010-10-11 16:00:27 -07001587 * {@hide}
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001588 * @deprecated Deprecated in favor of {@link #getLinkProperties}
Robert Greenwalt434203a2010-10-11 16:00:27 -07001589 */
Jason Monk207900c2014-04-25 15:00:09 -04001590 public ProxyInfo getProxy() {
Robert Greenwalt434203a2010-10-11 16:00:27 -07001591 try {
1592 return mService.getProxy();
1593 } catch (RemoteException e) {
1594 return null;
1595 }
1596 }
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001597
1598 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001599 * Sets a secondary requirement bit for the given networkType.
1600 * This requirement bit is generally under the control of the carrier
1601 * or its agents and is not directly controlled by the user.
1602 *
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001603 * @param networkType The network who's dependence has changed
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001604 * @param met Boolean - true if network use is OK, false if not
1605 *
1606 * <p>This method requires the call to hold the permission
1607 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
Robert Greenwaltd55a6b42011-03-25 13:09:25 -07001608 * {@hide}
1609 */
1610 public void setDataDependency(int networkType, boolean met) {
1611 try {
1612 mService.setDataDependency(networkType, met);
1613 } catch (RemoteException e) {
1614 }
1615 }
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001616
1617 /**
1618 * Returns true if the hardware supports the given network type
1619 * else it returns false. This doesn't indicate we have coverage
1620 * or are authorized onto a network, just whether or not the
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001621 * hardware supports it. For example a GSM phone without a SIM
1622 * should still return {@code true} for mobile data, but a wifi only
1623 * tablet would return {@code false}.
1624 *
1625 * @param networkType The network type we'd like to check
1626 * @return {@code true} if supported, else {@code false}
1627 *
1628 * <p>This method requires the call to hold the permission
1629 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Robert Greenwalt9b2886e2011-08-31 11:46:42 -07001630 * @hide
1631 */
1632 public boolean isNetworkSupported(int networkType) {
1633 try {
1634 return mService.isNetworkSupported(networkType);
1635 } catch (RemoteException e) {}
1636 return false;
1637 }
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001638
1639 /**
1640 * Returns if the currently active data network is metered. A network is
1641 * classified as metered when the user is sensitive to heavy data usage on
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001642 * that connection due to monetary costs, data limitations or
1643 * battery/performance issues. You should check this before doing large
1644 * data transfers, and warn the user or delay the operation until another
1645 * network is available.
1646 *
1647 * @return {@code true} if large transfers should be avoided, otherwise
1648 * {@code false}.
1649 *
1650 * <p>This method requires the call to hold the permission
1651 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
Jeff Sharkey9f7cbf02012-04-12 18:34:54 -07001652 */
1653 public boolean isActiveNetworkMetered() {
1654 try {
1655 return mService.isActiveNetworkMetered();
1656 } catch (RemoteException e) {
1657 return false;
1658 }
1659 }
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001660
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001661 /**
1662 * If the LockdownVpn mechanism is enabled, updates the vpn
1663 * with a reload of its profile.
1664 *
1665 * @return a boolean with {@code} indicating success
1666 *
1667 * <p>This method can only be called by the system UID
1668 * {@hide}
1669 */
Jeff Sharkey69ddab42012-08-25 00:05:46 -07001670 public boolean updateLockdownVpn() {
1671 try {
1672 return mService.updateLockdownVpn();
1673 } catch (RemoteException e) {
1674 return false;
1675 }
1676 }
Irfan Sheriffda6da092012-08-16 12:49:23 -07001677
1678 /**
Robert Greenwalt5a6bdc42013-02-15 10:56:35 -08001679 * Signal that the captive portal check on the indicated network
Wink Savilled747cbc2013-08-07 16:22:47 -07001680 * is complete and whether its a captive portal or not.
1681 *
1682 * @param info the {@link NetworkInfo} object for the networkType
1683 * in question.
1684 * @param isCaptivePortal true/false.
1685 *
1686 * <p>This method requires the call to hold the permission
1687 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
1688 * {@hide}
1689 */
1690 public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
1691 try {
1692 mService.captivePortalCheckCompleted(info, isCaptivePortal);
1693 } catch (RemoteException e) {
1694 }
1695 }
1696
1697 /**
Robert Greenwalt665e1ae2012-08-21 19:27:00 -07001698 * Supply the backend messenger for a network tracker
1699 *
Dianne Hackborn77b987f2014-02-26 16:20:52 -08001700 * @param networkType NetworkType to set
Robert Greenwalt665e1ae2012-08-21 19:27:00 -07001701 * @param messenger {@link Messenger}
1702 * {@hide}
1703 */
1704 public void supplyMessenger(int networkType, Messenger messenger) {
1705 try {
1706 mService.supplyMessenger(networkType, messenger);
1707 } catch (RemoteException e) {
1708 }
1709 }
Wink Savilleab9321d2013-06-29 21:10:57 -07001710
1711 /**
Wink Saville948282b2013-08-29 08:55:16 -07001712 * Check mobile provisioning.
Wink Savilleab9321d2013-06-29 21:10:57 -07001713 *
Wink Savilleab9321d2013-06-29 21:10:57 -07001714 * @param suggestedTimeOutMs, timeout in milliseconds
Wink Savilleab9321d2013-06-29 21:10:57 -07001715 *
1716 * @return time out that will be used, maybe less that suggestedTimeOutMs
1717 * -1 if an error.
1718 *
1719 * {@hide}
1720 */
Wink Saville948282b2013-08-29 08:55:16 -07001721 public int checkMobileProvisioning(int suggestedTimeOutMs) {
Wink Savilleab9321d2013-06-29 21:10:57 -07001722 int timeOutMs = -1;
1723 try {
Wink Saville948282b2013-08-29 08:55:16 -07001724 timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
Wink Savilleab9321d2013-06-29 21:10:57 -07001725 } catch (RemoteException e) {
1726 }
1727 return timeOutMs;
1728 }
Robert Greenwalte182bfe2013-07-16 12:06:09 -07001729
1730 /**
Wink Saville42d4f082013-07-20 20:31:59 -07001731 * Get the mobile provisioning url.
Robert Greenwalte182bfe2013-07-16 12:06:09 -07001732 * {@hide}
1733 */
1734 public String getMobileProvisioningUrl() {
1735 try {
1736 return mService.getMobileProvisioningUrl();
1737 } catch (RemoteException e) {
1738 }
1739 return null;
1740 }
Wink Saville42d4f082013-07-20 20:31:59 -07001741
1742 /**
1743 * Get the mobile redirected provisioning url.
1744 * {@hide}
1745 */
1746 public String getMobileRedirectedProvisioningUrl() {
1747 try {
1748 return mService.getMobileRedirectedProvisioningUrl();
1749 } catch (RemoteException e) {
1750 }
1751 return null;
1752 }
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001753
1754 /**
1755 * get the information about a specific network link
1756 * @hide
1757 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001758 public LinkQualityInfo getLinkQualityInfo(int networkType) {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001759 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001760 LinkQualityInfo li = mService.getLinkQualityInfo(networkType);
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001761 return li;
1762 } catch (RemoteException e) {
1763 return null;
1764 }
1765 }
1766
1767 /**
1768 * get the information of currently active network link
1769 * @hide
1770 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001771 public LinkQualityInfo getActiveLinkQualityInfo() {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001772 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001773 LinkQualityInfo li = mService.getActiveLinkQualityInfo();
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001774 return li;
1775 } catch (RemoteException e) {
1776 return null;
1777 }
1778 }
1779
1780 /**
1781 * get the information of all network links
1782 * @hide
1783 */
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001784 public LinkQualityInfo[] getAllLinkQualityInfo() {
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001785 try {
Vinit Deshapnde6a2d3252013-09-04 14:11:24 -07001786 LinkQualityInfo[] li = mService.getAllLinkQualityInfo();
Vinit Deshapnde1f12cb52013-08-21 13:09:01 -07001787 return li;
1788 } catch (RemoteException e) {
1789 return null;
1790 }
1791 }
Wink Saville7788c612013-08-29 14:57:08 -07001792
1793 /**
Wink Saville948282b2013-08-29 08:55:16 -07001794 * Set sign in error notification to visible or in visible
1795 *
1796 * @param visible
1797 * @param networkType
1798 *
1799 * {@hide}
1800 */
1801 public void setProvisioningNotificationVisible(boolean visible, int networkType,
1802 String extraInfo, String url) {
1803 try {
1804 mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url);
1805 } catch (RemoteException e) {
1806 }
1807 }
Yuhao Zheng5cd1a0e2013-09-09 17:00:04 -07001808
1809 /**
1810 * Set the value for enabling/disabling airplane mode
1811 *
1812 * @param enable whether to enable airplane mode or not
1813 *
1814 * <p>This method requires the call to hold the permission
1815 * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
1816 * @hide
1817 */
1818 public void setAirplaneMode(boolean enable) {
1819 try {
1820 mService.setAirplaneMode(enable);
1821 } catch (RemoteException e) {
1822 }
1823 }
Robert Greenwalte049c232014-04-11 15:53:27 -07001824
1825 /** {@hide} */
Robert Greenwalta67be032014-05-16 15:49:14 -07001826 public void registerNetworkFactory(Messenger messenger, String name) {
Robert Greenwalte049c232014-04-11 15:53:27 -07001827 try {
Robert Greenwalta67be032014-05-16 15:49:14 -07001828 mService.registerNetworkFactory(messenger, name);
1829 } catch (RemoteException e) { }
1830 }
1831
1832 /** {@hide} */
1833 public void unregisterNetworkFactory(Messenger messenger) {
1834 try {
1835 mService.unregisterNetworkFactory(messenger);
Robert Greenwalte049c232014-04-11 15:53:27 -07001836 } catch (RemoteException e) { }
1837 }
Robert Greenwalt7b816022014-04-18 15:25:25 -07001838
1839 /** {@hide} */
1840 public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
1841 NetworkCapabilities nc, int score) {
1842 try {
1843 mService.registerNetworkAgent(messenger, ni, lp, nc, score);
1844 } catch (RemoteException e) { }
1845 }
1846
Robert Greenwalt9258c642014-03-26 16:47:06 -07001847 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001848 * Base class for NetworkRequest callbacks. Used for notifications about network
1849 * changes. Should be extended by applications wanting notifications.
Robert Greenwalt9258c642014-03-26 16:47:06 -07001850 */
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001851 public static class NetworkCallbackListener {
Robert Greenwalt9258c642014-03-26 16:47:06 -07001852 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001853 public static final int PRECHECK = 1;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001854 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001855 public static final int AVAILABLE = 2;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001856 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001857 public static final int LOSING = 3;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001858 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001859 public static final int LOST = 4;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001860 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001861 public static final int UNAVAIL = 5;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001862 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001863 public static final int CAP_CHANGED = 6;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001864 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001865 public static final int PROP_CHANGED = 7;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001866 /** @hide */
Robert Greenwalt7b816022014-04-18 15:25:25 -07001867 public static final int CANCELED = 8;
1868
1869 /**
1870 * @hide
1871 * Called whenever the framework connects to a network that it may use to
1872 * satisfy this request
1873 */
1874 public void onPreCheck(NetworkRequest networkRequest, Network network) {}
1875
1876 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001877 * Called when the framework connects and has declared new network ready for use.
1878 *
1879 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
1880 * @param network The {@link Network} of the satisfying network.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001881 */
1882 public void onAvailable(NetworkRequest networkRequest, Network network) {}
1883
1884 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001885 * Called when the network is about to be disconnected. Often paired with an
1886 * {@link NetworkCallbackListener#onAvailable} call with the new replacement network
1887 * for graceful handover. This may not be called if we have a hard loss
1888 * (loss without warning). This may be followed by either a
1889 * {@link NetworkCallbackListener#onLost} call or a
1890 * {@link NetworkCallbackListener#onAvailable} call for this network depending
1891 * on whether we lose or regain it.
1892 *
1893 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
1894 * @param network The {@link Network} of the failing network.
1895 * @param maxSecToLive The time in seconds the framework will attempt to keep the
1896 * network connected. Note that the network may suffers a
1897 * hard loss at any time.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001898 */
1899 public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {}
1900
1901 /**
1902 * Called when the framework has a hard loss of the network or when the
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001903 * graceful failure ends.
1904 *
1905 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
1906 * @param network The {@link Network} lost.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001907 */
1908 public void onLost(NetworkRequest networkRequest, Network network) {}
1909
1910 /**
1911 * Called if no network is found in the given timeout time. If no timeout is given,
1912 * this will not be called.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001913 * @hide
Robert Greenwalt7b816022014-04-18 15:25:25 -07001914 */
1915 public void onUnavailable(NetworkRequest networkRequest) {}
1916
1917 /**
1918 * Called when the network the framework connected to for this request
1919 * changes capabilities but still satisfies the stated need.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001920 *
1921 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
1922 * @param network The {@link Network} whose capabilities have changed.
1923 * @param networkCapabilities The new {@link NetworkCapabilities} for this network.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001924 */
Robert Greenwalt9258c642014-03-26 16:47:06 -07001925 public void onNetworkCapabilitiesChanged(NetworkRequest networkRequest, Network network,
Robert Greenwalt7b816022014-04-18 15:25:25 -07001926 NetworkCapabilities networkCapabilities) {}
1927
1928 /**
1929 * Called when the network the framework connected to for this request
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001930 * changes {@link LinkProperties}.
1931 *
1932 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
1933 * @param network The {@link Network} whose link properties have changed.
1934 * @param linkProperties The new {@link LinkProperties} for this network.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001935 */
Robert Greenwalt9258c642014-03-26 16:47:06 -07001936 public void onLinkPropertiesChanged(NetworkRequest networkRequest, Network network,
Robert Greenwalt7b816022014-04-18 15:25:25 -07001937 LinkProperties linkProperties) {}
1938
1939 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001940 * Called when a {@link #releaseNetworkRequest} call concludes and the registered
1941 * callbacks will no longer be used.
1942 *
1943 * @param networkRequest The {@link NetworkRequest} used to initiate the request.
Robert Greenwalt7b816022014-04-18 15:25:25 -07001944 */
Robert Greenwalt9258c642014-03-26 16:47:06 -07001945 public void onReleased(NetworkRequest networkRequest) {}
Robert Greenwalt7b816022014-04-18 15:25:25 -07001946 }
1947
Robert Greenwalt9258c642014-03-26 16:47:06 -07001948 private static final int BASE = Protocol.BASE_CONNECTIVITY_MANAGER;
1949 /** @hide obj = pair(NetworkRequest, Network) */
1950 public static final int CALLBACK_PRECHECK = BASE + 1;
1951 /** @hide obj = pair(NetworkRequest, Network) */
1952 public static final int CALLBACK_AVAILABLE = BASE + 2;
1953 /** @hide obj = pair(NetworkRequest, Network), arg1 = ttl */
1954 public static final int CALLBACK_LOSING = BASE + 3;
1955 /** @hide obj = pair(NetworkRequest, Network) */
1956 public static final int CALLBACK_LOST = BASE + 4;
1957 /** @hide obj = NetworkRequest */
1958 public static final int CALLBACK_UNAVAIL = BASE + 5;
1959 /** @hide obj = pair(NetworkRequest, Network) */
1960 public static final int CALLBACK_CAP_CHANGED = BASE + 6;
1961 /** @hide obj = pair(NetworkRequest, Network) */
1962 public static final int CALLBACK_IP_CHANGED = BASE + 7;
1963 /** @hide obj = NetworkRequest */
1964 public static final int CALLBACK_RELEASED = BASE + 8;
1965 /** @hide */
1966 public static final int CALLBACK_EXIT = BASE + 9;
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07001967 /** @hide obj = NetworkCapabilities, arg1 = seq number */
1968 private static final int EXPIRE_LEGACY_REQUEST = BASE + 10;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001969
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07001970 private class CallbackHandler extends Handler {
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001971 private final HashMap<NetworkRequest, NetworkCallbackListener>mCallbackMap;
Robert Greenwalt9258c642014-03-26 16:47:06 -07001972 private final AtomicInteger mRefCount;
1973 private static final String TAG = "ConnectivityManager.CallbackHandler";
1974 private final ConnectivityManager mCm;
1975
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001976 CallbackHandler(Looper looper, HashMap<NetworkRequest, NetworkCallbackListener>callbackMap,
Robert Greenwalt9258c642014-03-26 16:47:06 -07001977 AtomicInteger refCount, ConnectivityManager cm) {
1978 super(looper);
1979 mCallbackMap = callbackMap;
1980 mRefCount = refCount;
1981 mCm = cm;
1982 }
1983
1984 @Override
1985 public void handleMessage(Message message) {
1986 Log.d(TAG, "CM callback handler got msg " + message.what);
1987 switch (message.what) {
1988 case CALLBACK_PRECHECK: {
1989 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07001990 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07001991 if (callbacks != null) {
1992 callbacks.onPreCheck(request, getNetwork(message));
1993 } else {
1994 Log.e(TAG, "callback not found for PRECHECK message");
1995 }
1996 break;
1997 }
1998 case CALLBACK_AVAILABLE: {
1999 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002000 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002001 if (callbacks != null) {
2002 callbacks.onAvailable(request, getNetwork(message));
2003 } else {
2004 Log.e(TAG, "callback not found for AVAILABLE message");
2005 }
2006 break;
2007 }
2008 case CALLBACK_LOSING: {
2009 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002010 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002011 if (callbacks != null) {
2012 callbacks.onLosing(request, getNetwork(message), message.arg1);
2013 } else {
2014 Log.e(TAG, "callback not found for LOSING message");
2015 }
2016 break;
2017 }
2018 case CALLBACK_LOST: {
2019 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002020 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002021 if (callbacks != null) {
2022 callbacks.onLost(request, getNetwork(message));
2023 } else {
2024 Log.e(TAG, "callback not found for LOST message");
2025 }
2026 break;
2027 }
2028 case CALLBACK_UNAVAIL: {
2029 NetworkRequest req = (NetworkRequest)message.obj;
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002030 NetworkCallbackListener callbacks = null;
Robert Greenwalt9258c642014-03-26 16:47:06 -07002031 synchronized(mCallbackMap) {
2032 callbacks = mCallbackMap.get(req);
2033 }
2034 if (callbacks != null) {
2035 callbacks.onUnavailable(req);
2036 } else {
2037 Log.e(TAG, "callback not found for UNAVAIL message");
2038 }
2039 break;
2040 }
2041 case CALLBACK_CAP_CHANGED: {
2042 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002043 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002044 if (callbacks != null) {
2045 Network network = getNetwork(message);
2046 NetworkCapabilities cap = mCm.getNetworkCapabilities(network);
2047
2048 callbacks.onNetworkCapabilitiesChanged(request, network, cap);
2049 } else {
2050 Log.e(TAG, "callback not found for CHANGED message");
2051 }
2052 break;
2053 }
2054 case CALLBACK_IP_CHANGED: {
2055 NetworkRequest request = getNetworkRequest(message);
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002056 NetworkCallbackListener callbacks = getCallbacks(request);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002057 if (callbacks != null) {
2058 Network network = getNetwork(message);
2059 LinkProperties lp = mCm.getLinkProperties(network);
2060
2061 callbacks.onLinkPropertiesChanged(request, network, lp);
2062 } else {
2063 Log.e(TAG, "callback not found for CHANGED message");
2064 }
2065 break;
2066 }
2067 case CALLBACK_RELEASED: {
2068 NetworkRequest req = (NetworkRequest)message.obj;
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002069 NetworkCallbackListener callbacks = null;
Robert Greenwalt9258c642014-03-26 16:47:06 -07002070 synchronized(mCallbackMap) {
2071 callbacks = mCallbackMap.remove(req);
2072 }
2073 if (callbacks != null) {
2074 callbacks.onReleased(req);
2075 } else {
2076 Log.e(TAG, "callback not found for CANCELED message");
2077 }
2078 synchronized(mRefCount) {
2079 if (mRefCount.decrementAndGet() == 0) {
2080 getLooper().quit();
2081 }
2082 }
2083 break;
2084 }
2085 case CALLBACK_EXIT: {
2086 Log.d(TAG, "Listener quiting");
2087 getLooper().quit();
2088 break;
2089 }
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002090 case EXPIRE_LEGACY_REQUEST: {
2091 expireRequest((NetworkCapabilities)message.obj, message.arg1);
2092 break;
2093 }
Robert Greenwalt9258c642014-03-26 16:47:06 -07002094 }
2095 }
2096
2097 private NetworkRequest getNetworkRequest(Message msg) {
2098 return (NetworkRequest)(msg.obj);
2099 }
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002100 private NetworkCallbackListener getCallbacks(NetworkRequest req) {
Robert Greenwalt9258c642014-03-26 16:47:06 -07002101 synchronized(mCallbackMap) {
2102 return mCallbackMap.get(req);
2103 }
2104 }
2105 private Network getNetwork(Message msg) {
2106 return new Network(msg.arg2);
2107 }
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002108 private NetworkCallbackListener removeCallbacks(Message msg) {
Robert Greenwalt9258c642014-03-26 16:47:06 -07002109 NetworkRequest req = (NetworkRequest)msg.obj;
2110 synchronized(mCallbackMap) {
2111 return mCallbackMap.remove(req);
2112 }
2113 }
2114 }
2115
2116 private void addCallbackListener() {
2117 synchronized(sCallbackRefCount) {
2118 if (sCallbackRefCount.incrementAndGet() == 1) {
2119 // TODO - switch this over to a ManagerThread or expire it when done
2120 HandlerThread callbackThread = new HandlerThread("ConnectivityManager");
2121 callbackThread.start();
2122 sCallbackHandler = new CallbackHandler(callbackThread.getLooper(),
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002123 sNetworkCallbackListener, sCallbackRefCount, this);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002124 }
2125 }
2126 }
2127
2128 private void removeCallbackListener() {
2129 synchronized(sCallbackRefCount) {
2130 if (sCallbackRefCount.decrementAndGet() == 0) {
2131 sCallbackHandler.obtainMessage(CALLBACK_EXIT).sendToTarget();
2132 sCallbackHandler = null;
2133 }
2134 }
2135 }
2136
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002137 static final HashMap<NetworkRequest, NetworkCallbackListener> sNetworkCallbackListener =
2138 new HashMap<NetworkRequest, NetworkCallbackListener>();
Robert Greenwalt9258c642014-03-26 16:47:06 -07002139 static final AtomicInteger sCallbackRefCount = new AtomicInteger(0);
2140 static CallbackHandler sCallbackHandler = null;
2141
2142 private final static int LISTEN = 1;
2143 private final static int REQUEST = 2;
2144
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002145 private NetworkRequest sendRequestForNetwork(NetworkCapabilities need,
2146 NetworkCallbackListener networkCallbackListener, int timeoutSec, int action,
2147 boolean legacy) {
Robert Greenwalt9258c642014-03-26 16:47:06 -07002148 NetworkRequest networkRequest = null;
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002149 if (networkCallbackListener == null) {
2150 throw new IllegalArgumentException("null NetworkCallbackListener");
2151 }
Robert Greenwalt9258c642014-03-26 16:47:06 -07002152 if (need == null) throw new IllegalArgumentException("null NetworkCapabilities");
2153 try {
2154 addCallbackListener();
2155 if (action == LISTEN) {
2156 networkRequest = mService.listenForNetwork(need, new Messenger(sCallbackHandler),
2157 new Binder());
2158 } else {
2159 networkRequest = mService.requestNetwork(need, new Messenger(sCallbackHandler),
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002160 timeoutSec, new Binder(), legacy);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002161 }
2162 if (networkRequest != null) {
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002163 synchronized(sNetworkCallbackListener) {
2164 sNetworkCallbackListener.put(networkRequest, networkCallbackListener);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002165 }
2166 }
2167 } catch (RemoteException e) {}
2168 if (networkRequest == null) removeCallbackListener();
2169 return networkRequest;
2170 }
2171
2172 /**
2173 * Request a network to satisfy a set of {@link NetworkCapabilities}.
2174 *
2175 * This {@link NetworkRequest} will live until released via
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002176 * {@link #releaseNetworkRequest} or the calling application exits.
2177 * Status of the request can be followed by listening to the various
2178 * callbacks described in {@link NetworkCallbackListener}. The {@link Network}
2179 * can be used to direct traffic to the network.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002180 *
2181 * @param need {@link NetworkCapabilities} required by this request.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002182 * @param networkCallbackListener The {@link NetworkCallbackListener} to be utilized for this
2183 * request. Note the callbacks can be shared by multiple
2184 * requests and the NetworkRequest token utilized to
2185 * determine to which request the callback relates.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002186 * @return A {@link NetworkRequest} object identifying the request.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002187 */
2188 public NetworkRequest requestNetwork(NetworkCapabilities need,
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002189 NetworkCallbackListener networkCallbackListener) {
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002190 return sendRequestForNetwork(need, networkCallbackListener, 0, REQUEST, false);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002191 }
2192
2193 /**
2194 * Request a network to satisfy a set of {@link NetworkCapabilities}, limited
2195 * by a timeout.
2196 *
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002197 * This function behaves identically to the non-timedout version, but if a suitable
2198 * network is not found within the given time (in Seconds) the
2199 * {@link NetworkCallbackListener#unavailable} callback is called. The request must
2200 * still be released normally by calling {@link releaseNetworkRequest}.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002201 * @param need {@link NetworkCapabilities} required by this request.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002202 * @param networkCallbackListener The callbacks to be utilized for this request. Note
Robert Greenwalt9258c642014-03-26 16:47:06 -07002203 * the callbacks can be shared by multiple requests and
2204 * the NetworkRequest token utilized to determine to which
2205 * request the callback relates.
2206 * @param timeoutSec The time in seconds to attempt looking for a suitable network
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002207 * before {@link NetworkCallbackListener#unavailable} is called.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002208 * @return A {@link NetworkRequest} object identifying the request.
2209 * @hide
2210 */
2211 public NetworkRequest requestNetwork(NetworkCapabilities need,
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002212 NetworkCallbackListener networkCallbackListener, int timeoutSec) {
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002213 return sendRequestForNetwork(need, networkCallbackListener, timeoutSec, REQUEST, false);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002214 }
2215
2216 /**
2217 * The maximum number of seconds the framework will look for a suitable network
2218 * during a timeout-equiped call to {@link requestNetwork}.
2219 * {@hide}
2220 */
2221 public final static int MAX_NETWORK_REQUEST_TIMEOUT_SEC = 100 * 60;
2222
2223 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002224 * The lookup key for a {@link Network} object included with the intent after
2225 * succesfully finding a network for the applications request. Retrieve it with
2226 * {@link android.content.Intent#getParcelableExtra(String)}.
2227 */
2228 public static final String EXTRA_NETWORK_REQUEST_NETWORK = "networkRequestNetwork";
2229
2230 /**
2231 * The lookup key for a {@link NetworkCapabilities} object included with the intent after
2232 * succesfully finding a network for the applications request. Retrieve it with
2233 * {@link android.content.Intent#getParcelableExtra(String)}.
2234 */
2235 public static final String EXTRA_NETWORK_REQUEST_NETWORK_CAPABILITIES =
2236 "networkRequestNetworkCapabilities";
2237
2238
2239 /**
Robert Greenwalt9258c642014-03-26 16:47:06 -07002240 * Request a network to satisfy a set of {@link NetworkCapabilities}.
2241 *
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002242 * This function behavies identically to the callback-equiped version, but instead
2243 * of {@link NetworkCallbackListener} a {@link PendingIntent} is used. This means
2244 * the request may outlive the calling application and get called back when a suitable
2245 * network is found.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002246 * <p>
2247 * The operation is an Intent broadcast that goes to a broadcast receiver that
2248 * you registered with {@link Context#registerReceiver} or through the
2249 * &lt;receiver&gt; tag in an AndroidManifest.xml file
2250 * <p>
2251 * The operation Intent is delivered with two extras, a {@link Network} typed
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002252 * extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK} and a {@link NetworkCapabilities}
2253 * typed extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK_CAPABILITIES} containing
Robert Greenwalt9258c642014-03-26 16:47:06 -07002254 * the original requests parameters. It is important to create a new,
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002255 * {@link NetworkCallbackListener} based request before completing the processing of the
Robert Greenwalt9258c642014-03-26 16:47:06 -07002256 * Intent to reserve the network or it will be released shortly after the Intent
2257 * is processed.
2258 * <p>
2259 * If there is already an request for this Intent registered (with the equality of
2260 * two Intents defined by {@link Intent#filterEquals}), then it will be removed and
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002261 * replaced by this one, effectively releasing the previous {@link NetworkRequest}.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002262 * <p>
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002263 * The request may be released normally by calling {@link #releaseNetworkRequest}.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002264 *
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002265 * @param need {@link NetworkCapabilities} required by this request.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002266 * @param operation Action to perform when the network is available (corresponds
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002267 * to the {@link NetworkCallbackListener#onAvailable} call. Typically
Robert Greenwalt9258c642014-03-26 16:47:06 -07002268 * comes from {@link PendingIntent#getBroadcast}.
2269 * @return A {@link NetworkRequest} object identifying the request.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002270 */
2271 public NetworkRequest requestNetwork(NetworkCapabilities need, PendingIntent operation) {
2272 try {
2273 return mService.pendingRequestForNetwork(need, operation);
2274 } catch (RemoteException e) {}
2275 return null;
2276 }
2277
2278 /**
2279 * Registers to receive notifications about all networks which satisfy the given
2280 * {@link NetworkCapabilities}. The callbacks will continue to be called until
2281 * either the application exits or the request is released using
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002282 * {@link #releaseNetworkRequest}.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002283 *
2284 * @param need {@link NetworkCapabilities} required by this request.
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002285 * @param networkCallbackListener The {@link NetworkCallbackListener} to be called as suitable
Robert Greenwalt9258c642014-03-26 16:47:06 -07002286 * networks change state.
2287 * @return A {@link NetworkRequest} object identifying the request.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002288 */
2289 public NetworkRequest listenForNetwork(NetworkCapabilities need,
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002290 NetworkCallbackListener networkCallbackListener) {
Robert Greenwalt71bf33a2014-05-15 18:07:26 -07002291 return sendRequestForNetwork(need, networkCallbackListener, 0, LISTEN, false);
Robert Greenwalt9258c642014-03-26 16:47:06 -07002292 }
2293
2294 /**
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002295 * Releases a {@link NetworkRequest} generated either through a {@link #requestNetwork}
2296 * or a {@link #listenForNetwork} call. The {@link NetworkCallbackListener} given in the
2297 * earlier call may continue receiving calls until the
2298 * {@link NetworkCallbackListener#onReleased} function is called, signifying the end
2299 * of the request.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002300 *
2301 * @param networkRequest The {@link NetworkRequest} generated by an earlier call to
Robert Greenwaltd19c41c2014-05-18 23:07:25 -07002302 * {@link #requestNetwork} or {@link #listenForNetwork}.
Robert Greenwalt9258c642014-03-26 16:47:06 -07002303 */
2304 public void releaseNetworkRequest(NetworkRequest networkRequest) {
2305 if (networkRequest == null) throw new IllegalArgumentException("null NetworkRequest");
2306 try {
2307 mService.releaseNetworkRequest(networkRequest);
2308 } catch (RemoteException e) {}
2309 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002310}