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 |
| 65 | * reciever should expect another broadcast soon, indicating either that |
| 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 | */ |
| 73 | public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 74 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | /** |
Jeff Sharkey | 961e304 | 2011-08-29 16:02:57 -0700 | [diff] [blame] | 76 | * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any |
| 77 | * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}. |
| 78 | * |
| 79 | * @hide |
| 80 | */ |
| 81 | public static final String CONNECTIVITY_ACTION_IMMEDIATE = |
| 82 | "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE"; |
| 83 | |
| 84 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | * The lookup key for a {@link NetworkInfo} object. Retrieve with |
| 86 | * {@link android.content.Intent#getParcelableExtra(String)}. |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 87 | * |
| 88 | * @deprecated Since {@link NetworkInfo} can vary based on UID, applications |
| 89 | * should always obtain network information through |
| 90 | * {@link #getActiveNetworkInfo()} or |
| 91 | * {@link #getAllNetworkInfo()}. |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame^] | 92 | * @see #EXTRA_NETWORK_TYPE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | */ |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 94 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | public static final String EXTRA_NETWORK_INFO = "networkInfo"; |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | /** |
Jeff Sharkey | 75fbb4b | 2012-08-06 11:41:50 -0700 | [diff] [blame^] | 98 | * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast. |
| 99 | * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo} |
| 100 | * state based on the calling application. |
| 101 | * |
| 102 | * @see android.content.Intent#getIntExtra(String, int) |
| 103 | */ |
| 104 | public static final String EXTRA_NETWORK_TYPE = "networkType"; |
| 105 | |
| 106 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | * The lookup key for a boolean that indicates whether a connect event |
| 108 | * is for a network to which the connectivity manager was failing over |
| 109 | * following a disconnect on another network. |
| 110 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 111 | */ |
| 112 | public static final String EXTRA_IS_FAILOVER = "isFailover"; |
| 113 | /** |
| 114 | * The lookup key for a {@link NetworkInfo} object. This is supplied when |
| 115 | * there is another network that it may be possible to connect to. Retrieve with |
| 116 | * {@link android.content.Intent#getParcelableExtra(String)}. |
| 117 | */ |
| 118 | public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork"; |
| 119 | /** |
| 120 | * The lookup key for a boolean that indicates whether there is a |
| 121 | * complete lack of connectivity, i.e., no network is available. |
| 122 | * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}. |
| 123 | */ |
| 124 | public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity"; |
| 125 | /** |
| 126 | * The lookup key for a string that indicates why an attempt to connect |
| 127 | * to a network failed. The string has no particular structure. It is |
| 128 | * intended to be used in notifications presented to users. Retrieve |
| 129 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 130 | */ |
| 131 | public static final String EXTRA_REASON = "reason"; |
| 132 | /** |
| 133 | * The lookup key for a string that provides optionally supplied |
| 134 | * extra information about the network state. The information |
| 135 | * may be passed up from the lower networking layers, and its |
| 136 | * meaning may be specific to a particular network type. Retrieve |
| 137 | * it with {@link android.content.Intent#getStringExtra(String)}. |
| 138 | */ |
| 139 | public static final String EXTRA_EXTRA_INFO = "extraInfo"; |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 140 | /** |
| 141 | * The lookup key for an int that provides information about |
| 142 | * our connection to the internet at large. 0 indicates no connection, |
| 143 | * 100 indicates a great connection. Retrieve it with |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 144 | * {@link android.content.Intent#getIntExtra(String, int)}. |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 145 | * {@hide} |
| 146 | */ |
| 147 | public static final String EXTRA_INET_CONDITION = "inetCondition"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
| 149 | /** |
Haoyu Bai | db3c867 | 2012-06-20 14:29:57 -0700 | [diff] [blame] | 150 | * Broadcast action to indicate the change of data activity status |
| 151 | * (idle or active) on a network in a recent period. |
| 152 | * The network becomes active when data transimission is started, or |
| 153 | * idle if there is no data transimition for a period of time. |
| 154 | * {@hide} |
| 155 | */ |
| 156 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 157 | public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE"; |
| 158 | /** |
| 159 | * The lookup key for an enum that indicates the network device type on which this data activity |
| 160 | * change happens. |
| 161 | * {@hide} |
| 162 | */ |
| 163 | public static final String EXTRA_DEVICE_TYPE = "deviceType"; |
| 164 | /** |
| 165 | * The lookup key for a boolean that indicates the device is active or not. {@code true} means |
| 166 | * it is actively sending or receiving data and {@code false} means it is idle. |
| 167 | * {@hide} |
| 168 | */ |
| 169 | public static final String EXTRA_IS_ACTIVE = "isActive"; |
| 170 | |
| 171 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | * Broadcast Action: The setting for background data usage has changed |
| 173 | * values. Use {@link #getBackgroundDataSetting()} to get the current value. |
| 174 | * <p> |
| 175 | * If an application uses the network in the background, it should listen |
| 176 | * 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] | 177 | * {@code false}. |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 178 | * <p> |
| 179 | * |
| 180 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability |
| 181 | * of background data depends on several combined factors, and |
| 182 | * this broadcast is no longer sent. Instead, when background |
| 183 | * data is unavailable, {@link #getActiveNetworkInfo()} will now |
| 184 | * appear disconnected. During first boot after a platform |
| 185 | * upgrade, this broadcast will be sent once if |
| 186 | * {@link #getBackgroundDataSetting()} was {@code false} before |
| 187 | * the upgrade. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | */ |
| 189 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
Jeff Sharkey | 54ee2ad | 2012-01-30 16:29:24 -0800 | [diff] [blame] | 190 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = |
| 192 | "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; |
| 193 | |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 194 | /** |
| 195 | * Broadcast Action: The network connection may not be good |
| 196 | * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and |
| 197 | * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify |
| 198 | * the network and it's condition. |
| 199 | * @hide |
| 200 | */ |
| 201 | public static final String INET_CONDITION_ACTION = |
| 202 | "android.net.conn.INET_CONDITION_ACTION"; |
| 203 | |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 204 | /** |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 205 | * Broadcast Action: A tetherable connection has come or gone |
| 206 | * TODO - finish the doc |
| 207 | * @hide |
| 208 | */ |
| 209 | public static final String ACTION_TETHER_STATE_CHANGED = |
| 210 | "android.net.conn.TETHER_STATE_CHANGED"; |
| 211 | |
| 212 | /** |
| 213 | * @hide |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 214 | * gives a String[] |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 215 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 216 | public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * @hide |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 220 | * gives a String[] |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 221 | */ |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 222 | public static final String EXTRA_ACTIVE_TETHER = "activeArray"; |
| 223 | |
| 224 | /** |
| 225 | * @hide |
| 226 | * gives a String[] |
| 227 | */ |
| 228 | public static final String EXTRA_ERRORED_TETHER = "erroredArray"; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 229 | |
| 230 | /** |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 231 | * The absence of APN.. |
| 232 | * @hide |
| 233 | */ |
| 234 | public static final int TYPE_NONE = -1; |
| 235 | |
| 236 | /** |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 237 | * The Default Mobile data connection. When active, all data traffic |
Robert Greenwalt | 97ab2d4 | 2011-05-27 11:29:13 -0700 | [diff] [blame] | 238 | * will use this connection by default. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 239 | */ |
| 240 | public static final int TYPE_MOBILE = 0; |
| 241 | /** |
| 242 | * The Default WIFI data connection. When active, all data traffic |
Robert Greenwalt | 97ab2d4 | 2011-05-27 11:29:13 -0700 | [diff] [blame] | 243 | * will use this connection by default. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 244 | */ |
| 245 | public static final int TYPE_WIFI = 1; |
| 246 | /** |
| 247 | * An MMS-specific Mobile data connection. This connection may be the |
Robert Greenwalt | 1bc3c37 | 2010-01-13 11:29:03 -0800 | [diff] [blame] | 248 | * same as {@link #TYPE_MOBILE} but it may be different. This is used |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 249 | * by applications needing to talk to the carrier's Multimedia Messaging |
| 250 | * Service servers. It may coexist with default data connections. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 251 | */ |
| 252 | public static final int TYPE_MOBILE_MMS = 2; |
| 253 | /** |
| 254 | * A SUPL-specific Mobile data connection. This connection may be the |
Robert Greenwalt | 1bc3c37 | 2010-01-13 11:29:03 -0800 | [diff] [blame] | 255 | * same as {@link #TYPE_MOBILE} but it may be different. This is used |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 256 | * by applications needing to talk to the carrier's Secure User Plane |
| 257 | * Location servers for help locating the device. It may coexist with |
| 258 | * default data connections. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 259 | */ |
| 260 | public static final int TYPE_MOBILE_SUPL = 3; |
| 261 | /** |
| 262 | * A DUN-specific Mobile data connection. This connection may be the |
Robert Greenwalt | 1bc3c37 | 2010-01-13 11:29:03 -0800 | [diff] [blame] | 263 | * same as {@link #TYPE_MOBILE} but it may be different. This is used |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 264 | * by applicaitons performing a Dial Up Networking bridge so that |
| 265 | * the carrier is aware of DUN traffic. It may coexist with default data |
| 266 | * connections. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 267 | */ |
| 268 | public static final int TYPE_MOBILE_DUN = 4; |
| 269 | /** |
| 270 | * A High Priority Mobile data connection. This connection is typically |
Robert Greenwalt | 1bc3c37 | 2010-01-13 11:29:03 -0800 | [diff] [blame] | 271 | * the same as {@link #TYPE_MOBILE} but the routing setup is different. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 272 | * Only requesting processes will have access to the Mobile DNS servers |
| 273 | * and only IP's explicitly requested via {@link #requestRouteToHost} |
Robert Greenwalt | c849cdf | 2010-01-08 11:47:27 -0800 | [diff] [blame] | 274 | * will route over this interface if a default route exists. |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 275 | */ |
| 276 | public static final int TYPE_MOBILE_HIPRI = 5; |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 277 | /** |
| 278 | * The Default WiMAX data connection. When active, all data traffic |
Robert Greenwalt | 97ab2d4 | 2011-05-27 11:29:13 -0700 | [diff] [blame] | 279 | * will use this connection by default. |
jsh | 8214deb | 2010-03-11 15:04:43 -0800 | [diff] [blame] | 280 | */ |
| 281 | public static final int TYPE_WIMAX = 6; |
Robert Greenwalt | da3d5e6 | 2010-12-06 13:56:24 -0800 | [diff] [blame] | 282 | |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 283 | /** |
Robert Greenwalt | 97ab2d4 | 2011-05-27 11:29:13 -0700 | [diff] [blame] | 284 | * The Default Bluetooth data connection. When active, all data traffic |
| 285 | * will use this connection by default. |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 286 | */ |
| 287 | public static final int TYPE_BLUETOOTH = 7; |
| 288 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 289 | /** |
| 290 | * Dummy data connection. This should not be used on shipping devices. |
| 291 | */ |
Jaikumar Ganesh | 15c7439 | 2010-12-21 22:31:44 -0800 | [diff] [blame] | 292 | public static final int TYPE_DUMMY = 8; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 293 | |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 294 | /** |
Robert Greenwalt | 97ab2d4 | 2011-05-27 11:29:13 -0700 | [diff] [blame] | 295 | * The Default Ethernet data connection. When active, all data traffic |
| 296 | * will use this connection by default. |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 297 | */ |
Robert Greenwalt | e12aec9 | 2011-01-28 14:48:37 -0800 | [diff] [blame] | 298 | public static final int TYPE_ETHERNET = 9; |
Robert Greenwalt | 6081084 | 2011-04-22 15:28:18 -0700 | [diff] [blame] | 299 | |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 300 | /** |
| 301 | * Over the air Adminstration. |
| 302 | * {@hide} |
| 303 | */ |
| 304 | public static final int TYPE_MOBILE_FOTA = 10; |
| 305 | |
| 306 | /** |
| 307 | * IP Multimedia Subsystem |
| 308 | * {@hide} |
| 309 | */ |
| 310 | public static final int TYPE_MOBILE_IMS = 11; |
| 311 | |
| 312 | /** |
| 313 | * Carrier Branded Services |
| 314 | * {@hide} |
| 315 | */ |
| 316 | public static final int TYPE_MOBILE_CBS = 12; |
| 317 | |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 318 | /** |
| 319 | * A Wi-Fi p2p connection. Only requesting processes will have access to |
| 320 | * the peers connected. |
| 321 | * {@hide} |
| 322 | */ |
| 323 | public static final int TYPE_WIFI_P2P = 13; |
Wink Saville | 9d7d628 | 2011-03-12 14:52:01 -0800 | [diff] [blame] | 324 | |
| 325 | /** {@hide} */ |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 326 | public static final int MAX_RADIO_TYPE = TYPE_WIFI_P2P; |
| 327 | |
| 328 | /** {@hide} */ |
| 329 | 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] | 330 | |
| 331 | public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; |
| 332 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 333 | private final IConnectivityManager mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 335 | public static boolean isNetworkTypeValid(int networkType) { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 336 | return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 339 | /** {@hide} */ |
| 340 | public static String getNetworkTypeName(int type) { |
| 341 | switch (type) { |
| 342 | case TYPE_MOBILE: |
| 343 | return "MOBILE"; |
| 344 | case TYPE_WIFI: |
| 345 | return "WIFI"; |
| 346 | case TYPE_MOBILE_MMS: |
| 347 | return "MOBILE_MMS"; |
| 348 | case TYPE_MOBILE_SUPL: |
| 349 | return "MOBILE_SUPL"; |
| 350 | case TYPE_MOBILE_DUN: |
| 351 | return "MOBILE_DUN"; |
| 352 | case TYPE_MOBILE_HIPRI: |
| 353 | return "MOBILE_HIPRI"; |
| 354 | case TYPE_WIMAX: |
| 355 | return "WIMAX"; |
| 356 | case TYPE_BLUETOOTH: |
| 357 | return "BLUETOOTH"; |
| 358 | case TYPE_DUMMY: |
| 359 | return "DUMMY"; |
| 360 | case TYPE_ETHERNET: |
| 361 | return "ETHERNET"; |
| 362 | case TYPE_MOBILE_FOTA: |
| 363 | return "MOBILE_FOTA"; |
| 364 | case TYPE_MOBILE_IMS: |
| 365 | return "MOBILE_IMS"; |
| 366 | case TYPE_MOBILE_CBS: |
| 367 | return "MOBILE_CBS"; |
repo sync | aea743a | 2011-07-29 23:55:49 -0700 | [diff] [blame] | 368 | case TYPE_WIFI_P2P: |
| 369 | return "WIFI_P2P"; |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 370 | default: |
| 371 | return Integer.toString(type); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /** {@hide} */ |
| 376 | public static boolean isNetworkTypeMobile(int networkType) { |
| 377 | switch (networkType) { |
| 378 | case TYPE_MOBILE: |
| 379 | case TYPE_MOBILE_MMS: |
| 380 | case TYPE_MOBILE_SUPL: |
| 381 | case TYPE_MOBILE_DUN: |
| 382 | case TYPE_MOBILE_HIPRI: |
| 383 | case TYPE_MOBILE_FOTA: |
| 384 | case TYPE_MOBILE_IMS: |
| 385 | case TYPE_MOBILE_CBS: |
| 386 | return true; |
| 387 | default: |
| 388 | return false; |
| 389 | } |
| 390 | } |
| 391 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | public void setNetworkPreference(int preference) { |
| 393 | try { |
| 394 | mService.setNetworkPreference(preference); |
| 395 | } catch (RemoteException e) { |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | public int getNetworkPreference() { |
| 400 | try { |
| 401 | return mService.getNetworkPreference(); |
| 402 | } catch (RemoteException e) { |
| 403 | return -1; |
| 404 | } |
| 405 | } |
| 406 | |
Scott Main | 671644c | 2011-10-06 19:02:28 -0700 | [diff] [blame] | 407 | /** |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 408 | * Returns details about the currently active data network. When connected, |
| 409 | * this network is the default route for outgoing connections. You should |
| 410 | * always check {@link NetworkInfo#isConnected()} before initiating network |
| 411 | * traffic. This may return {@code null} when no networks are available. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 412 | * <p>This method requires the caller to hold the permission |
| 413 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 414 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | public NetworkInfo getActiveNetworkInfo() { |
| 416 | try { |
| 417 | return mService.getActiveNetworkInfo(); |
| 418 | } catch (RemoteException e) { |
| 419 | return null; |
| 420 | } |
| 421 | } |
| 422 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 423 | /** {@hide} */ |
| 424 | public NetworkInfo getActiveNetworkInfoForUid(int uid) { |
| 425 | try { |
| 426 | return mService.getActiveNetworkInfoForUid(uid); |
| 427 | } catch (RemoteException e) { |
| 428 | return null; |
| 429 | } |
| 430 | } |
| 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | public NetworkInfo getNetworkInfo(int networkType) { |
| 433 | try { |
| 434 | return mService.getNetworkInfo(networkType); |
| 435 | } catch (RemoteException e) { |
| 436 | return null; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | public NetworkInfo[] getAllNetworkInfo() { |
| 441 | try { |
| 442 | return mService.getAllNetworkInfo(); |
| 443 | } catch (RemoteException e) { |
| 444 | return null; |
| 445 | } |
| 446 | } |
| 447 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 448 | /** {@hide} */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 449 | public LinkProperties getActiveLinkProperties() { |
| 450 | try { |
| 451 | return mService.getActiveLinkProperties(); |
| 452 | } catch (RemoteException e) { |
| 453 | return null; |
| 454 | } |
| 455 | } |
| 456 | |
Jeff Sharkey | c006f1a | 2011-05-19 17:12:49 -0700 | [diff] [blame] | 457 | /** {@hide} */ |
Robert Greenwalt | d192dad | 2010-09-14 09:18:02 -0700 | [diff] [blame] | 458 | public LinkProperties getLinkProperties(int networkType) { |
| 459 | try { |
| 460 | return mService.getLinkProperties(networkType); |
| 461 | } catch (RemoteException e) { |
| 462 | return null; |
| 463 | } |
| 464 | } |
| 465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | /** {@hide} */ |
| 467 | public boolean setRadios(boolean turnOn) { |
| 468 | try { |
| 469 | return mService.setRadios(turnOn); |
| 470 | } catch (RemoteException e) { |
| 471 | return false; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | /** {@hide} */ |
| 476 | public boolean setRadio(int networkType, boolean turnOn) { |
| 477 | try { |
| 478 | return mService.setRadio(networkType, turnOn); |
| 479 | } catch (RemoteException e) { |
| 480 | return false; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Tells the underlying networking system that the caller wants to |
| 486 | * begin using the named feature. The interpretation of {@code feature} |
| 487 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 488 | * <p>This method requires the caller to hold the permission |
| 489 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | * @param networkType specifies which network the request pertains to |
| 491 | * @param feature the name of the feature to be used |
| 492 | * @return an integer value representing the outcome of the request. |
| 493 | * The interpretation of this value is specific to each networking |
| 494 | * implementation+feature combination, except that the value {@code -1} |
| 495 | * always indicates failure. |
| 496 | */ |
| 497 | public int startUsingNetworkFeature(int networkType, String feature) { |
| 498 | try { |
Robert Greenwalt | 42acef3 | 2009-08-12 16:08:25 -0700 | [diff] [blame] | 499 | return mService.startUsingNetworkFeature(networkType, feature, |
| 500 | new Binder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } catch (RemoteException e) { |
| 502 | return -1; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Tells the underlying networking system that the caller is finished |
| 508 | * using the named feature. The interpretation of {@code feature} |
| 509 | * is completely up to each networking implementation. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 510 | * <p>This method requires the caller to hold the permission |
| 511 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | * @param networkType specifies which network the request pertains to |
| 513 | * @param feature the name of the feature that is no longer needed |
| 514 | * @return an integer value representing the outcome of the request. |
| 515 | * The interpretation of this value is specific to each networking |
| 516 | * implementation+feature combination, except that the value {@code -1} |
| 517 | * always indicates failure. |
| 518 | */ |
| 519 | public int stopUsingNetworkFeature(int networkType, String feature) { |
| 520 | try { |
| 521 | return mService.stopUsingNetworkFeature(networkType, feature); |
| 522 | } catch (RemoteException e) { |
| 523 | return -1; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Ensure that a network route exists to deliver traffic to the specified |
| 529 | * host via the specified network interface. An attempt to add a route that |
| 530 | * already exists is ignored, but treated as successful. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 531 | * <p>This method requires the caller to hold the permission |
| 532 | * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | * @param networkType the type of the network over which traffic to the specified |
| 534 | * host is to be routed |
| 535 | * @param hostAddress the IP address of the host to which the route is desired |
| 536 | * @return {@code true} on success, {@code false} on failure |
| 537 | */ |
| 538 | public boolean requestRouteToHost(int networkType, int hostAddress) { |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 539 | InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); |
| 540 | |
| 541 | if (inetAddress == null) { |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | return requestRouteToHostAddress(networkType, inetAddress); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Ensure that a network route exists to deliver traffic to the specified |
| 550 | * host via the specified network interface. An attempt to add a route that |
| 551 | * already exists is ignored, but treated as successful. |
| 552 | * @param networkType the type of the network over which traffic to the specified |
| 553 | * host is to be routed |
| 554 | * @param hostAddress the IP address of the host to which the route is desired |
| 555 | * @return {@code true} on success, {@code false} on failure |
| 556 | * @hide |
| 557 | */ |
| 558 | public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { |
| 559 | byte[] address = hostAddress.getAddress(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | try { |
Robert Greenwalt | 585ac0f | 2010-08-27 09:24:29 -0700 | [diff] [blame] | 561 | return mService.requestRouteToHostAddress(networkType, address); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | } catch (RemoteException e) { |
| 563 | return false; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Returns the value of the setting for background data usage. If false, |
| 569 | * applications should not use the network if the application is not in the |
| 570 | * foreground. Developers should respect this setting, and check the value |
| 571 | * of this before performing any background data operations. |
| 572 | * <p> |
| 573 | * All applications that have background services that use the network |
| 574 | * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 575 | * <p> |
Scott Main | 4cc5333 | 2011-10-06 18:32:43 -0700 | [diff] [blame] | 576 | * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 577 | * background data depends on several combined factors, and this method will |
| 578 | * always return {@code true}. Instead, when background data is unavailable, |
| 579 | * {@link #getActiveNetworkInfo()} will now appear disconnected. |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 580 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | * @return Whether background data usage is allowed. |
| 582 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 583 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | public boolean getBackgroundDataSetting() { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 585 | // assume that background data is allowed; final authority is |
| 586 | // NetworkInfo which may be blocked. |
| 587 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Sets the value of the setting for background data usage. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 592 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | * @param allowBackgroundData Whether an application should use data while |
| 594 | * it is in the background. |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 595 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING |
| 597 | * @see #getBackgroundDataSetting() |
| 598 | * @hide |
| 599 | */ |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 600 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | public void setBackgroundDataSetting(boolean allowBackgroundData) { |
Jeff Sharkey | 3a844fc | 2011-08-16 14:37:57 -0700 | [diff] [blame] | 602 | // ignored |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | } |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 604 | |
| 605 | /** |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 606 | * Return quota status for the current active network, or {@code null} if no |
| 607 | * network is active. Quota status can change rapidly, so these values |
| 608 | * shouldn't be cached. |
Jeff Sharkey | 44a3e0d | 2011-10-06 10:50:09 -0700 | [diff] [blame] | 609 | * |
| 610 | * @hide |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 611 | */ |
| 612 | public NetworkQuotaInfo getActiveNetworkQuotaInfo() { |
| 613 | try { |
| 614 | return mService.getActiveNetworkQuotaInfo(); |
| 615 | } catch (RemoteException e) { |
| 616 | return null; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 621 | * Gets the value of the setting for enabling Mobile data. |
| 622 | * |
| 623 | * @return Whether mobile data is enabled. |
| 624 | * @hide |
| 625 | */ |
| 626 | public boolean getMobileDataEnabled() { |
| 627 | try { |
| 628 | return mService.getMobileDataEnabled(); |
| 629 | } catch (RemoteException e) { |
| 630 | return true; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Sets the persisted value for enabling/disabling Mobile data. |
| 636 | * |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 637 | * @param enabled Whether the mobile data connection should be |
Robert Greenwalt | c03fa50 | 2010-02-23 18:58:05 -0800 | [diff] [blame] | 638 | * used or not. |
| 639 | * @hide |
| 640 | */ |
| 641 | public void setMobileDataEnabled(boolean enabled) { |
| 642 | try { |
| 643 | mService.setMobileDataEnabled(enabled); |
| 644 | } catch (RemoteException e) { |
| 645 | } |
| 646 | } |
| 647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | * {@hide} |
| 650 | */ |
| 651 | public ConnectivityManager(IConnectivityManager service) { |
Jeff Sharkey | f0ceede | 2011-08-02 17:22:34 -0700 | [diff] [blame] | 652 | mService = checkNotNull(service, "missing IConnectivityManager"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 654 | |
Jeff Sharkey | 8fc27e8 | 2012-04-04 20:40:58 -0700 | [diff] [blame] | 655 | /** {@hide} */ |
| 656 | public static ConnectivityManager from(Context context) { |
| 657 | return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
| 658 | } |
| 659 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 660 | /** |
| 661 | * {@hide} |
| 662 | */ |
| 663 | public String[] getTetherableIfaces() { |
| 664 | try { |
| 665 | return mService.getTetherableIfaces(); |
| 666 | } catch (RemoteException e) { |
| 667 | return new String[0]; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * {@hide} |
| 673 | */ |
| 674 | public String[] getTetheredIfaces() { |
| 675 | try { |
| 676 | return mService.getTetheredIfaces(); |
| 677 | } catch (RemoteException e) { |
| 678 | return new String[0]; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * {@hide} |
| 684 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 685 | public String[] getTetheringErroredIfaces() { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 686 | try { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 687 | return mService.getTetheringErroredIfaces(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 688 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 689 | return new String[0]; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | /** |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 694 | * @return error A TETHER_ERROR value indicating success or failure type |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 695 | * {@hide} |
| 696 | */ |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 697 | public int tether(String iface) { |
| 698 | try { |
| 699 | return mService.tether(iface); |
| 700 | } catch (RemoteException e) { |
| 701 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /** |
| 706 | * @return error A TETHER_ERROR value indicating success or failure type |
| 707 | * {@hide} |
| 708 | */ |
| 709 | public int untether(String iface) { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 710 | try { |
| 711 | return mService.untether(iface); |
| 712 | } catch (RemoteException e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 713 | return TETHER_ERROR_SERVICE_UNAVAIL; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 714 | } |
| 715 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 716 | |
| 717 | /** |
| 718 | * {@hide} |
| 719 | */ |
| 720 | public boolean isTetheringSupported() { |
| 721 | try { |
| 722 | return mService.isTetheringSupported(); |
| 723 | } catch (RemoteException e) { |
| 724 | return false; |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * {@hide} |
| 730 | */ |
| 731 | public String[] getTetherableUsbRegexs() { |
| 732 | try { |
| 733 | return mService.getTetherableUsbRegexs(); |
| 734 | } catch (RemoteException e) { |
| 735 | return new String[0]; |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * {@hide} |
| 741 | */ |
| 742 | public String[] getTetherableWifiRegexs() { |
| 743 | try { |
| 744 | return mService.getTetherableWifiRegexs(); |
| 745 | } catch (RemoteException e) { |
| 746 | return new String[0]; |
| 747 | } |
| 748 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 749 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 750 | /** |
| 751 | * {@hide} |
| 752 | */ |
| 753 | public String[] getTetherableBluetoothRegexs() { |
| 754 | try { |
| 755 | return mService.getTetherableBluetoothRegexs(); |
| 756 | } catch (RemoteException e) { |
| 757 | return new String[0]; |
| 758 | } |
| 759 | } |
| 760 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 761 | /** |
| 762 | * {@hide} |
| 763 | */ |
| 764 | public int setUsbTethering(boolean enable) { |
| 765 | try { |
| 766 | return mService.setUsbTethering(enable); |
| 767 | } catch (RemoteException e) { |
| 768 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 769 | } |
| 770 | } |
| 771 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 772 | /** {@hide} */ |
| 773 | public static final int TETHER_ERROR_NO_ERROR = 0; |
| 774 | /** {@hide} */ |
| 775 | public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; |
| 776 | /** {@hide} */ |
| 777 | public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; |
| 778 | /** {@hide} */ |
| 779 | public static final int TETHER_ERROR_UNSUPPORTED = 3; |
| 780 | /** {@hide} */ |
| 781 | public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; |
| 782 | /** {@hide} */ |
| 783 | public static final int TETHER_ERROR_MASTER_ERROR = 5; |
| 784 | /** {@hide} */ |
| 785 | public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; |
| 786 | /** {@hide} */ |
| 787 | public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; |
| 788 | /** {@hide} */ |
| 789 | public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; |
| 790 | /** {@hide} */ |
| 791 | public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; |
| 792 | /** {@hide} */ |
| 793 | public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; |
| 794 | |
| 795 | /** |
| 796 | * @param iface The name of the interface we're interested in |
| 797 | * @return error The error code of the last error tethering or untethering the named |
| 798 | * interface |
| 799 | * {@hide} |
| 800 | */ |
| 801 | public int getLastTetherError(String iface) { |
| 802 | try { |
| 803 | return mService.getLastTetherError(iface); |
| 804 | } catch (RemoteException e) { |
| 805 | return TETHER_ERROR_SERVICE_UNAVAIL; |
| 806 | } |
Robert Greenwalt | 14f2ef4 | 2010-06-15 12:19:37 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /** |
| 810 | * Ensure the device stays awake until we connect with the next network |
| 811 | * @param forWhome The name of the network going down for logging purposes |
| 812 | * @return {@code true} on success, {@code false} on failure |
| 813 | * {@hide} |
| 814 | */ |
| 815 | public boolean requestNetworkTransitionWakelock(String forWhom) { |
| 816 | try { |
| 817 | mService.requestNetworkTransitionWakelock(forWhom); |
| 818 | return true; |
| 819 | } catch (RemoteException e) { |
| 820 | return false; |
| 821 | } |
| 822 | } |
Robert Greenwalt | ca4306c | 2010-09-09 13:15:32 -0700 | [diff] [blame] | 823 | |
Robert Greenwalt | 67fd6c9 | 2010-09-09 14:22:59 -0700 | [diff] [blame] | 824 | /** |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 825 | * @param networkType The type of network you want to report on |
| 826 | * @param percentage The quality of the connection 0 is bad, 100 is good |
| 827 | * {@hide} |
| 828 | */ |
| 829 | public void reportInetCondition(int networkType, int percentage) { |
| 830 | try { |
| 831 | mService.reportInetCondition(networkType, percentage); |
| 832 | } catch (RemoteException e) { |
| 833 | } |
| 834 | } |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 835 | |
| 836 | /** |
| 837 | * @param proxyProperties The definition for the new global http proxy |
| 838 | * {@hide} |
| 839 | */ |
| 840 | public void setGlobalProxy(ProxyProperties p) { |
| 841 | try { |
| 842 | mService.setGlobalProxy(p); |
| 843 | } catch (RemoteException e) { |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * @return proxyProperties for the current global proxy |
| 849 | * {@hide} |
| 850 | */ |
| 851 | public ProxyProperties getGlobalProxy() { |
| 852 | try { |
| 853 | return mService.getGlobalProxy(); |
| 854 | } catch (RemoteException e) { |
| 855 | return null; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * @return proxyProperties for the current proxy (global if set, network specific if not) |
| 861 | * {@hide} |
| 862 | */ |
| 863 | public ProxyProperties getProxy() { |
| 864 | try { |
| 865 | return mService.getProxy(); |
| 866 | } catch (RemoteException e) { |
| 867 | return null; |
| 868 | } |
| 869 | } |
Robert Greenwalt | d55a6b4 | 2011-03-25 13:09:25 -0700 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * @param networkType The network who's dependence has changed |
| 873 | * @param met Boolean - true if network use is ok, false if not |
| 874 | * {@hide} |
| 875 | */ |
| 876 | public void setDataDependency(int networkType, boolean met) { |
| 877 | try { |
| 878 | mService.setDataDependency(networkType, met); |
| 879 | } catch (RemoteException e) { |
| 880 | } |
| 881 | } |
Robert Greenwalt | 9b2886e | 2011-08-31 11:46:42 -0700 | [diff] [blame] | 882 | |
| 883 | /** |
| 884 | * Returns true if the hardware supports the given network type |
| 885 | * else it returns false. This doesn't indicate we have coverage |
| 886 | * or are authorized onto a network, just whether or not the |
| 887 | * hardware supports it. For example a gsm phone without a sim |
| 888 | * should still return true for mobile data, but a wifi only tablet |
| 889 | * would return false. |
| 890 | * @param networkType The nework type we'd like to check |
| 891 | * @return true if supported, else false |
| 892 | * @hide |
| 893 | */ |
| 894 | public boolean isNetworkSupported(int networkType) { |
| 895 | try { |
| 896 | return mService.isNetworkSupported(networkType); |
| 897 | } catch (RemoteException e) {} |
| 898 | return false; |
| 899 | } |
Jeff Sharkey | 9f7cbf0 | 2012-04-12 18:34:54 -0700 | [diff] [blame] | 900 | |
| 901 | /** |
| 902 | * Returns if the currently active data network is metered. A network is |
| 903 | * classified as metered when the user is sensitive to heavy data usage on |
| 904 | * that connection. You should check this before doing large data transfers, |
| 905 | * and warn the user or delay the operation until another network is |
| 906 | * available. |
| 907 | */ |
| 908 | public boolean isActiveNetworkMetered() { |
| 909 | try { |
| 910 | return mService.isActiveNetworkMetered(); |
| 911 | } catch (RemoteException e) { |
| 912 | return false; |
| 913 | } |
| 914 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | } |