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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.RemoteException; |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 27 | import android.provider.Settings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 29 | import java.net.InetAddress; |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 30 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Class that answers queries about the state of network connectivity. It also |
| 33 | * notifies applications when network connectivity changes. Get an instance |
| 34 | * of this class by calling |
| 35 | * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}. |
| 36 | * <p> |
| 37 | * The primary responsibilities of this class are to: |
| 38 | * <ol> |
| 39 | * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li> |
| 40 | * <li>Send broadcast intents when network connectivity changes</li> |
| 41 | * <li>Attempt to "fail over" to another network when connectivity to a network |
| 42 | * is lost</li> |
| 43 | * <li>Provide an API that allows applications to query the coarse-grained or fine-grained |
| 44 | * state of the available networks</li> |
| 45 | * </ol> |
| 46 | */ |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 47 | public class ConnectivityManager { |
| 48 | private static final String TAG = "ConnectivityManager"; |
| 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | /** |
| 51 | * A change in network connectivity has occurred. A connection has either |
| 52 | * been established or lost. The NetworkInfo for the affected network is |
| 53 | * sent as an extra; it should be consulted to see what kind of |
| 54 | * connectivity event occurred. |
| 55 | * <p/> |
| 56 | * If this is a connection that was the result of failing over from a |
| 57 | * disconnected network, then the FAILOVER_CONNECTION boolean extra is |
| 58 | * set to true. |
| 59 | * <p/> |
| 60 | * For a loss of connectivity, if the connectivity manager is attempting |
| 61 | * to connect (or has already connected) to another network, the |
| 62 | * NetworkInfo for the new network is also passed as an extra. This lets |
| 63 | * any receivers of the broadcast know that they should not necessarily |
| 64 | * tell the user that no data traffic will be possible. Instead, the |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 65 | * receiver should expect another broadcast soon, indicating either that |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | * the failover attempt succeeded (and so there is still overall data |
| 67 | * connectivity), or that the failover attempt failed, meaning that all |
| 68 | * connectivity has been lost. |
| 69 | * <p/> |
| 70 | * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY |
| 71 | * is set to {@code true} if there are no connected networks at all. |
| 72 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 73 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 75 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | /** |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 77 | * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any |
| 78 | * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}. |
| 79 | * |
| 80 | * @hide |
| 81 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 82 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 83 | public static final String CONNECTIVITY_ACTION_IMMEDIATE = |
| 84 | "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE"; |
| 85 | |
| 86 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | * The lookup key for a {@link NetworkInfo} object. Retrieve with |
| 88 | * {@link android.content.Intent#getParcelableExtra(String)}. |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 89 | * |
| 90 | * @deprecated Since {@link NetworkInfo} can vary based on UID, applications |
| 91 | * should always obtain network information through |
| 92 | * {@link #getActiveNetworkInfo()} or |
| 93 | * {@link #getAllNetworkInfo()}. |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame] | 94 | * @see #EXTRA_NETWORK_TYPE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | */ |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 96 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | public static final String EXTRA_NETWORK_INFO = "networkInfo"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | /** |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame] | 100 | * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast. |
| 101 | * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo} |
| 102 | * state based on the calling application. |
| 103 | * |
| 104 | * @see android.content.Intent#getIntExtra(String, int) |
| 105 | */ |
| 106 | public static final String EXTRA_NETWORK_TYPE = "networkType"; |
| 107 | |
| 108 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | * The lookup key for a boolean that indicates whether a connect event |
| 110 | * is for a network to which the connectivity manager was failing over |
| 111 | * following a disconnect on another network. |
| 112 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 113 | */ |
| 114 | public static final String EXTRA_IS_FAILOVER = "isFailover"; |
| 115 | /** |
| 116 | * The lookup key for a {@link NetworkInfo} object. This is supplied when |
| 117 | * there is another network that it may be possible to connect to. Retrieve with |
| 118 | * {@link android.content.Intent#getParcelableExtra(String)}. |
| 119 | */ |
| 120 | public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork"; |
| 121 | /** |
| 122 | * The lookup key for a boolean that indicates whether there is a |
| 123 | * complete lack of connectivity, i.e., no network is available. |
| 124 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 125 | */ |
| 126 | public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity"; |
| 127 | /** |
| 128 | * The lookup key for a string that indicates why an attempt to connect |
| 129 | * to a network failed. The string has no particular structure. It is |
| 130 | * intended to be used in notifications presented to users. Retrieve |
| 131 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 132 | */ |
| 133 | public static final String EXTRA_REASON = "reason"; |
| 134 | /** |
| 135 | * The lookup key for a string that provides optionally supplied |
| 136 | * extra information about the network state. The information |
| 137 | * may be passed up from the lower networking layers, and its |
| 138 | * meaning may be specific to a particular network type. Retrieve |
| 139 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 140 | */ |
| 141 | public static final String EXTRA_EXTRA_INFO = "extraInfo"; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 142 | /** |
| 143 | * The lookup key for an int that provides information about |
| 144 | * our connection to the internet at large. 0 indicates no connection, |
| 145 | * 100 indicates a great connection. Retrieve it with |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 146 | * {@link android.content.Intent#getIntExtra(String, int)}. |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 147 | * {@hide} |
| 148 | */ |
| 149 | public static final String EXTRA_INET_CONDITION = "inetCondition"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
| 151 | /** |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 152 | * Broadcast action to indicate the change of data activity status |
| 153 | * (idle or active) on a network in a recent period. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 154 | * The network becomes active when data transmission is started, or |
| 155 | * idle if there is no data transmission for a period of time. |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 156 | * {@hide} |
| 157 | */ |
| 158 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 159 | public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE"; |
| 160 | /** |
| 161 | * The lookup key for an enum that indicates the network device type on which this data activity |
| 162 | * change happens. |
| 163 | * {@hide} |
| 164 | */ |
| 165 | public static final String EXTRA_DEVICE_TYPE = "deviceType"; |
| 166 | /** |
| 167 | * The lookup key for a boolean that indicates the device is active or not. {@code true} means |
| 168 | * it is actively sending or receiving data and {@code false} means it is idle. |
| 169 | * {@hide} |
| 170 | */ |
| 171 | public static final String EXTRA_IS_ACTIVE = "isActive"; |
| 172 | |
| 173 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | * Broadcast Action: The setting for background data usage has changed |
| 175 | * values. Use {@link #getBackgroundDataSetting()} to get the current value. |
| 176 | * <p> |
| 177 | * If an application uses the network in the background, it should listen |
| 178 | * for this broadcast and stop using the background data if the value is |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 179 | * {@code false}. |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 180 | * <p> |
| 181 | * |
| 182 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability |
| 183 | * of background data depends on several combined factors, and |
| 184 | * this broadcast is no longer sent. Instead, when background |
| 185 | * data is unavailable, {@link #getActiveNetworkInfo()} will now |
| 186 | * appear disconnected. During first boot after a platform |
| 187 | * upgrade, this broadcast will be sent once if |
| 188 | * {@link #getBackgroundDataSetting()} was {@code false} before |
| 189 | * the upgrade. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | */ |
| 191 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 192 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = |
| 194 | "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; |
| 195 | |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Broadcast Action: The network connection may not be good |
| 198 | * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and |
| 199 | * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify |
| 200 | * the network and it's condition. |
| 201 | * @hide |
| 202 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 203 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 204 | public static final String INET_CONDITION_ACTION = |
| 205 | "android.net.conn.INET_CONDITION_ACTION"; |
| 206 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 207 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 208 | * Broadcast Action: A tetherable connection has come or gone. |
| 209 | * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER}, |
| 210 | * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and |
| 211 | * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate |
| 212 | * the current state of tethering. Each include a list of |
| 213 | * interface names in that state (may be empty). |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 214 | * @hide |
| 215 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 216 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 217 | public static final String ACTION_TETHER_STATE_CHANGED = |
| 218 | "android.net.conn.TETHER_STATE_CHANGED"; |
| 219 | |
| 220 | /** |
| 221 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 222 | * gives a String[] listing all the interfaces configured for |
| 223 | * tethering and currently available for tethering. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 224 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 225 | public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 229 | * gives a String[] listing all the interfaces currently tethered |
| 230 | * (ie, has dhcp support and packets potentially forwarded/NATed) |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 231 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 232 | public static final String EXTRA_ACTIVE_TETHER = "activeArray"; |
| 233 | |
| 234 | /** |
| 235 | * @hide |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 236 | * gives a String[] listing all the interfaces we tried to tether and |
| 237 | * failed. Use {@link #getLastTetherError} to find the error code |
| 238 | * for any interfaces listed here. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 239 | */ |
| 240 | public static final String EXTRA_ERRORED_TETHER = "erroredArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 241 | |
| 242 | /** |
Russell Brenner | 108da0c | 2013-02-12 10:03:14 -0800 | [diff] [blame] | 243 | * Broadcast Action: The captive portal tracker has finished its test. |
| 244 | * Sent only while running Setup Wizard, in lieu of showing a user |
| 245 | * notification. |
| 246 | * @hide |
| 247 | */ |
Jeff Sharkey | 4fa63b2 | 2013-02-20 18:21:19 -0800 | [diff] [blame] | 248 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Russell Brenner | 108da0c | 2013-02-12 10:03:14 -0800 | [diff] [blame] | 249 | public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED = |
| 250 | "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED"; |
| 251 | /** |
| 252 | * The lookup key for a boolean that indicates whether a captive portal was detected. |
| 253 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 254 | * @hide |
| 255 | */ |
| 256 | public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal"; |
| 257 | |
| 258 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 259 | * The absence of a connection type. |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 260 | * @hide |
| 261 | */ |
| 262 | public static final int TYPE_NONE = -1; |
| 263 | |
| 264 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 265 | * The Mobile data connection. When active, all data traffic |
| 266 | * will use this network type's interface by default |
| 267 | * (it has a default route) |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 268 | */ |
| 269 | public static final int TYPE_MOBILE = 0; |
| 270 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 271 | * The WIFI data connection. When active, all data traffic |
| 272 | * will use this network type's interface by default |
| 273 | * (it has a default route). |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 274 | */ |
| 275 | public static final int TYPE_WIFI = 1; |
| 276 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 277 | * An MMS-specific Mobile data connection. This network type may use the |
| 278 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 279 | * one. This is used by applications needing to talk to the carrier's |
| 280 | * Multimedia Messaging Service servers. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 281 | */ |
| 282 | public static final int TYPE_MOBILE_MMS = 2; |
| 283 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 284 | * A SUPL-specific Mobile data connection. This network type may use the |
| 285 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 286 | * one. This is used by applications needing to talk to the carrier's |
| 287 | * Secure User Plane Location servers for help locating the device. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 288 | */ |
| 289 | public static final int TYPE_MOBILE_SUPL = 3; |
| 290 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 291 | * A DUN-specific Mobile data connection. This network type may use the |
| 292 | * same network interface as {@link #TYPE_MOBILE} or it may use a different |
| 293 | * one. This is sometimes by the system when setting up an upstream connection |
| 294 | * for tethering so that the carrier is aware of DUN traffic. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 295 | */ |
| 296 | public static final int TYPE_MOBILE_DUN = 4; |
| 297 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 298 | * A High Priority Mobile data connection. This network type uses the |
| 299 | * same network interface as {@link #TYPE_MOBILE} but the routing setup |
| 300 | * is different. Only requesting processes will have access to the |
| 301 | * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost} |
| 302 | * will route over this interface if no default route exists. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 303 | */ |
| 304 | public static final int TYPE_MOBILE_HIPRI = 5; |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 305 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 306 | * The WiMAX data connection. When active, all data traffic |
| 307 | * will use this network type's interface by default |
| 308 | * (it has a default route). |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 309 | */ |
| 310 | public static final int TYPE_WIMAX = 6; |
Robert Greenwalt | da3d5e6 | 2010-12-06 13:56:24 -0800 | [diff] [blame] | 311 | |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 312 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 313 | * The Bluetooth data connection. When active, all data traffic |
| 314 | * will use this network type's interface by default |
| 315 | * (it has a default route). |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 316 | */ |
| 317 | public static final int TYPE_BLUETOOTH = 7; |
| 318 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Dummy data connection. This should not be used on shipping devices. |
| 321 | */ |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 322 | public static final int TYPE_DUMMY = 8; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 323 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 324 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 325 | * The Ethernet data connection. When active, all data traffic |
| 326 | * will use this network type's interface by default |
| 327 | * (it has a default route). |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 328 | */ |
Robert Greenwalt | e12aec9 | 2011-01-28 14:48:37 -0800 | [diff] [blame] | 329 | public static final int TYPE_ETHERNET = 9; |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 330 | |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 331 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 332 | * Over the air Administration. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 333 | * {@hide} |
| 334 | */ |
| 335 | public static final int TYPE_MOBILE_FOTA = 10; |
| 336 | |
| 337 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 338 | * IP Multimedia Subsystem. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 339 | * {@hide} |
| 340 | */ |
| 341 | public static final int TYPE_MOBILE_IMS = 11; |
| 342 | |
| 343 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 344 | * Carrier Branded Services. |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 345 | * {@hide} |
| 346 | */ |
| 347 | public static final int TYPE_MOBILE_CBS = 12; |
| 348 | |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 349 | /** |
| 350 | * A Wi-Fi p2p connection. Only requesting processes will have access to |
| 351 | * the peers connected. |
| 352 | * {@hide} |
| 353 | */ |
| 354 | public static final int TYPE_WIFI_P2P = 13; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 355 | |
| 356 | /** {@hide} */ |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 357 | public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P; |
| 358 | |
| 359 | /** {@hide} */ |
| 360 | public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 362 | /** |
| 363 | * If you want to set the default network preference,you can directly |
| 364 | * change the networkAttributes array in framework's config.xml. |
| 365 | * |
| 366 | * @deprecated Since we support so many more networks now, the single |
| 367 | * network default network preference can't really express |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 368 | * the hierarchy. Instead, the default is defined by the |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 369 | * networkAttributes in config.xml. You can determine |
Robert Greenwalt | 4c8b748 | 2012-12-07 09:56:50 -0800 | [diff] [blame] | 370 | * the current value by calling {@link #getNetworkPreference()} |
Jianzheng Zhou | dcf03f3 | 2012-11-16 13:45:20 +0800 | [diff] [blame] | 371 | * from an App. |
| 372 | */ |
| 373 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; |
| 375 | |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 378 | * milliseconds. This was introduced because IPv6 routes seem to take a |
| 379 | * moment to settle - trying network activity before the routes are adjusted |
| 380 | * can lead to packets using the wrong interface or having the wrong IP address. |
| 381 | * This delay is a bit crude, but in the future hopefully we will have kernel |
| 382 | * notifications letting us know when it's safe to use the new network. |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000; |
| 387 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 388 | private final IConnectivityManager mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 390 | /** |
| 391 | * Tests if a given integer represents a valid network type. |
| 392 | * @param networkType the type to be tested |
| 393 | * @return a boolean. {@code true} if the type is valid, else {@code false} |
| 394 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 395 | public static boolean isNetworkTypeValid(int networkType) { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 396 | return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 399 | /** |
| 400 | * Returns a non-localized string representing a given network type. |
| 401 | * ONLY used for debugging output. |
| 402 | * @param type the type needing naming |
| 403 | * @return a String for the given type, or a string version of the type ("87") |
| 404 | * if no name is known. |
| 405 | * {@hide} |
| 406 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 407 | public static String getNetworkTypeName(int type) { |
| 408 | switch (type) { |
| 409 | case TYPE_MOBILE: |
| 410 | return "MOBILE"; |
| 411 | case TYPE_WIFI: |
| 412 | return "WIFI"; |
| 413 | case TYPE_MOBILE_MMS: |
| 414 | return "MOBILE_MMS"; |
| 415 | case TYPE_MOBILE_SUPL: |
| 416 | return "MOBILE_SUPL"; |
| 417 | case TYPE_MOBILE_DUN: |
| 418 | return "MOBILE_DUN"; |
| 419 | case TYPE_MOBILE_HIPRI: |
| 420 | return "MOBILE_HIPRI"; |
| 421 | case TYPE_WIMAX: |
| 422 | return "WIMAX"; |
| 423 | case TYPE_BLUETOOTH: |
| 424 | return "BLUETOOTH"; |
| 425 | case TYPE_DUMMY: |
| 426 | return "DUMMY"; |
| 427 | case TYPE_ETHERNET: |
| 428 | return "ETHERNET"; |
| 429 | case TYPE_MOBILE_FOTA: |
| 430 | return "MOBILE_FOTA"; |
| 431 | case TYPE_MOBILE_IMS: |
| 432 | return "MOBILE_IMS"; |
| 433 | case TYPE_MOBILE_CBS: |
| 434 | return "MOBILE_CBS"; |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 435 | case TYPE_WIFI_P2P: |
| 436 | return "WIFI_P2P"; |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 437 | default: |
| 438 | return Integer.toString(type); |
| 439 | } |
| 440 | } |
| 441 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 442 | /** |
| 443 | * Checks if a given type uses the cellular data connection. |
| 444 | * This should be replaced in the future by a network property. |
| 445 | * @param networkType the type to check |
| 446 | * @return a boolean - {@code true} if uses cellular network, else {@code false} |
| 447 | * {@hide} |
| 448 | */ |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 449 | public static boolean isNetworkTypeMobile(int networkType) { |
| 450 | switch (networkType) { |
| 451 | case TYPE_MOBILE: |
| 452 | case TYPE_MOBILE_MMS: |
| 453 | case TYPE_MOBILE_SUPL: |
| 454 | case TYPE_MOBILE_DUN: |
| 455 | case TYPE_MOBILE_HIPRI: |
| 456 | case TYPE_MOBILE_FOTA: |
| 457 | case TYPE_MOBILE_IMS: |
| 458 | case TYPE_MOBILE_CBS: |
| 459 | return true; |
| 460 | default: |
| 461 | return false; |
| 462 | } |
| 463 | } |
| 464 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 465 | /** |
| 466 | * Specifies the preferred network type. When the device has more |
| 467 | * than one type available the preferred network type will be used. |
| 468 | * Note that this made sense when we only had 2 network types, |
| 469 | * but with more and more default networks we need an array to list |
| 470 | * their ordering. This will be deprecated soon. |
| 471 | * |
| 472 | * @param preference the network type to prefer over all others. It is |
| 473 | * unspecified what happens to the old preferred network in the |
| 474 | * overall ordering. |
| 475 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | public void setNetworkPreference(int preference) { |
| 477 | try { |
| 478 | mService.setNetworkPreference(preference); |
| 479 | } catch (RemoteException e) { |
| 480 | } |
| 481 | } |
| 482 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 483 | /** |
| 484 | * Retrieves the current preferred network type. |
| 485 | * Note that this made sense when we only had 2 network types, |
| 486 | * but with more and more default networks we need an array to list |
| 487 | * their ordering. This will be deprecated soon. |
| 488 | * |
| 489 | * @return an integer representing the preferred network type |
| 490 | * |
| 491 | * <p>This method requires the caller to hold the permission |
| 492 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 493 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | public int getNetworkPreference() { |
| 495 | try { |
| 496 | return mService.getNetworkPreference(); |
| 497 | } catch (RemoteException e) { |
| 498 | return -1; |
| 499 | } |
| 500 | } |
| 501 | |
Scott Main | 671644c | 2011-10-06 19:02:28 -0700 | [diff] [blame] | 502 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 503 | * Returns details about the currently active default data network. When |
| 504 | * connected, this network is the default route for outgoing connections. |
| 505 | * You should always check {@link NetworkInfo#isConnected()} before initiating |
| 506 | * network traffic. This may return {@code null} when there is no default |
| 507 | * network. |
| 508 | * |
| 509 | * @return a {@link NetworkInfo} object for the current default network |
| 510 | * or {@code null} if no network default network is currently active |
| 511 | * |
| 512 | * <p>This method requires the call to hold the permission |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 513 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 514 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | public NetworkInfo getActiveNetworkInfo() { |
| 516 | try { |
| 517 | return mService.getActiveNetworkInfo(); |
| 518 | } catch (RemoteException e) { |
| 519 | return null; |
| 520 | } |
| 521 | } |
| 522 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 523 | /** |
| 524 | * Returns details about the currently active default data network |
| 525 | * for a given uid. This is for internal use only to avoid spying |
| 526 | * other apps. |
| 527 | * |
| 528 | * @return a {@link NetworkInfo} object for the current default network |
| 529 | * for the given uid or {@code null} if no default network is |
| 530 | * available for the specified uid. |
| 531 | * |
| 532 | * <p>This method requires the caller to hold the permission |
| 533 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL} |
| 534 | * {@hide} |
| 535 | */ |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 536 | public NetworkInfo getActiveNetworkInfoForUid(int uid) { |
| 537 | try { |
| 538 | return mService.getActiveNetworkInfoForUid(uid); |
| 539 | } catch (RemoteException e) { |
| 540 | return null; |
| 541 | } |
| 542 | } |
| 543 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 544 | /** |
| 545 | * Returns connection status information about a particular |
| 546 | * network type. |
| 547 | * |
| 548 | * @param networkType integer specifying which networkType in |
| 549 | * which you're interested. |
| 550 | * @return a {@link NetworkInfo} object for the requested |
| 551 | * network type or {@code null} if the type is not |
| 552 | * supported by the device. |
| 553 | * |
| 554 | * <p>This method requires the call to hold the permission |
| 555 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 556 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | public NetworkInfo getNetworkInfo(int networkType) { |
| 558 | try { |
| 559 | return mService.getNetworkInfo(networkType); |
| 560 | } catch (RemoteException e) { |
| 561 | return null; |
| 562 | } |
| 563 | } |
| 564 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 565 | /** |
| 566 | * Returns connection status information about all network |
| 567 | * types supported by the device. |
| 568 | * |
| 569 | * @return an array of {@link NetworkInfo} objects. Check each |
| 570 | * {@link NetworkInfo#getType} for which type each applies. |
| 571 | * |
| 572 | * <p>This method requires the call to hold the permission |
| 573 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 574 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | public NetworkInfo[] getAllNetworkInfo() { |
| 576 | try { |
| 577 | return mService.getAllNetworkInfo(); |
| 578 | } catch (RemoteException e) { |
| 579 | return null; |
| 580 | } |
| 581 | } |
| 582 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 583 | /** |
| 584 | * Returns the IP information for the current default network. |
| 585 | * |
| 586 | * @return a {@link LinkProperties} object describing the IP info |
| 587 | * for the current default network, or {@code null} if there |
| 588 | * is no current default network. |
| 589 | * |
| 590 | * <p>This method requires the call to hold the permission |
| 591 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 592 | * {@hide} |
| 593 | */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 594 | public LinkProperties getActiveLinkProperties() { |
| 595 | try { |
| 596 | return mService.getActiveLinkProperties(); |
| 597 | } catch (RemoteException e) { |
| 598 | return null; |
| 599 | } |
| 600 | } |
| 601 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 602 | /** |
| 603 | * Returns the IP information for a given network type. |
| 604 | * |
| 605 | * @param networkType the network type of interest. |
| 606 | * @return a {@link LinkProperties} object describing the IP info |
| 607 | * for the given networkType, or {@code null} if there is |
| 608 | * no current default network. |
| 609 | * |
| 610 | * <p>This method requires the call to hold the permission |
| 611 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 612 | * {@hide} |
| 613 | */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 614 | public LinkProperties getLinkProperties(int networkType) { |
| 615 | try { |
| 616 | return mService.getLinkProperties(networkType); |
| 617 | } catch (RemoteException e) { |
| 618 | return null; |
| 619 | } |
| 620 | } |
| 621 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 622 | /** |
| 623 | * Tells each network type to set its radio power state as directed. |
| 624 | * |
| 625 | * @param turnOn a boolean, {@code true} to turn the radios on, |
| 626 | * {@code false} to turn them off. |
| 627 | * @return a boolean, {@code true} indicating success. All network types |
| 628 | * will be tried, even if some fail. |
| 629 | * |
| 630 | * <p>This method requires the call to hold the permission |
| 631 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
| 632 | * {@hide} |
| 633 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | public boolean setRadios(boolean turnOn) { |
| 635 | try { |
| 636 | return mService.setRadios(turnOn); |
| 637 | } catch (RemoteException e) { |
| 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 642 | /** |
| 643 | * Tells a given networkType to set its radio power state as directed. |
| 644 | * |
| 645 | * @param networkType the int networkType of interest. |
| 646 | * @param turnOn a boolean, {@code true} to turn the radio on, |
| 647 | * {@code} false to turn it off. |
| 648 | * @return a boolean, {@code true} indicating success. |
| 649 | * |
| 650 | * <p>This method requires the call to hold the permission |
| 651 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
| 652 | * {@hide} |
| 653 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | public boolean setRadio(int networkType, boolean turnOn) { |
| 655 | try { |
| 656 | return mService.setRadio(networkType, turnOn); |
| 657 | } catch (RemoteException e) { |
| 658 | return false; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Tells the underlying networking system that the caller wants to |
| 664 | * begin using the named feature. The interpretation of {@code feature} |
| 665 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 666 | * <p>This method requires the caller to hold the permission |
| 667 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | * @param networkType specifies which network the request pertains to |
| 669 | * @param feature the name of the feature to be used |
| 670 | * @return an integer value representing the outcome of the request. |
| 671 | * The interpretation of this value is specific to each networking |
| 672 | * implementation+feature combination, except that the value {@code -1} |
| 673 | * always indicates failure. |
| 674 | */ |
| 675 | public int startUsingNetworkFeature(int networkType, String feature) { |
| 676 | try { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 677 | return mService.startUsingNetworkFeature(networkType, feature, |
| 678 | new Binder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | } catch (RemoteException e) { |
| 680 | return -1; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Tells the underlying networking system that the caller is finished |
| 686 | * using the named feature. The interpretation of {@code feature} |
| 687 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 688 | * <p>This method requires the caller to hold the permission |
| 689 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | * @param networkType specifies which network the request pertains to |
| 691 | * @param feature the name of the feature that is no longer needed |
| 692 | * @return an integer value representing the outcome of the request. |
| 693 | * The interpretation of this value is specific to each networking |
| 694 | * implementation+feature combination, except that the value {@code -1} |
| 695 | * always indicates failure. |
| 696 | */ |
| 697 | public int stopUsingNetworkFeature(int networkType, String feature) { |
| 698 | try { |
| 699 | return mService.stopUsingNetworkFeature(networkType, feature); |
| 700 | } catch (RemoteException e) { |
| 701 | return -1; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * Ensure that a network route exists to deliver traffic to the specified |
| 707 | * host via the specified network interface. An attempt to add a route that |
| 708 | * already exists is ignored, but treated as successful. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 709 | * <p>This method requires the caller to hold the permission |
| 710 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | * @param networkType the type of the network over which traffic to the specified |
| 712 | * host is to be routed |
| 713 | * @param hostAddress the IP address of the host to which the route is desired |
| 714 | * @return {@code true} on success, {@code false} on failure |
| 715 | */ |
| 716 | public boolean requestRouteToHost(int networkType, int hostAddress) { |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 717 | InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); |
| 718 | |
| 719 | if (inetAddress == null) { |
| 720 | return false; |
| 721 | } |
| 722 | |
| 723 | return requestRouteToHostAddress(networkType, inetAddress); |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Ensure that a network route exists to deliver traffic to the specified |
| 728 | * host via the specified network interface. An attempt to add a route that |
| 729 | * already exists is ignored, but treated as successful. |
| 730 | * @param networkType the type of the network over which traffic to the specified |
| 731 | * host is to be routed |
| 732 | * @param hostAddress the IP address of the host to which the route is desired |
| 733 | * @return {@code true} on success, {@code false} on failure |
| 734 | * @hide |
| 735 | */ |
| 736 | public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { |
| 737 | byte[] address = hostAddress.getAddress(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | try { |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 739 | return mService.requestRouteToHostAddress(networkType, address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | } catch (RemoteException e) { |
| 741 | return false; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns the value of the setting for background data usage. If false, |
| 747 | * applications should not use the network if the application is not in the |
| 748 | * foreground. Developers should respect this setting, and check the value |
| 749 | * of this before performing any background data operations. |
| 750 | * <p> |
| 751 | * All applications that have background services that use the network |
| 752 | * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 753 | * <p> |
Scott Main | 4cc5333 | 2011-10-06 18:32:43 -0700 | [diff] [blame] | 754 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 755 | * background data depends on several combined factors, and this method will |
| 756 | * always return {@code true}. Instead, when background data is unavailable, |
| 757 | * {@link #getActiveNetworkInfo()} will now appear disconnected. |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 758 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | * @return Whether background data usage is allowed. |
| 760 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 761 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | public boolean getBackgroundDataSetting() { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 763 | // assume that background data is allowed; final authority is |
| 764 | // NetworkInfo which may be blocked. |
| 765 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Sets the value of the setting for background data usage. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 770 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | * @param allowBackgroundData Whether an application should use data while |
| 772 | * it is in the background. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 773 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING |
| 775 | * @see #getBackgroundDataSetting() |
| 776 | * @hide |
| 777 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 778 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | public void setBackgroundDataSetting(boolean allowBackgroundData) { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 780 | // ignored |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | } |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 782 | |
| 783 | /** |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 784 | * Return quota status for the current active network, or {@code null} if no |
| 785 | * network is active. Quota status can change rapidly, so these values |
| 786 | * shouldn't be cached. |
Jeff Sharkey | 44a3e0d | 2011-10-06 10:50:09 -0700 | [diff] [blame] | 787 | * |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 788 | * <p>This method requires the call to hold the permission |
| 789 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
| 790 | * |
Jeff Sharkey | 44a3e0d | 2011-10-06 10:50:09 -0700 | [diff] [blame] | 791 | * @hide |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 792 | */ |
| 793 | public NetworkQuotaInfo getActiveNetworkQuotaInfo() { |
| 794 | try { |
| 795 | return mService.getActiveNetworkQuotaInfo(); |
| 796 | } catch (RemoteException e) { |
| 797 | return null; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /** |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 802 | * Gets the value of the setting for enabling Mobile data. |
| 803 | * |
| 804 | * @return Whether mobile data is enabled. |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 805 | * |
| 806 | * <p>This method requires the call to hold the permission |
| 807 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 808 | * @hide |
| 809 | */ |
| 810 | public boolean getMobileDataEnabled() { |
| 811 | try { |
| 812 | return mService.getMobileDataEnabled(); |
| 813 | } catch (RemoteException e) { |
| 814 | return true; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Sets the persisted value for enabling/disabling Mobile data. |
| 820 | * |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 821 | * @param enabled Whether the user wants the mobile data connection used |
| 822 | * or not. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 823 | * @hide |
| 824 | */ |
| 825 | public void setMobileDataEnabled(boolean enabled) { |
| 826 | try { |
| 827 | mService.setMobileDataEnabled(enabled); |
| 828 | } catch (RemoteException e) { |
| 829 | } |
| 830 | } |
| 831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | * {@hide} |
| 834 | */ |
| 835 | public ConnectivityManager(IConnectivityManager service) { |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 836 | mService = checkNotNull(service, "missing IConnectivityManager"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 838 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 839 | /** {@hide} */ |
| 840 | public static ConnectivityManager from(Context context) { |
| 841 | return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 842 | } |
| 843 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 844 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 845 | * Get the set of tetherable, available interfaces. This list is limited by |
| 846 | * device configuration and current interface existence. |
| 847 | * |
| 848 | * @return an array of 0 or more Strings of tetherable interface names. |
| 849 | * |
| 850 | * <p>This method requires the call to hold the permission |
| 851 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 852 | * {@hide} |
| 853 | */ |
| 854 | public String[] getTetherableIfaces() { |
| 855 | try { |
| 856 | return mService.getTetherableIfaces(); |
| 857 | } catch (RemoteException e) { |
| 858 | return new String[0]; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 863 | * Get the set of tethered interfaces. |
| 864 | * |
| 865 | * @return an array of 0 or more String of currently tethered interface names. |
| 866 | * |
| 867 | * <p>This method requires the call to hold the permission |
| 868 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 869 | * {@hide} |
| 870 | */ |
| 871 | public String[] getTetheredIfaces() { |
| 872 | try { |
| 873 | return mService.getTetheredIfaces(); |
| 874 | } catch (RemoteException e) { |
| 875 | return new String[0]; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 880 | * Get the set of interface names which attempted to tether but |
| 881 | * failed. Re-attempting to tether may cause them to reset to the Tethered |
| 882 | * state. Alternatively, causing the interface to be destroyed and recreated |
| 883 | * may cause them to reset to the available state. |
| 884 | * {@link ConnectivityManager#getLastTetherError} can be used to get more |
| 885 | * information on the cause of the errors. |
| 886 | * |
| 887 | * @return an array of 0 or more String indicating the interface names |
| 888 | * which failed to tether. |
| 889 | * |
| 890 | * <p>This method requires the call to hold the permission |
| 891 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 892 | * {@hide} |
| 893 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 894 | public String[] getTetheringErroredIfaces() { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 895 | try { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 896 | return mService.getTetheringErroredIfaces(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 897 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 898 | return new String[0]; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 903 | * Attempt to tether the named interface. This will setup a dhcp server |
| 904 | * on the interface, forward and NAT IP packets and forward DNS requests |
| 905 | * to the best active upstream network interface. Note that if no upstream |
| 906 | * IP network interface is available, dhcp will still run and traffic will be |
| 907 | * allowed between the tethered devices and this device, though upstream net |
| 908 | * access will of course fail until an upstream network interface becomes |
| 909 | * active. |
| 910 | * |
| 911 | * @param iface the interface name to tether. |
| 912 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 913 | * |
| 914 | * <p>This method requires the call to hold the permission |
| 915 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 916 | * {@hide} |
| 917 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 918 | public int tether(String iface) { |
| 919 | try { |
| 920 | return mService.tether(iface); |
| 921 | } catch (RemoteException e) { |
| 922 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 927 | * Stop tethering the named interface. |
| 928 | * |
| 929 | * @param iface the interface name to untether. |
| 930 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 931 | * |
| 932 | * <p>This method requires the call to hold the permission |
| 933 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 934 | * {@hide} |
| 935 | */ |
| 936 | public int untether(String iface) { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 937 | try { |
| 938 | return mService.untether(iface); |
| 939 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 940 | return TETHER_ERROR_SERVICE_UNAVAIL; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 941 | } |
| 942 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 943 | |
| 944 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 945 | * Check if the device allows for tethering. It may be disabled via |
| 946 | * {@code ro.tether.denied} system property, {@link Settings#TETHER_SUPPORTED} or |
| 947 | * due to device configuration. |
| 948 | * |
| 949 | * @return a boolean - {@code true} indicating Tethering is supported. |
| 950 | * |
| 951 | * <p>This method requires the call to hold the permission |
| 952 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 953 | * {@hide} |
| 954 | */ |
| 955 | public boolean isTetheringSupported() { |
| 956 | try { |
| 957 | return mService.isTetheringSupported(); |
| 958 | } catch (RemoteException e) { |
| 959 | return false; |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 964 | * Get the list of regular expressions that define any tetherable |
| 965 | * USB network interfaces. If USB tethering is not supported by the |
| 966 | * device, this list should be empty. |
| 967 | * |
| 968 | * @return an array of 0 or more regular expression Strings defining |
| 969 | * what interfaces are considered tetherable usb interfaces. |
| 970 | * |
| 971 | * <p>This method requires the call to hold the permission |
| 972 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 973 | * {@hide} |
| 974 | */ |
| 975 | public String[] getTetherableUsbRegexs() { |
| 976 | try { |
| 977 | return mService.getTetherableUsbRegexs(); |
| 978 | } catch (RemoteException e) { |
| 979 | return new String[0]; |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 984 | * Get the list of regular expressions that define any tetherable |
| 985 | * Wifi network interfaces. If Wifi tethering is not supported by the |
| 986 | * device, this list should be empty. |
| 987 | * |
| 988 | * @return an array of 0 or more regular expression Strings defining |
| 989 | * what interfaces are considered tetherable wifi interfaces. |
| 990 | * |
| 991 | * <p>This method requires the call to hold the permission |
| 992 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 993 | * {@hide} |
| 994 | */ |
| 995 | public String[] getTetherableWifiRegexs() { |
| 996 | try { |
| 997 | return mService.getTetherableWifiRegexs(); |
| 998 | } catch (RemoteException e) { |
| 999 | return new String[0]; |
| 1000 | } |
| 1001 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1002 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1003 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1004 | * Get the list of regular expressions that define any tetherable |
| 1005 | * Bluetooth network interfaces. If Bluetooth tethering is not supported by the |
| 1006 | * device, this list should be empty. |
| 1007 | * |
| 1008 | * @return an array of 0 or more regular expression Strings defining |
| 1009 | * what interfaces are considered tetherable bluetooth interfaces. |
| 1010 | * |
| 1011 | * <p>This method requires the call to hold the permission |
| 1012 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 1013 | * {@hide} |
| 1014 | */ |
| 1015 | public String[] getTetherableBluetoothRegexs() { |
| 1016 | try { |
| 1017 | return mService.getTetherableBluetoothRegexs(); |
| 1018 | } catch (RemoteException e) { |
| 1019 | return new String[0]; |
| 1020 | } |
| 1021 | } |
| 1022 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 1023 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1024 | * Attempt to both alter the mode of USB and Tethering of USB. A |
| 1025 | * utility method to deal with some of the complexity of USB - will |
| 1026 | * attempt to switch to Rndis and subsequently tether the resulting |
| 1027 | * interface on {@code true} or turn off tethering and switch off |
| 1028 | * Rndis on {@code false}. |
| 1029 | * |
| 1030 | * @param enable a boolean - {@code true} to enable tethering |
| 1031 | * @return error a {@code TETHER_ERROR} value indicating success or failure type |
| 1032 | * |
| 1033 | * <p>This method requires the call to hold the permission |
| 1034 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 1035 | * {@hide} |
| 1036 | */ |
| 1037 | public int setUsbTethering(boolean enable) { |
| 1038 | try { |
| 1039 | return mService.setUsbTethering(enable); |
| 1040 | } catch (RemoteException e) { |
| 1041 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 1042 | } |
| 1043 | } |
| 1044 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1045 | /** {@hide} */ |
| 1046 | public static final int TETHER_ERROR_NO_ERROR = 0; |
| 1047 | /** {@hide} */ |
| 1048 | public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; |
| 1049 | /** {@hide} */ |
| 1050 | public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; |
| 1051 | /** {@hide} */ |
| 1052 | public static final int TETHER_ERROR_UNSUPPORTED = 3; |
| 1053 | /** {@hide} */ |
| 1054 | public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; |
| 1055 | /** {@hide} */ |
| 1056 | public static final int TETHER_ERROR_MASTER_ERROR = 5; |
| 1057 | /** {@hide} */ |
| 1058 | public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; |
| 1059 | /** {@hide} */ |
| 1060 | public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; |
| 1061 | /** {@hide} */ |
| 1062 | public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; |
| 1063 | /** {@hide} */ |
| 1064 | public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; |
| 1065 | /** {@hide} */ |
| 1066 | public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; |
| 1067 | |
| 1068 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1069 | * Get a more detailed error code after a Tethering or Untethering |
| 1070 | * request asynchronously failed. |
| 1071 | * |
| 1072 | * @param iface The name of the interface of interest |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1073 | * @return error The error code of the last error tethering or untethering the named |
| 1074 | * interface |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1075 | * |
| 1076 | * <p>This method requires the call to hold the permission |
| 1077 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1078 | * {@hide} |
| 1079 | */ |
| 1080 | public int getLastTetherError(String iface) { |
| 1081 | try { |
| 1082 | return mService.getLastTetherError(iface); |
| 1083 | } catch (RemoteException e) { |
| 1084 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 1085 | } |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1089 | * Try to ensure the device stays awake until we connect with the next network. |
| 1090 | * Actually just holds a wakelock for a number of seconds while we try to connect |
| 1091 | * to any default networks. This will expire if the timeout passes or if we connect |
| 1092 | * to a default after this is called. For internal use only. |
| 1093 | * |
| 1094 | * @param forWhom the name of the network going down for logging purposes |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1095 | * @return {@code true} on success, {@code false} on failure |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1096 | * |
| 1097 | * <p>This method requires the call to hold the permission |
| 1098 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 1099 | * {@hide} |
| 1100 | */ |
| 1101 | public boolean requestNetworkTransitionWakelock(String forWhom) { |
| 1102 | try { |
| 1103 | mService.requestNetworkTransitionWakelock(forWhom); |
| 1104 | return true; |
| 1105 | } catch (RemoteException e) { |
| 1106 | return false; |
| 1107 | } |
| 1108 | } |
Robert Greenwalt | ca4306c | 2010-09-09 13:15:32 -0700 | [diff] [blame] | 1109 | |
Robert Greenwalt | 67fd6c9 | 2010-09-09 14:22:59 -0700 | [diff] [blame] | 1110 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1111 | * Report network connectivity status. This is currently used only |
| 1112 | * to alter status bar UI. |
| 1113 | * |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 1114 | * @param networkType The type of network you want to report on |
| 1115 | * @param percentage The quality of the connection 0 is bad, 100 is good |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1116 | * |
| 1117 | * <p>This method requires the call to hold the permission |
| 1118 | * {@link android.Manifest.permission#STATUS_BAR}. |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 1119 | * {@hide} |
| 1120 | */ |
| 1121 | public void reportInetCondition(int networkType, int percentage) { |
| 1122 | try { |
| 1123 | mService.reportInetCondition(networkType, percentage); |
| 1124 | } catch (RemoteException e) { |
| 1125 | } |
| 1126 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1127 | |
| 1128 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1129 | * Set a network-independent global http proxy. This is not normally what you want |
| 1130 | * for typical HTTP proxies - they are general network dependent. However if you're |
| 1131 | * doing something unusual like general internal filtering this may be useful. On |
| 1132 | * a private network where the proxy is not accessible, you may break HTTP using this. |
| 1133 | * |
| 1134 | * @param proxyProperties The a {@link ProxyProperites} object defining the new global |
| 1135 | * HTTP proxy. A {@code null} value will clear the global HTTP proxy. |
| 1136 | * |
| 1137 | * <p>This method requires the call to hold the permission |
| 1138 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1139 | * {@hide} |
| 1140 | */ |
| 1141 | public void setGlobalProxy(ProxyProperties p) { |
| 1142 | try { |
| 1143 | mService.setGlobalProxy(p); |
| 1144 | } catch (RemoteException e) { |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1149 | * Retrieve any network-independent global HTTP proxy. |
| 1150 | * |
| 1151 | * @return {@link ProxyProperties} for the current global HTTP proxy or {@code null} |
| 1152 | * if no global HTTP proxy is set. |
| 1153 | * |
| 1154 | * <p>This method requires the call to hold the permission |
| 1155 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1156 | * {@hide} |
| 1157 | */ |
| 1158 | public ProxyProperties getGlobalProxy() { |
| 1159 | try { |
| 1160 | return mService.getGlobalProxy(); |
| 1161 | } catch (RemoteException e) { |
| 1162 | return null; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1167 | * Get the HTTP proxy settings for the current default network. Note that |
| 1168 | * if a global proxy is set, it will override any per-network setting. |
| 1169 | * |
| 1170 | * @return the {@link ProxyProperties} for the current HTTP proxy, or {@code null} if no |
| 1171 | * HTTP proxy is active. |
| 1172 | * |
| 1173 | * <p>This method requires the call to hold the permission |
| 1174 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 1175 | * {@hide} |
| 1176 | */ |
| 1177 | public ProxyProperties getProxy() { |
| 1178 | try { |
| 1179 | return mService.getProxy(); |
| 1180 | } catch (RemoteException e) { |
| 1181 | return null; |
| 1182 | } |
| 1183 | } |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1184 | |
| 1185 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1186 | * Sets a secondary requirement bit for the given networkType. |
| 1187 | * This requirement bit is generally under the control of the carrier |
| 1188 | * or its agents and is not directly controlled by the user. |
| 1189 | * |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1190 | * @param networkType The network who's dependence has changed |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1191 | * @param met Boolean - true if network use is OK, false if not |
| 1192 | * |
| 1193 | * <p>This method requires the call to hold the permission |
| 1194 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 1195 | * {@hide} |
| 1196 | */ |
| 1197 | public void setDataDependency(int networkType, boolean met) { |
| 1198 | try { |
| 1199 | mService.setDataDependency(networkType, met); |
| 1200 | } catch (RemoteException e) { |
| 1201 | } |
| 1202 | } |
Robert Greenwalt | 9b2886e | 2011-08-31 11:46:42 -0700 | [diff] [blame] | 1203 | |
| 1204 | /** |
| 1205 | * Returns true if the hardware supports the given network type |
| 1206 | * else it returns false. This doesn't indicate we have coverage |
| 1207 | * or are authorized onto a network, just whether or not the |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1208 | * hardware supports it. For example a GSM phone without a SIM |
| 1209 | * should still return {@code true} for mobile data, but a wifi only |
| 1210 | * tablet would return {@code false}. |
| 1211 | * |
| 1212 | * @param networkType The network type we'd like to check |
| 1213 | * @return {@code true} if supported, else {@code false} |
| 1214 | * |
| 1215 | * <p>This method requires the call to hold the permission |
| 1216 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Robert Greenwalt | 9b2886e | 2011-08-31 11:46:42 -0700 | [diff] [blame] | 1217 | * @hide |
| 1218 | */ |
| 1219 | public boolean isNetworkSupported(int networkType) { |
| 1220 | try { |
| 1221 | return mService.isNetworkSupported(networkType); |
| 1222 | } catch (RemoteException e) {} |
| 1223 | return false; |
| 1224 | } |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 1225 | |
| 1226 | /** |
| 1227 | * Returns if the currently active data network is metered. A network is |
| 1228 | * classified as metered when the user is sensitive to heavy data usage on |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1229 | * that connection due to monetary costs, data limitations or |
| 1230 | * battery/performance issues. You should check this before doing large |
| 1231 | * data transfers, and warn the user or delay the operation until another |
| 1232 | * network is available. |
| 1233 | * |
| 1234 | * @return {@code true} if large transfers should be avoided, otherwise |
| 1235 | * {@code false}. |
| 1236 | * |
| 1237 | * <p>This method requires the call to hold the permission |
| 1238 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 1239 | */ |
| 1240 | public boolean isActiveNetworkMetered() { |
| 1241 | try { |
| 1242 | return mService.isActiveNetworkMetered(); |
| 1243 | } catch (RemoteException e) { |
| 1244 | return false; |
| 1245 | } |
| 1246 | } |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 1247 | |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1248 | /** |
| 1249 | * If the LockdownVpn mechanism is enabled, updates the vpn |
| 1250 | * with a reload of its profile. |
| 1251 | * |
| 1252 | * @return a boolean with {@code} indicating success |
| 1253 | * |
| 1254 | * <p>This method can only be called by the system UID |
| 1255 | * {@hide} |
| 1256 | */ |
Jeff Sharkey | 69ddab4 | 2012-08-25 00:05:46 -0700 | [diff] [blame] | 1257 | public boolean updateLockdownVpn() { |
| 1258 | try { |
| 1259 | return mService.updateLockdownVpn(); |
| 1260 | } catch (RemoteException e) { |
| 1261 | return false; |
| 1262 | } |
| 1263 | } |
Irfan Sheriff | da6da09 | 2012-08-16 12:49:23 -0700 | [diff] [blame] | 1264 | |
| 1265 | /** |
Robert Greenwalt | 5a6bdc4 | 2013-02-15 10:56:35 -0800 | [diff] [blame^] | 1266 | * Signal that the captive portal check on the indicated network |
| 1267 | * is complete and we can turn the network on for general use. |
| 1268 | * |
| 1269 | * @param info the {@link NetworkInfo} object for the networkType |
| 1270 | * in question. |
| 1271 | * |
| 1272 | * <p>This method requires the call to hold the permission |
| 1273 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}. |
Irfan Sheriff | da6da09 | 2012-08-16 12:49:23 -0700 | [diff] [blame] | 1274 | * {@hide} |
| 1275 | */ |
| 1276 | public void captivePortalCheckComplete(NetworkInfo info) { |
| 1277 | try { |
| 1278 | mService.captivePortalCheckComplete(info); |
| 1279 | } catch (RemoteException e) { |
| 1280 | } |
| 1281 | } |
| 1282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | } |