@Implements(value=android.net.ConnectivityManager.class) public class ShadowConnectivityManager extends Object
| Constructor and 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()
Counts ConnectivityManager.TYPE_MOBILE networks as metered. Other types will be considered unmetered.
true if the active network is metered, otherwise false.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()
Returns the captive portal URL previously set with setCaptivePortalServerUrl(java.lang.String).
public void setCaptivePortalServerUrl(String captivePortalServerUrl)
Sets the captive portal URL, which will be returned in 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)
Adds new network to the list of all Networks.
network - The network.networkInfo - The network info paired with the Network.public void removeNetwork(Network network)
Removes the network from the list of all Networks.
network - The network.public void clearAllNetworks()
Clears the list of all Networks.
public void setDefaultNetworkActive(boolean isActive)
Sets the active state of the default network.
By default this is true and affects the result of 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()
true by default, or the value specifed via 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)
Gets the network capabilities of a given Network.
network - The Network object identifying the network in question.NetworkCapabilities for the network.setNetworkCapabilities(Network, NetworkCapabilities)public void setNetworkCapabilities(Network network, NetworkCapabilities networkCapabilities)
Sets network capability and affects the result of 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)
Sets the value for enabling/disabling airplane mode
enable - new status for airplane mode@Implementation(minSdk=21) protected LinkProperties getLinkProperties(Network network)
public void setLinkProperties(Network network, LinkProperties linkProperties)
Sets the LinkProperties for the given Network.
A LinkProperties can be constructed by org.robolectric.util.ReflectionHelpers.callConstructor in tests.