Helper interface for manipulating wifi services on device.
Nested classes |
enum |
IWifiHelper.WifiState
The Wifi supplicant state.
|
Public methods |
abstract
boolean
|
addOpenNetwork(String ssid)
Adds the open security network identified by ssid.
|
abstract
boolean
|
addOpenNetwork(String ssid, boolean scanSsid)
Adds the open security network identified by ssid.
|
abstract
boolean
|
addWpaPskNetwork(String ssid, String psk)
Adds the WPA-PSK security network identified by ssid.
|
abstract
boolean
|
addWpaPskNetwork(String ssid, String psk, boolean scanSsid)
Adds the WPA-PSK security network identified by ssid.
|
abstract
boolean
|
checkConnectivity(String urlToCheck)
Checks connectivity by sending HTTP request to the given url.
|
abstract
void
|
cleanUp()
Clean up the resources and the wifi helper packaged install.
|
abstract
boolean
|
connectToNetwork(String ssid, String psk, String urlToCheck)
Connects to a wifi network and check connectivity.
|
abstract
boolean
|
connectToNetwork(String ssid, String psk, String urlToCheck, boolean scanSsid)
Connects to a wifi network and check connectivity.
|
abstract
boolean
|
disableWifi()
Disables wifi state on device.
|
abstract
boolean
|
disconnectFromNetwork()
Disconnect from the current wifi network and disable wifi.
|
abstract
boolean
|
enableWifi()
Enables wifi state on device.
|
abstract
String
|
getBSSID()
Gets the basic service set identifier (BSSID) of the currently access point.
|
abstract
String
|
getIpAddress()
Gets the IP address associated with the wifi interface.
|
abstract
String
|
getSSID()
Gets the service set identifier of the currently connected network.
|
abstract
Map<String, String>
|
getWifiInfo()
Gets the current wifi connection information.
|
abstract
boolean
|
hasValidIp()
|
abstract
boolean
|
isWifiEnabled()
Check if wifi is currently enabled.
|
abstract
boolean
|
removeAllNetworks()
Removes all known networks.
|
abstract
boolean
|
startMonitor(long interval, String urlToCheck)
Starts network connectivity monitoring.
|
abstract
List<Long>
|
stopMonitor()
Stops network connectivity monitoring.
|
abstract
boolean
|
waitForIp(long timeout)
Wait until an ip address is assigned to wifi adapter.
|
abstract
boolean
|
waitForWifiDisabled(long timeout)
Wait for isWifiEnabled() to be false.
|
abstract
boolean
|
waitForWifiDisabled()
Wait for isWifiEnabled() to be false with a default timeout.
|
abstract
boolean
|
waitForWifiEnabled(long timeout)
Wait for isWifiEnabled() to be true.
|
abstract
boolean
|
waitForWifiEnabled()
Wait for isWifiEnabled() to be true with a default timeout.
|
abstract
boolean
|
waitForWifiState(WifiState... expectedStates)
Waits until one of the expected wifi states occurs.
|
Public methods
addOpenNetwork
public abstract boolean addOpenNetwork (String ssid)
Adds the open security network identified by ssid.
To connect to any wifi network, a network profile must be created in wpa_supplicant
configuration first. This will call wpa_cli to add the open security network identified by
ssid.
Parameters |
ssid |
String : the ssid of network to add. |
Returns |
boolean |
true if network was added successfully, false otherwise. |
addOpenNetwork
public abstract boolean addOpenNetwork (String ssid,
boolean scanSsid)
Adds the open security network identified by ssid.
To connect to any wifi network, a network profile must be created in wpa_supplicant
configuration first. This will call wpa_cli to add the open security network identified by
ssid.
Parameters |
ssid |
String : the ssid of network to add. |
scanSsid |
boolean : whether to scan for hidden SSID for this network. |
Returns |
boolean |
true if network was added successfully, false otherwise. |
addWpaPskNetwork
public abstract boolean addWpaPskNetwork (String ssid,
String psk)
Adds the WPA-PSK security network identified by ssid.
Parameters |
ssid |
String : the ssid of network to add. |
psk |
String : the WPA-PSK passphrase to use |
Returns |
boolean |
true if network was added successfully, false otherwise. |
addWpaPskNetwork
public abstract boolean addWpaPskNetwork (String ssid,
String psk,
boolean scanSsid)
Adds the WPA-PSK security network identified by ssid.
Parameters |
ssid |
String : the ssid of network to add. |
psk |
String : the WPA-PSK passphrase to use |
scanSsid |
boolean : whether to scan for hidden SSID for this network. |
Returns |
boolean |
true if network was added successfully, false otherwise. |
checkConnectivity
public abstract boolean checkConnectivity (String urlToCheck)
Checks connectivity by sending HTTP request to the given url.
Parameters |
urlToCheck |
String : a destination url for a HTTP request check |
Returns |
boolean |
true if the device pass connectivity check. |
cleanUp
public abstract void cleanUp ()
Clean up the resources and the wifi helper packaged install. This should only be called when
Wifi is not needed anymore for the invocation since the device would lose the wifi connection
when the helper is uninstalled.
connectToNetwork
public abstract boolean connectToNetwork (String ssid,
String psk,
String urlToCheck)
Connects to a wifi network and check connectivity.
Parameters |
ssid |
String : the ssid of network to connect |
psk |
String : the WPA-PSK passphrase to use. This can be null. |
urlToCheck |
String : a destination url for a HTTP request check |
Returns |
boolean |
true if the device pass connectivity check. |
connectToNetwork
public abstract boolean connectToNetwork (String ssid,
String psk,
String urlToCheck,
boolean scanSsid)
Connects to a wifi network and check connectivity.
Parameters |
ssid |
String : the ssid of network to connect |
psk |
String : the WPA-PSK passphrase to use. This can be null. |
urlToCheck |
String : a destination url for a HTTP request check |
scanSsid |
boolean : whether to scan for hidden SSID for this network |
Returns |
boolean |
true if the device pass connectivity check. |
disableWifi
public abstract boolean disableWifi ()
Disables wifi state on device.
Returns |
boolean |
true if wifi was disabled successfully |
disconnectFromNetwork
public abstract boolean disconnectFromNetwork ()
Disconnect from the current wifi network and disable wifi.
Returns |
boolean |
true if the operation succeeded. |
enableWifi
public abstract boolean enableWifi ()
Enables wifi state on device.
Returns |
boolean |
true if wifi was enabled successfully |
getBSSID
public abstract String getBSSID ()
Gets the basic service set identifier (BSSID) of the currently access point.
getIpAddress
public abstract String getIpAddress ()
Gets the IP address associated with the wifi interface. Returns null
if there
was a failure retrieving ip address.
getSSID
public abstract String getSSID ()
Gets the service set identifier of the currently connected network.
getWifiInfo
public abstract Map<String, String> getWifiInfo ()
Gets the current wifi connection information.
This includes SSID, BSSID, IP address, link speed, and RSSI.
Returns |
Map<String, String> |
a map containing wifi connection information. |
hasValidIp
public abstract boolean hasValidIp ()
Returns |
boolean |
true if device has a valid IP address |
isWifiEnabled
public abstract boolean isWifiEnabled ()
Check if wifi is currently enabled.
removeAllNetworks
public abstract boolean removeAllNetworks ()
Removes all known networks.
startMonitor
public abstract boolean startMonitor (long interval,
String urlToCheck)
Starts network connectivity monitoring.
Parameters |
interval |
long : interval between connectivity checks. |
urlToCheck |
String : a URL to check connectivity with. |
Returns |
boolean |
true if the operation succeeded. |
stopMonitor
public abstract List<Long> stopMonitor ()
Stops network connectivity monitoring.
This also returns the latency history since the last
startMonitor(long, String)
call.
Returns |
List<Long> |
the latency history. |
waitForIp
public abstract boolean waitForIp (long timeout)
Wait until an ip address is assigned to wifi adapter.
Parameters |
timeout |
long : how long to wait |
Returns |
boolean |
true if an ip address is assigned before timeout, false
otherwise |
waitForWifiDisabled
public abstract boolean waitForWifiDisabled (long timeout)
Wait for isWifiEnabled()
to be false.
Parameters |
timeout |
long : time in ms to wait |
Returns |
boolean |
true if wifi was disabled before timeout, false otherwise. |
waitForWifiDisabled
public abstract boolean waitForWifiDisabled ()
Wait for isWifiEnabled()
to be false with a default timeout.
Returns |
boolean |
true if wifi was disabled before timeout, false otherwise. |
waitForWifiEnabled
public abstract boolean waitForWifiEnabled (long timeout)
Wait for isWifiEnabled()
to be true.
Parameters |
timeout |
long : time in ms to wait |
Returns |
boolean |
true if wifi was enabled before timeout, false otherwise. |
waitForWifiEnabled
public abstract boolean waitForWifiEnabled ()
Wait for isWifiEnabled()
to be true with a default timeout.
Returns |
boolean |
true if wifi was enabled before timeout, false otherwise. |
waitForWifiState
public abstract boolean waitForWifiState (WifiState... expectedStates)
Waits until one of the expected wifi states occurs.
Parameters |
expectedStates |
WifiState : one or more wifi states to expect |
Returns |
boolean |
true if the one of the expected states occurred. false if
none of the states occurred before timeout is reached |
Interfaces
Classes
Enums
Exceptions
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2019-10-02 UTC.