Merge "Skip testCallbacks when unrestricted interfaces are present" into main

This commit is contained in:
Patrick Rohr 2025-08-26 20:42:47 -07:00 • committed by Android (Google) Code Review
commit 41a8778165

View file

@ -324,6 +324,12 @@ class EthernetManagerTest {
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 {
@ -617,7 +623,7 @@ class EthernetManagerTest {
// 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()
@ -680,6 +686,15 @@ class EthernetManagerTest {
}
}
private fun assumeNoUnrestrictedInterfacesAvailable() {
val listener = EthernetStateListener()
addInterfaceStateListener(listener)
// Force interface state listener callbacks to be processed before proceeding.
setEthernetEnabled(ethernetEnabled)
listener.assumeNoCallback()
}
@Test
fun testCallbacks_forServerModeInterfaces() {
// do not run this test if an interface that can be used for tethering already exists.