Merge "offload.c - make tether_error_map read only."
diff --git a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
index 776e49f..c2ab6c0 100644
--- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
+++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
@@ -60,7 +60,6 @@
import android.os.SystemProperties
import android.os.Process
import android.platform.test.annotations.AppModeFull
-import android.util.ArraySet
import androidx.test.platform.app.InstrumentationRegistry
import com.android.net.module.util.ArrayTrackRecord
import com.android.net.module.util.TrackRecord
@@ -409,9 +408,7 @@
}
private fun addInterfaceStateListener(listener: EthernetStateListener) {
- runAsShell(CONNECTIVITY_USE_RESTRICTED_NETWORKS) {
- em.addInterfaceStateListener(handler::post, listener)
- }
+ em.addInterfaceStateListener(handler::post, listener)
addedListeners.add(listener)
}
@@ -575,11 +572,18 @@
@Test
fun testCallbacks() {
+ // Only run this test when no non-restricted / physical interfaces are present.
+ // This test ensures that interface state listeners function properly, so the assumption
+ // check is explicitly *not* using an interface state listener.
+ // Since restricted interfaces cannot be used for tethering,
+ // assumeNoInterfaceForTetheringAvailable() is an okay proxy.
+ assumeNoInterfaceForTetheringAvailable()
+
// If an interface exists when the callback is registered, it is reported on registration.
val iface = createInterface()
val listener1 = EthernetStateListener()
addInterfaceStateListener(listener1)
- validateListenerOnRegistration(listener1)
+ listener1.expectCallback(iface, STATE_LINK_UP, ROLE_CLIENT)
// If an interface appears, existing callbacks see it.
val iface2 = createInterface()
@@ -589,7 +593,8 @@
// Register a new listener, it should see state of all existing interfaces immediately.
val listener2 = EthernetStateListener()
addInterfaceStateListener(listener2)
- validateListenerOnRegistration(listener2)
+ listener2.expectCallback(iface, STATE_LINK_UP, ROLE_CLIENT)
+ listener2.expectCallback(iface2, STATE_LINK_UP, ROLE_CLIENT)
// Removing interfaces first sends link down, then STATE_ABSENT/ROLE_NONE.
removeInterface(iface)
@@ -608,9 +613,10 @@
@Test
fun testCallbacks_withRunningInterface() {
- // This test disables ethernet, so check that adb is not connected over ethernet.
assumeFalse(isAdbOverEthernet())
- assumeTrue(em.getInterfaceList().isEmpty())
+ // Only run this test when no non-restricted / physical interfaces are present.
+ assumeNoInterfaceForTetheringAvailable()
+
val iface = createInterface()
val listener = EthernetStateListener()
addInterfaceStateListener(listener)
@@ -666,28 +672,6 @@
listener.expectCallback(iface, STATE_LINK_UP, ROLE_CLIENT)
}
- /**
- * Validate all interfaces are returned for an EthernetStateListener upon registration.
- */
- private fun validateListenerOnRegistration(listener: EthernetStateListener) {
- // Get all tracked interfaces to validate on listener registration. Ordering and interface
- // state (up/down) can't be validated for interfaces not created as part of testing.
- val ifaces = em.getInterfaceList()
- val polledIfaces = ArraySet<String>()
- for (i in ifaces) {
- val event = (listener.pollForNextCallback() as InterfaceStateChanged)
- val iface = event.iface
- assertTrue(polledIfaces.add(iface), "Duplicate interface $iface returned")
- assertTrue(ifaces.contains(iface), "Untracked interface $iface returned")
- // If the event's iface was created in the test, additional criteria can be validated.
- createdIfaces.find { it.name.equals(iface) }?.let {
- assertEquals(event, listener.createChangeEvent(it.name, STATE_LINK_UP, ROLE_CLIENT))
- }
- }
- // Assert all callbacks are accounted for.
- listener.assertNoCallback()
- }
-
@Test
fun testGetInterfaceList() {
// Create two test interfaces and check the return list contains the interface names.
@@ -968,6 +952,12 @@
val updatedNetwork = cb.expectAvailable()
// With the test process UID allowed, binding to a restricted network should be successful.
Socket().use { socket -> updatedNetwork.bindSocket(socket) }
+
+ // Reset capabilities to not-restricted, otherwise tearDown won't see the interface callback
+ // as ifaceListener does not have the restricted permission.
+ // TODO: Find a better way to do this when there are more tests around restricted
+ // interfaces.
+ updateConfiguration(iface, capabilities = TEST_CAPS).expectResult(iface.name)
}
// TODO: consider only having this test in MTS as it makes use of the fact that