Merge "Fix Automated API Review issues." am: acb5eca325 am: f1f3b08982

am: affa3f497d

Change-Id: Iba1630161579571d4975aba9bbd5c767f82c8a98
This commit is contained in:
Paul Hu 2019-03-21 11:54:51 -07:00 • committed by android-build-merger
commit 2e2bc9c173

View file

@ -26,6 +26,7 @@ import static android.system.OsConstants.RT_SCOPE_SITE;
import static android.system.OsConstants.RT_SCOPE_UNIVERSE;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
@ -107,8 +108,8 @@ public class LinkAddress implements Parcelable {
*
* Per RFC 4193 section 8, fc00::/7 identifies these addresses.
*/
private boolean isIPv6ULA() {
if (isIPv6()) {
private boolean isIpv6ULA() {
if (isIpv6()) {
byte[] bytes = address.getAddress();
return ((bytes[0] & (byte)0xfe) == (byte)0xfc);
}
@ -121,17 +122,29 @@ public class LinkAddress implements Parcelable {
*/
@TestApi
@SystemApi
public boolean isIPv6() {
public boolean isIpv6() {
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.
* @hide
*/
@TestApi
@SystemApi
public boolean isIPv4() {
public boolean isIpv4() {
return address instanceof Inet4Address;
}
@ -217,7 +230,7 @@ public class LinkAddress implements Parcelable {
*/
@SystemApi
@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.
// TODO: consider rejecting mapped IPv4 addresses such as "::ffff:192.0.2.5/24".
Pair<InetAddress, Integer> ipAndMask = NetworkUtils.parseIpAndMask(address);
@ -276,7 +289,10 @@ public class LinkAddress implements Parcelable {
*/
@TestApi
@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;
}
@ -331,10 +347,10 @@ public class LinkAddress implements Parcelable {
* state has cleared either DAD has succeeded or failed, and both
* flags are cleared regardless).
*/
return (scope == RT_SCOPE_UNIVERSE &&
!isIPv6ULA() &&
(flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED)) == 0L &&
((flags & IFA_F_TENTATIVE) == 0L || (flags & IFA_F_OPTIMISTIC) != 0L));
return (scope == RT_SCOPE_UNIVERSE
&& !isIpv6ULA()
&& (flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED)) == 0L
&& ((flags & IFA_F_TENTATIVE) == 0L || (flags & IFA_F_OPTIMISTIC) != 0L));
}
/**