@Implements(value=android.net.ConnectivityManager.class) public class ShadowConnectivityManager extends java.lang.Object
Constructor and Description |
---|
ShadowConnectivityManager() |
Modifier and Type | Method and Description |
---|---|
protected void |
addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener l) |
void |
addNetwork(android.net.Network network,
android.net.NetworkInfo networkInfo)
Adds new
network to the list of all Network s. |
protected boolean |
bindProcessToNetwork(android.net.Network network) |
void |
clearAllNetworks()
Clears the list of all
Network s. |
protected android.net.Network |
getActiveNetwork() |
protected android.net.NetworkInfo |
getActiveNetworkInfo() |
protected android.net.NetworkInfo[] |
getAllNetworkInfo() |
protected android.net.Network[] |
getAllNetworks() |
protected boolean |
getBackgroundDataSetting() |
protected android.net.Network |
getBoundNetworkForProcess() |
protected java.lang.String |
getCaptivePortalServerUrl()
Returns the captive portal URL previously set with
setCaptivePortalServerUrl(java.lang.String) . |
protected android.net.LinkProperties |
getLinkProperties(android.net.Network network) |
java.util.Set<android.net.ConnectivityManager.NetworkCallback> |
getNetworkCallbacks() |
protected android.net.NetworkCapabilities |
getNetworkCapabilities(android.net.Network network)
Gets the network capabilities of a given
Network . |
protected android.net.NetworkInfo |
getNetworkInfo(int networkType) |
protected android.net.NetworkInfo |
getNetworkInfo(android.net.Network network) |
protected int |
getNetworkPreference() |
java.util.Map<android.net.Network,java.lang.Boolean> |
getReportedNetworkConnectivity() |
protected boolean |
isActiveNetworkMetered()
Counts
ConnectivityManager.TYPE_MOBILE networks as metered. |
protected boolean |
isDefaultNetworkActive() |
protected void |
registerNetworkCallback(android.net.NetworkRequest request,
android.net.ConnectivityManager.NetworkCallback networkCallback) |
protected void |
registerNetworkCallback(android.net.NetworkRequest request,
android.net.ConnectivityManager.NetworkCallback networkCallback,
android.os.Handler handler) |
protected void |
removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener l) |
void |
removeNetwork(android.net.Network network)
Removes the
network from the list of all Network s. |
protected void |
reportNetworkConnectivity(android.net.Network network,
boolean hasConnectivity) |
protected void |
requestNetwork(android.net.NetworkRequest request,
android.net.ConnectivityManager.NetworkCallback networkCallback) |
void |
setActiveNetworkInfo(android.net.NetworkInfo info) |
protected void |
setAirplaneMode(boolean enable)
Sets the value for enabling/disabling airplane mode
|
void |
setBackgroundDataSetting(boolean b) |
void |
setCaptivePortalServerUrl(java.lang.String captivePortalServerUrl)
Sets the captive portal URL, which will be returned in
getCaptivePortalServerUrl() . |
void |
setDefaultNetworkActive(boolean isActive)
Sets the active state of the default network.
|
void |
setLinkProperties(android.net.Network network,
android.net.LinkProperties linkProperties)
Sets the LinkProperties for the given Network.
|
void |
setNetworkCapabilities(android.net.Network network,
android.net.NetworkCapabilities networkCapabilities)
Sets network capability and affects the result of
ConnectivityManager.getNetworkCapabilities(Network) |
void |
setNetworkInfo(int networkType,
android.net.NetworkInfo networkInfo) |
protected void |
setNetworkPreference(int preference) |
protected void |
unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback networkCallback) |
public java.util.Set<android.net.ConnectivityManager.NetworkCallback> getNetworkCallbacks()
public java.util.Map<android.net.Network,java.lang.Boolean> getReportedNetworkConnectivity()
reportNetworkConnectivity(android.net.Network, boolean)
.@Implementation(minSdk=21) protected void registerNetworkCallback(android.net.NetworkRequest request, android.net.ConnectivityManager.NetworkCallback networkCallback)
@Implementation(minSdk=26) protected void registerNetworkCallback(android.net.NetworkRequest request, android.net.ConnectivityManager.NetworkCallback networkCallback, android.os.Handler handler)
@Implementation(minSdk=21) protected void requestNetwork(android.net.NetworkRequest request, android.net.ConnectivityManager.NetworkCallback networkCallback)
@Implementation(minSdk=21) protected void unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback networkCallback)
@Implementation protected android.net.NetworkInfo getActiveNetworkInfo()
@Implementation(minSdk=23) protected android.net.Network getActiveNetwork()
@Implementation protected android.net.NetworkInfo[] getAllNetworkInfo()
@Implementation protected android.net.NetworkInfo getNetworkInfo(int networkType)
@Implementation(minSdk=21) protected android.net.NetworkInfo getNetworkInfo(android.net.Network network)
@Implementation(minSdk=21) protected android.net.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(android.net.Network network)
@Implementation(minSdk=23) protected android.net.Network getBoundNetworkForProcess()
public void setNetworkInfo(int networkType, android.net.NetworkInfo networkInfo)
@Implementation(minSdk=24) protected java.lang.String getCaptivePortalServerUrl()
Returns the captive portal URL previously set with setCaptivePortalServerUrl(java.lang.String)
.
public void setCaptivePortalServerUrl(java.lang.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(android.net.NetworkInfo info)
public void addNetwork(android.net.Network network, android.net.NetworkInfo networkInfo)
Adds new network
to the list of all Network
s.
network
- The network.networkInfo
- The network info paired with the Network
.public void removeNetwork(android.net.Network network)
Removes the network
from the list of all Network
s.
network
- The network.public void clearAllNetworks()
Clears the list of all Network
s.
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(android.net.ConnectivityManager.OnNetworkActiveListener l)
@Implementation(minSdk=21) protected void removeDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener l)
@Implementation(minSdk=23) protected void reportNetworkConnectivity(android.net.Network network, boolean hasConnectivity)
@Implementation(minSdk=21) protected android.net.NetworkCapabilities getNetworkCapabilities(android.net.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(android.net.Network network, android.net.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 android.net.LinkProperties getLinkProperties(android.net.Network network)
public void setLinkProperties(android.net.Network network, android.net.LinkProperties linkProperties)
Sets the LinkProperties for the given Network.
A LinkProperties can be constructed by org.robolectric.util.ReflectionHelpers.callConstructor
in tests.