Snap for 14172376 from 077707c1ef2c8473a8531c8aefc8cee1588ddfe7 to android15-tests-release

Change-Id: Iffa31e0358997805884c15a6173768e9c5b7159e
diff --git a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
index 61ebd8f..d7d5b38 100644
--- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
+++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
@@ -287,6 +287,12 @@
             val cb = events.poll(NO_CALLBACK_TIMEOUT_MS)
             assertNull(cb, "Expected no callback but got $cb")
         }
+
+        fun assumeNoCallback() {
+            val cb = events.poll(0 /* timeout */)
+            // Note that assumeNull does not exist.
+            assumeTrue(cb == null)
+        }
     }
 
     private class TetheredInterfaceListener : TetheredInterfaceCallback {
@@ -562,7 +568,7 @@
         // check is explicitly *not* using an interface state listener.
         // Since restricted interfaces cannot be used for tethering,
         // assumeNoInterfaceForTetheringAvailable() is an okay proxy.
-        assumeNoInterfaceForTetheringAvailable()
+        assumeNoUnrestrictedInterfacesAvailable()
 
         // If an interface exists when the callback is registered, it is reported on registration.
         val iface = createInterface()
@@ -634,6 +640,15 @@
         }
     }
 
+    private fun assumeNoUnrestrictedInterfacesAvailable() {
+        val listener = EthernetStateListener()
+        addInterfaceStateListener(listener)
+
+        // Force interface state listener callbacks to be processed before proceeding.
+        setEthernetEnabled(true)
+        listener.assumeNoCallback()
+    }
+
     @Test
     fun testCallbacks_forServerModeInterfaces() {
         // do not run this test if an interface that can be used for tethering already exists.