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