Merge "Send callback if ip provisioning is interrupted" am: 7d5aae1a55 am: 6775e2eaea

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2123881

Change-Id: Ib8c11b71d599d48c422c0cee470d60e15c101d22
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
James Mattis
2022-06-17 20:34:53 +00:00
committed by Automerger Merge Worker
2 changed files with 15 additions and 4 deletions

View File

@@ -488,8 +488,6 @@ public class EthernetNetworkFactory {
if (null != capabilities) { if (null != capabilities) {
setCapabilities(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 // 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 // be required due to the capabilities or ipConfiguration values, not all
// capabilities changes require a restart. // capabilities changes require a restart.
@@ -651,6 +649,8 @@ public class EthernetNetworkFactory {
mIpClientCallback.awaitIpClientShutdown(); mIpClientCallback.awaitIpClientShutdown();
mIpClient = null; mIpClient = null;
} }
// Send an abort callback if an updateInterface request was in progress.
maybeSendNetworkManagementCallbackForAbort();
mIpClientCallback = null; mIpClientCallback = null;
if (mNetworkAgent != null) { if (mNetworkAgent != null) {
@@ -662,7 +662,6 @@ public class EthernetNetworkFactory {
public void destroy() { public void destroy() {
mNetworkProvider.unregisterNetworkOffer(mNetworkOfferCallback); mNetworkProvider.unregisterNetworkOffer(mNetworkOfferCallback);
maybeSendNetworkManagementCallbackForAbort();
stop(); stop();
mRequests.clear(); mRequests.clear();
} }

View File

@@ -92,6 +92,8 @@ public class EthernetNetworkFactoryTest {
private Handler mHandler; private Handler mHandler;
private EthernetNetworkFactory mNetFactory = null; private EthernetNetworkFactory mNetFactory = null;
private IpClientCallbacks mIpClientCallbacks; private IpClientCallbacks mIpClientCallbacks;
private NetworkOfferCallback mNetworkOfferCallback;
private NetworkRequest mRequestToKeepNetworkUp;
@Mock private Context mContext; @Mock private Context mContext;
@Mock private Resources mResources; @Mock private Resources mResources;
@Mock private EthernetNetworkFactory.Dependencies mDeps; @Mock private EthernetNetworkFactory.Dependencies mDeps;
@@ -244,7 +246,9 @@ public class EthernetNetworkFactoryTest {
ArgumentCaptor<NetworkOfferCallback> captor = ArgumentCaptor.forClass( ArgumentCaptor<NetworkOfferCallback> captor = ArgumentCaptor.forClass(
NetworkOfferCallback.class); NetworkOfferCallback.class);
verify(mNetworkProvider).registerNetworkOffer(any(), any(), any(), captor.capture()); verify(mNetworkProvider).registerNetworkOffer(any(), any(), any(), captor.capture());
captor.getValue().onNetworkNeeded(createDefaultRequest()); mRequestToKeepNetworkUp = createDefaultRequest();
mNetworkOfferCallback = captor.getValue();
mNetworkOfferCallback.onNetworkNeeded(mRequestToKeepNetworkUp);
verifyStart(ipConfig); verifyStart(ipConfig);
clearInvocations(mDeps); clearInvocations(mDeps);
@@ -624,6 +628,14 @@ public class EthernetNetworkFactoryTest {
() -> mNetFactory.updateInterfaceLinkState(TEST_IFACE, false, NULL_LISTENER)); () -> mNetFactory.updateInterfaceLinkState(TEST_IFACE, false, NULL_LISTENER));
} }
@Test
public void testUpdateInterfaceAbortsOnNetworkUneededRemovesAllRequests() throws Exception {
initEthernetNetworkFactory();
verifyNetworkManagementCallIsAbortedWhenInterrupted(
TEST_IFACE,
() -> mNetworkOfferCallback.onNetworkUnneeded(mRequestToKeepNetworkUp));
}
@Test @Test
public void testUpdateInterfaceCallsListenerCorrectlyOnConcurrentRequests() throws Exception { public void testUpdateInterfaceCallsListenerCorrectlyOnConcurrentRequests() throws Exception {
initEthernetNetworkFactory(); initEthernetNetworkFactory();