From 2ca3fb29b5a4ff4d6aee905884c8e1c82fa147ea Mon Sep 17 00:00:00 2001 From: Purushottam Kushwaha Date: Fri, 17 Apr 2020 09:44:05 +0530 Subject: Softap: Disconnect all connected clients during Softap turn-off. This commit uses existing forceClientDisconnect() API to disconnect all connected stations during softap turn off. This helps legacy stations to disconnect immidiately during softap turn-off. Bug: 154286607 Test: atest com.android.server.wifi Change-Id: I5f2440916ed817115f061f8564924489b3413bdd --- .../com/android/server/wifi/HostapdHalTest.java | 24 ++++++++++++++++-- .../com/android/server/wifi/SoftApManagerTest.java | 29 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java index 9db553f3b..52a28eafe 100644 --- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java @@ -34,6 +34,7 @@ import android.hidl.manager.V1_0.IServiceNotification; import android.net.MacAddress; import android.net.wifi.SoftApConfiguration; import android.net.wifi.SoftApConfiguration.Builder; +import android.net.wifi.WifiManager; import android.net.wifi.nl80211.WifiNl80211Manager; import android.os.Handler; import android.os.IHwBinder; @@ -820,10 +821,28 @@ public class HostapdHalTest extends WifiBaseTest { when(mIHostapdMockV12.forceClientDisconnect(any(), any(), anyShort())) .thenReturn(mStatusSuccess12); - assertTrue(mHostapdHal.forceClientDisconnect(IFACE_NAME, test_client, 0)); + assertTrue(mHostapdHal.forceClientDisconnect(IFACE_NAME, test_client, + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER)); verify(mIHostapdMockV12).forceClientDisconnect(any(), any(), anyShort()); } + @Test + public void testForceClientDisconnectFailureDueToInvalidArg() throws Exception { + executeAndValidateInitializationSequence(); + when(mServiceManagerMock.getTransport(anyString(), anyString())) + .thenReturn(IServiceManager.Transport.HWBINDER); + MacAddress test_client = MacAddress.fromString("da:a1:19:0:0:0"); + mIHostapdMockV12 = mock(android.hardware.wifi.hostapd.V1_2.IHostapd.class); + when(mIHostapdMockV12.forceClientDisconnect(any(), any(), anyShort())) + .thenReturn(mStatusSuccess12); + + try { + mHostapdHal.forceClientDisconnect(IFACE_NAME, test_client, -1); + fail(); + } catch (IllegalArgumentException e) { + } + } + /** * Verifies the failure handling in forceClientDisconnect. */ @@ -837,7 +856,8 @@ public class HostapdHalTest extends WifiBaseTest { when(mIHostapdMockV12.forceClientDisconnect(any(), any(), anyShort())) .thenReturn(mStatusFailure12); - assertFalse(mHostapdHal.forceClientDisconnect(IFACE_NAME, test_client, 0)); + assertFalse(mHostapdHal.forceClientDisconnect(IFACE_NAME, test_client, + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_BLOCKED_BY_USER)); verify(mIHostapdMockV12).forceClientDisconnect(any(), any(), anyShort()); } diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index a7e21c996..ca7bc627c 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -23,6 +23,7 @@ import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_INTERFACE_NAME; import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_MODE; import static android.net.wifi.WifiManager.EXTRA_WIFI_AP_STATE; import static android.net.wifi.WifiManager.IFACE_IP_MODE_LOCAL_ONLY; +import static android.net.wifi.WifiManager.SAP_CLIENT_DISCONNECT_REASON_CODE_UNSPECIFIED; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLED; import static android.net.wifi.WifiManager.WIFI_AP_STATE_DISABLING; import static android.net.wifi.WifiManager.WIFI_AP_STATE_ENABLED; @@ -1105,6 +1106,34 @@ public class SoftApManagerTest extends WifiBaseTest { } + @Test + public void stopDisconnectsConnectedClients() throws Exception { + InOrder order = inOrder(mCallback, mWifiMetrics); + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null, + mTestSoftApCapability); + startSoftApAndVerifyEnabled(apConfig); + + order.verify(mCallback).onConnectedClientsChanged(new ArrayList<>()); + + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT, true); + mLooper.dispatchAll(); + + order.verify(mCallback).onConnectedClientsChanged( + Mockito.argThat((List clients) -> + clients.contains(TEST_CONNECTED_CLIENT)) + ); + verify(mWifiMetrics).addSoftApNumAssociatedStationsChangedEvent( + 1, apConfig.getTargetMode()); + + mSoftApManager.stop(); + mLooper.dispatchAll(); + + verify(mWifiNative).forceClientDisconnect(TEST_INTERFACE_NAME, TEST_MAC_ADDRESS, + SAP_CLIENT_DISCONNECT_REASON_CODE_UNSPECIFIED); + } + @Test public void handlesInvalidConnectedClients() throws Exception { SoftApModeConfiguration apConfig = -- cgit v1.2.3