public final class NetworkCapabilities extends Object implements Parcelable
ConnectivityManager
and when inspecting a network.
Note that this replaces the old ConnectivityManager.TYPE_MOBILE
method
of network selection. Rather than indicate a need for Wi-Fi because an application
needs high bandwidth and risk obsolescence when a new, fast network appears (like LTE),
the application should specify it needs high bandwidth. Similarly if an application
needs an unmetered network for a bulk transfer it can specify that rather than assuming
all cellular based connections are metered and all Wi-Fi based connections are not.Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<NetworkCapabilities> |
CREATOR |
static String |
MATCH_ALL_REQUESTS_NETWORK_SPECIFIER
Network specifier for factories which want to match any network specifier
(NS) in a request.
|
static int |
NET_CAPABILITY_CAPTIVE_PORTAL
Indicates that this network was found to have a captive portal in place last time it was
probed.
|
static int |
NET_CAPABILITY_CBS
Indicates this is a network that has the ability to reach the carrier's
CBS servers, used for carrier specific services.
|
static int |
NET_CAPABILITY_DUN
Indicates this is a network that has the ability to reach the carrier's
DUN or tethering gateway.
|
static int |
NET_CAPABILITY_EIMS
Indicates this is a network that has the ability to reach a carrier's
Emergency IMS servers or other services, used for network signaling
during emergency calls.
|
static int |
NET_CAPABILITY_FOREGROUND
Indicates that this network is available for use by apps, and not a network that is being
kept up in the background to facilitate fast network switching.
|
static int |
NET_CAPABILITY_FOTA
Indicates this is a network that has the ability to reach the carrier's
FOTA portal, used for over the air updates.
|
static int |
NET_CAPABILITY_IA
Indicates this is a network that has the ability to reach a carrier's
Initial Attach servers.
|
static int |
NET_CAPABILITY_IMS
Indicates this is a network that has the ability to reach the carrier's
IMS servers, used for network registration and signaling.
|
static int |
NET_CAPABILITY_INTERNET
Indicates that this network should be able to reach the internet.
|
static int |
NET_CAPABILITY_MMS
Indicates this is a network that has the ability to reach the
carrier's MMSC for sending and receiving MMS messages.
|
static int |
NET_CAPABILITY_NOT_METERED
Indicates that this network is unmetered.
|
static int |
NET_CAPABILITY_NOT_RESTRICTED
Indicates that this network is available for general use.
|
static int |
NET_CAPABILITY_NOT_VPN
Indicates that this network is not a VPN.
|
static int |
NET_CAPABILITY_RCS
Indicates this is a network that has the ability to reach a carrier's
RCS servers, used for Rich Communication Services.
|
static int |
NET_CAPABILITY_SUPL
Indicates this is a network that has the ability to reach the carrier's
SUPL server, used to retrieve GPS information.
|
static int |
NET_CAPABILITY_TRUSTED
Indicates that the user has indicated implicit trust of this network.
|
static int |
NET_CAPABILITY_VALIDATED
Indicates that connectivity on this network was successfully validated.
|
static int |
NET_CAPABILITY_WIFI_P2P
Indicates this is a network that has the ability to reach a Wi-Fi direct
peer.
|
static int |
NET_CAPABILITY_XCAP
Indicates this is a network that has the ability to reach a carrier's
XCAP servers, used for configuration and control.
|
static int |
SIGNAL_STRENGTH_UNSPECIFIED
Magic value that indicates no signal strength provided.
|
static int |
TRANSPORT_BLUETOOTH
Indicates this network uses a Bluetooth transport.
|
static int |
TRANSPORT_CELLULAR
Indicates this network uses a Cellular transport.
|
static int |
TRANSPORT_ETHERNET
Indicates this network uses an Ethernet transport.
|
static int |
TRANSPORT_VPN
Indicates this network uses a VPN transport.
|
static int |
TRANSPORT_WIFI
Indicates this network uses a Wi-Fi transport.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
NetworkCapabilities() |
NetworkCapabilities(NetworkCapabilities nc) |
Modifier and Type | Method and Description |
---|---|
NetworkCapabilities |
addCapability(int capability)
Adds the given capability to this
NetworkCapability instance. |
NetworkCapabilities |
addTransportType(int transportType)
Adds the given transport type to this
NetworkCapability instance. |
void |
clearAll()
Completely clears the contents of this object, removing even the capabilities that are set
by default when the object is constructed.
|
void |
combineCapabilities(NetworkCapabilities nc)
Combine a set of Capabilities to this one.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
String |
describeFirstNonRequestableCapability()
Convenience function that returns a human-readable description of the first mutable
capability we find.
|
boolean |
equalImmutableCapabilities(NetworkCapabilities nc)
Checks that our immutable capabilities are the same as those of the given
NetworkCapabilities . |
boolean |
equalRequestableCapabilities(NetworkCapabilities nc)
Checks that our requestable capabilities are the same as those of the given
NetworkCapabilities . |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
boolean |
equalsNetCapabilities(NetworkCapabilities nc) |
boolean |
equalsTransportTypes(NetworkCapabilities nc) |
int[] |
getCapabilities()
Gets all the capabilities set on this
NetworkCapability instance. |
int |
getLinkDownstreamBandwidthKbps()
Retrieves the downstream bandwidth for this network in Kbps.
|
int |
getLinkUpstreamBandwidthKbps()
Retrieves the upstream bandwidth for this network in Kbps.
|
String |
getNetworkSpecifier()
Gets the optional bearer specific network specifier.
|
int |
getSignalStrength()
Retrieves the signal strength.
|
int[] |
getTransportTypes()
Gets all the transports set on this
NetworkCapability instance. |
boolean |
hasCapability(int capability)
Tests for the presence of a capabilitity on this instance.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
hasSignalStrength()
Returns
true if this object specifies a signal strength. |
boolean |
hasTransport(int transportType)
Tests for the presence of a transport on this instance.
|
void |
maybeMarkCapabilitiesRestricted()
Removes the NET_CAPABILITY_NOT_RESTRICTED capability if all the capabilities it provides are
typically provided by restricted networks.
|
NetworkCapabilities |
removeCapability(int capability)
Removes (if found) the given capability from this
NetworkCapability instance. |
NetworkCapabilities |
removeTransportType(int transportType)
Removes (if found) the given transport from this
NetworkCapability instance. |
boolean |
satisfiedByImmutableNetworkCapabilities(NetworkCapabilities nc)
Check if our immutable requirements are satisfied by the given
NetworkCapabilities . |
boolean |
satisfiedByNetworkCapabilities(NetworkCapabilities nc)
Check if our requirements are satisfied by the given
NetworkCapabilities . |
void |
setLinkDownstreamBandwidthKbps(int downKbps)
Sets the downstream bandwidth for this network in Kbps.
|
void |
setLinkUpstreamBandwidthKbps(int upKbps)
Sets the upstream bandwidth for this network in Kbps.
|
NetworkCapabilities |
setNetworkSpecifier(String networkSpecifier)
Sets the optional bearer specific network specifier.
|
void |
setSignalStrength(int signalStrength)
Sets the signal strength.
|
String |
toString()
Returns a string representation of the object.
|
static String |
transportNamesOf(int[] types) |
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final int NET_CAPABILITY_MMS
public static final int NET_CAPABILITY_SUPL
public static final int NET_CAPABILITY_DUN
public static final int NET_CAPABILITY_FOTA
public static final int NET_CAPABILITY_IMS
public static final int NET_CAPABILITY_CBS
public static final int NET_CAPABILITY_WIFI_P2P
public static final int NET_CAPABILITY_IA
public static final int NET_CAPABILITY_RCS
public static final int NET_CAPABILITY_XCAP
public static final int NET_CAPABILITY_EIMS
public static final int NET_CAPABILITY_NOT_METERED
public static final int NET_CAPABILITY_INTERNET
public static final int NET_CAPABILITY_NOT_RESTRICTED
public static final int NET_CAPABILITY_TRUSTED
public static final int NET_CAPABILITY_NOT_VPN
public static final int NET_CAPABILITY_VALIDATED
public static final int NET_CAPABILITY_CAPTIVE_PORTAL
public static final int NET_CAPABILITY_FOREGROUND
public static final String MATCH_ALL_REQUESTS_NETWORK_SPECIFIER
public static final int TRANSPORT_CELLULAR
public static final int TRANSPORT_WIFI
public static final int TRANSPORT_BLUETOOTH
public static final int TRANSPORT_ETHERNET
public static final int TRANSPORT_VPN
public static final int SIGNAL_STRENGTH_UNSPECIFIED
public static final Parcelable.Creator<NetworkCapabilities> CREATOR
public NetworkCapabilities()
public NetworkCapabilities(NetworkCapabilities nc)
public void clearAll()
public NetworkCapabilities addCapability(int capability)
NetworkCapability
instance.
Multiple capabilities may be applied sequentially. Note that when searching
for a network to satisfy a request, all capabilities requested must be satisfied.capability
- the NetworkCapabilities.NET_CAPABILITY_*
to be added.public NetworkCapabilities removeCapability(int capability)
NetworkCapability
instance.capability
- the NetworkCapabilities.NET_CAPABILTIY_*
to be removed.public int[] getCapabilities()
NetworkCapability
instance.NetworkCapabilities.NET_CAPABILITY_*
values
for this instance.public boolean hasCapability(int capability)
capability
- the NetworkCapabilities.NET_CAPABILITY_*
to be tested for.true
if set on this instance.public String describeFirstNonRequestableCapability()
public boolean equalsNetCapabilities(NetworkCapabilities nc)
public void maybeMarkCapabilitiesRestricted()
public NetworkCapabilities addTransportType(int transportType)
NetworkCapability
instance.
Multiple transports may be applied sequentially. Note that when searching
for a network to satisfy a request, any listed in the request will satisfy the request.
For example TRANSPORT_WIFI
and TRANSPORT_ETHERNET
added to a
NetworkCapabilities
would cause either a Wi-Fi network or an Ethernet network
to be selected. This is logically different than
NetworkCapabilities.NET_CAPABILITY_*
listed above.transportType
- the NetworkCapabilities.TRANSPORT_*
to be added.public NetworkCapabilities removeTransportType(int transportType)
NetworkCapability
instance.transportType
- the NetworkCapabilities.TRANSPORT_*
to be removed.public int[] getTransportTypes()
NetworkCapability
instance.NetworkCapabilities.TRANSPORT_*
values
for this instance.public boolean hasTransport(int transportType)
transportType
- the NetworkCapabilities.TRANSPORT_*
to be tested for.true
if set on this instance.public boolean equalsTransportTypes(NetworkCapabilities nc)
public void setLinkUpstreamBandwidthKbps(int upKbps)
Note that when used to request a network, this specifies the minimum acceptable. When received as the state of an existing network this specifies the typical first hop bandwidth expected. This is never measured, but rather is inferred from technology type and other link parameters. It could be used to differentiate between very slow 1xRTT cellular links and other faster networks or even between 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between fast backhauls and slow backhauls.
upKbps
- the estimated first hop upstream (device to network) bandwidth.public int getLinkUpstreamBandwidthKbps()
public void setLinkDownstreamBandwidthKbps(int downKbps)
Note that when used to request a network, this specifies the minimum acceptable. When received as the state of an existing network this specifies the typical first hop bandwidth expected. This is never measured, but rather is inferred from technology type and other link parameters. It could be used to differentiate between very slow 1xRTT cellular links and other faster networks or even between 802.11b vs 802.11AC wifi technologies. It should not be used to differentiate between fast backhauls and slow backhauls.
downKbps
- the estimated first hop downstream (network to device) bandwidth.public int getLinkDownstreamBandwidthKbps()
public NetworkCapabilities setNetworkSpecifier(String networkSpecifier)
String
is bearer specific and bearers that use
it should document their particulars. For example, Bluetooth may use some sort of
device id while WiFi could used SSID and/or BSSID. Cellular may use carrier SPN (name)
or Subscription ID.networkSpecifier
- An String
of opaque format used to specify the bearer
specific network specifier where the bearer has a choice of
networks.public String getNetworkSpecifier()
String
specifying the bearer specific network specifier.
See setNetworkSpecifier(java.lang.String)
.public void setSignalStrength(int signalStrength)
Note that when used to register a network callback, this specifies the minimum acceptable signal strength. When received as the state of an existing network it specifies the current value. A value of code SIGNAL_STRENGTH_UNSPECIFIED} means no value when received and has no effect when requesting a callback.
signalStrength
- the bearer-specific signal strength.public boolean hasSignalStrength()
true
if this object specifies a signal strength.public int getSignalStrength()
public void combineCapabilities(NetworkCapabilities nc)
public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc)
NetworkCapabilities
.nc
- the NetworkCapabilities
that may or may not satisfy our requirements.public boolean satisfiedByImmutableNetworkCapabilities(NetworkCapabilities nc)
NetworkCapabilities
.nc
- the NetworkCapabilities
that may or may not satisfy our requirements.public boolean equalImmutableCapabilities(NetworkCapabilities nc)
NetworkCapabilities
.public boolean equalRequestableCapabilities(NetworkCapabilities nc)
NetworkCapabilities
.public boolean equals(Object obj)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public int hashCode()
Object
HashMap
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer, provided no information
used in equals
comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode
method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object
does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
JavaTM programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public static String transportNamesOf(int[] types)