Merge "Skip stop if keepalive is already in stopping state" am: 57b79f463d am: e1d31ea908 am: 4a3701853a am: 58caa343cb am: 01851b58ea

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1424190

Change-Id: I46a3c91dd56d806fc06388ad448bd641a0db0ae4
This commit is contained in:
Junyu Lai
2020-09-24 04:52:57 +00:00
committed by Automerger Merge Worker
3 changed files with 47 additions and 5 deletions

View File

@@ -4292,6 +4292,32 @@ public class ConnectivityServiceTest {
myNet = connectKeepaliveNetwork(lp);
mWiFiNetworkAgent.setStartKeepaliveEvent(SocketKeepalive.SUCCESS);
// Check that a stop followed by network disconnects does not result in crash.
try (SocketKeepalive ka = mCm.createSocketKeepalive(
myNet, testSocket, myIPv4, dstIPv4, executor, callback)) {
ka.start(validKaInterval);
callback.expectStarted();
// Delay the response of keepalive events in networkAgent long enough to make sure
// the follow-up network disconnection will be processed first.
mWiFiNetworkAgent.setKeepaliveResponseDelay(3 * TIMEOUT_MS);
ka.stop();
// Make sure the stop has been processed. Wait for executor idle is needed to prevent
// flaky since the actual stop call to the service is delegated to executor thread.
waitForIdleSerialExecutor(executor, TIMEOUT_MS);
waitForIdle();
mWiFiNetworkAgent.disconnect();
mWiFiNetworkAgent.expectDisconnected();
callback.expectStopped();
callback.assertNoCallback();
}
// Reconnect.
waitForIdle();
myNet = connectKeepaliveNetwork(lp);
mWiFiNetworkAgent.setStartKeepaliveEvent(SocketKeepalive.SUCCESS);
// Check that keepalive slots start from 1 and increment. The first one gets slot 1.
mWiFiNetworkAgent.setExpectedKeepaliveSlot(1);
int srcPort2 = 0;