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
-
Constructor Details
-
ShadowConnectivityManager
public ShadowConnectivityManager()
-
-
Method Details
-
getNetworkCallbacks
-
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
-
getActiveNetwork
-
getAllNetworkInfo
-
getNetworkInfo
-
getNetworkInfo
-
getAllNetworks
-
getBackgroundDataSetting
-
setNetworkPreference
-
getNetworkPreference
-
isActiveNetworkMetered
CountsConnectivityManager.TYPE_MOBILE
networks 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
-
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 newnetwork
to the list of allNetwork
s.- Parameters:
network
- The network.networkInfo
- The network info paired with theNetwork
.
-
removeNetwork
Removes thenetwork
from the list of allNetwork
s.- Parameters:
network
- The network.
-
clearAllNetworks
public void clearAllNetworks()Clears the list of allNetwork
s. -
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 withtrue
after 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:
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
Gets the network capabilities of a givenNetwork
.- Parameters:
network
- TheNetwork
object identifying the network in question.- Returns:
- The
NetworkCapabilities
for the network. - See Also:
setNetworkCapabilities(Network, NetworkCapabilities)
-
setNetworkCapabilities
Sets network capability and affects the result ofConnectivityManager.getNetworkCapabilities(Network)
- Parameters:
network
- TheNetwork
object identifying the network in question.networkCapabilities
- TheNetworkCapabilities
for 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.callConstructor
in 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)
.
-