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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidaddNetwork(Network network, NetworkInfo networkInfo) Adds newnetworkto the list of allNetworks.protected booleanbindProcessToNetwork(Network network) voidClears the list of allNetworks.protected Networkprotected NetworkInfoprotected NetworkInfo[]protected Network[]protected booleanprotected Networkprotected StringReturns the captive portal URL previously set withsetCaptivePortalServerUrl(java.lang.String).protected LinkPropertiesgetLinkProperties(Network network) protected NetworkCapabilitiesgetNetworkCapabilities(Network network) Gets the network capabilities of a givenNetwork.protected NetworkInfogetNetworkInfo(int networkType) protected NetworkInfogetNetworkInfo(Network network) protected intprotected ProxyInfogetProxyForNetwork(Network network) Returns a proxy for a givenNetwork.protected intGets the RESTRICT_BACKGROUND_STATUS value.protected booleanCountsConnectivityManager.TYPE_MOBILEnetworks as metered.protected booleanprotected voidregisterBestMatchingNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) protected voidregisterDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback) protected voidregisterNetworkCallback(NetworkRequest request, PendingIntent pendingIntent) protected voidregisterNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback) protected voidregisterNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) protected voidvoidremoveNetwork(Network network) Removes thenetworkfrom the list of allNetworks.protected voidreportNetworkConnectivity(Network network, boolean hasConnectivity) protected voidrequestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback) protected voidrequestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, int timeoutMs) protected voidrequestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) protected voidrequestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler, int timeoutMs) voidprotected voidsetAirplaneMode(boolean enable) Sets the value for enabling/disabling airplane modevoidsetBackgroundDataSetting(boolean b) voidsetCaptivePortalServerUrl(String captivePortalServerUrl) Sets the captive portal URL, which will be returned ingetCaptivePortalServerUrl().voidsetDefaultNetworkActive(boolean isActive) Sets the active state of the default network.voidsetLinkProperties(Network network, LinkProperties linkProperties) Sets the LinkProperties for the given Network.voidsetNetworkCapabilities(Network network, NetworkCapabilities networkCapabilities) Sets network capability and affects the result ofConnectivityManager.getNetworkCapabilities(Network)voidsetNetworkInfo(int networkType, NetworkInfo networkInfo) protected voidsetNetworkPreference(int preference) voidsetProxyForNetwork(Network network, ProxyInfo proxyInfo) Sets a proxy for a givenNetwork.voidsetRestrictBackgroundStatus(int status) Sets the next return value forConnectivityManager.getRestrictBackgroundStatus().protected voidunregisterNetworkCallback(PendingIntent pendingIntent) protected voidunregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
-
Constructor Details
-
ShadowConnectivityManager
public ShadowConnectivityManager()
-
-
Method Details
-
getNetworkCallbacks
-
getNetworkCallbackPendingIntents
-
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) -
registerNetworkCallback
@Implementation(minSdk=23) protected void registerNetworkCallback(NetworkRequest request, PendingIntent pendingIntent) -
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) -
registerBestMatchingNetworkCallback
@Implementation(minSdk=31) protected void registerBestMatchingNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler) -
unregisterNetworkCallback
@Implementation(minSdk=21) protected void unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback) -
unregisterNetworkCallback
-
getActiveNetworkInfo
-
getActiveNetwork
-
getAllNetworkInfo
-
getNetworkInfo
-
getNetworkInfo
-
getAllNetworks
-
getBackgroundDataSetting
-
setNetworkPreference
-
getNetworkPreference
-
isActiveNetworkMetered
CountsConnectivityManager.TYPE_MOBILEnetworks as metered. Other types will be considered unmetered.- Returns:
- true if the active network is metered, otherwise false.
- See Also:
-
bindProcessToNetwork
-
getBoundNetworkForProcess
-
setNetworkInfo
-
getCaptivePortalServerUrl
Returns the captive portal URL previously set withsetCaptivePortalServerUrl(java.lang.String). -
setCaptivePortalServerUrl
Sets the captive portal URL, which will be returned ingetCaptivePortalServerUrl().- Parameters:
captivePortalServerUrl- the url of captive portal.
-
setBackgroundDataSetting
-
setActiveNetworkInfo
-
addNetwork
Adds newnetworkto the list of allNetworks.- Parameters:
network- The network.networkInfo- The network info paired with theNetwork.
-
removeNetwork
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
- Returns:
- true by default, or the value specifed via
setDefaultNetworkActive(boolean) - See Also:
-
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
Gets the network capabilities of a givenNetwork.- Parameters:
network- TheNetworkobject identifying the network in question.- Returns:
- The
NetworkCapabilitiesfor the network. - See Also:
-
setNetworkCapabilities
Sets network capability and affects the result ofConnectivityManager.getNetworkCapabilities(Network)- Parameters:
network- TheNetworkobject identifying the network in question.networkCapabilities- TheNetworkCapabilitiesfor the network.
-
setAirplaneMode
Sets the value for enabling/disabling airplane mode- Parameters:
enable- new status for airplane mode
-
getLinkProperties
-
setLinkProperties
Sets the LinkProperties for the given Network.A LinkProperties can be constructed by
org.robolectric.util.ReflectionHelpers.callConstructorin tests. -
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
Sets a proxy for a givenNetwork.- Parameters:
network- The network.proxyInfo- The proxy info.
-
getProxyForNetwork
Returns a proxy for a givenNetwork.In order
ConnectivityManager.getDefaultProxy()to work the default network should be set usingConnectivityManager.bindProcessToNetwork(Network).
-