Fields Summary |
---|
private long | mNetworkCapabilitiesRepresents the network's capabilities. If any are specified they will be satisfied
by any Network that matches all of them. |
public static final int | NET_CAPABILITY_MMSIndicates this is a network that has the ability to reach the
carrier's MMSC for sending and receiving MMS messages. |
public static final int | NET_CAPABILITY_SUPLIndicates this is a network that has the ability to reach the carrier's
SUPL server, used to retrieve GPS information. |
public static final int | NET_CAPABILITY_DUNIndicates this is a network that has the ability to reach the carrier's
DUN or tethering gateway. |
public static final int | NET_CAPABILITY_FOTAIndicates this is a network that has the ability to reach the carrier's
FOTA portal, used for over the air updates. |
public static final int | NET_CAPABILITY_IMSIndicates this is a network that has the ability to reach the carrier's
IMS servers, used for network registration and signaling. |
public static final int | NET_CAPABILITY_CBSIndicates this is a network that has the ability to reach the carrier's
CBS servers, used for carrier specific services. |
public static final int | NET_CAPABILITY_WIFI_P2PIndicates this is a network that has the ability to reach a Wi-Fi direct
peer. |
public static final int | NET_CAPABILITY_IAIndicates this is a network that has the ability to reach a carrier's
Initial Attach servers. |
public static final int | NET_CAPABILITY_RCSIndicates this is a network that has the ability to reach a carrier's
RCS servers, used for Rich Communication Services. |
public static final int | NET_CAPABILITY_XCAPIndicates this is a network that has the ability to reach a carrier's
XCAP servers, used for configuration and control. |
public static final int | NET_CAPABILITY_EIMSIndicates this is a network that has the ability to reach a carrier's
Emergency IMS servers, used for network signaling during emergency calls. |
public static final int | NET_CAPABILITY_NOT_METEREDIndicates that this network is unmetered. |
public static final int | NET_CAPABILITY_INTERNETIndicates that this network should be able to reach the internet. |
public static final int | NET_CAPABILITY_NOT_RESTRICTEDIndicates that this network is available for general use. If this is not set
applications should not attempt to communicate on this network. Note that this
is simply informative and not enforcement - enforcement is handled via other means.
Set by default. |
public static final int | NET_CAPABILITY_TRUSTEDIndicates that the user has indicated implicit trust of this network. This
generally means it's a sim-selected carrier, a plugged in ethernet, a paired
BT device or a wifi the user asked to connect to. Untrusted networks
are probably limited to unknown wifi AP. Set by default. |
public static final int | NET_CAPABILITY_NOT_VPN |
public static final int | NET_CAPABILITY_VALIDATEDIndicates that connectivity on this network was successfully validated. For example, for a
network with NET_CAPABILITY_INTERNET, it means that Internet connectivity was successfully
detected. |
private static final int | MIN_NET_CAPABILITY |
private static final int | MAX_NET_CAPABILITY |
private long | mTransportTypesRepresenting the transport type. Apps should generally not care about transport. A
request for a fast internet connection could be satisfied by a number of different
transports. If any are specified here it will be satisfied a Network that matches
any of them. If a caller doesn't care about the transport it should not specify any. |
public static final int | TRANSPORT_CELLULARIndicates this network uses a Cellular transport. |
public static final int | TRANSPORT_WIFIIndicates this network uses a Wi-Fi transport. |
public static final int | TRANSPORT_BLUETOOTHIndicates this network uses a Bluetooth transport. |
public static final int | TRANSPORT_ETHERNETIndicates this network uses an Ethernet transport. |
public static final int | TRANSPORT_VPNIndicates this network uses a VPN transport. |
private static final int | MIN_TRANSPORT |
private static final int | MAX_TRANSPORT |
private int | mLinkUpBandwidthKbpsPassive link bandwidth. This is a rough guide of the expected peak bandwidth
for the first hop on the given transport. It is not measured, but may take into account
link parameters (Radio technology, allocated channels, etc). |
private int | mLinkDownBandwidthKbps |
private String | mNetworkSpecifier |
public static final Creator | CREATOR |
Methods Summary |
---|
public android.net.NetworkCapabilities | addCapability(int capability)Adds the given capability to this {@code 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.
if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
throw new IllegalArgumentException("NetworkCapability out of range");
}
mNetworkCapabilities |= 1 << capability;
return this;
|
public android.net.NetworkCapabilities | addTransportType(int transportType)Adds the given transport type to this {@code 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 {@code TRANSPORT_WIFI} and {@code TRANSPORT_ETHERNET} added to a
{@code NetworkCapabilities} would cause either a Wi-Fi network or an Ethernet network
to be selected. This is logically different than
{@code NetworkCapabilities.NET_CAPABILITY_*} listed above.
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
mTransportTypes |= 1 << transportType;
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
|
public void | combineCapabilities(android.net.NetworkCapabilities nc)Combine a set of Capabilities to this one. Useful for coming up with the complete set
{@hide}
combineNetCapabilities(nc);
combineTransportTypes(nc);
combineLinkBandwidths(nc);
combineSpecifiers(nc);
|
private void | combineLinkBandwidths(android.net.NetworkCapabilities nc)
this.mLinkUpBandwidthKbps =
Math.max(this.mLinkUpBandwidthKbps, nc.mLinkUpBandwidthKbps);
this.mLinkDownBandwidthKbps =
Math.max(this.mLinkDownBandwidthKbps, nc.mLinkDownBandwidthKbps);
|
private void | combineNetCapabilities(android.net.NetworkCapabilities nc)
this.mNetworkCapabilities |= nc.mNetworkCapabilities;
|
private void | combineSpecifiers(android.net.NetworkCapabilities nc)
String otherSpecifier = nc.getNetworkSpecifier();
if (TextUtils.isEmpty(otherSpecifier)) return;
if (TextUtils.isEmpty(mNetworkSpecifier) == false) {
throw new IllegalStateException("Can't combine two networkSpecifiers");
}
setNetworkSpecifier(otherSpecifier);
|
private void | combineTransportTypes(android.net.NetworkCapabilities nc)
this.mTransportTypes |= nc.mTransportTypes;
|
public int | describeContents()
return 0;
|
private int[] | enumerateBits(long val)
int size = Long.bitCount(val);
int[] result = new int[size];
int index = 0;
int resource = 0;
while (val > 0) {
if ((val & 1) == 1) result[index++] = resource;
val = val >> 1;
resource++;
}
return result;
|
public boolean | equals(java.lang.Object obj)
if (obj == null || (obj instanceof NetworkCapabilities == false)) return false;
NetworkCapabilities that = (NetworkCapabilities)obj;
return (equalsNetCapabilities(that) &&
equalsTransportTypes(that) &&
equalsLinkBandwidths(that) &&
equalsSpecifier(that));
|
private boolean | equalsLinkBandwidths(android.net.NetworkCapabilities nc)
return (this.mLinkUpBandwidthKbps == nc.mLinkUpBandwidthKbps &&
this.mLinkDownBandwidthKbps == nc.mLinkDownBandwidthKbps);
|
public boolean | equalsNetCapabilities(android.net.NetworkCapabilities nc)
return (nc.mNetworkCapabilities == this.mNetworkCapabilities);
|
private boolean | equalsSpecifier(android.net.NetworkCapabilities nc)
if (TextUtils.isEmpty(mNetworkSpecifier)) {
return TextUtils.isEmpty(nc.mNetworkSpecifier);
} else {
return mNetworkSpecifier.equals(nc.mNetworkSpecifier);
}
|
public boolean | equalsTransportTypes(android.net.NetworkCapabilities nc)
return (nc.mTransportTypes == this.mTransportTypes);
|
public int[] | getCapabilities()Gets all the capabilities set on this {@code NetworkCapability} instance.
return enumerateBits(mNetworkCapabilities);
|
public int | getLinkDownstreamBandwidthKbps()Retrieves the downstream bandwidth for this network in Kbps. This always only refers to
the estimated first hop transport bandwidth.
return mLinkDownBandwidthKbps;
|
public int | getLinkUpstreamBandwidthKbps()Retrieves the upstream bandwidth for this network in Kbps. This always only refers to
the estimated first hop transport bandwidth.
return mLinkUpBandwidthKbps;
|
public java.lang.String | getNetworkSpecifier()Gets the optional bearer specific network specifier.
return mNetworkSpecifier;
|
public int[] | getTransportTypes()Gets all the transports set on this {@code NetworkCapability} instance.
return enumerateBits(mTransportTypes);
|
public boolean | hasCapability(int capability)Tests for the presence of a capabilitity on this instance.
if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
return false;
}
return ((mNetworkCapabilities & (1 << capability)) != 0);
|
public boolean | hasTransport(int transportType)Tests for the presence of a transport on this instance.
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
return false;
}
return ((mTransportTypes & (1 << transportType)) != 0);
|
public int | hashCode()
return ((int)(mNetworkCapabilities & 0xFFFFFFFF) +
((int)(mNetworkCapabilities >> 32) * 3) +
((int)(mTransportTypes & 0xFFFFFFFF) * 5) +
((int)(mTransportTypes >> 32) * 7) +
(mLinkUpBandwidthKbps * 11) +
(mLinkDownBandwidthKbps * 13) +
(TextUtils.isEmpty(mNetworkSpecifier) ? 0 : mNetworkSpecifier.hashCode() * 17));
|
public android.net.NetworkCapabilities | removeCapability(int capability)Removes (if found) the given capability from this {@code NetworkCapability} instance.
if (capability < MIN_NET_CAPABILITY || capability > MAX_NET_CAPABILITY) {
throw new IllegalArgumentException("NetworkCapability out of range");
}
mNetworkCapabilities &= ~(1 << capability);
return this;
|
public android.net.NetworkCapabilities | removeTransportType(int transportType)Removes (if found) the given transport from this {@code NetworkCapability} instance.
if (transportType < MIN_TRANSPORT || transportType > MAX_TRANSPORT) {
throw new IllegalArgumentException("TransportType out of range");
}
mTransportTypes &= ~(1 << transportType);
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
return this;
|
private boolean | satisfiedByLinkBandwidths(android.net.NetworkCapabilities nc)
return !(this.mLinkUpBandwidthKbps > nc.mLinkUpBandwidthKbps ||
this.mLinkDownBandwidthKbps > nc.mLinkDownBandwidthKbps);
|
private boolean | satisfiedByNetCapabilities(android.net.NetworkCapabilities nc)
return ((nc.mNetworkCapabilities & this.mNetworkCapabilities) == this.mNetworkCapabilities);
|
public boolean | satisfiedByNetworkCapabilities(android.net.NetworkCapabilities nc)Check if our requirements are satisfied by the given Capabilities.
{@hide}
return (nc != null &&
satisfiedByNetCapabilities(nc) &&
satisfiedByTransportTypes(nc) &&
satisfiedByLinkBandwidths(nc) &&
satisfiedBySpecifier(nc));
|
private boolean | satisfiedBySpecifier(android.net.NetworkCapabilities nc)
return (TextUtils.isEmpty(mNetworkSpecifier) ||
mNetworkSpecifier.equals(nc.mNetworkSpecifier));
|
private boolean | satisfiedByTransportTypes(android.net.NetworkCapabilities nc)
return ((this.mTransportTypes == 0) ||
((this.mTransportTypes & nc.mTransportTypes) != 0));
|
public void | setLinkDownstreamBandwidthKbps(int downKbps)Sets the downstream bandwidth for this network in Kbps. This always only refers to
the estimated first hop transport bandwidth.
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.
mLinkDownBandwidthKbps = downKbps;
|
public void | setLinkUpstreamBandwidthKbps(int upKbps)Sets the upstream bandwidth for this network in Kbps. This always only refers to
the estimated first hop transport bandwidth.
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.
mLinkUpBandwidthKbps = upKbps;
|
public void | setNetworkSpecifier(java.lang.String networkSpecifier)Sets the optional bearer specific network specifier.
This has no meaning if a single transport is also not specified, so calling
this without a single transport set will generate an exception, as will
subsequently adding or removing transports after this is set.
The interpretation of this {@code 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.
if (TextUtils.isEmpty(networkSpecifier) == false && Long.bitCount(mTransportTypes) != 1) {
throw new IllegalStateException("Must have a single transport specified to use " +
"setNetworkSpecifier");
}
mNetworkSpecifier = networkSpecifier;
|
public java.lang.String | toString()
int[] types = getTransportTypes();
String transports = (types.length > 0 ? " Transports: " : "");
for (int i = 0; i < types.length;) {
switch (types[i]) {
case TRANSPORT_CELLULAR: transports += "CELLULAR"; break;
case TRANSPORT_WIFI: transports += "WIFI"; break;
case TRANSPORT_BLUETOOTH: transports += "BLUETOOTH"; break;
case TRANSPORT_ETHERNET: transports += "ETHERNET"; break;
case TRANSPORT_VPN: transports += "VPN"; break;
}
if (++i < types.length) transports += "|";
}
types = getCapabilities();
String capabilities = (types.length > 0 ? " Capabilities: " : "");
for (int i = 0; i < types.length; ) {
switch (types[i]) {
case NET_CAPABILITY_MMS: capabilities += "MMS"; break;
case NET_CAPABILITY_SUPL: capabilities += "SUPL"; break;
case NET_CAPABILITY_DUN: capabilities += "DUN"; break;
case NET_CAPABILITY_FOTA: capabilities += "FOTA"; break;
case NET_CAPABILITY_IMS: capabilities += "IMS"; break;
case NET_CAPABILITY_CBS: capabilities += "CBS"; break;
case NET_CAPABILITY_WIFI_P2P: capabilities += "WIFI_P2P"; break;
case NET_CAPABILITY_IA: capabilities += "IA"; break;
case NET_CAPABILITY_RCS: capabilities += "RCS"; break;
case NET_CAPABILITY_XCAP: capabilities += "XCAP"; break;
case NET_CAPABILITY_EIMS: capabilities += "EIMS"; break;
case NET_CAPABILITY_NOT_METERED: capabilities += "NOT_METERED"; break;
case NET_CAPABILITY_INTERNET: capabilities += "INTERNET"; break;
case NET_CAPABILITY_NOT_RESTRICTED: capabilities += "NOT_RESTRICTED"; break;
case NET_CAPABILITY_TRUSTED: capabilities += "TRUSTED"; break;
case NET_CAPABILITY_NOT_VPN: capabilities += "NOT_VPN"; break;
}
if (++i < types.length) capabilities += "&";
}
String upBand = ((mLinkUpBandwidthKbps > 0) ? " LinkUpBandwidth>=" +
mLinkUpBandwidthKbps + "Kbps" : "");
String dnBand = ((mLinkDownBandwidthKbps > 0) ? " LinkDnBandwidth>=" +
mLinkDownBandwidthKbps + "Kbps" : "");
String specifier = (mNetworkSpecifier == null ?
"" : " Specifier: <" + mNetworkSpecifier + ">");
return "[" + transports + capabilities + upBand + dnBand + specifier + "]";
|
public void | writeToParcel(android.os.Parcel dest, int flags)
dest.writeLong(mNetworkCapabilities);
dest.writeLong(mTransportTypes);
dest.writeInt(mLinkUpBandwidthKbps);
dest.writeInt(mLinkDownBandwidthKbps);
dest.writeString(mNetworkSpecifier);
|