ConnectivityManager.java revision 75fbb4bdfde9188081f000506845d852f31362f0
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.content.Context; 24import android.os.Binder; 25import android.os.Build.VERSION_CODES; 26import android.os.RemoteException; 27import android.provider.Settings; 28 29import 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 */ 47public 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 * @see #EXTRA_NETWORK_TYPE 93 */ 94 @Deprecated 95 public static final String EXTRA_NETWORK_INFO = "networkInfo"; 96 97 /** 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 /** 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"; 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 144 * {@link android.content.Intent#getIntExtra(String, int)}. 145 * {@hide} 146 */ 147 public static final String EXTRA_INET_CONDITION = "inetCondition"; 148 149 /** 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 /** 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 177 * {@code false}. 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. 188 */ 189 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 190 @Deprecated 191 public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED = 192 "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; 193 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 204 /** 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 214 * gives a String[] 215 */ 216 public static final String EXTRA_AVAILABLE_TETHER = "availableArray"; 217 218 /** 219 * @hide 220 * gives a String[] 221 */ 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"; 229 230 /** 231 * The absence of APN.. 232 * @hide 233 */ 234 public static final int TYPE_NONE = -1; 235 236 /** 237 * The Default Mobile data connection. When active, all data traffic 238 * will use this connection by default. 239 */ 240 public static final int TYPE_MOBILE = 0; 241 /** 242 * The Default WIFI data connection. When active, all data traffic 243 * will use this connection by default. 244 */ 245 public static final int TYPE_WIFI = 1; 246 /** 247 * An MMS-specific Mobile data connection. This connection may be the 248 * same as {@link #TYPE_MOBILE} but it may be different. This is used 249 * by applications needing to talk to the carrier's Multimedia Messaging 250 * Service servers. It may coexist with default data connections. 251 */ 252 public static final int TYPE_MOBILE_MMS = 2; 253 /** 254 * A SUPL-specific Mobile data connection. This connection may be the 255 * same as {@link #TYPE_MOBILE} but it may be different. This is used 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. 259 */ 260 public static final int TYPE_MOBILE_SUPL = 3; 261 /** 262 * A DUN-specific Mobile data connection. This connection may be the 263 * same as {@link #TYPE_MOBILE} but it may be different. This is used 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. 267 */ 268 public static final int TYPE_MOBILE_DUN = 4; 269 /** 270 * A High Priority Mobile data connection. This connection is typically 271 * the same as {@link #TYPE_MOBILE} but the routing setup is different. 272 * Only requesting processes will have access to the Mobile DNS servers 273 * and only IP's explicitly requested via {@link #requestRouteToHost} 274 * will route over this interface if a default route exists. 275 */ 276 public static final int TYPE_MOBILE_HIPRI = 5; 277 /** 278 * The Default WiMAX data connection. When active, all data traffic 279 * will use this connection by default. 280 */ 281 public static final int TYPE_WIMAX = 6; 282 283 /** 284 * The Default Bluetooth data connection. When active, all data traffic 285 * will use this connection by default. 286 */ 287 public static final int TYPE_BLUETOOTH = 7; 288 289 /** 290 * Dummy data connection. This should not be used on shipping devices. 291 */ 292 public static final int TYPE_DUMMY = 8; 293 294 /** 295 * The Default Ethernet data connection. When active, all data traffic 296 * will use this connection by default. 297 */ 298 public static final int TYPE_ETHERNET = 9; 299 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 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; 324 325 /** {@hide} */ 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; 330 331 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; 332 333 private final IConnectivityManager mService; 334 335 public static boolean isNetworkTypeValid(int networkType) { 336 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; 337 } 338 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"; 368 case TYPE_WIFI_P2P: 369 return "WIFI_P2P"; 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 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 407 /** 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. 412 * <p>This method requires the caller to hold the permission 413 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. 414 */ 415 public NetworkInfo getActiveNetworkInfo() { 416 try { 417 return mService.getActiveNetworkInfo(); 418 } catch (RemoteException e) { 419 return null; 420 } 421 } 422 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 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 448 /** {@hide} */ 449 public LinkProperties getActiveLinkProperties() { 450 try { 451 return mService.getActiveLinkProperties(); 452 } catch (RemoteException e) { 453 return null; 454 } 455 } 456 457 /** {@hide} */ 458 public LinkProperties getLinkProperties(int networkType) { 459 try { 460 return mService.getLinkProperties(networkType); 461 } catch (RemoteException e) { 462 return null; 463 } 464 } 465 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. 488 * <p>This method requires the caller to hold the permission 489 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 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 { 499 return mService.startUsingNetworkFeature(networkType, feature, 500 new Binder()); 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. 510 * <p>This method requires the caller to hold the permission 511 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 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. 531 * <p>This method requires the caller to hold the permission 532 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 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) { 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(); 560 try { 561 return mService.requestRouteToHostAddress(networkType, address); 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}. 575 * <p> 576 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of 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. 580 * 581 * @return Whether background data usage is allowed. 582 */ 583 @Deprecated 584 public boolean getBackgroundDataSetting() { 585 // assume that background data is allowed; final authority is 586 // NetworkInfo which may be blocked. 587 return true; 588 } 589 590 /** 591 * Sets the value of the setting for background data usage. 592 * 593 * @param allowBackgroundData Whether an application should use data while 594 * it is in the background. 595 * 596 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING 597 * @see #getBackgroundDataSetting() 598 * @hide 599 */ 600 @Deprecated 601 public void setBackgroundDataSetting(boolean allowBackgroundData) { 602 // ignored 603 } 604 605 /** 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. 609 * 610 * @hide 611 */ 612 public NetworkQuotaInfo getActiveNetworkQuotaInfo() { 613 try { 614 return mService.getActiveNetworkQuotaInfo(); 615 } catch (RemoteException e) { 616 return null; 617 } 618 } 619 620 /** 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 * 637 * @param enabled Whether the mobile data connection should be 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 648 /** 649 * {@hide} 650 */ 651 public ConnectivityManager(IConnectivityManager service) { 652 mService = checkNotNull(service, "missing IConnectivityManager"); 653 } 654 655 /** {@hide} */ 656 public static ConnectivityManager from(Context context) { 657 return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 658 } 659 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 */ 685 public String[] getTetheringErroredIfaces() { 686 try { 687 return mService.getTetheringErroredIfaces(); 688 } catch (RemoteException e) { 689 return new String[0]; 690 } 691 } 692 693 /** 694 * @return error A TETHER_ERROR value indicating success or failure type 695 * {@hide} 696 */ 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) { 710 try { 711 return mService.untether(iface); 712 } catch (RemoteException e) { 713 return TETHER_ERROR_SERVICE_UNAVAIL; 714 } 715 } 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 } 749 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 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 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 } 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 } 823 824 /** 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 } 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 } 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 } 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 } 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 } 915} 916