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     /** {@hide} */
    359     public static final int MAX_RADIO_TYPE   = TYPE_WIFI_P2P;
    360 
    361     /** {@hide} */
    362     public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
    363 
    364     /**
    365      * If you want to set the default network preference,you can directly
    366      * change the networkAttributes array in framework's config.xml.
    367      *
    368      * @deprecated Since we support so many more networks now, the single
    369      *             network default network preference can't really express
    370      *             the hierarchy.  Instead, the default is defined by the
    371      *             networkAttributes in config.xml.  You can determine
    372      *             the current value by calling {@link #getNetworkPreference()}
    373      *             from an App.
    374      */
    375     @Deprecated
    376     public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
    377 
    378     /**
    379      * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
    380      * milliseconds.  This was introduced because IPv6 routes seem to take a
    381      * moment to settle - trying network activity before the routes are adjusted
    382      * can lead to packets using the wrong interface or having the wrong IP address.
    383      * This delay is a bit crude, but in the future hopefully we will have kernel
    384      * notifications letting us know when it's safe to use the new network.
    385      *
    386      * @hide
    387      */
    388     public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
    389 
    390     private final IConnectivityManager mService;
    391 
    392     /**
    393      * Tests if a given integer represents a valid network type.
    394      * @param networkType the type to be tested
    395      * @return a boolean.  {@code true} if the type is valid, else {@code false}
    396      */
    397     public static boolean isNetworkTypeValid(int networkType) {
    398         return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
    399     }
    400 
    401     /**
    402      * Returns a non-localized string representing a given network type.
    403      * ONLY used for debugging output.
    404      * @param type the type needing naming
    405      * @return a String for the given type, or a string version of the type ("87")
    406      * if no name is known.
    407      * {@hide}
    408      */
    409     public static String getNetworkTypeName(int type) {
    410         switch (type) {
    411             case TYPE_MOBILE:
    412                 return "MOBILE";
    413             case TYPE_WIFI:
    414                 return "WIFI";
    415             case TYPE_MOBILE_MMS:
    416                 return "MOBILE_MMS";
    417             case TYPE_MOBILE_SUPL:
    418                 return "MOBILE_SUPL";
    419             case TYPE_MOBILE_DUN:
    420                 return "MOBILE_DUN";
    421             case TYPE_MOBILE_HIPRI:
    422                 return "MOBILE_HIPRI";
    423             case TYPE_WIMAX:
    424                 return "WIMAX";
    425             case TYPE_BLUETOOTH:
    426                 return "BLUETOOTH";
    427             case TYPE_DUMMY:
    428                 return "DUMMY";
    429             case TYPE_ETHERNET:
    430                 return "ETHERNET";
    431             case TYPE_MOBILE_FOTA:
    432                 return "MOBILE_FOTA";
    433             case TYPE_MOBILE_IMS:
    434                 return "MOBILE_IMS";
    435             case TYPE_MOBILE_CBS:
    436                 return "MOBILE_CBS";
    437             case TYPE_WIFI_P2P:
    438                 return "WIFI_P2P";
    439             default:
    440                 return Integer.toString(type);
    441         }
    442     }
    443 
    444     /**
    445      * Checks if a given type uses the cellular data connection.
    446      * This should be replaced in the future by a network property.
    447      * @param networkType the type to check
    448      * @return a boolean - {@code true} if uses cellular network, else {@code false}
    449      * {@hide}
    450      */
    451     public static boolean isNetworkTypeMobile(int networkType) {
    452         switch (networkType) {
    453             case TYPE_MOBILE:
    454             case TYPE_MOBILE_MMS:
    455             case TYPE_MOBILE_SUPL:
    456             case TYPE_MOBILE_DUN:
    457             case TYPE_MOBILE_HIPRI:
    458             case TYPE_MOBILE_FOTA:
    459             case TYPE_MOBILE_IMS:
    460             case TYPE_MOBILE_CBS:
    461                 return true;
    462             default:
    463                 return false;
    464         }
    465     }
    466 
    467     /**
    468      * Specifies the preferred network type.  When the device has more
    469      * than one type available the preferred network type will be used.
    470      * Note that this made sense when we only had 2 network types,
    471      * but with more and more default networks we need an array to list
    472      * their ordering.  This will be deprecated soon.
    473      *
    474      * @param preference the network type to prefer over all others.  It is
    475      *         unspecified what happens to the old preferred network in the
    476      *         overall ordering.
    477      */
    478     public void setNetworkPreference(int preference) {
    479         try {
    480             mService.setNetworkPreference(preference);
    481         } catch (RemoteException e) {
    482         }
    483     }
    484 
    485     /**
    486      * Retrieves the current preferred network type.
    487      * Note that this made sense when we only had 2 network types,
    488      * but with more and more default networks we need an array to list
    489      * their ordering.  This will be deprecated soon.
    490      *
    491      * @return an integer representing the preferred network type
    492      *
    493      * <p>This method requires the caller to hold the permission
    494      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    495      */
    496     public int getNetworkPreference() {
    497         try {
    498             return mService.getNetworkPreference();
    499         } catch (RemoteException e) {
    500             return -1;
    501         }
    502     }
    503 
    504     /**
    505      * Returns details about the currently active default data network. When
    506      * connected, this network is the default route for outgoing connections.
    507      * You should always check {@link NetworkInfo#isConnected()} before initiating
    508      * network traffic. This may return {@code null} when there is no default
    509      * network.
    510      *
    511      * @return a {@link NetworkInfo} object for the current default network
    512      *        or {@code null} if no network default network is currently active
    513      *
    514      * <p>This method requires the call to hold the permission
    515      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    516      */
    517     public NetworkInfo getActiveNetworkInfo() {
    518         try {
    519             return mService.getActiveNetworkInfo();
    520         } catch (RemoteException e) {
    521             return null;
    522         }
    523     }
    524 
    525     /**
    526      * Returns details about the currently active default data network
    527      * for a given uid.  This is for internal use only to avoid spying
    528      * other apps.
    529      *
    530      * @return a {@link NetworkInfo} object for the current default network
    531      *        for the given uid or {@code null} if no default network is
    532      *        available for the specified uid.
    533      *
    534      * <p>This method requires the caller to hold the permission
    535      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}
    536      * {@hide}
    537      */
    538     public NetworkInfo getActiveNetworkInfoForUid(int uid) {
    539         try {
    540             return mService.getActiveNetworkInfoForUid(uid);
    541         } catch (RemoteException e) {
    542             return null;
    543         }
    544     }
    545 
    546     /**
    547      * Returns connection status information about a particular
    548      * network type.
    549      *
    550      * @param networkType integer specifying which networkType in
    551      *        which you're interested.
    552      * @return a {@link NetworkInfo} object for the requested
    553      *        network type or {@code null} if the type is not
    554      *        supported by the device.
    555      *
    556      * <p>This method requires the call to hold the permission
    557      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    558      */
    559     public NetworkInfo getNetworkInfo(int networkType) {
    560         try {
    561             return mService.getNetworkInfo(networkType);
    562         } catch (RemoteException e) {
    563             return null;
    564         }
    565     }
    566 
    567     /**
    568      * Returns connection status information about all network
    569      * types supported by the device.
    570      *
    571      * @return an array of {@link NetworkInfo} objects.  Check each
    572      * {@link NetworkInfo#getType} for which type each applies.
    573      *
    574      * <p>This method requires the call to hold the permission
    575      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    576      */
    577     public NetworkInfo[] getAllNetworkInfo() {
    578         try {
    579             return mService.getAllNetworkInfo();
    580         } catch (RemoteException e) {
    581             return null;
    582         }
    583     }
    584 
    585     /**
    586      * Returns details about the Provisioning or currently active default data network. When
    587      * connected, this network is the default route for outgoing connections.
    588      * You should always check {@link NetworkInfo#isConnected()} before initiating
    589      * network traffic. This may return {@code null} when there is no default
    590      * network.
    591      *
    592      * @return a {@link NetworkInfo} object for the current default network
    593      *        or {@code null} if no network default network is currently active
    594      *
    595      * <p>This method requires the call to hold the permission
    596      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    597      *
    598      * {@hide}
    599      */
    600     public NetworkInfo getProvisioningOrActiveNetworkInfo() {
    601         try {
    602             return mService.getProvisioningOrActiveNetworkInfo();
    603         } catch (RemoteException e) {
    604             return null;
    605         }
    606     }
    607 
    608     /**
    609      * Returns the IP information for the current default network.
    610      *
    611      * @return a {@link LinkProperties} object describing the IP info
    612      *        for the current default network, or {@code null} if there
    613      *        is no current default network.
    614      *
    615      * <p>This method requires the call to hold the permission
    616      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    617      * {@hide}
    618      */
    619     public LinkProperties getActiveLinkProperties() {
    620         try {
    621             return mService.getActiveLinkProperties();
    622         } catch (RemoteException e) {
    623             return null;
    624         }
    625     }
    626 
    627     /**
    628      * Returns the IP information for a given network type.
    629      *
    630      * @param networkType the network type of interest.
    631      * @return a {@link LinkProperties} object describing the IP info
    632      *        for the given networkType, or {@code null} if there is
    633      *        no current default network.
    634      *
    635      * <p>This method requires the call to hold the permission
    636      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    637      * {@hide}
    638      */
    639     public LinkProperties getLinkProperties(int networkType) {
    640         try {
    641             return mService.getLinkProperties(networkType);
    642         } catch (RemoteException e) {
    643             return null;
    644         }
    645     }
    646 
    647     /**
    648      * Tells each network type to set its radio power state as directed.
    649      *
    650      * @param turnOn a boolean, {@code true} to turn the radios on,
    651      *        {@code false} to turn them off.
    652      * @return a boolean, {@code true} indicating success.  All network types
    653      *        will be tried, even if some fail.
    654      *
    655      * <p>This method requires the call to hold the permission
    656      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    657      * {@hide}
    658      */
    659     public boolean setRadios(boolean turnOn) {
    660         try {
    661             return mService.setRadios(turnOn);
    662         } catch (RemoteException e) {
    663             return false;
    664         }
    665     }
    666 
    667     /**
    668      * Tells a given networkType to set its radio power state as directed.
    669      *
    670      * @param networkType the int networkType of interest.
    671      * @param turnOn a boolean, {@code true} to turn the radio on,
    672      *        {@code} false to turn it off.
    673      * @return a boolean, {@code true} indicating success.
    674      *
    675      * <p>This method requires the call to hold the permission
    676      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    677      * {@hide}
    678      */
    679     public boolean setRadio(int networkType, boolean turnOn) {
    680         try {
    681             return mService.setRadio(networkType, turnOn);
    682         } catch (RemoteException e) {
    683             return false;
    684         }
    685     }
    686 
    687     /**
    688      * Tells the underlying networking system that the caller wants to
    689      * begin using the named feature. The interpretation of {@code feature}
    690      * is completely up to each networking implementation.
    691      * <p>This method requires the caller to hold the permission
    692      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    693      * @param networkType specifies which network the request pertains to
    694      * @param feature the name of the feature to be used
    695      * @return an integer value representing the outcome of the request.
    696      * The interpretation of this value is specific to each networking
    697      * implementation+feature combination, except that the value {@code -1}
    698      * always indicates failure.
    699      */
    700     public int startUsingNetworkFeature(int networkType, String feature) {
    701         try {
    702             return mService.startUsingNetworkFeature(networkType, feature,
    703                     new Binder());
    704         } catch (RemoteException e) {
    705             return -1;
    706         }
    707     }
    708 
    709     /**
    710      * Tells the underlying networking system that the caller is finished
    711      * using the named feature. The interpretation of {@code feature}
    712      * is completely up to each networking implementation.
    713      * <p>This method requires the caller to hold the permission
    714      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    715      * @param networkType specifies which network the request pertains to
    716      * @param feature the name of the feature that is no longer needed
    717      * @return an integer value representing the outcome of the request.
    718      * The interpretation of this value is specific to each networking
    719      * implementation+feature combination, except that the value {@code -1}
    720      * always indicates failure.
    721      */
    722     public int stopUsingNetworkFeature(int networkType, String feature) {
    723         try {
    724             return mService.stopUsingNetworkFeature(networkType, feature);
    725         } catch (RemoteException e) {
    726             return -1;
    727         }
    728     }
    729 
    730     /**
    731      * Ensure that a network route exists to deliver traffic to the specified
    732      * host via the specified network interface. An attempt to add a route that
    733      * already exists is ignored, but treated as successful.
    734      * <p>This method requires the caller to hold the permission
    735      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    736      * @param networkType the type of the network over which traffic to the specified
    737      * host is to be routed
    738      * @param hostAddress the IP address of the host to which the route is desired
    739      * @return {@code true} on success, {@code false} on failure
    740      */
    741     public boolean requestRouteToHost(int networkType, int hostAddress) {
    742         InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
    743 
    744         if (inetAddress == null) {
    745             return false;
    746         }
    747 
    748         return requestRouteToHostAddress(networkType, inetAddress);
    749     }
    750 
    751     /**
    752      * Ensure that a network route exists to deliver traffic to the specified
    753      * host via the specified network interface. An attempt to add a route that
    754      * already exists is ignored, but treated as successful.
    755      * @param networkType the type of the network over which traffic to the specified
    756      * host is to be routed
    757      * @param hostAddress the IP address of the host to which the route is desired
    758      * @return {@code true} on success, {@code false} on failure
    759      * @hide
    760      */
    761     public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
    762         byte[] address = hostAddress.getAddress();
    763         try {
    764             return mService.requestRouteToHostAddress(networkType, address);
    765         } catch (RemoteException e) {
    766             return false;
    767         }
    768     }
    769 
    770     /**
    771      * Returns the value of the setting for background data usage. If false,
    772      * applications should not use the network if the application is not in the
    773      * foreground. Developers should respect this setting, and check the value
    774      * of this before performing any background data operations.
    775      * <p>
    776      * All applications that have background services that use the network
    777      * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
    778      * <p>
    779      * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
    780      * background data depends on several combined factors, and this method will
    781      * always return {@code true}. Instead, when background data is unavailable,
    782      * {@link #getActiveNetworkInfo()} will now appear disconnected.
    783      *
    784      * @return Whether background data usage is allowed.
    785      */
    786     @Deprecated
    787     public boolean getBackgroundDataSetting() {
    788         // assume that background data is allowed; final authority is
    789         // NetworkInfo which may be blocked.
    790         return true;
    791     }
    792 
    793     /**
    794      * Sets the value of the setting for background data usage.
    795      *
    796      * @param allowBackgroundData Whether an application should use data while
    797      *            it is in the background.
    798      *
    799      * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
    800      * @see #getBackgroundDataSetting()
    801      * @hide
    802      */
    803     @Deprecated
    804     public void setBackgroundDataSetting(boolean allowBackgroundData) {
    805         // ignored
    806     }
    807 
    808     /**
    809      * Return quota status for the current active network, or {@code null} if no
    810      * network is active. Quota status can change rapidly, so these values
    811      * shouldn't be cached.
    812      *
    813      * <p>This method requires the call to hold the permission
    814      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    815      *
    816      * @hide
    817      */
    818     public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
    819         try {
    820             return mService.getActiveNetworkQuotaInfo();
    821         } catch (RemoteException e) {
    822             return null;
    823         }
    824     }
    825 
    826     /**
    827      * Gets the value of the setting for enabling Mobile data.
    828      *
    829      * @return Whether mobile data is enabled.
    830      *
    831      * <p>This method requires the call to hold the permission
    832      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    833      * @hide
    834      */
    835     public boolean getMobileDataEnabled() {
    836         try {
    837             return mService.getMobileDataEnabled();
    838         } catch (RemoteException e) {
    839             return true;
    840         }
    841     }
    842 
    843     /**
    844      * Sets the persisted value for enabling/disabling Mobile data.
    845      *
    846      * @param enabled Whether the user wants the mobile data connection used
    847      *            or not.
    848      * @hide
    849      */
    850     public void setMobileDataEnabled(boolean enabled) {
    851         try {
    852             mService.setMobileDataEnabled(enabled);
    853         } catch (RemoteException e) {
    854         }
    855     }
    856 
    857     /**
    858      * {@hide}
    859      */
    860     public ConnectivityManager(IConnectivityManager service) {
    861         mService = checkNotNull(service, "missing IConnectivityManager");
    862     }
    863 
    864     /** {@hide} */
    865     public static ConnectivityManager from(Context context) {
    866         return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    867     }
    868 
    869     /**
    870      * Get the set of tetherable, available interfaces.  This list is limited by
    871      * device configuration and current interface existence.
    872      *
    873      * @return an array of 0 or more Strings of tetherable interface names.
    874      *
    875      * <p>This method requires the call to hold the permission
    876      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    877      * {@hide}
    878      */
    879     public String[] getTetherableIfaces() {
    880         try {
    881             return mService.getTetherableIfaces();
    882         } catch (RemoteException e) {
    883             return new String[0];
    884         }
    885     }
    886 
    887     /**
    888      * Get the set of tethered interfaces.
    889      *
    890      * @return an array of 0 or more String of currently tethered interface names.
    891      *
    892      * <p>This method requires the call to hold the permission
    893      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    894      * {@hide}
    895      */
    896     public String[] getTetheredIfaces() {
    897         try {
    898             return mService.getTetheredIfaces();
    899         } catch (RemoteException e) {
    900             return new String[0];
    901         }
    902     }
    903 
    904     /**
    905      * Get the set of interface names which attempted to tether but
    906      * failed.  Re-attempting to tether may cause them to reset to the Tethered
    907      * state.  Alternatively, causing the interface to be destroyed and recreated
    908      * may cause them to reset to the available state.
    909      * {@link ConnectivityManager#getLastTetherError} can be used to get more
    910      * information on the cause of the errors.
    911      *
    912      * @return an array of 0 or more String indicating the interface names
    913      *        which failed to tether.
    914      *
    915      * <p>This method requires the call to hold the permission
    916      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    917      * {@hide}
    918      */
    919     public String[] getTetheringErroredIfaces() {
    920         try {
    921             return mService.getTetheringErroredIfaces();
    922         } catch (RemoteException e) {
    923             return new String[0];
    924         }
    925     }
    926 
    927     /**
    928      * Attempt to tether the named interface.  This will setup a dhcp server
    929      * on the interface, forward and NAT IP packets and forward DNS requests
    930      * to the best active upstream network interface.  Note that if no upstream
    931      * IP network interface is available, dhcp will still run and traffic will be
    932      * allowed between the tethered devices and this device, though upstream net
    933      * access will of course fail until an upstream network interface becomes
    934      * active.
    935      *
    936      * @param iface the interface name to tether.
    937      * @return error a {@code TETHER_ERROR} value indicating success or failure type
    938      *
    939      * <p>This method requires the call to hold the permission
    940      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    941      * {@hide}
    942      */
    943     public int tether(String iface) {
    944         try {
    945             return mService.tether(iface);
    946         } catch (RemoteException e) {
    947             return TETHER_ERROR_SERVICE_UNAVAIL;
    948         }
    949     }
    950 
    951     /**
    952      * Stop tethering the named interface.
    953      *
    954      * @param iface the interface name to untether.
    955      * @return error a {@code TETHER_ERROR} value indicating success or failure type
    956      *
    957      * <p>This method requires the call to hold the permission
    958      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
    959      * {@hide}
    960      */
    961     public int untether(String iface) {
    962         try {
    963             return mService.untether(iface);
    964         } catch (RemoteException e) {
    965             return TETHER_ERROR_SERVICE_UNAVAIL;
    966         }
    967     }
    968 
    969     /**
    970      * Check if the device allows for tethering.  It may be disabled via
    971      * {@code ro.tether.denied} system property, {@link Settings#TETHER_SUPPORTED} or
    972      * due to device configuration.
    973      *
    974      * @return a boolean - {@code true} indicating Tethering is supported.
    975      *
    976      * <p>This method requires the call to hold the permission
    977      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    978      * {@hide}
    979      */
    980     public boolean isTetheringSupported() {
    981         try {
    982             return mService.isTetheringSupported();
    983         } catch (RemoteException e) {
    984             return false;
    985         }
    986     }
    987 
    988     /**
    989      * Get the list of regular expressions that define any tetherable
    990      * USB network interfaces.  If USB tethering is not supported by the
    991      * device, this list should be empty.
    992      *
    993      * @return an array of 0 or more regular expression Strings defining
    994      *        what interfaces are considered tetherable usb interfaces.
    995      *
    996      * <p>This method requires the call to hold the permission
    997      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
    998      * {@hide}
    999      */
   1000     public String[] getTetherableUsbRegexs() {
   1001         try {
   1002             return mService.getTetherableUsbRegexs();
   1003         } catch (RemoteException e) {
   1004             return new String[0];
   1005         }
   1006     }
   1007 
   1008     /**
   1009      * Get the list of regular expressions that define any tetherable
   1010      * Wifi network interfaces.  If Wifi tethering is not supported by the
   1011      * device, this list should be empty.
   1012      *
   1013      * @return an array of 0 or more regular expression Strings defining
   1014      *        what interfaces are considered tetherable wifi interfaces.
   1015      *
   1016      * <p>This method requires the call to hold the permission
   1017      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1018      * {@hide}
   1019      */
   1020     public String[] getTetherableWifiRegexs() {
   1021         try {
   1022             return mService.getTetherableWifiRegexs();
   1023         } catch (RemoteException e) {
   1024             return new String[0];
   1025         }
   1026     }
   1027 
   1028     /**
   1029      * Get the list of regular expressions that define any tetherable
   1030      * Bluetooth network interfaces.  If Bluetooth tethering is not supported by the
   1031      * device, this list should be empty.
   1032      *
   1033      * @return an array of 0 or more regular expression Strings defining
   1034      *        what interfaces are considered tetherable bluetooth interfaces.
   1035      *
   1036      * <p>This method requires the call to hold the permission
   1037      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1038      * {@hide}
   1039      */
   1040     public String[] getTetherableBluetoothRegexs() {
   1041         try {
   1042             return mService.getTetherableBluetoothRegexs();
   1043         } catch (RemoteException e) {
   1044             return new String[0];
   1045         }
   1046     }
   1047 
   1048     /**
   1049      * Attempt to both alter the mode of USB and Tethering of USB.  A
   1050      * utility method to deal with some of the complexity of USB - will
   1051      * attempt to switch to Rndis and subsequently tether the resulting
   1052      * interface on {@code true} or turn off tethering and switch off
   1053      * Rndis on {@code false}.
   1054      *
   1055      * @param enable a boolean - {@code true} to enable tethering
   1056      * @return error a {@code TETHER_ERROR} value indicating success or failure type
   1057      *
   1058      * <p>This method requires the call to hold the permission
   1059      * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
   1060      * {@hide}
   1061      */
   1062     public int setUsbTethering(boolean enable) {
   1063         try {
   1064             return mService.setUsbTethering(enable);
   1065         } catch (RemoteException e) {
   1066             return TETHER_ERROR_SERVICE_UNAVAIL;
   1067         }
   1068     }
   1069 
   1070     /** {@hide} */
   1071     public static final int TETHER_ERROR_NO_ERROR           = 0;
   1072     /** {@hide} */
   1073     public static final int TETHER_ERROR_UNKNOWN_IFACE      = 1;
   1074     /** {@hide} */
   1075     public static final int TETHER_ERROR_SERVICE_UNAVAIL    = 2;
   1076     /** {@hide} */
   1077     public static final int TETHER_ERROR_UNSUPPORTED        = 3;
   1078     /** {@hide} */
   1079     public static final int TETHER_ERROR_UNAVAIL_IFACE      = 4;
   1080     /** {@hide} */
   1081     public static final int TETHER_ERROR_MASTER_ERROR       = 5;
   1082     /** {@hide} */
   1083     public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
   1084     /** {@hide} */
   1085     public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
   1086     /** {@hide} */
   1087     public static final int TETHER_ERROR_ENABLE_NAT_ERROR     = 8;
   1088     /** {@hide} */
   1089     public static final int TETHER_ERROR_DISABLE_NAT_ERROR    = 9;
   1090     /** {@hide} */
   1091     public static final int TETHER_ERROR_IFACE_CFG_ERROR      = 10;
   1092 
   1093     /**
   1094      * Get a more detailed error code after a Tethering or Untethering
   1095      * request asynchronously failed.
   1096      *
   1097      * @param iface The name of the interface of interest
   1098      * @return error The error code of the last error tethering or untethering the named
   1099      *               interface
   1100      *
   1101      * <p>This method requires the call to hold the permission
   1102      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1103      * {@hide}
   1104      */
   1105     public int getLastTetherError(String iface) {
   1106         try {
   1107             return mService.getLastTetherError(iface);
   1108         } catch (RemoteException e) {
   1109             return TETHER_ERROR_SERVICE_UNAVAIL;
   1110         }
   1111     }
   1112 
   1113     /**
   1114      * Try to ensure the device stays awake until we connect with the next network.
   1115      * Actually just holds a wakelock for a number of seconds while we try to connect
   1116      * to any default networks.  This will expire if the timeout passes or if we connect
   1117      * to a default after this is called.  For internal use only.
   1118      *
   1119      * @param forWhom the name of the network going down for logging purposes
   1120      * @return {@code true} on success, {@code false} on failure
   1121      *
   1122      * <p>This method requires the call to hold the permission
   1123      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1124      * {@hide}
   1125      */
   1126     public boolean requestNetworkTransitionWakelock(String forWhom) {
   1127         try {
   1128             mService.requestNetworkTransitionWakelock(forWhom);
   1129             return true;
   1130         } catch (RemoteException e) {
   1131             return false;
   1132         }
   1133     }
   1134 
   1135     /**
   1136      * Report network connectivity status.  This is currently used only
   1137      * to alter status bar UI.
   1138      *
   1139      * @param networkType The type of network you want to report on
   1140      * @param percentage The quality of the connection 0 is bad, 100 is good
   1141      *
   1142      * <p>This method requires the call to hold the permission
   1143      * {@link android.Manifest.permission#STATUS_BAR}.
   1144      * {@hide}
   1145      */
   1146     public void reportInetCondition(int networkType, int percentage) {
   1147         try {
   1148             mService.reportInetCondition(networkType, percentage);
   1149         } catch (RemoteException e) {
   1150         }
   1151     }
   1152 
   1153     /**
   1154      * Set a network-independent global http proxy.  This is not normally what you want
   1155      * for typical HTTP proxies - they are general network dependent.  However if you're
   1156      * doing something unusual like general internal filtering this may be useful.  On
   1157      * a private network where the proxy is not accessible, you may break HTTP using this.
   1158      *
   1159      * @param proxyProperties The a {@link ProxyProperites} object defining the new global
   1160      *        HTTP proxy.  A {@code null} value will clear the global HTTP proxy.
   1161      *
   1162      * <p>This method requires the call to hold the permission
   1163      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1164      * {@hide}
   1165      */
   1166     public void setGlobalProxy(ProxyProperties p) {
   1167         try {
   1168             mService.setGlobalProxy(p);
   1169         } catch (RemoteException e) {
   1170         }
   1171     }
   1172 
   1173     /**
   1174      * Retrieve any network-independent global HTTP proxy.
   1175      *
   1176      * @return {@link ProxyProperties} for the current global HTTP proxy or {@code null}
   1177      *        if no global HTTP proxy is set.
   1178      *
   1179      * <p>This method requires the call to hold the permission
   1180      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1181      * {@hide}
   1182      */
   1183     public ProxyProperties getGlobalProxy() {
   1184         try {
   1185             return mService.getGlobalProxy();
   1186         } catch (RemoteException e) {
   1187             return null;
   1188         }
   1189     }
   1190 
   1191     /**
   1192      * Get the HTTP proxy settings for the current default network.  Note that
   1193      * if a global proxy is set, it will override any per-network setting.
   1194      *
   1195      * @return the {@link ProxyProperties} for the current HTTP proxy, or {@code null} if no
   1196      *        HTTP proxy is active.
   1197      *
   1198      * <p>This method requires the call to hold the permission
   1199      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1200      * {@hide}
   1201      */
   1202     public ProxyProperties getProxy() {
   1203         try {
   1204             return mService.getProxy();
   1205         } catch (RemoteException e) {
   1206             return null;
   1207         }
   1208     }
   1209 
   1210     /**
   1211      * Sets a secondary requirement bit for the given networkType.
   1212      * This requirement bit is generally under the control of the carrier
   1213      * or its agents and is not directly controlled by the user.
   1214      *
   1215      * @param networkType The network who's dependence has changed
   1216      * @param met Boolean - true if network use is OK, false if not
   1217      *
   1218      * <p>This method requires the call to hold the permission
   1219      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1220      * {@hide}
   1221      */
   1222     public void setDataDependency(int networkType, boolean met) {
   1223         try {
   1224             mService.setDataDependency(networkType, met);
   1225         } catch (RemoteException e) {
   1226         }
   1227     }
   1228 
   1229     /**
   1230      * Returns true if the hardware supports the given network type
   1231      * else it returns false.  This doesn't indicate we have coverage
   1232      * or are authorized onto a network, just whether or not the
   1233      * hardware supports it.  For example a GSM phone without a SIM
   1234      * should still return {@code true} for mobile data, but a wifi only
   1235      * tablet would return {@code false}.
   1236      *
   1237      * @param networkType The network type we'd like to check
   1238      * @return {@code true} if supported, else {@code false}
   1239      *
   1240      * <p>This method requires the call to hold the permission
   1241      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1242      * @hide
   1243      */
   1244     public boolean isNetworkSupported(int networkType) {
   1245         try {
   1246             return mService.isNetworkSupported(networkType);
   1247         } catch (RemoteException e) {}
   1248         return false;
   1249     }
   1250 
   1251     /**
   1252      * Returns if the currently active data network is metered. A network is
   1253      * classified as metered when the user is sensitive to heavy data usage on
   1254      * that connection due to monetary costs, data limitations or
   1255      * battery/performance issues. You should check this before doing large
   1256      * data transfers, and warn the user or delay the operation until another
   1257      * network is available.
   1258      *
   1259      * @return {@code true} if large transfers should be avoided, otherwise
   1260      *        {@code false}.
   1261      *
   1262      * <p>This method requires the call to hold the permission
   1263      * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
   1264      */
   1265     public boolean isActiveNetworkMetered() {
   1266         try {
   1267             return mService.isActiveNetworkMetered();
   1268         } catch (RemoteException e) {
   1269             return false;
   1270         }
   1271     }
   1272 
   1273     /**
   1274      * If the LockdownVpn mechanism is enabled, updates the vpn
   1275      * with a reload of its profile.
   1276      *
   1277      * @return a boolean with {@code} indicating success
   1278      *
   1279      * <p>This method can only be called by the system UID
   1280      * {@hide}
   1281      */
   1282     public boolean updateLockdownVpn() {
   1283         try {
   1284             return mService.updateLockdownVpn();
   1285         } catch (RemoteException e) {
   1286             return false;
   1287         }
   1288     }
   1289 
   1290     /**
   1291      * Signal that the captive portal check on the indicated network
   1292      * is complete and we can turn the network on for general use.
   1293      *
   1294      * @param info the {@link NetworkInfo} object for the networkType
   1295      *        in question.
   1296      *
   1297      * <p>This method requires the call to hold the permission
   1298      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1299      * {@hide}
   1300      */
   1301     public void captivePortalCheckComplete(NetworkInfo info) {
   1302         try {
   1303             mService.captivePortalCheckComplete(info);
   1304         } catch (RemoteException e) {
   1305         }
   1306     }
   1307 
   1308     /**
   1309      * Signal that the captive portal check on the indicated network
   1310      * is complete and whether its a captive portal or not.
   1311      *
   1312      * @param info the {@link NetworkInfo} object for the networkType
   1313      *        in question.
   1314      * @param isCaptivePortal true/false.
   1315      *
   1316      * <p>This method requires the call to hold the permission
   1317      * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL}.
   1318      * {@hide}
   1319      */
   1320     public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
   1321         try {
   1322             mService.captivePortalCheckCompleted(info, isCaptivePortal);
   1323         } catch (RemoteException e) {
   1324         }
   1325     }
   1326 
   1327     /**
   1328      * Supply the backend messenger for a network tracker
   1329      *
   1330      * @param type NetworkType to set
   1331      * @param messenger {@link Messenger}
   1332      * {@hide}
   1333      */
   1334     public void supplyMessenger(int networkType, Messenger messenger) {
   1335         try {
   1336             mService.supplyMessenger(networkType, messenger);
   1337         } catch (RemoteException e) {
   1338         }
   1339     }
   1340 
   1341     /**
   1342      * Check mobile provisioning.
   1343      *
   1344      * @param suggestedTimeOutMs, timeout in milliseconds
   1345      *
   1346      * @return time out that will be used, maybe less that suggestedTimeOutMs
   1347      * -1 if an error.
   1348      *
   1349      * {@hide}
   1350      */
   1351     public int checkMobileProvisioning(int suggestedTimeOutMs) {
   1352         int timeOutMs = -1;
   1353         try {
   1354             timeOutMs = mService.checkMobileProvisioning(suggestedTimeOutMs);
   1355         } catch (RemoteException e) {
   1356         }
   1357         return timeOutMs;
   1358     }
   1359 
   1360     /**
   1361      * Get the mobile provisioning url.
   1362      * {@hide}
   1363      */
   1364     public String getMobileProvisioningUrl() {
   1365         try {
   1366             return mService.getMobileProvisioningUrl();
   1367         } catch (RemoteException e) {
   1368         }
   1369         return null;
   1370     }
   1371 
   1372     /**
   1373      * Get the mobile redirected provisioning url.
   1374      * {@hide}
   1375      */
   1376     public String getMobileRedirectedProvisioningUrl() {
   1377         try {
   1378             return mService.getMobileRedirectedProvisioningUrl();
   1379         } catch (RemoteException e) {
   1380         }
   1381         return null;
   1382     }
   1383 
   1384     /**
   1385      * Set sign in error notification to visible or in visible
   1386      *
   1387      * @param visible
   1388      * @param networkType
   1389      *
   1390      * {@hide}
   1391      */
   1392     public void setProvisioningNotificationVisible(boolean visible, int networkType,
   1393             String extraInfo, String url) {
   1394         try {
   1395             mService.setProvisioningNotificationVisible(visible, networkType, extraInfo, url);
   1396         } catch (RemoteException e) {
   1397         }
   1398     }
   1399 }
   1400