Package org.robolectric.shadows
Class ShadowConnectivityManager
- java.lang.Object
-
- org.robolectric.shadows.ShadowConnectivityManager
-
@Implements(android.net.ConnectivityManager.class) public class ShadowConnectivityManager extends Object
-
-
Constructor Summary
Constructors Constructor Description ShadowConnectivityManager()
-
Method Summary
-
-
-
Method Detail
-
getNetworkCallbacks
public Set<ConnectivityManager.NetworkCallback> getNetworkCallbacks()
-
getReportedNetworkConnectivity
public Map<Network,Boolean> getReportedNetworkConnectivity()
- Returns:
- networks and their connectivity status which was reported with
reportNetworkConnectivity(android.net.Network, boolean).
-
registerNetworkCallback
@Implementation(minSdk=21) protected void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
-
registerNetworkCallback
@Implementation(minSdk=26) protected void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler)
-
requestNetwork
@Implementation(minSdk=21) protected void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
-
requestNetwork
@Implementation(minSdk=26) protected void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, int timeoutMs)
-
requestNetwork
@Implementation(minSdk=26) protected void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler)
-
requestNetwork
@Implementation(minSdk=26) protected void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler, int timeoutMs)
-
registerDefaultNetworkCallback
@Implementation(minSdk=24) protected void registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
-
unregisterNetworkCallback
@Implementation(minSdk=21) protected void unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
-
getActiveNetworkInfo
@Implementation protected NetworkInfo getActiveNetworkInfo()
-
getActiveNetwork
@Implementation(minSdk=23) protected Network getActiveNetwork()
-
getAllNetworkInfo
@Implementation protected NetworkInfo[] getAllNetworkInfo()
-
getNetworkInfo
@Implementation protected NetworkInfo getNetworkInfo(int networkType)
-
getNetworkInfo
@Implementation(minSdk=21) protected NetworkInfo getNetworkInfo(Network network)
-
getAllNetworks
@Implementation(minSdk=21) protected Network[] getAllNetworks()
-
getBackgroundDataSetting
@Implementation protected boolean getBackgroundDataSetting()
-
setNetworkPreference
@Implementation protected void setNetworkPreference(int preference)
-
getNetworkPreference
@Implementation protected int getNetworkPreference()
-
isActiveNetworkMetered
@Implementation protected boolean isActiveNetworkMetered()
CountsConnectivityManager.TYPE_MOBILEnetworks as metered. Other types will be considered unmetered.- Returns:
- true if the active network is metered, otherwise false.
- See Also:
setActiveNetworkInfo(NetworkInfo),setDefaultNetworkActive(boolean)
-
bindProcessToNetwork
@Implementation(minSdk=23) protected boolean bindProcessToNetwork(Network network)
-
getBoundNetworkForProcess
@Implementation(minSdk=23) protected Network getBoundNetworkForProcess()
-
setNetworkInfo
public void setNetworkInfo(int networkType, NetworkInfo networkInfo)
-
getCaptivePortalServerUrl
@Implementation(minSdk=24) protected String getCaptivePortalServerUrl()
Returns the captive portal URL previously set withsetCaptivePortalServerUrl(java.lang.String).
-
setCaptivePortalServerUrl
public void setCaptivePortalServerUrl(String captivePortalServerUrl)
Sets the captive portal URL, which will be returned ingetCaptivePortalServerUrl().- Parameters:
captivePortalServerUrl- the url of captive portal.
-
setBackgroundDataSetting
@HiddenApi @Implementation public void setBackgroundDataSetting(boolean b)
-
setActiveNetworkInfo
public void setActiveNetworkInfo(NetworkInfo info)
-
addNetwork
public void addNetwork(Network network, NetworkInfo networkInfo)
Adds newnetworkto the list of allNetworks.- Parameters:
network- The network.networkInfo- The network info paired with theNetwork.
-
removeNetwork
public void removeNetwork(Network network)
Removes thenetworkfrom the list of allNetworks.- Parameters:
network- The network.
-
clearAllNetworks
public void clearAllNetworks()
Clears the list of allNetworks.
-
setDefaultNetworkActive
public void setDefaultNetworkActive(boolean isActive)
Sets the active state of the default network. By default this is true and affects the result ofConnectivityManager.isActiveNetworkMetered(),ConnectivityManager.isDefaultNetworkActive(),ConnectivityManager.getActiveNetwork()andConnectivityManager.getAllNetworkInfo(). Calling this method withtrueafter any listeners have been registered withConnectivityManager.addDefaultNetworkActiveListener(OnNetworkActiveListener)will result in those listeners being fired.- Parameters:
isActive- The active state of the default network.
-
isDefaultNetworkActive
@Implementation(minSdk=21) protected boolean isDefaultNetworkActive()
- Returns:
- true by default, or the value specifed via
setDefaultNetworkActive(boolean) - See Also:
setDefaultNetworkActive(boolean)
-
addDefaultNetworkActiveListener
@Implementation(minSdk=21) protected void addDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
-
removeDefaultNetworkActiveListener
@Implementation(minSdk=21) protected void removeDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
-
reportNetworkConnectivity
@Implementation(minSdk=23) protected void reportNetworkConnectivity(Network network, boolean hasConnectivity)
-
getNetworkCapabilities
@Implementation(minSdk=21) protected NetworkCapabilities getNetworkCapabilities(Network network)
Gets the network capabilities of a givenNetwork.- Parameters:
network- TheNetworkobject identifying the network in question.- Returns:
- The
NetworkCapabilitiesfor the network. - See Also:
setNetworkCapabilities(Network, NetworkCapabilities)
-
setNetworkCapabilities
public void setNetworkCapabilities(Network network, NetworkCapabilities networkCapabilities)
Sets network capability and affects the result ofConnectivityManager.getNetworkCapabilities(Network)- Parameters:
network- TheNetworkobject identifying the network in question.networkCapabilities- TheNetworkCapabilitiesfor the network.
-
setAirplaneMode
@Implementation(minSdk=19) protected void setAirplaneMode(boolean enable)
Sets the value for enabling/disabling airplane mode- Parameters:
enable- new status for airplane mode
-
getLinkProperties
@Implementation(minSdk=21) protected LinkProperties getLinkProperties(Network network)
-
setLinkProperties
public void setLinkProperties(Network network, LinkProperties linkProperties)
Sets the LinkProperties for the given Network.A LinkProperties can be constructed by
org.robolectric.util.ReflectionHelpers.callConstructorin tests.
-
getRestrictBackgroundStatus
@Implementation(minSdk=24) protected int getRestrictBackgroundStatus()
Gets the RESTRICT_BACKGROUND_STATUS value. Default value is 1 (RESTRICT_BACKGROUND_STATUS_DISABLED).
-
setRestrictBackgroundStatus
public void setRestrictBackgroundStatus(int status)
Sets the next return value forConnectivityManager.getRestrictBackgroundStatus().
-
setProxyForNetwork
public void setProxyForNetwork(Network network, ProxyInfo proxyInfo)
Sets a proxy for a givenNetwork.- Parameters:
network- The network.proxyInfo- The proxy info.
-
getProxyForNetwork
@Implementation(minSdk=23) protected ProxyInfo getProxyForNetwork(Network network)
Returns a proxy for a givenNetwork.In order
ConnectivityManager.getDefaultProxy()to work the default network should be set usingConnectivityManager.bindProcessToNetwork(Network).
-
-