Class ShadowWifiManager

java.lang.Object
org.robolectric.shadows.ShadowWifiManager

@Implements(android.net.wifi.WifiManager.class) public class ShadowWifiManager extends Object
Shadow for WifiManager.
  • Constructor Details

    • ShadowWifiManager

      public ShadowWifiManager()
  • Method Details

    • triggerLocalConnectionFailure

      public void triggerLocalConnectionFailure(WifiNetworkSpecifier specifier, int failureReason)
      Simulates a connection failure for a specified local network connection.
      Parameters:
      specifier - the WifiNetworkSpecifier describing 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_*
    • setAddNetworkSuggestionsResult

      public void setAddNetworkSuggestionsResult(int result)
    • addNetworkSuggestions

      @Implementation(minSdk=29) protected int addNetworkSuggestions(List<WifiNetworkSuggestion> networkSuggestions)
    • getNetworkSuggestions

      @Implementation(minSdk=30) protected List<WifiNetworkSuggestion> getNetworkSuggestions()
    • addLocalOnlyConnectionFailureListener

      @Implementation(minSdk=34) protected void addLocalOnlyConnectionFailureListener(Executor executor, WifiManager.LocalOnlyConnectionFailureListener listener)
    • removeLocalOnlyConnectionFailureListener

      @Implementation(minSdk=34) protected void removeLocalOnlyConnectionFailureListener(WifiManager.LocalOnlyConnectionFailureListener listener)
    • 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 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(boolean).
    • setStaApConcurrencySupported

      public void setStaApConcurrencySupported(boolean isStaApConcurrencySupported)
      Sets whether STA/AP concurrency is supported.
    • isWpa3SaeSupported

      @Implementation(minSdk=29) protected boolean isWpa3SaeSupported()
      Returns last value provided to setWpa3SaeSupported(boolean).
    • setWpa3SaeSupported

      public void setWpa3SaeSupported(boolean isWpa3SaeSupported)
      Sets whether WPA3-Personal SAE is supported.
    • isWpa3SaePublicKeySupported

      @Implementation(minSdk=31) protected boolean isWpa3SaePublicKeySupported()
      Returns last value provided to setWpa3SaePublicKeySupported(boolean).
    • setWpa3SaePublicKeySupported

      public void setWpa3SaePublicKeySupported(boolean isWpa3SaePublicKeySupported)
      Sets whether WPA3 SAE Public Key is supported.
    • isWpa3SaeH2eSupported

      @Implementation(minSdk=31) protected boolean isWpa3SaeH2eSupported()
      Returns last value provided to setWpa3SaeH2eSupported(boolean).
    • setWpa3SaeH2eSupported

      public void setWpa3SaeH2eSupported(boolean isWpa3SaeH2eSupported)
      Sets whether WPA3 SAE Hash-to-Element is supported.
    • isWpa3SuiteBSupported

      @Implementation(minSdk=29) protected boolean isWpa3SuiteBSupported()
      Returns last value provided to setWpa3SuiteBSupported(boolean).
    • setWpa3SuiteBSupported

      public void setWpa3SuiteBSupported(boolean isWpa3SuiteBSupported)
      Sets whether WPA3-Enterprise Suite-B-192 is supported.
    • setConnectionInfo

      public void setConnectionInfo(WifiInfo wifiInfo)
      Sets the connection info as the provided WifiInfo.
    • setStartScanSucceeds

      public void setStartScanSucceeds(boolean succeeds)
      Sets the return value of startScan().
    • setDoesCallerHavePermissionForGetPrivilegedConfiguredNetworks

      public void setDoesCallerHavePermissionForGetPrivilegedConfiguredNetworks(boolean value)
    • getScanResults

      @Implementation protected List<ScanResult> getScanResults()
    • getCallerConfiguredNetworks

      @Implementation(minSdk=31) protected List<WifiConfiguration> 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

      @Implementation protected List<WifiConfiguration> getConfiguredNetworks()
    • getPrivilegedConfiguredNetworks

      @Implementation protected List<WifiConfiguration> getPrivilegedConfiguredNetworks()
    • setAddNetworkFailure

      public 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

      @Implementation protected int addNetwork(WifiConfiguration config)
    • addNetworkPrivileged

      @Implementation(minSdk=31) protected WifiManager.AddNetworkResult addNetworkPrivileged(WifiConfiguration config)
      The new version of addNetwork(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

      @Implementation protected boolean removeNetwork(int netId)
    • removeNonCallerConfiguredNetworks

      @Implementation(minSdk=31) protected boolean 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

      @Implementation protected int updateNetwork(WifiConfiguration config)
      Adds or updates a network which can later be retrieved with getWifiConfiguration(int) method. A null , or one with a networkId less than 0, or a networkId that had its updatePermission removed using the setUpdateNetworkPermission(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 either true or false on Android 9+.

      Returns:
      the value configured by setStartScanSucceeds(boolean), or true if that method was never called.
    • getDhcpInfo

      @Implementation protected DhcpInfo getDhcpInfo()
    • isScanAlwaysAvailable

      @Implementation protected boolean isScanAlwaysAvailable()
    • connect

      @HiddenApi @Implementation protected void connect(WifiConfiguration wifiConfiguration, WifiManager.ActionListener listener)
    • connect

      @HiddenApi @Implementation 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)
    • setChangeWifiStatePermission

      public void setChangeWifiStatePermission(boolean changeWifiStatePermission)
    • setUpdateNetworkPermission

      public void setUpdateNetworkPermission(int networkId, boolean hasPermission)
      Prevents a networkId from being updated using the updateNetwork(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)
    • getLastEnabledNetwork

      public Pair<Integer,Boolean> 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

      public WifiConfiguration getWifiConfiguration(int netId)
    • 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

      @Implementation(minSdk=30) @HiddenApi protected void clearWifiConnectedNetworkScorer()
    • isWifiConnectedNetworkScorerEnabled

      public boolean isWifiConnectedNetworkScorerEnabled()
      Returns if wifi connected betwork scorer enabled
    • setWifiApConfiguration

      @Implementation protected boolean setWifiApConfiguration(WifiConfiguration apConfig)
    • getWifiApConfiguration

      @Implementation protected WifiConfiguration getWifiApConfiguration()
    • setSoftApConfiguration

      @Implementation(minSdk=30) protected boolean setSoftApConfiguration(SoftApConfiguration softApConfig)
    • getSoftApConfiguration

      @Implementation(minSdk=30) protected SoftApConfiguration getSoftApConfiguration()
    • getUsabilityScores

      public List<ShadowWifiManager.WifiUsabilityScore> getUsabilityScores()
      Returns wifi usability scores previous passed to WifiManager.updateWifiUsabilityScore(int, int, int)
    • clearUsabilityScores

      public void clearUsabilityScores()
      Clears wifi usability scores previous passed to WifiManager.updateWifiUsabilityScore(int, int, int)
    • postUsabilityStats

      public void postUsabilityStats(int seqNum, boolean isSameBssidAndFreq, WifiUsabilityStatsEntryBuilder statsBuilder)
    • networksFoundFromPnoScan

      public void networksFoundFromPnoScan(List<ScanResult> scanResults)
      Informs the WifiManager of a list of PNO ScanResult.
    • setExternalPnoScanRequest

      @Implementation(minSdk=33) protected void setExternalPnoScanRequest(List<?> ssids, int[] frequencies, Executor executor, Object callback)
    • clearExternalPnoScanRequest

      @Implementation(minSdk=33) @HiddenApi protected void clearExternalPnoScanRequest()