Snap for 7562097 from 5d39cb6ea74958c60b72e81ea5052e8a82928177 to sdk-release

Change-Id: I440801d4159db83436894eaf6515528d893cd84a
diff --git a/common/framework/com/android/net/module/util/NetworkCapabilitiesUtils.java b/common/framework/com/android/net/module/util/NetworkCapabilitiesUtils.java
index d4b1c9e..903214e 100644
--- a/common/framework/com/android/net/module/util/NetworkCapabilitiesUtils.java
+++ b/common/framework/com/android/net/module/util/NetworkCapabilitiesUtils.java
@@ -33,6 +33,7 @@
 import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
 import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
+import static android.net.NetworkCapabilities.TRANSPORT_USB;
 import static android.net.NetworkCapabilities.TRANSPORT_VPN;
 import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
 import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE;
@@ -47,12 +48,6 @@
  * @hide
  */
 public final class NetworkCapabilitiesUtils {
-    /**
-     * See android.net.NetworkCapabilities.TRANSPORT_USB
-     * TODO: Use API constant when all downstream branches are S-based
-     */
-    public static final int TRANSPORT_USB = 8;
-
     // Transports considered to classify networks in UI, in order of which transport should be
     // surfaced when there are multiple transports. Transports not in this list do not have
     // an ordering preference (in practice they will have a deterministic order based on the
diff --git a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRunner.kt b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRunner.kt
index 73b2843..da7bf97 100644
--- a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRunner.kt
+++ b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRunner.kt
@@ -21,7 +21,13 @@
 import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
 import org.junit.runner.Description
 import org.junit.runner.Runner
+import org.junit.runner.manipulation.Filter
+import org.junit.runner.manipulation.Filterable
+import org.junit.runner.manipulation.NoTestsRemainException
+import org.junit.runner.manipulation.Sortable
+import org.junit.runner.manipulation.Sorter
 import org.junit.runner.notification.RunNotifier
+import kotlin.jvm.Throws
 
 /**
  * A runner that can skip tests based on the development SDK as defined in [DevSdkIgnoreRule].
@@ -41,7 +47,7 @@
  *     @IgnoreUpTo(Build.VERSION_CODES.Q)
  *     class MyTestClass { ... }
  */
-class DevSdkIgnoreRunner(private val klass: Class<*>) : Runner() {
+class DevSdkIgnoreRunner(private val klass: Class<*>) : Runner(), Filterable, Sortable {
     private val baseRunner = klass.let {
         val ignoreAfter = it.getAnnotation(IgnoreAfter::class.java)
         val ignoreUpTo = it.getAnnotation(IgnoreUpTo::class.java)
@@ -55,8 +61,9 @@
             return
         }
 
-        // Report a single, skipped placeholder test for this class, so that the class is still
-        // visible as skipped in test results.
+        // Report a single, skipped placeholder test for this class, as the class is expected to
+        // report results when run. In practice runners that apply the Filterable implementation
+        // would see a NoTestsRemainException and not call the run method.
         notifier.fireTestIgnored(
                 Description.createTestDescription(klass, "skippedClassForDevSdkMismatch"))
     }
@@ -65,8 +72,20 @@
         return baseRunner?.description ?: Description.createSuiteDescription(klass)
     }
 
+    /**
+     * Get the test count before applying the [Filterable] implementation.
+     */
     override fun testCount(): Int {
         // When ignoring the tests, a skipped placeholder test is reported, so test count is 1.
         return baseRunner?.testCount() ?: 1
     }
+
+    @Throws(NoTestsRemainException::class)
+    override fun filter(filter: Filter?) {
+        baseRunner?.filter(filter) ?: throw NoTestsRemainException()
+    }
+
+    override fun sort(sorter: Sorter?) {
+        baseRunner?.sort(sorter)
+    }
 }
\ No newline at end of file
diff --git a/common/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt b/common/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
index 1b3d0f6..7d851f1 100644
--- a/common/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
+++ b/common/testutils/devicetests/com/android/testutils/TestableNetworkCallback.kt
@@ -116,6 +116,7 @@
     val mark get() = history.mark
 
     override fun onAvailable(network: Network) {
+        Log.d(TAG, "onAvailable $network")
         history.add(Available(network))
     }
 
@@ -199,6 +200,15 @@
         if (null != cb) fail("Expected no callback but got $cb")
     }
 
+    fun assertNoCallbackThat(
+        timeoutMs: Long = defaultTimeoutMs,
+        valid: (CallbackEntry) -> Boolean
+    ) {
+        val cb = history.poll(timeoutMs) { valid(it) }.let {
+            if (null != it) fail("Expected no callback but got $it")
+        }
+    }
+
     // Expects a callback of the specified type on the specified network within the timeout.
     // If no callback arrives, or a different callback arrives, fail. Returns the callback.
     inline fun <reified T : CallbackEntry> expectCallback(