Home | History | Annotate | Download | only in net
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.net;
     18 
     19 import static com.android.internal.util.Preconditions.checkNotNull;
     20 
     21 import android.annotation.SdkConstant;
     22 import android.annotation.SdkConstant.SdkConstantType;
     23 import android.content.Context;
     24 import android.os.Binder;
     25 import android.os.Build.VERSION_CODES;
     26 import android.os.Messenger;
     27 import android.os.RemoteException;
     28 import android.os.ResultReceiver;
     29 import android.provider.Settings;
     30 
     31 import java.net.InetAddress;
     32 
     33 /**
     34  * Class that answers queries about the state of network connectivity. It also
     35  * notifies applications when network connectivity changes. Get an instance
     36  * of this class by calling
     37  * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
     38  * <p>
     39  * The primary responsibilities of this class are to:
     40  * <ol>
     41  * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
     42  * <li>Send broadcast intents when network connectivity changes</li>
     43  * <li>Attempt to "fail over" to another network when connectivity to a network
     44  * is lost</li>
     45  * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
     46  * state of the available networks</li>
     47  * </ol>
     48  */
     49 public class ConnectivityManager {
     50     private static final String TAG = "ConnectivityManager";
     51 
     52     /**
     53      * A change in network connectivity has occurred. A connection has either
     54      * been established or lost. The NetworkInfo for the affected network is
     55      * sent as an extra; it should be consulted to see what kind of
     56      * connectivity event occurred.
     57      * <p/>
     58      * If this is a connection that was the result of failing over from a
     59      * disconnected network, then the FAILOVER_CONNECTION boolean extra is
     60      * set to true.
     61      * <p/>
     62      * For a loss of connectivity, if the connectivity manager is attempting
     63      * to connect (or has already connected) to another network, the
     64      * NetworkInfo for the new network is also passed as an extra. This lets
     65      * any receivers of the broadcast know that they should not necessarily
     66      * tell the user that no data traffic will be possible. Instead, the
     67      * receiver should expect another broadcast soon, indicating either that
     68      * the failover attempt succeeded (and so there is still overall data
     69      * connectivity), or that the failover attempt failed, meaning that all
     70      * connectivity has been lost.
     71      * <p/>
     72      * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
     73      * is set to {@code true} if there are no connected networks at all.
     74      */
     75     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     76     public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
     77 
     78     /**
     79      * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
     80      * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}.
     81      *
     82      * @hide
     83      */
     84     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     85     public static final String CONNECTIVITY_ACTION_IMMEDIATE =
     86             "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
     87 
     88     /**
     89      * The lookup key for a {@link NetworkInfo} object. Retrieve with
     90      * {@link android.content.Intent#getParcelableExtra(String)}.
     91      *
     92      * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
     93      *             should always obtain network information through
     94      *             {@link #getActiveNetworkInfo()} or
     95      *             {@link #getAllNetworkInfo()}.
     96      * @see #EXTRA_NETWORK_TYPE
     97      */
     98     @Deprecated
     99     public static final String EXTRA_NETWORK_INFO = "networkInfo";
    100 
    101     /**
    102      * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast.
    103      * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo}
    104      * state based on the calling application.
    105      *
    106      * @see android.content.Intent#getIntExtra(String, int)
    107      */
    108     public static final String EXTRA_NETWORK_TYPE = "networkType";
    109 
    110     /**
    111      * The lookup key for a boolean that indicates whether a connect event
    112      * is for a network to which the connectivity manager was failing over
    113      * following a disconnect on another network.
    114      * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
    115      */
    116     public static final String EXTRA_IS_FAILOVER = "isFailover";
    117     /**
    118      * The lookup key for a {@link NetworkInfo} object. This is supplied when
    119      * there is another network that it may be possible to connect to. Retrieve with
    120      * {@link android.content.Intent#getParcelableExtra(String)}.
    121      */
    122     public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
    123     /**
    124      * The lookup key for a boolean that indicates whether there is a
    125      * complete lack of connectivity, i.e., no network is available.
    126      * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
    127      */
    128     public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
    129     /**
    130      * The lookup key for a string that indicates why an attempt to connect
    131      * to a network failed. The string has no particular structure. It is
    132      * intended to be used in notifications presented to users. Retrieve
    133      * it with {@link android.content.Intent#getStringExtra(String)}.
    134      */
    135     public static final String EXTRA_REASON = "reason";
    136     /**
    137      * The lookup key for a string that provides optionally supplied
    138      * extra information about the network state. The information
    139      * may be passed up from the lower networking layers, and its
    140      * meaning may be specific to a particular network type. Retrieve
    141      * it with {@link android.content.Intent#getStringExtra(String)}.
    142      */
    143     public static final String EXTRA_EXTRA_INFO = "extraInfo";
    144     /**
    145      * The lookup key for an int that provides information about
    146      * our connection to the internet at large.  0 indicates no connection,
    147      * 100 indicates a great connection.  Retrieve it with
    148      * {@link android.content.Intent#getIntExtra(String, int)}.
    149      * {@hide}
    150      */
    151     public static final String EXTRA_INET_CONDITION = "inetCondition";
    152 
    153     /**
    154      * Broadcast action to indicate the change of data activity status
    155      * (idle or active) on a network in a recent period.
    156      * The network becomes active when data transmission is started, or
    157      * idle if there is no data transmission for a period of time.
    158      * {@hide}
    159      */
    160     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    161     public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
    162     /**
    163      * The lookup key for an enum that indicates the network device type on which this data activity
    164      * change happens.
    165      * {@hide}
    166      */
    167     public static final String EXTRA_DEVICE_TYPE = "deviceType";
    168     /**
    169      * The lookup key for a boolean that indicates the device is active or not. {@code true} means
    170      * it is actively sending or receiving data and {@code false} means it is idle.
    171      * {@hide}
    172      */
    173     public static final String EXTRA_IS_ACTIVE = "isActive";
    174 
    175     /**
    176      * Broadcast Action: The setting for background data usage has changed
    177      * values. Use {@link #getBackgroundDataSetting()} to get the current value.
    178      * <p>
    179      * If an application uses the network in the background, it should listen
    180      * for this broadcast and stop using the background data if the value is
    181      * {@code false}.
    182      * <p>
    183      *
    184      * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability
    185      *             of background data depends on several combined factors, and
    186      *             this broadcast is no longer sent. Instead, when background
    187      *             data is unavailable, {@link #getActiveNetworkInfo()} will now
    188      *             appear disconnected. During first boot after a platform
    189      *             upgrade, this broadcast will be sent once if
    190      *             {@link #getBackgroundDataSetting()} was {@code false} before
    191      *             the upgrade.
    192      */
    193     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    194     @Deprecated
    195     public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
    196             "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
    197 
    198     /**
    199      * Broadcast Action: The network connection may not be good
    200      * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
    201      * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
    202      * the network and it's condition.
    203      * @hide
    204      */
    205     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    206     public static final String INET_CONDITION_ACTION =
    207             "android.net.conn.INET_CONDITION_ACTION";
    208 
    209     /**
    210      * Broadcast Action: A tetherable connection has come or gone.
    211      * Uses {@code ConnectivityManager.EXTRA_AVAILABLE_TETHER},
    212      * {@code ConnectivityManager.EXTRA_ACTIVE_TETHER} and
    213      * {@code ConnectivityManager.EXTRA_ERRORED_TETHER} to indicate
    214      * the current state of tethering.  Each include a list of
    215      * interface names in that state (may be empty).
    216      * @hide
    217      */
    218     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    219     public static final String ACTION_TETHER_STATE_CHANGED =
    220             "android.net.conn.TETHER_STATE_CHANGED";
    221 
    222     /**
    223      * @hide
    224      * gives a String[] listing all the interfaces configured for
    225      * tethering and currently available for tethering.
    226      */
    227     public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
    228 
    229     /**
    230      * @hide
    231      * gives a String[] listing all the interfaces currently tethered
    232      * (ie, has dhcp support and packets potentially forwarded/NATed)
    233      */
    234     public static final String EXTRA_ACTIVE_TETHER = "activeArray";
    235 
    236     /**
    237      * @hide
    238      * gives a String[] listing all the interfaces we tried to tether and
    239      * failed.  Use {@link #getLastTetherError} to find the error code
    240      * for any interfaces listed here.
    241      */
    242     public static final String EXTRA_ERRORED_TETHER = "erroredArray";
    243 
    244     /**
    245      * Broadcast Action: The captive portal tracker has finished its test.
    246      * Sent only while running Setup Wizard, in lieu of showing a user
    247      * notification.
    248      * @hide
    249      */
    250     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    251     public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED =
    252             "android.net.conn.CAPTIVE_PORTAL_TEST_COMPLETED";
    253     /**
    254      * The lookup key for a boolean that indicates whether a captive portal was detected.
    255      * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
    256      * @hide
    257      */
    258     public static final String EXTRA_IS_CAPTIVE_PORTAL = "captivePortal";
    259 
    260     /**
    261      * The absence of a connection type.
    262      * @hide
    263      */
    264     public static final int TYPE_NONE        = -1;
    265 
    266     /**
    267      * The Mobile data connection.  When active, all data traffic
    268      * will use this network type's interface by default
    269      * (it has a default route)
    270      */
    271     public static final int TYPE_MOBILE      = 0;
    272     /**
    273      * The WIFI data connection.  When active, all data traffic
    274      * will use this network type's interface by default
    275      * (it has a default route).
    276      */
    277     public static final int TYPE_WIFI        = 1;
    278     /**
    279      * An MMS-specific Mobile data connection.  This network type may use the
    280      * same network interface as {@link #TYPE_MOBILE} or it may use a different
    281      * one.  This is used by applications needing to talk to the carrier's
    282      * Multimedia Messaging Service servers.
    283      */
    284     public static final int TYPE_MOBILE_MMS  = 2;
    285     /**
    286      * A SUPL-specific Mobile data connection.  This network type may use the
    287      * same network interface as {@link #TYPE_MOBILE} or it may use a different
    288      * one.  This is used by applications needing to talk to the carrier's
    289      * Secure User Plane Location servers for help locating the device.
    290      */
    291     public static final int TYPE_MOBILE_SUPL = 3;
    292     /**
    293      * A DUN-specific Mobile data connection.  This network type may use the
    294      * same network interface as {@link #TYPE_MOBILE} or it may use a different
    295      * one.  This is sometimes by the system when setting up an upstream connection
    296      * for tethering so that the carrier is aware of DUN traffic.
    297      */
    298     public static final int TYPE_MOBILE_DUN  = 4;
    299     /**
    300      * A High Priority Mobile data connection.  This network type uses the
    301      * same network interface as {@link #TYPE_MOBILE} but the routing setup
    302      * is different.  Only requesting processes will have access to the
    303      * Mobile DNS servers and only IP's explicitly requested via {@link #requestRouteToHost}
    304      * will route over this interface if no default route exists.
    305      */
    306     public static final int TYPE_MOBILE_HIPRI = 5;
    307     /**
    308      * The WiMAX data connection.  When active, all data traffic
    309      * will use this network type's interface by default
    310      * (it has a default route).
    311      */
    312     public static final int TYPE_WIMAX       = 6;
    313 
    314     /**
    315      * The Bluetooth data connection.  When active, all data traffic
    316      * will use this network type's interface by default
    317      * (it has a default route).
    318      */
    319     public static final int TYPE_BLUETOOTH   = 7;
    320 
    321     /**
    322      * Dummy data connection.  This should not be used on shipping devices.
    323      */
    324     public static final int TYPE_DUMMY       = 8;
    325 
    326     /**
    327      * The Ethernet data connection.  When active, all data traffic
    328      * will use this network type's interface by default
    329      * (it has a default route).
    330      */
    331     public static final int TYPE_ETHERNET    = 9;
    332 
    333     /**
    334      * Over the air Administration.
    335      * {@hide}
    336      */
    337     public static final int TYPE_MOBILE_FOTA = 10;
    338 
    339     /**
    340      * IP Multimedia Subsystem.
    341      * {@hide}
    342      */
    343     public static final int TYPE_MOBILE_IMS  = 11;
    344 
    345     /**
    346      * Carrier Branded Services.
    347      * {@hide}
    348      */
    349     public static final int TYPE_MOBILE_CBS  = 12;
    350 
    351     /**
    352      * A Wi-Fi p2p connection. Only requesting processes will have access to
    353      * the peers connected.
    354      * {@hide}
    355      */
    356     public static final int TYPE_WIFI_P2P    = 13;
    357 
    358     /**
    359      * The network to use for initially attaching to the network
    360      * {@hide}
    361      */
    362     public static final int TYPE_MOBILE_IA = 14;
    363 
    364     /** {@hide} */
    365     public static final int MAX_RADIO_TYPE   = TYPE_MOBILE_IA;
    366 
    367     /** {@hide} */
    368     public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_IA;
    369 
    370     /**
    371      * If you want to set the default network preference,you can directly
    372      * change the networkAttributes array in framework's config.xml.
    373      *
    374      * @deprecated Since we support so many more networks now, the single
    375      *             network default network preference can't really express
    376      *             the hierarchy.  Instead, the default is defined by the
    377      *             networkAttributes in config.xml.  You can determine
    378      *             the current value by calling {@link #getNetworkPreference()}
    379      *             from an App.
    380      */
    381     @Deprecated
    382     public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
    383 
    384     /**
    385      * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
    386      * milliseconds.  This was introduced because IPv6 routes seem to take a
    387      * moment to settle - trying network activity before the routes are adjusted
    388      * can lead to packets using the wrong interface or having the wrong IP address.
    389      * This delay is a bit crude, but in the future hopefully we will have kernel
    390      * notifications letting us know when it's safe to use the new network.
    391      *
    392      * @hide
    393      */
    394     public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
    395 
    396     private final IConnectivityManager mService;
    397 
    398     private final String mPackageName;
    399 
    400     /**
    401      * Tests if a given integer represents a valid network type.
    402      * @param networkType the type to be tested
    403      * @return a boolean.  {@code true} if the type is valid, else {@code false}
    404      */
    405     public static boolean isNetworkTypeValid(int networkType) {
    406         return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
    407     }
    408 
    409     /**
    410      * Returns a non-localized string representing a given network type.
    411      * ONLY used for debugging output.
    412      * @param type the type needing naming
    413      * @return a String for the given type, or a string version of the type ("87")
    414      * if no name is known.
    415      * {@hide}
    416      */
    417     public static String getNetworkTypeName(int type) {
    418         switch (type) {
    419             case TYPE_MOBILE:
    420                 return "MOBILE";
    421             case TYPE_WIFI:
    422                 return "WIFI";
    423             case TYPE_MOBILE_MMS:
    424                 return "MOBILE_MMS";
    425             case TYPE_MOBILE_SUPL:
    426                 return "MOBILE_SUPL";
    427             case TYPE_MOBILE_DUN:
    428                 return "MOBILE_DUN";
    429             case TYPE_MOBILE_HIPRI:
    430                 return "MOBILE_HIPRI";
    431             case TYPE_WIMAX:
    432                 return "WIMAX";
    433             case TYPE_BLUETOOTH:
    434                 return "BLUETOOTH";
    435             case TYPE_DUMMY:
    436                 return "DUMMY";
    437             case TYPE_ETHERNET:
    438                 return "ETHERNET";
    439             case TYPE_MOBILE_FOTA:
    440                 return "MOBILE_FOTA";
    441             case TYPE_MOBILE_IMS:
    442                 return "MOBILE_IMS";
    443             case TYPE_MOBILE_CBS:
    444                 return "MOBILE_CBS";
    445             case TYPE_WIFI_P2P:
    446                 return "WIFI_P2P";
    447             case TYPE_MOBILE_IA:
    448                 return "MOBILE_IA";
    449             default:
    450                 return Integer.toString(type);
    451         }
    452     }
    453 
    454     /**
    455      * Checks if a given type uses the cellular data connection.
    456      * This should be replaced in the future by a network property.
    457      * @param networkType the type to check
    458      * @return a boolean - {@code true} if uses cellular network, else {@code false}
    459      * {@hide}
    460      */
    461     public static boolean isNetworkTypeMobile(int networkType) {
    462         switch (networkType) {
    463             case TYPE_MOBILE:
    464             case TYPE_MOBILE_MMS:
    465             case TYPE_MOBILE_SUPL:
    466             case TYPE_MOBILE_DUN:
    467             case TYPE_MOBILE_HIPRI:
    468             case TYPE_MOBILE_FOTA:
    469             case TYPE_MOBILE_IMS:
    470             case TYPE_MOBILE_CBS:
    471             case TYPE_MOBILE_IA:
    472                 return true;
    473             default:
    474                 return false;
    475         }
    476     }
    477 
    478     /**
    479      * Checks if the given network type is backed by a Wi-Fi radio.
    480      *
    481      * @hide
    482      */
    483     public static boolean isNetworkTypeWifi(int networkType) {
    484         switch (networkType) {
    485             case TYPE_WIFI:
    486             case TYPE_WIFI_P2P:
    487                 return true;
    488             default:
    489                 return false;
    490         }
    491     }
    492 
    493     /**
    494      * Checks if the given network type should be exempt from VPN routing rules
    495      *
    496      * @hide
    497      */
    498     public static boolean isNetworkTypeExempt(int networkType) {
    499         switch (networkType) {
    500             case TYPE_MOBILE_MMS:
    501             case TYPE_MOBILE_SUPL:
    502             case TYPE_MOBILE_HIPRI:
    503             case TYPE_MOBILE_IA:
    504                 return true;
    505             default:
    506                 return false;
    507         }
    508     }
    509 
    510     /**
    511      * Specifies the preferred network type.  When the device has more
    512      * than one type available the preferred network type will be used.
    513      * Note that this made sense when we only had 2 network types,
    514      * but with more and more default networks we need an array to list
    515      * their ordering.  This will be deprecated soon.
    516      *
    517      * @param preference the network type to prefer over all others.  It is
    518      *         unspecified what happens to the old preferred network in the
    519      *         overall ordering.
    520      */
    521     public void setNetworkPreference(int preference) {
    522         try {
    523             mService.setNetworkPreference(preference);
    524         } catch (RemoteException e) {
    525         }
    526     }
    527 
    528     /**
    529      * Retrieves the current preferred network type.
    530      * Note that this made sense when we only had 2 network types,
    531      * but with more and more default networks we need an array to list
    532      * their ordering.  This will be deprecated soon.
    533      *
    534      * @return an integer representing the preferred network type
    535      *
    536      * <p>This method requires the caller to hold the permission
    537      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    538      */
    539     public int getNetworkPreference() {
    540         try {
    541             return mService.getNetworkPreference();
    542         } catch (RemoteException e) {
    543             return -1;
    544         }
    545     }
    546 
    547     /**
    548      * Returns details about the currently active default data network. When
    549      * connected, this network is the default route for outgoing connections.
    550      * You should always check {@link NetworkInfo#isConnected()} before initiating
    551      * network traffic. This may return {@code null} when there is no default
    552      * network.
    553      *
    554      * @return a {@link NetworkInfo} object for the current default network
    555      *        or {@code null} if no network default network is currently active
    556      *
    557      * <p>This method requires the call to hold the permission
    558      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    559      */
    560     public NetworkInfo getActiveNetworkInfo() {
    561         try {
    562             return mService.getActiveNetworkInfo();
    563         } catch (RemoteException e) {
    564             return null;
    565         }
    566     }
    567 
    568     /**
    569      * Returns details about the currently active default data network
    570      * for a given uid.  This is for internal use only to avoid spying
    571      * other apps.
    572      *
    573      * @return a {@link NetworkInfo} object for the current default network
    574      *        for the given uid or {@code null} if no default network is
    575      *        available for the specified uid.
    576      *
    577      * <p>This method requires the caller to hold the permission
    578      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
    579      * {@hide}
    580      */
    581     public NetworkInfo getActiveNetworkInfoForUid(int uid) {
    582         try {
    583             return mService.getActiveNetworkInfoForUid(uid);
    584         } catch (RemoteException e) {
    585             return null;
    586         }
    587     }
    588 
    589     /**
    590      * Returns connection status information about a particular
    591      * network type.
    592      *
    593      * @param networkType integer specifying which networkType in
    594      *        which you're interested.
    595      * @return a {@link NetworkInfo} object for the requested
    596      *        network type or {@code null} if the type is not
    597      *        supported by the device.
    598      *
    599      * <p>This method requires the call to hold the permission
    600      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    601      */
    602     public NetworkInfo getNetworkInfo(int networkType) {
    603         try {
    604             return mService.getNetworkInfo(networkType);
    605         } catch (RemoteException e) {
    606             return null;
    607         }
    608     }
    609 
    610     /**
    611      * Returns connection status information about all network
    612      * types supported by the device.
    613      *
    614      * @return an array of {@link NetworkInfo} objects.  Check each
    615      * {@link NetworkInfo#getType} for which type each applies.
    616      *
    617      * <p>This method requires the call to hold the permission
    618      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    619      */
    620     public NetworkInfo[] getAllNetworkInfo() {
    621         try {
    622             return mService.getAllNetworkInfo();
    623         } catch (RemoteException e) {
    624             return null;
    625         }
    626     }
    627 
    628     /**
    629      * Returns details about the Provisioning or currently active default data network. When
    630      * connected, this network is the default route for outgoing connections.
    631      * You should always check {@link NetworkInfo#isConnected()} before initiating
    632      * network traffic. This may return {@code null} when there is no default
    633      * network.
    634      *
    635      * @return a {@link NetworkInfo} object for the current default network
    636      *        or {@code null} if no network default network is currently active
    637      *
    638      * <p>This method requires the call to hold the permission
    639      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    640      *
    641      * {@hide}
    642      */
    643     public NetworkInfo getProvisioningOrActiveNetworkInfo() {
    644         try {
    645             return mService.getProvisioningOrActiveNetworkInfo();
    646         } catch (RemoteException e) {
    647             return null;
    648         }
    649     }
    650 
    651     /**
    652      * Returns the IP information for the current default network.
    653      *
    654      * @return a {@link LinkProperties} object describing the IP info
    655      *        for the current default network, or {@code null} if there
    656      *        is no current default network.
    657      *
    658      * <p>This method requires the call to hold the permission
    659      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    660      * {@hide}
    661      */
    662     public LinkProperties getActiveLinkProperties() {
    663         try {
    664             return mService.getActiveLinkProperties();
    665         } catch (RemoteException e) {
    666             return null;
    667         }
    668     }
    669 
    670     /**
    671      * Returns the IP information for a given network type.
    672      *
    673      * @param networkType the network type of interest.
    674      * @return a {@link LinkProperties} object describing the IP info
    675      *        for the given networkType, or {@code null} if there is
    676      *        no current default network.
    677      *
    678      * <p>This method requires the call to hold the permission
    679      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    680      * {@hide}
    681      */
    682     public LinkProperties getLinkProperties(int networkType) {
    683         try {
    684             return mService.getLinkProperties(networkType);
    685         } catch (RemoteException e) {
    686             return null;
    687         }
    688     }
    689 
    690     /**
    691      * Tells each network type to set its radio power state as directed.
    692      *
    693      * @param turnOn a boolean, {@code true} to turn the radios on,
    694      *        {@code false} to turn them off.
    695      * @return a boolean, {@code true} indicating success.  All network types
    696      *        will be tried, even if some fail.
    697      *
    698      * <p>This method requires the call to hold the permission
    699      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    700      * {@hide}
    701      */
    702     public boolean setRadios(boolean turnOn) {
    703         try {
    704             return mService.setRadios(turnOn);
    705         } catch (RemoteException e) {
    706             return false;
    707         }
    708     }
    709 
    710     /**
    711      * Tells a given networkType to set its radio power state as directed.
    712      *
    713      * @param networkType the int networkType of interest.
    714      * @param turnOn a boolean, {@code true} to turn the radio on,
    715      *        {@code} false to turn it off.
    716      * @return a boolean, {@code true} indicating success.
    717      *
    718      * <p>This method requires the call to hold the permission
    719      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    720      * {@hide}
    721      */
    722     public boolean setRadio(int networkType, boolean turnOn) {
    723         try {
    724             return mService.setRadio(networkType, turnOn);
    725         } catch (RemoteException e) {
    726             return false;
    727         }
    728     }
    729 
    730     /**
    731      * Tells the underlying networking system that the caller wants to
    732      * begin using the named feature. The interpretation of {@code feature}
    733      * is completely up to each networking implementation.
    734      * <p>This method requires the caller to hold the permission
    735      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    736      * @param networkType specifies which network the request pertains to
    737      * @param feature the name of the feature to be used
    738      * @return an integer value representing the outcome of the request.
    739      * The interpretation of this value is specific to each networking
    740      * implementation+feature combination, except that the value {@code -1}
    741      * always indicates failure.
    742      */
    743     public int startUsingNetworkFeature(int networkType, String feature) {
    744         try {
    745             return mService.startUsingNetworkFeature(networkType, feature,
    746                     new Binder());
    747         } catch (RemoteException e) {
    748             return -1;
    749         }
    750     }
    751 
    752     /**
    753      * Tells the underlying networking system that the caller is finished
    754      * using the named feature. The interpretation of {@code feature}
    755      * is completely up to each networking implementation.
    756      * <p>This method requires the caller to hold the permission
    757      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    758      * @param networkType specifies which network the request pertains to
    759      * @param feature the name of the feature that is no longer needed
    760      * @return an integer value representing the outcome of the request.
    761      * The interpretation of this value is specific to each networking
    762      * implementation+feature combination, except that the value {@code -1}
    763      * always indicates failure.
    764      */
    765     public int stopUsingNetworkFeature(int networkType, String feature) {
    766         try {
    767             return mService.stopUsingNetworkFeature(networkType, feature);
    768         } catch (RemoteException e) {
    769             return -1;
    770         }
    771     }
    772 
    773     /**
    774      * Ensure that a network route exists to deliver traffic to the specified
    775      * host via the specified network interface. An attempt to add a route that
    776      * already exists is ignored, but treated as successful.
    777      * <p>This method requires the caller to hold the permission
    778      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    779      * @param networkType the type of the network over which traffic to the specified
    780      * host is to be routed
    781      * @param hostAddress the IP address of the host to which the route is desired
    782      * @return {@code true} on success, {@code false} on failure
    783      */
    784     public boolean requestRouteToHost(int networkType, int hostAddress) {
    785         InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
    786 
    787         if (inetAddress == null) {
    788             return false;
    789         }
    790 
    791         return requestRouteToHostAddress(networkType, inetAddress);
    792     }
    793 
    794     /**
    795      * Ensure that a network route exists to deliver traffic to the specified
    796      * host via the specified network interface. An attempt to add a route that
    797      * already exists is ignored, but treated as successful.
    798      * @param networkType the type of the network over which traffic to the specified
    799      * host is to be routed
    800      * @param hostAddress the IP address of the host to which the route is desired
    801      * @return {@code true} on success, {@code false} on failure
    802      * @hide
    803      */
    804     public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
    805         byte[] address = hostAddress.getAddress();
    806         try {
    807             return mService.requestRouteToHostAddress(networkType, address, mPackageName);
    808         } catch (RemoteException e) {
    809             return false;
    810         }
    811     }
    812 
    813     /**
    814      * Returns the value of the setting for background data usage. If false,
    815      * applications should not use the network if the application is not in the
    816      * foreground. Developers should respect this setting, and check the value
    817      * of this before performing any background data operations.
    818      * <p>
    819      * All applications that have background services that use the network
    820      * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
    821      * <p>
    822      * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
    823      * background data depends on several combined factors, and this method will
    824      * always return {@code true}. Instead, when background data is unavailable,
    825      * {@link #getActiveNetworkInfo()} will now appear disconnected.
    826      *
    827      * @return Whether background data usage is allowed.
    828      */
    829     @Deprecated
    830     public boolean getBackgroundDataSetting() {
    831         // assume that background data is allowed; final authority is
    832         // NetworkInfo which may be blocked.
    833         return true;
    834     }
    835 
    836     /**
    837      * Sets the value of the setting for background data usage.
    838      *
    839      * @param allowBackgroundData Whether an application should use data while
    840      *            it is in the background.
    841      *
    842      * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
    843      * @see #getBackgroundDataSetting()
    844      * @hide
    845      */
    846     @Deprecated
    847     public void setBackgroundDataSetting(boolean allowBackgroundData) {
    848         // ignored
    849     }
    850 
    851     /**
    852      * Return quota status for the current active network, or {@code null} if no
    853      * network is active. Quota status can change rapidly, so these values
    854      * shouldn't be cached.
    855      *
    856      * <p>This method requires the call to hold the permission
    857      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    858      *
    859      * @hide
    860      */
    861     public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
    862         try {
    863             return mService.getActiveNetworkQuotaInfo();
    864         } catch (RemoteException e) {
    865             return null;
    866         }
    867     }
    868 
    869     /**
    870      * Gets the value of the setting for enabling Mobile data.
    871      *
    872      * @return Whether mobile data is enabled.
    873      *
    874      * <p>This method requires the call to hold the permission
    875      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    876      * @hide
    877      */
    878     public boolean getMobileDataEnabled() {
    879         try {
    880             return mService.getMobileDataEnabled();
    881         } catch (RemoteException e) {
    882             return true;
    883         }
    884     }
    885 
    886     /**
    887      * Sets the persisted value for enabling/disabling Mobile data.
    888      *
    889      * @param enabled Whether the user wants the mobile data connection used
    890      *            or not.
    891      * @hide
    892      */
    893     public void setMobileDataEnabled(boolean enabled) {
    894         try {
    895             mService.setMobileDataEnabled(enabled);
    896         } catch (RemoteException e) {
    897         }
    898     }
    899 
    900     /**
    901      * {@hide}
    902      */
    903     public ConnectivityManager(IConnectivityManager service, String packageName) {
    904         mService = checkNotNull(service, "missing IConnectivityManager");
    905         mPackageName = checkNotNull(packageName, "missing package name");
    906     }
    907 
    908     /** {@hide} */
    909     public static ConnectivityManager from(Context context) {
    910         return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    911     }
    912 
    913     /**
    914      * Get the set of tetherable, available interfaces.  This list is limited by
    915      * device configuration and current interface existence.
    916      *
    917      * @return an array of 0 or more Strings of tetherable interface names.
    918      *
    919      * <p>This method requires the call to hold the permission
    920      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    921      * {@hide}
    922      */
    923     public String[] getTetherableIfaces() {
    924         try {
    925             return mService.getTetherableIfaces();
    926         } catch (RemoteException e) {
    927             return new String[0];
    928         }
    929     }
    930 
    931     /**
    932      * Get the set of tethered interfaces.
    933      *
    934      * @return an array of 0 or more String of currently tethered interface names.
    935      *
    936      * <p>This method requires the call to hold the permission
    937      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    938      * {@hide}
    939      */
    940     public String[] getTetheredIfaces() {
    941         try {
    942             return mService.getTetheredIfaces();
    943         } catch (RemoteException e) {
    944             return new String[0];
    945         }
    946     }
    947 
    948     /**
    949      * Get the set of interface names which attempted to tether but
    950      * failed.  Re-attempting to tether may cause them to reset to the Tethered
    951      * state.  Alternatively, causing the interface to be destroyed and recreated
    952      * may cause them to reset to the available state.
    953      * {@link ConnectivityManager#getLastTetherError} can be used to get more
    954      * information on the cause of the errors.
    955      *
    956      * @return an array of 0 or more String indicating the interface names
    957      *        which failed to tether.
    958      *
    959      * <p>This method requires the call to hold the permission
    960      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    961      * {@hide}
    962      */
    963     public String[] getTetheringErroredIfaces() {
    964         try {
    965             return mService.getTetheringErroredIfaces();
    966         } catch (RemoteException e) {
    967             return new String[0];
    968         }
    969     }
    970 
    971     /**
    972      * Attempt to tether the named interface.  This will setup a dhcp server
    973      * on the interface, forward and NAT IP packets and forward DNS requests
    974      * to the best active upstream network interface.  Note that if no upstream
    975      * IP network interface is available, dhcp will still run and traffic will be
    976      * allowed between the tethered devices and this device, though upstream net
    977      * access will of course fail until an upstream network interface becomes
    978      * active.
    979      *
    980      * @param iface the interface name to tether.
    981      * @return error a {@code TETHER_ERROR} value indicating success or failure type
    982      *
    983      * <p>This method requires the call to hold the permission
    984      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    985      * {@hide}
    986      */
    987     public int tether(String iface) {
    988         try {
    989             return mService.tether(iface);
    990         } catch (RemoteException e) {
    991             return TETHER_ERROR_SERVICE_UNAVAIL;
    992         }
    993     }
    994 
    995     /**
    996      * Stop tethering the named interface.
    997      *
    998      * @param iface the interface name to untether.
    999      * @return error a {@code TETHER_ERROR} value indicating success or failure type
   1000      *
   1001      * <p>This method requires the call to hold the permission
   1002      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
   1003      * {@hide}
   1004      */
   1005     public int untether(String iface) {
   1006         try {
   1007             return mService.untether(iface);
   1008         } catch (RemoteException e) {
   1009             return TETHER_ERROR_SERVICE_UNAVAIL;
   1010         }
   1011     }
   1012 
   1013     /**
   1014      * Check if the device allows for tethering.  It may be disabled via
   1015      * {@code ro.tether.denied} system property, {@link Settings#TETHER_SUPPORTED} or
   1016      * due to device configuration.
   1017      *
   1018      * @return a boolean - {@code true} indicating Tethering is supported.
   1019      *
   1020      * <p>This method requires the call to hold the permission
   1021      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1022      * {@hide}
   1023      */
   1024     public boolean isTetheringSupported() {
   1025         try {
   1026             return mService.isTetheringSupported();
   1027         } catch (RemoteException e) {
   1028             return false;
   1029         }
   1030     }
   1031 
   1032     /**
   1033      * Get the list of regular expressions that define any tetherable
   1034      * USB network interfaces.  If USB tethering is not supported by the
   1035      * device, this list should be empty.
   1036      *
   1037      * @return an array of 0 or more regular expression Strings defining
   1038      *        what interfaces are considered tetherable usb interfaces.
   1039      *
   1040      * <p>This method requires the call to hold the permission
   1041      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1042      * {@hide}
   1043      */
   1044     public String[] getTetherableUsbRegexs() {
   1045         try {
   1046             return mService.getTetherableUsbRegexs();
   1047         } catch (RemoteException e) {
   1048             return new String[0];
   1049         }
   1050     }
   1051 
   1052     /**
   1053      * Get the list of regular expressions that define any tetherable
   1054      * Wifi network interfaces.  If Wifi tethering is not supported by the
   1055      * device, this list should be empty.
   1056      *
   1057      * @return an array of 0 or more regular expression Strings defining
   1058      *        what interfaces are considered tetherable wifi interfaces.
   1059      *
   1060      * <p>This method requires the call to hold the permission
   1061      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1062      * {@hide}
   1063      */
   1064     public String[] getTetherableWifiRegexs() {
   1065         try {
   1066             return mService.getTetherableWifiRegexs();
   1067         } catch (RemoteException e) {
   1068             return new String[0];
   1069         }
   1070     }
   1071 
   1072     /**
   1073      * Get the list of regular expressions that define any tetherable
   1074      * Bluetooth network interfaces.  If Bluetooth tethering is not supported by the
   1075      * device, this list should be empty.
   1076      *
   1077      * @return an array of 0 or more regular expression Strings defining
   1078      *        what interfaces are considered tetherable bluetooth interfaces.
   1079      *
   1080      * <p>This method requires the call to hold the permission
   1081      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1082      * {@hide}
   1083      */
   1084     public String[] getTetherableBluetoothRegexs() {
   1085         try {
   1086             return mService.getTetherableBluetoothRegexs();
   1087         } catch (RemoteException e) {
   1088             return new String[0];
   1089         }
   1090     }
   1091 
   1092     /**
   1093      * Attempt to both alter the mode of USB and Tethering of USB.  A
   1094      * utility method to deal with some of the complexity of USB - will
   1095      * attempt to switch to Rndis and subsequently tether the resulting
   1096      * interface on {@code true} or turn off tethering and switch off
   1097      * Rndis on {@code false}.
   1098      *
   1099      * @param enable a boolean - {@code true} to enable tethering
   1100      * @return error a {@code TETHER_ERROR} value indicating success or failure type
   1101      *
   1102      * <p>This method requires the call to hold the permission
   1103      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
   1104      * {@hide}
   1105      */
   1106     public int setUsbTethering(boolean enable) {
   1107         try {
   1108             return mService.setUsbTethering(enable);
   1109         } catch (RemoteException e) {
   1110             return TETHER_ERROR_SERVICE_UNAVAIL;
   1111         }
   1112     }
   1113 
   1114     /** {@hide} */
   1115     public static final int TETHER_ERROR_NO_ERROR           = 0;
   1116     /** {@hide} */
   1117     public static final int TETHER_ERROR_UNKNOWN_IFACE      = 1;
   1118     /** {@hide} */
   1119     public static final int TETHER_ERROR_SERVICE_UNAVAIL    = 2;
   1120     /** {@hide} */
   1121     public static final int TETHER_ERROR_UNSUPPORTED        = 3;
   1122     /** {@hide} */
   1123     public static final int TETHER_ERROR_UNAVAIL_IFACE      = 4;
   1124     /** {@hide} */
   1125     public static final int TETHER_ERROR_MASTER_ERROR       = 5;
   1126     /** {@hide} */
   1127     public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
   1128     /** {@hide} */
   1129     public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
   1130     /** {@hide} */
   1131     public static final int TETHER_ERROR_ENABLE_NAT_ERROR     = 8;
   1132     /** {@hide} */
   1133     public static final int TETHER_ERROR_DISABLE_NAT_ERROR    = 9;
   1134     /** {@hide} */
   1135     public static final int TETHER_ERROR_IFACE_CFG_ERROR      = 10;
   1136 
   1137     /**
   1138      * Get a more detailed error code after a Tethering or Untethering
   1139      * request asynchronously failed.
   1140      *
   1141      * @param iface The name of the interface of interest
   1142      * @return error The error code of the last error tethering or untethering the named
   1143      *               interface
   1144      *
   1145      * <p>This method requires the call to hold the permission
   1146      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1147      * {@hide}
   1148      */
   1149     public int getLastTetherError(String iface) {
   1150         try {
   1151             return mService.getLastTetherError(iface);
   1152         } catch (RemoteException e) {
   1153             return TETHER_ERROR_SERVICE_UNAVAIL;
   1154         }
   1155     }
   1156 
   1157     /**
   1158      * Try to ensure the device stays awake until we connect with the next network.
   1159      * Actually just holds a wakelock for a number of seconds while we try to connect
   1160      * to any default networks.  This will expire if the timeout passes or if we connect
   1161      * to a default after this is called.  For internal use only.
   1162      *
   1163      * @param forWhom the name of the network going down for logging purposes
   1164      * @return {@code true} on success, {@code false} on failure
   1165      *
   1166      * <p>This method requires the call to hold the permission
   1167      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1168      * {@hide}
   1169      */
   1170     public boolean requestNetworkTransitionWakelock(String forWhom) {
   1171         try {
   1172             mService.requestNetworkTransitionWakelock(forWhom);
   1173             return true;
   1174         } catch (RemoteException e) {
   1175             return false;
   1176         }
   1177     }
   1178 
   1179     /**
   1180      * Report network connectivity status.  This is currently used only
   1181      * to alter status bar UI.
   1182      *
   1183      * @param networkType The type of network you want to report on
   1184      * @param percentage The quality of the connection 0 is bad, 100 is good
   1185      *
   1186      * <p>This method requires the call to hold the permission
   1187      * {@link android.Manifest.permission#STATUS_BAR}.
   1188      * {@hide}
   1189      */
   1190     public void reportInetCondition(int networkType, int percentage) {
   1191         try {
   1192             mService.reportInetCondition(networkType, percentage);
   1193         } catch (RemoteException e) {
   1194         }
   1195     }
   1196 
   1197     /**
   1198      * Set a network-independent global http proxy.  This is not normally what you want
   1199      * for typical HTTP proxies - they are general network dependent.  However if you're
   1200      * doing something unusual like general internal filtering this may be useful.  On
   1201      * a private network where the proxy is not accessible, you may break HTTP using this.
   1202      *
   1203      * @param proxyProperties The a {@link ProxyProperites} object defining the new global
   1204      *        HTTP proxy.  A {@code null} value will clear the global HTTP proxy.
   1205      *
   1206      * <p>This method requires the call to hold the permission
   1207      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1208      * {@hide}
   1209      */
   1210     public void setGlobalProxy(ProxyProperties p) {
   1211         try {
   1212             mService.setGlobalProxy(p);
   1213         } catch (RemoteException e) {
   1214         }
   1215     }
   1216 
   1217     /**
   1218      * Retrieve any network-independent global HTTP proxy.
   1219      *
   1220      * @return {@link ProxyProperties} for the current global HTTP proxy or {@code null}
   1221      *        if no global HTTP proxy is set.
   1222      *
   1223      * <p>This method requires the call to hold the permission
   1224      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1225      * {@hide}
   1226      */
   1227     public ProxyProperties getGlobalProxy() {
   1228         try {
   1229             return mService.getGlobalProxy();
   1230         } catch (RemoteException e) {
   1231             return null;
   1232         }
   1233     }
   1234 
   1235     /**
   1236      * Get the HTTP proxy settings for the current default network.  Note that
   1237      * if a global proxy is set, it will override any per-network setting.
   1238      *
   1239      * @return the {@link ProxyProperties} for the current HTTP proxy, or {@code null} if no
   1240      *        HTTP proxy is active.
   1241      *
   1242      * <p>This method requires the call to hold the permission
   1243      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1244      * {@hide}
   1245      */
   1246     public ProxyProperties getProxy() {
   1247         try {
   1248             return mService.getProxy();
   1249         } catch (RemoteException e) {
   1250             return null;
   1251         }
   1252     }
   1253 
   1254     /**
   1255      * Sets a secondary requirement bit for the given networkType.
   1256      * This requirement bit is generally under the control of the carrier
   1257      * or its agents and is not directly controlled by the user.
   1258      *
   1259      * @param networkType The network who's dependence has changed
   1260      * @param met Boolean - true if network use is OK, false if not
   1261      *
   1262      * <p>This method requires the call to hold the permission
   1263      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1264      * {@hide}
   1265      */
   1266     public void setDataDependency(int networkType, boolean met) {
   1267         try {
   1268             mService.setDataDependency(networkType, met);
   1269         } catch (RemoteException e) {
   1270         }
   1271     }
   1272 
   1273     /**
   1274      * Returns true if the hardware supports the given network type
   1275      * else it returns false.  This doesn't indicate we have coverage
   1276      * or are authorized onto a network, just whether or not the
   1277      * hardware supports it.  For example a GSM phone without a SIM
   1278      * should still return {@code true} for mobile data, but a wifi only
   1279      * tablet would return {@code false}.
   1280      *
   1281      * @param networkType The network type we'd like to check
   1282      * @return {@code true} if supported, else {@code false}
   1283      *
   1284      * <p>This method requires the call to hold the permission
   1285      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1286      * @hide
   1287      */
   1288     public boolean isNetworkSupported(int networkType) {
   1289         try {
   1290             return mService.isNetworkSupported(networkType);
   1291         } catch (RemoteException e) {}
   1292         return false;
   1293     }
   1294 
   1295     /**
   1296      * Returns if the currently active data network is metered. A network is
   1297      * classified as metered when the user is sensitive to heavy data usage on
   1298      * that connection due to monetary costs, data limitations or
   1299      * battery/performance issues. You should check this before doing large
   1300      * data transfers, and warn the user or delay the operation until another
   1301      * network is available.
   1302      *
   1303      * @return {@code true} if large transfers should be avoided, otherwise
   1304      *        {@code false}.
   1305      *
   1306      * <p>This method requires the call to hold the permission
   1307      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1308      */
   1309     public boolean isActiveNetworkMetered() {
   1310         try {
   1311             return mService.isActiveNetworkMetered();
   1312         } catch (RemoteException e) {
   1313             return false;
   1314         }
   1315     }
   1316 
   1317     /**
   1318      * If the LockdownVpn mechanism is enabled, updates the vpn
   1319      * with a reload of its profile.
   1320      *
   1321      * @return a boolean with {@code} indicating success
   1322      *
   1323      * <p>This method can only be called by the system UID
   1324      * {@hide}
   1325      */
   1326     public boolean updateLockdownVpn() {
   1327         try {
   1328             return mService.updateLockdownVpn();
   1329         } catch (RemoteException e) {
   1330             return false;
   1331         }
   1332     }
   1333 
   1334     /**
   1335      * Signal that the captive portal check on the indicated network
   1336      * is complete and we can turn the network on for general use.
   1337      *
   1338      * @param info the {@link NetworkInfo} object for the networkType
   1339      *        in question.
   1340      *
   1341      * <p>This method requires the call to hold the permission
   1342      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1343      * {@hide}
   1344      */
   1345     public void captivePortalCheckComplete(NetworkInfo info) {
   1346         try {
   1347             mService.captivePortalCheckComplete(info);
   1348         } catch (RemoteException e) {
   1349         }
   1350     }
   1351 
   1352     /**
   1353      * Signal that the captive portal check on the indicated network
   1354      * is complete and whether its a captive portal or not.
   1355      *
   1356      * @param info the {@link NetworkInfo} object for the networkType
   1357      *        in question.
   1358      * @param isCaptivePortal true/false.
   1359      *
   1360      * <p>This method requires the call to hold the permission
   1361      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1362      * {@hide}
   1363      */
   1364     public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
   1365         try {
   1366             mService.captivePortalCheckCompleted(info, isCaptivePortal);
   1367         } catch (RemoteException e) {
   1368         }
   1369     }
   1370 
   1371     /**
   1372      * Supply the backend messenger for a network tracker
   1373      *
   1374      * @param type NetworkType to set
   1375      * @param messenger {@link Messenger}
   1376      * {@hide}
   1377      */
   1378     public void supplyMessenger(int networkType, Messenger messenger) {
   1379         try {
   1380             mService.supplyMessenger(networkType, messenger);
   1381         } catch (RemoteException e) {
   1382         }
   1383     }
   1384 
   1385     /**
   1386      * Check mobile provisioning.
   1387      *
   1388      * @param suggestedTimeOutMs, timeout in milliseconds
   1389      *
   1390      * @return time out that will be used, maybe less that suggestedTimeOutMs
   1391      * -1 if an error.
   1392      *
   1393      * {@hide}
   1394      */
   1395     public int checkMobileProvisioning(int suggestedTimeOutMs) {
   1396         int timeOutMs = -1;
   1397         try {
   1398             timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
   1399         } catch (RemoteException e) {
   1400         }
   1401         return timeOutMs;
   1402     }
   1403 
   1404     /**
   1405      * Get the mobile provisioning url.
   1406      * {@hide}
   1407      */
   1408     public String getMobileProvisioningUrl() {
   1409         try {
   1410             return mService.getMobileProvisioningUrl();
   1411         } catch (RemoteException e) {
   1412         }
   1413         return null;
   1414     }
   1415 
   1416     /**
   1417      * Get the mobile redirected provisioning url.
   1418      * {@hide}
   1419      */
   1420     public String getMobileRedirectedProvisioningUrl() {
   1421         try {
   1422             return mService.getMobileRedirectedProvisioningUrl();
   1423         } catch (RemoteException e) {
   1424         }
   1425         return null;
   1426     }
   1427 
   1428     /**
   1429      * get the information about a specific network link
   1430      * @hide
   1431      */
   1432     public LinkQualityInfo getLinkQualityInfo(int networkType) {
   1433         try {
   1434             LinkQualityInfo li = mService.getLinkQualityInfo(networkType);
   1435             return li;
   1436         } catch (RemoteException e) {
   1437             return null;
   1438         }
   1439     }
   1440 
   1441     /**
   1442      * get the information of currently active network link
   1443      * @hide
   1444      */
   1445     public LinkQualityInfo getActiveLinkQualityInfo() {
   1446         try {
   1447             LinkQualityInfo li = mService.getActiveLinkQualityInfo();
   1448             return li;
   1449         } catch (RemoteException e) {
   1450             return null;
   1451         }
   1452     }
   1453 
   1454     /**
   1455      * get the information of all network links
   1456      * @hide
   1457      */
   1458     public LinkQualityInfo[] getAllLinkQualityInfo() {
   1459         try {
   1460             LinkQualityInfo[] li = mService.getAllLinkQualityInfo();
   1461             return li;
   1462         } catch (RemoteException e) {
   1463             return null;
   1464         }
   1465     }
   1466 
   1467     /**
   1468      * Set sign in error notification to visible or in visible
   1469      *
   1470      * @param visible
   1471      * @param networkType
   1472      *
   1473      * {@hide}
   1474      */
   1475     public void setProvisioningNotificationVisible(boolean visible, int networkType,
   1476             String extraInfo, String url) {
   1477         try {
   1478             mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url);
   1479         } catch (RemoteException e) {
   1480         }
   1481     }
   1482 
   1483     /**
   1484      * Set the value for enabling/disabling airplane mode
   1485      *
   1486      * @param enable whether to enable airplane mode or not
   1487      *
   1488      * <p>This method requires the call to hold the permission
   1489      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1490      * @hide
   1491      */
   1492     public void setAirplaneMode(boolean enable) {
   1493         try {
   1494             mService.setAirplaneMode(enable);
   1495         } catch (RemoteException e) {
   1496         }
   1497     }
   1498 }
   1499