The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 19 | import static com.android.internal.util.Preconditions.checkNotNull; |
| 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.annotation.SdkConstant; |
| 22 | import android.annotation.SdkConstant.SdkConstantType; |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 24 | import android.os.Binder; |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 25 | import android.os.Build.VERSION_CODES; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 26 | import android.os.IBinder; |
| 27 | import android.os.INetworkActivityListener; |
| 28 | import android.os.INetworkManagementService; |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 29 | import android.os.Messenger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.os.RemoteException; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 31 | import android.os.ServiceManager; |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 32 | import android.provider.Settings; |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 33 | import android.util.ArrayMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 35 | import java.net.InetAddress; |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 36 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Class that answers queries about the state of network connectivity. It also |
| 39 | * notifies applications when network connectivity changes. Get an instance |
| 40 | * of this class by calling |
| 41 | * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}. |
| 42 | * <p> |
| 43 | * The primary responsibilities of this class are to: |
| 44 | * <ol> |
| 45 | * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li> |
| 46 | * <li>Send broadcast intents when network connectivity changes</li> |
| 47 | * <li>Attempt to "fail over" to another network when connectivity to a network |
| 48 | * is lost</li> |
| 49 | * <li>Provide an API that allows applications to query the coarse-grained or fine-grained |
| 50 | * state of the available networks</li> |
| 51 | * </ol> |
| 52 | */ |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 53 | public class ConnectivityManager { |
| 54 | private static final String TAG = "ConnectivityManager"; |
| 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | /** |
| 57 | * A change in network connectivity has occurred. A connection has either |
| 58 | * been established or lost. The NetworkInfo for the affected network is |
| 59 | * sent as an extra; it should be consulted to see what kind of |
| 60 | * connectivity event occurred. |
| 61 | * <p/> |
| 62 | * If this is a connection that was the result of failing over from a |
| 63 | * disconnected network, then the FAILOVER_CONNECTION boolean extra is |
| 64 | * set to true. |
| 65 | * <p/> |
| 66 | * For a loss of connectivity, if the connectivity manager is attempting |
| 67 | * to connect (or has already connected) to another network, the |
| 68 | * NetworkInfo for the new network is also passed as an extra. This lets |
| 69 | * any receivers of the broadcast know that they should not necessarily |
| 70 | * tell the user that no data traffic will be possible. Instead, the |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 71 | * receiver should expect another broadcast soon, indicating either that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | * the failover attempt succeeded (and so there is still overall data |
| 73 | * connectivity), or that the failover attempt failed, meaning that all |
| 74 | * connectivity has been lost. |
| 75 | * <p/> |
| 76 | * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY |
| 77 | * is set to {@code true} if there are no connected networks at all. |
| 78 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 79 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | /** |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 83 | * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 84 | * applicable {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY}. |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 85 | * |
| 86 | * @hide |
| 87 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 88 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 89 | public static final String CONNECTIVITY_ACTION_IMMEDIATE = |
| 90 | "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE"; |
| 91 | |
| 92 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | * The lookup key for a {@link NetworkInfo} object. Retrieve with |
| 94 | * {@link android.content.Intent#getParcelableExtra(String)}. |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 95 | * |
| 96 | * @deprecated Since {@link NetworkInfo} can vary based on UID, applications |
| 97 | * should always obtain network information through |
| 98 | * {@link #getActiveNetworkInfo()} or |
| 99 | * {@link #getAllNetworkInfo()}. |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame] | 100 | * @see #EXTRA_NETWORK_TYPE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | */ |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 102 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | public static final String EXTRA_NETWORK_INFO = "networkInfo"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | /** |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame] | 106 | * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast. |
| 107 | * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo} |
| 108 | * state based on the calling application. |
| 109 | * |
| 110 | * @see android.content.Intent#getIntExtra(String, int) |
| 111 | */ |
| 112 | public static final String EXTRA_NETWORK_TYPE = "networkType"; |
| 113 | |
| 114 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | * The lookup key for a boolean that indicates whether a connect event |
| 116 | * is for a network to which the connectivity manager was failing over |
| 117 | * following a disconnect on another network. |
| 118 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 119 | */ |
| 120 | public static final String EXTRA_IS_FAILOVER = "isFailover"; |
| 121 | /** |
| 122 | * The lookup key for a {@link NetworkInfo} object. This is supplied when |
| 123 | * there is another network that it may be possible to connect to. Retrieve with |
| 124 | * {@link android.content.Intent#getParcelableExtra(String)}. |
| 125 | */ |
| 126 | public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork"; |
| 127 | /** |
| 128 | * The lookup key for a boolean that indicates whether there is a |
| 129 | * complete lack of connectivity, i.e., no network is available. |
| 130 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 131 | */ |
| 132 | public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity"; |
| 133 | /** |
| 134 | * The lookup key for a string that indicates why an attempt to connect |
| 135 | * to a network failed. The string has no particular structure. It is |
| 136 | * intended to be used in notifications presented to users. Retrieve |
| 137 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 138 | */ |
| 139 | public static final String EXTRA_REASON = "reason"; |
| 140 | /** |
| 141 | * The lookup key for a string that provides optionally supplied |
| 142 | * extra information about the network state. The information |
| 143 | * may be passed up from the lower networking layers, and its |
| 144 | * meaning may be specific to a particular network type. Retrieve |
| 145 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 146 | */ |
| 147 | public static final String EXTRA_EXTRA_INFO = "extraInfo"; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 148 | /** |
| 149 | * The lookup key for an int that provides information about |
| 150 | * our connection to the internet at large. 0 indicates no connection, |
| 151 | * 100 indicates a great connection. Retrieve it with |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 152 | * {@link android.content.Intent#getIntExtra(String, int)}. |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 153 | * {@hide} |
| 154 | */ |
| 155 | public static final String EXTRA_INET_CONDITION = "inetCondition"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
| 157 | /** |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 158 | * Broadcast action to indicate the change of data activity status |
| 159 | * (idle or active) on a network in a recent period. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 160 | * The network becomes active when data transmission is started, or |
| 161 | * idle if there is no data transmission for a period of time. |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 162 | * {@hide} |
| 163 | */ |
| 164 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 165 | public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE"; |
| 166 | /** |
| 167 | * The lookup key for an enum that indicates the network device type on which this data activity |
| 168 | * change happens. |
| 169 | * {@hide} |
| 170 | */ |
| 171 | public static final String EXTRA_DEVICE_TYPE = "deviceType"; |
| 172 | /** |
| 173 | * The lookup key for a boolean that indicates the device is active or not. {@code true} means |
| 174 | * it is actively sending or receiving data and {@code false} means it is idle. |
| 175 | * {@hide} |
| 176 | */ |
| 177 | public static final String EXTRA_IS_ACTIVE = "isActive"; |
Ashish Sharma | 0535a9f | 2014-03-12 18:42:23 -0700 | [diff] [blame] | 178 | /** |
| 179 | * The lookup key for a long that contains the timestamp (nanos) of the radio state change. |
| 180 | * {@hide} |
| 181 | */ |
| 182 | public static final String EXTRA_REALTIME_NS = "tsNanos"; |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | * Broadcast Action: The setting for background data usage has changed |
| 186 | * values. Use {@link #getBackgroundDataSetting()} to get the current value. |
| 187 | * <p> |
| 188 | * If an application uses the network in the background, it should listen |
| 189 | * for this broadcast and stop using the background data if the value is |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 190 | * {@code false}. |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 191 | * <p> |
| 192 | * |
| 193 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability |
| 194 | * of background data depends on several combined factors, and |
| 195 | * this broadcast is no longer sent. Instead, when background |
| 196 | * data is unavailable, {@link #getActiveNetworkInfo()} will now |
| 197 | * appear disconnected. During first boot after a platform |
| 198 | * upgrade, this broadcast will be sent once if |
| 199 | * {@link #getBackgroundDataSetting()} was {@code false} before |
| 200 | * the upgrade. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | */ |
| 202 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 203 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = |
| 205 | "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; |
| 206 | |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 207 | /** |
| 208 | * Broadcast Action: The network connection may not be good |
| 209 | * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and |
| 210 | * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify |
| 211 | * the network and it's condition. |
| 212 | * @hide |
| 213 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 214 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 215 | public static final String INET_CONDITION_ACTION = |
| 216 | "android.net.conn.INET_CONDITION_ACTION"; |
| 217 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 218 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 219 | * Broadcast Action: A tetherable connection has come or gone. |
| 220 | * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER}, |
| 221 | * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and |
| 222 | * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate |
| 223 | * the current state of tethering. Each include a list of |
| 224 | * interface names in that state (may be empty). |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 225 | * @hide |
| 226 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 227 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 228 | public static final String ACTION_TETHER_STATE_CHANGED = |
| 229 | "android.net.conn.TETHER_STATE_CHANGED"; |
| 230 | |
| 231 | /** |
| 232 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 233 | * gives a String[] listing all the interfaces configured for |
| 234 | * tethering and currently available for tethering. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 235 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 236 | public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 240 | * gives a String[] listing all the interfaces currently tethered |
| 241 | * (ie, has dhcp support and packets potentially forwarded/NATed) |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 242 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 243 | public static final String EXTRA_ACTIVE_TETHER = "activeArray"; |
| 244 | |
| 245 | /** |
| 246 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 247 | * gives a String[] listing all the interfaces we tried to tether and |
| 248 | * failed. Use {@link #getLastTetherError} to find the error code |
| 249 | * for any interfaces listed here. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 250 | */ |
| 251 | public static final String EXTRA_ERRORED_TETHER = "erroredArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 252 | |
| 253 | /** |
Russell Brenner | 108da0c | 2013-02-12 10:03:14 -0800 | [diff] [blame] | 254 | * Broadcast Action: The captive portal tracker has finished its test. |
| 255 | * Sent only while running Setup Wizard, in lieu of showing a user |
| 256 | * notification. |
| 257 | * @hide |
| 258 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 259 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Russell Brenner | 108da0c | 2013-02-12 10:03:14 -0800 | [diff] [blame] | 260 | public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED = |
| 261 | "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED"; |
| 262 | /** |
| 263 | * The lookup key for a boolean that indicates whether a captive portal was detected. |
| 264 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 265 | * @hide |
| 266 | */ |
| 267 | public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal"; |
| 268 | |
| 269 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 270 | * The absence of a connection type. |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 271 | * @hide |
| 272 | */ |
| 273 | public static final int TYPE_NONE = -1; |
| 274 | |
| 275 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 276 | * The Mobile data connection. When active, all data traffic |
| 277 | * will use this network type's interface by default |
| 278 | * (it has a default route) |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 279 | */ |
| 280 | public static final int TYPE_MOBILE = 0; |
| 281 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 282 | * The WIFI data connection. When active, all data traffic |
| 283 | * will use this network type's interface by default |
| 284 | * (it has a default route). |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 285 | */ |
| 286 | public static final int TYPE_WIFI = 1; |
| 287 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 288 | * An MMS-specific Mobile data connection. This network type may use the |
| 289 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 290 | * one. This is used by applications needing to talk to the carrier's |
| 291 | * Multimedia Messaging Service servers. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 292 | */ |
| 293 | public static final int TYPE_MOBILE_MMS = 2; |
| 294 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 295 | * A SUPL-specific Mobile data connection. This network type may use the |
| 296 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 297 | * one. This is used by applications needing to talk to the carrier's |
| 298 | * Secure User Plane Location servers for help locating the device. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 299 | */ |
| 300 | public static final int TYPE_MOBILE_SUPL = 3; |
| 301 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 302 | * A DUN-specific Mobile data connection. This network type may use the |
| 303 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 304 | * one. This is sometimes by the system when setting up an upstream connection |
| 305 | * for tethering so that the carrier is aware of DUN traffic. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 306 | */ |
| 307 | public static final int TYPE_MOBILE_DUN = 4; |
| 308 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 309 | * A High Priority Mobile data connection. This network type uses the |
| 310 | * same network interface as {@link #TYPE_MOBILE} but the routing setup |
| 311 | * is different. Only requesting processes will have access to the |
| 312 | * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost} |
| 313 | * will route over this interface if no default route exists. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 314 | */ |
| 315 | public static final int TYPE_MOBILE_HIPRI = 5; |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 316 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 317 | * The WiMAX data connection. When active, all data traffic |
| 318 | * will use this network type's interface by default |
| 319 | * (it has a default route). |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 320 | */ |
| 321 | public static final int TYPE_WIMAX = 6; |
Robert Greenwalt | da3d5e6 | 2010-12-06 13:56:24 -0800 | [diff] [blame] | 322 | |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 323 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 324 | * The Bluetooth data connection. When active, all data traffic |
| 325 | * will use this network type's interface by default |
| 326 | * (it has a default route). |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 327 | */ |
| 328 | public static final int TYPE_BLUETOOTH = 7; |
| 329 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 330 | /** |
| 331 | * Dummy data connection. This should not be used on shipping devices. |
| 332 | */ |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 333 | public static final int TYPE_DUMMY = 8; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 334 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 335 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 336 | * The Ethernet data connection. When active, all data traffic |
| 337 | * will use this network type's interface by default |
| 338 | * (it has a default route). |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 339 | */ |
Robert Greenwalt | e12aec9 | 2011-01-28 14:48:37 -0800 | [diff] [blame] | 340 | public static final int TYPE_ETHERNET = 9; |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 341 | |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 342 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 343 | * Over the air Administration. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 344 | * {@hide} |
| 345 | */ |
| 346 | public static final int TYPE_MOBILE_FOTA = 10; |
| 347 | |
| 348 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 349 | * IP Multimedia Subsystem. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 350 | * {@hide} |
| 351 | */ |
| 352 | public static final int TYPE_MOBILE_IMS = 11; |
| 353 | |
| 354 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 355 | * Carrier Branded Services. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 356 | * {@hide} |
| 357 | */ |
| 358 | public static final int TYPE_MOBILE_CBS = 12; |
| 359 | |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 360 | /** |
| 361 | * A Wi-Fi p2p connection. Only requesting processes will have access to |
| 362 | * the peers connected. |
| 363 | * {@hide} |
| 364 | */ |
| 365 | public static final int TYPE_WIFI_P2P = 13; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 366 | |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 367 | /** |
| 368 | * The network to use for initially attaching to the network |
| 369 | * {@hide} |
| 370 | */ |
| 371 | public static final int TYPE_MOBILE_IA = 14; |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 372 | |
Hui Lu | 1c5624a | 2014-01-15 11:05:36 -0500 | [diff] [blame] | 373 | /** |
| 374 | * The network that uses proxy to achieve connectivity. |
| 375 | * {@hide} |
| 376 | */ |
| 377 | public static final int TYPE_PROXY = 16; |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 378 | |
| 379 | /** {@hide} */ |
Hui Lu | 1c5624a | 2014-01-15 11:05:36 -0500 | [diff] [blame] | 380 | public static final int MAX_RADIO_TYPE = TYPE_PROXY; |
| 381 | |
| 382 | /** {@hide} */ |
| 383 | public static final int MAX_NETWORK_TYPE = TYPE_PROXY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 385 | /** |
| 386 | * If you want to set the default network preference,you can directly |
| 387 | * change the networkAttributes array in framework's config.xml. |
| 388 | * |
| 389 | * @deprecated Since we support so many more networks now, the single |
| 390 | * network default network preference can't really express |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 391 | * the hierarchy. Instead, the default is defined by the |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 392 | * networkAttributes in config.xml. You can determine |
Robert Greenwalt | 4c8b748 | 2012-12-07 09:56:50 -0800 | [diff] [blame] | 393 | * the current value by calling {@link #getNetworkPreference()} |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 394 | * from an App. |
| 395 | */ |
| 396 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; |
| 398 | |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 399 | /** |
| 400 | * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 401 | * milliseconds. This was introduced because IPv6 routes seem to take a |
| 402 | * moment to settle - trying network activity before the routes are adjusted |
| 403 | * can lead to packets using the wrong interface or having the wrong IP address. |
| 404 | * This delay is a bit crude, but in the future hopefully we will have kernel |
| 405 | * notifications letting us know when it's safe to use the new network. |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 406 | * |
| 407 | * @hide |
| 408 | */ |
| 409 | public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000; |
| 410 | |
Robert Greenwalt | 9ba9c58 | 2014-03-19 17:56:12 -0700 | [diff] [blame] | 411 | /** |
| 412 | * @hide |
| 413 | */ |
| 414 | public final static int INVALID_NET_ID = 0; |
| 415 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 416 | private final IConnectivityManager mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | |
Chad Brubaker | f81daa9 | 2014-02-14 13:22:34 -0800 | [diff] [blame] | 418 | private final String mPackageName; |
| 419 | |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 420 | private INetworkManagementService mNMService; |
| 421 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 422 | /** |
| 423 | * Tests if a given integer represents a valid network type. |
| 424 | * @param networkType the type to be tested |
| 425 | * @return a boolean. {@code true} if the type is valid, else {@code false} |
| 426 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 427 | public static boolean isNetworkTypeValid(int networkType) { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 428 | return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 431 | /** |
| 432 | * Returns a non-localized string representing a given network type. |
| 433 | * ONLY used for debugging output. |
| 434 | * @param type the type needing naming |
| 435 | * @return a String for the given type, or a string version of the type ("87") |
| 436 | * if no name is known. |
| 437 | * {@hide} |
| 438 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 439 | public static String getNetworkTypeName(int type) { |
| 440 | switch (type) { |
| 441 | case TYPE_MOBILE: |
| 442 | return "MOBILE"; |
| 443 | case TYPE_WIFI: |
| 444 | return "WIFI"; |
| 445 | case TYPE_MOBILE_MMS: |
| 446 | return "MOBILE_MMS"; |
| 447 | case TYPE_MOBILE_SUPL: |
| 448 | return "MOBILE_SUPL"; |
| 449 | case TYPE_MOBILE_DUN: |
| 450 | return "MOBILE_DUN"; |
| 451 | case TYPE_MOBILE_HIPRI: |
| 452 | return "MOBILE_HIPRI"; |
| 453 | case TYPE_WIMAX: |
| 454 | return "WIMAX"; |
| 455 | case TYPE_BLUETOOTH: |
| 456 | return "BLUETOOTH"; |
| 457 | case TYPE_DUMMY: |
| 458 | return "DUMMY"; |
| 459 | case TYPE_ETHERNET: |
| 460 | return "ETHERNET"; |
| 461 | case TYPE_MOBILE_FOTA: |
| 462 | return "MOBILE_FOTA"; |
| 463 | case TYPE_MOBILE_IMS: |
| 464 | return "MOBILE_IMS"; |
| 465 | case TYPE_MOBILE_CBS: |
| 466 | return "MOBILE_CBS"; |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 467 | case TYPE_WIFI_P2P: |
| 468 | return "WIFI_P2P"; |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 469 | case TYPE_MOBILE_IA: |
| 470 | return "MOBILE_IA"; |
Hui Lu | 1c5624a | 2014-01-15 11:05:36 -0500 | [diff] [blame] | 471 | case TYPE_PROXY: |
| 472 | return "PROXY"; |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 473 | default: |
| 474 | return Integer.toString(type); |
| 475 | } |
| 476 | } |
| 477 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 478 | /** |
| 479 | * Checks if a given type uses the cellular data connection. |
| 480 | * This should be replaced in the future by a network property. |
| 481 | * @param networkType the type to check |
| 482 | * @return a boolean - {@code true} if uses cellular network, else {@code false} |
| 483 | * {@hide} |
| 484 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 485 | public static boolean isNetworkTypeMobile(int networkType) { |
| 486 | switch (networkType) { |
| 487 | case TYPE_MOBILE: |
| 488 | case TYPE_MOBILE_MMS: |
| 489 | case TYPE_MOBILE_SUPL: |
| 490 | case TYPE_MOBILE_DUN: |
| 491 | case TYPE_MOBILE_HIPRI: |
| 492 | case TYPE_MOBILE_FOTA: |
| 493 | case TYPE_MOBILE_IMS: |
| 494 | case TYPE_MOBILE_CBS: |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 495 | case TYPE_MOBILE_IA: |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 496 | return true; |
| 497 | default: |
| 498 | return false; |
| 499 | } |
| 500 | } |
| 501 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 502 | /** |
Jeff Sharkey | 7a1c3fc | 2013-06-04 12:29:00 -0700 | [diff] [blame] | 503 | * Checks if the given network type is backed by a Wi-Fi radio. |
| 504 | * |
| 505 | * @hide |
| 506 | */ |
| 507 | public static boolean isNetworkTypeWifi(int networkType) { |
| 508 | switch (networkType) { |
| 509 | case TYPE_WIFI: |
| 510 | case TYPE_WIFI_P2P: |
| 511 | return true; |
| 512 | default: |
| 513 | return false; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /** |
Chad Brubaker | f336d72 | 2013-07-15 16:34:04 -0700 | [diff] [blame] | 518 | * Checks if the given network type should be exempt from VPN routing rules |
| 519 | * |
| 520 | * @hide |
| 521 | */ |
| 522 | public static boolean isNetworkTypeExempt(int networkType) { |
| 523 | switch (networkType) { |
| 524 | case TYPE_MOBILE_MMS: |
| 525 | case TYPE_MOBILE_SUPL: |
| 526 | case TYPE_MOBILE_HIPRI: |
Wink Saville | 5e56bc5 | 2013-07-29 15:00:57 -0700 | [diff] [blame] | 527 | case TYPE_MOBILE_IA: |
Chad Brubaker | f336d72 | 2013-07-15 16:34:04 -0700 | [diff] [blame] | 528 | return true; |
| 529 | default: |
| 530 | return false; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 535 | * Specifies the preferred network type. When the device has more |
| 536 | * than one type available the preferred network type will be used. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 537 | * |
| 538 | * @param preference the network type to prefer over all others. It is |
| 539 | * unspecified what happens to the old preferred network in the |
| 540 | * overall ordering. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 541 | * @Deprecated Functionality has been removed as it no longer makes sense, |
| 542 | * with many more than two networks - we'd need an array to express |
| 543 | * preference. Instead we use dynamic network properties of |
| 544 | * the networks to describe their precedence. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 545 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | public void setNetworkPreference(int preference) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 549 | /** |
| 550 | * Retrieves the current preferred network type. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 551 | * |
| 552 | * @return an integer representing the preferred network type |
| 553 | * |
| 554 | * <p>This method requires the caller to hold the permission |
| 555 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 556 | * @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 Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 560 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | public int getNetworkPreference() { |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 562 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Scott Main | 671644c | 2011-10-06 19:02:28 -0700 | [diff] [blame] | 565 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 566 | * Returns details about the currently active default data network. When |
| 567 | * connected, this network is the default route for outgoing connections. |
| 568 | * You should always check {@link NetworkInfo#isConnected()} before initiating |
| 569 | * network traffic. This may return {@code null} when there is no default |
| 570 | * network. |
| 571 | * |
| 572 | * @return a {@link NetworkInfo} object for the current default network |
| 573 | * or {@code null} if no network default network is currently active |
| 574 | * |
| 575 | * <p>This method requires the call to hold the permission |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 576 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 577 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | public NetworkInfo getActiveNetworkInfo() { |
| 579 | try { |
| 580 | return mService.getActiveNetworkInfo(); |
| 581 | } catch (RemoteException e) { |
| 582 | return null; |
| 583 | } |
| 584 | } |
| 585 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 586 | /** |
| 587 | * Returns details about the currently active default data network |
| 588 | * for a given uid. This is for internal use only to avoid spying |
| 589 | * other apps. |
| 590 | * |
| 591 | * @return a {@link NetworkInfo} object for the current default network |
| 592 | * for the given uid or {@code null} if no default network is |
| 593 | * available for the specified uid. |
| 594 | * |
| 595 | * <p>This method requires the caller to hold the permission |
| 596 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL} |
| 597 | * {@hide} |
| 598 | */ |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 599 | public NetworkInfo getActiveNetworkInfoForUid(int uid) { |
| 600 | try { |
| 601 | return mService.getActiveNetworkInfoForUid(uid); |
| 602 | } catch (RemoteException e) { |
| 603 | return null; |
| 604 | } |
| 605 | } |
| 606 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 607 | /** |
| 608 | * Returns connection status information about a particular |
| 609 | * network type. |
| 610 | * |
| 611 | * @param networkType integer specifying which networkType in |
| 612 | * which you're interested. |
| 613 | * @return a {@link NetworkInfo} object for the requested |
| 614 | * network type or {@code null} if the type is not |
| 615 | * supported by the device. |
| 616 | * |
| 617 | * <p>This method requires the call to hold the permission |
| 618 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 619 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | public NetworkInfo getNetworkInfo(int networkType) { |
| 621 | try { |
| 622 | return mService.getNetworkInfo(networkType); |
| 623 | } catch (RemoteException e) { |
| 624 | return null; |
| 625 | } |
| 626 | } |
| 627 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 628 | /** |
| 629 | * Returns connection status information about all network |
| 630 | * types supported by the device. |
| 631 | * |
| 632 | * @return an array of {@link NetworkInfo} objects. Check each |
| 633 | * {@link NetworkInfo#getType} for which type each applies. |
| 634 | * |
| 635 | * <p>This method requires the call to hold the permission |
| 636 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 637 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | public NetworkInfo[] getAllNetworkInfo() { |
| 639 | try { |
| 640 | return mService.getAllNetworkInfo(); |
| 641 | } catch (RemoteException e) { |
| 642 | return null; |
| 643 | } |
| 644 | } |
| 645 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 646 | /** |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 647 | * Returns details about the Provisioning or currently active default data network. When |
| 648 | * connected, this network is the default route for outgoing connections. |
| 649 | * You should always check {@link NetworkInfo#isConnected()} before initiating |
| 650 | * network traffic. This may return {@code null} when there is no default |
| 651 | * network. |
| 652 | * |
| 653 | * @return a {@link NetworkInfo} object for the current default network |
| 654 | * or {@code null} if no network default network is currently active |
| 655 | * |
| 656 | * <p>This method requires the call to hold the permission |
| 657 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 658 | * |
| 659 | * {@hide} |
| 660 | */ |
| 661 | public NetworkInfo getProvisioningOrActiveNetworkInfo() { |
| 662 | try { |
| 663 | return mService.getProvisioningOrActiveNetworkInfo(); |
| 664 | } catch (RemoteException e) { |
| 665 | return null; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 670 | * Returns the IP information for the current default network. |
| 671 | * |
| 672 | * @return a {@link LinkProperties} object describing the IP info |
| 673 | * for the current default network, or {@code null} if there |
| 674 | * is no current default network. |
| 675 | * |
| 676 | * <p>This method requires the call to hold the permission |
| 677 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 678 | * {@hide} |
| 679 | */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 680 | public LinkProperties getActiveLinkProperties() { |
| 681 | try { |
| 682 | return mService.getActiveLinkProperties(); |
| 683 | } catch (RemoteException e) { |
| 684 | return null; |
| 685 | } |
| 686 | } |
| 687 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 688 | /** |
| 689 | * Returns the IP information for a given network type. |
| 690 | * |
| 691 | * @param networkType the network type of interest. |
| 692 | * @return a {@link LinkProperties} object describing the IP info |
| 693 | * for the given networkType, or {@code null} if there is |
| 694 | * no current default network. |
| 695 | * |
| 696 | * <p>This method requires the call to hold the permission |
| 697 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 698 | * {@hide} |
| 699 | */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 700 | public LinkProperties getLinkProperties(int networkType) { |
| 701 | try { |
| 702 | return mService.getLinkProperties(networkType); |
| 703 | } catch (RemoteException e) { |
| 704 | return null; |
| 705 | } |
| 706 | } |
| 707 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 708 | /** |
| 709 | * Tells each network type to set its radio power state as directed. |
| 710 | * |
| 711 | * @param turnOn a boolean, {@code true} to turn the radios on, |
| 712 | * {@code false} to turn them off. |
| 713 | * @return a boolean, {@code true} indicating success. All network types |
| 714 | * will be tried, even if some fail. |
| 715 | * |
| 716 | * <p>This method requires the call to hold the permission |
| 717 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
| 718 | * {@hide} |
| 719 | */ |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 720 | // TODO - check for any callers and remove |
| 721 | // public boolean setRadios(boolean turnOn) { |
| 722 | // try { |
| 723 | // return mService.setRadios(turnOn); |
| 724 | // } catch (RemoteException e) { |
| 725 | // return false; |
| 726 | // } |
| 727 | // } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 729 | /** |
| 730 | * Tells a given networkType to set its radio power state as directed. |
| 731 | * |
| 732 | * @param networkType the int networkType of interest. |
| 733 | * @param turnOn a boolean, {@code true} to turn the radio on, |
| 734 | * {@code} false to turn it off. |
| 735 | * @return a boolean, {@code true} indicating success. |
| 736 | * |
| 737 | * <p>This method requires the call to hold the permission |
| 738 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
| 739 | * {@hide} |
| 740 | */ |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 741 | // TODO - check for any callers and remove |
| 742 | // public boolean setRadio(int networkType, boolean turnOn) { |
| 743 | // try { |
| 744 | // return mService.setRadio(networkType, turnOn); |
| 745 | // } catch (RemoteException e) { |
| 746 | // return false; |
| 747 | // } |
| 748 | // } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | |
| 750 | /** |
| 751 | * Tells the underlying networking system that the caller wants to |
| 752 | * begin using the named feature. The interpretation of {@code feature} |
| 753 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 754 | * <p>This method requires the caller to hold the permission |
| 755 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | * @param networkType specifies which network the request pertains to |
| 757 | * @param feature the name of the feature to be used |
| 758 | * @return an integer value representing the outcome of the request. |
| 759 | * The interpretation of this value is specific to each networking |
| 760 | * implementation+feature combination, except that the value {@code -1} |
| 761 | * always indicates failure. |
| 762 | */ |
| 763 | public int startUsingNetworkFeature(int networkType, String feature) { |
| 764 | try { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 765 | return mService.startUsingNetworkFeature(networkType, feature, |
| 766 | new Binder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | } catch (RemoteException e) { |
| 768 | return -1; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Tells the underlying networking system that the caller is finished |
| 774 | * using the named feature. The interpretation of {@code feature} |
| 775 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 776 | * <p>This method requires the caller to hold the permission |
| 777 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | * @param networkType specifies which network the request pertains to |
| 779 | * @param feature the name of the feature that is no longer needed |
| 780 | * @return an integer value representing the outcome of the request. |
| 781 | * The interpretation of this value is specific to each networking |
| 782 | * implementation+feature combination, except that the value {@code -1} |
| 783 | * always indicates failure. |
| 784 | */ |
| 785 | public int stopUsingNetworkFeature(int networkType, String feature) { |
| 786 | try { |
| 787 | return mService.stopUsingNetworkFeature(networkType, feature); |
| 788 | } catch (RemoteException e) { |
| 789 | return -1; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Ensure that a network route exists to deliver traffic to the specified |
| 795 | * host via the specified network interface. An attempt to add a route that |
| 796 | * already exists is ignored, but treated as successful. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 797 | * <p>This method requires the caller to hold the permission |
| 798 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | * @param networkType the type of the network over which traffic to the specified |
| 800 | * host is to be routed |
| 801 | * @param hostAddress the IP address of the host to which the route is desired |
| 802 | * @return {@code true} on success, {@code false} on failure |
| 803 | */ |
| 804 | public boolean requestRouteToHost(int networkType, int hostAddress) { |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 805 | InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); |
| 806 | |
| 807 | if (inetAddress == null) { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | return requestRouteToHostAddress(networkType, inetAddress); |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Ensure that a network route exists to deliver traffic to the specified |
| 816 | * host via the specified network interface. An attempt to add a route that |
| 817 | * already exists is ignored, but treated as successful. |
Jake Hamby | 8f9b33e | 2014-01-15 13:08:03 -0800 | [diff] [blame] | 818 | * <p>This method requires the caller to hold the permission |
| 819 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 820 | * @param networkType the type of the network over which traffic to the specified |
| 821 | * host is to be routed |
| 822 | * @param hostAddress the IP address of the host to which the route is desired |
| 823 | * @return {@code true} on success, {@code false} on failure |
| 824 | * @hide |
| 825 | */ |
| 826 | public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { |
| 827 | byte[] address = hostAddress.getAddress(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | try { |
Chad Brubaker | f81daa9 | 2014-02-14 13:22:34 -0800 | [diff] [blame] | 829 | return mService.requestRouteToHostAddress(networkType, address, mPackageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | } catch (RemoteException e) { |
| 831 | return false; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /** |
| 836 | * Returns the value of the setting for background data usage. If false, |
| 837 | * applications should not use the network if the application is not in the |
| 838 | * foreground. Developers should respect this setting, and check the value |
| 839 | * of this before performing any background data operations. |
| 840 | * <p> |
| 841 | * All applications that have background services that use the network |
| 842 | * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 843 | * <p> |
Scott Main | 4cc5333 | 2011-10-06 18:32:43 -0700 | [diff] [blame] | 844 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 845 | * background data depends on several combined factors, and this method will |
| 846 | * always return {@code true}. Instead, when background data is unavailable, |
| 847 | * {@link #getActiveNetworkInfo()} will now appear disconnected. |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 848 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | * @return Whether background data usage is allowed. |
| 850 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 851 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | public boolean getBackgroundDataSetting() { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 853 | // assume that background data is allowed; final authority is |
| 854 | // NetworkInfo which may be blocked. |
| 855 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Sets the value of the setting for background data usage. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 860 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | * @param allowBackgroundData Whether an application should use data while |
| 862 | * it is in the background. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 863 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING |
| 865 | * @see #getBackgroundDataSetting() |
| 866 | * @hide |
| 867 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 868 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | public void setBackgroundDataSetting(boolean allowBackgroundData) { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 870 | // ignored |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | } |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 872 | |
| 873 | /** |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 874 | * Return quota status for the current active network, or {@code null} if no |
| 875 | * network is active. Quota status can change rapidly, so these values |
| 876 | * shouldn't be cached. |
Jeff Sharkey | 44a3e0d | 2011-10-06 10:50:09 -0700 | [diff] [blame] | 877 | * |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 878 | * <p>This method requires the call to hold the permission |
| 879 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 880 | * |
Jeff Sharkey | 44a3e0d | 2011-10-06 10:50:09 -0700 | [diff] [blame] | 881 | * @hide |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 882 | */ |
| 883 | public NetworkQuotaInfo getActiveNetworkQuotaInfo() { |
| 884 | try { |
| 885 | return mService.getActiveNetworkQuotaInfo(); |
| 886 | } catch (RemoteException e) { |
| 887 | return null; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | /** |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 892 | * Gets the value of the setting for enabling Mobile data. |
| 893 | * |
| 894 | * @return Whether mobile data is enabled. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 895 | * |
| 896 | * <p>This method requires the call to hold the permission |
| 897 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 898 | * @hide |
| 899 | */ |
| 900 | public boolean getMobileDataEnabled() { |
| 901 | try { |
| 902 | return mService.getMobileDataEnabled(); |
| 903 | } catch (RemoteException e) { |
| 904 | return true; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Sets the persisted value for enabling/disabling Mobile data. |
| 910 | * |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 911 | * @param enabled Whether the user wants the mobile data connection used |
| 912 | * or not. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 913 | * @hide |
| 914 | */ |
| 915 | public void setMobileDataEnabled(boolean enabled) { |
| 916 | try { |
| 917 | mService.setMobileDataEnabled(enabled); |
| 918 | } catch (RemoteException e) { |
| 919 | } |
| 920 | } |
| 921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | /** |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 923 | * Callback for use with {@link ConnectivityManager#registerNetworkActiveListener} to |
| 924 | * find out when the current network has gone in to a high power state. |
| 925 | */ |
| 926 | public interface OnNetworkActiveListener { |
| 927 | /** |
| 928 | * Called on the main thread of the process to report that the current data network |
| 929 | * has become active, and it is now a good time to perform any pending network |
| 930 | * operations. Note that this listener only tells you when the network becomes |
| 931 | * active; if at any other time you want to know whether it is active (and thus okay |
| 932 | * to initiate network traffic), you can retrieve its instantaneous state with |
| 933 | * {@link ConnectivityManager#isNetworkActive}. |
| 934 | */ |
| 935 | public void onNetworkActive(); |
| 936 | } |
| 937 | |
| 938 | private INetworkManagementService getNetworkManagementService() { |
| 939 | synchronized (this) { |
| 940 | if (mNMService != null) { |
| 941 | return mNMService; |
| 942 | } |
| 943 | IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); |
| 944 | mNMService = INetworkManagementService.Stub.asInterface(b); |
| 945 | return mNMService; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | private final ArrayMap<OnNetworkActiveListener, INetworkActivityListener> |
| 950 | mNetworkActivityListeners |
| 951 | = new ArrayMap<OnNetworkActiveListener, INetworkActivityListener>(); |
| 952 | |
| 953 | /** |
| 954 | * Start listening to reports when the data network is active, meaning it is |
| 955 | * a good time to perform network traffic. Use {@link #isNetworkActive()} |
| 956 | * to determine the current state of the network after registering the listener. |
| 957 | * |
| 958 | * @param l The listener to be told when the network is active. |
| 959 | */ |
| 960 | public void registerNetworkActiveListener(final OnNetworkActiveListener l) { |
| 961 | INetworkActivityListener rl = new INetworkActivityListener.Stub() { |
| 962 | @Override |
| 963 | public void onNetworkActive() throws RemoteException { |
| 964 | l.onNetworkActive(); |
| 965 | } |
| 966 | }; |
| 967 | |
| 968 | try { |
| 969 | getNetworkManagementService().registerNetworkActivityListener(rl); |
| 970 | mNetworkActivityListeners.put(l, rl); |
| 971 | } catch (RemoteException e) { |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Remove network active listener previously registered with |
| 977 | * {@link #registerNetworkActiveListener}. |
| 978 | * |
| 979 | * @param l Previously registered listener. |
| 980 | */ |
| 981 | public void unregisterNetworkActiveListener(OnNetworkActiveListener l) { |
| 982 | INetworkActivityListener rl = mNetworkActivityListeners.get(l); |
| 983 | if (rl == null) { |
| 984 | throw new IllegalArgumentException("Listener not registered: " + l); |
| 985 | } |
| 986 | try { |
| 987 | getNetworkManagementService().unregisterNetworkActivityListener(rl); |
| 988 | } catch (RemoteException e) { |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * Return whether the data network is currently active. An active network means that |
| 994 | * it is currently in a high power state for performing data transmission. On some |
| 995 | * types of networks, it may be expensive to move and stay in such a state, so it is |
| 996 | * more power efficient to batch network traffic together when the radio is already in |
| 997 | * this state. This method tells you whether right now is currently a good time to |
| 998 | * initiate network traffic, as the network is already active. |
| 999 | */ |
| 1000 | public boolean isNetworkActive() { |
| 1001 | try { |
| 1002 | return getNetworkManagementService().isNetworkActive(); |
| 1003 | } catch (RemoteException e) { |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | * {@hide} |
| 1010 | */ |
Chad Brubaker | f81daa9 | 2014-02-14 13:22:34 -0800 | [diff] [blame] | 1011 | public ConnectivityManager(IConnectivityManager service, String packageName) { |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 1012 | mService = checkNotNull(service, "missing IConnectivityManager"); |
Chad Brubaker | f81daa9 | 2014-02-14 13:22:34 -0800 | [diff] [blame] | 1013 | mPackageName = checkNotNull(packageName, "missing package name"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1015 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 1016 | /** {@hide} */ |
| 1017 | public static ConnectivityManager from(Context context) { |
| 1018 | return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 1019 | } |
| 1020 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1021 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1022 | * Get the set of tetherable, available interfaces. This list is limited by |
| 1023 | * device configuration and current interface existence. |
| 1024 | * |
| 1025 | * @return an array of 0 or more Strings of tetherable interface names. |
| 1026 | * |
| 1027 | * <p>This method requires the call to hold the permission |
| 1028 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1029 | * {@hide} |
| 1030 | */ |
| 1031 | public String[] getTetherableIfaces() { |
| 1032 | try { |
| 1033 | return mService.getTetherableIfaces(); |
| 1034 | } catch (RemoteException e) { |
| 1035 | return new String[0]; |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1040 | * Get the set of tethered interfaces. |
| 1041 | * |
| 1042 | * @return an array of 0 or more String of currently tethered interface names. |
| 1043 | * |
| 1044 | * <p>This method requires the call to hold the permission |
| 1045 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1046 | * {@hide} |
| 1047 | */ |
| 1048 | public String[] getTetheredIfaces() { |
| 1049 | try { |
| 1050 | return mService.getTetheredIfaces(); |
| 1051 | } catch (RemoteException e) { |
| 1052 | return new String[0]; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1057 | * Get the set of interface names which attempted to tether but |
| 1058 | * failed. Re-attempting to tether may cause them to reset to the Tethered |
| 1059 | * state. Alternatively, causing the interface to be destroyed and recreated |
| 1060 | * may cause them to reset to the available state. |
| 1061 | * {@link ConnectivityManager#getLastTetherError} can be used to get more |
| 1062 | * information on the cause of the errors. |
| 1063 | * |
| 1064 | * @return an array of 0 or more String indicating the interface names |
| 1065 | * which failed to tether. |
| 1066 | * |
| 1067 | * <p>This method requires the call to hold the permission |
| 1068 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1069 | * {@hide} |
| 1070 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1071 | public String[] getTetheringErroredIfaces() { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1072 | try { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1073 | return mService.getTetheringErroredIfaces(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1074 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1075 | return new String[0]; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1080 | * Attempt to tether the named interface. This will setup a dhcp server |
| 1081 | * on the interface, forward and NAT IP packets and forward DNS requests |
| 1082 | * to the best active upstream network interface. Note that if no upstream |
| 1083 | * IP network interface is available, dhcp will still run and traffic will be |
| 1084 | * allowed between the tethered devices and this device, though upstream net |
| 1085 | * access will of course fail until an upstream network interface becomes |
| 1086 | * active. |
| 1087 | * |
| 1088 | * @param iface the interface name to tether. |
| 1089 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 1090 | * |
| 1091 | * <p>This method requires the call to hold the permission |
| 1092 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1093 | * {@hide} |
| 1094 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1095 | public int tether(String iface) { |
| 1096 | try { |
| 1097 | return mService.tether(iface); |
| 1098 | } catch (RemoteException e) { |
| 1099 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1104 | * Stop tethering the named interface. |
| 1105 | * |
| 1106 | * @param iface the interface name to untether. |
| 1107 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 1108 | * |
| 1109 | * <p>This method requires the call to hold the permission |
| 1110 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1111 | * {@hide} |
| 1112 | */ |
| 1113 | public int untether(String iface) { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1114 | try { |
| 1115 | return mService.untether(iface); |
| 1116 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1117 | return TETHER_ERROR_SERVICE_UNAVAIL; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1118 | } |
| 1119 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1120 | |
| 1121 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1122 | * Check if the device allows for tethering. It may be disabled via |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1123 | * {@code ro.tether.denied} system property, Settings.TETHER_SUPPORTED or |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1124 | * due to device configuration. |
| 1125 | * |
| 1126 | * @return a boolean - {@code true} indicating Tethering is supported. |
| 1127 | * |
| 1128 | * <p>This method requires the call to hold the permission |
| 1129 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1130 | * {@hide} |
| 1131 | */ |
| 1132 | public boolean isTetheringSupported() { |
| 1133 | try { |
| 1134 | return mService.isTetheringSupported(); |
| 1135 | } catch (RemoteException e) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1141 | * Get the list of regular expressions that define any tetherable |
| 1142 | * USB network interfaces. If USB tethering is not supported by the |
| 1143 | * device, this list should be empty. |
| 1144 | * |
| 1145 | * @return an array of 0 or more regular expression Strings defining |
| 1146 | * what interfaces are considered tetherable usb interfaces. |
| 1147 | * |
| 1148 | * <p>This method requires the call to hold the permission |
| 1149 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1150 | * {@hide} |
| 1151 | */ |
| 1152 | public String[] getTetherableUsbRegexs() { |
| 1153 | try { |
| 1154 | return mService.getTetherableUsbRegexs(); |
| 1155 | } catch (RemoteException e) { |
| 1156 | return new String[0]; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1161 | * Get the list of regular expressions that define any tetherable |
| 1162 | * Wifi network interfaces. If Wifi tethering is not supported by the |
| 1163 | * device, this list should be empty. |
| 1164 | * |
| 1165 | * @return an array of 0 or more regular expression Strings defining |
| 1166 | * what interfaces are considered tetherable wifi interfaces. |
| 1167 | * |
| 1168 | * <p>This method requires the call to hold the permission |
| 1169 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1170 | * {@hide} |
| 1171 | */ |
| 1172 | public String[] getTetherableWifiRegexs() { |
| 1173 | try { |
| 1174 | return mService.getTetherableWifiRegexs(); |
| 1175 | } catch (RemoteException e) { |
| 1176 | return new String[0]; |
| 1177 | } |
| 1178 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1179 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1180 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1181 | * Get the list of regular expressions that define any tetherable |
| 1182 | * Bluetooth network interfaces. If Bluetooth tethering is not supported by the |
| 1183 | * device, this list should be empty. |
| 1184 | * |
| 1185 | * @return an array of 0 or more regular expression Strings defining |
| 1186 | * what interfaces are considered tetherable bluetooth interfaces. |
| 1187 | * |
| 1188 | * <p>This method requires the call to hold the permission |
| 1189 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1190 | * {@hide} |
| 1191 | */ |
| 1192 | public String[] getTetherableBluetoothRegexs() { |
| 1193 | try { |
| 1194 | return mService.getTetherableBluetoothRegexs(); |
| 1195 | } catch (RemoteException e) { |
| 1196 | return new String[0]; |
| 1197 | } |
| 1198 | } |
| 1199 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 1200 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1201 | * Attempt to both alter the mode of USB and Tethering of USB. A |
| 1202 | * utility method to deal with some of the complexity of USB - will |
| 1203 | * attempt to switch to Rndis and subsequently tether the resulting |
| 1204 | * interface on {@code true} or turn off tethering and switch off |
| 1205 | * Rndis on {@code false}. |
| 1206 | * |
| 1207 | * @param enable a boolean - {@code true} to enable tethering |
| 1208 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 1209 | * |
| 1210 | * <p>This method requires the call to hold the permission |
| 1211 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 1212 | * {@hide} |
| 1213 | */ |
| 1214 | public int setUsbTethering(boolean enable) { |
| 1215 | try { |
| 1216 | return mService.setUsbTethering(enable); |
| 1217 | } catch (RemoteException e) { |
| 1218 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1222 | /** {@hide} */ |
| 1223 | public static final int TETHER_ERROR_NO_ERROR = 0; |
| 1224 | /** {@hide} */ |
| 1225 | public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; |
| 1226 | /** {@hide} */ |
| 1227 | public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; |
| 1228 | /** {@hide} */ |
| 1229 | public static final int TETHER_ERROR_UNSUPPORTED = 3; |
| 1230 | /** {@hide} */ |
| 1231 | public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; |
| 1232 | /** {@hide} */ |
| 1233 | public static final int TETHER_ERROR_MASTER_ERROR = 5; |
| 1234 | /** {@hide} */ |
| 1235 | public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; |
| 1236 | /** {@hide} */ |
| 1237 | public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; |
| 1238 | /** {@hide} */ |
| 1239 | public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; |
| 1240 | /** {@hide} */ |
| 1241 | public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; |
| 1242 | /** {@hide} */ |
| 1243 | public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; |
| 1244 | |
| 1245 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1246 | * Get a more detailed error code after a Tethering or Untethering |
| 1247 | * request asynchronously failed. |
| 1248 | * |
| 1249 | * @param iface The name of the interface of interest |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1250 | * @return error The error code of the last error tethering or untethering the named |
| 1251 | * interface |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1252 | * |
| 1253 | * <p>This method requires the call to hold the permission |
| 1254 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1255 | * {@hide} |
| 1256 | */ |
| 1257 | public int getLastTetherError(String iface) { |
| 1258 | try { |
| 1259 | return mService.getLastTetherError(iface); |
| 1260 | } catch (RemoteException e) { |
| 1261 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 1262 | } |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1266 | * Try to ensure the device stays awake until we connect with the next network. |
| 1267 | * Actually just holds a wakelock for a number of seconds while we try to connect |
| 1268 | * to any default networks. This will expire if the timeout passes or if we connect |
| 1269 | * to a default after this is called. For internal use only. |
| 1270 | * |
| 1271 | * @param forWhom the name of the network going down for logging purposes |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1272 | * @return {@code true} on success, {@code false} on failure |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1273 | * |
| 1274 | * <p>This method requires the call to hold the permission |
| 1275 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1276 | * {@hide} |
| 1277 | */ |
| 1278 | public boolean requestNetworkTransitionWakelock(String forWhom) { |
| 1279 | try { |
| 1280 | mService.requestNetworkTransitionWakelock(forWhom); |
| 1281 | return true; |
| 1282 | } catch (RemoteException e) { |
| 1283 | return false; |
| 1284 | } |
| 1285 | } |
Robert Greenwalt | ca4306c | 2010-09-09 13:15:32 -0700 | [diff] [blame] | 1286 | |
Robert Greenwalt | 67fd6c9 | 2010-09-09 14:22:59 -0700 | [diff] [blame] | 1287 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1288 | * Report network connectivity status. This is currently used only |
| 1289 | * to alter status bar UI. |
| 1290 | * |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 1291 | * @param networkType The type of network you want to report on |
| 1292 | * @param percentage The quality of the connection 0 is bad, 100 is good |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1293 | * |
| 1294 | * <p>This method requires the call to hold the permission |
| 1295 | * {@link android.Manifest.permission#STATUS_BAR}. |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 1296 | * {@hide} |
| 1297 | */ |
| 1298 | public void reportInetCondition(int networkType, int percentage) { |
| 1299 | try { |
| 1300 | mService.reportInetCondition(networkType, percentage); |
| 1301 | } catch (RemoteException e) { |
| 1302 | } |
| 1303 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1304 | |
| 1305 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1306 | * Set a network-independent global http proxy. This is not normally what you want |
| 1307 | * for typical HTTP proxies - they are general network dependent. However if you're |
| 1308 | * doing something unusual like general internal filtering this may be useful. On |
| 1309 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1310 | * |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1311 | * @param p The a {@link ProxyInfo} object defining the new global |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1312 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1313 | * |
| 1314 | * <p>This method requires the call to hold the permission |
Jason Monk | faf3fd5 | 2014-05-07 18:41:13 -0400 | [diff] [blame] | 1315 | * android.Manifest.permission#CONNECTIVITY_INTERNAL. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1316 | */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1317 | public void setGlobalProxy(ProxyInfo p) { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1318 | try { |
| 1319 | mService.setGlobalProxy(p); |
| 1320 | } catch (RemoteException e) { |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1325 | * Retrieve any network-independent global HTTP proxy. |
| 1326 | * |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1327 | * @return {@link ProxyInfo} for the current global HTTP proxy or {@code null} |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1328 | * if no global HTTP proxy is set. |
| 1329 | * |
| 1330 | * <p>This method requires the call to hold the permission |
| 1331 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1332 | */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1333 | public ProxyInfo getGlobalProxy() { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1334 | try { |
| 1335 | return mService.getGlobalProxy(); |
| 1336 | } catch (RemoteException e) { |
| 1337 | return null; |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1342 | * Get the HTTP proxy settings for the current default network. Note that |
| 1343 | * if a global proxy is set, it will override any per-network setting. |
| 1344 | * |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1345 | * @return the {@link ProxyInfo} for the current HTTP proxy, or {@code null} if no |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1346 | * HTTP proxy is active. |
| 1347 | * |
| 1348 | * <p>This method requires the call to hold the permission |
| 1349 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1350 | * {@hide} |
| 1351 | */ |
Jason Monk | 207900c | 2014-04-25 15:00:09 -0400 | [diff] [blame] | 1352 | public ProxyInfo getProxy() { |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1353 | try { |
| 1354 | return mService.getProxy(); |
| 1355 | } catch (RemoteException e) { |
| 1356 | return null; |
| 1357 | } |
| 1358 | } |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1359 | |
| 1360 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1361 | * Sets a secondary requirement bit for the given networkType. |
| 1362 | * This requirement bit is generally under the control of the carrier |
| 1363 | * or its agents and is not directly controlled by the user. |
| 1364 | * |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1365 | * @param networkType The network who's dependence has changed |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1366 | * @param met Boolean - true if network use is OK, false if not |
| 1367 | * |
| 1368 | * <p>This method requires the call to hold the permission |
| 1369 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1370 | * {@hide} |
| 1371 | */ |
| 1372 | public void setDataDependency(int networkType, boolean met) { |
| 1373 | try { |
| 1374 | mService.setDataDependency(networkType, met); |
| 1375 | } catch (RemoteException e) { |
| 1376 | } |
| 1377 | } |
Robert Greenwalt | 9b2886e | 2011-08-31 11:46:42 -0700 | [diff] [blame] | 1378 | |
| 1379 | /** |
| 1380 | * Returns true if the hardware supports the given network type |
| 1381 | * else it returns false. This doesn't indicate we have coverage |
| 1382 | * or are authorized onto a network, just whether or not the |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1383 | * hardware supports it. For example a GSM phone without a SIM |
| 1384 | * should still return {@code true} for mobile data, but a wifi only |
| 1385 | * tablet would return {@code false}. |
| 1386 | * |
| 1387 | * @param networkType The network type we'd like to check |
| 1388 | * @return {@code true} if supported, else {@code false} |
| 1389 | * |
| 1390 | * <p>This method requires the call to hold the permission |
| 1391 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 9b2886e | 2011-08-31 11:46:42 -0700 | [diff] [blame] | 1392 | * @hide |
| 1393 | */ |
| 1394 | public boolean isNetworkSupported(int networkType) { |
| 1395 | try { |
| 1396 | return mService.isNetworkSupported(networkType); |
| 1397 | } catch (RemoteException e) {} |
| 1398 | return false; |
| 1399 | } |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 1400 | |
| 1401 | /** |
| 1402 | * Returns if the currently active data network is metered. A network is |
| 1403 | * classified as metered when the user is sensitive to heavy data usage on |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1404 | * that connection due to monetary costs, data limitations or |
| 1405 | * battery/performance issues. You should check this before doing large |
| 1406 | * data transfers, and warn the user or delay the operation until another |
| 1407 | * network is available. |
| 1408 | * |
| 1409 | * @return {@code true} if large transfers should be avoided, otherwise |
| 1410 | * {@code false}. |
| 1411 | * |
| 1412 | * <p>This method requires the call to hold the permission |
| 1413 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 1414 | */ |
| 1415 | public boolean isActiveNetworkMetered() { |
| 1416 | try { |
| 1417 | return mService.isActiveNetworkMetered(); |
| 1418 | } catch (RemoteException e) { |
| 1419 | return false; |
| 1420 | } |
| 1421 | } |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 1422 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1423 | /** |
| 1424 | * If the LockdownVpn mechanism is enabled, updates the vpn |
| 1425 | * with a reload of its profile. |
| 1426 | * |
| 1427 | * @return a boolean with {@code} indicating success |
| 1428 | * |
| 1429 | * <p>This method can only be called by the system UID |
| 1430 | * {@hide} |
| 1431 | */ |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 1432 | public boolean updateLockdownVpn() { |
| 1433 | try { |
| 1434 | return mService.updateLockdownVpn(); |
| 1435 | } catch (RemoteException e) { |
| 1436 | return false; |
| 1437 | } |
| 1438 | } |
Irfan Sheriff | da6da09 | 2012-08-16 12:49:23 -0700 | [diff] [blame] | 1439 | |
| 1440 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame] | 1441 | * Signal that the captive portal check on the indicated network |
Wink Saville | d747cbc | 2013-08-07 16:22:47 -0700 | [diff] [blame] | 1442 | * is complete and whether its a captive portal or not. |
| 1443 | * |
| 1444 | * @param info the {@link NetworkInfo} object for the networkType |
| 1445 | * in question. |
| 1446 | * @param isCaptivePortal true/false. |
| 1447 | * |
| 1448 | * <p>This method requires the call to hold the permission |
| 1449 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
| 1450 | * {@hide} |
| 1451 | */ |
| 1452 | public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) { |
| 1453 | try { |
| 1454 | mService.captivePortalCheckCompleted(info, isCaptivePortal); |
| 1455 | } catch (RemoteException e) { |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /** |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 1460 | * Supply the backend messenger for a network tracker |
| 1461 | * |
Dianne Hackborn | 77b987f | 2014-02-26 16:20:52 -0800 | [diff] [blame] | 1462 | * @param networkType NetworkType to set |
Robert Greenwalt | 665e1ae | 2012-08-21 19:27:00 -0700 | [diff] [blame] | 1463 | * @param messenger {@link Messenger} |
| 1464 | * {@hide} |
| 1465 | */ |
| 1466 | public void supplyMessenger(int networkType, Messenger messenger) { |
| 1467 | try { |
| 1468 | mService.supplyMessenger(networkType, messenger); |
| 1469 | } catch (RemoteException e) { |
| 1470 | } |
| 1471 | } |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1472 | |
| 1473 | /** |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 1474 | * Check mobile provisioning. |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1475 | * |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1476 | * @param suggestedTimeOutMs, timeout in milliseconds |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1477 | * |
| 1478 | * @return time out that will be used, maybe less that suggestedTimeOutMs |
| 1479 | * -1 if an error. |
| 1480 | * |
| 1481 | * {@hide} |
| 1482 | */ |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 1483 | public int checkMobileProvisioning(int suggestedTimeOutMs) { |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1484 | int timeOutMs = -1; |
| 1485 | try { |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 1486 | timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs); |
Wink Saville | ab9321d | 2013-06-29 21:10:57 -0700 | [diff] [blame] | 1487 | } catch (RemoteException e) { |
| 1488 | } |
| 1489 | return timeOutMs; |
| 1490 | } |
Robert Greenwalt | e182bfe | 2013-07-16 12:06:09 -0700 | [diff] [blame] | 1491 | |
| 1492 | /** |
Wink Saville | 42d4f08 | 2013-07-20 20:31:59 -0700 | [diff] [blame] | 1493 | * Get the mobile provisioning url. |
Robert Greenwalt | e182bfe | 2013-07-16 12:06:09 -0700 | [diff] [blame] | 1494 | * {@hide} |
| 1495 | */ |
| 1496 | public String getMobileProvisioningUrl() { |
| 1497 | try { |
| 1498 | return mService.getMobileProvisioningUrl(); |
| 1499 | } catch (RemoteException e) { |
| 1500 | } |
| 1501 | return null; |
| 1502 | } |
Wink Saville | 42d4f08 | 2013-07-20 20:31:59 -0700 | [diff] [blame] | 1503 | |
| 1504 | /** |
| 1505 | * Get the mobile redirected provisioning url. |
| 1506 | * {@hide} |
| 1507 | */ |
| 1508 | public String getMobileRedirectedProvisioningUrl() { |
| 1509 | try { |
| 1510 | return mService.getMobileRedirectedProvisioningUrl(); |
| 1511 | } catch (RemoteException e) { |
| 1512 | } |
| 1513 | return null; |
| 1514 | } |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1515 | |
| 1516 | /** |
| 1517 | * get the information about a specific network link |
| 1518 | * @hide |
| 1519 | */ |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1520 | public LinkQualityInfo getLinkQualityInfo(int networkType) { |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1521 | try { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1522 | LinkQualityInfo li = mService.getLinkQualityInfo(networkType); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1523 | return li; |
| 1524 | } catch (RemoteException e) { |
| 1525 | return null; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | /** |
| 1530 | * get the information of currently active network link |
| 1531 | * @hide |
| 1532 | */ |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1533 | public LinkQualityInfo getActiveLinkQualityInfo() { |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1534 | try { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1535 | LinkQualityInfo li = mService.getActiveLinkQualityInfo(); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1536 | return li; |
| 1537 | } catch (RemoteException e) { |
| 1538 | return null; |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | /** |
| 1543 | * get the information of all network links |
| 1544 | * @hide |
| 1545 | */ |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1546 | public LinkQualityInfo[] getAllLinkQualityInfo() { |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1547 | try { |
Vinit Deshapnde | 6a2d325 | 2013-09-04 14:11:24 -0700 | [diff] [blame] | 1548 | LinkQualityInfo[] li = mService.getAllLinkQualityInfo(); |
Vinit Deshapnde | 1f12cb5 | 2013-08-21 13:09:01 -0700 | [diff] [blame] | 1549 | return li; |
| 1550 | } catch (RemoteException e) { |
| 1551 | return null; |
| 1552 | } |
| 1553 | } |
Wink Saville | 7788c61 | 2013-08-29 14:57:08 -0700 | [diff] [blame] | 1554 | |
| 1555 | /** |
Wink Saville | 948282b | 2013-08-29 08:55:16 -0700 | [diff] [blame] | 1556 | * Set sign in error notification to visible or in visible |
| 1557 | * |
| 1558 | * @param visible |
| 1559 | * @param networkType |
| 1560 | * |
| 1561 | * {@hide} |
| 1562 | */ |
| 1563 | public void setProvisioningNotificationVisible(boolean visible, int networkType, |
| 1564 | String extraInfo, String url) { |
| 1565 | try { |
| 1566 | mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url); |
| 1567 | } catch (RemoteException e) { |
| 1568 | } |
| 1569 | } |
Yuhao Zheng | 5cd1a0e | 2013-09-09 17:00:04 -0700 | [diff] [blame] | 1570 | |
| 1571 | /** |
| 1572 | * Set the value for enabling/disabling airplane mode |
| 1573 | * |
| 1574 | * @param enable whether to enable airplane mode or not |
| 1575 | * |
| 1576 | * <p>This method requires the call to hold the permission |
| 1577 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
| 1578 | * @hide |
| 1579 | */ |
| 1580 | public void setAirplaneMode(boolean enable) { |
| 1581 | try { |
| 1582 | mService.setAirplaneMode(enable); |
| 1583 | } catch (RemoteException e) { |
| 1584 | } |
| 1585 | } |
Robert Greenwalt | e049c23 | 2014-04-11 15:53:27 -0700 | [diff] [blame] | 1586 | |
| 1587 | /** {@hide} */ |
| 1588 | public void registerNetworkFactory(Messenger messenger) { |
| 1589 | try { |
| 1590 | mService.registerNetworkFactory(messenger); |
| 1591 | } catch (RemoteException e) { } |
| 1592 | } |
Robert Greenwalt | 7b81602 | 2014-04-18 15:25:25 -0700 | [diff] [blame^] | 1593 | |
| 1594 | /** {@hide} */ |
| 1595 | public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, |
| 1596 | NetworkCapabilities nc, int score) { |
| 1597 | try { |
| 1598 | mService.registerNetworkAgent(messenger, ni, lp, nc, score); |
| 1599 | } catch (RemoteException e) { } |
| 1600 | } |
| 1601 | |
| 1602 | /** Interface for NetworkRequest callbacks {@hide} */ |
| 1603 | public static class NetworkCallbacks { |
| 1604 | public static final int PRECHECK = 1; |
| 1605 | public static final int AVAILABLE = 2; |
| 1606 | public static final int LOSING = 3; |
| 1607 | public static final int LOST = 4; |
| 1608 | public static final int UNAVAIL = 5; |
| 1609 | public static final int CAP_CHANGED = 6; |
| 1610 | public static final int PROP_CHANGED = 7; |
| 1611 | public static final int CANCELED = 8; |
| 1612 | |
| 1613 | /** |
| 1614 | * @hide |
| 1615 | * Called whenever the framework connects to a network that it may use to |
| 1616 | * satisfy this request |
| 1617 | */ |
| 1618 | public void onPreCheck(NetworkRequest networkRequest, Network network) {} |
| 1619 | |
| 1620 | /** |
| 1621 | * Called when the framework connects and has validated the new network. |
| 1622 | */ |
| 1623 | public void onAvailable(NetworkRequest networkRequest, Network network) {} |
| 1624 | |
| 1625 | /** |
| 1626 | * Called when the framework is losing the network. Often paired with an |
| 1627 | * onAvailable call with the new replacement network for graceful handover. |
| 1628 | * This may not be called if we have a hard loss (loss without warning). |
| 1629 | * This may be followed by either an onLost call or an onAvailable call for this |
| 1630 | * network depending on if we lose or regain it. |
| 1631 | */ |
| 1632 | public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {} |
| 1633 | |
| 1634 | /** |
| 1635 | * Called when the framework has a hard loss of the network or when the |
| 1636 | * graceful failure ends. Note applications should only request this callback |
| 1637 | * if the application is willing to track the Available and Lost callbacks |
| 1638 | * together, else the application may think it has no network when it |
| 1639 | * really does (A Avail, B Avail, A Lost.. still have B). |
| 1640 | */ |
| 1641 | public void onLost(NetworkRequest networkRequest, Network network) {} |
| 1642 | |
| 1643 | /** |
| 1644 | * Called if no network is found in the given timeout time. If no timeout is given, |
| 1645 | * this will not be called. |
| 1646 | */ |
| 1647 | public void onUnavailable(NetworkRequest networkRequest) {} |
| 1648 | |
| 1649 | /** |
| 1650 | * Called when the network the framework connected to for this request |
| 1651 | * changes capabilities but still satisfies the stated need. |
| 1652 | */ |
| 1653 | public void onCapabilitiesChanged(NetworkRequest networkRequest, Network network, |
| 1654 | NetworkCapabilities networkCapabilities) {} |
| 1655 | |
| 1656 | /** |
| 1657 | * Called when the network the framework connected to for this request |
| 1658 | * changes properties. |
| 1659 | */ |
| 1660 | public void onPropertiesChanged(NetworkRequest networkRequest, Network network, |
| 1661 | LinkProperties linkProperties) {} |
| 1662 | |
| 1663 | /** |
| 1664 | * Called when a CancelRequest call concludes and the registered callbacks will |
| 1665 | * no longer be used. |
| 1666 | */ |
| 1667 | public void onCanceled(NetworkRequest networkRequest) {} |
| 1668 | } |
| 1669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1670 | } |