diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 79802fbd86..c4ea9ae8b0 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -488,8 +488,6 @@ public class EthernetNetworkFactory { if (null != capabilities) { setCapabilities(capabilities); } - // Send an abort callback if a request is filed before the previous one has completed. - maybeSendNetworkManagementCallbackForAbort(); // 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. @@ -651,6 +649,8 @@ public class EthernetNetworkFactory { mIpClientCallback.awaitIpClientShutdown(); mIpClient = null; } + // Send an abort callback if an updateInterface request was in progress. + maybeSendNetworkManagementCallbackForAbort(); mIpClientCallback = null; if (mNetworkAgent != null) { @@ -662,7 +662,6 @@ public class EthernetNetworkFactory { public void destroy() { mNetworkProvider.unregisterNetworkOffer(mNetworkOfferCallback); - maybeSendNetworkManagementCallbackForAbort(); stop(); mRequests.clear(); } diff --git a/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java index 4f849d2a9a..2178b33727 100644 --- a/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java +++ b/tests/unit/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java @@ -92,6 +92,8 @@ public class EthernetNetworkFactoryTest { private Handler mHandler; private EthernetNetworkFactory mNetFactory = null; private IpClientCallbacks mIpClientCallbacks; + private NetworkOfferCallback mNetworkOfferCallback; + private NetworkRequest mRequestToKeepNetworkUp; @Mock private Context mContext; @Mock private Resources mResources; @Mock private EthernetNetworkFactory.Dependencies mDeps; @@ -244,7 +246,9 @@ public class EthernetNetworkFactoryTest { ArgumentCaptor captor = ArgumentCaptor.forClass( NetworkOfferCallback.class); verify(mNetworkProvider).registerNetworkOffer(any(), any(), any(), captor.capture()); - captor.getValue().onNetworkNeeded(createDefaultRequest()); + mRequestToKeepNetworkUp = createDefaultRequest(); + mNetworkOfferCallback = captor.getValue(); + mNetworkOfferCallback.onNetworkNeeded(mRequestToKeepNetworkUp); verifyStart(ipConfig); clearInvocations(mDeps); @@ -624,6 +628,14 @@ public class EthernetNetworkFactoryTest { () -> mNetFactory.updateInterfaceLinkState(TEST_IFACE, false, NULL_LISTENER)); } + @Test + public void testUpdateInterfaceAbortsOnNetworkUneededRemovesAllRequests() throws Exception { + initEthernetNetworkFactory(); + verifyNetworkManagementCallIsAbortedWhenInterrupted( + TEST_IFACE, + () -> mNetworkOfferCallback.onNetworkUnneeded(mRequestToKeepNetworkUp)); + } + @Test public void testUpdateInterfaceCallsListenerCorrectlyOnConcurrentRequests() throws Exception { initEthernetNetworkFactory();