Fix Automated API Review issues.

1. Some API's argument/return value must be marked either
@NonNull or @Nullable.
2. Change some system APIs to public APIs.
3. Modify the method name

Bug: 126700123
Bug: 126702339
Bug: 126699682
Bug: 118296575
Bug: 126699216
Bug: 126699675
Bug: 126699429
Bug: 126699193
Bug: 123586045
Test: atest FrameworksNetTests
Change-Id: Iaa2832cdcf83758ed0fec81b954a0c63bc5a7bf6
This commit is contained in:
paulhu
2019-03-08 16:35:20 +08:00
parent 6505a76d78
commit cbbc3db924
15 changed files with 347 additions and 266 deletions

View File

@@ -4088,7 +4088,7 @@ public class ConnectivityManager {
@SystemApi @SystemApi
@TestApi @TestApi
@RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) @RequiresPermission(NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK)
public void startCaptivePortalApp(Network network, Bundle appExtras) { public void startCaptivePortalApp(@NonNull Network network, @NonNull Bundle appExtras) {
try { try {
mService.startCaptivePortalAppInternal(network, appExtras); mService.startCaptivePortalAppInternal(network, appExtras);
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@@ -16,6 +16,7 @@
package android.net; package android.net;
import android.annotation.NonNull;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.os.Parcel; import android.os.Parcel;
@@ -70,7 +71,7 @@ public final class IpPrefix implements Parcelable {
* *
* @hide * @hide
*/ */
public IpPrefix(byte[] address, int prefixLength) { public IpPrefix(@NonNull byte[] address, int prefixLength) {
this.address = address.clone(); this.address = address.clone();
this.prefixLength = prefixLength; this.prefixLength = prefixLength;
checkAndMaskAddressAndPrefixLength(); checkAndMaskAddressAndPrefixLength();
@@ -87,7 +88,7 @@ public final class IpPrefix implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public IpPrefix(InetAddress address, int prefixLength) { public IpPrefix(@NonNull InetAddress address, int prefixLength) {
// We don't reuse the (byte[], int) constructor because it calls clone() on the byte array, // We don't reuse the (byte[], int) constructor because it calls clone() on the byte array,
// which is unnecessary because getAddress() already returns a clone. // which is unnecessary because getAddress() already returns a clone.
this.address = address.getAddress(); this.address = address.getAddress();
@@ -106,7 +107,7 @@ public final class IpPrefix implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public IpPrefix(String prefix) { public IpPrefix(@NonNull String prefix) {
// We don't reuse the (InetAddress, int) constructor because "error: call to this must be // We don't reuse the (InetAddress, int) constructor because "error: call to this must be
// first statement in constructor". We could factor out setting the member variables to an // first statement in constructor". We could factor out setting the member variables to an
// init() method, but if we did, then we'd have to make the members non-final, or "error: // init() method, but if we did, then we'd have to make the members non-final, or "error:

View File

@@ -26,6 +26,7 @@ import static android.system.OsConstants.RT_SCOPE_SITE;
import static android.system.OsConstants.RT_SCOPE_UNIVERSE; import static android.system.OsConstants.RT_SCOPE_UNIVERSE;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
@@ -107,8 +108,8 @@ public class LinkAddress implements Parcelable {
* *
* Per RFC 4193 section 8, fc00::/7 identifies these addresses. * Per RFC 4193 section 8, fc00::/7 identifies these addresses.
*/ */
private boolean isIPv6ULA() { private boolean isIpv6ULA() {
if (isIPv6()) { if (isIpv6()) {
byte[] bytes = address.getAddress(); byte[] bytes = address.getAddress();
return ((bytes[0] & (byte)0xfe) == (byte)0xfc); return ((bytes[0] & (byte)0xfe) == (byte)0xfc);
} }
@@ -121,17 +122,29 @@ public class LinkAddress implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isIPv6() { public boolean isIpv6() {
return address instanceof Inet6Address; return address instanceof Inet6Address;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return true if the address is IPv6.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean isIPv6() {
return isIpv6();
}
/** /**
* @return true if the address is IPv4 or is a mapped IPv4 address. * @return true if the address is IPv4 or is a mapped IPv4 address.
* @hide * @hide
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isIPv4() { public boolean isIpv4() {
return address instanceof Inet4Address; return address instanceof Inet4Address;
} }
@@ -217,7 +230,7 @@ public class LinkAddress implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public LinkAddress(String address, int flags, int scope) { public LinkAddress(@NonNull String address, int flags, int scope) {
// This may throw an IllegalArgumentException; catching it is the caller's responsibility. // This may throw an IllegalArgumentException; catching it is the caller's responsibility.
// TODO: consider rejecting mapped IPv4 addresses such as "::ffff:192.0.2.5/24". // TODO: consider rejecting mapped IPv4 addresses such as "::ffff:192.0.2.5/24".
Pair<InetAddress, Integer> ipAndMask = NetworkUtils.parseIpAndMask(address); Pair<InetAddress, Integer> ipAndMask = NetworkUtils.parseIpAndMask(address);
@@ -276,7 +289,10 @@ public class LinkAddress implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isSameAddressAs(LinkAddress other) { public boolean isSameAddressAs(@Nullable LinkAddress other) {
if (other == null) {
return false;
}
return address.equals(other.address) && prefixLength == other.prefixLength; return address.equals(other.address) && prefixLength == other.prefixLength;
} }
@@ -331,10 +347,10 @@ public class LinkAddress implements Parcelable {
* state has cleared either DAD has succeeded or failed, and both * state has cleared either DAD has succeeded or failed, and both
* flags are cleared regardless). * flags are cleared regardless).
*/ */
return (scope == RT_SCOPE_UNIVERSE && return (scope == RT_SCOPE_UNIVERSE
!isIPv6ULA() && && !isIpv6ULA()
(flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED)) == 0L && && (flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED)) == 0L
((flags & IFA_F_TENTATIVE) == 0L || (flags & IFA_F_OPTIMISTIC) != 0L)); && ((flags & IFA_F_TENTATIVE) == 0L || (flags & IFA_F_OPTIMISTIC) != 0L));
} }
/** /**

View File

@@ -54,11 +54,11 @@ public final class LinkProperties implements Parcelable {
// The interface described by the network link. // The interface described by the network link.
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
private String mIfaceName; private String mIfaceName;
private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>(); private final ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>();
private ArrayList<InetAddress> mDnses = new ArrayList<>(); private final ArrayList<InetAddress> mDnses = new ArrayList<>();
// PCSCF addresses are addresses of SIP proxies that only exist for the IMS core service. // PCSCF addresses are addresses of SIP proxies that only exist for the IMS core service.
private ArrayList<InetAddress> mPcscfs = new ArrayList<InetAddress>(); private final ArrayList<InetAddress> mPcscfs = new ArrayList<InetAddress>();
private ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>(); private final ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>();
private boolean mUsePrivateDns; private boolean mUsePrivateDns;
private String mPrivateDnsServerName; private String mPrivateDnsServerName;
private String mDomains; private String mDomains;
@@ -150,8 +150,8 @@ public final class LinkProperties implements Parcelable {
// connections getting stuck until timeouts fire and other // connections getting stuck until timeouts fire and other
// baffling failures. Therefore, loss of either IPv4 or IPv6 on a // baffling failures. Therefore, loss of either IPv4 or IPv6 on a
// previously dual-stack network is deemed a lost of provisioning. // previously dual-stack network is deemed a lost of provisioning.
if ((before.isIPv4Provisioned() && !after.isIPv4Provisioned()) || if ((before.isIpv4Provisioned() && !after.isIpv4Provisioned())
(before.isIPv6Provisioned() && !after.isIPv6Provisioned())) { || (before.isIpv6Provisioned() && !after.isIpv6Provisioned())) {
return ProvisioningChange.LOST_PROVISIONING; return ProvisioningChange.LOST_PROVISIONING;
} }
return ProvisioningChange.STILL_PROVISIONED; return ProvisioningChange.STILL_PROVISIONED;
@@ -165,9 +165,8 @@ public final class LinkProperties implements Parcelable {
} }
/** /**
* @hide * Constructs a new {@code LinkProperties} with default values.
*/ */
@SystemApi
public LinkProperties() { public LinkProperties() {
} }
@@ -176,7 +175,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public LinkProperties(LinkProperties source) { public LinkProperties(@Nullable LinkProperties source) {
if (source != null) { if (source != null) {
mIfaceName = source.mIfaceName; mIfaceName = source.mIfaceName;
mLinkAddresses.addAll(source.mLinkAddresses); mLinkAddresses.addAll(source.mLinkAddresses);
@@ -202,10 +201,8 @@ public final class LinkProperties implements Parcelable {
* will have their interface changed to match this new value. * will have their interface changed to match this new value.
* *
* @param iface The name of the network interface used for this link. * @param iface The name of the network interface used for this link.
* @hide
*/ */
@SystemApi public void setInterfaceName(@Nullable String iface) {
public void setInterfaceName(String iface) {
mIfaceName = iface; mIfaceName = iface;
ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size()); ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size());
for (RouteInfo route : mRoutes) { for (RouteInfo route : mRoutes) {
@@ -227,7 +224,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public List<String> getAllInterfaceNames() { public @NonNull List<String> getAllInterfaceNames() {
List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1); List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1);
if (mIfaceName != null) interfaceNames.add(mIfaceName); if (mIfaceName != null) interfaceNames.add(mIfaceName);
for (LinkProperties stacked: mStackedLinks.values()) { for (LinkProperties stacked: mStackedLinks.values()) {
@@ -247,8 +244,8 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public List<InetAddress> getAddresses() { public @NonNull List<InetAddress> getAddresses() {
List<InetAddress> addresses = new ArrayList<>(); final List<InetAddress> addresses = new ArrayList<>();
for (LinkAddress linkAddress : mLinkAddresses) { for (LinkAddress linkAddress : mLinkAddresses) {
addresses.add(linkAddress.getAddress()); addresses.add(linkAddress.getAddress());
} }
@@ -260,7 +257,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public List<InetAddress> getAllAddresses() { public @NonNull List<InetAddress> getAllAddresses() {
List<InetAddress> addresses = new ArrayList<>(); List<InetAddress> addresses = new ArrayList<>();
for (LinkAddress linkAddress : mLinkAddresses) { for (LinkAddress linkAddress : mLinkAddresses) {
addresses.add(linkAddress.getAddress()); addresses.add(linkAddress.getAddress());
@@ -289,7 +286,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public boolean addLinkAddress(LinkAddress address) { public boolean addLinkAddress(@NonNull LinkAddress address) {
if (address == null) { if (address == null) {
return false; return false;
} }
@@ -318,7 +315,10 @@ public final class LinkProperties implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public boolean removeLinkAddress(LinkAddress toRemove) { public boolean removeLinkAddress(@NonNull LinkAddress toRemove) {
if (toRemove == null) {
return false;
}
int i = findLinkAddressIndex(toRemove); int i = findLinkAddressIndex(toRemove);
if (i >= 0) { if (i >= 0) {
mLinkAddresses.remove(i); mLinkAddresses.remove(i);
@@ -333,7 +333,7 @@ public final class LinkProperties implements Parcelable {
* *
* @return An unmodifiable {@link List} of {@link LinkAddress} for this link. * @return An unmodifiable {@link List} of {@link LinkAddress} for this link.
*/ */
public List<LinkAddress> getLinkAddresses() { public @NonNull List<LinkAddress> getLinkAddresses() {
return Collections.unmodifiableList(mLinkAddresses); return Collections.unmodifiableList(mLinkAddresses);
} }
@@ -356,10 +356,8 @@ public final class LinkProperties implements Parcelable {
* *
* @param addresses The {@link Collection} of {@link LinkAddress} to set in this * @param addresses The {@link Collection} of {@link LinkAddress} to set in this
* object. * object.
* @hide
*/ */
@SystemApi public void setLinkAddresses(@NonNull Collection<LinkAddress> addresses) {
public void setLinkAddresses(Collection<LinkAddress> addresses) {
mLinkAddresses.clear(); mLinkAddresses.clear();
for (LinkAddress address: addresses) { for (LinkAddress address: addresses) {
addLinkAddress(address); addLinkAddress(address);
@@ -375,7 +373,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean addDnsServer(InetAddress dnsServer) { public boolean addDnsServer(@NonNull InetAddress dnsServer) {
if (dnsServer != null && !mDnses.contains(dnsServer)) { if (dnsServer != null && !mDnses.contains(dnsServer)) {
mDnses.add(dnsServer); mDnses.add(dnsServer);
return true; return true;
@@ -392,7 +390,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean removeDnsServer(InetAddress dnsServer) { public boolean removeDnsServer(@NonNull InetAddress dnsServer) {
if (dnsServer != null) { if (dnsServer != null) {
return mDnses.remove(dnsServer); return mDnses.remove(dnsServer);
} }
@@ -404,10 +402,8 @@ public final class LinkProperties implements Parcelable {
* the given {@link Collection} of {@link InetAddress} objects. * the given {@link Collection} of {@link InetAddress} objects.
* *
* @param dnsServers The {@link Collection} of DNS servers to set in this object. * @param dnsServers The {@link Collection} of DNS servers to set in this object.
* @hide
*/ */
@SystemApi public void setDnsServers(@NonNull Collection<InetAddress> dnsServers) {
public void setDnsServers(Collection<InetAddress> dnsServers) {
mDnses.clear(); mDnses.clear();
for (InetAddress dnsServer: dnsServers) { for (InetAddress dnsServer: dnsServers) {
addDnsServer(dnsServer); addDnsServer(dnsServer);
@@ -420,7 +416,7 @@ public final class LinkProperties implements Parcelable {
* @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on * @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on
* this link. * this link.
*/ */
public List<InetAddress> getDnsServers() { public @NonNull List<InetAddress> getDnsServers() {
return Collections.unmodifiableList(mDnses); return Collections.unmodifiableList(mDnses);
} }
@@ -490,7 +486,7 @@ public final class LinkProperties implements Parcelable {
* @return true if the DNS server was added, false if it was already present. * @return true if the DNS server was added, false if it was already present.
* @hide * @hide
*/ */
public boolean addValidatedPrivateDnsServer(InetAddress dnsServer) { public boolean addValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) {
if (dnsServer != null && !mValidatedPrivateDnses.contains(dnsServer)) { if (dnsServer != null && !mValidatedPrivateDnses.contains(dnsServer)) {
mValidatedPrivateDnses.add(dnsServer); mValidatedPrivateDnses.add(dnsServer);
return true; return true;
@@ -506,11 +502,8 @@ public final class LinkProperties implements Parcelable {
* @return true if the DNS server was removed, false if it did not exist. * @return true if the DNS server was removed, false if it did not exist.
* @hide * @hide
*/ */
public boolean removeValidatedPrivateDnsServer(InetAddress dnsServer) { public boolean removeValidatedPrivateDnsServer(@NonNull InetAddress dnsServer) {
if (dnsServer != null) { return mValidatedPrivateDnses.remove(dnsServer);
return mValidatedPrivateDnses.remove(dnsServer);
}
return false;
} }
/** /**
@@ -523,7 +516,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public void setValidatedPrivateDnsServers(Collection<InetAddress> dnsServers) { public void setValidatedPrivateDnsServers(@NonNull Collection<InetAddress> dnsServers) {
mValidatedPrivateDnses.clear(); mValidatedPrivateDnses.clear();
for (InetAddress dnsServer: dnsServers) { for (InetAddress dnsServer: dnsServers) {
addValidatedPrivateDnsServer(dnsServer); addValidatedPrivateDnsServer(dnsServer);
@@ -534,13 +527,13 @@ public final class LinkProperties implements Parcelable {
* Returns all the {@link InetAddress} for validated private DNS servers on this link. * Returns all the {@link InetAddress} for validated private DNS servers on this link.
* These are resolved from the private DNS server name. * These are resolved from the private DNS server name.
* *
* @return An umodifiable {@link List} of {@link InetAddress} for validated private * @return An unmodifiable {@link List} of {@link InetAddress} for validated private
* DNS servers on this link. * DNS servers on this link.
* @hide * @hide
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public List<InetAddress> getValidatedPrivateDnsServers() { public @NonNull List<InetAddress> getValidatedPrivateDnsServers() {
return Collections.unmodifiableList(mValidatedPrivateDnses); return Collections.unmodifiableList(mValidatedPrivateDnses);
} }
@@ -551,7 +544,7 @@ public final class LinkProperties implements Parcelable {
* @return true if the PCSCF server was added, false otherwise. * @return true if the PCSCF server was added, false otherwise.
* @hide * @hide
*/ */
public boolean addPcscfServer(InetAddress pcscfServer) { public boolean addPcscfServer(@NonNull InetAddress pcscfServer) {
if (pcscfServer != null && !mPcscfs.contains(pcscfServer)) { if (pcscfServer != null && !mPcscfs.contains(pcscfServer)) {
mPcscfs.add(pcscfServer); mPcscfs.add(pcscfServer);
return true; return true;
@@ -562,27 +555,24 @@ public final class LinkProperties implements Parcelable {
/** /**
* Removes the given {@link InetAddress} from the list of PCSCF servers. * Removes the given {@link InetAddress} from the list of PCSCF servers.
* *
* @param pcscf Server The {@link InetAddress} to remove from the list of PCSCF servers. * @param pcscfServer The {@link InetAddress} to remove from the list of PCSCF servers.
* @return true if the PCSCF server was removed, false otherwise. * @return true if the PCSCF server was removed, false otherwise.
* @hide * @hide
*/ */
public boolean removePcscfServer(InetAddress pcscfServer) { public boolean removePcscfServer(@NonNull InetAddress pcscfServer) {
if (pcscfServer != null) { return mPcscfs.remove(pcscfServer);
return mPcscfs.remove(pcscfServer);
}
return false;
} }
/** /**
* Replaces the PCSCF servers in this {@code LinkProperties} with * Replaces the PCSCF servers in this {@code LinkProperties} with
* the given {@link Collection} of {@link InetAddress} objects. * the given {@link Collection} of {@link InetAddress} objects.
* *
* @param addresses The {@link Collection} of PCSCF servers to set in this object. * @param pcscfServers The {@link Collection} of PCSCF servers to set in this object.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public void setPcscfServers(Collection<InetAddress> pcscfServers) { public void setPcscfServers(@NonNull Collection<InetAddress> pcscfServers) {
mPcscfs.clear(); mPcscfs.clear();
for (InetAddress pcscfServer: pcscfServers) { for (InetAddress pcscfServer: pcscfServers) {
addPcscfServer(pcscfServer); addPcscfServer(pcscfServer);
@@ -598,7 +588,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public List<InetAddress> getPcscfServers() { public @NonNull List<InetAddress> getPcscfServers() {
return Collections.unmodifiableList(mPcscfs); return Collections.unmodifiableList(mPcscfs);
} }
@@ -607,20 +597,18 @@ public final class LinkProperties implements Parcelable {
* *
* @param domains A {@link String} listing in priority order the comma separated * @param domains A {@link String} listing in priority order the comma separated
* domains to search when resolving host names on this link. * domains to search when resolving host names on this link.
* @hide
*/ */
@SystemApi public void setDomains(@Nullable String domains) {
public void setDomains(String domains) {
mDomains = domains; mDomains = domains;
} }
/** /**
* Get the DNS domains search path set for this link. * Get the DNS domains search path set for this link. May be {@code null} if not set.
* *
* @return A {@link String} containing the comma separated domains to search when resolving * @return A {@link String} containing the comma separated domains to search when resolving host
* host names on this link. * names on this link or {@code null}.
*/ */
public String getDomains() { public @Nullable String getDomains() {
return mDomains; return mDomains;
} }
@@ -630,9 +618,7 @@ public final class LinkProperties implements Parcelable {
* 10000 will be ignored. * 10000 will be ignored.
* *
* @param mtu The MTU to use for this link. * @param mtu The MTU to use for this link.
* @hide
*/ */
@SystemApi
public void setMtu(int mtu) { public void setMtu(int mtu) {
mMtu = mtu; mMtu = mtu;
} }
@@ -657,20 +643,20 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public void setTcpBufferSizes(String tcpBufferSizes) { public void setTcpBufferSizes(@Nullable String tcpBufferSizes) {
mTcpBufferSizes = tcpBufferSizes; mTcpBufferSizes = tcpBufferSizes;
} }
/** /**
* Gets the tcp buffer sizes. * Gets the tcp buffer sizes. May be {@code null} if not set.
* *
* @return the tcp buffer sizes to use when this link is the system default. * @return the tcp buffer sizes to use when this link is the system default or {@code null}.
* *
* @hide * @hide
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public String getTcpBufferSizes() { public @Nullable String getTcpBufferSizes() {
return mTcpBufferSizes; return mTcpBufferSizes;
} }
@@ -690,23 +676,18 @@ public final class LinkProperties implements Parcelable {
* *
* @param route A {@link RouteInfo} to add to this object. * @param route A {@link RouteInfo} to add to this object.
* @return {@code false} if the route was already present, {@code true} if it was added. * @return {@code false} if the route was already present, {@code true} if it was added.
*
* @hide
*/ */
@SystemApi public boolean addRoute(@NonNull RouteInfo route) {
public boolean addRoute(RouteInfo route) { String routeIface = route.getInterface();
if (route != null) { if (routeIface != null && !routeIface.equals(mIfaceName)) {
String routeIface = route.getInterface(); throw new IllegalArgumentException(
if (routeIface != null && !routeIface.equals(mIfaceName)) { "Route added with non-matching interface: " + routeIface
throw new IllegalArgumentException( + " vs. " + mIfaceName);
"Route added with non-matching interface: " + routeIface + }
" vs. " + mIfaceName); route = routeWithInterface(route);
} if (!mRoutes.contains(route)) {
route = routeWithInterface(route); mRoutes.add(route);
if (!mRoutes.contains(route)) { return true;
mRoutes.add(route);
return true;
}
} }
return false; return false;
} }
@@ -722,10 +703,8 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean removeRoute(RouteInfo route) { public boolean removeRoute(@NonNull RouteInfo route) {
return route != null && return Objects.equals(mIfaceName, route.getInterface()) && mRoutes.remove(route);
Objects.equals(mIfaceName, route.getInterface()) &&
mRoutes.remove(route);
} }
/** /**
@@ -733,7 +712,7 @@ public final class LinkProperties implements Parcelable {
* *
* @return An unmodifiable {@link List} of {@link RouteInfo} for this link. * @return An unmodifiable {@link List} of {@link RouteInfo} for this link.
*/ */
public List<RouteInfo> getRoutes() { public @NonNull List<RouteInfo> getRoutes() {
return Collections.unmodifiableList(mRoutes); return Collections.unmodifiableList(mRoutes);
} }
@@ -753,7 +732,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public List<RouteInfo> getAllRoutes() { public @NonNull List<RouteInfo> getAllRoutes() {
List<RouteInfo> routes = new ArrayList<>(mRoutes); List<RouteInfo> routes = new ArrayList<>(mRoutes);
for (LinkProperties stacked: mStackedLinks.values()) { for (LinkProperties stacked: mStackedLinks.values()) {
routes.addAll(stacked.getAllRoutes()); routes.addAll(stacked.getAllRoutes());
@@ -767,26 +746,24 @@ public final class LinkProperties implements Parcelable {
* not enforce it and applications may ignore them. * not enforce it and applications may ignore them.
* *
* @param proxy A {@link ProxyInfo} defining the HTTP Proxy to use on this link. * @param proxy A {@link ProxyInfo} defining the HTTP Proxy to use on this link.
* @hide
*/ */
@SystemApi public void setHttpProxy(@Nullable ProxyInfo proxy) {
public void setHttpProxy(ProxyInfo proxy) {
mHttpProxy = proxy; mHttpProxy = proxy;
} }
/** /**
* Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link. * Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link.
* *
* @return The {@link ProxyInfo} set on this link * @return The {@link ProxyInfo} set on this link or {@code null}.
*/ */
public ProxyInfo getHttpProxy() { public @Nullable ProxyInfo getHttpProxy() {
return mHttpProxy; return mHttpProxy;
} }
/** /**
* Returns the NAT64 prefix in use on this link, if any. * Returns the NAT64 prefix in use on this link, if any.
* *
* @return the NAT64 prefix. * @return the NAT64 prefix or {@code null}.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@@ -799,14 +776,14 @@ public final class LinkProperties implements Parcelable {
* Sets the NAT64 prefix in use on this link. * Sets the NAT64 prefix in use on this link.
* *
* Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the * Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the
* 128-bit IPv6 address) are supported. * 128-bit IPv6 address) are supported or {@code null} for no prefix.
* *
* @param prefix the NAT64 prefix. * @param prefix the NAT64 prefix.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public void setNat64Prefix(IpPrefix prefix) { public void setNat64Prefix(@Nullable IpPrefix prefix) {
if (prefix != null && prefix.getPrefixLength() != 96) { if (prefix != null && prefix.getPrefixLength() != 96) {
throw new IllegalArgumentException("Only 96-bit prefixes are supported: " + prefix); throw new IllegalArgumentException("Only 96-bit prefixes are supported: " + prefix);
} }
@@ -818,15 +795,15 @@ public final class LinkProperties implements Parcelable {
* *
* If there is already a stacked link with the same interface name as link, * If there is already a stacked link with the same interface name as link,
* that link is replaced with link. Otherwise, link is added to the list * that link is replaced with link. Otherwise, link is added to the list
* of stacked links. If link is null, nothing changes. * of stacked links.
* *
* @param link The link to add. * @param link The link to add.
* @return true if the link was stacked, false otherwise. * @return true if the link was stacked, false otherwise.
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean addStackedLink(LinkProperties link) { public boolean addStackedLink(@NonNull LinkProperties link) {
if (link != null && link.getInterfaceName() != null) { if (link.getInterfaceName() != null) {
mStackedLinks.put(link.getInterfaceName(), link); mStackedLinks.put(link.getInterfaceName(), link);
return true; return true;
} }
@@ -843,12 +820,9 @@ public final class LinkProperties implements Parcelable {
* @return true if the link was removed, false otherwise. * @return true if the link was removed, false otherwise.
* @hide * @hide
*/ */
public boolean removeStackedLink(String iface) { public boolean removeStackedLink(@NonNull String iface) {
if (iface != null) { LinkProperties removed = mStackedLinks.remove(iface);
LinkProperties removed = mStackedLinks.remove(iface); return removed != null;
return removed != null;
}
return false;
} }
/** /**
@@ -860,7 +834,7 @@ public final class LinkProperties implements Parcelable {
if (mStackedLinks.isEmpty()) { if (mStackedLinks.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<LinkProperties> stacked = new ArrayList<>(); final List<LinkProperties> stacked = new ArrayList<>();
for (LinkProperties link : mStackedLinks.values()) { for (LinkProperties link : mStackedLinks.values()) {
stacked.add(new LinkProperties(link)); stacked.add(new LinkProperties(link));
} }
@@ -869,9 +843,7 @@ public final class LinkProperties implements Parcelable {
/** /**
* Clears this object to its initial state. * Clears this object to its initial state.
* @hide
*/ */
@SystemApi
public void clear() { public void clear() {
mIfaceName = null; mIfaceName = null;
mLinkAddresses.clear(); mLinkAddresses.clear();
@@ -988,7 +960,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean hasIPv4Address() { public boolean hasIpv4Address() {
for (LinkAddress address : mLinkAddresses) { for (LinkAddress address : mLinkAddresses) {
if (address.getAddress() instanceof Inet4Address) { if (address.getAddress() instanceof Inet4Address) {
return true; return true;
@@ -997,16 +969,28 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is an IPv4 address, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasIPv4Address() {
return hasIpv4Address();
}
/** /**
* Returns true if this link or any of its stacked interfaces has an IPv4 address. * Returns true if this link or any of its stacked interfaces has an IPv4 address.
* *
* @return {@code true} if there is an IPv4 address, {@code false} otherwise. * @return {@code true} if there is an IPv4 address, {@code false} otherwise.
*/ */
private boolean hasIPv4AddressOnInterface(String iface) { private boolean hasIpv4AddressOnInterface(String iface) {
// mIfaceName can be null. // mIfaceName can be null.
return (Objects.equals(iface, mIfaceName) && hasIPv4Address()) || return (Objects.equals(iface, mIfaceName) && hasIpv4Address())
(iface != null && mStackedLinks.containsKey(iface) && || (iface != null && mStackedLinks.containsKey(iface)
mStackedLinks.get(iface).hasIPv4Address()); && mStackedLinks.get(iface).hasIpv4Address());
} }
/** /**
@@ -1017,7 +1001,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean hasGlobalIPv6Address() { public boolean hasGlobalIpv6Address() {
for (LinkAddress address : mLinkAddresses) { for (LinkAddress address : mLinkAddresses) {
if (address.getAddress() instanceof Inet6Address && address.isGlobalPreferred()) { if (address.getAddress() instanceof Inet6Address && address.isGlobalPreferred()) {
return true; return true;
@@ -1026,6 +1010,18 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is a global preferred IPv6 address, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasGlobalIPv6Address() {
return hasGlobalIpv6Address();
}
/** /**
* Returns true if this link has an IPv4 default route. * Returns true if this link has an IPv4 default route.
* *
@@ -1033,7 +1029,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean hasIPv4DefaultRoute() { public boolean hasIpv4DefaultRoute() {
for (RouteInfo r : mRoutes) { for (RouteInfo r : mRoutes) {
if (r.isIPv4Default()) { if (r.isIPv4Default()) {
return true; return true;
@@ -1042,6 +1038,18 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is an IPv4 default route, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasIPv4DefaultRoute() {
return hasIpv4DefaultRoute();
}
/** /**
* Returns true if this link has an IPv6 default route. * Returns true if this link has an IPv6 default route.
* *
@@ -1050,7 +1058,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean hasIPv6DefaultRoute() { public boolean hasIpv6DefaultRoute() {
for (RouteInfo r : mRoutes) { for (RouteInfo r : mRoutes) {
if (r.isIPv6Default()) { if (r.isIPv6Default()) {
return true; return true;
@@ -1059,6 +1067,18 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is an IPv6 default route, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasIPv6DefaultRoute() {
return hasIpv6DefaultRoute();
}
/** /**
* Returns true if this link has an IPv4 DNS server. * Returns true if this link has an IPv4 DNS server.
* *
@@ -1066,7 +1086,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean hasIPv4DnsServer() { public boolean hasIpv4DnsServer() {
for (InetAddress ia : mDnses) { for (InetAddress ia : mDnses) {
if (ia instanceof Inet4Address) { if (ia instanceof Inet4Address) {
return true; return true;
@@ -1075,6 +1095,18 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is an IPv4 DNS server, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasIPv4DnsServer() {
return hasIpv4DnsServer();
}
/** /**
* Returns true if this link has an IPv6 DNS server. * Returns true if this link has an IPv6 DNS server.
* *
@@ -1082,7 +1114,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean hasIPv6DnsServer() { public boolean hasIpv6DnsServer() {
for (InetAddress ia : mDnses) { for (InetAddress ia : mDnses) {
if (ia instanceof Inet6Address) { if (ia instanceof Inet6Address) {
return true; return true;
@@ -1091,13 +1123,25 @@ public final class LinkProperties implements Parcelable {
return false; return false;
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if there is an IPv6 DNS server, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean hasIPv6DnsServer() {
return hasIpv6DnsServer();
}
/** /**
* Returns true if this link has an IPv4 PCSCF server. * Returns true if this link has an IPv4 PCSCF server.
* *
* @return {@code true} if there is an IPv4 PCSCF server, {@code false} otherwise. * @return {@code true} if there is an IPv4 PCSCF server, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean hasIPv4PcscfServer() { public boolean hasIpv4PcscfServer() {
for (InetAddress ia : mPcscfs) { for (InetAddress ia : mPcscfs) {
if (ia instanceof Inet4Address) { if (ia instanceof Inet4Address) {
return true; return true;
@@ -1112,7 +1156,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if there is an IPv6 PCSCF server, {@code false} otherwise. * @return {@code true} if there is an IPv6 PCSCF server, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean hasIPv6PcscfServer() { public boolean hasIpv6PcscfServer() {
for (InetAddress ia : mPcscfs) { for (InetAddress ia : mPcscfs) {
if (ia instanceof Inet6Address) { if (ia instanceof Inet6Address) {
return true; return true;
@@ -1130,10 +1174,10 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isIPv4Provisioned() { public boolean isIpv4Provisioned() {
return (hasIPv4Address() && return (hasIpv4Address()
hasIPv4DefaultRoute() && && hasIpv4DefaultRoute()
hasIPv4DnsServer()); && hasIpv4DnsServer());
} }
/** /**
@@ -1145,12 +1189,25 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isIPv6Provisioned() { public boolean isIpv6Provisioned() {
return (hasGlobalIPv6Address() && return (hasGlobalIpv6Address()
hasIPv6DefaultRoute() && && hasIpv6DefaultRoute()
hasIPv6DnsServer()); && hasIpv6DnsServer());
} }
/**
* For backward compatibility.
* This was annotated with @UnsupportedAppUsage in P, so we can't remove the method completely
* just yet.
* @return {@code true} if the link is provisioned, {@code false} otherwise.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
public boolean isIPv6Provisioned() {
return isIpv6Provisioned();
}
/** /**
* Returns true if this link is provisioned for global connectivity, * Returns true if this link is provisioned for global connectivity,
* for at least one Internet Protocol family. * for at least one Internet Protocol family.
@@ -1161,7 +1218,7 @@ public final class LinkProperties implements Parcelable {
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isProvisioned() { public boolean isProvisioned() {
return (isIPv4Provisioned() || isIPv6Provisioned()); return (isIpv4Provisioned() || isIpv6Provisioned());
} }
/** /**
@@ -1173,7 +1230,7 @@ public final class LinkProperties implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean isReachable(InetAddress ip) { public boolean isReachable(@NonNull InetAddress ip) {
final List<RouteInfo> allRoutes = getAllRoutes(); final List<RouteInfo> allRoutes = getAllRoutes();
// If we don't have a route to this IP address, it's not reachable. // If we don't have a route to this IP address, it's not reachable.
final RouteInfo bestRoute = RouteInfo.selectBestRoute(allRoutes, ip); final RouteInfo bestRoute = RouteInfo.selectBestRoute(allRoutes, ip);
@@ -1185,7 +1242,7 @@ public final class LinkProperties implements Parcelable {
if (ip instanceof Inet4Address) { if (ip instanceof Inet4Address) {
// For IPv4, it suffices for now to simply have any address. // For IPv4, it suffices for now to simply have any address.
return hasIPv4AddressOnInterface(bestRoute.getInterface()); return hasIpv4AddressOnInterface(bestRoute.getInterface());
} else if (ip instanceof Inet6Address) { } else if (ip instanceof Inet6Address) {
if (ip.isLinkLocalAddress()) { if (ip.isLinkLocalAddress()) {
// For now, just make sure link-local destinations have // For now, just make sure link-local destinations have
@@ -1196,7 +1253,7 @@ public final class LinkProperties implements Parcelable {
// For non-link-local destinations check that either the best route // For non-link-local destinations check that either the best route
// is directly connected or that some global preferred address exists. // is directly connected or that some global preferred address exists.
// TODO: reconsider all cases (disconnected ULA networks, ...). // TODO: reconsider all cases (disconnected ULA networks, ...).
return (!bestRoute.hasGateway() || hasGlobalIPv6Address()); return (!bestRoute.hasGateway() || hasGlobalIpv6Address());
} }
} }
@@ -1211,7 +1268,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean isIdenticalInterfaceName(LinkProperties target) { public boolean isIdenticalInterfaceName(@NonNull LinkProperties target) {
return TextUtils.equals(getInterfaceName(), target.getInterfaceName()); return TextUtils.equals(getInterfaceName(), target.getInterfaceName());
} }
@@ -1223,7 +1280,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean isIdenticalAddresses(LinkProperties target) { public boolean isIdenticalAddresses(@NonNull LinkProperties target) {
Collection<InetAddress> targetAddresses = target.getAddresses(); Collection<InetAddress> targetAddresses = target.getAddresses();
Collection<InetAddress> sourceAddresses = getAddresses(); Collection<InetAddress> sourceAddresses = getAddresses();
return (sourceAddresses.size() == targetAddresses.size()) ? return (sourceAddresses.size() == targetAddresses.size()) ?
@@ -1238,7 +1295,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean isIdenticalDnses(LinkProperties target) { public boolean isIdenticalDnses(@NonNull LinkProperties target) {
Collection<InetAddress> targetDnses = target.getDnsServers(); Collection<InetAddress> targetDnses = target.getDnsServers();
String targetDomains = target.getDomains(); String targetDomains = target.getDomains();
if (mDomains == null) { if (mDomains == null) {
@@ -1258,7 +1315,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalPrivateDns(LinkProperties target) { public boolean isIdenticalPrivateDns(@NonNull LinkProperties target) {
return (isPrivateDnsActive() == target.isPrivateDnsActive() return (isPrivateDnsActive() == target.isPrivateDnsActive()
&& TextUtils.equals(getPrivateDnsServerName(), && TextUtils.equals(getPrivateDnsServerName(),
target.getPrivateDnsServerName())); target.getPrivateDnsServerName()));
@@ -1272,7 +1329,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalValidatedPrivateDnses(LinkProperties target) { public boolean isIdenticalValidatedPrivateDnses(@NonNull LinkProperties target) {
Collection<InetAddress> targetDnses = target.getValidatedPrivateDnsServers(); Collection<InetAddress> targetDnses = target.getValidatedPrivateDnsServers();
return (mValidatedPrivateDnses.size() == targetDnses.size()) return (mValidatedPrivateDnses.size() == targetDnses.size())
? mValidatedPrivateDnses.containsAll(targetDnses) : false; ? mValidatedPrivateDnses.containsAll(targetDnses) : false;
@@ -1285,7 +1342,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalPcscfs(LinkProperties target) { public boolean isIdenticalPcscfs(@NonNull LinkProperties target) {
Collection<InetAddress> targetPcscfs = target.getPcscfServers(); Collection<InetAddress> targetPcscfs = target.getPcscfServers();
return (mPcscfs.size() == targetPcscfs.size()) ? return (mPcscfs.size() == targetPcscfs.size()) ?
mPcscfs.containsAll(targetPcscfs) : false; mPcscfs.containsAll(targetPcscfs) : false;
@@ -1299,7 +1356,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean isIdenticalRoutes(LinkProperties target) { public boolean isIdenticalRoutes(@NonNull LinkProperties target) {
Collection<RouteInfo> targetRoutes = target.getRoutes(); Collection<RouteInfo> targetRoutes = target.getRoutes();
return (mRoutes.size() == targetRoutes.size()) ? return (mRoutes.size() == targetRoutes.size()) ?
mRoutes.containsAll(targetRoutes) : false; mRoutes.containsAll(targetRoutes) : false;
@@ -1313,7 +1370,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public boolean isIdenticalHttpProxy(LinkProperties target) { public boolean isIdenticalHttpProxy(@NonNull LinkProperties target) {
return getHttpProxy() == null ? target.getHttpProxy() == null : return getHttpProxy() == null ? target.getHttpProxy() == null :
getHttpProxy().equals(target.getHttpProxy()); getHttpProxy().equals(target.getHttpProxy());
} }
@@ -1326,7 +1383,7 @@ public final class LinkProperties implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public boolean isIdenticalStackedLinks(LinkProperties target) { public boolean isIdenticalStackedLinks(@NonNull LinkProperties target) {
if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) { if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) {
return false; return false;
} }
@@ -1347,7 +1404,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalMtu(LinkProperties target) { public boolean isIdenticalMtu(@NonNull LinkProperties target) {
return getMtu() == target.getMtu(); return getMtu() == target.getMtu();
} }
@@ -1358,7 +1415,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalTcpBufferSizes(LinkProperties target) { public boolean isIdenticalTcpBufferSizes(@NonNull LinkProperties target) {
return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes); return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
} }
@@ -1369,7 +1426,7 @@ public final class LinkProperties implements Parcelable {
* @return {@code true} if both are identical, {@code false} otherwise. * @return {@code true} if both are identical, {@code false} otherwise.
* @hide * @hide
*/ */
public boolean isIdenticalNat64Prefix(LinkProperties target) { public boolean isIdenticalNat64Prefix(@NonNull LinkProperties target) {
return Objects.equals(mNat64Prefix, target.mNat64Prefix); return Objects.equals(mNat64Prefix, target.mNat64Prefix);
} }
@@ -1421,7 +1478,7 @@ public final class LinkProperties implements Parcelable {
* @return the differences between the addresses. * @return the differences between the addresses.
* @hide * @hide
*/ */
public CompareResult<LinkAddress> compareAddresses(LinkProperties target) { public @NonNull CompareResult<LinkAddress> compareAddresses(@Nullable LinkProperties target) {
/* /*
* Duplicate the LinkAddresses into removed, we will be removing * Duplicate the LinkAddresses into removed, we will be removing
* address which are common between mLinkAddresses and target * address which are common between mLinkAddresses and target
@@ -1441,7 +1498,7 @@ public final class LinkProperties implements Parcelable {
* @return the differences between the DNS addresses. * @return the differences between the DNS addresses.
* @hide * @hide
*/ */
public CompareResult<InetAddress> compareDnses(LinkProperties target) { public @NonNull CompareResult<InetAddress> compareDnses(@Nullable LinkProperties target) {
/* /*
* Duplicate the InetAddresses into removed, we will be removing * Duplicate the InetAddresses into removed, we will be removing
* dns address which are common between mDnses and target * dns address which are common between mDnses and target
@@ -1460,7 +1517,8 @@ public final class LinkProperties implements Parcelable {
* @return the differences between the DNS addresses. * @return the differences between the DNS addresses.
* @hide * @hide
*/ */
public CompareResult<InetAddress> compareValidatedPrivateDnses(LinkProperties target) { public @NonNull CompareResult<InetAddress> compareValidatedPrivateDnses(
@Nullable LinkProperties target) {
return new CompareResult<>(mValidatedPrivateDnses, return new CompareResult<>(mValidatedPrivateDnses,
target != null ? target.getValidatedPrivateDnsServers() : null); target != null ? target.getValidatedPrivateDnsServers() : null);
} }
@@ -1473,7 +1531,7 @@ public final class LinkProperties implements Parcelable {
* @return the differences between the routes. * @return the differences between the routes.
* @hide * @hide
*/ */
public CompareResult<RouteInfo> compareAllRoutes(LinkProperties target) { public @NonNull CompareResult<RouteInfo> compareAllRoutes(@Nullable LinkProperties target) {
/* /*
* Duplicate the RouteInfos into removed, we will be removing * Duplicate the RouteInfos into removed, we will be removing
* routes which are common between mRoutes and target * routes which are common between mRoutes and target
@@ -1491,7 +1549,8 @@ public final class LinkProperties implements Parcelable {
* @return the differences between the interface names. * @return the differences between the interface names.
* @hide * @hide
*/ */
public CompareResult<String> compareAllInterfaceNames(LinkProperties target) { public @NonNull CompareResult<String> compareAllInterfaceNames(
@Nullable LinkProperties target) {
/* /*
* Duplicate the interface names into removed, we will be removing * Duplicate the interface names into removed, we will be removing
* interface names which are common between this and target * interface names which are common between this and target

View File

@@ -16,6 +16,7 @@
package android.net; package android.net;
import android.annotation.NonNull;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
@@ -125,7 +126,7 @@ public class Network implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public Network(Network that) { public Network(@NonNull Network that) {
this(that.netId, that.mPrivateDnsBypass); this(that.netId, that.mPrivateDnsBypass);
} }
@@ -163,7 +164,7 @@ public class Network implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public Network getPrivateDnsBypassingCopy() { public @NonNull Network getPrivateDnsBypassingCopy() {
return new Network(netId, true); return new Network(netId, true);
} }

View File

@@ -17,6 +17,7 @@
package android.net; package android.net;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
@@ -91,7 +92,7 @@ public final class NetworkCapabilities implements Parcelable {
* Set all contents of this object to the contents of a NetworkCapabilities. * Set all contents of this object to the contents of a NetworkCapabilities.
* @hide * @hide
*/ */
public void set(NetworkCapabilities nc) { public void set(@NonNull NetworkCapabilities nc) {
mNetworkCapabilities = nc.mNetworkCapabilities; mNetworkCapabilities = nc.mNetworkCapabilities;
mTransportTypes = nc.mTransportTypes; mTransportTypes = nc.mTransportTypes;
mLinkUpBandwidthKbps = nc.mLinkUpBandwidthKbps; mLinkUpBandwidthKbps = nc.mLinkUpBandwidthKbps;
@@ -405,7 +406,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public NetworkCapabilities addCapability(@NetCapability int capability) { public @NonNull NetworkCapabilities addCapability(@NetCapability int capability) {
checkValidCapability(capability); checkValidCapability(capability);
mNetworkCapabilities |= 1 << capability; mNetworkCapabilities |= 1 << capability;
mUnwantedNetworkCapabilities &= ~(1 << capability); // remove from unwanted capability list mUnwantedNetworkCapabilities &= ~(1 << capability); // remove from unwanted capability list
@@ -442,7 +443,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public NetworkCapabilities removeCapability(@NetCapability int capability) { public @NonNull NetworkCapabilities removeCapability(@NetCapability int capability) {
checkValidCapability(capability); checkValidCapability(capability);
final long mask = ~(1 << capability); final long mask = ~(1 << capability);
mNetworkCapabilities &= mask; mNetworkCapabilities &= mask;
@@ -456,7 +457,8 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public NetworkCapabilities setCapability(@NetCapability int capability, boolean value) { public @NonNull NetworkCapabilities setCapability(@NetCapability int capability,
boolean value) {
if (value) { if (value) {
addCapability(capability); addCapability(capability);
} else { } else {
@@ -534,7 +536,7 @@ public final class NetworkCapabilities implements Parcelable {
} }
/** Note this method may result in having the same capability in wanted and unwanted lists. */ /** Note this method may result in having the same capability in wanted and unwanted lists. */
private void combineNetCapabilities(NetworkCapabilities nc) { private void combineNetCapabilities(@NonNull NetworkCapabilities nc) {
this.mNetworkCapabilities |= nc.mNetworkCapabilities; this.mNetworkCapabilities |= nc.mNetworkCapabilities;
this.mUnwantedNetworkCapabilities |= nc.mUnwantedNetworkCapabilities; this.mUnwantedNetworkCapabilities |= nc.mUnwantedNetworkCapabilities;
} }
@@ -546,7 +548,7 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public String describeFirstNonRequestableCapability() { public @Nullable String describeFirstNonRequestableCapability() {
final long nonRequestable = (mNetworkCapabilities | mUnwantedNetworkCapabilities) final long nonRequestable = (mNetworkCapabilities | mUnwantedNetworkCapabilities)
& NON_REQUESTABLE_CAPABILITIES; & NON_REQUESTABLE_CAPABILITIES;
@@ -558,7 +560,8 @@ public final class NetworkCapabilities implements Parcelable {
return null; return null;
} }
private boolean satisfiedByNetCapabilities(NetworkCapabilities nc, boolean onlyImmutable) { private boolean satisfiedByNetCapabilities(@NonNull NetworkCapabilities nc,
boolean onlyImmutable) {
long requestedCapabilities = mNetworkCapabilities; long requestedCapabilities = mNetworkCapabilities;
long requestedUnwantedCapabilities = mUnwantedNetworkCapabilities; long requestedUnwantedCapabilities = mUnwantedNetworkCapabilities;
long providedCapabilities = nc.mNetworkCapabilities; long providedCapabilities = nc.mNetworkCapabilities;
@@ -572,12 +575,12 @@ public final class NetworkCapabilities implements Parcelable {
} }
/** @hide */ /** @hide */
public boolean equalsNetCapabilities(NetworkCapabilities nc) { public boolean equalsNetCapabilities(@NonNull NetworkCapabilities nc) {
return (nc.mNetworkCapabilities == this.mNetworkCapabilities) return (nc.mNetworkCapabilities == this.mNetworkCapabilities)
&& (nc.mUnwantedNetworkCapabilities == this.mUnwantedNetworkCapabilities); && (nc.mUnwantedNetworkCapabilities == this.mUnwantedNetworkCapabilities);
} }
private boolean equalsNetCapabilitiesRequestable(NetworkCapabilities that) { private boolean equalsNetCapabilitiesRequestable(@NonNull NetworkCapabilities that) {
return ((this.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) == return ((this.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) ==
(that.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES)) (that.mNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES))
&& ((this.mUnwantedNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) == && ((this.mUnwantedNetworkCapabilities & ~NON_REQUESTABLE_CAPABILITIES) ==
@@ -713,7 +716,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public NetworkCapabilities addTransportType(@Transport int transportType) { public @NonNull NetworkCapabilities addTransportType(@Transport int transportType) {
checkValidTransportType(transportType); checkValidTransportType(transportType);
mTransportTypes |= 1 << transportType; mTransportTypes |= 1 << transportType;
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
@@ -727,7 +730,7 @@ public final class NetworkCapabilities implements Parcelable {
* @return This NetworkCapabilities instance, to facilitate chaining. * @return This NetworkCapabilities instance, to facilitate chaining.
* @hide * @hide
*/ */
public NetworkCapabilities removeTransportType(@Transport int transportType) { public @NonNull NetworkCapabilities removeTransportType(@Transport int transportType) {
checkValidTransportType(transportType); checkValidTransportType(transportType);
mTransportTypes &= ~(1 << transportType); mTransportTypes &= ~(1 << transportType);
setNetworkSpecifier(mNetworkSpecifier); // used for exception checking setNetworkSpecifier(mNetworkSpecifier); // used for exception checking
@@ -740,7 +743,8 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public NetworkCapabilities setTransportType(@Transport int transportType, boolean value) { public @NonNull NetworkCapabilities setTransportType(@Transport int transportType,
boolean value) {
if (value) { if (value) {
addTransportType(transportType); addTransportType(transportType);
} else { } else {
@@ -757,7 +761,7 @@ public final class NetworkCapabilities implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public @Transport int[] getTransportTypes() { @NonNull public @Transport int[] getTransportTypes() {
return BitUtils.unpackBits(mTransportTypes); return BitUtils.unpackBits(mTransportTypes);
} }
@@ -847,7 +851,7 @@ public final class NetworkCapabilities implements Parcelable {
* @param upKbps the estimated first hop upstream (device to network) bandwidth. * @param upKbps the estimated first hop upstream (device to network) bandwidth.
* @hide * @hide
*/ */
public NetworkCapabilities setLinkUpstreamBandwidthKbps(int upKbps) { public @NonNull NetworkCapabilities setLinkUpstreamBandwidthKbps(int upKbps) {
mLinkUpBandwidthKbps = upKbps; mLinkUpBandwidthKbps = upKbps;
return this; return this;
} }
@@ -877,7 +881,7 @@ public final class NetworkCapabilities implements Parcelable {
* @param downKbps the estimated first hop downstream (network to device) bandwidth. * @param downKbps the estimated first hop downstream (network to device) bandwidth.
* @hide * @hide
*/ */
public NetworkCapabilities setLinkDownstreamBandwidthKbps(int downKbps) { public @NonNull NetworkCapabilities setLinkDownstreamBandwidthKbps(int downKbps) {
mLinkDownBandwidthKbps = downKbps; mLinkDownBandwidthKbps = downKbps;
return this; return this;
} }
@@ -936,7 +940,7 @@ public final class NetworkCapabilities implements Parcelable {
* @return This NetworkCapabilities instance, to facilitate chaining. * @return This NetworkCapabilities instance, to facilitate chaining.
* @hide * @hide
*/ */
public NetworkCapabilities setNetworkSpecifier(NetworkSpecifier networkSpecifier) { public @NonNull NetworkCapabilities setNetworkSpecifier(NetworkSpecifier networkSpecifier) {
if (networkSpecifier != null && Long.bitCount(mTransportTypes) != 1) { if (networkSpecifier != null && Long.bitCount(mTransportTypes) != 1) {
throw new IllegalStateException("Must have a single transport specified to use " + throw new IllegalStateException("Must have a single transport specified to use " +
"setNetworkSpecifier"); "setNetworkSpecifier");
@@ -955,20 +959,20 @@ public final class NetworkCapabilities implements Parcelable {
* @return This NetworkCapabilities instance, to facilitate chaining. * @return This NetworkCapabilities instance, to facilitate chaining.
* @hide * @hide
*/ */
public NetworkCapabilities setTransportInfo(TransportInfo transportInfo) { public @NonNull NetworkCapabilities setTransportInfo(TransportInfo transportInfo) {
mTransportInfo = transportInfo; mTransportInfo = transportInfo;
return this; return this;
} }
/** /**
* Gets the optional bearer specific network specifier. * Gets the optional bearer specific network specifier. May be {@code null} if not set.
* *
* @return The optional {@link NetworkSpecifier} specifying the bearer specific network * @return The optional {@link NetworkSpecifier} specifying the bearer specific network
* specifier. See {@link #setNetworkSpecifier}. * specifier or {@code null}. See {@link #setNetworkSpecifier}.
* @hide * @hide
*/ */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public NetworkSpecifier getNetworkSpecifier() { public @Nullable NetworkSpecifier getNetworkSpecifier() {
return mNetworkSpecifier; return mNetworkSpecifier;
} }
@@ -1015,8 +1019,6 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* Magic value that indicates no signal strength provided. A request specifying this value is * Magic value that indicates no signal strength provided. A request specifying this value is
* always satisfied. * always satisfied.
*
* @hide
*/ */
public static final int SIGNAL_STRENGTH_UNSPECIFIED = Integer.MIN_VALUE; public static final int SIGNAL_STRENGTH_UNSPECIFIED = Integer.MIN_VALUE;
@@ -1024,7 +1026,7 @@ public final class NetworkCapabilities implements Parcelable {
* Signal strength. This is a signed integer, and higher values indicate better signal. * Signal strength. This is a signed integer, and higher values indicate better signal.
* The exact units are bearer-dependent. For example, Wi-Fi uses RSSI. * The exact units are bearer-dependent. For example, Wi-Fi uses RSSI.
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
private int mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED; private int mSignalStrength = SIGNAL_STRENGTH_UNSPECIFIED;
/** /**
@@ -1041,7 +1043,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public NetworkCapabilities setSignalStrength(int signalStrength) { public @NonNull NetworkCapabilities setSignalStrength(int signalStrength) {
mSignalStrength = signalStrength; mSignalStrength = signalStrength;
return this; return this;
} }
@@ -1060,9 +1062,7 @@ public final class NetworkCapabilities implements Parcelable {
* Retrieves the signal strength. * Retrieves the signal strength.
* *
* @return The bearer-specific signal strength. * @return The bearer-specific signal strength.
* @hide
*/ */
@SystemApi
public int getSignalStrength() { public int getSignalStrength() {
return mSignalStrength; return mSignalStrength;
} }
@@ -1120,7 +1120,7 @@ public final class NetworkCapabilities implements Parcelable {
* Convenience method to set the UIDs this network applies to to a single UID. * Convenience method to set the UIDs this network applies to to a single UID.
* @hide * @hide
*/ */
public NetworkCapabilities setSingleUid(int uid) { public @NonNull NetworkCapabilities setSingleUid(int uid) {
final ArraySet<UidRange> identity = new ArraySet<>(1); final ArraySet<UidRange> identity = new ArraySet<>(1);
identity.add(new UidRange(uid, uid)); identity.add(new UidRange(uid, uid));
setUids(identity); setUids(identity);
@@ -1132,7 +1132,7 @@ public final class NetworkCapabilities implements Parcelable {
* This makes a copy of the set so that callers can't modify it after the call. * This makes a copy of the set so that callers can't modify it after the call.
* @hide * @hide
*/ */
public NetworkCapabilities setUids(Set<UidRange> uids) { public @NonNull NetworkCapabilities setUids(Set<UidRange> uids) {
if (null == uids) { if (null == uids) {
mUids = null; mUids = null;
} else { } else {
@@ -1146,7 +1146,7 @@ public final class NetworkCapabilities implements Parcelable {
* This returns a copy of the set so that callers can't modify the original object. * This returns a copy of the set so that callers can't modify the original object.
* @hide * @hide
*/ */
public Set<UidRange> getUids() { public @Nullable Set<UidRange> getUids() {
return null == mUids ? null : new ArraySet<>(mUids); return null == mUids ? null : new ArraySet<>(mUids);
} }
@@ -1179,7 +1179,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@VisibleForTesting @VisibleForTesting
public boolean equalsUids(NetworkCapabilities nc) { public boolean equalsUids(@NonNull NetworkCapabilities nc) {
Set<UidRange> comparedUids = nc.mUids; Set<UidRange> comparedUids = nc.mUids;
if (null == comparedUids) return null == mUids; if (null == comparedUids) return null == mUids;
if (null == mUids) return false; if (null == mUids) return false;
@@ -1212,7 +1212,7 @@ public final class NetworkCapabilities implements Parcelable {
* @see #appliesToUid * @see #appliesToUid
* @hide * @hide
*/ */
public boolean satisfiedByUids(NetworkCapabilities nc) { public boolean satisfiedByUids(@NonNull NetworkCapabilities nc) {
if (null == nc.mUids || null == mUids) return true; // The network satisfies everything. if (null == nc.mUids || null == mUids) return true; // The network satisfies everything.
for (UidRange requiredRange : mUids) { for (UidRange requiredRange : mUids) {
if (requiredRange.contains(nc.mEstablishingVpnAppUid)) return true; if (requiredRange.contains(nc.mEstablishingVpnAppUid)) return true;
@@ -1232,7 +1232,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@VisibleForTesting @VisibleForTesting
public boolean appliesToUidRange(UidRange requiredRange) { public boolean appliesToUidRange(@Nullable UidRange requiredRange) {
if (null == mUids) return true; if (null == mUids) return true;
for (UidRange uidRange : mUids) { for (UidRange uidRange : mUids) {
if (uidRange.containsRange(requiredRange)) { if (uidRange.containsRange(requiredRange)) {
@@ -1247,7 +1247,7 @@ public final class NetworkCapabilities implements Parcelable {
* NetworkCapabilities apply to. * NetworkCapabilities apply to.
* nc is assumed nonnull. * nc is assumed nonnull.
*/ */
private void combineUids(NetworkCapabilities nc) { private void combineUids(@NonNull NetworkCapabilities nc) {
if (null == nc.mUids || null == mUids) { if (null == nc.mUids || null == mUids) {
mUids = null; mUids = null;
return; return;
@@ -1268,7 +1268,7 @@ public final class NetworkCapabilities implements Parcelable {
* Sets the SSID of this network. * Sets the SSID of this network.
* @hide * @hide
*/ */
public NetworkCapabilities setSSID(String ssid) { public @NonNull NetworkCapabilities setSSID(@Nullable String ssid) {
mSSID = ssid; mSSID = ssid;
return this; return this;
} }
@@ -1277,7 +1277,7 @@ public final class NetworkCapabilities implements Parcelable {
* Gets the SSID of this network, or null if none or unknown. * Gets the SSID of this network, or null if none or unknown.
* @hide * @hide
*/ */
public String getSSID() { public @Nullable String getSSID() {
return mSSID; return mSSID;
} }
@@ -1285,7 +1285,7 @@ public final class NetworkCapabilities implements Parcelable {
* Tests if the SSID of this network is the same as the SSID of the passed network. * Tests if the SSID of this network is the same as the SSID of the passed network.
* @hide * @hide
*/ */
public boolean equalsSSID(NetworkCapabilities nc) { public boolean equalsSSID(@NonNull NetworkCapabilities nc) {
return Objects.equals(mSSID, nc.mSSID); return Objects.equals(mSSID, nc.mSSID);
} }
@@ -1293,7 +1293,7 @@ public final class NetworkCapabilities implements Parcelable {
* Check if the SSID requirements of this object are matched by the passed object. * Check if the SSID requirements of this object are matched by the passed object.
* @hide * @hide
*/ */
public boolean satisfiedBySSID(NetworkCapabilities nc) { public boolean satisfiedBySSID(@NonNull NetworkCapabilities nc) {
return mSSID == null || mSSID.equals(nc.mSSID); return mSSID == null || mSSID.equals(nc.mSSID);
} }
@@ -1304,7 +1304,7 @@ public final class NetworkCapabilities implements Parcelable {
* equal. * equal.
* @hide * @hide
*/ */
private void combineSSIDs(NetworkCapabilities nc) { private void combineSSIDs(@NonNull NetworkCapabilities nc) {
if (mSSID != null && !mSSID.equals(nc.mSSID)) { if (mSSID != null && !mSSID.equals(nc.mSSID)) {
throw new IllegalStateException("Can't combine two SSIDs"); throw new IllegalStateException("Can't combine two SSIDs");
} }
@@ -1319,7 +1319,7 @@ public final class NetworkCapabilities implements Parcelable {
* both lists will never be satisfied. * both lists will never be satisfied.
* @hide * @hide
*/ */
public void combineCapabilities(NetworkCapabilities nc) { public void combineCapabilities(@NonNull NetworkCapabilities nc) {
combineNetCapabilities(nc); combineNetCapabilities(nc);
combineTransportTypes(nc); combineTransportTypes(nc);
combineLinkBandwidths(nc); combineLinkBandwidths(nc);
@@ -1359,7 +1359,7 @@ public final class NetworkCapabilities implements Parcelable {
*/ */
@TestApi @TestApi
@SystemApi @SystemApi
public boolean satisfiedByNetworkCapabilities(NetworkCapabilities nc) { public boolean satisfiedByNetworkCapabilities(@Nullable NetworkCapabilities nc) {
return satisfiedByNetworkCapabilities(nc, false); return satisfiedByNetworkCapabilities(nc, false);
} }
@@ -1370,7 +1370,7 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public boolean satisfiedByImmutableNetworkCapabilities(NetworkCapabilities nc) { public boolean satisfiedByImmutableNetworkCapabilities(@Nullable NetworkCapabilities nc) {
return satisfiedByNetworkCapabilities(nc, true); return satisfiedByNetworkCapabilities(nc, true);
} }
@@ -1381,7 +1381,7 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public String describeImmutableDifferences(NetworkCapabilities that) { public String describeImmutableDifferences(@Nullable NetworkCapabilities that) {
if (that == null) { if (that == null) {
return "other NetworkCapabilities was null"; return "other NetworkCapabilities was null";
} }
@@ -1420,7 +1420,7 @@ public final class NetworkCapabilities implements Parcelable {
* *
* @hide * @hide
*/ */
public boolean equalRequestableCapabilities(NetworkCapabilities nc) { public boolean equalRequestableCapabilities(@Nullable NetworkCapabilities nc) {
if (nc == null) return false; if (nc == null) return false;
return (equalsNetCapabilitiesRequestable(nc) && return (equalsNetCapabilitiesRequestable(nc) &&
equalsTransportTypes(nc) && equalsTransportTypes(nc) &&
@@ -1428,7 +1428,7 @@ public final class NetworkCapabilities implements Parcelable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj == null || (obj instanceof NetworkCapabilities == false)) return false; if (obj == null || (obj instanceof NetworkCapabilities == false)) return false;
NetworkCapabilities that = (NetworkCapabilities) obj; NetworkCapabilities that = (NetworkCapabilities) obj;
return (equalsNetCapabilities(that) return (equalsNetCapabilities(that)
@@ -1502,7 +1502,7 @@ public final class NetworkCapabilities implements Parcelable {
}; };
@Override @Override
public String toString() { public @NonNull String toString() {
final StringBuilder sb = new StringBuilder("["); final StringBuilder sb = new StringBuilder("[");
if (0 != mTransportTypes) { if (0 != mTransportTypes) {
sb.append(" Transports: "); sb.append(" Transports: ");
@@ -1561,8 +1561,8 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* @hide * @hide
*/ */
public static void appendStringRepresentationOfBitMaskToStringBuilder(StringBuilder sb, public static void appendStringRepresentationOfBitMaskToStringBuilder(@NonNull StringBuilder sb,
long bitMask, NameOf nameFetcher, String separator) { long bitMask, @NonNull NameOf nameFetcher, @NonNull String separator) {
int bitPos = 0; int bitPos = 0;
boolean firstElementAdded = false; boolean firstElementAdded = false;
while (bitMask != 0) { while (bitMask != 0) {
@@ -1580,7 +1580,7 @@ public final class NetworkCapabilities implements Parcelable {
} }
/** @hide */ /** @hide */
public void writeToProto(ProtoOutputStream proto, long fieldId) { public void writeToProto(@NonNull ProtoOutputStream proto, long fieldId) {
final long token = proto.start(fieldId); final long token = proto.start(fieldId);
for (int transport : getTransportTypes()) { for (int transport : getTransportTypes()) {
@@ -1610,7 +1610,7 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* @hide * @hide
*/ */
public static String capabilityNamesOf(@NetCapability int[] capabilities) { public static @NonNull String capabilityNamesOf(@Nullable @NetCapability int[] capabilities) {
StringJoiner joiner = new StringJoiner("|"); StringJoiner joiner = new StringJoiner("|");
if (capabilities != null) { if (capabilities != null) {
for (int c : capabilities) { for (int c : capabilities) {
@@ -1623,7 +1623,7 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* @hide * @hide
*/ */
public static String capabilityNameOf(@NetCapability int capability) { public static @NonNull String capabilityNameOf(@NetCapability int capability) {
switch (capability) { switch (capability) {
case NET_CAPABILITY_MMS: return "MMS"; case NET_CAPABILITY_MMS: return "MMS";
case NET_CAPABILITY_SUPL: return "SUPL"; case NET_CAPABILITY_SUPL: return "SUPL";
@@ -1658,7 +1658,7 @@ public final class NetworkCapabilities implements Parcelable {
* @hide * @hide
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public static String transportNamesOf(@Transport int[] types) { public static @NonNull String transportNamesOf(@Nullable @Transport int[] types) {
StringJoiner joiner = new StringJoiner("|"); StringJoiner joiner = new StringJoiner("|");
if (types != null) { if (types != null) {
for (int t : types) { for (int t : types) {
@@ -1671,7 +1671,7 @@ public final class NetworkCapabilities implements Parcelable {
/** /**
* @hide * @hide
*/ */
public static String transportNameOf(@Transport int transport) { public static @NonNull String transportNameOf(@Transport int transport) {
if (!isValidTransport(transport)) { if (!isValidTransport(transport)) {
return "UNKNOWN"; return "UNKNOWN";
} }

View File

@@ -16,6 +16,7 @@
package android.net; package android.net;
import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
@@ -138,7 +139,9 @@ public class NetworkInfo implements Parcelable {
private int mSubtype; private int mSubtype;
private String mTypeName; private String mTypeName;
private String mSubtypeName; private String mSubtypeName;
@NonNull
private State mState; private State mState;
@NonNull
private DetailedState mDetailedState; private DetailedState mDetailedState;
private String mReason; private String mReason;
private String mExtraInfo; private String mExtraInfo;
@@ -451,7 +454,7 @@ public class NetworkInfo implements Parcelable {
* the device and let apps react more easily and quickly to changes. * the device and let apps react more easily and quickly to changes.
*/ */
@Deprecated @Deprecated
public DetailedState getDetailedState() { public @NonNull DetailedState getDetailedState() {
synchronized (this) { synchronized (this) {
return mDetailedState; return mDetailedState;
} }

View File

@@ -347,7 +347,7 @@ public class NetworkRequest implements Parcelable {
* @hide * @hide
*/ */
@SystemApi @SystemApi
public Builder setSignalStrength(int signalStrength) { public @NonNull Builder setSignalStrength(int signalStrength) {
mNetworkCapabilities.setSignalStrength(signalStrength); mNetworkCapabilities.setSignalStrength(signalStrength);
return this; return this;
} }

View File

@@ -16,6 +16,7 @@
package android.net; package android.net;
import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage;
@@ -112,7 +113,8 @@ public final class RouteInfo implements Parcelable {
*/ */
@SystemApi @SystemApi
@TestApi @TestApi
public RouteInfo(IpPrefix destination, InetAddress gateway, String iface, int type) { public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway,
@Nullable String iface, int type) {
switch (type) { switch (type) {
case RTN_UNICAST: case RTN_UNICAST:
case RTN_UNREACHABLE: case RTN_UNREACHABLE:

View File

@@ -16,6 +16,7 @@
package android.net.apf; package android.net.apf;
import android.annotation.NonNull;
import android.annotation.SystemApi; import android.annotation.SystemApi;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.content.Context; import android.content.Context;
@@ -115,14 +116,14 @@ public final class ApfCapabilities implements Parcelable {
/** /**
* @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames. * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
*/ */
public static boolean getApfDrop8023Frames(Context context) { public static boolean getApfDrop8023Frames(@NonNull Context context) {
return context.getResources().getBoolean(R.bool.config_apfDrop802_3Frames); return context.getResources().getBoolean(R.bool.config_apfDrop802_3Frames);
} }
/** /**
* @return An array of blacklisted EtherType, packets with EtherTypes within it will be dropped. * @return An array of blacklisted EtherType, packets with EtherTypes within it will be dropped.
*/ */
public static int[] getApfEthTypeBlackList(Context context) { public static @NonNull int[] getApfEthTypeBlackList(@NonNull Context context) {
return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList); return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList);
} }
} }

View File

@@ -2174,7 +2174,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (VDBG) log("identical MTU - not setting"); if (VDBG) log("identical MTU - not setting");
return; return;
} }
if (LinkProperties.isValidMtu(mtu, newLp.hasGlobalIPv6Address()) == false) { if (!LinkProperties.isValidMtu(mtu, newLp.hasGlobalIpv6Address())) {
if (mtu != 0) loge("Unexpected mtu value: " + mtu + ", " + iface); if (mtu != 0) loge("Unexpected mtu value: " + mtu + ", " + iface);
return; return;
} }

View File

@@ -107,8 +107,8 @@ public class Nat464Xlat extends BaseNetworkObserver {
// Only run clat on networks that have a global IPv6 address and don't have a native IPv4 // Only run clat on networks that have a global IPv6 address and don't have a native IPv4
// address. // address.
LinkProperties lp = nai.linkProperties; LinkProperties lp = nai.linkProperties;
final boolean isIpv6OnlyNetwork = (lp != null) && lp.hasGlobalIPv6Address() final boolean isIpv6OnlyNetwork = (lp != null) && lp.hasGlobalIpv6Address()
&& !lp.hasIPv4Address(); && !lp.hasIpv4Address();
// If the network tells us it doesn't use clat, respect that. // If the network tells us it doesn't use clat, respect that.
final boolean skip464xlat = (nai.netMisc() != null) && nai.netMisc().skip464xlat; final boolean skip464xlat = (nai.netMisc() != null) && nai.netMisc().skip464xlat;

View File

@@ -34,10 +34,12 @@ import android.util.Pair;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import libcore.io.IoUtils;
import java.io.Closeable; import java.io.Closeable;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.InterruptedIOException;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
@@ -48,17 +50,13 @@ import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CountDownLatch;
import libcore.io.IoUtils; import java.util.concurrent.TimeUnit;
/** /**
* NetworkDiagnostics * NetworkDiagnostics
@@ -186,7 +184,7 @@ public class NetworkDiagnostics {
// TODO: we could use mLinkProperties.isReachable(TEST_DNS6) here, because we won't set any // TODO: we could use mLinkProperties.isReachable(TEST_DNS6) here, because we won't set any
// DNS servers for which isReachable() is false, but since this is diagnostic code, be extra // DNS servers for which isReachable() is false, but since this is diagnostic code, be extra
// careful. // careful.
if (mLinkProperties.hasGlobalIPv6Address() || mLinkProperties.hasIPv6DefaultRoute()) { if (mLinkProperties.hasGlobalIpv6Address() || mLinkProperties.hasIpv6DefaultRoute()) {
mLinkProperties.addDnsServer(TEST_DNS6); mLinkProperties.addDnsServer(TEST_DNS6);
} }

View File

@@ -81,14 +81,14 @@ public class LinkAddressTest {
assertEquals(25, address.getPrefixLength()); assertEquals(25, address.getPrefixLength());
assertEquals(0, address.getFlags()); assertEquals(0, address.getFlags());
assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
assertTrue(address.isIPv4()); assertTrue(address.isIpv4());
address = new LinkAddress(V6_ADDRESS, 127); address = new LinkAddress(V6_ADDRESS, 127);
assertEquals(V6_ADDRESS, address.getAddress()); assertEquals(V6_ADDRESS, address.getAddress());
assertEquals(127, address.getPrefixLength()); assertEquals(127, address.getPrefixLength());
assertEquals(0, address.getFlags()); assertEquals(0, address.getFlags());
assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
assertTrue(address.isIPv6()); assertTrue(address.isIpv6());
// Nonsensical flags/scopes or combinations thereof are acceptable. // Nonsensical flags/scopes or combinations thereof are acceptable.
address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK); address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK);
@@ -96,14 +96,14 @@ public class LinkAddressTest {
assertEquals(64, address.getPrefixLength()); assertEquals(64, address.getPrefixLength());
assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags()); assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags());
assertEquals(RT_SCOPE_LINK, address.getScope()); assertEquals(RT_SCOPE_LINK, address.getScope());
assertTrue(address.isIPv6()); assertTrue(address.isIpv6());
address = new LinkAddress(V4 + "/23", 123, 456); address = new LinkAddress(V4 + "/23", 123, 456);
assertEquals(V4_ADDRESS, address.getAddress()); assertEquals(V4_ADDRESS, address.getAddress());
assertEquals(23, address.getPrefixLength()); assertEquals(23, address.getPrefixLength());
assertEquals(123, address.getFlags()); assertEquals(123, address.getFlags());
assertEquals(456, address.getScope()); assertEquals(456, address.getScope());
assertTrue(address.isIPv4()); assertTrue(address.isIpv4());
// InterfaceAddress doesn't have a constructor. Fetch some from an interface. // InterfaceAddress doesn't have a constructor. Fetch some from an interface.
List<InterfaceAddress> addrs = NetworkInterface.getByName("lo").getInterfaceAddresses(); List<InterfaceAddress> addrs = NetworkInterface.getByName("lo").getInterfaceAddresses();

View File

@@ -405,8 +405,8 @@ public class LinkPropertiesTest {
LinkProperties lp = new LinkProperties(); LinkProperties lp = new LinkProperties();
// No addresses. // No addresses.
assertFalse(lp.hasIPv4Address()); assertFalse(lp.hasIpv4Address());
assertFalse(lp.hasGlobalIPv6Address()); assertFalse(lp.hasGlobalIpv6Address());
// Addresses on stacked links don't count. // Addresses on stacked links don't count.
LinkProperties stacked = new LinkProperties(); LinkProperties stacked = new LinkProperties();
@@ -414,53 +414,53 @@ public class LinkPropertiesTest {
lp.addStackedLink(stacked); lp.addStackedLink(stacked);
stacked.addLinkAddress(LINKADDRV4); stacked.addLinkAddress(LINKADDRV4);
stacked.addLinkAddress(LINKADDRV6); stacked.addLinkAddress(LINKADDRV6);
assertTrue(stacked.hasIPv4Address()); assertTrue(stacked.hasIpv4Address());
assertTrue(stacked.hasGlobalIPv6Address()); assertTrue(stacked.hasGlobalIpv6Address());
assertFalse(lp.hasIPv4Address()); assertFalse(lp.hasIpv4Address());
assertFalse(lp.hasGlobalIPv6Address()); assertFalse(lp.hasGlobalIpv6Address());
lp.removeStackedLink("stacked"); lp.removeStackedLink("stacked");
assertFalse(lp.hasIPv4Address()); assertFalse(lp.hasIpv4Address());
assertFalse(lp.hasGlobalIPv6Address()); assertFalse(lp.hasGlobalIpv6Address());
// Addresses on the base link. // Addresses on the base link.
// Check the return values of hasIPvXAddress and ensure the add/remove methods return true // Check the return values of hasIpvXAddress and ensure the add/remove methods return true
// iff something changes. // iff something changes.
assertEquals(0, lp.getLinkAddresses().size()); assertEquals(0, lp.getLinkAddresses().size());
assertTrue(lp.addLinkAddress(LINKADDRV6)); assertTrue(lp.addLinkAddress(LINKADDRV6));
assertEquals(1, lp.getLinkAddresses().size()); assertEquals(1, lp.getLinkAddresses().size());
assertFalse(lp.hasIPv4Address()); assertFalse(lp.hasIpv4Address());
assertTrue(lp.hasGlobalIPv6Address()); assertTrue(lp.hasGlobalIpv6Address());
assertTrue(lp.removeLinkAddress(LINKADDRV6)); assertTrue(lp.removeLinkAddress(LINKADDRV6));
assertEquals(0, lp.getLinkAddresses().size()); assertEquals(0, lp.getLinkAddresses().size());
assertTrue(lp.addLinkAddress(LINKADDRV6LINKLOCAL)); assertTrue(lp.addLinkAddress(LINKADDRV6LINKLOCAL));
assertEquals(1, lp.getLinkAddresses().size()); assertEquals(1, lp.getLinkAddresses().size());
assertFalse(lp.hasGlobalIPv6Address()); assertFalse(lp.hasGlobalIpv6Address());
assertTrue(lp.addLinkAddress(LINKADDRV4)); assertTrue(lp.addLinkAddress(LINKADDRV4));
assertEquals(2, lp.getLinkAddresses().size()); assertEquals(2, lp.getLinkAddresses().size());
assertTrue(lp.hasIPv4Address()); assertTrue(lp.hasIpv4Address());
assertFalse(lp.hasGlobalIPv6Address()); assertFalse(lp.hasGlobalIpv6Address());
assertTrue(lp.addLinkAddress(LINKADDRV6)); assertTrue(lp.addLinkAddress(LINKADDRV6));
assertEquals(3, lp.getLinkAddresses().size()); assertEquals(3, lp.getLinkAddresses().size());
assertTrue(lp.hasIPv4Address()); assertTrue(lp.hasIpv4Address());
assertTrue(lp.hasGlobalIPv6Address()); assertTrue(lp.hasGlobalIpv6Address());
assertTrue(lp.removeLinkAddress(LINKADDRV6LINKLOCAL)); assertTrue(lp.removeLinkAddress(LINKADDRV6LINKLOCAL));
assertEquals(2, lp.getLinkAddresses().size()); assertEquals(2, lp.getLinkAddresses().size());
assertTrue(lp.hasIPv4Address()); assertTrue(lp.hasIpv4Address());
assertTrue(lp.hasGlobalIPv6Address()); assertTrue(lp.hasGlobalIpv6Address());
// Adding an address twice has no effect. // Adding an address twice has no effect.
// Removing an address that's not present has no effect. // Removing an address that's not present has no effect.
assertFalse(lp.addLinkAddress(LINKADDRV4)); assertFalse(lp.addLinkAddress(LINKADDRV4));
assertEquals(2, lp.getLinkAddresses().size()); assertEquals(2, lp.getLinkAddresses().size());
assertTrue(lp.hasIPv4Address()); assertTrue(lp.hasIpv4Address());
assertTrue(lp.removeLinkAddress(LINKADDRV4)); assertTrue(lp.removeLinkAddress(LINKADDRV4));
assertEquals(1, lp.getLinkAddresses().size()); assertEquals(1, lp.getLinkAddresses().size());
assertFalse(lp.hasIPv4Address()); assertFalse(lp.hasIpv4Address());
assertFalse(lp.removeLinkAddress(LINKADDRV4)); assertFalse(lp.removeLinkAddress(LINKADDRV4));
assertEquals(1, lp.getLinkAddresses().size()); assertEquals(1, lp.getLinkAddresses().size());
@@ -546,8 +546,8 @@ public class LinkPropertiesTest {
assertFalse("v4only:addr+dns", lp4.isProvisioned()); assertFalse("v4only:addr+dns", lp4.isProvisioned());
lp4.addRoute(new RouteInfo(GATEWAY1)); lp4.addRoute(new RouteInfo(GATEWAY1));
assertTrue("v4only:addr+dns+route", lp4.isProvisioned()); assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned()); assertTrue("v4only:addr+dns+route", lp4.isIpv4Provisioned());
assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned()); assertFalse("v4only:addr+dns+route", lp4.isIpv6Provisioned());
LinkProperties lp6 = new LinkProperties(); LinkProperties lp6 = new LinkProperties();
assertFalse("v6only:empty", lp6.isProvisioned()); assertFalse("v6only:empty", lp6.isProvisioned());
@@ -558,11 +558,11 @@ public class LinkPropertiesTest {
lp6.addRoute(new RouteInfo(GATEWAY61)); lp6.addRoute(new RouteInfo(GATEWAY61));
assertFalse("v6only:fe80+dns+route", lp6.isProvisioned()); assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
lp6.addLinkAddress(LINKADDRV6); lp6.addLinkAddress(LINKADDRV6);
assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned()); assertTrue("v6only:fe80+global+dns+route", lp6.isIpv6Provisioned());
assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned()); assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
lp6.removeLinkAddress(LINKADDRV6LINKLOCAL); lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned()); assertFalse("v6only:global+dns+route", lp6.isIpv4Provisioned());
assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned()); assertTrue("v6only:global+dns+route", lp6.isIpv6Provisioned());
assertTrue("v6only:global+dns+route", lp6.isProvisioned()); assertTrue("v6only:global+dns+route", lp6.isProvisioned());
LinkProperties lp46 = new LinkProperties(); LinkProperties lp46 = new LinkProperties();
@@ -572,12 +572,12 @@ public class LinkPropertiesTest {
lp46.addDnsServer(DNS6); lp46.addDnsServer(DNS6);
assertFalse("dualstack:missing-routes", lp46.isProvisioned()); assertFalse("dualstack:missing-routes", lp46.isProvisioned());
lp46.addRoute(new RouteInfo(GATEWAY1)); lp46.addRoute(new RouteInfo(GATEWAY1));
assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned()); assertTrue("dualstack:v4-provisioned", lp46.isIpv4Provisioned());
assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned()); assertFalse("dualstack:v4-provisioned", lp46.isIpv6Provisioned());
assertTrue("dualstack:v4-provisioned", lp46.isProvisioned()); assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
lp46.addRoute(new RouteInfo(GATEWAY61)); lp46.addRoute(new RouteInfo(GATEWAY61));
assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned()); assertTrue("dualstack:both-provisioned", lp46.isIpv4Provisioned());
assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned()); assertTrue("dualstack:both-provisioned", lp46.isIpv6Provisioned());
assertTrue("dualstack:both-provisioned", lp46.isProvisioned()); assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
// A link with an IPv6 address and default route, but IPv4 DNS server. // A link with an IPv6 address and default route, but IPv4 DNS server.
@@ -585,8 +585,8 @@ public class LinkPropertiesTest {
mixed.addLinkAddress(LINKADDRV6); mixed.addLinkAddress(LINKADDRV6);
mixed.addDnsServer(DNS1); mixed.addDnsServer(DNS1);
mixed.addRoute(new RouteInfo(GATEWAY61)); mixed.addRoute(new RouteInfo(GATEWAY61));
assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned()); assertFalse("mixed:addr6+route6+dns4", mixed.isIpv4Provisioned());
assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned()); assertFalse("mixed:addr6+route6+dns4", mixed.isIpv6Provisioned());
assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned()); assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
} }
@@ -617,16 +617,16 @@ public class LinkPropertiesTest {
v6lp.addLinkAddress(LINKADDRV6); v6lp.addLinkAddress(LINKADDRV6);
v6lp.addRoute(new RouteInfo(GATEWAY61)); v6lp.addRoute(new RouteInfo(GATEWAY61));
v6lp.addDnsServer(DNS6); v6lp.addDnsServer(DNS6);
assertFalse(v6lp.isIPv4Provisioned()); assertFalse(v6lp.isIpv4Provisioned());
assertTrue(v6lp.isIPv6Provisioned()); assertTrue(v6lp.isIpv6Provisioned());
assertTrue(v6lp.isProvisioned()); assertTrue(v6lp.isProvisioned());
LinkProperties v46lp = new LinkProperties(v6lp); LinkProperties v46lp = new LinkProperties(v6lp);
v46lp.addLinkAddress(LINKADDRV4); v46lp.addLinkAddress(LINKADDRV4);
v46lp.addRoute(new RouteInfo(GATEWAY1)); v46lp.addRoute(new RouteInfo(GATEWAY1));
v46lp.addDnsServer(DNS1); v46lp.addDnsServer(DNS1);
assertTrue(v46lp.isIPv4Provisioned()); assertTrue(v46lp.isIpv4Provisioned());
assertTrue(v46lp.isIPv6Provisioned()); assertTrue(v46lp.isIpv6Provisioned());
assertTrue(v46lp.isProvisioned()); assertTrue(v46lp.isProvisioned());
assertEquals(ProvisioningChange.STILL_PROVISIONED, assertEquals(ProvisioningChange.STILL_PROVISIONED,