From 590d408a0629bdd4deff9d775c746592408ba51a Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 17 Jan 2020 15:28:50 -0800 Subject: [PATCH 1/3] Added expiration time and deprecation time support Added link address deprecation time and expiration time for SSC mode 3 support. Bug: 135717900 Bug: 142949345 Test: LinkAddressTest Merged-In: Ibc030d2a70ded66e00dd3bdae209609b9118de78 Change-Id: Ibc030d2a70ded66e00dd3bdae209609b9118de78 (cherry picked from commit 05d5b3b59f3cb212e066a4a68c768643a073afce) --- core/java/android/net/LinkAddress.java | 174 ++++++++++++++++-- .../java/android/net/LinkAddressTest.java | 83 ++++++++- 2 files changed, 245 insertions(+), 12 deletions(-) diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java index bf8b38fc7f..8d9f0d068a 100644 --- a/core/java/android/net/LinkAddress.java +++ b/core/java/android/net/LinkAddress.java @@ -19,6 +19,7 @@ package android.net; import static android.system.OsConstants.IFA_F_DADFAILED; import static android.system.OsConstants.IFA_F_DEPRECATED; import static android.system.OsConstants.IFA_F_OPTIMISTIC; +import static android.system.OsConstants.IFA_F_PERMANENT; import static android.system.OsConstants.IFA_F_TENTATIVE; import static android.system.OsConstants.RT_SCOPE_HOST; import static android.system.OsConstants.RT_SCOPE_LINK; @@ -34,6 +35,7 @@ import android.compat.annotation.UnsupportedAppUsage; import android.os.Build; import android.os.Parcel; import android.os.Parcelable; +import android.os.SystemClock; import android.util.Pair; import java.net.Inet4Address; @@ -41,6 +43,7 @@ import java.net.Inet6Address; import java.net.InetAddress; import java.net.InterfaceAddress; import java.net.UnknownHostException; +import java.util.Objects; /** * Identifies an IP address on a network link. @@ -58,6 +61,21 @@ import java.net.UnknownHostException; * */ public class LinkAddress implements Parcelable { + + /** + * Indicates the deprecation or expiration time is unknown + * @hide + */ + @SystemApi + public static final long LIFETIME_UNKNOWN = -1; + + /** + * Indicates this address is permanent. + * @hide + */ + @SystemApi + public static final long LIFETIME_PERMANENT = Long.MAX_VALUE; + /** * IPv4 or IPv6 address. */ @@ -71,7 +89,9 @@ public class LinkAddress implements Parcelable { private int prefixLength; /** - * Address flags. A bitmask of IFA_F_* values. + * Address flags. A bitmask of {@code IFA_F_*} values. Note that {@link #getFlags()} may not + * return these exact values. For example, it may set or clear the {@code IFA_F_DEPRECATED} + * flag depending on the current preferred lifetime. */ private int flags; @@ -80,6 +100,23 @@ public class LinkAddress implements Parcelable { */ private int scope; + /** + * The time, as reported by {@link SystemClock#elapsedRealtime}, when this LinkAddress will be + * or was deprecated. {@link #LIFETIME_UNKNOWN} indicates this information is not available. At + * the time existing connections can still use this address until it expires, but new + * connections should use the new address. {@link #LIFETIME_PERMANENT} indicates this + * {@link LinkAddress} will never be deprecated. + */ + private long deprecationTime; + + /** + * The time, as reported by {@link SystemClock#elapsedRealtime}, when this {@link LinkAddress} + * will expire and be removed from the interface. {@link #LIFETIME_UNKNOWN} indicates this + * information is not available. {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} + * will never expire. + */ + private long expirationTime; + /** * Utility function to determines the scope of a unicast address. Per RFC 4291 section 2.5 and * RFC 6724 section 3.2. @@ -152,7 +189,8 @@ public class LinkAddress implements Parcelable { /** * Utility function for the constructors. */ - private void init(InetAddress address, int prefixLength, int flags, int scope) { + private void init(InetAddress address, int prefixLength, int flags, int scope, + long deprecationTime, long expirationTime) { if (address == null || address.isMulticastAddress() || prefixLength < 0 || @@ -161,15 +199,42 @@ public class LinkAddress implements Parcelable { throw new IllegalArgumentException("Bad LinkAddress params " + address + "/" + prefixLength); } + + // deprecation time and expiration time must be both provided, or neither. + if ((deprecationTime == LIFETIME_UNKNOWN) != (expirationTime == LIFETIME_UNKNOWN)) { + throw new IllegalArgumentException( + "Must not specify only one of deprecation time and expiration time"); + } + + // deprecation time needs to be a positive value. + if (deprecationTime != LIFETIME_UNKNOWN && deprecationTime < 0) { + throw new IllegalArgumentException("invalid deprecation time " + deprecationTime); + } + + // expiration time needs to be a positive value. + if (expirationTime != LIFETIME_UNKNOWN && expirationTime < 0) { + throw new IllegalArgumentException("invalid expiration time " + expirationTime); + } + + // expiration time can't be earlier than deprecation time + if (deprecationTime != LIFETIME_UNKNOWN && expirationTime != LIFETIME_UNKNOWN + && expirationTime < deprecationTime) { + throw new IllegalArgumentException("expiration earlier than deprecation (" + + deprecationTime + ", " + expirationTime + ")"); + } + this.address = address; this.prefixLength = prefixLength; this.flags = flags; this.scope = scope; + this.deprecationTime = deprecationTime; + this.expirationTime = expirationTime; } /** * Constructs a new {@code LinkAddress} from an {@code InetAddress} and prefix length, with * the specified flags and scope. Flags and scope are not checked for validity. + * * @param address The IP address. * @param prefixLength The prefix length. Must be >= 0 and <= (32 or 128) (IPv4 or IPv6). * @param flags A bitmask of {@code IFA_F_*} values representing properties of the address. @@ -181,7 +246,39 @@ public class LinkAddress implements Parcelable { @TestApi public LinkAddress(@NonNull InetAddress address, @IntRange(from = 0, to = 128) int prefixLength, int flags, int scope) { - init(address, prefixLength, flags, scope); + init(address, prefixLength, flags, scope, LIFETIME_UNKNOWN, LIFETIME_UNKNOWN); + } + + /** + * Constructs a new {@code LinkAddress} from an {@code InetAddress}, prefix length, with + * the specified flags, scope, deprecation time, and expiration time. Flags and scope are not + * checked for validity. The value of the {@code IFA_F_DEPRECATED} and {@code IFA_F_PERMANENT} + * flag will be adjusted based on the passed-in lifetimes. + * + * @param address The IP address. + * @param prefixLength The prefix length. Must be >= 0 and <= (32 or 128) (IPv4 or IPv6). + * @param flags A bitmask of {@code IFA_F_*} values representing properties of the address. + * @param scope An integer defining the scope in which the address is unique (e.g., + * {@link OsConstants#RT_SCOPE_LINK} or {@link OsConstants#RT_SCOPE_SITE}). + * @param deprecationTime The time, as reported by {@link SystemClock#elapsedRealtime}, when + * this {@link LinkAddress} will be or was deprecated. + * {@link #LIFETIME_UNKNOWN} indicates this information is not available. + * At the time existing connections can still use this address until it + * expires, but new connections should use the new address. + * {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} will + * never be deprecated. + * @param expirationTime The time, as reported by {@link SystemClock#elapsedRealtime}, when this + * {@link LinkAddress} will expire and be removed from the interface. + * {@link #LIFETIME_UNKNOWN} indicates this information is not available. + * {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} will + * never expire. + * @hide + */ + @SystemApi + @TestApi + public LinkAddress(@NonNull InetAddress address, @IntRange(from = 0, to = 128) int prefixLength, + int flags, int scope, long deprecationTime, long expirationTime) { + init(address, prefixLength, flags, scope, deprecationTime, expirationTime); } /** @@ -237,7 +334,7 @@ public class LinkAddress implements Parcelable { // 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 ipAndMask = NetworkUtils.parseIpAndMask(address); - init(ipAndMask.first, ipAndMask.second, flags, scope); + init(ipAndMask.first, ipAndMask.second, flags, scope, LIFETIME_UNKNOWN, LIFETIME_UNKNOWN); } /** @@ -265,10 +362,12 @@ public class LinkAddress implements Parcelable { return false; } LinkAddress linkAddress = (LinkAddress) obj; - return this.address.equals(linkAddress.address) && - this.prefixLength == linkAddress.prefixLength && - this.flags == linkAddress.flags && - this.scope == linkAddress.scope; + return this.address.equals(linkAddress.address) + && this.prefixLength == linkAddress.prefixLength + && this.flags == linkAddress.flags + && this.scope == linkAddress.scope + && this.deprecationTime == linkAddress.deprecationTime + && this.expirationTime == linkAddress.expirationTime; } /** @@ -276,7 +375,7 @@ public class LinkAddress implements Parcelable { */ @Override public int hashCode() { - return address.hashCode() + 11 * prefixLength + 19 * flags + 43 * scope; + return Objects.hash(address, prefixLength, flags, scope, deprecationTime, expirationTime); } /** @@ -329,6 +428,25 @@ public class LinkAddress implements Parcelable { * Returns the flags of this {@code LinkAddress}. */ public int getFlags() { + int flags = this.flags; + if (deprecationTime != LIFETIME_UNKNOWN) { + if (SystemClock.elapsedRealtime() >= deprecationTime) { + flags |= IFA_F_DEPRECATED; + } else { + // If deprecation time is in the future, or permanent. + flags &= ~IFA_F_DEPRECATED; + } + } + + if (expirationTime == LIFETIME_PERMANENT) { + flags |= IFA_F_PERMANENT; + } else if (expirationTime != LIFETIME_UNKNOWN) { + // If we know this address expired or will expire in the future or, then this address + // should not be permanent. + flags &= ~IFA_F_PERMANENT; + } + + // Do no touch the original flags. Return the adjusted flags here. return flags; } @@ -340,7 +458,35 @@ public class LinkAddress implements Parcelable { } /** - * Returns true if this {@code LinkAddress} is global scope and preferred. + * @return The time that this address will be deprecated. At the time the existing connection + * can still use this address until it expires, but the new connection should use the new + * address. This is the EPOCH time in milliseconds. 0 indicates this information is not + * available. + * + * @hide + */ + @SystemApi + @TestApi + public long getDeprecationTime() { + return deprecationTime; + } + + /** + * @return The time that this address will expire and will be no longer valid. This is the EPOCH + * time in milliseconds. 0 indicates this information is not available. + * + * @hide + */ + @SystemApi + @TestApi + public long getExpirationTime() { + return expirationTime; + } + + /** + * Returns true if this {@code LinkAddress} is global scope and preferred (i.e., not currently + * deprecated). + * * @hide */ @TestApi @@ -352,6 +498,7 @@ public class LinkAddress implements Parcelable { * state has cleared either DAD has succeeded or failed, and both * flags are cleared regardless). */ + int flags = getFlags(); return (scope == RT_SCOPE_UNIVERSE && !isIpv6ULA() && (flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED)) == 0L @@ -373,6 +520,8 @@ public class LinkAddress implements Parcelable { dest.writeInt(prefixLength); dest.writeInt(this.flags); dest.writeInt(scope); + dest.writeLong(deprecationTime); + dest.writeLong(expirationTime); } /** @@ -392,7 +541,10 @@ public class LinkAddress implements Parcelable { int prefixLength = in.readInt(); int flags = in.readInt(); int scope = in.readInt(); - return new LinkAddress(address, prefixLength, flags, scope); + long deprecationTime = in.readLong(); + long expirationTime = in.readLong(); + return new LinkAddress(address, prefixLength, flags, scope, deprecationTime, + expirationTime); } public LinkAddress[] newArray(int size) { diff --git a/tests/net/common/java/android/net/LinkAddressTest.java b/tests/net/common/java/android/net/LinkAddressTest.java index b2e573b6c7..096f7bdca0 100644 --- a/tests/net/common/java/android/net/LinkAddressTest.java +++ b/tests/net/common/java/android/net/LinkAddressTest.java @@ -38,6 +38,8 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import android.os.SystemClock; + import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -316,11 +318,83 @@ public class LinkAddressTest { l = new LinkAddress(V6_ADDRESS, 64, 123, 456); assertParcelingIsLossless(l); + l = new LinkAddress(V6_ADDRESS, 64, 123, 456, + 1L, 3600000L); + assertParcelingIsLossless(l); l = new LinkAddress(V4 + "/28", IFA_F_PERMANENT, RT_SCOPE_LINK); - assertParcelSane(l, 4); + assertParcelSane(l, 6); } + @Test + public void testDeprecationTime() { + try { + new LinkAddress(V6_ADDRESS, 64, 0, 456, + LinkAddress.LIFETIME_UNKNOWN, + SystemClock.elapsedRealtime() + 200000); + fail("Only one time provided should cause exception"); + } catch (IllegalArgumentException expected) { } + + try { + new LinkAddress(V6_ADDRESS, 64, 0, 456, + SystemClock.elapsedRealtime() - 100000, + SystemClock.elapsedRealtime() - 200000); + fail("deprecation time later than expiration time should cause exception"); + } catch (IllegalArgumentException expected) { } + + try { + new LinkAddress(V6_ADDRESS, 64, 0, 456, + -2, SystemClock.elapsedRealtime()); + fail("negative deprecation time should cause exception"); + } catch (IllegalArgumentException expected) { } + } + + @Test + public void testExpirationTime() { + try { + new LinkAddress(V6_ADDRESS, 64, 0, 456, + SystemClock.elapsedRealtime() + 200000, + LinkAddress.LIFETIME_UNKNOWN); + fail("Only one time provided should cause exception"); + } catch (IllegalArgumentException expected) { } + + try { + new LinkAddress(V6_ADDRESS, 64, 0, 456, + SystemClock.elapsedRealtime() - 10000, -2); + fail("negative expiration time should cause exception"); + } catch (IllegalArgumentException expected) { } + } + + @Test + public void testGetFlags() { + LinkAddress l = new LinkAddress(V6_ADDRESS, 64, 123, RT_SCOPE_HOST); + assertEquals(123, l.getFlags()); + + // Test if deprecated bit was added/remove automatically based on the provided deprecation + // time + l = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_HOST, + SystemClock.elapsedRealtime() - 100000, LinkAddress.LIFETIME_PERMANENT); + // Check if the flag is added automatically. + assertTrue((l.getFlags() & IFA_F_DEPRECATED) != 0); + + l = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_HOST, + SystemClock.elapsedRealtime() + 100000, LinkAddress.LIFETIME_PERMANENT); + // Check if the flag is removed automatically. + assertTrue((l.getFlags() & IFA_F_DEPRECATED) == 0); + + l = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_HOST, + LinkAddress.LIFETIME_PERMANENT, LinkAddress.LIFETIME_PERMANENT); + // Check if the permanent flag is added. + assertTrue((l.getFlags() & IFA_F_PERMANENT) != 0); + + l = new LinkAddress(V6_ADDRESS, 64, IFA_F_PERMANENT, RT_SCOPE_HOST, + SystemClock.elapsedRealtime() - 100000, + SystemClock.elapsedRealtime() + 100000); + // Check if the permanent flag is removed + assertTrue((l.getFlags() & IFA_F_PERMANENT) == 0); + } + + private void assertGlobalPreferred(LinkAddress l, String msg) { assertTrue(msg, l.isGlobalPreferred()); } @@ -389,5 +463,12 @@ public class LinkAddressTest { (IFA_F_TEMPORARY|IFA_F_TENTATIVE|IFA_F_OPTIMISTIC), RT_SCOPE_UNIVERSE); assertGlobalPreferred(l, "v6,global,tempaddr+optimistic"); + + l = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, + RT_SCOPE_UNIVERSE, SystemClock.elapsedRealtime() + 100000, + SystemClock.elapsedRealtime() + 200000); + // Although the deprecated bit is set, but the deprecation time is in the future, test + // if the flag is removed automatically. + assertGlobalPreferred(l, "v6,global,tempaddr+deprecated in the future"); } } From 632771fd435d150881644a192902430cdfff4e0a Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 23 Jan 2020 22:09:29 -0800 Subject: [PATCH 2/3] Disabled the tests Will re-enable after fixing the negative time issue Test: LinkAddressTest Bug: 148257086 Merged-In: Ia6ce0608a2ce95be980e4f9ea62315076c4453be Change-Id: Ia6ce0608a2ce95be980e4f9ea62315076c4453be (cherry picked from commit d40e5498d0c559503bfdf0815e17e583357f3941) --- tests/net/common/java/android/net/LinkAddressTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/net/common/java/android/net/LinkAddressTest.java b/tests/net/common/java/android/net/LinkAddressTest.java index 096f7bdca0..e566e44c81 100644 --- a/tests/net/common/java/android/net/LinkAddressTest.java +++ b/tests/net/common/java/android/net/LinkAddressTest.java @@ -326,6 +326,7 @@ public class LinkAddressTest { assertParcelSane(l, 6); } + /* @Test public void testDeprecationTime() { try { @@ -392,7 +393,7 @@ public class LinkAddressTest { SystemClock.elapsedRealtime() + 100000); // Check if the permanent flag is removed assertTrue((l.getFlags() & IFA_F_PERMANENT) == 0); - } + }*/ private void assertGlobalPreferred(LinkAddress l, String msg) { From d956e5b32680d1e4cac41e59e3a7d7bca694d35f Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Sun, 26 Jan 2020 15:52:11 -0800 Subject: [PATCH 3/3] Fixed the documentation and unit tests Fixed the documentation and re-eanble the broken unit tests. Test: LinkAddressTest Bug: 142949345 Merged-In: I0ac8c022f70cdf9305c183996c2464a8e04ba5ae Change-Id: I0ac8c022f70cdf9305c183996c2464a8e04ba5ae (cherry picked from commit b67261b01c787392bb24a6fe3f067937e33a0d6a) --- core/java/android/net/LinkAddress.java | 35 +++++++++++-------- .../java/android/net/LinkAddressTest.java | 24 +++++-------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java index 8d9f0d068a..a9d7f17017 100644 --- a/core/java/android/net/LinkAddress.java +++ b/core/java/android/net/LinkAddress.java @@ -102,9 +102,9 @@ public class LinkAddress implements Parcelable { /** * The time, as reported by {@link SystemClock#elapsedRealtime}, when this LinkAddress will be - * or was deprecated. {@link #LIFETIME_UNKNOWN} indicates this information is not available. At - * the time existing connections can still use this address until it expires, but new - * connections should use the new address. {@link #LIFETIME_PERMANENT} indicates this + * or was deprecated. At the time existing connections can still use this address until it + * expires, but new connections should use the new address. {@link #LIFETIME_UNKNOWN} indicates + * this information is not available. {@link #LIFETIME_PERMANENT} indicates this * {@link LinkAddress} will never be deprecated. */ private long deprecationTime; @@ -261,10 +261,10 @@ public class LinkAddress implements Parcelable { * @param scope An integer defining the scope in which the address is unique (e.g., * {@link OsConstants#RT_SCOPE_LINK} or {@link OsConstants#RT_SCOPE_SITE}). * @param deprecationTime The time, as reported by {@link SystemClock#elapsedRealtime}, when - * this {@link LinkAddress} will be or was deprecated. - * {@link #LIFETIME_UNKNOWN} indicates this information is not available. - * At the time existing connections can still use this address until it - * expires, but new connections should use the new address. + * this {@link LinkAddress} will be or was deprecated. At the time + * existing connections can still use this address until it expires, but + * new connections should use the new address. {@link #LIFETIME_UNKNOWN} + * indicates this information is not available. * {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} will * never be deprecated. * @param expirationTime The time, as reported by {@link SystemClock#elapsedRealtime}, when this @@ -441,7 +441,7 @@ public class LinkAddress implements Parcelable { if (expirationTime == LIFETIME_PERMANENT) { flags |= IFA_F_PERMANENT; } else if (expirationTime != LIFETIME_UNKNOWN) { - // If we know this address expired or will expire in the future or, then this address + // If we know this address expired or will expire in the future, then this address // should not be permanent. flags &= ~IFA_F_PERMANENT; } @@ -458,10 +458,13 @@ public class LinkAddress implements Parcelable { } /** - * @return The time that this address will be deprecated. At the time the existing connection - * can still use this address until it expires, but the new connection should use the new - * address. This is the EPOCH time in milliseconds. 0 indicates this information is not - * available. + * Get the deprecation time, as reported by {@link SystemClock#elapsedRealtime}, when this + * {@link LinkAddress} will be or was deprecated. At the time existing connections can still use + * this address until it expires, but new connections should use the new address. + * + * @return The deprecation time in milliseconds. {@link #LIFETIME_UNKNOWN} indicates this + * information is not available. {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} + * will never be deprecated. * * @hide */ @@ -472,8 +475,12 @@ public class LinkAddress implements Parcelable { } /** - * @return The time that this address will expire and will be no longer valid. This is the EPOCH - * time in milliseconds. 0 indicates this information is not available. + * Get the expiration time, as reported by {@link SystemClock#elapsedRealtime}, when this + * {@link LinkAddress} will expire and be removed from the interface. + * + * @return The expiration time in milliseconds. {@link #LIFETIME_UNKNOWN} indicates this + * information is not available. {@link #LIFETIME_PERMANENT} indicates this {@link LinkAddress} + * will never expire. * * @hide */ diff --git a/tests/net/common/java/android/net/LinkAddressTest.java b/tests/net/common/java/android/net/LinkAddressTest.java index e566e44c81..06c6301d66 100644 --- a/tests/net/common/java/android/net/LinkAddressTest.java +++ b/tests/net/common/java/android/net/LinkAddressTest.java @@ -326,26 +326,23 @@ public class LinkAddressTest { assertParcelSane(l, 6); } - /* @Test public void testDeprecationTime() { try { new LinkAddress(V6_ADDRESS, 64, 0, 456, - LinkAddress.LIFETIME_UNKNOWN, - SystemClock.elapsedRealtime() + 200000); + LinkAddress.LIFETIME_UNKNOWN, 100000L); fail("Only one time provided should cause exception"); } catch (IllegalArgumentException expected) { } try { new LinkAddress(V6_ADDRESS, 64, 0, 456, - SystemClock.elapsedRealtime() - 100000, - SystemClock.elapsedRealtime() - 200000); + 200000L, 100000L); fail("deprecation time later than expiration time should cause exception"); } catch (IllegalArgumentException expected) { } try { new LinkAddress(V6_ADDRESS, 64, 0, 456, - -2, SystemClock.elapsedRealtime()); + -2, 100000L); fail("negative deprecation time should cause exception"); } catch (IllegalArgumentException expected) { } } @@ -354,14 +351,13 @@ public class LinkAddressTest { public void testExpirationTime() { try { new LinkAddress(V6_ADDRESS, 64, 0, 456, - SystemClock.elapsedRealtime() + 200000, - LinkAddress.LIFETIME_UNKNOWN); + 200000L, LinkAddress.LIFETIME_UNKNOWN); fail("Only one time provided should cause exception"); } catch (IllegalArgumentException expected) { } try { new LinkAddress(V6_ADDRESS, 64, 0, 456, - SystemClock.elapsedRealtime() - 10000, -2); + 100000L, -2); fail("negative expiration time should cause exception"); } catch (IllegalArgumentException expected) { } } @@ -374,12 +370,12 @@ public class LinkAddressTest { // Test if deprecated bit was added/remove automatically based on the provided deprecation // time l = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_HOST, - SystemClock.elapsedRealtime() - 100000, LinkAddress.LIFETIME_PERMANENT); + 1L, LinkAddress.LIFETIME_PERMANENT); // Check if the flag is added automatically. assertTrue((l.getFlags() & IFA_F_DEPRECATED) != 0); l = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_HOST, - SystemClock.elapsedRealtime() + 100000, LinkAddress.LIFETIME_PERMANENT); + SystemClock.elapsedRealtime() + 100000L, LinkAddress.LIFETIME_PERMANENT); // Check if the flag is removed automatically. assertTrue((l.getFlags() & IFA_F_DEPRECATED) == 0); @@ -389,12 +385,10 @@ public class LinkAddressTest { assertTrue((l.getFlags() & IFA_F_PERMANENT) != 0); l = new LinkAddress(V6_ADDRESS, 64, IFA_F_PERMANENT, RT_SCOPE_HOST, - SystemClock.elapsedRealtime() - 100000, - SystemClock.elapsedRealtime() + 100000); + 1000L, SystemClock.elapsedRealtime() + 100000L); // Check if the permanent flag is removed assertTrue((l.getFlags() & IFA_F_PERMANENT) == 0); - }*/ - + } private void assertGlobalPreferred(LinkAddress l, String msg) { assertTrue(msg, l.isGlobalPreferred());