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