ConnectivityManager.java revision 625239a05401bbf18b04d9874cea3f82da7c29a1
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.net;
18
19import static com.android.internal.util.Preconditions.checkNotNull;
20
21import android.annotation.SdkConstant;
22import android.annotation.SdkConstant.SdkConstantType;
23import android.content.Context;
24import android.os.Binder;
25import android.os.Build.VERSION_CODES;
26import android.os.RemoteException;
27import android.provider.Settings;
28
29import java.net.InetAddress;
30
31/**
32 * Class that answers queries about the state of network connectivity. It also
33 * notifies applications when network connectivity changes. Get an instance
34 * of this class by calling
35 * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.CONNECTIVITY_SERVICE)}.
36 * <p>
37 * The primary responsibilities of this class are to:
38 * <ol>
39 * <li>Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)</li>
40 * <li>Send broadcast intents when network connectivity changes</li>
41 * <li>Attempt to "fail over" to another network when connectivity to a network
42 * is lost</li>
43 * <li>Provide an API that allows applications to query the coarse-grained or fine-grained
44 * state of the available networks</li>
45 * </ol>
46 */
47public class ConnectivityManager {
48    private static final String TAG = "ConnectivityManager";
49
50    /**
51     * A change in network connectivity has occurred. A connection has either
52     * been established or lost. The NetworkInfo for the affected network is
53     * sent as an extra; it should be consulted to see what kind of
54     * connectivity event occurred.
55     * <p/>
56     * If this is a connection that was the result of failing over from a
57     * disconnected network, then the FAILOVER_CONNECTION boolean extra is
58     * set to true.
59     * <p/>
60     * For a loss of connectivity, if the connectivity manager is attempting
61     * to connect (or has already connected) to another network, the
62     * NetworkInfo for the new network is also passed as an extra. This lets
63     * any receivers of the broadcast know that they should not necessarily
64     * tell the user that no data traffic will be possible. Instead, the
65     * reciever should expect another broadcast soon, indicating either that
66     * the failover attempt succeeded (and so there is still overall data
67     * connectivity), or that the failover attempt failed, meaning that all
68     * connectivity has been lost.
69     * <p/>
70     * For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY
71     * is set to {@code true} if there are no connected networks at all.
72     */
73    public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
74
75    /**
76     * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
77     * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}.
78     *
79     * @hide
80     */
81    public static final String CONNECTIVITY_ACTION_IMMEDIATE =
82            "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
83
84    /**
85     * The lookup key for a {@link NetworkInfo} object. Retrieve with
86     * {@link android.content.Intent#getParcelableExtra(String)}.
87     *
88     * @deprecated Since {@link NetworkInfo} can vary based on UID, applications
89     *             should always obtain network information through
90     *             {@link #getActiveNetworkInfo()} or
91     *             {@link #getAllNetworkInfo()}.
92     * @see #EXTRA_NETWORK_TYPE
93     */
94    @Deprecated
95    public static final String EXTRA_NETWORK_INFO = "networkInfo";
96
97    /**
98     * Network type which triggered a {@link #CONNECTIVITY_ACTION} broadcast.
99     * Can be used with {@link #getNetworkInfo(int)} to get {@link NetworkInfo}
100     * state based on the calling application.
101     *
102     * @see android.content.Intent#getIntExtra(String, int)
103     */
104    public static final String EXTRA_NETWORK_TYPE = "networkType";
105
106    /**
107     * The lookup key for a boolean that indicates whether a connect event
108     * is for a network to which the connectivity manager was failing over
109     * following a disconnect on another network.
110     * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
111     */
112    public static final String EXTRA_IS_FAILOVER = "isFailover";
113    /**
114     * The lookup key for a {@link NetworkInfo} object. This is supplied when
115     * there is another network that it may be possible to connect to. Retrieve with
116     * {@link android.content.Intent#getParcelableExtra(String)}.
117     */
118    public static final String EXTRA_OTHER_NETWORK_INFO = "otherNetwork";
119    /**
120     * The lookup key for a boolean that indicates whether there is a
121     * complete lack of connectivity, i.e., no network is available.
122     * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
123     */
124    public static final String EXTRA_NO_CONNECTIVITY = "noConnectivity";
125    /**
126     * The lookup key for a string that indicates why an attempt to connect
127     * to a network failed. The string has no particular structure. It is
128     * intended to be used in notifications presented to users. Retrieve
129     * it with {@link android.content.Intent#getStringExtra(String)}.
130     */
131    public static final String EXTRA_REASON = "reason";
132    /**
133     * The lookup key for a string that provides optionally supplied
134     * extra information about the network state. The information
135     * may be passed up from the lower networking layers, and its
136     * meaning may be specific to a particular network type. Retrieve
137     * it with {@link android.content.Intent#getStringExtra(String)}.
138     */
139    public static final String EXTRA_EXTRA_INFO = "extraInfo";
140    /**
141     * The lookup key for an int that provides information about
142     * our connection to the internet at large.  0 indicates no connection,
143     * 100 indicates a great connection.  Retrieve it with
144     * {@link android.content.Intent#getIntExtra(String, int)}.
145     * {@hide}
146     */
147    public static final String EXTRA_INET_CONDITION = "inetCondition";
148
149    /**
150     * Broadcast action to indicate the change of data activity status
151     * (idle or active) on a network in a recent period.
152     * The network becomes active when data transimission is started, or
153     * idle if there is no data transimition for a period of time.
154     * {@hide}
155     */
156    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
157    public static final String ACTION_DATA_ACTIVITY_CHANGE = "android.net.conn.DATA_ACTIVITY_CHANGE";
158    /**
159     * The lookup key for an enum that indicates the network device type on which this data activity
160     * change happens.
161     * {@hide}
162     */
163    public static final String EXTRA_DEVICE_TYPE = "deviceType";
164    /**
165     * The lookup key for a boolean that indicates the device is active or not. {@code true} means
166     * it is actively sending or receiving data and {@code false} means it is idle.
167     * {@hide}
168     */
169    public static final String EXTRA_IS_ACTIVE = "isActive";
170
171    /**
172     * Broadcast Action: The setting for background data usage has changed
173     * values. Use {@link #getBackgroundDataSetting()} to get the current value.
174     * <p>
175     * If an application uses the network in the background, it should listen
176     * for this broadcast and stop using the background data if the value is
177     * {@code false}.
178     * <p>
179     *
180     * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability
181     *             of background data depends on several combined factors, and
182     *             this broadcast is no longer sent. Instead, when background
183     *             data is unavailable, {@link #getActiveNetworkInfo()} will now
184     *             appear disconnected. During first boot after a platform
185     *             upgrade, this broadcast will be sent once if
186     *             {@link #getBackgroundDataSetting()} was {@code false} before
187     *             the upgrade.
188     */
189    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
190    @Deprecated
191    public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
192            "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";
193
194    /**
195     * Broadcast Action: The network connection may not be good
196     * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
197     * {@code ConnectivityManager.EXTRA_NETWORK_INFO} to specify
198     * the network and it's condition.
199     * @hide
200     */
201    public static final String INET_CONDITION_ACTION =
202            "android.net.conn.INET_CONDITION_ACTION";
203
204    /**
205     * Broadcast Action: A tetherable connection has come or gone
206     * TODO - finish the doc
207     * @hide
208     */
209    public static final String ACTION_TETHER_STATE_CHANGED =
210            "android.net.conn.TETHER_STATE_CHANGED";
211
212    /**
213     * @hide
214     * gives a String[]
215     */
216    public static final String EXTRA_AVAILABLE_TETHER = "availableArray";
217
218    /**
219     * @hide
220     * gives a String[]
221     */
222    public static final String EXTRA_ACTIVE_TETHER = "activeArray";
223
224    /**
225     * @hide
226     * gives a String[]
227     */
228    public static final String EXTRA_ERRORED_TETHER = "erroredArray";
229
230    /**
231     * The absence of APN..
232     * @hide
233     */
234    public static final int TYPE_NONE        = -1;
235
236    /**
237     * The Default Mobile data connection.  When active, all data traffic
238     * will use this connection by default.
239     */
240    public static final int TYPE_MOBILE      = 0;
241    /**
242     * The Default WIFI data connection.  When active, all data traffic
243     * will use this connection by default.
244     */
245    public static final int TYPE_WIFI        = 1;
246    /**
247     * An MMS-specific Mobile data connection.  This connection may be the
248     * same as {@link #TYPE_MOBILE} but it may be different.  This is used
249     * by applications needing to talk to the carrier's Multimedia Messaging
250     * Service servers.  It may coexist with default data connections.
251     */
252    public static final int TYPE_MOBILE_MMS  = 2;
253    /**
254     * A SUPL-specific Mobile data connection.  This connection may be the
255     * same as {@link #TYPE_MOBILE} but it may be different.  This is used
256     * by applications needing to talk to the carrier's Secure User Plane
257     * Location servers for help locating the device.  It may coexist with
258     * default data connections.
259     */
260    public static final int TYPE_MOBILE_SUPL = 3;
261    /**
262     * A DUN-specific Mobile data connection.  This connection may be the
263     * same as {@link #TYPE_MOBILE} but it may be different.  This is used
264     * by applicaitons performing a Dial Up Networking bridge so that
265     * the carrier is aware of DUN traffic.  It may coexist with default data
266     * connections.
267     */
268    public static final int TYPE_MOBILE_DUN  = 4;
269    /**
270     * A High Priority Mobile data connection.  This connection is typically
271     * the same as {@link #TYPE_MOBILE} but the routing setup is different.
272     * Only requesting processes will have access to the Mobile DNS servers
273     * and only IP's explicitly requested via {@link #requestRouteToHost}
274     * will route over this interface if a default route exists.
275     */
276    public static final int TYPE_MOBILE_HIPRI = 5;
277    /**
278     * The Default WiMAX data connection.  When active, all data traffic
279     * will use this connection by default.
280     */
281    public static final int TYPE_WIMAX       = 6;
282
283    /**
284     * The Default Bluetooth data connection. When active, all data traffic
285     * will use this connection by default.
286     */
287    public static final int TYPE_BLUETOOTH   = 7;
288
289    /**
290     * Dummy data connection.  This should not be used on shipping devices.
291     */
292    public static final int TYPE_DUMMY       = 8;
293
294    /**
295     * The Default Ethernet data connection.  When active, all data traffic
296     * will use this connection by default.
297     */
298    public static final int TYPE_ETHERNET    = 9;
299
300    /**
301     * Over the air Adminstration.
302     * {@hide}
303     */
304    public static final int TYPE_MOBILE_FOTA = 10;
305
306    /**
307     * IP Multimedia Subsystem
308     * {@hide}
309     */
310    public static final int TYPE_MOBILE_IMS  = 11;
311
312    /**
313     * Carrier Branded Services
314     * {@hide}
315     */
316    public static final int TYPE_MOBILE_CBS  = 12;
317
318    /**
319     * A Wi-Fi p2p connection. Only requesting processes will have access to
320     * the peers connected.
321     * {@hide}
322     */
323    public static final int TYPE_WIFI_P2P    = 13;
324
325    /** {@hide} */
326    public static final int MAX_RADIO_TYPE   = TYPE_WIFI_P2P;
327
328    /** {@hide} */
329    public static final int MAX_NETWORK_TYPE = TYPE_WIFI_P2P;
330
331    public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;
332
333    /**
334     * Default value for {@link Settings.Global#CONNECTIVITY_CHANGE_DELAY} in
335     * milliseconds.
336     *
337     * @hide
338     */
339    public static final int CONNECTIVITY_CHANGE_DELAY_DEFAULT = 3000;
340
341    private final IConnectivityManager mService;
342
343    public static boolean isNetworkTypeValid(int networkType) {
344        return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
345    }
346
347    /** {@hide} */
348    public static String getNetworkTypeName(int type) {
349        switch (type) {
350            case TYPE_MOBILE:
351                return "MOBILE";
352            case TYPE_WIFI:
353                return "WIFI";
354            case TYPE_MOBILE_MMS:
355                return "MOBILE_MMS";
356            case TYPE_MOBILE_SUPL:
357                return "MOBILE_SUPL";
358            case TYPE_MOBILE_DUN:
359                return "MOBILE_DUN";
360            case TYPE_MOBILE_HIPRI:
361                return "MOBILE_HIPRI";
362            case TYPE_WIMAX:
363                return "WIMAX";
364            case TYPE_BLUETOOTH:
365                return "BLUETOOTH";
366            case TYPE_DUMMY:
367                return "DUMMY";
368            case TYPE_ETHERNET:
369                return "ETHERNET";
370            case TYPE_MOBILE_FOTA:
371                return "MOBILE_FOTA";
372            case TYPE_MOBILE_IMS:
373                return "MOBILE_IMS";
374            case TYPE_MOBILE_CBS:
375                return "MOBILE_CBS";
376            case TYPE_WIFI_P2P:
377                return "WIFI_P2P";
378            default:
379                return Integer.toString(type);
380        }
381    }
382
383    /** {@hide} */
384    public static boolean isNetworkTypeMobile(int networkType) {
385        switch (networkType) {
386            case TYPE_MOBILE:
387            case TYPE_MOBILE_MMS:
388            case TYPE_MOBILE_SUPL:
389            case TYPE_MOBILE_DUN:
390            case TYPE_MOBILE_HIPRI:
391            case TYPE_MOBILE_FOTA:
392            case TYPE_MOBILE_IMS:
393            case TYPE_MOBILE_CBS:
394                return true;
395            default:
396                return false;
397        }
398    }
399
400    public void setNetworkPreference(int preference) {
401        try {
402            mService.setNetworkPreference(preference);
403        } catch (RemoteException e) {
404        }
405    }
406
407    public int getNetworkPreference() {
408        try {
409            return mService.getNetworkPreference();
410        } catch (RemoteException e) {
411            return -1;
412        }
413    }
414
415    /**
416     * Returns details about the currently active data network. When connected,
417     * this network is the default route for outgoing connections. You should
418     * always check {@link NetworkInfo#isConnected()} before initiating network
419     * traffic. This may return {@code null} when no networks are available.
420     * <p>This method requires the caller to hold the permission
421     * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
422     */
423    public NetworkInfo getActiveNetworkInfo() {
424        try {
425            return mService.getActiveNetworkInfo();
426        } catch (RemoteException e) {
427            return null;
428        }
429    }
430
431    /** {@hide} */
432    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
433        try {
434            return mService.getActiveNetworkInfoForUid(uid);
435        } catch (RemoteException e) {
436            return null;
437        }
438    }
439
440    public NetworkInfo getNetworkInfo(int networkType) {
441        try {
442            return mService.getNetworkInfo(networkType);
443        } catch (RemoteException e) {
444            return null;
445        }
446    }
447
448    public NetworkInfo[] getAllNetworkInfo() {
449        try {
450            return mService.getAllNetworkInfo();
451        } catch (RemoteException e) {
452            return null;
453        }
454    }
455
456    /** {@hide} */
457    public LinkProperties getActiveLinkProperties() {
458        try {
459            return mService.getActiveLinkProperties();
460        } catch (RemoteException e) {
461            return null;
462        }
463    }
464
465    /** {@hide} */
466    public LinkProperties getLinkProperties(int networkType) {
467        try {
468            return mService.getLinkProperties(networkType);
469        } catch (RemoteException e) {
470            return null;
471        }
472    }
473
474    /** {@hide} */
475    public boolean setRadios(boolean turnOn) {
476        try {
477            return mService.setRadios(turnOn);
478        } catch (RemoteException e) {
479            return false;
480        }
481    }
482
483    /** {@hide} */
484    public boolean setRadio(int networkType, boolean turnOn) {
485        try {
486            return mService.setRadio(networkType, turnOn);
487        } catch (RemoteException e) {
488            return false;
489        }
490    }
491
492    /**
493     * Tells the underlying networking system that the caller wants to
494     * begin using the named feature. The interpretation of {@code feature}
495     * is completely up to each networking implementation.
496     * <p>This method requires the caller to hold the permission
497     * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
498     * @param networkType specifies which network the request pertains to
499     * @param feature the name of the feature to be used
500     * @return an integer value representing the outcome of the request.
501     * The interpretation of this value is specific to each networking
502     * implementation+feature combination, except that the value {@code -1}
503     * always indicates failure.
504     */
505    public int startUsingNetworkFeature(int networkType, String feature) {
506        try {
507            return mService.startUsingNetworkFeature(networkType, feature,
508                    new Binder());
509        } catch (RemoteException e) {
510            return -1;
511        }
512    }
513
514    /**
515     * Tells the underlying networking system that the caller is finished
516     * using the named feature. The interpretation of {@code feature}
517     * is completely up to each networking implementation.
518     * <p>This method requires the caller to hold the permission
519     * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
520     * @param networkType specifies which network the request pertains to
521     * @param feature the name of the feature that is no longer needed
522     * @return an integer value representing the outcome of the request.
523     * The interpretation of this value is specific to each networking
524     * implementation+feature combination, except that the value {@code -1}
525     * always indicates failure.
526     */
527    public int stopUsingNetworkFeature(int networkType, String feature) {
528        try {
529            return mService.stopUsingNetworkFeature(networkType, feature);
530        } catch (RemoteException e) {
531            return -1;
532        }
533    }
534
535    /**
536     * Ensure that a network route exists to deliver traffic to the specified
537     * host via the specified network interface. An attempt to add a route that
538     * already exists is ignored, but treated as successful.
539     * <p>This method requires the caller to hold the permission
540     * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}.
541     * @param networkType the type of the network over which traffic to the specified
542     * host is to be routed
543     * @param hostAddress the IP address of the host to which the route is desired
544     * @return {@code true} on success, {@code false} on failure
545     */
546    public boolean requestRouteToHost(int networkType, int hostAddress) {
547        InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
548
549        if (inetAddress == null) {
550            return false;
551        }
552
553        return requestRouteToHostAddress(networkType, inetAddress);
554    }
555
556    /**
557     * Ensure that a network route exists to deliver traffic to the specified
558     * host via the specified network interface. An attempt to add a route that
559     * already exists is ignored, but treated as successful.
560     * @param networkType the type of the network over which traffic to the specified
561     * host is to be routed
562     * @param hostAddress the IP address of the host to which the route is desired
563     * @return {@code true} on success, {@code false} on failure
564     * @hide
565     */
566    public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
567        byte[] address = hostAddress.getAddress();
568        try {
569            return mService.requestRouteToHostAddress(networkType, address);
570        } catch (RemoteException e) {
571            return false;
572        }
573    }
574
575    /**
576     * Returns the value of the setting for background data usage. If false,
577     * applications should not use the network if the application is not in the
578     * foreground. Developers should respect this setting, and check the value
579     * of this before performing any background data operations.
580     * <p>
581     * All applications that have background services that use the network
582     * should listen to {@link #ACTION_BACKGROUND_DATA_SETTING_CHANGED}.
583     * <p>
584     * @deprecated As of {@link VERSION_CODES#ICE_CREAM_SANDWICH}, availability of
585     * background data depends on several combined factors, and this method will
586     * always return {@code true}. Instead, when background data is unavailable,
587     * {@link #getActiveNetworkInfo()} will now appear disconnected.
588     *
589     * @return Whether background data usage is allowed.
590     */
591    @Deprecated
592    public boolean getBackgroundDataSetting() {
593        // assume that background data is allowed; final authority is
594        // NetworkInfo which may be blocked.
595        return true;
596    }
597
598    /**
599     * Sets the value of the setting for background data usage.
600     *
601     * @param allowBackgroundData Whether an application should use data while
602     *            it is in the background.
603     *
604     * @attr ref android.Manifest.permission#CHANGE_BACKGROUND_DATA_SETTING
605     * @see #getBackgroundDataSetting()
606     * @hide
607     */
608    @Deprecated
609    public void setBackgroundDataSetting(boolean allowBackgroundData) {
610        // ignored
611    }
612
613    /**
614     * Return quota status for the current active network, or {@code null} if no
615     * network is active. Quota status can change rapidly, so these values
616     * shouldn't be cached.
617     *
618     * @hide
619     */
620    public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
621        try {
622            return mService.getActiveNetworkQuotaInfo();
623        } catch (RemoteException e) {
624            return null;
625        }
626    }
627
628    /**
629     * Gets the value of the setting for enabling Mobile data.
630     *
631     * @return Whether mobile data is enabled.
632     * @hide
633     */
634    public boolean getMobileDataEnabled() {
635        try {
636            return mService.getMobileDataEnabled();
637        } catch (RemoteException e) {
638            return true;
639        }
640    }
641
642    /**
643     * Sets the persisted value for enabling/disabling Mobile data.
644     *
645     * @param enabled Whether the mobile data connection should be
646     *            used or not.
647     * @hide
648     */
649    public void setMobileDataEnabled(boolean enabled) {
650        try {
651            mService.setMobileDataEnabled(enabled);
652        } catch (RemoteException e) {
653        }
654    }
655
656    /**
657     * {@hide}
658     */
659    public ConnectivityManager(IConnectivityManager service) {
660        mService = checkNotNull(service, "missing IConnectivityManager");
661    }
662
663    /** {@hide} */
664    public static ConnectivityManager from(Context context) {
665        return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
666    }
667
668    /**
669     * {@hide}
670     */
671    public String[] getTetherableIfaces() {
672        try {
673            return mService.getTetherableIfaces();
674        } catch (RemoteException e) {
675            return new String[0];
676        }
677    }
678
679    /**
680     * {@hide}
681     */
682    public String[] getTetheredIfaces() {
683        try {
684            return mService.getTetheredIfaces();
685        } catch (RemoteException e) {
686            return new String[0];
687        }
688    }
689
690    /**
691     * {@hide}
692     */
693    public String[] getTetheringErroredIfaces() {
694        try {
695            return mService.getTetheringErroredIfaces();
696        } catch (RemoteException e) {
697            return new String[0];
698        }
699    }
700
701    /**
702     * @return error A TETHER_ERROR value indicating success or failure type
703     * {@hide}
704     */
705    public int tether(String iface) {
706        try {
707            return mService.tether(iface);
708        } catch (RemoteException e) {
709            return TETHER_ERROR_SERVICE_UNAVAIL;
710        }
711    }
712
713    /**
714     * @return error A TETHER_ERROR value indicating success or failure type
715     * {@hide}
716     */
717    public int untether(String iface) {
718        try {
719            return mService.untether(iface);
720        } catch (RemoteException e) {
721            return TETHER_ERROR_SERVICE_UNAVAIL;
722        }
723    }
724
725    /**
726     * {@hide}
727     */
728    public boolean isTetheringSupported() {
729        try {
730            return mService.isTetheringSupported();
731        } catch (RemoteException e) {
732            return false;
733        }
734    }
735
736    /**
737     * {@hide}
738     */
739    public String[] getTetherableUsbRegexs() {
740        try {
741            return mService.getTetherableUsbRegexs();
742        } catch (RemoteException e) {
743            return new String[0];
744        }
745    }
746
747    /**
748     * {@hide}
749     */
750    public String[] getTetherableWifiRegexs() {
751        try {
752            return mService.getTetherableWifiRegexs();
753        } catch (RemoteException e) {
754            return new String[0];
755        }
756    }
757
758    /**
759     * {@hide}
760     */
761    public String[] getTetherableBluetoothRegexs() {
762        try {
763            return mService.getTetherableBluetoothRegexs();
764        } catch (RemoteException e) {
765            return new String[0];
766        }
767    }
768
769    /**
770     * {@hide}
771     */
772    public int setUsbTethering(boolean enable) {
773        try {
774            return mService.setUsbTethering(enable);
775        } catch (RemoteException e) {
776            return TETHER_ERROR_SERVICE_UNAVAIL;
777        }
778    }
779
780    /** {@hide} */
781    public static final int TETHER_ERROR_NO_ERROR           = 0;
782    /** {@hide} */
783    public static final int TETHER_ERROR_UNKNOWN_IFACE      = 1;
784    /** {@hide} */
785    public static final int TETHER_ERROR_SERVICE_UNAVAIL    = 2;
786    /** {@hide} */
787    public static final int TETHER_ERROR_UNSUPPORTED        = 3;
788    /** {@hide} */
789    public static final int TETHER_ERROR_UNAVAIL_IFACE      = 4;
790    /** {@hide} */
791    public static final int TETHER_ERROR_MASTER_ERROR       = 5;
792    /** {@hide} */
793    public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6;
794    /** {@hide} */
795    public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7;
796    /** {@hide} */
797    public static final int TETHER_ERROR_ENABLE_NAT_ERROR     = 8;
798    /** {@hide} */
799    public static final int TETHER_ERROR_DISABLE_NAT_ERROR    = 9;
800    /** {@hide} */
801    public static final int TETHER_ERROR_IFACE_CFG_ERROR      = 10;
802
803    /**
804     * @param iface The name of the interface we're interested in
805     * @return error The error code of the last error tethering or untethering the named
806     *               interface
807     * {@hide}
808     */
809    public int getLastTetherError(String iface) {
810        try {
811            return mService.getLastTetherError(iface);
812        } catch (RemoteException e) {
813            return TETHER_ERROR_SERVICE_UNAVAIL;
814        }
815    }
816
817    /**
818     * Ensure the device stays awake until we connect with the next network
819     * @param forWhome The name of the network going down for logging purposes
820     * @return {@code true} on success, {@code false} on failure
821     * {@hide}
822     */
823    public boolean requestNetworkTransitionWakelock(String forWhom) {
824        try {
825            mService.requestNetworkTransitionWakelock(forWhom);
826            return true;
827        } catch (RemoteException e) {
828            return false;
829        }
830    }
831
832    /**
833     * @param networkType The type of network you want to report on
834     * @param percentage The quality of the connection 0 is bad, 100 is good
835     * {@hide}
836     */
837    public void reportInetCondition(int networkType, int percentage) {
838        try {
839            mService.reportInetCondition(networkType, percentage);
840        } catch (RemoteException e) {
841        }
842    }
843
844    /**
845     * @param proxyProperties The definition for the new global http proxy
846     * {@hide}
847     */
848    public void setGlobalProxy(ProxyProperties p) {
849        try {
850            mService.setGlobalProxy(p);
851        } catch (RemoteException e) {
852        }
853    }
854
855    /**
856     * @return proxyProperties for the current global proxy
857     * {@hide}
858     */
859    public ProxyProperties getGlobalProxy() {
860        try {
861            return mService.getGlobalProxy();
862        } catch (RemoteException e) {
863            return null;
864        }
865    }
866
867    /**
868     * @return proxyProperties for the current proxy (global if set, network specific if not)
869     * {@hide}
870     */
871    public ProxyProperties getProxy() {
872        try {
873            return mService.getProxy();
874        } catch (RemoteException e) {
875            return null;
876        }
877    }
878
879    /**
880     * @param networkType The network who's dependence has changed
881     * @param met Boolean - true if network use is ok, false if not
882     * {@hide}
883     */
884    public void setDataDependency(int networkType, boolean met) {
885        try {
886            mService.setDataDependency(networkType, met);
887        } catch (RemoteException e) {
888        }
889    }
890
891    /**
892     * Returns true if the hardware supports the given network type
893     * else it returns false.  This doesn't indicate we have coverage
894     * or are authorized onto a network, just whether or not the
895     * hardware supports it.  For example a gsm phone without a sim
896     * should still return true for mobile data, but a wifi only tablet
897     * would return false.
898     * @param networkType The nework type we'd like to check
899     * @return true if supported, else false
900     * @hide
901     */
902    public boolean isNetworkSupported(int networkType) {
903        try {
904            return mService.isNetworkSupported(networkType);
905        } catch (RemoteException e) {}
906        return false;
907    }
908
909    /**
910     * Returns if the currently active data network is metered. A network is
911     * classified as metered when the user is sensitive to heavy data usage on
912     * that connection. You should check this before doing large data transfers,
913     * and warn the user or delay the operation until another network is
914     * available.
915     */
916    public boolean isActiveNetworkMetered() {
917        try {
918            return mService.isActiveNetworkMetered();
919        } catch (RemoteException e) {
920            return false;
921        }
922    }
923
924    /** {@hide} */
925    public boolean updateLockdownVpn() {
926        try {
927            return mService.updateLockdownVpn();
928        } catch (RemoteException e) {
929            return false;
930        }
931    }
932
933    /**
934     * {@hide}
935     */
936    public void captivePortalCheckComplete(NetworkInfo info) {
937        try {
938            mService.captivePortalCheckComplete(info);
939        } catch (RemoteException e) {
940        }
941    }
942
943}
944