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