From 168ede29fc294eb4063f0cc2e54b4e9f9394dc01 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 6 Apr 2020 19:07:38 -0700 Subject: WifiNetworkFactory: Ensure we disconnect when we release request If the app releases a request in the midst of a connection attempt, ensure we trigger a disconnect. The current logic only triggers a disconnect if the app releases the request after the connection is established. Bug: 149500993 Test: act.py -c wifi_manager_cross.config -tb dut-name -tc WifiNetworkRequestTest Test: atest com.android.server.wifi Change-Id: I614c43b1d3121d50c719c428a835305df51ef792 --- .../server/wifi/WifiNetworkFactoryTest.java | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index 684fd1449..b495b49c7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -1578,6 +1578,36 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue()); } + /** + * Verify handling of request release after starting connection to the network. + */ + @Test + public void testHandleNetworkReleaseWithSpecifierAfterConnectionStart() throws Exception { + sendNetworkRequestAndSetupForConnectionStatus(); + + assertNotNull(mSelectedNetwork); + + // Now release the network request. + WifiConfiguration wcmNetwork = new WifiConfiguration(mSelectedNetwork); + wcmNetwork.networkId = TEST_NETWORK_ID_1; + wcmNetwork.creatorUid = TEST_UID_1; + wcmNetwork.creatorName = TEST_PACKAGE_NAME_1; + wcmNetwork.shared = false; + wcmNetwork.fromWifiNetworkSpecifier = true; + wcmNetwork.ephemeral = true; + when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getKey())) + .thenReturn(wcmNetwork); + mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest); + // verify we canceled the timeout alarm. + verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue()); + // Verify that we triggered a disconnect. + verify(mClientModeImpl, times(2)).disconnectCommand(); + verify(mWifiConfigManager).removeNetwork( + TEST_NETWORK_ID_1, TEST_UID_1, TEST_PACKAGE_NAME_1); + // Re-enable connectivity manager . + verify(mWifiConnectivityManager).setSpecificNetworkRequestInProgress(false); + } + /** * Verify handling of request release after connecting to the network. */ @@ -1601,9 +1631,10 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { wcmNetwork.networkId = TEST_NETWORK_ID_1; wcmNetwork.creatorUid = TEST_UID_1; wcmNetwork.creatorName = TEST_PACKAGE_NAME_1; + wcmNetwork.shared = false; wcmNetwork.fromWifiNetworkSpecifier = true; wcmNetwork.ephemeral = true; - when(mWifiConfigManager.getConfiguredNetwork(mSelectedNetwork.getKey())) + when(mWifiConfigManager.getConfiguredNetwork(wcmNetwork.getKey())) .thenReturn(wcmNetwork); mWifiNetworkFactory.releaseNetworkFor(mNetworkRequest); // Verify that we triggered a disconnect. -- cgit v1.2.3