ConnectivityManager.java revision 4c8b7481cf8f2e571a160d086079e2f65a6afb05
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 /** 332 * If you want to set the default network preference,you can directly 333 * change the networkAttributes array in framework's config.xml. 334 * 335 * @deprecated Since we support so many more networks now, the single 336 * network default network preference can't really express 337 * the heirarchy. Instead, the default is defined by the 338 * networkAttributes in config.xml. You can determine 339 * the current value by calling {@link #getNetworkPreference()} 340 * from an App. 341 */ 342 @Deprecated 343 public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI; 344 345 /** 346 * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in 347 * milliseconds. 348 * 349 * @hide 350 */ 351 public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000; 352 353 private final IConnectivityManager mService; 354 355 public static boolean isNetworkTypeValid(int networkType) { 356 return networkType >= 0 && networkType <= MAX_NETWORK_TYPE; 357 } 358 359 /** {@hide} */ 360 public static String getNetworkTypeName(int type) { 361 switch (type) { 362 case TYPE_MOBILE: 363 return "MOBILE"; 364 case TYPE_WIFI: 365 return "WIFI"; 366 case TYPE_MOBILE_MMS: 367 return "MOBILE_MMS"; 368 case TYPE_MOBILE_SUPL: 369 return "MOBILE_SUPL"; 370 case TYPE_MOBILE_DUN: 371 return "MOBILE_DUN"; 372 case TYPE_MOBILE_HIPRI: 373 return "MOBILE_HIPRI"; 374 case TYPE_WIMAX: 375 return "WIMAX"; 376 case TYPE_BLUETOOTH: 377 return "BLUETOOTH"; 378 case TYPE_DUMMY: 379 return "DUMMY"; 380 case TYPE_ETHERNET: 381 return "ETHERNET"; 382 case TYPE_MOBILE_FOTA: 383 return "MOBILE_FOTA"; 384 case TYPE_MOBILE_IMS: 385 return "MOBILE_IMS"; 386 case TYPE_MOBILE_CBS: 387 return "MOBILE_CBS"; 388 case TYPE_WIFI_P2P: 389 return "WIFI_P2P"; 390 default: 391 return Integer.toString(type); 392 } 393 } 394 395 /** {@hide} */ 396 public static boolean isNetworkTypeMobile(int networkType) { 397 switch (networkType) { 398 case TYPE_MOBILE: 399 case TYPE_MOBILE_MMS: 400 case TYPE_MOBILE_SUPL: 401 case TYPE_MOBILE_DUN: 402 case TYPE_MOBILE_HIPRI: 403 case TYPE_MOBILE_FOTA: 404 case TYPE_MOBILE_IMS: 405 case TYPE_MOBILE_CBS: 406 return true; 407 default: 408 return false; 409 } 410 } 411 412 public void setNetworkPreference(int preference) { 413 try { 414 mService.setNetworkPreference(preference); 415 } catch (RemoteException e) { 416 } 417 } 418 419 public int getNetworkPreference() { 420 try { 421 return mService.getNetworkPreference(); 422 } catch (RemoteException e) { 423 return -1; 424 } 425 } 426 427 /** 428 * Returns details about the currently active data network. When connected, 429 * this network is the default route for outgoing connections. You should 430 * always check {@link NetworkInfo#isConnected()} before initiating network 431 * traffic. This may return {@code null} when no networks are available. 432 * <p>This method requires the caller to hold the permission 433 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. 434 */ 435 public NetworkInfo getActiveNetworkInfo() { 436 try { 437 return mService.getActiveNetworkInfo(); 438 } catch (RemoteException e) { 439 return null; 440 } 441 } 442 443 /** {@hide} */ 444 public NetworkInfo getActiveNetworkInfoForUid(int uid) { 445 try { 446 return mService.getActiveNetworkInfoForUid(uid); 447 } catch (RemoteException e) { 448 return null; 449 } 450 } 451 452 public NetworkInfo getNetworkInfo(int networkType) { 453 try { 454 return mService.getNetworkInfo(networkType); 455 } catch (RemoteException e) { 456 return null; 457 } 458 } 459 460 public NetworkInfo[] getAllNetworkInfo() { 461 try { 462 return mService.getAllNetworkInfo(); 463 } catch (RemoteException e) { 464 return null; 465 } 466 } 467 468 /** {@hide} */ 469 public LinkProperties getActiveLinkProperties() { 470 try { 471 return mService.getActiveLinkProperties(); 472 } catch (RemoteException e) { 473 return null; 474 } 475 } 476 477 /** {@hide} */ 478 public LinkProperties getLinkProperties(int networkType) { 479 try { 480 return mService.getLinkProperties(networkType); 481 } catch (RemoteException e) { 482 return null; 483 } 484 } 485 486 /** {@hide} */ 487 public boolean setRadios(boolean turnOn) { 488 try { 489 return mService.setRadios(turnOn); 490 } catch (RemoteException e) { 491 return false; 492 } 493 } 494 495 /** {@hide} */ 496 public boolean setRadio(int networkType, boolean turnOn) { 497 try { 498 return mService.setRadio(networkType, turnOn); 499 } catch (RemoteException e) { 500 return false; 501 } 502 } 503 504 /** 505 * Tells the underlying networking system that the caller wants to 506 * begin using the named feature. The interpretation of {@code feature} 507 * is completely up to each networking implementation. 508 * <p>This method requires the caller to hold the permission 509 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 510 * @param networkType specifies which network the request pertains to 511 * @param feature the name of the feature to be used 512 * @return an integer value representing the outcome of the request. 513 * The interpretation of this value is specific to each networking 514 * implementation+feature combination, except that the value {@code -1} 515 * always indicates failure. 516 */ 517 public int startUsingNetworkFeature(int networkType, String feature) { 518 try { 519 return mService.startUsingNetworkFeature(networkType, feature, 520 new Binder()); 521 } catch (RemoteException e) { 522 return -1; 523 } 524 } 525 526 /** 527 * Tells the underlying networking system that the caller is finished 528 * using the named feature. The interpretation of {@code feature} 529 * is completely up to each networking implementation. 530 * <p>This method requires the caller to hold the permission 531 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 532 * @param networkType specifies which network the request pertains to 533 * @param feature the name of the feature that is no longer needed 534 * @return an integer value representing the outcome of the request. 535 * The interpretation of this value is specific to each networking 536 * implementation+feature combination, except that the value {@code -1} 537 * always indicates failure. 538 */ 539 public int stopUsingNetworkFeature(int networkType, String feature) { 540 try { 541 return mService.stopUsingNetworkFeature(networkType, feature); 542 } catch (RemoteException e) { 543 return -1; 544 } 545 } 546 547 /** 548 * Ensure that a network route exists to deliver traffic to the specified 549 * host via the specified network interface. An attempt to add a route that 550 * already exists is ignored, but treated as successful. 551 * <p>This method requires the caller to hold the permission 552 * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. 553 * @param networkType the type of the network over which traffic to the specified 554 * host is to be routed 555 * @param hostAddress the IP address of the host to which the route is desired 556 * @return {@code true} on success, {@code false} on failure 557 */ 558 public boolean requestRouteToHost(int networkType, int hostAddress) { 559 InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); 560 561 if (inetAddress == null) { 562 return false; 563 } 564 565 return requestRouteToHostAddress(networkType, inetAddress); 566 } 567 568 /** 569 * Ensure that a network route exists to deliver traffic to the specified 570 * host via the specified network interface. An attempt to add a route that 571 * already exists is ignored, but treated as successful. 572 * @param networkType the type of the network over which traffic to the specified 573 * host is to be routed 574 * @param hostAddress the IP address of the host to which the route is desired 575 * @return {@code true} on success, {@code false} on failure 576 * @hide 577 */ 578 public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { 579 byte[] address = hostAddress.getAddress(); 580 try { 581 return mService.requestRouteToHostAddress(networkType, address); 582 } catch (RemoteException e) { 583 return false; 584 } 585 } 586 587 /** 588 * Returns the value of the setting for background data usage. If false, 589 * applications should not use the network if the application is not in the 590 * foreground. Developers should respect this setting, and check the value 591 * of this before performing any background data operations. 592 * <p> 593 * All applications that have background services that use the network 594 * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}. 595 * <p> 596 * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of 597 * background data depends on several combined factors, and this method will 598 * always return {@code true}. Instead, when background data is unavailable, 599 * {@link #getActiveNetworkInfo()} will now appear disconnected. 600 * 601 * @return Whether background data usage is allowed. 602 */ 603 @Deprecated 604 public boolean getBackgroundDataSetting() { 605 // assume that background data is allowed; final authority is 606 // NetworkInfo which may be blocked. 607 return true; 608 } 609 610 /** 611 * Sets the value of the setting for background data usage. 612 * 613 * @param allowBackgroundData Whether an application should use data while 614 * it is in the background. 615 * 616 * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING 617 * @see #getBackgroundDataSetting() 618 * @hide 619 */ 620 @Deprecated 621 public void setBackgroundDataSetting(boolean allowBackgroundData) { 622 // ignored 623 } 624 625 /** 626 * Return quota status for the current active network, or {@code null} if no 627 * network is active. Quota status can change rapidly, so these values 628 * shouldn't be cached. 629 * 630 * @hide 631 */ 632 public NetworkQuotaInfo getActiveNetworkQuotaInfo() { 633 try { 634 return mService.getActiveNetworkQuotaInfo(); 635 } catch (RemoteException e) { 636 return null; 637 } 638 } 639 640 /** 641 * Gets the value of the setting for enabling Mobile data. 642 * 643 * @return Whether mobile data is enabled. 644 * @hide 645 */ 646 public boolean getMobileDataEnabled() { 647 try { 648 return mService.getMobileDataEnabled(); 649 } catch (RemoteException e) { 650 return true; 651 } 652 } 653 654 /** 655 * Sets the persisted value for enabling/disabling Mobile data. 656 * 657 * @param enabled Whether the mobile data connection should be 658 * used or not. 659 * @hide 660 */ 661 public void setMobileDataEnabled(boolean enabled) { 662 try { 663 mService.setMobileDataEnabled(enabled); 664 } catch (RemoteException e) { 665 } 666 } 667 668 /** 669 * {@hide} 670 */ 671 public ConnectivityManager(IConnectivityManager service) { 672 mService = checkNotNull(service, "missing IConnectivityManager"); 673 } 674 675 /** {@hide} */ 676 public static ConnectivityManager from(Context context) { 677 return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 678 } 679 680 /** 681 * {@hide} 682 */ 683 public String[] getTetherableIfaces() { 684 try { 685 return mService.getTetherableIfaces(); 686 } catch (RemoteException e) { 687 return new String[0]; 688 } 689 } 690 691 /** 692 * {@hide} 693 */ 694 public String[] getTetheredIfaces() { 695 try { 696 return mService.getTetheredIfaces(); 697 } catch (RemoteException e) { 698 return new String[0]; 699 } 700 } 701 702 /** 703 * {@hide} 704 */ 705 public String[] getTetheringErroredIfaces() { 706 try { 707 return mService.getTetheringErroredIfaces(); 708 } catch (RemoteException e) { 709 return new String[0]; 710 } 711 } 712 713 /** 714 * @return error A TETHER_ERROR value indicating success or failure type 715 * {@hide} 716 */ 717 public int tether(String iface) { 718 try { 719 return mService.tether(iface); 720 } catch (RemoteException e) { 721 return TETHER_ERROR_SERVICE_UNAVAIL; 722 } 723 } 724 725 /** 726 * @return error A TETHER_ERROR value indicating success or failure type 727 * {@hide} 728 */ 729 public int untether(String iface) { 730 try { 731 return mService.untether(iface); 732 } catch (RemoteException e) { 733 return TETHER_ERROR_SERVICE_UNAVAIL; 734 } 735 } 736 737 /** 738 * {@hide} 739 */ 740 public boolean isTetheringSupported() { 741 try { 742 return mService.isTetheringSupported(); 743 } catch (RemoteException e) { 744 return false; 745 } 746 } 747 748 /** 749 * {@hide} 750 */ 751 public String[] getTetherableUsbRegexs() { 752 try { 753 return mService.getTetherableUsbRegexs(); 754 } catch (RemoteException e) { 755 return new String[0]; 756 } 757 } 758 759 /** 760 * {@hide} 761 */ 762 public String[] getTetherableWifiRegexs() { 763 try { 764 return mService.getTetherableWifiRegexs(); 765 } catch (RemoteException e) { 766 return new String[0]; 767 } 768 } 769 770 /** 771 * {@hide} 772 */ 773 public String[] getTetherableBluetoothRegexs() { 774 try { 775 return mService.getTetherableBluetoothRegexs(); 776 } catch (RemoteException e) { 777 return new String[0]; 778 } 779 } 780 781 /** 782 * {@hide} 783 */ 784 public int setUsbTethering(boolean enable) { 785 try { 786 return mService.setUsbTethering(enable); 787 } catch (RemoteException e) { 788 return TETHER_ERROR_SERVICE_UNAVAIL; 789 } 790 } 791 792 /** {@hide} */ 793 public static final int TETHER_ERROR_NO_ERROR = 0; 794 /** {@hide} */ 795 public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; 796 /** {@hide} */ 797 public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; 798 /** {@hide} */ 799 public static final int TETHER_ERROR_UNSUPPORTED = 3; 800 /** {@hide} */ 801 public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; 802 /** {@hide} */ 803 public static final int TETHER_ERROR_MASTER_ERROR = 5; 804 /** {@hide} */ 805 public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; 806 /** {@hide} */ 807 public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; 808 /** {@hide} */ 809 public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; 810 /** {@hide} */ 811 public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; 812 /** {@hide} */ 813 public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; 814 815 /** 816 * @param iface The name of the interface we're interested in 817 * @return error The error code of the last error tethering or untethering the named 818 * interface 819 * {@hide} 820 */ 821 public int getLastTetherError(String iface) { 822 try { 823 return mService.getLastTetherError(iface); 824 } catch (RemoteException e) { 825 return TETHER_ERROR_SERVICE_UNAVAIL; 826 } 827 } 828 829 /** 830 * Ensure the device stays awake until we connect with the next network 831 * @param forWhome The name of the network going down for logging purposes 832 * @return {@code true} on success, {@code false} on failure 833 * {@hide} 834 */ 835 public boolean requestNetworkTransitionWakelock(String forWhom) { 836 try { 837 mService.requestNetworkTransitionWakelock(forWhom); 838 return true; 839 } catch (RemoteException e) { 840 return false; 841 } 842 } 843 844 /** 845 * @param networkType The type of network you want to report on 846 * @param percentage The quality of the connection 0 is bad, 100 is good 847 * {@hide} 848 */ 849 public void reportInetCondition(int networkType, int percentage) { 850 try { 851 mService.reportInetCondition(networkType, percentage); 852 } catch (RemoteException e) { 853 } 854 } 855 856 /** 857 * @param proxyProperties The definition for the new global http proxy 858 * {@hide} 859 */ 860 public void setGlobalProxy(ProxyProperties p) { 861 try { 862 mService.setGlobalProxy(p); 863 } catch (RemoteException e) { 864 } 865 } 866 867 /** 868 * @return proxyProperties for the current global proxy 869 * {@hide} 870 */ 871 public ProxyProperties getGlobalProxy() { 872 try { 873 return mService.getGlobalProxy(); 874 } catch (RemoteException e) { 875 return null; 876 } 877 } 878 879 /** 880 * @return proxyProperties for the current proxy (global if set, network specific if not) 881 * {@hide} 882 */ 883 public ProxyProperties getProxy() { 884 try { 885 return mService.getProxy(); 886 } catch (RemoteException e) { 887 return null; 888 } 889 } 890 891 /** 892 * @param networkType The network who's dependence has changed 893 * @param met Boolean - true if network use is ok, false if not 894 * {@hide} 895 */ 896 public void setDataDependency(int networkType, boolean met) { 897 try { 898 mService.setDataDependency(networkType, met); 899 } catch (RemoteException e) { 900 } 901 } 902 903 /** 904 * Returns true if the hardware supports the given network type 905 * else it returns false. This doesn't indicate we have coverage 906 * or are authorized onto a network, just whether or not the 907 * hardware supports it. For example a gsm phone without a sim 908 * should still return true for mobile data, but a wifi only tablet 909 * would return false. 910 * @param networkType The nework type we'd like to check 911 * @return true if supported, else false 912 * @hide 913 */ 914 public boolean isNetworkSupported(int networkType) { 915 try { 916 return mService.isNetworkSupported(networkType); 917 } catch (RemoteException e) {} 918 return false; 919 } 920 921 /** 922 * Returns if the currently active data network is metered. A network is 923 * classified as metered when the user is sensitive to heavy data usage on 924 * that connection. You should check this before doing large data transfers, 925 * and warn the user or delay the operation until another network is 926 * available. 927 */ 928 public boolean isActiveNetworkMetered() { 929 try { 930 return mService.isActiveNetworkMetered(); 931 } catch (RemoteException e) { 932 return false; 933 } 934 } 935 936 /** {@hide} */ 937 public boolean updateLockdownVpn() { 938 try { 939 return mService.updateLockdownVpn(); 940 } catch (RemoteException e) { 941 return false; 942 } 943 } 944 945 /** 946 * {@hide} 947 */ 948 public void captivePortalCheckComplete(NetworkInfo info) { 949 try { 950 mService.captivePortalCheckComplete(info); 951 } catch (RemoteException e) { 952 } 953 } 954 955} 956