Loading apishim/29/com/android/networkstack/apishim/api29/NetworkInformationShimImpl.java +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim.api29; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -74,6 +75,18 @@ public class NetworkInformationShimImpl implements NetworkInformationShim { return null; } @Nullable @Override public IpPrefix getNat64Prefix(@NonNull LinkProperties lp) { // Not supported on this API level return null; } @Override public void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix) { // Not supported on this API level: no-op } @Nullable @Override public String getSsid(@Nullable NetworkCapabilities nc) { Loading apishim/30/com/android/networkstack/apishim/NetworkInformationShimImpl.java +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -71,6 +72,17 @@ public class NetworkInformationShimImpl extends return new CaptivePortalDataShimImpl(lp.getCaptivePortalData()); } @Nullable @Override public IpPrefix getNat64Prefix(@NonNull LinkProperties lp) { return lp.getNat64Prefix(); } @Override public void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix) { lp.setNat64Prefix(prefix); } @Nullable @Override public String getSsid(@Nullable NetworkCapabilities nc) { Loading apishim/common/com/android/networkstack/apishim/NetworkInformationShim.java +13 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -47,6 +48,17 @@ public interface NetworkInformationShim { @Nullable CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp); /** * @see LinkProperties#getNat64Prefix() */ @Nullable IpPrefix getNat64Prefix(@NonNull LinkProperties lp); /** * @see LinkProperties#setNat64Prefix() */ void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix); /** * @see NetworkCapabilities#getSSID() */ Loading @@ -62,8 +74,6 @@ public interface NetworkInformationShim { /** * @see LinkProperties#setDhcpServerAddress() */ @NonNull void setDhcpServerAddress(@NonNull LinkProperties lp, @NonNull Inet4Address serverAddress); void setDhcpServerAddress(@NonNull LinkProperties lp, @NonNull Inet4Address serverAddress); } tests/lib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ java_library { "androidx.annotation_annotation", ], static_libs: [ "androidx.test.ext.junit", "net-tests-utils-multivariant", ], } Loading tests/lib/src/com/android/testutils/DevSdkIgnoreRule.kt +21 −10 Original line number Diff line number Diff line Loading @@ -22,6 +22,23 @@ import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement /** * Returns true if the development SDK version of the device is in the provided range. * * If the device is not using a release SDK, the development SDK is considered to be higher than * [Build.VERSION.SDK_INT]. */ fun isDevSdkInRange(minExclusive: Int?, maxInclusive: Int?): Boolean { // In-development API n+1 will have SDK_INT == n and CODENAME != REL. // Stable API n has SDK_INT == n and CODENAME == REL. val release = "REL" == Build.VERSION.CODENAME val sdkInt = Build.VERSION.SDK_INT val devApiLevel = sdkInt + if (release) 0 else 1 return (minExclusive == null || devApiLevel > minExclusive) && (maxInclusive == null || devApiLevel <= maxInclusive) } /** * A test rule to ignore tests based on the development SDK level. * Loading Loading @@ -63,16 +80,10 @@ class DevSdkIgnoreRule @JvmOverloads constructor( val ignoreAfter = description.getAnnotation(IgnoreAfter::class.java) val ignoreUpTo = description.getAnnotation(IgnoreUpTo::class.java) // In-development API n+1 will have SDK_INT == n and CODENAME != REL. // Stable API n has SDK_INT == n and CODENAME == REL. val release = "REL" == Build.VERSION.CODENAME val sdkInt = Build.VERSION.SDK_INT val devApiLevel = sdkInt + if (release) 0 else 1 val message = "Skipping test for ${if (!release) "non-" else ""}release SDK $sdkInt" assumeTrue(message, ignoreClassAfter == null || devApiLevel <= ignoreClassAfter) assumeTrue(message, ignoreClassUpTo == null || devApiLevel > ignoreClassUpTo) assumeTrue(message, ignoreAfter == null || devApiLevel <= ignoreAfter.value) assumeTrue(message, ignoreUpTo == null || devApiLevel > ignoreUpTo.value) val message = "Skipping test for build ${Build.VERSION.CODENAME} " + "with SDK ${Build.VERSION.SDK_INT}" assumeTrue(message, isDevSdkInRange(ignoreClassUpTo, ignoreClassAfter)) assumeTrue(message, isDevSdkInRange(ignoreUpTo?.value, ignoreAfter?.value)) base.evaluate() } } Loading Loading
apishim/29/com/android/networkstack/apishim/api29/NetworkInformationShimImpl.java +13 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim.api29; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -74,6 +75,18 @@ public class NetworkInformationShimImpl implements NetworkInformationShim { return null; } @Nullable @Override public IpPrefix getNat64Prefix(@NonNull LinkProperties lp) { // Not supported on this API level return null; } @Override public void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix) { // Not supported on this API level: no-op } @Nullable @Override public String getSsid(@Nullable NetworkCapabilities nc) { Loading
apishim/30/com/android/networkstack/apishim/NetworkInformationShimImpl.java +12 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -71,6 +72,17 @@ public class NetworkInformationShimImpl extends return new CaptivePortalDataShimImpl(lp.getCaptivePortalData()); } @Nullable @Override public IpPrefix getNat64Prefix(@NonNull LinkProperties lp) { return lp.getNat64Prefix(); } @Override public void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix) { lp.setNat64Prefix(prefix); } @Nullable @Override public String getSsid(@Nullable NetworkCapabilities nc) { Loading
apishim/common/com/android/networkstack/apishim/NetworkInformationShim.java +13 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.networkstack.apishim; import android.net.IpPrefix; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.Uri; Loading Loading @@ -47,6 +48,17 @@ public interface NetworkInformationShim { @Nullable CaptivePortalDataShim getCaptivePortalData(@Nullable LinkProperties lp); /** * @see LinkProperties#getNat64Prefix() */ @Nullable IpPrefix getNat64Prefix(@NonNull LinkProperties lp); /** * @see LinkProperties#setNat64Prefix() */ void setNat64Prefix(@NonNull LinkProperties lp, @Nullable IpPrefix prefix); /** * @see NetworkCapabilities#getSSID() */ Loading @@ -62,8 +74,6 @@ public interface NetworkInformationShim { /** * @see LinkProperties#setDhcpServerAddress() */ @NonNull void setDhcpServerAddress(@NonNull LinkProperties lp, @NonNull Inet4Address serverAddress); void setDhcpServerAddress(@NonNull LinkProperties lp, @NonNull Inet4Address serverAddress); }
tests/lib/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ java_library { "androidx.annotation_annotation", ], static_libs: [ "androidx.test.ext.junit", "net-tests-utils-multivariant", ], } Loading
tests/lib/src/com/android/testutils/DevSdkIgnoreRule.kt +21 −10 Original line number Diff line number Diff line Loading @@ -22,6 +22,23 @@ import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement /** * Returns true if the development SDK version of the device is in the provided range. * * If the device is not using a release SDK, the development SDK is considered to be higher than * [Build.VERSION.SDK_INT]. */ fun isDevSdkInRange(minExclusive: Int?, maxInclusive: Int?): Boolean { // In-development API n+1 will have SDK_INT == n and CODENAME != REL. // Stable API n has SDK_INT == n and CODENAME == REL. val release = "REL" == Build.VERSION.CODENAME val sdkInt = Build.VERSION.SDK_INT val devApiLevel = sdkInt + if (release) 0 else 1 return (minExclusive == null || devApiLevel > minExclusive) && (maxInclusive == null || devApiLevel <= maxInclusive) } /** * A test rule to ignore tests based on the development SDK level. * Loading Loading @@ -63,16 +80,10 @@ class DevSdkIgnoreRule @JvmOverloads constructor( val ignoreAfter = description.getAnnotation(IgnoreAfter::class.java) val ignoreUpTo = description.getAnnotation(IgnoreUpTo::class.java) // In-development API n+1 will have SDK_INT == n and CODENAME != REL. // Stable API n has SDK_INT == n and CODENAME == REL. val release = "REL" == Build.VERSION.CODENAME val sdkInt = Build.VERSION.SDK_INT val devApiLevel = sdkInt + if (release) 0 else 1 val message = "Skipping test for ${if (!release) "non-" else ""}release SDK $sdkInt" assumeTrue(message, ignoreClassAfter == null || devApiLevel <= ignoreClassAfter) assumeTrue(message, ignoreClassUpTo == null || devApiLevel > ignoreClassUpTo) assumeTrue(message, ignoreAfter == null || devApiLevel <= ignoreAfter.value) assumeTrue(message, ignoreUpTo == null || devApiLevel > ignoreUpTo.value) val message = "Skipping test for build ${Build.VERSION.CODENAME} " + "with SDK ${Build.VERSION.SDK_INT}" assumeTrue(message, isDevSdkInRange(ignoreClassUpTo, ignoreClassAfter)) assumeTrue(message, isDevSdkInRange(ignoreUpTo?.value, ignoreAfter?.value)) base.evaluate() } } Loading