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 forWifiManager
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowWifiManager.ShadowMulticastLock
static class
ShadowWifiManager.ShadowWifiLock
static class
ShadowWifiManager.WifiUsabilityScore
Class to record scores passed to WifiManager#updateWifiUsabilityScore
-
Constructor Summary
Constructors Constructor Description ShadowWifiManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
addNetwork(WifiConfiguration config)
protected void
addOnWifiUsabilityStatsListener(Object executorObject, Object listenerObject)
protected static int
calculateSignalLevel(int rssi, int numLevels)
void
clearUsabilityScores()
Clears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
protected void
connect(int networkId, WifiManager.ActionListener listener)
protected void
connect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener)
protected WifiManager.MulticastLock
createMulticastLock(String tag)
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
getActiveLockCount()
Returns the number of WifiLocks and MulticastLocks that are currently acquired.protected List<WifiConfiguration>
getConfiguredNetworks()
protected WifiInfo
getConnectionInfo()
protected DhcpInfo
getDhcpInfo()
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 WifiConfiguration
getWifiApConfiguration()
WifiConfiguration
getWifiConfiguration(int netId)
protected int
getWifiState()
protected boolean
is5GHzBandSupported()
boolean
isNetworkEnabled(int netId)
Whether the network is enabled or not.protected boolean
isScanAlwaysAvailable()
protected boolean
isStaApConcurrencySupported()
Returns last value provided to #setStaApConcurrencySupported.protected boolean
isWifiEnabled()
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
reconnect()
protected boolean
removeNetwork(int netId)
protected void
removeOnWifiUsabilityStatsListener(Object listenerObject)
protected boolean
saveConfiguration()
void
setAccessWifiStatePermission(boolean accessWifiStatePermission)
void
setConnectionInfo(WifiInfo wifiInfo)
Sets the connection info as the providedWifiInfo
.void
setDhcpInfo(DhcpInfo dhcpInfo)
void
setIs5GHzBandSupported(boolean is5GHzBandSupported)
Sets whether 5ghz band is supported.void
setIsScanAlwaysAvailable(boolean isScanAlwaysAvailable)
void
setScanResults(List<ScanResult> scanResults)
static void
setSignalLevelInPercent(float level)
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
setWifiEnabled(boolean wifiEnabled)
void
setWifiState(int wifiState)
protected boolean
startScan()
Does nothing and returns the configured success status.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
wasConfigurationSaved()
-
-
-
Method Detail
-
setWifiEnabled
@Implementation protected boolean setWifiEnabled(boolean wifiEnabled)
-
setWifiState
public void setWifiState(int wifiState)
-
isWifiEnabled
@Implementation protected boolean isWifiEnabled()
-
getWifiState
@Implementation protected int getWifiState()
-
getConnectionInfo
@Implementation protected WifiInfo getConnectionInfo()
-
is5GHzBandSupported
@Implementation(minSdk=21) protected boolean is5GHzBandSupported()
-
setIs5GHzBandSupported
public void setIs5GHzBandSupported(boolean is5GHzBandSupported)
Sets whether 5ghz band is supported.
-
isStaApConcurrencySupported
@Implementation(minSdk=30) protected boolean isStaApConcurrencySupported()
Returns last value provided to #setStaApConcurrencySupported.
-
setStaApConcurrencySupported
public void setStaApConcurrencySupported(boolean isStaApConcurrencySupported)
Sets whether STA/AP concurrency is supported.
-
setConnectionInfo
public void setConnectionInfo(WifiInfo wifiInfo)
Sets the connection info as the providedWifiInfo
.
-
setStartScanSucceeds
public void setStartScanSucceeds(boolean succeeds)
Sets the return value ofstartScan()
.
-
getScanResults
@Implementation protected List<ScanResult> getScanResults()
-
getConfiguredNetworks
@Implementation protected List<WifiConfiguration> getConfiguredNetworks()
-
getPrivilegedConfiguredNetworks
@Implementation(minSdk=21) protected List<WifiConfiguration> getPrivilegedConfiguredNetworks()
-
addNetwork
@Implementation protected int addNetwork(WifiConfiguration config)
-
removeNetwork
@Implementation protected boolean removeNetwork(int netId)
-
updateNetwork
@Implementation protected int updateNetwork(WifiConfiguration config)
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
@Implementation protected boolean saveConfiguration()
-
enableNetwork
@Implementation protected boolean enableNetwork(int netId, boolean attemptConnect)
-
disableNetwork
@Implementation protected boolean disableNetwork(int netId)
-
createWifiLock
@Implementation protected WifiManager.WifiLock createWifiLock(int lockType, String tag)
-
createWifiLock
@Implementation protected WifiManager.WifiLock createWifiLock(String tag)
-
createMulticastLock
@Implementation protected WifiManager.MulticastLock createMulticastLock(String tag)
-
calculateSignalLevel
@Implementation protected static int calculateSignalLevel(int rssi, int numLevels)
-
startScan
@Implementation protected boolean 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
@Implementation protected DhcpInfo getDhcpInfo()
-
isScanAlwaysAvailable
@Implementation(minSdk=18) protected boolean 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
@Implementation protected boolean 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
public void setScanResults(List<ScanResult> scanResults)
-
setDhcpInfo
public void setDhcpInfo(DhcpInfo dhcpInfo)
-
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
public WifiConfiguration getWifiConfiguration(int netId)
-
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
@Implementation protected boolean setWifiApConfiguration(WifiConfiguration apConfig)
-
getWifiApConfiguration
@Implementation protected WifiConfiguration getWifiApConfiguration()
-
getUsabilityScores
public List<ShadowWifiManager.WifiUsabilityScore> 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)
-
-