From ae3ace443379046b2fefaeb477fbf51bdd162ce1 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Wed, 5 Oct 2022 09:27:55 -0700 Subject: [PATCH] ethernet: fix IpClient restart when link is down Do not restart IpClient when link is down after calling updateConfiguration(). Test: atest EthernetManagerTest Bug: 249897651 Change-Id: Ia0f6b67cde63747a608d35b8bec6ad37bcabb110 --- .../ethernet/EthernetNetworkFactory.java | 4 +++- .../android/net/cts/EthernetManagerTest.kt | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 48d68d7894..00f6c56849 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -469,7 +469,9 @@ public class EthernetNetworkFactory { // TODO: Update this logic to only do a restart if required. Although a restart may // be required due to the capabilities or ipConfiguration values, not all // capabilities changes require a restart. - restart(); + if (mIpClient != null) { + restart(); + } } boolean isRestricted() { diff --git a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt index 3635b7ba89..1e44440b8a 100644 --- a/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt +++ b/tests/cts/net/src/android/net/cts/EthernetManagerTest.kt @@ -979,4 +979,23 @@ class EthernetManagerTest { cb.eventuallyExpectCapabilities(TEST_CAPS) cb.eventuallyExpectLpForStaticConfig(STATIC_IP_CONFIGURATION.staticIpConfiguration) } + + @Test + fun testUpdateConfiguration_withLinkDown() { + assumeChangingCarrierSupported() + // createInterface without carrier is racy, so create it and then remove carrier. + val iface = createInterface() + val cb = requestNetwork(ETH_REQUEST) + cb.expectAvailable() + + iface.setCarrierEnabled(false) + cb.eventuallyExpectLost() + + updateConfiguration(iface, STATIC_IP_CONFIGURATION, TEST_CAPS).expectResult(iface.name) + cb.assertNoCallback() + + iface.setCarrierEnabled(true) + cb.eventuallyExpectCapabilities(TEST_CAPS) + cb.eventuallyExpectLpForStaticConfig(STATIC_IP_CONFIGURATION.staticIpConfiguration) + } }