@Implements(android.net.ConnectivityManager.class) public class ShadowConnectivityManager extends Object
Constructor | Description |
---|---|
ShadowConnectivityManager() |
public Set<ConnectivityManager.NetworkCallback> getNetworkCallbacks()
public Map<Network,Boolean> getReportedNetworkConnectivity()
reportNetworkConnectivity(android.net.Network, boolean)
.@Implementation(minSdk=21) protected void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
@Implementation(minSdk=26) protected void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, Handler handler)
@Implementation(minSdk=21) protected void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
@Implementation(minSdk=24) protected void registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
@Implementation(minSdk=21) protected void unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
@Implementation protected NetworkInfo getActiveNetworkInfo()
@Implementation(minSdk=23) protected Network getActiveNetwork()
@Implementation protected NetworkInfo[] getAllNetworkInfo()
@Implementation protected NetworkInfo getNetworkInfo(int networkType)
@Implementation(minSdk=21) protected NetworkInfo getNetworkInfo(Network network)
@Implementation(minSdk=21) protected Network[] getAllNetworks()
@Implementation protected boolean getBackgroundDataSetting()
@Implementation protected void setNetworkPreference(int preference)
@Implementation protected int getNetworkPreference()
@Implementation protected boolean isActiveNetworkMetered()
ConnectivityManager.TYPE_MOBILE
networks as metered. Other types will be
considered unmetered.setActiveNetworkInfo(NetworkInfo)
,
setDefaultNetworkActive(boolean)
@Implementation(minSdk=23) protected boolean bindProcessToNetwork(Network network)
@Implementation(minSdk=23) protected Network getBoundNetworkForProcess()
public void setNetworkInfo(int networkType, NetworkInfo networkInfo)
@Implementation(minSdk=24) protected String getCaptivePortalServerUrl()
setCaptivePortalServerUrl(java.lang.String)
.public void setCaptivePortalServerUrl(String captivePortalServerUrl)
getCaptivePortalServerUrl()
.captivePortalServerUrl
- the url of captive portal.@HiddenApi @Implementation public void setBackgroundDataSetting(boolean b)
public void setActiveNetworkInfo(NetworkInfo info)
public void addNetwork(Network network, NetworkInfo networkInfo)
network
to the list of all Network
s.network
- The network.networkInfo
- The network info paired with the Network
.public void removeNetwork(Network network)
network
from the list of all Network
s.network
- The network.public void clearAllNetworks()
Network
s.public void setDefaultNetworkActive(boolean isActive)
ConnectivityManager.isActiveNetworkMetered()
, ConnectivityManager.isDefaultNetworkActive()
, ConnectivityManager.getActiveNetwork()
and ConnectivityManager.getAllNetworkInfo()
.
Calling this method with true
after any listeners have been registered with ConnectivityManager.addDefaultNetworkActiveListener(OnNetworkActiveListener)
will result in
those listeners being fired.isActive
- The active state of the default network.@Implementation(minSdk=21) protected boolean isDefaultNetworkActive()
setDefaultNetworkActive(boolean)
setDefaultNetworkActive(boolean)
@Implementation(minSdk=21) protected void addDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
@Implementation(minSdk=21) protected void removeDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
@Implementation(minSdk=23) protected void reportNetworkConnectivity(Network network, boolean hasConnectivity)
@Implementation(minSdk=21) protected NetworkCapabilities getNetworkCapabilities(Network network)
Network
.network
- The Network
object identifying the network in question.NetworkCapabilities
for the network.setNetworkCapabilities(Network, NetworkCapabilities)
public void setNetworkCapabilities(Network network, NetworkCapabilities networkCapabilities)
ConnectivityManager.getNetworkCapabilities(Network)
network
- The Network
object identifying the network in question.networkCapabilities
- The NetworkCapabilities
for the network.@Implementation(minSdk=19) protected void setAirplaneMode(boolean enable)
enable
- new status for airplane mode@Implementation(minSdk=21) protected LinkProperties getLinkProperties(Network network)
public void setLinkProperties(Network network, LinkProperties linkProperties)
A LinkProperties can be constructed by
org.robolectric.util.ReflectionHelpers.callConstructor
in tests.
@Implementation(minSdk=24) protected int getRestrictBackgroundStatus()
public void setRestrictBackgroundStatus(int status)
ConnectivityManager.getRestrictBackgroundStatus()
.public void setProxyForNetwork(Network network, ProxyInfo proxyInfo)
Network
.network
- The network.proxyInfo
- The proxy info.@Implementation(minSdk=23) protected ProxyInfo getProxyForNetwork(Network network)
Network
.
In order ConnectivityManager.getDefaultProxy()
to work the default network should be
set using ConnectivityManager.bindProcessToNetwork(Network)
.