19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/*
29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License.
69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at
79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project *
109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and
149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License.
159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.net.wifi;
189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.annotation.SdkConstant;
209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.annotation.SdkConstant.SdkConstantType;
21ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriffimport android.content.Context;
229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.net.DhcpInfo;
239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Binder;
249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.IBinder;
259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler;
2688759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriffimport android.os.HandlerThread;
27d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriffimport android.os.Looper;
28d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriffimport android.os.Message;
299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.RemoteException;
307e9f4eb2608148436cef36c9969bf8a599b39e72Dianne Hackbornimport android.os.WorkSource;
31227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriffimport android.os.Messenger;
3288759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriffimport android.util.Log;
33d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriffimport android.util.SparseArray;
349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3588759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriffimport java.util.concurrent.CountDownLatch;
3688759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff
37ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriffimport com.android.internal.util.AsyncChannel;
38d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriffimport com.android.internal.util.Protocol;
39ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff
409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.util.List;
419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/**
439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This class provides the primary API for managing all aspects of Wi-Fi
449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * connectivity. Get an instance of this class by calling
459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link android.content.Context#getSystemService(String) Context.getSystemService(Context.WIFI_SERVICE)}.
469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It deals with several categories of items:
489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul>
499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>The list of configured networks. The list can be viewed and updated,
509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * and attributes of individual entries can be modified.</li>
519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>The currently active Wi-Fi network, if any. Connectivity can be
529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * established or torn down, and dynamic information about the state of
539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the network can be queried.</li>
549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>Results of access point scans, containing enough information to
559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * make decisions about what access point to connect to.</li>
569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>It defines the names of various Intent actions that are broadcast
579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * upon any sort of change in Wi-Fi state.
589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul>
599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This is the API to use when performing Wi-Fi specific operations. To
609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * perform operations that pertain to network connectivity at an abstract
619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * level, use {@link android.net.ConnectivityManager}.
629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */
639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class WifiManager {
649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6588759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private static final String TAG = "WifiManager";
669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    // Supplicant error codes:
679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The error code if there was a problem authenticating.
699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int ERROR_AUTHENTICATING = 1;
719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Broadcast intent action indicating that Wi-Fi has been enabled, disabled,
749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * enabling, disabling, or unknown. One extra provides this state as an int.
759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Another extra provides the previous state, if available.
76227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_WIFI_STATE
789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_PREVIOUS_WIFI_STATE
799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String WIFI_STATE_CHANGED_ACTION =
829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        "android.net.wifi.WIFI_STATE_CHANGED";
839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for an int that indicates whether Wi-Fi is enabled,
859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * disabled, enabling, disabling, or unknown.  Retrieve it with
869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Intent#getIntExtra(String,int)}.
87227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_DISABLED
899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_DISABLING
909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_ENABLED
919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_ENABLING
929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_UNKNOWN
939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_WIFI_STATE = "wifi_state";
959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The previous Wi-Fi state.
97227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_WIFI_STATE
999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_PREVIOUS_WIFI_STATE = "previous_wifi_state";
101227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi is currently being disabled. The state will change to {@link #WIFI_STATE_DISABLED} if
1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * it finishes successfully.
105227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_CHANGED_ACTION
1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_STATE_DISABLING = 0;
1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi is disabled.
112227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_CHANGED_ACTION
1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_STATE_DISABLED = 1;
1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi is currently being enabled. The state will change to {@link #WIFI_STATE_ENABLED} if
1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * it finishes successfully.
120227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_CHANGED_ACTION
1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_STATE_ENABLING = 2;
1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi is enabled.
127227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_CHANGED_ACTION
1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_STATE_ENABLED = 3;
1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi is in an unknown state. This state will occur when an error happens while enabling
1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * or disabling.
135227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
1369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #WIFI_STATE_CHANGED_ACTION
1379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
1389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
1399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_STATE_UNKNOWN = 4;
1405321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
1415321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1425321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Broadcast intent action indicating that Wi-Fi AP has been enabled, disabled,
1435321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * enabling, disabling, or failed.
1445321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1455321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1465321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
1475321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public static final String WIFI_AP_STATE_CHANGED_ACTION =
1485321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        "android.net.wifi.WIFI_AP_STATE_CHANGED";
1495321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
1505321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1515321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * The lookup key for an int that indicates whether Wi-Fi AP is enabled,
1525321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * disabled, enabling, disabling, or failed.  Retrieve it with
1535321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * {@link android.content.Intent#getIntExtra(String,int)}.
1545321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1555321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_DISABLED
1565321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_DISABLING
1575321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_ENABLED
1585321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_ENABLING
1595321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_FAILED
1605321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1615321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1625321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
1635321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public static final String EXTRA_WIFI_AP_STATE = "wifi_state";
1645321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1655321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * The previous Wi-Fi state.
1665321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1675321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #EXTRA_WIFI_AP_STATE
1685321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1695321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1705321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
1715321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public static final String EXTRA_PREVIOUS_WIFI_AP_STATE = "previous_wifi_state";
1725321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1735321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Wi-Fi AP is currently being disabled. The state will change to
1745321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * {@link #WIFI_AP_STATE_DISABLED} if it finishes successfully.
1755321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1765321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_CHANGED_ACTION
1775321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiApState()
1785321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1795321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1805321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
181a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff    public static final int WIFI_AP_STATE_DISABLING = 10;
1825321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1835321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Wi-Fi AP is disabled.
1845321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1855321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_CHANGED_ACTION
1865321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiState()
1875321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1885321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1895321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
190a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff    public static final int WIFI_AP_STATE_DISABLED = 11;
1915321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
1925321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Wi-Fi AP is currently being enabled. The state will change to
1935321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * {@link #WIFI_AP_STATE_ENABLED} if it finishes successfully.
1945321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1955321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_CHANGED_ACTION
1965321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiApState()
1975321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
1985321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
1995321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
200a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff    public static final int WIFI_AP_STATE_ENABLING = 12;
2015321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
2025321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Wi-Fi AP is enabled.
2035321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
2045321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_CHANGED_ACTION
2055321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiApState()
2065321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
2075321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
2085321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
209a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff    public static final int WIFI_AP_STATE_ENABLED = 13;
2105321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
2115321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Wi-Fi AP is in a failed state. This state will occur when an error occurs during
2125321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * enabling or disabling
2135321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
2145321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #WIFI_AP_STATE_CHANGED_ACTION
2155321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiApState()
2165321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
2175321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide
2185321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
219a2a1b911a31dd94ee75e94845f762b91f1db1368Irfan Sheriff    public static final int WIFI_AP_STATE_FAILED = 14;
2205321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Broadcast intent action indicating that a connection to the supplicant has
2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * been established (and it is now possible
2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * to perform Wi-Fi operations) or the connection to the supplicant has been
2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * lost. One extra provides the connection state as a boolean, where {@code true}
2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * means CONNECTED.
2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_SUPPLICANT_CONNECTED
2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String SUPPLICANT_CONNECTION_CHANGE_ACTION =
2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        "android.net.wifi.supplicant.CONNECTION_CHANGE";
2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for a boolean that indicates whether a connection to
2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * the supplicant daemon has been gained or lost. {@code true} means
2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * a connection now exists.
2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Retrieve it with {@link android.content.Intent#getBooleanExtra(String,boolean)}.
2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_SUPPLICANT_CONNECTED = "connected";
2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Broadcast intent action indicating that the state of Wi-Fi connectivity
2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * has changed. One extra provides the new state
2423550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * in the form of a {@link android.net.NetworkInfo} object. If the new
2433550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * state is CONNECTED, additional extras may provide the BSSID and WifiInfo of
2443550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * the access point.
2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * as a {@code String}.
2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_NETWORK_INFO
2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_BSSID
2483550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * @see #EXTRA_WIFI_INFO
2499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String NETWORK_STATE_CHANGED_ACTION = "android.net.wifi.STATE_CHANGE";
2529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for a {@link android.net.NetworkInfo} object associated with the
2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Wi-Fi network. Retrieve with
2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Intent#getParcelableExtra(String)}.
2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_NETWORK_INFO = "networkInfo";
2589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for a String giving the BSSID of the access point to which
2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * we are connected. Only present when the new state is CONNECTED.
2619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Retrieve with
2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Intent#getStringExtra(String)}.
2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_BSSID = "bssid";
2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2663550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * The lookup key for a {@link android.net.wifi.WifiInfo} object giving the
2673550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * information about the access point to which we are connected. Only present
2683550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * when the new state is CONNECTED.  Retrieve with
2693550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     * {@link android.content.Intent#getParcelableExtra(String)}.
2703550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy     */
2713550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy    public static final String EXTRA_WIFI_INFO = "wifiInfo";
2723550ac919c492f3fbaebbf868f4df0d1ea7ee784Isaac Levy    /**
2739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Broadcast intent action indicating that the state of establishing a connection to
2749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * an access point has changed.One extra provides the new
2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link SupplicantState}. Note that the supplicant state is Wi-Fi specific, and
2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * is not generally the most useful thing to look at if you are just interested in
2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * the overall state of connectivity.
2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_NEW_STATE
2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_SUPPLICANT_ERROR
2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String SUPPLICANT_STATE_CHANGED_ACTION =
2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        "android.net.wifi.supplicant.STATE_CHANGE";
2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for a {@link SupplicantState} describing the new state
2869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Retrieve with
2879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Intent#getParcelableExtra(String)}.
2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_NEW_STATE = "newState";
2909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
2929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for a {@link SupplicantState} describing the supplicant
2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * error code if any
2949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Retrieve with
2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Intent#getIntExtra(String, int)}.
2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #ERROR_AUTHENTICATING
2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_SUPPLICANT_ERROR = "supplicantError";
299fcb659b66756ac02bd1491ae1365b27e8509a890Irfan Sheriff
300fcb659b66756ac02bd1491ae1365b27e8509a890Irfan Sheriff    /**
301be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff     * Broadcast intent action indicating that the configured networks changed.
3021b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * This can be as a result of adding/updating/deleting a network. If
3031b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is set to true the new configuration
3041b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * can be retreived with the {@link #EXTRA_WIFI_CONFIGURATION} extra. If multiple
3051b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * Wi-Fi configurations changed, {@link #EXTRA_WIFI_CONFIGURATION} will not be present.
306e04653cbd0e8303eba92088344312b827e6b0babIrfan Sheriff     * @hide
307e04653cbd0e8303eba92088344312b827e6b0babIrfan Sheriff     */
308be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff    public static final String CONFIGURED_NETWORKS_CHANGED_ACTION =
309be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff        "android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3111b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * The lookup key for a (@link android.net.wifi.WifiConfiguration} object representing
3121b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * the changed Wi-Fi configuration when the {@link #CONFIGURED_NETWORKS_CHANGED_ACTION}
3131b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * broadcast is sent.
3141b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3151b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3161b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final String EXTRA_WIFI_CONFIGURATION = "wifiConfiguration";
3171b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3181b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * Multiple network configurations have changed.
3191b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @see #CONFIGURED_NETWORKS_CHANGED_ACTION
3201b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     *
3211b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3221b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3231b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
3241b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3251b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * The lookup key for an integer indicating the reason a Wi-Fi network configuration
3261b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * has changed. Only present if {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is {@code false}
3271b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @see #CONFIGURED_NETWORKS_CHANGED_ACTION
3281b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3291b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3301b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final String EXTRA_CHANGE_REASON = "changeReason";
3311b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3321b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * The configuration is new and was added.
3331b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3341b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3351b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final int CHANGE_REASON_ADDED = 0;
3361b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3371b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * The configuration was removed and is no longer present in the system's list of
3381b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * configured networks.
3391b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3401b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3411b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final int CHANGE_REASON_REMOVED = 1;
3421b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3431b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * The configuration has changed as a result of explicit action or because the system
3441b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * took an automated action such as disabling a malfunctioning configuration.
3451b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     * @hide
3461b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood     */
3471b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    public static final int CHANGE_REASON_CONFIG_CHANGE = 2;
3481b6989cdc212aec7579489a362f99b791abe7352Mike Lockwood    /**
3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * An access point scan has completed, and results are available from the supplicant.
3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Call {@link #getScanResults()} to obtain the results.
3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String SCAN_RESULTS_AVAILABLE_ACTION = "android.net.wifi.SCAN_RESULTS";
3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The RSSI (signal strength) has changed.
3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #EXTRA_NEW_RSSI
3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String RSSI_CHANGED_ACTION = "android.net.wifi.RSSI_CHANGED";
3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The lookup key for an {@code int} giving the new RSSI in dBm.
3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String EXTRA_NEW_RSSI = "newRssi";
3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
366be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff     * Broadcast intent action indicating that the link configuration
3670d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * changed on wifi.
3680d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
3690d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
370be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff    public static final String LINK_CONFIGURATION_CHANGED_ACTION =
371be9ee6a498afc08df1ca6d796b703b703b25c9a9Irfan Sheriff        "android.net.wifi.LINK_CONFIGURATION_CHANGED";
372f61101f6266be243c481d163b95e65d67b8d1669Wink Saville
3730d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    /**
37437e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt     * The lookup key for a {@link android.net.LinkProperties} object associated with the
3750d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * Wi-Fi network. Retrieve with
3760d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * {@link android.content.Intent#getParcelableExtra(String)}.
3770d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
3780d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
37937e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt    public static final String EXTRA_LINK_PROPERTIES = "linkProperties";
3800d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff
3810d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    /**
382f61101f6266be243c481d163b95e65d67b8d1669Wink Saville     * The lookup key for a {@link android.net.LinkCapabilities} object associated with the
383f61101f6266be243c481d163b95e65d67b8d1669Wink Saville     * Wi-Fi network. Retrieve with
384f61101f6266be243c481d163b95e65d67b8d1669Wink Saville     * {@link android.content.Intent#getParcelableExtra(String)}.
385f61101f6266be243c481d163b95e65d67b8d1669Wink Saville     * @hide
386f61101f6266be243c481d163b95e65d67b8d1669Wink Saville     */
387f61101f6266be243c481d163b95e65d67b8d1669Wink Saville    public static final String EXTRA_LINK_CAPABILITIES = "linkCapabilities";
388f61101f6266be243c481d163b95e65d67b8d1669Wink Saville
389f61101f6266be243c481d163b95e65d67b8d1669Wink Saville    /**
3909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The network IDs of the configured networks could have changed.
3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String NETWORK_IDS_CHANGED_ACTION = "android.net.wifi.NETWORK_IDS_CHANGED";
39437e65ebb7eb932e1a144b1cab262e11ca5fd109bRobert Greenwalt
3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Activity Action: Pick a Wi-Fi network to connect to.
3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <p>Input: Nothing.
3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <p>Output: Nothing.
3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final String ACTION_PICK_WIFI_NETWORK = "android.net.wifi.PICK_WIFI_NETWORK";
4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
40499001278289036a3c645e599ed832943ff1b6e15Eric Shienbrood     * In this Wi-Fi lock mode, Wi-Fi will be kept active,
4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * and will behave normally, i.e., it will attempt to automatically
4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * establish a connection to a remembered access point that is
4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * within range, and will do periodic scans if there are remembered
4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * access points but none are in range.
4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_MODE_FULL = 1;
4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
41299001278289036a3c645e599ed832943ff1b6e15Eric Shienbrood     * In this Wi-Fi lock mode, Wi-Fi will be kept active,
4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * but the only operation that will be supported is initiation of
4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * scans, and the subsequent reporting of scan results. No attempts
4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * will be made to automatically connect to remembered access points,
4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * nor will periodic scans be automatically performed looking for
4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * remembered access points. Scans must be explicitly requested by
4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * an application in this mode.
4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static final int WIFI_MODE_SCAN_ONLY = 2;
421652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff    /**
422652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * In this Wi-Fi lock mode, Wi-Fi will be kept active as in mode
423652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * {@link #WIFI_MODE_FULL} but it operates at high performance
424652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * with minimum packet loss and low packet latency even when
425652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * the device screen is off. This mode will consume more power
426652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * and hence should be used only when there is a need for such
427652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * an active connection.
428652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * <p>
429652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * An example use case is when a voice connection needs to be
430652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * kept active even after the device screen goes off. Holding the
431652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * regular {@link #WIFI_MODE_FULL} lock will keep the wifi
432652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * connection active, but the connection can be lossy.
433652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * Holding a {@link #WIFI_MODE_FULL_HIGH_PERF} lock for the
434652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * duration of the voice call will improve the call quality.
435652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * <p>
436652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * When there is no support from the hardware, this lock mode
437652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     * will have the same behavior as {@link #WIFI_MODE_FULL}
438652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff     */
439652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff    public static final int WIFI_MODE_FULL_HIGH_PERF = 3;
4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /** Anything worse than or equal to this will show 0 bars. */
4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final int MIN_RSSI = -100;
443652bc96444b0a82d34e6c3766b7862effac11adbIrfan Sheriff
4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /** Anything better than or equal to this will show the max bars. */
4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private static final int MAX_RSSI = -55;
44636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
44736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
448ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff     * Number of RSSI levels used in the framework to initiate
449ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff     * {@link #RSSI_CHANGED_ACTION} broadcast
450ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff     * @hide
451ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff     */
452ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff    public static final int RSSI_LEVELS = 5;
453ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff
454ea933cb3fddbf5971dd4c62090edabbed295c3a7Irfan Sheriff    /**
45536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Auto settings in the driver. The driver could choose to operate on both
45636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
45736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
45836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
45936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public static final int WIFI_FREQUENCY_BAND_AUTO = 0;
46036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
46136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
46236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Operation on 5 GHz alone
46336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
46436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
46536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;
46636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
46736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
46836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Operation on 2.4 GHz alone
46936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
47036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
47136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;
47236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
473227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    /** List of asyncronous notifications
474227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     * @hide
475227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     */
476227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    public static final int DATA_ACTIVITY_NOTIFICATION = 1;
477227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
478227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    //Lowest bit indicates data reception and the second lowest
479227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    //bit indicates data transmitted
480227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    /** @hide */
481227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    public static final int DATA_ACTIVITY_NONE         = 0x00;
482227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    /** @hide */
483227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    public static final int DATA_ACTIVITY_IN           = 0x01;
484227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    /** @hide */
485227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    public static final int DATA_ACTIVITY_OUT          = 0x02;
486227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    /** @hide */
487227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff    public static final int DATA_ACTIVITY_INOUT        = 0x03;
488227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
489617750604c69e6068f68266d0e30324273aa990eMike Lockwood    /* Maximum number of active locks we allow.
490617750604c69e6068f68266d0e30324273aa990eMike Lockwood     * This limit was added to prevent apps from creating a ridiculous number
491617750604c69e6068f68266d0e30324273aa990eMike Lockwood     * of locks and crashing the system by overflowing the global ref table.
492617750604c69e6068f68266d0e30324273aa990eMike Lockwood     */
493617750604c69e6068f68266d0e30324273aa990eMike Lockwood    private static final int MAX_ACTIVE_LOCKS = 50;
494617750604c69e6068f68266d0e30324273aa990eMike Lockwood
495617750604c69e6068f68266d0e30324273aa990eMike Lockwood    /* Number of currently active WifiLocks and MulticastLocks */
496617750604c69e6068f68266d0e30324273aa990eMike Lockwood    private int mActiveLockCount;
497617750604c69e6068f68266d0e30324273aa990eMike Lockwood
49888759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private Context mContext;
49988759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    IWifiManager mService;
50088759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff
50188759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private static final int INVALID_KEY = 0;
50288759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private int mListenerKey = 1;
50388759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private final SparseArray mListenerMap = new SparseArray();
50488759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private final Object mListenerMapLock = new Object();
50588759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff
50688759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private AsyncChannel mAsyncChannel = new AsyncChannel();
50788759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private ServiceHandler mHandler;
50888759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private Messenger mWifiServiceMessenger;
50988759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    private final CountDownLatch mConnected = new CountDownLatch(1);
51088759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff
5119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Create a new WifiManager instance.
5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Applications will almost always want to use
5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * the standard {@link android.content.Context#WIFI_SERVICE Context.WIFI_SERVICE}.
51688759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff     * @param context the application context
5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param service the Binder interface
5189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @hide - hide this because it takes in a parameter of type IWifiManager, which
5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * is a system private class.
5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
52188759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff    public WifiManager(Context context, IWifiManager service) {
52288759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff        mContext = context;
5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        mService = service;
52488759bbd31e05a4163e1f8e72804ca83000afd53Irfan Sheriff        init();
5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return a list of all the networks configured in the supplicant.
5299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Not all fields of WifiConfiguration are returned. Only the following
5309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * fields are filled in:
5319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <ul>
5329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>networkId</li>
5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>SSID</li>
5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>BSSID</li>
5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>priority</li>
5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>allowedProtocols</li>
5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>allowedKeyManagement</li>
5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>allowedAuthAlgorithms</li>
5399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>allowedPairwiseCiphers</li>
5409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <li>allowedGroupCiphers</li>
5419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * </ul>
5429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return a list of network configurations in the form of a list
54359358536d2f14b27cdc7386daeabc2b6dca8e177Irfan Sheriff     * of {@link WifiConfiguration} objects. Upon failure to fetch or
54459358536d2f14b27cdc7386daeabc2b6dca8e177Irfan Sheriff     * when when Wi-Fi is turned off, it can be null.
5459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public List<WifiConfiguration> getConfiguredNetworks() {
5479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
5489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.getConfiguredNetworks();
5499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
5509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
5519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Add a new network description to the set of configured networks.
5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The {@code networkId} field of the supplied configuration object
5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * is ignored.
5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <p/>
5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * The new network will be marked DISABLED by default. To enable it,
5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * called {@link #enableNetwork}.
561227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param config the set of variables that describe the configuration,
5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            contained in a {@link WifiConfiguration} object.
5649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the ID of the newly created network description. This is used in
5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         other operations to specified the network to be acted upon.
5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Returns {@code -1} on failure.
5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int addNetwork(WifiConfiguration config) {
5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (config == null) {
5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return -1;
5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        config.networkId = -1;
5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return addOrUpdateNetwork(config);
5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Update the network description of an existing configured network.
5789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
5799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param config the set of variables that describe the configuration,
5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            contained in a {@link WifiConfiguration} object. It may
5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            be sparse, so that only the items that are being changed
5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            are non-<code>null</code>. The {@code networkId} field
5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            must be set to the ID of the existing network being updated.
5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return Returns the {@code networkId} of the supplied
5859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         {@code WifiConfiguration} on success.
5869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         <br/>
5879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         Returns {@code -1} on failure, including when the {@code networkId}
5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         field of the {@code WifiConfiguration} does not refer to an
5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         existing network.
5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int updateNetwork(WifiConfiguration config) {
5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (config == null || config.networkId < 0) {
5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return -1;
5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return addOrUpdateNetwork(config);
5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Internal method for doing the RPC that creates a new network description
6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * or updates an existing one.
601227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param config The possibly sparse object containing the variables that
6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         are to set or updated in the network description.
6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the ID of the network on success, {@code -1} on failure.
6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    private int addOrUpdateNetwork(WifiConfiguration config) {
6079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.addOrUpdateNetwork(config);
6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return -1;
6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Remove the specified network from the list of configured networks.
6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * This may result in the asynchronous delivery of state change
6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * events.
6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param netId the integer that identifies the network configuration
6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * to the supplicant
6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean removeNetwork(int netId) {
6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.removeNetwork(netId);
6259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
6279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Allow a previously configured network to be associated with. If
6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <code>disableOthers</code> is true, then all other configured
6339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * networks are disabled, and an attempt to connect to the selected
6349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * network is initiated. This may result in the asynchronous delivery
6359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of state change events.
6369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param netId the ID of the network in the list of configured networks
6379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param disableOthers if true, disable all other networks. The way to
6389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * select a particular network to connect to is specify {@code true}
6399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * for this parameter.
6409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean enableNetwork(int netId, boolean disableOthers) {
6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.enableNetwork(netId, disableOthers);
6459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
6479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disable a configured network. The specified network will not be
6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * a candidate for associating. This may result in the asynchronous
6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * delivery of state change events.
6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param netId the ID of the network as returned by {@link #addNetwork}.
6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean disableNetwork(int netId) {
6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.disableNetwork(netId);
6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Disassociate from the currently active access point. This may result
6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * in the asynchronous delivery of state change events.
6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean disconnect() {
6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
672e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            mService.disconnect();
673e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            return true;
6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Reconnect to the currently active access point, if we are currently
6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * disconnected. This may result in the asynchronous delivery of state
6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * change events.
6839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
6859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean reconnect() {
6869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
687e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            mService.reconnect();
688e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            return true;
6899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
6909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
6919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
6929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
6939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
6959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Reconnect to the currently active access point, even if we are already
6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * connected. This may result in the asynchronous delivery of state
6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * change events.
6989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
6999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean reassociate() {
7019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
702e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            mService.reassociate();
703e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            return true;
7049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Check that the supplicant daemon is responding to requests.
7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if we were able to communicate with the supplicant and
7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * it returned the expected response to the PING message.
7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean pingSupplicant() {
7159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (mService == null)
7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.pingSupplicant();
7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
7219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Request a scan for access points. Returns immediately. The availability
7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * of the results is made known later by means of an asynchronous event sent
7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * on completion of the scan.
7289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded, i.e., the scan was initiated
7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
730a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood    public boolean startScan() {
7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
732e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            mService.startScan(false);
733e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            return true;
734a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood        } catch (RemoteException e) {
735a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood            return false;
736a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood        }
737a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood    }
738a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood
739a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood    /**
740a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * Request a scan for access points. Returns immediately. The availability
741a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * of the results is made known later by means of an asynchronous event sent
742a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * on completion of the scan.
743a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * This is a variant of startScan that forces an active scan, even if passive
744a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * scans are the current default
745a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * @return {@code true} if the operation succeeded, i.e., the scan was initiated
746a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     *
747a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     * @hide
748a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood     */
749a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood    public boolean startScanActive() {
750a5ec95cdb1a7d2024249277dff1f99d0046c9b56Mike Lockwood        try {
751e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            mService.startScan(true);
752e498475b187277309c81b38240c7e71ec049e369Irfan Sheriff            return true;
7539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
7559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return dynamic information about the current Wi-Fi connection, if any is active.
7609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the Wi-Fi information, contained in {@link WifiInfo}.
7619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public WifiInfo getConnectionInfo() {
7639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
7649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.getConnectionInfo();
7659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
7679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return the results of the latest access point scan.
7729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the list of access points found in the most recent scan.
7739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public List<ScanResult> getScanResults() {
7759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
7769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.getScanResults();
7779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
7799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
7839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Tell the supplicant to persist the current list of configured networks.
7849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * <p>
7859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Note: It is possible for this method to change the network IDs of
7869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * existing networks. You should assume the network IDs can be different
7879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * after calling this method.
788227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
7899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeded
7909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
7919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean saveConfiguration() {
7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
7939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.saveConfiguration();
7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
800ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff     * Set the country code.
801ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff     * @param countryCode country code in ISO 3166 format.
802ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff     * @param persist {@code true} if this needs to be remembered
8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *
804ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff     * @hide
8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
806ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff    public void setCountryCode(String country, boolean persist) {
8079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
808ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff            mService.setCountryCode(country, persist);
809ed4f28b492da3ff140bbaabbbda798a08c40ea5bIrfan Sheriff        } catch (RemoteException e) { }
8109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
81336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Set the operational frequency band.
81436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @param band  One of
81536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_AUTO},
81636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_5GHZ},
81736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_2GHZ},
81836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @param persist {@code true} if this needs to be remembered
81936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
82036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
82136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public void setFrequencyBand(int band, boolean persist) {
82236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        try {
82336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff            mService.setFrequencyBand(band, persist);
82436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        } catch (RemoteException e) { }
82536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    }
82636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
82736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
82836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Get the operational frequency band.
82936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @return One of
83036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_AUTO},
83136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_5GHZ},
83236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@link #WIFI_FREQUENCY_BAND_2GHZ} or
83336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     *     {@code -1} on failure.
83436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
83536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
83636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public int getFrequencyBand() {
83736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        try {
83836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff            return mService.getFrequencyBand();
83936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        } catch (RemoteException e) {
84036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff            return -1;
84136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        }
84236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    }
84336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
84436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
84536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * Check if the chipset supports dual frequency band (2.4 GHz and 5 GHz)
84636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @return {@code true} if supported, {@code false} otherwise.
84736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     * @hide
84836f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff     */
84936f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    public boolean isDualBandSupported() {
85036f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        try {
85136f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff            return mService.isDualBandSupported();
85236f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        } catch (RemoteException e) {
85336f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff            return false;
85436f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff        }
85536f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    }
85636f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff
85736f7413dabfab50699135019ba55151e9227f59dIrfan Sheriff    /**
8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Return the DHCP-assigned addresses from the last successful DHCP request,
8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * if any.
8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return the DHCP information
8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public DhcpInfo getDhcpInfo() {
8639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
8649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.getDhcpInfo();
8659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
8669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return null;
8679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Enable or disable Wi-Fi.
8739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param enabled {@code true} to enable, {@code false} to disable.
8749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if the operation succeeds (or if the existing state
8759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         is the same as the requested state).
8769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean setWifiEnabled(boolean enabled) {
8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.setWifiEnabled(enabled);
8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return false;
8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Gets the Wi-Fi enabled state.
8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return One of {@link #WIFI_STATE_DISABLED},
8889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         {@link #WIFI_STATE_DISABLING}, {@link #WIFI_STATE_ENABLED},
8899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         {@link #WIFI_STATE_ENABLING}, {@link #WIFI_STATE_UNKNOWN}
8909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #isWifiEnabled()
8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public int getWifiState() {
8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        try {
8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return mService.getWifiEnabledState();
8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } catch (RemoteException e) {
8969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return WIFI_STATE_UNKNOWN;
8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
899227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
901227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     * Return whether Wi-Fi is enabled or disabled.
9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return {@code true} if Wi-Fi is enabled
9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @see #getWifiState()
9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public boolean isWifiEnabled() {
9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return getWifiState() == WIFI_STATE_ENABLED;
9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
908227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
9099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
910f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng     * Return TX packet counter, for CTS test of WiFi watchdog.
911f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng     * @param listener is the interface to receive result
912f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng     *
913f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng     * @hide for CTS test only
914f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng     */
915f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    public void getTxPacketCount(TxPacketCountListener listener) {
916f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng        validateChannel();
917f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng        mAsyncChannel.sendMessage(RSSI_PKTCNT_FETCH, 0, putListener(listener));
918f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    }
919f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng
920f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    /**
9219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Calculates the level of the signal. This should be used any time a signal
9229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * is being shown.
923227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
9249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param rssi The power of the signal measured in RSSI.
9259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param numLevels The number of levels to consider in the calculated
9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *            level.
9279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return A level of the signal, given in the range of 0 to numLevels-1
9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         (both inclusive).
9299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static int calculateSignalLevel(int rssi, int numLevels) {
9319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        if (rssi <= MIN_RSSI) {
9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return 0;
9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else if (rssi >= MAX_RSSI) {
9349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project            return numLevels - 1;
9359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        } else {
9364c0d81b8add0372cc7194b17cc6d2bfc58baacd1Daniel Sandler            float inputRange = (MAX_RSSI - MIN_RSSI);
9374c0d81b8add0372cc7194b17cc6d2bfc58baacd1Daniel Sandler            float outputRange = (numLevels - 1);
9384c0d81b8add0372cc7194b17cc6d2bfc58baacd1Daniel Sandler            return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
9399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        }
9409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
941227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff
9429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
9439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * Compares two signal strengths.
944227bec49157bc496f7c9e8e8f63c12728a448922Irfan Sheriff     *
9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param rssiA The power of the first signal measured in RSSI.
9469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @param rssiB The power of the second signal measured in RSSI.
9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     * @return Returns <0 if the first signal is weaker than the second signal,
9489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         0 if the two signals have the same strength, and >0 if the first
9499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     *         signal is stronger than the second signal.
9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project     */
9519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    public static int compareSignalLevel(int rssiA, int rssiB) {
9529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project        return rssiA - rssiB;
9539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    }
9549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project
9559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project    /**
9565321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Start AccessPoint mode with the specified
9575321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * configuration. If the radio is already running in
9585321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * AP mode, update the new configuration
9595321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Note that starting in access point mode disables station
9605321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * mode operation
9615321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @param wifiConfig SSID, security and channel details as
9625321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *        part of WifiConfiguration
9635321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @return {@code true} if the operation succeeds, {@code false} otherwise
9645321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
9655321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide Dont open up yet
9665321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
9675321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
9685321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        try {
969ffcea7ae7316ab748a49f5e8f6c6798356f35719Irfan Sheriff            mService.setWifiApEnabled(wifiConfig, enabled);
970ffcea7ae7316ab748a49f5e8f6c6798356f35719Irfan Sheriff            return true;
9715321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        } catch (RemoteException e) {
9725321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff            return false;
9735321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        }
9745321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    }
9755321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
9765321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
9775321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Gets the Wi-Fi enabled state.
9785321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @return One of {@link #WIFI_AP_STATE_DISABLED},
9795321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *         {@link #WIFI_AP_STATE_DISABLING}, {@link #WIFI_AP_STATE_ENABLED},
9805321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *         {@link #WIFI_AP_STATE_ENABLING}, {@link #WIFI_AP_STATE_FAILED}
9815321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #isWifiApEnabled()
9825321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
9835321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide Dont open yet
9845321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
9855321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public int getWifiApState() {
9865321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        try {
9875321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff            return mService.getWifiApEnabledState();
9885321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        } catch (RemoteException e) {
9895321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff            return WIFI_AP_STATE_FAILED;
9905321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        }
9915321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    }
9925321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
9935321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
9945321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * Return whether Wi-Fi AP is enabled or disabled.
9955321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @return {@code true} if Wi-Fi AP is enabled
9965321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @see #getWifiApState()
9975321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     *
9985321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     * @hide Dont open yet
9995321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff     */
10005321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    public boolean isWifiApEnabled() {
10015321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff        return getWifiApState() == WIFI_AP_STATE_ENABLED;
10025321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    }
10035321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff
10045321aef4a22daef6ed01ed48d936cdd82f2e38b7Irfan Sheriff    /**
10059ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff     * Gets the Wi-Fi AP Configuration.
10069ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff     * @return AP details in WifiConfiguration
10079ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff     *
10089ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff     * @hide Dont open yet
10099ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff     */
10109ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff    public WifiConfiguration getWifiApConfiguration() {
10119ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff        try {
10129ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff            return mService.getWifiApConfiguration();
10139ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff        } catch (RemoteException e) {
10149ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff            return null;
10159ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff        }
10169ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff    }
10179ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff
10189ab518ad793385f8405edf19363fe825fb64f5f8Irfan Sheriff    /**
101917b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff     * Sets the Wi-Fi AP Configuration.
102017b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff     * @return {@code true} if the operation succeeded, {@code false} otherwise
102117b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff     *
102217b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff     * @hide Dont open yet
102317b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff     */
102417b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff    public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
102517b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff        try {
102617b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff            mService.setWifiApConfiguration(wifiConfig);
102717b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff            return true;
102817b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff        } catch (RemoteException e) {
102917b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff            return false;
103017b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff        }
103117b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff    }
103217b232b5b59ab91ab543b87e849583678a000f9bIrfan Sheriff
10330d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff   /**
10340d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * Start the driver and connect to network.
10350d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10360d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This function will over-ride WifiLock and device idle status. For example,
10370d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * even if the device is idle or there is only a scan-only lock held,
10380d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * a start wifi would mean that wifi connection is kept active until
10390d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * a stopWifi() is sent.
10400d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10410d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This API is used by WifiStateTracker
10420d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10430d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @return {@code true} if the operation succeeds else {@code false}
10440d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
10450d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
10460d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    public boolean startWifi() {
10470d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        try {
10480d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            mService.startWifi();
10490d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return true;
10500d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        } catch (RemoteException e) {
10510d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return false;
10520d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        }
10530d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    }
10540d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff
10550d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    /**
10560d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * Disconnect from a network (if any) and stop the driver.
10570d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10580d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This function will over-ride WifiLock and device idle status. Wi-Fi
10590d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * stays inactive until a startWifi() is issued.
10600d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10610d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This API is used by WifiStateTracker
10620d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10630d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @return {@code true} if the operation succeeds else {@code false}
10640d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
10650d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
10660d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    public boolean stopWifi() {
10670d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        try {
10680d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            mService.stopWifi();
10690d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return true;
10700d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        } catch (RemoteException e) {
10710d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return false;
10720d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        }
10730d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    }
10740d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff
10750d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    /**
10760d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * Add a bssid to the supplicant blacklist
10770d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10780d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This API is used by WifiWatchdogService
10790d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10800d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @return {@code true} if the operation succeeds else {@code false}
10810d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
10820d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
10830d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    public boolean addToBlacklist(String bssid) {
10840d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        try {
10850d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            mService.addToBlacklist(bssid);
10860d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return true;
10870d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        } catch (RemoteException e) {
10880d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return false;
10890d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        }
10900d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    }
10910d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff
10920d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    /**
10930d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * Clear the supplicant blacklist
10940d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10950d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * This API is used by WifiWatchdogService
10960d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     *
10970d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @return {@code true} if the operation succeeds else {@code false}
10980d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     * @hide
10990d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff     */
11000d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    public boolean clearBlacklist() {
11010d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        try {
11020d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            mService.clearBlacklist();
11030d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return true;
11040d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        } catch (RemoteException e) {
11050d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff            return false;
11060d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff        }
11070d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff    }
11080d25534fed91f636def5776ddc4605005bd7471cIrfan Sheriff
1109e04653cbd0e8303eba92088344312b827e6b0babIrfan Sheriff    /* TODO: deprecate synchronous API and open up the following API */
1110ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff
1111d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    private static final int BASE = Protocol.BASE_WIFI_MANAGER;
1112d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff
1113ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /* Commands to WifiService */
1114ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /** @hide */
1115d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int CONNECT_NETWORK                 = BASE + 1;
1116d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1117d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int CONNECT_NETWORK_FAILED          = BASE + 2;
1118d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1119d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int CONNECT_NETWORK_SUCCEEDED       = BASE + 3;
1120d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff
1121d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1122d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int FORGET_NETWORK                  = BASE + 4;
1123d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1124d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int FORGET_NETWORK_FAILED           = BASE + 5;
1125ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /** @hide */
1126d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int FORGET_NETWORK_SUCCEEDED        = BASE + 6;
1127d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff
1128ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /** @hide */
1129d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int SAVE_NETWORK                    = BASE + 7;
1130ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /** @hide */
1131d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int SAVE_NETWORK_FAILED             = BASE + 8;
11328dc6a1b2823f374a176fb21b8a174664a5f825faIsaac Levy    /** @hide */
1133d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int SAVE_NETWORK_SUCCEEDED          = BASE + 9;
1134ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff
1135ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff    /** @hide */
1136d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int START_WPS                       = BASE + 10;
1137d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1138d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int START_WPS_SUCCEEDED             = BASE + 11;
1139d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
1140d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int WPS_FAILED                      = BASE + 12;
114186a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    /** @hide */
1142d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    public static final int WPS_COMPLETED                   = BASE + 13;
1143d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff
1144d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
114586a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int CANCEL_WPS                      = BASE + 14;
114686a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    /** @hide */
114786a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int CANCEL_WPS_FAILED               = BASE + 15;
114886a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    /** @hide */
114986a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int CANCEL_WPS_SUCCEDED             = BASE + 16;
115086a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff
115186a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    /** @hide */
115286a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int DISABLE_NETWORK                 = BASE + 17;
1153d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
115486a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int DISABLE_NETWORK_FAILED          = BASE + 18;
1155d3975a917799b85cacaf382b65c5832813066b51Irfan Sheriff    /** @hide */
115686a5f5b9afa97a4ed6f5a2466fb9359ea131e2fbIrfan Sheriff    public static final int DISABLE_NETWORK_SUCCEEDED       = BASE + 19;
1157ebe606fccd9293674273d5f73246e0e8e6e6ddcfIrfan Sheriff
1158f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    /** @hide */
1159f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    public static final int RSSI_PKTCNT_FETCH               = BASE + 20;
1160f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    /** @hide */
1161f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    public static final int RSSI_PKTCNT_FETCH_SUCCEEDED     = BASE + 21;
1162f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    /** @hide */
1163f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng    public static final int RSSI_PKTCNT_FETCH_FAILED        = BASE + 22;
1164f6307820c88e694e102824225b9d8caa6de75a30Yuhao Zheng
1165