Loading api/current.txt +1 −2 Original line number Diff line number Diff line Loading @@ -16029,9 +16029,8 @@ package android.net { method public int describeContents(); method public java.net.InetAddress getAddress(); method public int getFlags(); method public int getNetworkPrefixLength(); method public int getPrefixLength(); method public int getScope(); method public boolean isSameAddressAs(android.net.LinkAddress); method public void writeToParcel(android.os.Parcel, int); } core/java/android/net/LinkAddress.java +21 −14 Original line number Diff line number Diff line Loading @@ -39,18 +39,13 @@ import static android.system.OsConstants.RT_SCOPE_UNIVERSE; * <ul> * <li>An IP address and prefix length (e.g., {@code 2001:db8::1/64} or {@code 192.0.2.1/24}). * The address must be unicast, as multicast addresses cannot be assigned to interfaces. * <li>Address flags: A bitmask of {@code IFA_F_*} values representing properties * of the address. * <li>Address scope: An integer defining the scope in which the address is unique (e.g., * {@code RT_SCOPE_LINK} or {@code RT_SCOPE_SITE}). * <ul> *<p> * When constructing a {@code LinkAddress}, the IP address and prefix are required. The flags and * scope are optional. If they are not specified, the flags are set to zero, and the scope will be * determined based on the IP address (e.g., link-local addresses will be created with a scope of * {@code RT_SCOPE_LINK}, global addresses with {@code RT_SCOPE_UNIVERSE}, * etc.) If they are specified, they are not checked for validity. * * <li>Address flags: A bitmask of {@code OsConstants.IFA_F_*} values representing properties * of the address (e.g., {@code android.system.OsConstants.IFA_F_OPTIMISTIC}). * <li>Address scope: One of the {@code OsConstants.IFA_F_*} values; defines the scope in which * the address is unique (e.g., * {@code android.system.OsConstants.RT_SCOPE_LINK} or * {@code android.system.OsConstants.RT_SCOPE_UNIVERSE}). * </ul> */ public class LinkAddress implements Parcelable { /** Loading Loading @@ -202,7 +197,9 @@ public class LinkAddress implements Parcelable { /** * Compares this {@code LinkAddress} instance against {@code obj}. Two addresses are equal if * their address, prefix length, flags and scope are equal. * their address, prefix length, flags and scope are equal. Thus, for example, two addresses * that have the same address and prefix length are not equal if one of them is deprecated and * the other is not. * * @param obj the object to be tested for equality. * @return {@code true} if both objects are equal, {@code false} otherwise. Loading Loading @@ -236,6 +233,7 @@ public class LinkAddress implements Parcelable { * @param other the {@code LinkAddress} to compare to. * @return {@code true} if both objects have the same address and prefix length, {@code false} * otherwise. * @hide */ public boolean isSameAddressAs(LinkAddress other) { return address.equals(other.address) && prefixLength == other.prefixLength; Loading @@ -251,10 +249,19 @@ public class LinkAddress implements Parcelable { /** * Returns the prefix length of this {@code LinkAddress}. */ public int getNetworkPrefixLength() { public int getPrefixLength() { return prefixLength; } /** * Returns the prefix length of this {@code LinkAddress}. * TODO: Delete all callers and remove in favour of getPrefixLength(). * @hide */ public int getNetworkPrefixLength() { return getPrefixLength(); } /** * Returns the flags of this {@code LinkAddress}. */ Loading core/java/android/net/RouteInfo.java +9 −9 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public final class RouteInfo implements Parcelable { mHasGateway = (!gateway.isAnyLocalAddress()); mDestination = new LinkAddress(NetworkUtils.getNetworkPart(destination.getAddress(), destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength()); destination.getPrefixLength()), destination.getPrefixLength()); if ((destination.getAddress() instanceof Inet4Address && (gateway instanceof Inet4Address == false)) || (destination.getAddress() instanceof Inet6Address && Loading Loading @@ -210,18 +210,18 @@ public final class RouteInfo implements Parcelable { private boolean isHost() { return (mDestination.getAddress() instanceof Inet4Address && mDestination.getNetworkPrefixLength() == 32) || mDestination.getPrefixLength() == 32) || (mDestination.getAddress() instanceof Inet6Address && mDestination.getNetworkPrefixLength() == 128); mDestination.getPrefixLength() == 128); } private boolean isDefault() { boolean val = false; if (mGateway != null) { if (mGateway instanceof Inet4Address) { val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); val = (mDestination == null || mDestination.getPrefixLength() == 0); } else { val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); val = (mDestination == null || mDestination.getPrefixLength() == 0); } } return val; Loading Loading @@ -306,7 +306,7 @@ public final class RouteInfo implements Parcelable { // match the route destination and destination with prefix length InetAddress dstNet = NetworkUtils.getNetworkPart(destination, mDestination.getNetworkPrefixLength()); mDestination.getPrefixLength()); return mDestination.getAddress().equals(dstNet); } Loading @@ -328,8 +328,8 @@ public final class RouteInfo implements Parcelable { for (RouteInfo route : routes) { if (NetworkUtils.addressTypeMatches(route.mDestination.getAddress(), dest)) { if ((bestRoute != null) && (bestRoute.mDestination.getNetworkPrefixLength() >= route.mDestination.getNetworkPrefixLength())) { (bestRoute.mDestination.getPrefixLength() >= route.mDestination.getPrefixLength())) { continue; } if (route.matches(dest)) bestRoute = route; Loading Loading @@ -392,7 +392,7 @@ public final class RouteInfo implements Parcelable { } else { dest.writeByte((byte) 1); dest.writeByteArray(mDestination.getAddress().getAddress()); dest.writeInt(mDestination.getNetworkPrefixLength()); dest.writeInt(mDestination.getPrefixLength()); } if (mGateway == null) { Loading core/tests/coretests/src/android/net/LinkAddressTest.java +6 −6 Original line number Diff line number Diff line Loading @@ -56,26 +56,26 @@ public class LinkAddressTest extends AndroidTestCase { // Valid addresses work as expected. address = new LinkAddress(V4_ADDRESS, 25); assertEquals(V4_ADDRESS, address.getAddress()); assertEquals(25, address.getNetworkPrefixLength()); assertEquals(25, address.getPrefixLength()); assertEquals(0, address.getFlags()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); address = new LinkAddress(V6_ADDRESS, 127); assertEquals(V6_ADDRESS, address.getAddress()); assertEquals(127, address.getNetworkPrefixLength()); assertEquals(127, address.getPrefixLength()); assertEquals(0, address.getFlags()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); // Nonsensical flags/scopes or combinations thereof are acceptable. address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK); assertEquals(V6_ADDRESS, address.getAddress()); assertEquals(64, address.getNetworkPrefixLength()); assertEquals(64, address.getPrefixLength()); assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags()); assertEquals(RT_SCOPE_LINK, address.getScope()); address = new LinkAddress(V4 + "/23", 123, 456); assertEquals(V4_ADDRESS, address.getAddress()); assertEquals(23, address.getNetworkPrefixLength()); assertEquals(23, address.getPrefixLength()); assertEquals(123, address.getFlags()); assertEquals(456, address.getScope()); Loading @@ -94,10 +94,10 @@ public class LinkAddressTest extends AndroidTestCase { } assertEquals(NetworkUtils.numericToInetAddress("127.0.0.1"), ipv4Loopback.getAddress()); assertEquals(8, ipv4Loopback.getNetworkPrefixLength()); assertEquals(8, ipv4Loopback.getPrefixLength()); assertEquals(NetworkUtils.numericToInetAddress("::1"), ipv6Loopback.getAddress()); assertEquals(128, ipv6Loopback.getNetworkPrefixLength()); assertEquals(128, ipv6Loopback.getPrefixLength()); // Null addresses are rejected. try { Loading services/core/java/com/android/server/ConnectivityService.java +1 −1 Original line number Diff line number Diff line Loading @@ -1669,7 +1669,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { continue; } int prefix = destination.getNetworkPrefixLength(); int prefix = destination.getPrefixLength(); InetAddress addrMasked = NetworkUtils.getNetworkPart(address, prefix); InetAddress destMasked = NetworkUtils.getNetworkPart(destination.getAddress(), prefix); Loading Loading
api/current.txt +1 −2 Original line number Diff line number Diff line Loading @@ -16029,9 +16029,8 @@ package android.net { method public int describeContents(); method public java.net.InetAddress getAddress(); method public int getFlags(); method public int getNetworkPrefixLength(); method public int getPrefixLength(); method public int getScope(); method public boolean isSameAddressAs(android.net.LinkAddress); method public void writeToParcel(android.os.Parcel, int); }
core/java/android/net/LinkAddress.java +21 −14 Original line number Diff line number Diff line Loading @@ -39,18 +39,13 @@ import static android.system.OsConstants.RT_SCOPE_UNIVERSE; * <ul> * <li>An IP address and prefix length (e.g., {@code 2001:db8::1/64} or {@code 192.0.2.1/24}). * The address must be unicast, as multicast addresses cannot be assigned to interfaces. * <li>Address flags: A bitmask of {@code IFA_F_*} values representing properties * of the address. * <li>Address scope: An integer defining the scope in which the address is unique (e.g., * {@code RT_SCOPE_LINK} or {@code RT_SCOPE_SITE}). * <ul> *<p> * When constructing a {@code LinkAddress}, the IP address and prefix are required. The flags and * scope are optional. If they are not specified, the flags are set to zero, and the scope will be * determined based on the IP address (e.g., link-local addresses will be created with a scope of * {@code RT_SCOPE_LINK}, global addresses with {@code RT_SCOPE_UNIVERSE}, * etc.) If they are specified, they are not checked for validity. * * <li>Address flags: A bitmask of {@code OsConstants.IFA_F_*} values representing properties * of the address (e.g., {@code android.system.OsConstants.IFA_F_OPTIMISTIC}). * <li>Address scope: One of the {@code OsConstants.IFA_F_*} values; defines the scope in which * the address is unique (e.g., * {@code android.system.OsConstants.RT_SCOPE_LINK} or * {@code android.system.OsConstants.RT_SCOPE_UNIVERSE}). * </ul> */ public class LinkAddress implements Parcelable { /** Loading Loading @@ -202,7 +197,9 @@ public class LinkAddress implements Parcelable { /** * Compares this {@code LinkAddress} instance against {@code obj}. Two addresses are equal if * their address, prefix length, flags and scope are equal. * their address, prefix length, flags and scope are equal. Thus, for example, two addresses * that have the same address and prefix length are not equal if one of them is deprecated and * the other is not. * * @param obj the object to be tested for equality. * @return {@code true} if both objects are equal, {@code false} otherwise. Loading Loading @@ -236,6 +233,7 @@ public class LinkAddress implements Parcelable { * @param other the {@code LinkAddress} to compare to. * @return {@code true} if both objects have the same address and prefix length, {@code false} * otherwise. * @hide */ public boolean isSameAddressAs(LinkAddress other) { return address.equals(other.address) && prefixLength == other.prefixLength; Loading @@ -251,10 +249,19 @@ public class LinkAddress implements Parcelable { /** * Returns the prefix length of this {@code LinkAddress}. */ public int getNetworkPrefixLength() { public int getPrefixLength() { return prefixLength; } /** * Returns the prefix length of this {@code LinkAddress}. * TODO: Delete all callers and remove in favour of getPrefixLength(). * @hide */ public int getNetworkPrefixLength() { return getPrefixLength(); } /** * Returns the flags of this {@code LinkAddress}. */ Loading
core/java/android/net/RouteInfo.java +9 −9 Original line number Diff line number Diff line Loading @@ -119,7 +119,7 @@ public final class RouteInfo implements Parcelable { mHasGateway = (!gateway.isAnyLocalAddress()); mDestination = new LinkAddress(NetworkUtils.getNetworkPart(destination.getAddress(), destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength()); destination.getPrefixLength()), destination.getPrefixLength()); if ((destination.getAddress() instanceof Inet4Address && (gateway instanceof Inet4Address == false)) || (destination.getAddress() instanceof Inet6Address && Loading Loading @@ -210,18 +210,18 @@ public final class RouteInfo implements Parcelable { private boolean isHost() { return (mDestination.getAddress() instanceof Inet4Address && mDestination.getNetworkPrefixLength() == 32) || mDestination.getPrefixLength() == 32) || (mDestination.getAddress() instanceof Inet6Address && mDestination.getNetworkPrefixLength() == 128); mDestination.getPrefixLength() == 128); } private boolean isDefault() { boolean val = false; if (mGateway != null) { if (mGateway instanceof Inet4Address) { val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); val = (mDestination == null || mDestination.getPrefixLength() == 0); } else { val = (mDestination == null || mDestination.getNetworkPrefixLength() == 0); val = (mDestination == null || mDestination.getPrefixLength() == 0); } } return val; Loading Loading @@ -306,7 +306,7 @@ public final class RouteInfo implements Parcelable { // match the route destination and destination with prefix length InetAddress dstNet = NetworkUtils.getNetworkPart(destination, mDestination.getNetworkPrefixLength()); mDestination.getPrefixLength()); return mDestination.getAddress().equals(dstNet); } Loading @@ -328,8 +328,8 @@ public final class RouteInfo implements Parcelable { for (RouteInfo route : routes) { if (NetworkUtils.addressTypeMatches(route.mDestination.getAddress(), dest)) { if ((bestRoute != null) && (bestRoute.mDestination.getNetworkPrefixLength() >= route.mDestination.getNetworkPrefixLength())) { (bestRoute.mDestination.getPrefixLength() >= route.mDestination.getPrefixLength())) { continue; } if (route.matches(dest)) bestRoute = route; Loading Loading @@ -392,7 +392,7 @@ public final class RouteInfo implements Parcelable { } else { dest.writeByte((byte) 1); dest.writeByteArray(mDestination.getAddress().getAddress()); dest.writeInt(mDestination.getNetworkPrefixLength()); dest.writeInt(mDestination.getPrefixLength()); } if (mGateway == null) { Loading
core/tests/coretests/src/android/net/LinkAddressTest.java +6 −6 Original line number Diff line number Diff line Loading @@ -56,26 +56,26 @@ public class LinkAddressTest extends AndroidTestCase { // Valid addresses work as expected. address = new LinkAddress(V4_ADDRESS, 25); assertEquals(V4_ADDRESS, address.getAddress()); assertEquals(25, address.getNetworkPrefixLength()); assertEquals(25, address.getPrefixLength()); assertEquals(0, address.getFlags()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); address = new LinkAddress(V6_ADDRESS, 127); assertEquals(V6_ADDRESS, address.getAddress()); assertEquals(127, address.getNetworkPrefixLength()); assertEquals(127, address.getPrefixLength()); assertEquals(0, address.getFlags()); assertEquals(RT_SCOPE_UNIVERSE, address.getScope()); // Nonsensical flags/scopes or combinations thereof are acceptable. address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK); assertEquals(V6_ADDRESS, address.getAddress()); assertEquals(64, address.getNetworkPrefixLength()); assertEquals(64, address.getPrefixLength()); assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags()); assertEquals(RT_SCOPE_LINK, address.getScope()); address = new LinkAddress(V4 + "/23", 123, 456); assertEquals(V4_ADDRESS, address.getAddress()); assertEquals(23, address.getNetworkPrefixLength()); assertEquals(23, address.getPrefixLength()); assertEquals(123, address.getFlags()); assertEquals(456, address.getScope()); Loading @@ -94,10 +94,10 @@ public class LinkAddressTest extends AndroidTestCase { } assertEquals(NetworkUtils.numericToInetAddress("127.0.0.1"), ipv4Loopback.getAddress()); assertEquals(8, ipv4Loopback.getNetworkPrefixLength()); assertEquals(8, ipv4Loopback.getPrefixLength()); assertEquals(NetworkUtils.numericToInetAddress("::1"), ipv6Loopback.getAddress()); assertEquals(128, ipv6Loopback.getNetworkPrefixLength()); assertEquals(128, ipv6Loopback.getPrefixLength()); // Null addresses are rejected. try { Loading
services/core/java/com/android/server/ConnectivityService.java +1 −1 Original line number Diff line number Diff line Loading @@ -1669,7 +1669,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { continue; } int prefix = destination.getNetworkPrefixLength(); int prefix = destination.getPrefixLength(); InetAddress addrMasked = NetworkUtils.getNetworkPart(address, prefix); InetAddress destMasked = NetworkUtils.getNetworkPart(destination.getAddress(), prefix); Loading