Package ej.net.util.wifi
Class WifiNetworkManager
- java.lang.Object
-
- ej.net.util.wifi.WifiNetworkManager
-
public class WifiNetworkManager extends Object
This manager manage the Wi-Fi manager and network to keep a state.- See Also:
WifiManager,NetworkInterfaceManager
-
-
Constructor Summary
Constructors Constructor Description WifiNetworkManager()Instantiates a WifiNetworkManager with a defaultAccessPointConfigurationandSoftAPConfiguration.WifiNetworkManager(AccessPointConfiguration configurationAP, SoftAPConfiguration softAPConfiguration)Instantiates a WifiNetworkManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AccessPointConfigurationgetAPConfiguration()Gets the configurationAP.WifiCapabilitygetCapabilities()Gets theWifiCapability.StringgetInterfaceName()Gets the interfaceName.AccessPointgetJoinedAccessPoint()Gets the joined access.SoftAPConfigurationgetSoftAPConfiguration()Gets the softAPConfiguration.NetworkInterfacegetWifiInterface()Gets the wifi Interface.WifiManagergetWifiManager()Gets the Wi-FI manager used.booleanisConnected()Checks if the Wi-FI is connected to network.booleanisInit()Checks if the Wi-FI Manager is initialized.booleanisSoftAPEnabled()Checks if the Wi-FI is has enabled the softAP.voidjoinAccessPoint(int timeout)Joins the access point configuration selected.voidjoinAccessPoint(AccessPoint access, String password, int timeout)Joins a specificAccessPoint.voidjoinAccessPoint(String ssid, String password, SecurityMode securityMode, int timeout)Joins a particular Access Point.voidleaveAccessPoint()Leaves the joined Access Point.voidmountSoftAccessPoint()Mounts a Soft Access Point.voidmountSoftAccessPoint(SoftAPConfiguration config)Mounts a Soft Access Point.AccessPoint[]scanAccessPoints()Scans Access Points.voidsetAPConfiguration(AccessPointConfiguration configurationAP)Sets the configurationAP.voidsetClientIPConfigure(IPConfiguration ipConfiguration)Sets theIPConfigurationfor the interface while in client mode.voidsetInterfaceName(String interfaceName)Sets the interfaceName.voidsetScanWhileSoftAP(boolean scanWhileSoftAP)Sets whether it supports scan while mounted.voidsetSoftAPConfiguration(SoftAPConfiguration softAPConfiguration)Sets the softAPConfiguration.voidsetSoftAPIPConfigure(IPConfiguration softAPIPConfiguration)Sets theIPConfigurationfor the interface while in softAP.booleansupportScanWhileSoftAP()Gets whether it supports scan while in softAP.voidunmountSoftAccessPoint()Unmounts a Soft Access Point.
-
-
-
Constructor Detail
-
WifiNetworkManager
public WifiNetworkManager() throws IOExceptionInstantiates a WifiNetworkManager with a defaultAccessPointConfigurationandSoftAPConfiguration.- Throws:
IOException- When initialise fail.- See Also:
WifiNetworkManager(AccessPointConfiguration, SoftAPConfiguration)
-
WifiNetworkManager
public WifiNetworkManager(@NonNull AccessPointConfiguration configurationAP, @NonNull SoftAPConfiguration softAPConfiguration) throws IOException, NullPointerException
Instantiates a WifiNetworkManager.- Parameters:
configurationAP- the configurationAP to use.softAPConfiguration- the softAPConfiguration to use.- Throws:
IOException- When initialise fail.NullPointerException- if parameters arenullorWifiManagernot found.- See Also:
WifiManager.getInstance()
-
-
Method Detail
-
isInit
public boolean isInit()
Checks if the Wi-FI Manager is initialized.- Returns:
trueif the Wi-FI manager is initialized.- See Also:
NetworkInterfaceManager.isEnabled(NetworkInterface)
-
scanAccessPoints
public AccessPoint[] scanAccessPoints() throws IOException
Scans Access Points.- Returns:
- the list of available access points (it is empty if there is no available access point).
- Throws:
IOException- if an error occurred.- See Also:
WifiManager.scan()
-
joinAccessPoint
public void joinAccessPoint(int timeout) throws IOException, NullPointerException, UnsupportedOperationException, IllegalArgumentExceptionJoins the access point configuration selected.- Parameters:
timeout- the timeout to wait for an IP, 0 for unlimited, cannot be less than 0.- Throws:
IOException- if an error occurred.NullPointerException- if AP is not set.UnsupportedOperationException- If the Wi-Fi does not support client mode.IllegalArgumentException- if timeout is less than 0.- See Also:
getAPConfiguration(),AccessPointConfiguration.setAccessPoint(AccessPoint),joinAccessPoint(AccessPoint, String, int),joinAccessPoint(AccessPoint, String, int),joinAccessPoint(String, String, SecurityMode, int)
-
joinAccessPoint
public void joinAccessPoint(@NonNull AccessPoint access, @Nullable String password, int timeout) throws IOException, NullPointerException, UnsupportedOperationException, IllegalArgumentException
Joins a specificAccessPoint.- Parameters:
access- theAccessPointto join.password- theAccessPointpassword.timeout- the timeout to wait for an IP, 0 for unlimited, cannot be less than 0.- Throws:
IOException- if an error occurred.NullPointerException- if the AP isnull.UnsupportedOperationException- If the Wi-Fi does not support client mode.IllegalArgumentException- if timeout is less than 0.- See Also:
WifiManager.join(AccessPoint, String)
-
joinAccessPoint
public void joinAccessPoint(@NonNull String ssid, @Nullable String password, @Nullable SecurityMode securityMode, int timeout) throws IOException, UnsupportedOperationException, IllegalArgumentException
Joins a particular Access Point.- Parameters:
ssid- the AP SSID.password- the AP password.securityMode- the security Mode to use.timeout- the timeout to wait for an IP, 0 for unlimited, cannot be less than 0.- Throws:
IOException- if an error occurred.UnsupportedOperationException- If the Wi-Fi does not support client mode.IllegalArgumentException- if timeout is less than 0.- See Also:
WifiManager.join(String, String)
-
leaveAccessPoint
public void leaveAccessPoint() throws IOExceptionLeaves the joined Access Point.- Throws:
IOException- if an error occurred.- See Also:
WifiManager.leave()
-
isConnected
public boolean isConnected() throws IOExceptionChecks if the Wi-FI is connected to network.- Returns:
- true if the Wi-FI manager is connected to a network.
- Throws:
IOException- If an I/O error occurs.- See Also:
WifiManager.getJoined()
-
isSoftAPEnabled
public boolean isSoftAPEnabled() throws IOExceptionChecks if the Wi-FI is has enabled the softAP.- Returns:
- true if enabled, false otherwise.
- Throws:
IOException- If an I/O error occurs.- See Also:
WifiManager.isSoftAPEnabled()
-
getJoinedAccessPoint
public AccessPoint getJoinedAccessPoint() throws IOException
Gets the joined access.- Returns:
- the joined access,
nullif none. - Throws:
IOException- If an I/O error occurs.- See Also:
WifiManager.getJoined()
-
getAPConfiguration
public AccessPointConfiguration getAPConfiguration()
Gets the configurationAP.- Returns:
- the configurationAP.
-
setAPConfiguration
public void setAPConfiguration(@NonNull AccessPointConfiguration configurationAP)
Sets the configurationAP.- Parameters:
configurationAP- the configurationAP to set.
-
getSoftAPConfiguration
public SoftAPConfiguration getSoftAPConfiguration()
Gets the softAPConfiguration.- Returns:
- the softAPConfiguration.
-
setSoftAPConfiguration
public void setSoftAPConfiguration(@NonNull SoftAPConfiguration softAPConfiguration) throws NullPointerException
Sets the softAPConfiguration.- Parameters:
softAPConfiguration- the softAPConfiguration to set, cannot benull.- Throws:
NullPointerException- ifSoftAPConfigurationisnull.
-
mountSoftAccessPoint
public void mountSoftAccessPoint() throws IOExceptionMounts a Soft Access Point.- Throws:
IOException- if an error occurred.- See Also:
WifiManager.enableSoftAP(SoftAPConfiguration)
-
mountSoftAccessPoint
public void mountSoftAccessPoint(@NonNull SoftAPConfiguration config) throws IOException, UnsupportedOperationException
Mounts a Soft Access Point.- Parameters:
config- the configuration to use.- Throws:
IOException- if an error occurred.UnsupportedOperationException- If the Wi-Fi does not support SoftAP mode.- See Also:
WifiManager.enableSoftAP(SoftAPConfiguration)
-
unmountSoftAccessPoint
public void unmountSoftAccessPoint() throws IOExceptionUnmounts a Soft Access Point.- Throws:
IOException- if an error occurred.- See Also:
WifiManager.disableSoftAP()
-
supportScanWhileSoftAP
public boolean supportScanWhileSoftAP()
Gets whether it supports scan while in softAP.- Returns:
trueif scan while mounted is supported.
-
setScanWhileSoftAP
public void setScanWhileSoftAP(boolean scanWhileSoftAP)
Sets whether it supports scan while mounted.- Parameters:
scanWhileSoftAP-trueif scan while mounted is supported.
-
getCapabilities
public WifiCapability getCapabilities() throws IOException
Gets theWifiCapability.- Returns:
- the capabilities.
- Throws:
IOException- If an I/O error occurs.- See Also:
WifiManager.getCapability()
-
setClientIPConfigure
public void setClientIPConfigure(@Nullable IPConfiguration ipConfiguration)
Sets theIPConfigurationfor the interface while in client mode. This will be taken in account on the next join.- Parameters:
ipConfiguration- theIPConfigurationto use, can benullthen it won't be used.
-
setSoftAPIPConfigure
public void setSoftAPIPConfigure(@Nullable IPConfiguration softAPIPConfiguration)
Sets theIPConfigurationfor the interface while in softAP. This will be taken in account on the nextmountSoftAccessPoint().- Parameters:
softAPIPConfiguration- theIPConfigurationto use when in softAP.
-
getInterfaceName
public String getInterfaceName()
Gets the interfaceName.- Returns:
- the interfaceName.
-
setInterfaceName
public void setInterfaceName(@Nullable String interfaceName)
Sets the interfaceName.- Parameters:
interfaceName- the interfaceName to set.
-
getWifiManager
public WifiManager getWifiManager()
Gets the Wi-FI manager used.- Returns:
- the Wi-FI manager.
-
getWifiInterface
public NetworkInterface getWifiInterface()
Gets the wifi Interface.- Returns:
- the wifiInterface.
-
-