ethernet: fix enable/disableInterface result
Calling enableInterface() / disableInterface() for an interface already
in the correct state used to return an error which is incorrect
according to the API specification in EthernetManager. onError() is now
only returned for untracked and server mode interfaces.
This change also fixes the updateInterfaceState() function signature.
Test: atest EthernetManagerTest
Change-Id: Ie7ee84c3756a8a0c489a38548214fd524352c8da
diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java
index 00dff5b..92c354f 100644
--- a/service-t/src/com/android/server/ethernet/EthernetTracker.java
+++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java
@@ -627,26 +627,24 @@
}
private void updateInterfaceState(String iface, boolean up) {
- // TODO: pull EthernetCallbacks out of EthernetNetworkFactory.
updateInterfaceState(iface, up, new EthernetCallback(null /* cb */));
}
- private void updateInterfaceState(@NonNull final String iface, final boolean up,
- @Nullable final EthernetCallback cb) {
+ // TODO(b/225315248): enable/disableInterface() should not affect link state.
+ private void updateInterfaceState(String iface, boolean up, EthernetCallback cb) {
final int mode = getInterfaceMode(iface);
- final boolean factoryLinkStateUpdated = (mode == INTERFACE_MODE_CLIENT)
- && mFactory.updateInterfaceLinkState(iface, up);
-
- if (factoryLinkStateUpdated) {
- broadcastInterfaceStateChange(iface);
- cb.onResult(iface);
- } else {
- // The interface may already be in the correct state. While usually this should not be
- // an error, since updateInterfaceState is used in setInterfaceEnabled() /
- // setInterfaceDisabled() it has to be reported as such.
- // It is also possible that the interface disappeared or is in server mode.
+ if (mode == INTERFACE_MODE_SERVER || !mFactory.hasInterface(iface)) {
+ // The interface is in server mode or is not tracked.
cb.onError("Failed to set link state " + (up ? "up" : "down") + " for " + iface);
+ return;
}
+
+ if (mFactory.updateInterfaceLinkState(iface, up)) {
+ broadcastInterfaceStateChange(iface);
+ }
+ // If updateInterfaceLinkState returns false, the interface is already in the correct state.
+ // Always return success.
+ cb.onResult(iface);
}
private void maybeUpdateServerModeInterfaceState(String iface, boolean available) {
diff --git a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
index b21c5b4..e865480 100644
--- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
+++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt
@@ -804,6 +804,26 @@
}
@Test
+ fun testEnableDisableInterface_withoutStateChange() {
+ val iface = createInterface()
+ // Interface is already enabled, so enableInterface() should return success
+ enableInterface(iface).expectResult(iface.name)
+
+ disableInterface(iface).expectResult(iface.name)
+ // Interface is already disabled, so disableInterface() should return success.
+ disableInterface(iface).expectResult(iface.name)
+ }
+
+ @Test
+ fun testEnableDisableInterface_withMissingInterface() {
+ val iface = createInterface()
+ removeInterface(iface)
+ // Interface does not exist, enable/disableInterface() should both return an error.
+ enableInterface(iface).expectError()
+ disableInterface(iface).expectError()
+ }
+
+ @Test
fun testUpdateConfiguration_forBothIpConfigAndCapabilities() {
val iface = createInterface()
val cb = requestNetwork(ETH_REQUEST.createCopyWithEthernetSpecifier(iface.name))