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
Nested Classes Modifier and Type Class Description static classShadowWifiManager.ShadowMulticastLockstatic classShadowWifiManager.ShadowWifiLockstatic classShadowWifiManager.WifiUsabilityScoreClass to record scores passed to WifiManager#updateWifiUsabilityScore -
Constructor Summary
Constructors Constructor Description ShadowWifiManager() -
Method Summary
Modifier and Type Method Description protected intaddNetwork(WifiConfiguration config)protected voidaddOnWifiUsabilityStatsListener(Object executorObject, Object listenerObject)protected static intcalculateSignalLevel(int rssi, int numLevels)voidclearUsabilityScores()Clears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)protected voidconnect(int networkId, WifiManager.ActionListener listener)protected voidconnect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener)protected WifiManager.MulticastLockcreateMulticastLock(String tag)protected WifiManager.WifiLockcreateWifiLock(int lockType, String tag)protected WifiManager.WifiLockcreateWifiLock(String tag)protected booleandisableNetwork(int netId)protected booleanenableNetwork(int netId, boolean attemptConnect)intgetActiveLockCount()Returns the number of WifiLocks and MulticastLocks that are currently acquired.protected List<WifiConfiguration>getConfiguredNetworks()protected WifiInfogetConnectionInfo()protected DhcpInfogetDhcpInfo()Pair<Integer,Boolean>getLastEnabledNetwork()protected List<WifiConfiguration>getPrivilegedConfiguredNetworks()protected List<ScanResult>getScanResults()List<ShadowWifiManager.WifiUsabilityScore>getUsabilityScores()Returns wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)protected WifiConfigurationgetWifiApConfiguration()WifiConfigurationgetWifiConfiguration(int netId)protected intgetWifiState()protected booleanis5GHzBandSupported()booleanisNetworkEnabled(int netId)Whether the network is enabled or not.protected booleanisScanAlwaysAvailable()protected booleanisWifiEnabled()voidpostUsabilityStats(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 booleanreconnect()protected booleanremoveNetwork(int netId)protected voidremoveOnWifiUsabilityStatsListener(Object listenerObject)protected booleansaveConfiguration()voidsetAccessWifiStatePermission(boolean accessWifiStatePermission)voidsetConnectionInfo(WifiInfo wifiInfo)Sets the connection info as the providedWifiInfo.voidsetDhcpInfo(DhcpInfo dhcpInfo)voidsetIs5GHzBandSupported(boolean is5GHzBandSupported)Sets whether 5ghz band is supported.voidsetIsScanAlwaysAvailable(boolean isScanAlwaysAvailable)voidsetScanResults(List<ScanResult> scanResults)static voidsetSignalLevelInPercent(float level)voidsetStartScanSucceeds(boolean succeeds)Sets the return value ofstartScan().voidsetUpdateNetworkPermission(int networkId, boolean hasPermission)Prevents a networkId from being updated using theupdateNetwork(android.net.wifi.WifiConfiguration)method.protected booleansetWifiApConfiguration(WifiConfiguration apConfig)protected booleansetWifiEnabled(boolean wifiEnabled)voidsetWifiState(int wifiState)protected booleanstartScan()Does nothing and returns the configured success status.protected intupdateNetwork(WifiConfiguration config)Adds or updates a network which can later be retrieved withgetWifiConfiguration(int)method.protected voidupdateWifiUsabilityScore(int seqNum, int score, int predictionHorizonSec)booleanwasConfigurationSaved()
-
Constructor Details
-
ShadowWifiManager
public ShadowWifiManager()
-
-
Method Details
-
setWifiEnabled
-
setWifiState
public void setWifiState(int wifiState) -
isWifiEnabled
-
getWifiState
-
getConnectionInfo
-
is5GHzBandSupported
-
setIs5GHzBandSupported
public void setIs5GHzBandSupported(boolean is5GHzBandSupported)Sets whether 5ghz band is supported. -
setConnectionInfo
Sets the connection info as the providedWifiInfo. -
setStartScanSucceeds
public void setStartScanSucceeds(boolean succeeds)Sets the return value ofstartScan(). -
getScanResults
-
getConfiguredNetworks
-
getPrivilegedConfiguredNetworks
-
addNetwork
-
removeNetwork
-
updateNetwork
Adds or updates a network which can later be retrieved withgetWifiConfiguration(int)method. A null {@param config}, 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
trueup to and including Android 8, and eithertrueorfalseon Android 9+.- Returns:
- the value configured by
setStartScanSucceeds(boolean), ortrueif that method was never called.
-
getDhcpInfo
-
isScanAlwaysAvailable
-
connect
@HiddenApi @Implementation(minSdk=19) protected void connect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener) -
connect
@HiddenApi @Implementation(minSdk=19) protected void connect(int networkId, WifiManager.ActionListener listener) -
reconnect
-
setSignalLevelInPercent
public static void setSignalLevelInPercent(float level) -
setAccessWifiStatePermission
public void setAccessWifiStatePermission(boolean accessWifiStatePermission) -
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) -
setWifiApConfiguration
-
getWifiApConfiguration
-
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)
-