From f67983967623524bc785cac8ac3e294fb9183746 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 12 Feb 2018 09:30:30 -0800 Subject: WificondControl: Remove supplicant/hostapd start/stop This is no longer needed since we'll be using the lazy HAL startup mechanism provided by HIDL to start/stop supplicant. Created a new method for registering the softap callbacks (previously was a part of startHostapd. The callback will be removed when we teardown the interface. Bug: 72394251 Test: Unit tests Test: Softap & WifiManager integration tests Change-Id: I462c005299ae0c8ee183091e2a5d02353b646a59 --- .../wifi/WifiNativeInterfaceManagementTest.java | 2 + .../com/android/server/wifi/WifiNativeTest.java | 12 -- .../android/server/wifi/WificondControlTest.java | 190 +-------------------- 3 files changed, 10 insertions(+), 194 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java index e3d131476..1f513699e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeInterfaceManagementTest.java @@ -130,6 +130,7 @@ public class WifiNativeInterfaceManagementTest { when(mWificondControl.tearDownClientInterface(any())).thenReturn(true); when(mWificondControl.tearDownSoftApInterface(any())).thenReturn(true); when(mWificondControl.tearDownInterfaces()).thenReturn(true); + when(mWificondControl.registerApListener(any(), any())).thenReturn(true); when(mSupplicantStaIfaceHal.registerDeathHandler(mSupplicantDeathHandlerCaptor.capture())) .thenReturn(true); @@ -772,6 +773,7 @@ public class WifiNativeInterfaceManagementTest { assertTrue(mWifiNative.startSoftAp(IFACE_NAME_0, new WifiConfiguration(), mock(WifiNative.SoftApListener.class))); + mInOrder.verify(mWificondControl).registerApListener(any(), any()); mInOrder.verify(mHostapdHal).addAccessPoint(any(), any()); // Trigger vendor HAL death diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index abec9dc8b..1a9f6b3dd 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -575,18 +575,6 @@ public class WifiNativeTest { verify(mWifiVendorHal).setMacAddress(WIFI_IFACE_NAME, TEST_MAC_ADDRESS); } - /** - * Test to check if the softap start failure metrics are incremented correctly. - */ - @Test - public void testStartSoftApFailureIncrementsMetrics() throws Exception { - when(mWificondControl.startHostapd(any(), any())).thenReturn(false); - WifiNative.SoftApListener mockListener = mock(WifiNative.SoftApListener.class); - mWifiNative.startSoftAp(WIFI_IFACE_NAME, new WifiConfiguration(), mockListener); - verify(mWificondControl).startHostapd(WIFI_IFACE_NAME, mockListener); - verify(mWifiMetrics).incrementNumSetupSoftApInterfaceFailureDueToHostapd(); - } - /** * Test that selectTxPowerScenario() calls into WifiVendorHal (success case) */ diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java index bfa77d575..76388446d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -392,9 +392,9 @@ public class WificondControlTest { public void testTeardownSoftApInterfaceClearsHandles() throws Exception { testTeardownSoftApInterface(); - assertFalse(mWificondControl.startHostapd( + assertFalse(mWificondControl.registerApListener( TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface, never()).startHostapd(any()); + verify(mApInterface, never()).registerCallback(any()); } /** @@ -427,74 +427,6 @@ public class WificondControlTest { verify(mWificond).tearDownApInterface(TEST_INTERFACE_NAME1); } - /** - * Verifies that enableSupplicant() calls wificond. - */ - @Test - public void testEnableSupplicant() throws Exception { - when(mWifiInjector.makeWificond()).thenReturn(mWificond); - when(mWificond.enableSupplicant()).thenReturn(true); - - assertTrue(mWificondControl.enableSupplicant()); - verify(mWifiInjector).makeWificond(); - verify(mWificond).enableSupplicant(); - } - - /** - * Verifies that enableSupplicant() returns false when there is no configured - * client interface. - */ - @Test - public void testEnableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception { - when(mWifiInjector.makeWificond()).thenReturn(mWificond); - when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface); - - // Configure client interface. - IClientInterface returnedClientInterface = - mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME); - assertEquals(mClientInterface, returnedClientInterface); - - // Tear down interfaces. - assertTrue(mWificondControl.tearDownInterfaces()); - - // Enabling supplicant should fail. - assertFalse(mWificondControl.enableSupplicant()); - } - - /** - * Verifies that disableSupplicant() calls wificond. - */ - @Test - public void testDisableSupplicant() throws Exception { - when(mWifiInjector.makeWificond()).thenReturn(mWificond); - when(mWificond.disableSupplicant()).thenReturn(true); - - assertTrue(mWificondControl.disableSupplicant()); - verify(mWifiInjector).makeWificond(); - verify(mWificond).disableSupplicant(); - } - - /** - * Verifies that disableSupplicant() returns false when there is no configured - * client interface. - */ - @Test - public void testDisableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception { - when(mWifiInjector.makeWificond()).thenReturn(mWificond); - when(mWificond.createClientInterface(TEST_INTERFACE_NAME)).thenReturn(mClientInterface); - - // Configure client interface. - IClientInterface returnedClientInterface = - mWificondControl.setupInterfaceForClientMode(TEST_INTERFACE_NAME); - assertEquals(mClientInterface, returnedClientInterface); - - // Tear down interfaces. - assertTrue(mWificondControl.tearDownInterfaces()); - - // Disabling supplicant should fail. - assertFalse(mWificondControl.disableSupplicant()); - } - /** * Verifies that tearDownInterfaces() calls wificond. */ @@ -910,19 +842,6 @@ public class WificondControlTest { verify(mWifiScannerImpl).abortScan(); } - /** - * Verifies successful soft ap start. - */ - @Test - public void testStartHostapdWithPskConfig() throws Exception { - testSetupInterfaceForSoftApMode(); - when(mApInterface.startHostapd(any())).thenReturn(true); - - assertTrue(mWificondControl.startHostapd( - TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface).startHostapd(any()); - } - /** * Ensures that the Ap interface callbacks are forwarded to the * SoftApListener used for starting soft AP. @@ -934,14 +853,14 @@ public class WificondControlTest { WifiConfiguration config = new WifiConfiguration(); config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8); - when(mApInterface.startHostapd(any())).thenReturn(true); + when(mApInterface.registerCallback(any())).thenReturn(true); final ArgumentCaptor apInterfaceCallbackCaptor = ArgumentCaptor.forClass(IApInterfaceEventCallback.class); - assertTrue(mWificondControl.startHostapd( + assertTrue(mWificondControl.registerApListener( TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface).startHostapd(apInterfaceCallbackCaptor.capture()); + verify(mApInterface).registerCallback(apInterfaceCallbackCaptor.capture()); int numStations = 5; apInterfaceCallbackCaptor.getValue().onNumAssociatedStationsChanged(numStations); @@ -954,97 +873,6 @@ public class WificondControlTest { verify(mSoftApListener).onSoftApChannelSwitched(eq(channelFrequency), eq(channelBandwidth)); } - /** - * Ensure that soft ap start fails when the interface is not setup. - */ - @Test - public void testStartHostapdWithoutSetupInterface() throws Exception { - assertFalse(mWificondControl.startHostapd( - TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface, never()).startHostapd(any()); - } - - /** - * Verifies soft ap start failure. - */ - @Test - public void testStartHostapdFailDueToStartError() throws Exception { - testSetupInterfaceForSoftApMode(); - WifiConfiguration config = new WifiConfiguration(); - config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8); - - when(mApInterface.startHostapd(any())).thenReturn(false); - - assertFalse(mWificondControl.startHostapd( - TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface).startHostapd(any()); - } - - /** - * Verifies soft ap start failure. - */ - @Test - public void testStartHostapdFailDueToExceptionInStart() throws Exception { - testSetupInterfaceForSoftApMode(); - WifiConfiguration config = new WifiConfiguration(); - config.SSID = new String(TEST_SSID, StandardCharsets.UTF_8); - - doThrow(new RemoteException()).when(mApInterface).startHostapd(any()); - - assertFalse(mWificondControl.startHostapd( - TEST_INTERFACE_NAME, mSoftApListener)); - verify(mApInterface).startHostapd(any()); - } - - /** - * Verifies soft ap stop success. - */ - @Test - public void testStopSoftAp() throws Exception { - testSetupInterfaceForSoftApMode(); - - when(mApInterface.stopHostapd()).thenReturn(true); - - assertTrue(mWificondControl.stopHostapd(TEST_INTERFACE_NAME)); - verify(mApInterface).stopHostapd(); - } - - /** - * Ensure that soft ap stop fails when the interface is not setup. - */ - @Test - public void testStopSoftApWithOutSetupInterface() throws Exception { - when(mApInterface.stopHostapd()).thenReturn(true); - assertFalse(mWificondControl.stopHostapd(TEST_INTERFACE_NAME)); - verify(mApInterface, never()).stopHostapd(); - } - - /** - * Verifies soft ap stop failure. - */ - @Test - public void testStopSoftApFailDueToStopError() throws Exception { - testSetupInterfaceForSoftApMode(); - - when(mApInterface.stopHostapd()).thenReturn(false); - - assertFalse(mWificondControl.stopHostapd(TEST_INTERFACE_NAME)); - verify(mApInterface).stopHostapd(); - } - - /** - * Verifies soft ap stop failure. - */ - @Test - public void testStopSoftApFailDueToExceptionInStop() throws Exception { - testSetupInterfaceForSoftApMode(); - - doThrow(new RemoteException()).when(mApInterface).stopHostapd(); - - assertFalse(mWificondControl.stopHostapd(TEST_INTERFACE_NAME)); - verify(mApInterface).stopHostapd(); - } - /** * Verifies registration and invocation of wificond death handler. */ @@ -1073,11 +901,9 @@ public class WificondControlTest { mWificondControl.binderDied(); verify(handler).onDeath(); - // The handles should be cleared after death, so these should retrieve new handles. - when(mWificond.enableSupplicant()).thenReturn(true); - assertTrue(mWificondControl.enableSupplicant()); - verify(mWifiInjector, times(2)).makeWificond(); - verify(mWificond).enableSupplicant(); + // The handles should be cleared after death. + assertNull(mWificondControl.getChannelsForBand(WifiScanner.WIFI_BAND_5_GHZ)); + verify(mWificond, never()).getAvailable5gNonDFSChannels(); } /** -- cgit v1.2.3