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