public class ConnectivityManager extends Object
Context.getSystemService(Context.CONNECTIVITY_SERVICE)
.
The primary responsibilities of this class are to:
Modifier and Type | Class and Description |
---|---|
static class |
ConnectivityManager.NetworkCallback
Base class for NetworkRequest callbacks.
|
static interface |
ConnectivityManager.OnNetworkActiveListener
Callback for use with
addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener)
to find out when the system default network has gone in to a high power state. |
static class |
ConnectivityManager.OnStartTetheringCallback
Callback for use with
startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback) to find out whether tethering succeeded. |
class |
ConnectivityManager.PacketKeepalive
Allows applications to request that the system periodically send specific packets on their
behalf, using hardware offload to save battery power.
|
static class |
ConnectivityManager.PacketKeepaliveCallback |
static interface |
ConnectivityManager.RestrictBackgroundStatus |
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_BACKGROUND_DATA_SETTING_CHANGED
Deprecated.
As of
Build.VERSION_CODES.ICE_CREAM_SANDWICH , availability
of background data depends on several combined factors, and
this broadcast is no longer sent. Instead, when background
data is unavailable, getActiveNetworkInfo() will now
appear disconnected. During first boot after a platform
upgrade, this broadcast will be sent once if
getBackgroundDataSetting() was false before
the upgrade. |
static String |
ACTION_CAPTIVE_PORTAL_SIGN_IN
The device has connected to a network that has presented a captive
portal, which is blocking Internet connectivity.
|
static String |
ACTION_CAPTIVE_PORTAL_TEST_COMPLETED
Broadcast Action: The captive portal tracker has finished its test.
|
static String |
ACTION_DATA_ACTIVITY_CHANGE
Broadcast action to indicate the change of data activity status
(idle or active) on a network in a recent period.
|
static String |
ACTION_PROMPT_LOST_VALIDATION
Action used to display a dialog that asks the user whether to avoid a network that is no
longer validated.
|
static String |
ACTION_PROMPT_UNVALIDATED
Action used to display a dialog that asks the user whether to connect to a network that is
not validated.
|
static String |
ACTION_RESTRICT_BACKGROUND_CHANGED
A change in the background metered network activity restriction has occurred.
|
static String |
ACTION_TETHER_STATE_CHANGED
Broadcast Action: A tetherable connection has come or gone.
|
static int |
CALLBACK_AVAILABLE |
static int |
CALLBACK_CAP_CHANGED |
static int |
CALLBACK_EXIT |
static int |
CALLBACK_IP_CHANGED |
static int |
CALLBACK_LOSING |
static int |
CALLBACK_LOST |
static int |
CALLBACK_PRECHECK |
static int |
CALLBACK_RELEASED |
static int |
CALLBACK_RESUMED |
static int |
CALLBACK_SUSPENDED |
static int |
CALLBACK_UNAVAIL |
static String |
CONNECTIVITY_ACTION
A change in network connectivity has occurred.
|
static String |
CONNECTIVITY_ACTION_SUPL
A temporary hack until SUPL system can get off the legacy APIS.
|
static int |
DEFAULT_NETWORK_PREFERENCE
Deprecated.
Since we support so many more networks now, the single
network default network preference can't really express
the hierarchy. Instead, the default is defined by the
networkAttributes in config.xml. You can determine
the current value by calling
getNetworkPreference()
from an App. |
static String |
EXTRA_ACTIVE_TETHER |
static String |
EXTRA_ADD_TETHER_TYPE
Extra used for communicating with the TetherService.
|
static String |
EXTRA_AVAILABLE_TETHER |
static String |
EXTRA_CAPTIVE_PORTAL
The lookup key for a
CaptivePortal object included with the
ACTION_CAPTIVE_PORTAL_SIGN_IN intent. |
static String |
EXTRA_CAPTIVE_PORTAL_URL
Key for passing a URL to the captive portal login activity.
|
static String |
EXTRA_DEVICE_TYPE
The lookup key for an enum that indicates the network device type on which this data activity
change happens.
|
static String |
EXTRA_ERRORED_TETHER |
static String |
EXTRA_EXTRA_INFO
The lookup key for a string that provides optionally supplied
extra information about the network state.
|
static String |
EXTRA_INET_CONDITION
The lookup key for an int that provides information about
our connection to the internet at large. 0 indicates no connection,
100 indicates a great connection.
|
static String |
EXTRA_IS_ACTIVE
The lookup key for a boolean that indicates the device is active or not.
|
static String |
EXTRA_IS_CAPTIVE_PORTAL
The lookup key for a boolean that indicates whether a captive portal was detected.
|
static String |
EXTRA_IS_FAILOVER
The lookup key for a boolean that indicates whether a connect event
is for a network to which the connectivity manager was failing over
following a disconnect on another network.
|
static String |
EXTRA_NETWORK
The lookup key for a
Network object included with the intent after
successfully finding a network for the applications request. |
static String |
EXTRA_NETWORK_INFO
Deprecated.
Since
NetworkInfo can vary based on UID, applications
should always obtain network information through
getActiveNetworkInfo() . |
static String |
EXTRA_NETWORK_REQUEST
The lookup key for a
NetworkRequest object included with the intent after
successfully finding a network for the applications request. |
static String |
EXTRA_NETWORK_TYPE
Network type which triggered a
CONNECTIVITY_ACTION broadcast. |
static String |
EXTRA_NO_CONNECTIVITY
The lookup key for a boolean that indicates whether there is a
complete lack of connectivity, i.e., no network is available.
|
static String |
EXTRA_OTHER_NETWORK_INFO
The lookup key for a
NetworkInfo object. |
static String |
EXTRA_PROVISION_CALLBACK
Extra used for communicating with the TetherService.
|
static String |
EXTRA_REALTIME_NS
The lookup key for a long that contains the timestamp (nanos) of the radio state change.
|
static String |
EXTRA_REASON
The lookup key for a string that indicates why an attempt to connect
to a network failed.
|
static String |
EXTRA_REM_TETHER_TYPE
Extra used for communicating with the TetherService.
|
static String |
EXTRA_RUN_PROVISION
Tells the TetherService to run a provision check now.
|
static String |
EXTRA_SET_ALARM
Extra used for communicating with the TetherService.
|
static String |
INET_CONDITION_ACTION
Broadcast Action: The network connection may not be good
uses
ConnectivityManager.EXTRA_INET_CONDITION and
ConnectivityManager.EXTRA_NETWORK_INFO to specify
the network and it's condition. |
static int |
MAX_NETWORK_REQUEST_TIMEOUT_MS
The maximum number of milliseconds the framework will look for a suitable network
during a timeout-equiped call to
requestNetwork . |
static int |
MAX_NETWORK_TYPE |
static int |
MAX_RADIO_TYPE |
static int |
NETID_UNSET
A NetID indicating no Network is selected.
|
static int |
REQUEST_ID_UNSET |
static int |
RESTRICT_BACKGROUND_STATUS_DISABLED
Device is not restricting metered network activity while application is running on
background.
|
static int |
RESTRICT_BACKGROUND_STATUS_ENABLED
Device is restricting metered network activity while application is running on background.
|
static int |
RESTRICT_BACKGROUND_STATUS_WHITELISTED
Device is restricting metered network activity while application is running on background,
but application is allowed to bypass it.
|
static int |
TETHER_ERROR_DISABLE_NAT_ERROR |
static int |
TETHER_ERROR_ENABLE_NAT_ERROR |
static int |
TETHER_ERROR_IFACE_CFG_ERROR |
static int |
TETHER_ERROR_MASTER_ERROR |
static int |
TETHER_ERROR_NO_ERROR |
static int |
TETHER_ERROR_PROVISION_FAILED |
static int |
TETHER_ERROR_SERVICE_UNAVAIL |
static int |
TETHER_ERROR_TETHER_IFACE_ERROR |
static int |
TETHER_ERROR_UNAVAIL_IFACE |
static int |
TETHER_ERROR_UNKNOWN_IFACE |
static int |
TETHER_ERROR_UNSUPPORTED |
static int |
TETHER_ERROR_UNTETHER_IFACE_ERROR |
static int |
TETHERING_BLUETOOTH
Bluetooth tethering type.
|
static int |
TETHERING_INVALID
Invalid tethering type.
|
static int |
TETHERING_USB
USB tethering type.
|
static int |
TETHERING_WIFI
Wifi tethering type.
|
static int |
TYPE_BLUETOOTH
The Bluetooth data connection.
|
static int |
TYPE_DUMMY
Dummy data connection.
|
static int |
TYPE_ETHERNET
The Ethernet data connection.
|
static int |
TYPE_MOBILE
The Mobile data connection.
|
static int |
TYPE_MOBILE_CBS
Carrier Branded Services.
|
static int |
TYPE_MOBILE_DUN
A DUN-specific Mobile data connection.
|
static int |
TYPE_MOBILE_EMERGENCY
Emergency PDN connection for emergency services.
|
static int |
TYPE_MOBILE_FOTA
Over the air Administration.
|
static int |
TYPE_MOBILE_HIPRI
Deprecated.
Applications should instead use
requestNetwork(NetworkRequest, NetworkCallback) to request a network that
uses the NetworkCapabilities.TRANSPORT_CELLULAR transport. |
static int |
TYPE_MOBILE_IA
The network to use for initially attaching to the network
|
static int |
TYPE_MOBILE_IMS
IP Multimedia Subsystem.
|
static int |
TYPE_MOBILE_MMS
Deprecated.
Applications should instead use
requestNetwork(NetworkRequest, NetworkCallback) to request a network that
provides the NetworkCapabilities.NET_CAPABILITY_MMS capability. |
static int |
TYPE_MOBILE_SUPL
Deprecated.
Applications should instead use
requestNetwork(NetworkRequest, NetworkCallback) to request a network that
provides the NetworkCapabilities.NET_CAPABILITY_SUPL capability. |
static int |
TYPE_NONE
The absence of a connection type.
|
static int |
TYPE_PROXY
The network that uses proxy to achieve connectivity.
|
static int |
TYPE_VPN
A virtual network using one or more native bearers.
|
static int |
TYPE_WIFI
The WIFI data connection.
|
static int |
TYPE_WIFI_P2P
A Wi-Fi p2p connection.
|
static int |
TYPE_WIMAX
The WiMAX data connection.
|
Constructor and Description |
---|
ConnectivityManager(Context context,
IConnectivityManager service) |
Modifier and Type | Method and Description |
---|---|
void |
addDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
Start listening to reports when the system's default data network is active, meaning it is
a good time to perform network traffic.
|
boolean |
bindProcessToNetwork(Network network)
Binds the current process to
network . |
static boolean |
checkChangePermission(Context context) |
int |
checkMobileProvisioning(int suggestedTimeOutMs)
Check mobile provisioning.
|
static void |
enforceChangePermission(Context context) |
static void |
enforceTetherChangePermission(Context context)
{@hide
|
void |
factoryReset()
Resets all connectivity manager settings back to factory defaults.
|
static ConnectivityManager |
from(Context context) |
LinkProperties |
getActiveLinkProperties()
Returns the IP information for the current default network.
|
Network |
getActiveNetwork()
Returns a
Network object corresponding to the currently active
default data network. |
Network |
getActiveNetworkForUid(int uid)
Returns a
Network object corresponding to the currently active
default data network for a specific UID. |
Network |
getActiveNetworkForUid(int uid,
boolean ignoreBlocked) |
NetworkInfo |
getActiveNetworkInfo()
Returns details about the currently active default data network.
|
NetworkInfo |
getActiveNetworkInfoForUid(int uid)
Returns details about the currently active default data network
for a given uid.
|
NetworkInfo |
getActiveNetworkInfoForUid(int uid,
boolean ignoreBlocked) |
NetworkQuotaInfo |
getActiveNetworkQuotaInfo()
Return quota status for the current active network, or
null if no
network is active. |
NetworkInfo[] |
getAllNetworkInfo()
Deprecated.
This method does not support multiple connected networks
of the same type. Use
getAllNetworks() and
getNetworkInfo(android.net.Network) instead. |
Network[] |
getAllNetworks()
Returns an array of all
Network currently tracked by the
framework. |
String |
getAlwaysOnVpnPackageForUser(int userId)
Returns the package name of the currently set always-on VPN application.
|
boolean |
getBackgroundDataSetting()
Deprecated.
As of
Build.VERSION_CODES.ICE_CREAM_SANDWICH , availability of
background data depends on several combined factors, and this method will
always return true . Instead, when background data is unavailable,
getActiveNetworkInfo() will now appear disconnected. |
Network |
getBoundNetworkForProcess()
Returns the
Network currently bound to this process via
bindProcessToNetwork(android.net.Network) , or null if no Network is explicitly bound. |
String |
getCaptivePortalServerUrl()
Gets the URL that should be used for resolving whether a captive portal is present.
1.
|
NetworkCapabilities[] |
getDefaultNetworkCapabilitiesForUser(int userId)
Returns an array of
NetworkCapabilities objects, representing
the Networks that applications run by the given user will use by default. |
ProxyInfo |
getDefaultProxy()
Get the current default HTTP proxy settings.
|
ProxyInfo |
getGlobalProxy()
Retrieve any network-independent global HTTP proxy.
|
int |
getLastTetherError(String iface)
Get a more detailed error code after a Tethering or Untethering
request asynchronously failed.
|
LinkProperties |
getLinkProperties(int networkType)
Deprecated.
This method does not support multiple connected networks
of the same type. Use
getAllNetworks() ,
getNetworkInfo(android.net.Network) , and
getLinkProperties(android.net.Network) instead. |
LinkProperties |
getLinkProperties(Network network)
Get the
LinkProperties for the given Network . |
boolean |
getMobileDataEnabled()
Deprecated.
Talk to TelephonyManager directly
|
String |
getMobileProvisioningUrl()
Get the mobile provisioning url.
|
NetworkCapabilities |
getNetworkCapabilities(Network network)
Get the
NetworkCapabilities for the given Network . |
Network |
getNetworkForType(int networkType)
Deprecated.
This method does not support multiple connected networks
of the same type. Use
getAllNetworks() and
getNetworkInfo(android.net.Network) instead. |
NetworkInfo |
getNetworkInfo(int networkType)
Deprecated.
This method does not support multiple connected networks
of the same type. Use
getAllNetworks() and
getNetworkInfo(android.net.Network) instead. |
NetworkInfo |
getNetworkInfo(Network network)
Returns connection status information about a particular
Network.
|
NetworkInfo |
getNetworkInfoForUid(Network network,
int uid,
boolean ignoreBlocked) |
int |
getNetworkPreference()
Deprecated.
Functionality has been removed as it no longer makes sense,
with many more than two networks - we'd need an array to express
preference. Instead we use dynamic network properties of
the networks to describe their precedence.
|
static String |
getNetworkTypeName(int type)
Returns a non-localized string representing a given network type.
|
static Network |
getProcessDefaultNetwork()
Deprecated.
Using this function can lead to other functions throwing
IllegalStateException . Use getBoundNetworkForProcess() instead.
getBoundNetworkForProcess is a direct replacement. |
ProxyInfo |
getProxyForNetwork(Network network)
Retrieve the global HTTP proxy, or if no global HTTP proxy is set, a
network-specific HTTP proxy.
|
int |
getRestrictBackgroundStatus()
Determines if the calling application is subject to metered network restrictions while
running on background.
|
String[] |
getTetherableBluetoothRegexs()
Get the list of regular expressions that define any tetherable
Bluetooth network interfaces.
|
String[] |
getTetherableIfaces()
Get the set of tetherable, available interfaces.
|
String[] |
getTetherableUsbRegexs()
Get the list of regular expressions that define any tetherable
USB network interfaces.
|
String[] |
getTetherableWifiRegexs()
Get the list of regular expressions that define any tetherable
Wifi network interfaces.
|
String[] |
getTetheredDhcpRanges()
Get the set of tethered dhcp ranges.
|
String[] |
getTetheredIfaces()
Get the set of tethered interfaces.
|
String[] |
getTetheringErroredIfaces()
Get the set of interface names which attempted to tether but
failed.
|
boolean |
isActiveNetworkMetered()
Returns if the currently active data network is metered.
|
boolean |
isDefaultNetworkActive()
Return whether the data network is currently active.
|
boolean |
isNetworkSupported(int networkType)
Returns true if the hardware supports the given network type
else it returns false.
|
static boolean |
isNetworkTypeMobile(int networkType)
Checks if a given type uses the cellular data connection.
|
static boolean |
isNetworkTypeValid(int networkType)
Deprecated.
All APIs accepting a network type are deprecated. There should be no need to
validate a network type.
|
static boolean |
isNetworkTypeWifi(int networkType)
Checks if the given network type is backed by a Wi-Fi radio.
|
boolean |
isTetheringSupported()
Check if the device allows for tethering.
|
void |
registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
Registers to receive notifications about changes in the system default network.
|
int |
registerNetworkAgent(Messenger messenger,
NetworkInfo ni,
LinkProperties lp,
NetworkCapabilities nc,
int score,
NetworkMisc misc) |
void |
registerNetworkCallback(NetworkRequest request,
ConnectivityManager.NetworkCallback networkCallback)
Registers to receive notifications about all networks which satisfy the given
NetworkRequest . |
void |
registerNetworkCallback(NetworkRequest request,
PendingIntent operation)
Registers a PendingIntent to be sent when a network is available which satisfies the given
NetworkRequest . |
void |
registerNetworkFactory(Messenger messenger,
String name) |
void |
releaseNetworkRequest(PendingIntent operation)
Removes a request made via
requestNetwork(NetworkRequest, android.app.PendingIntent)
This method has the same behavior as
unregisterNetworkCallback(android.app.PendingIntent) with respect to
releasing network resources and disconnecting. |
void |
removeDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
Remove network active listener previously registered with
addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener) . |
void |
reportBadNetwork(Network network)
Deprecated.
Use
reportNetworkConnectivity(android.net.Network, boolean) which allows reporting both
working and non-working connectivity. |
void |
reportInetCondition(int networkType,
int percentage)
Report network connectivity status.
|
void |
reportNetworkConnectivity(Network network,
boolean hasConnectivity)
Report to the framework whether a network has working connectivity.
|
boolean |
requestBandwidthUpdate(Network network)
Requests bandwidth update for a given
Network and returns whether the update request
is accepted by ConnectivityService. |
void |
requestLinkProperties(ConnectivityManager.NetworkCallback networkCallback)
Request that this callback be invoked at ConnectivityService's earliest
convenience with the current satisfying network's LinkProperties.
|
void |
requestNetwork(NetworkRequest request,
ConnectivityManager.NetworkCallback networkCallback)
Request a network to satisfy a set of
NetworkCapabilities . |
void |
requestNetwork(NetworkRequest request,
ConnectivityManager.NetworkCallback networkCallback,
int timeoutMs)
Request a network to satisfy a set of
NetworkCapabilities , limited
by a timeout. |
void |
requestNetwork(NetworkRequest request,
ConnectivityManager.NetworkCallback networkCallback,
int timeoutMs,
int legacyType)
Helper function to request a network with a particular legacy type.
|
void |
requestNetwork(NetworkRequest request,
PendingIntent operation)
Request a network to satisfy a set of
NetworkCapabilities . |
void |
requestNetworkCapabilities(ConnectivityManager.NetworkCallback networkCallback)
Request that this callback be invoked at ConnectivityService's earliest
convenience with the current satisfying network's NetworkCapabilities.
|
boolean |
requestRouteToHost(int networkType,
int hostAddress)
Deprecated.
Deprecated in favor of the
requestNetwork(NetworkRequest, NetworkCallback) ,
bindProcessToNetwork(android.net.Network) and Network.getSocketFactory() API.
In Build.VERSION_CODES.M , and above, this method is unsupported and will
throw UnsupportedOperationException if called. |
boolean |
requestRouteToHostAddress(int networkType,
InetAddress hostAddress)
Deprecated.
Deprecated in favor of the
requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback, int, int) and
bindProcessToNetwork(android.net.Network) API. |
void |
setAcceptUnvalidated(Network network,
boolean accept,
boolean always)
Informs the system whether it should switch to
network regardless of whether it is
validated or not. |
void |
setAirplaneMode(boolean enable)
Set the value for enabling/disabling airplane mode
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL . |
boolean |
setAlwaysOnVpnPackageForUser(int userId,
String vpnPackage,
boolean lockdownEnabled)
Configures an always-on VPN connection through a specific application.
|
void |
setAvoidUnvalidated(Network network)
Informs the system to penalize
network 's score when it becomes unvalidated. |
void |
setBackgroundDataSetting(boolean allowBackgroundData)
Deprecated.
|
void |
setGlobalProxy(ProxyInfo p)
Set a network-independent global http proxy.
|
void |
setNetworkPreference(int preference)
Deprecated.
Functionality has been removed as it no longer makes sense,
with many more than two networks - we'd need an array to express
preference. Instead we use dynamic network properties of
the networks to describe their precedence.
|
static boolean |
setProcessDefaultNetwork(Network network)
Deprecated.
This function can throw
IllegalStateException . Use
bindProcessToNetwork(android.net.Network) instead. bindProcessToNetwork
is a direct replacement. |
static boolean |
setProcessDefaultNetworkForHostResolution(Network network)
Deprecated.
This is strictly for legacy usage to support
startUsingNetworkFeature(int, java.lang.String) . |
void |
setProvisioningNotificationVisible(boolean visible,
int networkType,
String action)
Deprecated.
Doesn't properly deal with multiple connected networks of the same type.
|
int |
setUsbTethering(boolean enable)
Attempt to both alter the mode of USB and Tethering of USB.
|
ConnectivityManager.PacketKeepalive |
startNattKeepalive(Network network,
int intervalSeconds,
ConnectivityManager.PacketKeepaliveCallback callback,
InetAddress srcAddr,
int srcPort,
InetAddress dstAddr)
Starts an IPsec NAT-T keepalive packet with the specified parameters.
|
void |
startTethering(int type,
boolean showProvisioningUi,
ConnectivityManager.OnStartTetheringCallback callback)
Convenient overload for
startTethering(int, boolean, OnStartTetheringCallback, Handler) which passes a null
handler to run on the current thread's Looper . |
void |
startTethering(int type,
boolean showProvisioningUi,
ConnectivityManager.OnStartTetheringCallback callback,
Handler handler)
Runs tether provisioning for the given type if needed and then starts tethering if
the check succeeds.
|
int |
startUsingNetworkFeature(int networkType,
String feature)
Deprecated.
Deprecated in favor of the cleaner
requestNetwork(NetworkRequest, NetworkCallback) API.
In Build.VERSION_CODES.M , and above, this method is unsupported and will
throw UnsupportedOperationException if called. |
void |
stopTethering(int type)
Stops tethering for the given type.
|
int |
stopUsingNetworkFeature(int networkType,
String feature)
Deprecated.
Deprecated in favor of the cleaner
unregisterNetworkCallback(NetworkCallback) API.
In Build.VERSION_CODES.M , and above, this method is unsupported and will
throw UnsupportedOperationException if called. |
int |
tether(String iface)
Attempt to tether the named interface.
|
void |
unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
Unregisters callbacks about and possibly releases networks originating from
requestNetwork(NetworkRequest, NetworkCallback) and
registerNetworkCallback(NetworkRequest, NetworkCallback) calls. |
void |
unregisterNetworkCallback(PendingIntent operation)
Unregisters a callback previously registered via
registerNetworkCallback(NetworkRequest, android.app.PendingIntent) . |
void |
unregisterNetworkFactory(Messenger messenger) |
int |
untether(String iface)
Stop tethering the named interface.
|
boolean |
updateLockdownVpn()
If the LockdownVpn mechanism is enabled, updates the vpn
with a reload of its profile.
|
public static final String CONNECTIVITY_ACTION
true
if there are no connected networks at all.public static final String CONNECTIVITY_ACTION_SUPL
public static final String ACTION_CAPTIVE_PORTAL_SIGN_IN
Network
typed extra called EXTRA_NETWORK
that represents
the network presenting the captive portal; all communication with the
captive portal must be done using this Network
object.
This activity includes a CaptivePortal
extra named
EXTRA_CAPTIVE_PORTAL
that can be used to indicate different
outcomes of the captive portal sign in to the system:
CaptivePortal.reportCaptivePortalDismissed()
so the system can
reevaluate the network. If reevaluation finds the network no longer
subject to a captive portal, the network may become the default active
data network. CaptivePortal.ignoreNetwork()
. @Deprecated public static final String EXTRA_NETWORK_INFO
NetworkInfo
can vary based on UID, applications
should always obtain network information through
getActiveNetworkInfo()
.NetworkInfo
object. Retrieve with
Intent.getParcelableExtra(String)
.EXTRA_NETWORK_TYPE
,
Constant Field Valuespublic static final String EXTRA_NETWORK_TYPE
CONNECTIVITY_ACTION
broadcast.public static final String EXTRA_IS_FAILOVER
Intent.getBooleanExtra(String,boolean)
.public static final String EXTRA_OTHER_NETWORK_INFO
NetworkInfo
object. This is supplied when
there is another network that it may be possible to connect to. Retrieve with
Intent.getParcelableExtra(String)
.public static final String EXTRA_NO_CONNECTIVITY
Intent.getBooleanExtra(String,boolean)
.public static final String EXTRA_REASON
Intent.getStringExtra(String)
.public static final String EXTRA_EXTRA_INFO
Intent.getStringExtra(String)
.public static final String EXTRA_INET_CONDITION
Intent.getIntExtra(String, int)
.
public static final String EXTRA_CAPTIVE_PORTAL
CaptivePortal
object included with the
ACTION_CAPTIVE_PORTAL_SIGN_IN
intent. The CaptivePortal
object can be used to either indicate to the system that the captive
portal has been dismissed or that the user does not want to pursue
signing in to captive portal. Retrieve it with
Intent.getParcelableExtra(String)
.public static final String EXTRA_CAPTIVE_PORTAL_URL
public static final String ACTION_DATA_ACTIVITY_CHANGE
public static final String EXTRA_DEVICE_TYPE
public static final String EXTRA_IS_ACTIVE
true
means
it is actively sending or receiving data and false
means it is idle.
public static final String EXTRA_REALTIME_NS
@Deprecated public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED
Build.VERSION_CODES.ICE_CREAM_SANDWICH
, availability
of background data depends on several combined factors, and
this broadcast is no longer sent. Instead, when background
data is unavailable, getActiveNetworkInfo()
will now
appear disconnected. During first boot after a platform
upgrade, this broadcast will be sent once if
getBackgroundDataSetting()
was false
before
the upgrade.getBackgroundDataSetting()
to get the current value.
If an application uses the network in the background, it should listen
for this broadcast and stop using the background data if the value is
false
.
public static final String INET_CONDITION_ACTION
ConnectivityManager.EXTRA_INET_CONDITION
and
ConnectivityManager.EXTRA_NETWORK_INFO
to specify
the network and it's condition.public static final String ACTION_TETHER_STATE_CHANGED
ConnectivityManager.EXTRA_AVAILABLE_TETHER
,
ConnectivityManager.EXTRA_ACTIVE_TETHER
and
ConnectivityManager.EXTRA_ERRORED_TETHER
to indicate
the current state of tethering. Each include a list of
interface names in that state (may be empty).public static final String EXTRA_AVAILABLE_TETHER
public static final String EXTRA_ACTIVE_TETHER
public static final String EXTRA_ERRORED_TETHER
public static final String ACTION_CAPTIVE_PORTAL_TEST_COMPLETED
public static final String EXTRA_IS_CAPTIVE_PORTAL
Intent.getBooleanExtra(String,boolean)
.public static final String ACTION_PROMPT_UNVALIDATED
public static final String ACTION_PROMPT_LOST_VALIDATION
public static final int TETHERING_INVALID
#startTethering(int, OnStartTetheringCallback, boolean)
,
Constant Field Valuespublic static final int TETHERING_WIFI
#startTethering(int, OnStartTetheringCallback, boolean)
,
Constant Field Valuespublic static final int TETHERING_USB
#startTethering(int, OnStartTetheringCallback, boolean)
,
Constant Field Valuespublic static final int TETHERING_BLUETOOTH
#startTethering(int, OnStartTetheringCallback, boolean)
,
Constant Field Valuespublic static final String EXTRA_ADD_TETHER_TYPE
public static final String EXTRA_REM_TETHER_TYPE
public static final String EXTRA_SET_ALARM
public static final String EXTRA_RUN_PROVISION
public static final String EXTRA_PROVISION_CALLBACK
ResultReceiver
which will receive provisioning results. Can be left empty.public static final int TYPE_NONE
public static final int TYPE_MOBILE
public static final int TYPE_WIFI
public static final int TYPE_MOBILE_MMS
requestNetwork(NetworkRequest, NetworkCallback)
to request a network that
provides the NetworkCapabilities.NET_CAPABILITY_MMS
capability.TYPE_MOBILE
or it may use a different
one. This is used by applications needing to talk to the carrier's
Multimedia Messaging Service servers.public static final int TYPE_MOBILE_SUPL
requestNetwork(NetworkRequest, NetworkCallback)
to request a network that
provides the NetworkCapabilities.NET_CAPABILITY_SUPL
capability.TYPE_MOBILE
or it may use a different
one. This is used by applications needing to talk to the carrier's
Secure User Plane Location servers for help locating the device.public static final int TYPE_MOBILE_DUN
TYPE_MOBILE
or it may use a different
one. This is sometimes by the system when setting up an upstream connection
for tethering so that the carrier is aware of DUN traffic.public static final int TYPE_MOBILE_HIPRI
requestNetwork(NetworkRequest, NetworkCallback)
to request a network that
uses the NetworkCapabilities.TRANSPORT_CELLULAR
transport.TYPE_MOBILE
but the routing setup
is different.public static final int TYPE_WIMAX
public static final int TYPE_BLUETOOTH
public static final int TYPE_DUMMY
public static final int TYPE_ETHERNET
public static final int TYPE_MOBILE_FOTA
public static final int TYPE_MOBILE_IMS
public static final int TYPE_MOBILE_CBS
public static final int TYPE_WIFI_P2P
public static final int TYPE_MOBILE_IA
public static final int TYPE_MOBILE_EMERGENCY
public static final int TYPE_PROXY
public static final int TYPE_VPN
public static final int MAX_RADIO_TYPE
public static final int MAX_NETWORK_TYPE
@Deprecated public static final int DEFAULT_NETWORK_PREFERENCE
getNetworkPreference()
from an App.public static final int REQUEST_ID_UNSET
public static final int NETID_UNSET
public static final int TETHER_ERROR_NO_ERROR
public static final int TETHER_ERROR_UNKNOWN_IFACE
public static final int TETHER_ERROR_SERVICE_UNAVAIL
public static final int TETHER_ERROR_UNSUPPORTED
public static final int TETHER_ERROR_UNAVAIL_IFACE
public static final int TETHER_ERROR_MASTER_ERROR
public static final int TETHER_ERROR_TETHER_IFACE_ERROR
public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR
public static final int TETHER_ERROR_ENABLE_NAT_ERROR
public static final int TETHER_ERROR_DISABLE_NAT_ERROR
public static final int TETHER_ERROR_IFACE_CFG_ERROR
public static final int TETHER_ERROR_PROVISION_FAILED
public static final int CALLBACK_PRECHECK
public static final int CALLBACK_AVAILABLE
public static final int CALLBACK_LOSING
public static final int CALLBACK_LOST
public static final int CALLBACK_UNAVAIL
public static final int CALLBACK_CAP_CHANGED
public static final int CALLBACK_IP_CHANGED
public static final int CALLBACK_RELEASED
public static final int CALLBACK_EXIT
public static final int CALLBACK_SUSPENDED
public static final int CALLBACK_RESUMED
public static final int MAX_NETWORK_REQUEST_TIMEOUT_MS
requestNetwork
.
public static final String EXTRA_NETWORK
Network
object included with the intent after
successfully finding a network for the applications request. Retrieve it with
Intent.getParcelableExtra(String)
.
Note that if you intend to invoke Network.openConnection(java.net.URL)
then you must get a ConnectivityManager instance before doing so.
public static final String EXTRA_NETWORK_REQUEST
NetworkRequest
object included with the intent after
successfully finding a network for the applications request. Retrieve it with
Intent.getParcelableExtra(String)
.public static final int RESTRICT_BACKGROUND_STATUS_DISABLED
public static final int RESTRICT_BACKGROUND_STATUS_WHITELISTED
In this state, application should take action to mitigate metered network access. For example, a music streaming application should switch to a low-bandwidth bitrate.
public static final int RESTRICT_BACKGROUND_STATUS_ENABLED
In this state, application should not try to use the network while running on background, because it would be denied.
public static final String ACTION_RESTRICT_BACKGROUND_CHANGED
Applications should call getRestrictBackgroundStatus()
to check if the restriction
applies to them.
This is only sent to registered receivers, not manifest receivers.
public ConnectivityManager(Context context, IConnectivityManager service)
public static boolean isNetworkTypeValid(int networkType)
networkType
- the type to be testedtrue
if the type is valid, else false
public static String getNetworkTypeName(int type)
type
- the type needing namingpublic static boolean isNetworkTypeMobile(int networkType)
networkType
- the type to checktrue
if uses cellular network, else false
public static boolean isNetworkTypeWifi(int networkType)
public void setNetworkPreference(int preference)
preference
- the network type to prefer over all others. It is
unspecified what happens to the old preferred network in the
overall ordering.public int getNetworkPreference()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public NetworkInfo getActiveNetworkInfo()
NetworkInfo.isConnected()
before initiating
network traffic. This may return null
when there is no default
network.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
NetworkInfo
object for the current default network
or null
if no default network is currently activepublic Network getActiveNetwork()
Network
object corresponding to the currently active
default data network. In the event that the current active default data
network disconnects, the returned Network
object will no longer
be usable. This will return null
when there is no default
network.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
Network
object for the current default network or
null
if no default network is currently activepublic Network getActiveNetworkForUid(int uid)
Network
object corresponding to the currently active
default data network for a specific UID. In the event that the default data
network disconnects, the returned Network
object will no longer
be usable. This will return null
when there is no default
network for the UID.
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL
.
Network
object for the current default network for the
given UID or null
if no default network is currently activepublic Network getActiveNetworkForUid(int uid, boolean ignoreBlocked)
public boolean setAlwaysOnVpnPackageForUser(int userId, String vpnPackage, boolean lockdownEnabled)
The designated package should declare a VpnService
in its
manifest guarded by android.Manifest.permission.BIND_VPN_SERVICE
,
otherwise the call will fail.
userId
- The identifier of the user to set an always-on VPN for.vpnPackage
- The package name for an installed VPN app on the device, or null
to remove an existing always-on VPN configuration.lockdownEnabled
- true
to disallow networking when the VPN is not connected or
false
otherwise.true
if the package is set as always-on VPN controller;
false
otherwise.public String getAlwaysOnVpnPackageForUser(int userId)
null
will be returned.null
if none is set.public NetworkInfo getActiveNetworkInfoForUid(int uid)
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL
NetworkInfo
object for the current default network
for the given uid or null
if no default network is
available for the specified uid.
public NetworkInfo getActiveNetworkInfoForUid(int uid, boolean ignoreBlocked)
public NetworkInfo getNetworkInfo(int networkType)
getAllNetworks()
and
getNetworkInfo(android.net.Network)
instead.This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
networkType
- integer specifying which networkType in
which you're interested.NetworkInfo
object for the requested
network type or null
if the type is not
supported by the device.public NetworkInfo getNetworkInfo(Network network)
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
network
- Network
specifying which network
in which you're interested.NetworkInfo
object for the requested
network or null
if the Network
is not valid.public NetworkInfo getNetworkInfoForUid(Network network, int uid, boolean ignoreBlocked)
public NetworkInfo[] getAllNetworkInfo()
getAllNetworks()
and
getNetworkInfo(android.net.Network)
instead.This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
NetworkInfo
objects. Check each
NetworkInfo.getType()
for which type each applies.public Network getNetworkForType(int networkType)
getAllNetworks()
and
getNetworkInfo(android.net.Network)
instead.Network
object currently serving a given type, or
null if the given type is not connected.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public Network[] getAllNetworks()
Network
currently tracked by the
framework.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
Network
objects.public NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(int userId)
NetworkCapabilities
objects, representing
the Networks that applications run by the given user will use by default.public LinkProperties getActiveLinkProperties()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
LinkProperties
object describing the IP info
for the current default network, or null
if there
is no current default network.
public LinkProperties getLinkProperties(int networkType)
getAllNetworks()
,
getNetworkInfo(android.net.Network)
, and
getLinkProperties(android.net.Network)
instead.This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
networkType
- the network type of interest.LinkProperties
object describing the IP info
for the given networkType, or null
if there is
no current default network.
public LinkProperties getLinkProperties(Network network)
LinkProperties
for the given Network
. This
will return null
if the network is unknown.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
network
- The Network
object identifying the network in question.LinkProperties
for the network, or null
.public void requestLinkProperties(ConnectivityManager.NetworkCallback networkCallback)
public NetworkCapabilities getNetworkCapabilities(Network network)
NetworkCapabilities
for the given Network
. This
will return null
if the network is unknown.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
network
- The Network
object identifying the network in question.NetworkCapabilities
for the network, or null
.public void requestNetworkCapabilities(ConnectivityManager.NetworkCallback networkCallback)
public String getCaptivePortalServerUrl()
public int startUsingNetworkFeature(int networkType, String feature)
requestNetwork(NetworkRequest, NetworkCallback)
API.
In Build.VERSION_CODES.M
, and above, this method is unsupported and will
throw UnsupportedOperationException
if called.feature
is completely up to each networking implementation.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
networkType
- specifies which network the request pertains tofeature
- the name of the feature to be used-1
always indicates failure.public int stopUsingNetworkFeature(int networkType, String feature)
unregisterNetworkCallback(NetworkCallback)
API.
In Build.VERSION_CODES.M
, and above, this method is unsupported and will
throw UnsupportedOperationException
if called.feature
is completely up to each networking implementation.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
networkType
- specifies which network the request pertains tofeature
- the name of the feature that is no longer needed-1
always indicates failure.public ConnectivityManager.PacketKeepalive startNattKeepalive(Network network, int intervalSeconds, ConnectivityManager.PacketKeepaliveCallback callback, InetAddress srcAddr, int srcPort, InetAddress dstAddr)
public boolean requestRouteToHost(int networkType, int hostAddress)
requestNetwork(NetworkRequest, NetworkCallback)
,
bindProcessToNetwork(android.net.Network)
and Network.getSocketFactory()
API.
In Build.VERSION_CODES.M
, and above, this method is unsupported and will
throw UnsupportedOperationException
if called.This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
networkType
- the type of the network over which traffic to the specified
host is to be routedhostAddress
- the IP address of the host to which the route is desiredtrue
on success, false
on failurepublic boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress)
requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback, int, int)
and
bindProcessToNetwork(android.net.Network)
API.This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
networkType
- the type of the network over which traffic to the specified
host is to be routedhostAddress
- the IP address of the host to which the route is desiredtrue
on success, false
on failure@Deprecated public boolean getBackgroundDataSetting()
Build.VERSION_CODES.ICE_CREAM_SANDWICH
, availability of
background data depends on several combined factors, and this method will
always return true
. Instead, when background data is unavailable,
getActiveNetworkInfo()
will now appear disconnected.
All applications that have background services that use the network
should listen to ACTION_BACKGROUND_DATA_SETTING_CHANGED
.
@Deprecated public void setBackgroundDataSetting(boolean allowBackgroundData)
allowBackgroundData
- Whether an application should use data while
it is in the background.getBackgroundDataSetting()
public NetworkQuotaInfo getActiveNetworkQuotaInfo()
null
if no
network is active. Quota status can change rapidly, so these values
shouldn't be cached.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public boolean getMobileDataEnabled()
public void addDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
isDefaultNetworkActive()
to determine the current state of the system's default network after registering the
listener.
If the process default network has been set with
bindProcessToNetwork(android.net.Network)
this function will not
reflect the process's default, but the system default.
l
- The listener to be told when the network is active.public void removeDefaultNetworkActiveListener(ConnectivityManager.OnNetworkActiveListener l)
addDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener)
.l
- Previously registered listener.public boolean isDefaultNetworkActive()
public static ConnectivityManager from(Context context)
public static final boolean checkChangePermission(Context context)
public static final void enforceChangePermission(Context context)
public static final void enforceTetherChangePermission(Context context)
public String[] getTetherableIfaces()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public String[] getTetheredIfaces()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public String[] getTetheringErroredIfaces()
getLastTetherError(java.lang.String)
can be used to get more
information on the cause of the errors.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public String[] getTetheredDhcpRanges()
String
of tethered dhcp ranges.
public int tether(String iface)
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
WARNING: New clients should not use this function. The only usages should be in PanService
and WifiStateMachine which need direct access. All other clients should use
startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback)
and stopTethering(int)
which encapsulate proper provisioning
logic.
iface
- the interface name to tether.TETHER_ERROR
value indicating success or failure type
public int untether(String iface)
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
WARNING: New clients should not use this function. The only usages should be in PanService
and WifiStateMachine which need direct access. All other clients should use
startTethering(int, boolean, android.net.ConnectivityManager.OnStartTetheringCallback)
and stopTethering(int)
which encapsulate proper provisioning
logic.
iface
- the interface name to untether.TETHER_ERROR
value indicating success or failure type
public boolean isTetheringSupported()
ro.tether.denied
system property, Settings.TETHER_SUPPORTED or
due to device configuration.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
true
indicating Tethering is supported.
public void startTethering(int type, boolean showProvisioningUi, ConnectivityManager.OnStartTetheringCallback callback)
startTethering(int, boolean, OnStartTetheringCallback, Handler)
which passes a null
handler to run on the current thread's Looper
.public void startTethering(int type, boolean showProvisioningUi, ConnectivityManager.OnStartTetheringCallback callback, Handler handler)
type
- The type of tethering to start. Must be one of
ConnectivityManager.TETHERING_WIFI
,
ConnectivityManager.TETHERING_USB
, or
ConnectivityManager.TETHERING_BLUETOOTH
.showProvisioningUi
- a boolean indicating to show the provisioning app UI if there
is one. This should be true the first time this function is called and also any time
the user can see this UI. It gives users information from their carrier about the
check failing and how they can sign up for tethering if possible.callback
- an ConnectivityManager.OnStartTetheringCallback
which will be called to notify the caller
of the result of trying to tether.handler
- Handler
to specify the thread upon which the callback will be invoked.public void stopTethering(int type)
type
- The type of tethering to stop. Must be one of
ConnectivityManager.TETHERING_WIFI
,
ConnectivityManager.TETHERING_USB
, or
ConnectivityManager.TETHERING_BLUETOOTH
.public String[] getTetherableUsbRegexs()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public String[] getTetherableWifiRegexs()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public String[] getTetherableBluetoothRegexs()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
public int setUsbTethering(boolean enable)
true
or turn off tethering and switch off
Rndis on false
.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
enable
- a boolean - true
to enable tetheringTETHER_ERROR
value indicating success or failure type
public int getLastTetherError(String iface)
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
iface
- The name of the interface of interestpublic void reportInetCondition(int networkType, int percentage)
This method requires the caller to hold the permission
android.Manifest.permission#STATUS_BAR
.
networkType
- The type of network you want to report onpercentage
- The quality of the connection 0 is bad, 100 is good
public void reportBadNetwork(Network network)
reportNetworkConnectivity(android.net.Network, boolean)
which allows reporting both
working and non-working connectivity.network
- The Network
the application was attempting to use
or null
to indicate the current default network.public void reportNetworkConnectivity(Network network, boolean hasConnectivity)
network
- The Network
the application was attempting to use
or null
to indicate the current default network.hasConnectivity
- true
if the application was able to successfully access the
Internet using network
or false
if not.public void setGlobalProxy(ProxyInfo p)
This method requires the caller to hold the permission android.Manifest.permission#CONNECTIVITY_INTERNAL.
p
- A ProxyInfo
object defining the new global
HTTP proxy. A null
value will clear the global HTTP proxy.public ProxyInfo getGlobalProxy()
ProxyInfo
for the current global HTTP proxy or null
if no global HTTP proxy is set.public ProxyInfo getProxyForNetwork(Network network)
network
is null, the
network-specific proxy returned is the proxy of the default active
network.ProxyInfo
for the current global HTTP proxy, or if no
global HTTP proxy is set, ProxyInfo
for network
,
or when network
is null
,
the ProxyInfo
for the default active network. Returns
null
when no proxy applies or the caller doesn't have
permission to use network
.public ProxyInfo getDefaultProxy()
Network
using
bindProcessToNetwork(android.net.Network)
then that Network
's proxy is returned, otherwise
the default network's proxy is returned.ProxyInfo
for the current HTTP proxy, or null
if no
HTTP proxy is active.public boolean isNetworkSupported(int networkType)
true
for mobile data, but a wifi only
tablet would return false
.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
networkType
- The network type we'd like to checktrue
if supported, else false
public boolean isActiveNetworkMetered()
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
true
if large transfers should be avoided, otherwise
false
.public boolean updateLockdownVpn()
This method can only be called by the system UID
public int checkMobileProvisioning(int suggestedTimeOutMs)
suggestedTimeOutMs,
- timeout in millisecondspublic String getMobileProvisioningUrl()
public void setProvisioningNotificationVisible(boolean visible, int networkType, String action)
visible
- networkType
- public void setAirplaneMode(boolean enable)
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL
.
enable
- whether to enable airplane mode or notpublic void unregisterNetworkFactory(Messenger messenger)
public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, NetworkCapabilities nc, int score, NetworkMisc misc)
public void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, int timeoutMs, int legacyType)
public void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
NetworkCapabilities
.
This NetworkRequest
will live until released via
unregisterNetworkCallback(NetworkCallback)
or the calling application exits.
Status of the request can be followed by listening to the various
callbacks described in ConnectivityManager.NetworkCallback
. The Network
can be used to direct traffic to the network.
It is presently unsupported to request a network with mutable
NetworkCapabilities
such as
NetworkCapabilities.NET_CAPABILITY_VALIDATED
or
NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL
as these NetworkCapabilities
represent states that a particular
network may never attain, and whether a network will attain these states
is unknown prior to bringing up the network so the framework does not
know how to go about satisfing a request with these capabilities.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
request
- NetworkRequest
describing this request.networkCallback
- The ConnectivityManager.NetworkCallback
to be utilized for this
request. Note the callback must not be shared - they
uniquely specify this request.IllegalArgumentException
- if request
specifies any mutable
NetworkCapabilities
.public void requestNetwork(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback, int timeoutMs)
NetworkCapabilities
, limited
by a timeout.
This function behaves identically to the non-timedout version, but if a suitable
network is not found within the given time (in milliseconds) the
NetworkCallback#unavailable
callback is called. The request must
still be released normally by calling unregisterNetworkCallback(NetworkCallback)
.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
request
- NetworkRequest
describing this request.networkCallback
- The callbacks to be utilized for this request. Note
the callbacks must not be shared - they uniquely specify
this request.timeoutMs
- The time in milliseconds to attempt looking for a suitable network
before NetworkCallback#unavailable
is called.
TODO: Make timeouts work and then unhide this method.public void requestNetwork(NetworkRequest request, PendingIntent operation)
NetworkCapabilities
.
This function behaves identically to the version that takes a NetworkCallback, but instead
of ConnectivityManager.NetworkCallback
a PendingIntent
is used. This means
the request may outlive the calling application and get called back when a suitable
network is found.
The operation is an Intent broadcast that goes to a broadcast receiver that
you registered with Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)
or through the
<receiver> tag in an AndroidManifest.xml file
The operation Intent is delivered with two extras, a Network
typed
extra called EXTRA_NETWORK
and a NetworkRequest
typed extra called EXTRA_NETWORK_REQUEST
containing
the original requests parameters. It is important to create a new,
ConnectivityManager.NetworkCallback
based request before completing the processing of the
Intent to reserve the network or it will be released shortly after the Intent
is processed.
If there is already a request for this Intent registered (with the equality of
two Intents defined by Intent.filterEquals(android.content.Intent)
), then it will be removed and
replaced by this one, effectively releasing the previous NetworkRequest
.
The request may be released normally by calling
releaseNetworkRequest(android.app.PendingIntent)
.
It is presently unsupported to request a network with either
NetworkCapabilities.NET_CAPABILITY_VALIDATED
or
NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL
as these NetworkCapabilities
represent states that a particular
network may never attain, and whether a network will attain these states
is unknown prior to bringing up the network so the framework does not
know how to go about satisfing a request with these capabilities.
This method requires the caller to hold either the
android.Manifest.permission#CHANGE_NETWORK_STATE
permission
or the ability to modify system settings as determined by
Settings.System.canWrite(android.content.Context)
.
request
- NetworkRequest
describing this request.operation
- Action to perform when the network is available (corresponds
to the ConnectivityManager.NetworkCallback.onAvailable(android.net.Network)
call. Typically
comes from PendingIntent.getBroadcast(android.content.Context, int, android.content.Intent, int)
. Cannot be null.IllegalArgumentException
- if request
contains either
NetworkCapabilities.NET_CAPABILITY_VALIDATED
or
NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL
.public void releaseNetworkRequest(PendingIntent operation)
requestNetwork(NetworkRequest, android.app.PendingIntent)
This method has the same behavior as
unregisterNetworkCallback(android.app.PendingIntent)
with respect to
releasing network resources and disconnecting.
operation
- A PendingIntent equal (as defined by Intent.filterEquals(android.content.Intent)
) to the
PendingIntent passed to
requestNetwork(NetworkRequest, android.app.PendingIntent)
with the
corresponding NetworkRequest you'd like to remove. Cannot be null.public void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
NetworkRequest
. The callbacks will continue to be called until
either the application exits or link #unregisterNetworkCallback(NetworkCallback)} is called.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
request
- NetworkRequest
describing this request.networkCallback
- The ConnectivityManager.NetworkCallback
that the system will call as suitable
networks change state.public void registerNetworkCallback(NetworkRequest request, PendingIntent operation)
NetworkRequest
.
This function behaves identically to the version that takes a NetworkCallback, but instead
of ConnectivityManager.NetworkCallback
a PendingIntent
is used. This means
the request may outlive the calling application and get called back when a suitable
network is found.
The operation is an Intent broadcast that goes to a broadcast receiver that
you registered with Context.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)
or through the
<receiver> tag in an AndroidManifest.xml file
The operation Intent is delivered with two extras, a Network
typed
extra called EXTRA_NETWORK
and a NetworkRequest
typed extra called EXTRA_NETWORK_REQUEST
containing
the original requests parameters.
If there is already a request for this Intent registered (with the equality of
two Intents defined by Intent.filterEquals(android.content.Intent)
), then it will be removed and
replaced by this one, effectively releasing the previous NetworkRequest
.
The request may be released normally by calling
unregisterNetworkCallback(android.app.PendingIntent)
.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
request
- NetworkRequest
describing this request.operation
- Action to perform when the network is available (corresponds
to the ConnectivityManager.NetworkCallback.onAvailable(android.net.Network)
call. Typically
comes from PendingIntent.getBroadcast(android.content.Context, int, android.content.Intent, int)
. Cannot be null.public void registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
unregisterNetworkCallback(NetworkCallback)
is called.
This method requires the caller to hold the permission
android.Manifest.permission#ACCESS_NETWORK_STATE
.
networkCallback
- The ConnectivityManager.NetworkCallback
that the system will call as the
system default network changes.public boolean requestBandwidthUpdate(Network network)
Network
and returns whether the update request
is accepted by ConnectivityService. Once accepted, ConnectivityService will poll underlying
network connection for updated bandwidth information. The caller will be notified via
ConnectivityManager.NetworkCallback
if there is an update. Notice that this
method assumes that the caller has previously called
registerNetworkCallback(NetworkRequest, NetworkCallback)
to listen for network
changes.public void unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
requestNetwork(NetworkRequest, NetworkCallback)
and
registerNetworkCallback(NetworkRequest, NetworkCallback)
calls.
If the given NetworkCallback
had previously been used with
#requestNetwork
, any networks that had been connected to only to satisfy that request
will be disconnected.networkCallback
- The ConnectivityManager.NetworkCallback
used when making the request.public void unregisterNetworkCallback(PendingIntent operation)
registerNetworkCallback(NetworkRequest, android.app.PendingIntent)
.operation
- A PendingIntent equal (as defined by Intent.filterEquals(android.content.Intent)
) to the
PendingIntent passed to
registerNetworkCallback(NetworkRequest, android.app.PendingIntent)
.
Cannot be null.public void setAcceptUnvalidated(Network network, boolean accept, boolean always)
network
regardless of whether it is
validated or not. If accept
is true, and the network was explicitly selected by the
user (e.g., by selecting a Wi-Fi network in the Settings app), then the network will become
the system default network regardless of any other network that's currently connected. If
always
is true, then the choice is remembered, so that the next time the user
connects to this network, the system will switch to it.
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL
network
- The network to accept.accept
- Whether to accept the network even if unvalidated.always
- Whether to remember this choice in the future.public void setAvoidUnvalidated(Network network)
network
's score when it becomes unvalidated. This is
only meaningful if the system is configured not to penalize such networks, e.g., if the
config_networkAvoidBadWifi
configuration variable is set to 0 and the NETWORK_AVOID_BAD_WIFI setting is unset
.
This method requires the caller to hold the permission
android.Manifest.permission#CONNECTIVITY_INTERNAL
network
- The network to accept.public void factoryReset()
public boolean bindProcessToNetwork(Network network)
network
. All Sockets created in the future
(and not explicitly bound via a bound SocketFactory from
Network.getSocketFactory()
) will be bound to
network
. All host name resolutions will be limited to network
as well.
Note that if network
ever disconnects, all Sockets created in this way will cease to
work and all host name resolutions will fail. This is by design so an application doesn't
accidentally use Sockets it thinks are still bound to a particular Network
.
To clear binding pass null
for network
. Using individually bound
Sockets created by Network.getSocketFactory().createSocket() and
performing network-specific host name resolutions via
Network.getAllByName
is preferred to calling
bindProcessToNetwork
.public static boolean setProcessDefaultNetwork(Network network)
IllegalStateException
. Use
bindProcessToNetwork(android.net.Network)
instead. bindProcessToNetwork
is a direct replacement.network
. All Sockets created in the future
(and not explicitly bound via a bound SocketFactory from
Network.getSocketFactory()
) will be bound to
network
. All host name resolutions will be limited to network
as well.
Note that if network
ever disconnects, all Sockets created in this way will cease to
work and all host name resolutions will fail. This is by design so an application doesn't
accidentally use Sockets it thinks are still bound to a particular Network
.
To clear binding pass null
for network
. Using individually bound
Sockets created by Network.getSocketFactory().createSocket() and
performing network-specific host name resolutions via
Network.getAllByName
is preferred to calling
setProcessDefaultNetwork
.public Network getBoundNetworkForProcess()
Network
currently bound to this process via
bindProcessToNetwork(android.net.Network)
, or null
if no Network
is explicitly bound.Network
to which this process is bound, or null
.public static Network getProcessDefaultNetwork()
IllegalStateException
. Use getBoundNetworkForProcess()
instead.
getBoundNetworkForProcess
is a direct replacement.Network
currently bound to this process via
bindProcessToNetwork(android.net.Network)
, or null
if no Network
is explicitly bound.Network
to which this process is bound, or null
.public static boolean setProcessDefaultNetworkForHostResolution(Network network)
startUsingNetworkFeature(int, java.lang.String)
.network
.
bindProcessToNetwork(android.net.Network)
takes precedence over this setting.public int getRestrictBackgroundStatus()