Package org.robolectric.shadows
Class ShadowWifiManager
java.lang.Object
org.robolectric.shadows.ShadowWifiManager
Shadow for 
WifiManager.- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classClass to record scores passed to WifiManager#updateWifiUsabilityScore
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaddLocalOnlyConnectionFailureListener(Executor executor, WifiManager.LocalOnlyConnectionFailureListener listener) protected intaddNetwork(WifiConfiguration config) protected WifiManager.AddNetworkResultThe new version ofaddNetwork(WifiConfiguration)which returns a more detailed failure codes.protected intaddNetworkSuggestions(List<WifiNetworkSuggestion> networkSuggestions) protected voidaddOnWifiUsabilityStatsListener(Executor executor, Object listener) protected static intcalculateSignalLevel(int rssi, int numLevels) protected voidvoidClears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)protected voidprotected voidconnect(int networkId, WifiManager.ActionListener listener) protected voidconnect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener) protected WifiManager.MulticastLockprotected WifiManager.WifiLockcreateWifiLock(int lockType, String tag) protected WifiManager.WifiLockcreateWifiLock(String tag) protected booleandisableNetwork(int netId) protected booleanenableNetwork(int netId, boolean attemptConnect) intReturns 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 WifiInfoprotected DhcpInfoprotected List<WifiNetworkSuggestion> protected List<WifiConfiguration> protected List<ScanResult> protected SoftApConfigurationReturns wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)protected WifiConfigurationgetWifiConfiguration(int netId) protected intprotected booleanbooleanisNetworkEnabled(int netId) Whether the network is enabled or not.protected booleanprotected booleanReturns last value provided tosetStaApConcurrencySupported(boolean).booleanReturns if wifi connected betwork scorer enabledprotected booleanprotected booleanReturns last value provided tosetWpa3SaeH2eSupported(boolean).protected booleanReturns last value provided tosetWpa3SaePublicKeySupported(boolean).protected booleanReturns last value provided tosetWpa3SaeSupported(boolean).protected booleanReturns last value provided tosetWpa3SuiteBSupported(boolean).voidnetworksFoundFromPnoScan(List<ScanResult> scanResults) Informs theWifiManagerof a list of PNOScanResult.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 booleanprotected voidprotected booleanremoveNetwork(int netId) protected booleanRemoves all configured networks regardless of the app that created the network.protected voidremoveOnWifiUsabilityStatsListener(Object listener) protected booleanvoidsetAccessWifiStatePermission(boolean accessWifiStatePermission) voidThe WifiManager#addNetwork() method can fail for various reasons, e.g.voidsetAddNetworkSuggestionsResult(int result) Uses the given result as the return value forWifiManager.addNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>).voidsetChangeWifiStatePermission(boolean changeWifiStatePermission) voidsetConnectionInfo(WifiInfo wifiInfo) Sets the connection info as the providedWifiInfo.voidsetDhcpInfo(DhcpInfo dhcpInfo) voidprotected voidsetExternalPnoScanRequest(List<?> ssids, int[] frequencies, Executor executor, Object callback) voidsetIs5GHzBandSupported(boolean is5GHzBandSupported) Sets whether 5ghz band is supported.voidsetIsScanAlwaysAvailable(boolean isScanAlwaysAvailable) voidsetScanResults(List<ScanResult> scanResults) static voidsetSignalLevelInPercent(float level) protected booleansetSoftApConfiguration(SoftApConfiguration softApConfig) voidsetStaApConcurrencySupported(boolean isStaApConcurrencySupported) Sets whether STA/AP concurrency is supported.voidsetStartScanSucceeds(boolean succeeds) Sets the return value ofstartScan().voidsetUpdateNetworkPermission(int networkId, boolean hasPermission) Prevents a networkId from being updated using theupdateNetwork(WifiConfiguration)method.protected booleansetWifiApConfiguration(WifiConfiguration apConfig) protected booleansetWifiConnectedNetworkScorer(Executor executor, Object scorer) Implements setWifiConnectedNetworkScorer() with the generic Object input as WifiConnectedNetworkScorer is a hidden/System API.protected booleansetWifiEnabled(boolean wifiEnabled) voidsetWifiState(int wifiState) voidsetWpa3SaeH2eSupported(boolean isWpa3SaeH2eSupported) Sets whether WPA3 SAE Hash-to-Element is supported.voidsetWpa3SaePublicKeySupported(boolean isWpa3SaePublicKeySupported) Sets whether WPA3 SAE Public Key is supported.voidsetWpa3SaeSupported(boolean isWpa3SaeSupported) Sets whether WPA3-Personal SAE is supported.voidsetWpa3SuiteBSupported(boolean isWpa3SuiteBSupported) Sets whether WPA3-Enterprise Suite-B-192 is supported.protected booleanDoes nothing and returns the configured success status.voidtriggerLocalConnectionFailure(WifiNetworkSpecifier specifier, int failureReason) Simulates a connection failure for a specified local network connection.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) boolean
- 
Constructor Details- 
ShadowWifiManagerpublic ShadowWifiManager()
 
- 
- 
Method Details- 
triggerLocalConnectionFailureSimulates a connection failure for a specified local network connection.- Parameters:
- specifier- the- WifiNetworkSpecifierdescribing the local network connection attempt
- failureReason- the reason for the network connection failure. This should be one of the values specified in- WifiManager#STATUS_LOCAL_ONLY_CONNECTION_FAILURE_*
 
- 
setAddNetworkSuggestionsResultpublic void setAddNetworkSuggestionsResult(int result) Uses the given result as the return value forWifiManager.addNetworkSuggestions(java.util.List<android.net.wifi.WifiNetworkSuggestion>).
- 
addNetworkSuggestions@Implementation(minSdk=29) protected int addNetworkSuggestions(List<WifiNetworkSuggestion> networkSuggestions) 
- 
getNetworkSuggestions
- 
addLocalOnlyConnectionFailureListener@Implementation(minSdk=34) protected void addLocalOnlyConnectionFailureListener(Executor executor, WifiManager.LocalOnlyConnectionFailureListener listener) 
- 
removeLocalOnlyConnectionFailureListener@Implementation(minSdk=34) protected void removeLocalOnlyConnectionFailureListener(WifiManager.LocalOnlyConnectionFailureListener listener) 
- 
setWifiEnabled
- 
setWifiStatepublic void setWifiState(int wifiState) 
- 
isWifiEnabled
- 
getWifiState
- 
getConnectionInfo
- 
is5GHzBandSupported
- 
setIs5GHzBandSupportedpublic void setIs5GHzBandSupported(boolean is5GHzBandSupported) Sets whether 5ghz band is supported.
- 
isStaApConcurrencySupportedReturns last value provided tosetStaApConcurrencySupported(boolean).
- 
setStaApConcurrencySupportedpublic void setStaApConcurrencySupported(boolean isStaApConcurrencySupported) Sets whether STA/AP concurrency is supported.
- 
isWpa3SaeSupportedReturns last value provided tosetWpa3SaeSupported(boolean).
- 
setWpa3SaeSupportedpublic void setWpa3SaeSupported(boolean isWpa3SaeSupported) Sets whether WPA3-Personal SAE is supported.
- 
isWpa3SaePublicKeySupportedReturns last value provided tosetWpa3SaePublicKeySupported(boolean).
- 
setWpa3SaePublicKeySupportedpublic void setWpa3SaePublicKeySupported(boolean isWpa3SaePublicKeySupported) Sets whether WPA3 SAE Public Key is supported.
- 
isWpa3SaeH2eSupportedReturns last value provided tosetWpa3SaeH2eSupported(boolean).
- 
setWpa3SaeH2eSupportedpublic void setWpa3SaeH2eSupported(boolean isWpa3SaeH2eSupported) Sets whether WPA3 SAE Hash-to-Element is supported.
- 
isWpa3SuiteBSupportedReturns last value provided tosetWpa3SuiteBSupported(boolean).
- 
setWpa3SuiteBSupportedpublic void setWpa3SuiteBSupported(boolean isWpa3SuiteBSupported) Sets whether WPA3-Enterprise Suite-B-192 is supported.
- 
setConnectionInfoSets the connection info as the providedWifiInfo.
- 
setStartScanSucceedspublic void setStartScanSucceeds(boolean succeeds) Sets the return value ofstartScan().
- 
setDoesCallerHavePermissionForGetPrivilegedConfiguredNetworkspublic void setDoesCallerHavePermissionForGetPrivilegedConfiguredNetworks(boolean value) 
- 
getScanResults
- 
getCallerConfiguredNetworksThe 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
- 
setAddNetworkFailurepublic void setAddNetworkFailure()The WifiManager#addNetwork() method can fail for various reasons, e.g. invalid network configuration, or third-party apps attempting to do this while targeting certain SDK levels (less than Q), or when it is disallowed by the user.
- 
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
- 
removeNonCallerConfiguredNetworksRemoves all configured networks regardless of the app that created the network. Can only be called by a Device Owner (DO) app.- Returns:
- trueif at least one network is removed,- falseotherwise
 
- 
updateNetworkAdds 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
- 
startScanDoes 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 protected void connect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener) 
- 
connect@HiddenApi @Implementation protected void connect(int networkId, WifiManager.ActionListener listener) 
- 
reconnect
- 
setSignalLevelInPercentpublic static void setSignalLevelInPercent(float level) 
- 
setAccessWifiStatePermissionpublic void setAccessWifiStatePermission(boolean accessWifiStatePermission) 
- 
setChangeWifiStatePermissionpublic void setChangeWifiStatePermission(boolean changeWifiStatePermission) 
- 
setUpdateNetworkPermissionpublic void setUpdateNetworkPermission(int networkId, boolean hasPermission) Prevents a networkId from being updated using theupdateNetwork(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
- 
isNetworkEnabledpublic boolean isNetworkEnabled(int netId) Whether the network is enabled or not.
- 
getActiveLockCountpublic int getActiveLockCount()Returns the number of WifiLocks and MulticastLocks that are currently acquired.
- 
wasConfigurationSavedpublic boolean wasConfigurationSaved()
- 
setIsScanAlwaysAvailablepublic void setIsScanAlwaysAvailable(boolean isScanAlwaysAvailable) 
- 
getWifiConfiguration
- 
addOnWifiUsabilityStatsListener@Implementation(minSdk=29) @HiddenApi protected void addOnWifiUsabilityStatsListener(Executor executor, Object listener) 
- 
removeOnWifiUsabilityStatsListener@Implementation(minSdk=29) @HiddenApi protected void removeOnWifiUsabilityStatsListener(Object listener) 
- 
updateWifiUsabilityScore@Implementation(minSdk=29) @HiddenApi protected void updateWifiUsabilityScore(int seqNum, int score, int predictionHorizonSec) 
- 
setWifiConnectedNetworkScorer@Implementation(minSdk=30) @HiddenApi protected boolean setWifiConnectedNetworkScorer(Executor executor, Object scorer) Implements setWifiConnectedNetworkScorer() with the generic Object input as WifiConnectedNetworkScorer is a hidden/System API.
- 
clearWifiConnectedNetworkScorer
- 
isWifiConnectedNetworkScorerEnabledpublic boolean isWifiConnectedNetworkScorerEnabled()Returns if wifi connected betwork scorer enabled
- 
setWifiApConfiguration
- 
getWifiApConfiguration
- 
setSoftApConfiguration@Implementation(minSdk=30) protected boolean setSoftApConfiguration(SoftApConfiguration softApConfig) 
- 
getSoftApConfiguration
- 
getUsabilityScoresReturns wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
- 
clearUsabilityScorespublic void clearUsabilityScores()Clears wifi usability scores previous passed toWifiManager.updateWifiUsabilityScore(int, int, int)
- 
postUsabilityStatspublic 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)
- 
networksFoundFromPnoScanInforms theWifiManagerof a list of PNOScanResult.
- 
setExternalPnoScanRequest@Implementation(minSdk=33) protected void setExternalPnoScanRequest(List<?> ssids, int[] frequencies, Executor executor, Object callback) 
- 
clearExternalPnoScanRequest
 
-