Package org.robolectric.shadows
Class ShadowWifiManager
java.lang.Object
org.robolectric.shadows.ShadowWifiManager
@Implements(value=android.net.wifi.WifiManager.class,
looseSignatures=true)
public class ShadowWifiManager
extends Object
Shadow for
WifiManager
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
Class to record scores passed to WifiManager#updateWifiUsabilityScore -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addLocalOnlyConnectionFailureListener
(Executor executor, WifiManager.LocalOnlyConnectionFailureListener listener) protected int
addNetwork
(WifiConfiguration config) protected WifiManager.AddNetworkResult
The new version ofaddNetwork(WifiConfiguration)
which returns a more detailed failure codes.protected void
addOnWifiUsabilityStatsListener
(Object executorObject, Object listenerObject) protected static int
calculateSignalLevel
(int rssi, int numLevels) protected void
void
Clears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
protected void
protected void
connect
(int networkId, WifiManager.ActionListener listener) protected void
connect
(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener) protected WifiManager.MulticastLock
protected WifiManager.WifiLock
createWifiLock
(int lockType, String tag) protected WifiManager.WifiLock
createWifiLock
(String tag) protected boolean
disableNetwork
(int netId) protected boolean
enableNetwork
(int netId, boolean attemptConnect) int
Returns the number of WifiLocks and MulticastLocks that are currently acquired.protected List<WifiConfiguration>
The original implementation allows this to be called by the Device Owner (DO), Profile Owner (PO), callers with carrier privilege and system apps, but this shadow can be called by all apps carrying the ACCESS_WIFI_STATE permission.protected List<WifiConfiguration>
protected WifiInfo
protected DhcpInfo
protected List<WifiConfiguration>
protected List<ScanResult>
protected SoftApConfiguration
Returns wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
protected WifiConfiguration
getWifiConfiguration
(int netId) protected int
protected boolean
boolean
isNetworkEnabled
(int netId) Whether the network is enabled or not.protected boolean
protected boolean
Returns last value provided tosetStaApConcurrencySupported(boolean)
.boolean
Returns if wifi connected betwork scorer enabledprotected boolean
protected boolean
Returns last value provided tosetWpa3SaeH2eSupported(boolean)
.protected boolean
Returns last value provided tosetWpa3SaePublicKeySupported(boolean)
.protected boolean
Returns last value provided tosetWpa3SaeSupported(boolean)
.protected boolean
Returns last value provided tosetWpa3SuiteBSupported(boolean)
.void
networksFoundFromPnoScan
(List<ScanResult> scanResults) Informs theWifiManager
of a list of PNOScanResult
.void
postUsabilityStats
(int seqNum, boolean isSameBssidAndFreq, WifiUsabilityStatsEntryBuilder statsBuilder) Post Wifi stats to any listeners registered withWifiManager.addOnWifiUsabilityStatsListener(java.util.concurrent.Executor, android.net.wifi.WifiManager.OnWifiUsabilityStatsListener)
protected boolean
protected void
protected boolean
removeNetwork
(int netId) protected boolean
Removes all configured networks regardless of the app that created the network.protected void
removeOnWifiUsabilityStatsListener
(Object listenerObject) protected boolean
void
setAccessWifiStatePermission
(boolean accessWifiStatePermission) void
setChangeWifiStatePermission
(boolean changeWifiStatePermission) void
setConnectionInfo
(WifiInfo wifiInfo) Sets the connection info as the providedWifiInfo
.void
setDhcpInfo
(DhcpInfo dhcpInfo) protected void
setExternalPnoScanRequest
(Object ssids, Object frequencies, Object executor, Object callback) void
setIs5GHzBandSupported
(boolean is5GHzBandSupported) Sets whether 5ghz band is supported.void
setIsScanAlwaysAvailable
(boolean isScanAlwaysAvailable) void
setScanResults
(List<ScanResult> scanResults) static void
setSignalLevelInPercent
(float level) protected boolean
setSoftApConfiguration
(SoftApConfiguration softApConfig) void
setStaApConcurrencySupported
(boolean isStaApConcurrencySupported) Sets whether STA/AP concurrency is supported.void
setStartScanSucceeds
(boolean succeeds) Sets the return value ofstartScan()
.void
setUpdateNetworkPermission
(int networkId, boolean hasPermission) Prevents a networkId from being updated using theupdateNetwork(android.net.wifi.WifiConfiguration)
method.protected boolean
setWifiApConfiguration
(WifiConfiguration apConfig) protected boolean
setWifiConnectedNetworkScorer
(Object executorObject, Object scorerObject) Implements setWifiConnectedNetworkScorer() with the generic Object input as WifiConnectedNetworkScorer is a hidden/System API.protected boolean
setWifiEnabled
(boolean wifiEnabled) void
setWifiState
(int wifiState) void
setWpa3SaeH2eSupported
(boolean isWpa3SaeH2eSupported) Sets whether WPA3 SAE Hash-to-Element is supported.void
setWpa3SaePublicKeySupported
(boolean isWpa3SaePublicKeySupported) Sets whether WPA3 SAE Public Key is supported.void
setWpa3SaeSupported
(boolean isWpa3SaeSupported) Sets whether WPA3-Personal SAE is supported.void
setWpa3SuiteBSupported
(boolean isWpa3SuiteBSupported) Sets whether WPA3-Enterprise Suite-B-192 is supported.protected boolean
Does nothing and returns the configured success status.void
triggerLocalConnectionFailure
(WifiNetworkSpecifier specifier, int failureReason) Simulates a connection failure for a specified local network connection.protected int
updateNetwork
(WifiConfiguration config) Adds or updates a network which can later be retrieved withgetWifiConfiguration(int)
method.protected void
updateWifiUsabilityScore
(int seqNum, int score, int predictionHorizonSec) boolean
-
Constructor Details
-
ShadowWifiManager
public ShadowWifiManager()
-
-
Method Details
-
triggerLocalConnectionFailure
Simulates a connection failure for a specified local network connection.- Parameters:
specifier
- theWifiNetworkSpecifier
describing the local network connection attemptfailureReason
- the reason for the network connection failure. This should be one of the values specified inWifiManager#STATUS_LOCAL_ONLY_CONNECTION_FAILURE_*
-
addLocalOnlyConnectionFailureListener
@Implementation(minSdk=34) protected void addLocalOnlyConnectionFailureListener(Executor executor, WifiManager.LocalOnlyConnectionFailureListener listener) -
removeLocalOnlyConnectionFailureListener
@Implementation(minSdk=34) protected void removeLocalOnlyConnectionFailureListener(WifiManager.LocalOnlyConnectionFailureListener listener) -
setWifiEnabled
-
setWifiState
public void setWifiState(int wifiState) -
isWifiEnabled
-
getWifiState
-
getConnectionInfo
-
is5GHzBandSupported
-
setIs5GHzBandSupported
public void setIs5GHzBandSupported(boolean is5GHzBandSupported) Sets whether 5ghz band is supported. -
isStaApConcurrencySupported
Returns last value provided tosetStaApConcurrencySupported(boolean)
. -
setStaApConcurrencySupported
public void setStaApConcurrencySupported(boolean isStaApConcurrencySupported) Sets whether STA/AP concurrency is supported. -
isWpa3SaeSupported
Returns last value provided tosetWpa3SaeSupported(boolean)
. -
setWpa3SaeSupported
public void setWpa3SaeSupported(boolean isWpa3SaeSupported) Sets whether WPA3-Personal SAE is supported. -
isWpa3SaePublicKeySupported
Returns last value provided tosetWpa3SaePublicKeySupported(boolean)
. -
setWpa3SaePublicKeySupported
public void setWpa3SaePublicKeySupported(boolean isWpa3SaePublicKeySupported) Sets whether WPA3 SAE Public Key is supported. -
isWpa3SaeH2eSupported
Returns last value provided tosetWpa3SaeH2eSupported(boolean)
. -
setWpa3SaeH2eSupported
public void setWpa3SaeH2eSupported(boolean isWpa3SaeH2eSupported) Sets whether WPA3 SAE Hash-to-Element is supported. -
isWpa3SuiteBSupported
Returns last value provided tosetWpa3SuiteBSupported(boolean)
. -
setWpa3SuiteBSupported
public void setWpa3SuiteBSupported(boolean isWpa3SuiteBSupported) Sets whether WPA3-Enterprise Suite-B-192 is supported. -
setConnectionInfo
Sets the connection info as the providedWifiInfo
. -
setStartScanSucceeds
public void setStartScanSucceeds(boolean succeeds) Sets the return value ofstartScan()
. -
getScanResults
-
getCallerConfiguredNetworks
The original implementation allows this to be called by the Device Owner (DO), Profile Owner (PO), callers with carrier privilege and system apps, but this shadow can be called by all apps carrying the ACCESS_WIFI_STATE permission.This shadow is a wrapper for getConfiguredNetworks() and does not actually check the caller.
-
getConfiguredNetworks
-
getPrivilegedConfiguredNetworks
-
addNetwork
-
addNetworkPrivileged
@Implementation(minSdk=31) protected WifiManager.AddNetworkResult addNetworkPrivileged(WifiConfiguration config) The new version ofaddNetwork(WifiConfiguration)
which returns a more detailed failure codes. The original implementation of this API is limited to Device Owner (DO), Profile Owner (PO), system app, and privileged apps but this shadow can be called by all apps. -
removeNetwork
-
removeNonCallerConfiguredNetworks
Removes all configured networks regardless of the app that created the network. Can only be called by a Device Owner (DO) app.- Returns:
true
if at least one network is removed,false
otherwise
-
updateNetwork
Adds or updates a network which can later be retrieved withgetWifiConfiguration(int)
method. A null , or one with a networkId less than 0, or a networkId that had its updatePermission removed using thesetUpdateNetworkPermission(int, boolean)
will return -1, which indicates a failure to update. -
saveConfiguration
-
enableNetwork
-
disableNetwork
-
createWifiLock
-
createWifiLock
-
createMulticastLock
-
calculateSignalLevel
-
startScan
Does nothing and returns the configured success status.That is different from the Android implementation which always returns
true
up to and including Android 8, and eithertrue
orfalse
on Android 9+.- Returns:
- the value configured by
setStartScanSucceeds(boolean)
, ortrue
if that method was never called.
-
getDhcpInfo
-
isScanAlwaysAvailable
-
connect
@HiddenApi @Implementation protected void connect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener) -
connect
@HiddenApi @Implementation protected void connect(int networkId, WifiManager.ActionListener listener) -
reconnect
-
setSignalLevelInPercent
public static void setSignalLevelInPercent(float level) -
setAccessWifiStatePermission
public void setAccessWifiStatePermission(boolean accessWifiStatePermission) -
setChangeWifiStatePermission
public void setChangeWifiStatePermission(boolean changeWifiStatePermission) -
setUpdateNetworkPermission
public void setUpdateNetworkPermission(int networkId, boolean hasPermission) Prevents a networkId from being updated using theupdateNetwork(android.net.wifi.WifiConfiguration)
method. This is to simulate the case where a separate application creates a network, and the Android security model prevents your application from updating it. -
setScanResults
-
setDhcpInfo
-
getLastEnabledNetwork
-
isNetworkEnabled
public boolean isNetworkEnabled(int netId) Whether the network is enabled or not. -
getActiveLockCount
public int getActiveLockCount()Returns the number of WifiLocks and MulticastLocks that are currently acquired. -
wasConfigurationSaved
public boolean wasConfigurationSaved() -
setIsScanAlwaysAvailable
public void setIsScanAlwaysAvailable(boolean isScanAlwaysAvailable) -
getWifiConfiguration
-
addOnWifiUsabilityStatsListener
@Implementation(minSdk=29) @HiddenApi protected void addOnWifiUsabilityStatsListener(Object executorObject, Object listenerObject) -
removeOnWifiUsabilityStatsListener
@Implementation(minSdk=29) @HiddenApi protected void removeOnWifiUsabilityStatsListener(Object listenerObject) -
updateWifiUsabilityScore
@Implementation(minSdk=29) @HiddenApi protected void updateWifiUsabilityScore(int seqNum, int score, int predictionHorizonSec) -
setWifiConnectedNetworkScorer
@Implementation(minSdk=30) @HiddenApi protected boolean setWifiConnectedNetworkScorer(Object executorObject, Object scorerObject) Implements setWifiConnectedNetworkScorer() with the generic Object input as WifiConnectedNetworkScorer is a hidden/System API. -
clearWifiConnectedNetworkScorer
-
isWifiConnectedNetworkScorerEnabled
public boolean isWifiConnectedNetworkScorerEnabled()Returns if wifi connected betwork scorer enabled -
setWifiApConfiguration
-
getWifiApConfiguration
-
setSoftApConfiguration
@Implementation(minSdk=30) protected boolean setSoftApConfiguration(SoftApConfiguration softApConfig) -
getSoftApConfiguration
-
getUsabilityScores
Returns wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
-
clearUsabilityScores
public void clearUsabilityScores()Clears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
-
postUsabilityStats
public void postUsabilityStats(int seqNum, boolean isSameBssidAndFreq, WifiUsabilityStatsEntryBuilder statsBuilder) Post Wifi stats to any listeners registered withWifiManager.addOnWifiUsabilityStatsListener(java.util.concurrent.Executor, android.net.wifi.WifiManager.OnWifiUsabilityStatsListener)
-
networksFoundFromPnoScan
Informs theWifiManager
of a list of PNOScanResult
. -
setExternalPnoScanRequest
@Implementation(minSdk=33) @HiddenApi protected void setExternalPnoScanRequest(Object ssids, Object frequencies, Object executor, Object callback) -
clearExternalPnoScanRequest
-