From c8305dfa608b0e03e20a780dac0ff85945ef72b7 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 4 Oct 2019 13:49:43 -0700 Subject: ActiveModeWarden: Add roles for each mode manager Introducing a new concept of "roles" for each mode manager. This is to make it easier for ActiveModeWarden to create multiple client mode managers in different roles and make it available to the rest of the wifi stack for various STA + STA use-cases. This also tries to homogenize the existing modes of operation for the mode managers (i.e scan only, tethered, local only) into this new "roles" concept. For ex: a) WifiNetworkfactory (which handles the peer to peer API) will request ActiveModeWarden for a ClientModeManager which it can use for making local connection (ActiveModeWarden.getLocalOnlyClientModeManager()). If the device supports STA + STA, ActiveModeWarden will hande WifiNetworkFactory the second STA, otherwise it will hand it the primary STA. b) WifiServiceImpl (which needs to handle public API calls) will request ActiveModeWarden for a ClientModeManager which is being used for primary wifi connection (ActiveModeWarden.getPrimaryClientModeManager()) to route the API calls. Future CL's will follow to enable creation/request for role specific STA's. Bug: 139157226 Test: Togged wifi/softap/APM/location on/off & ensured the existing behavior is preserved. Test: Need to fix unit tests Change-Id: I292ccafef34a6b58787c30bc34be7cafb835ad98 --- .../android/server/wifi/ActiveModeWardenTest.java | 53 ++++++++++++---------- .../android/server/wifi/ClientModeManagerTest.java | 8 ++-- 2 files changed, 34 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java index a8e4a8acc..8510807a8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java @@ -16,15 +16,17 @@ package com.android.server.wifi; -import static com.android.server.wifi.ActiveModeManager.SCAN_NONE; -import static com.android.server.wifi.ActiveModeManager.SCAN_WITHOUT_HIDDEN_NETWORKS; -import static com.android.server.wifi.ActiveModeManager.SCAN_WITH_HIDDEN_NETWORKS; +import static com.android.server.wifi.ActiveModeManager.ROLE_CLIENT_PRIMARY; +import static com.android.server.wifi.ActiveModeManager.ROLE_CLIENT_SCAN_ONLY; +import static com.android.server.wifi.ActiveModeManager.ROLE_SOFTAP_LOCAL_ONLY; +import static com.android.server.wifi.ActiveModeManager.ROLE_SOFTAP_TETHERED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -127,9 +129,9 @@ public class ActiveModeWardenTest extends WifiBaseTest { mLooper = new TestLooper(); when(mWifiInjector.getScanRequestProxy()).thenReturn(mScanRequestProxy); - when(mClientModeManager.getScanMode()).thenReturn(SCAN_WITH_HIDDEN_NETWORKS); + when(mClientModeManager.getRole()).thenReturn(ROLE_CLIENT_PRIMARY); when(mContext.getResources()).thenReturn(mResources); - when(mSoftApManager.getScanMode()).thenReturn(SCAN_NONE); + when(mSoftApManager.getRole()).thenReturn(ROLE_SOFTAP_TETHERED); when(mResources.getString(R.string.wifi_localhotspot_configure_ssid_default)) .thenReturn("AndroidShare"); @@ -203,8 +205,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { */ private void enterClientModeActiveState() throws Exception { String fromState = mActiveModeWarden.getCurrentMode(); - when(mClientModeManager.getScanMode()).thenReturn(SCAN_WITH_HIDDEN_NETWORKS); - when(mClientModeManager.isInConnectMode()).thenReturn(true); + when(mClientModeManager.getRole()).thenReturn(ROLE_CLIENT_PRIMARY); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(true); mActiveModeWarden.wifiToggled(); mLooper.dispatchAll(); @@ -213,7 +214,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToConnectMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_PRIMARY); verify(mScanRequestProxy).enableScanning(true, true); if (fromState.equals(DISABLED_STATE_STRING)) { verify(mBatteryStats).noteWifiOn(); @@ -225,8 +226,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { */ private void enterScanOnlyModeActiveState() throws Exception { String fromState = mActiveModeWarden.getCurrentMode(); - when(mClientModeManager.getScanMode()).thenReturn(SCAN_WITHOUT_HIDDEN_NETWORKS); - when(mClientModeManager.isInScanOnlyMode()).thenReturn(true); + when(mClientModeManager.getRole()).thenReturn(ROLE_CLIENT_SCAN_ONLY); when(mWifiPermissionsUtil.isLocationModeEnabled()).thenReturn(true); when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); when(mSettingsStore.isScanAlwaysAvailable()).thenReturn(true); @@ -238,7 +238,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToScanOnlyMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_SCAN_ONLY); verify(mScanRequestProxy).enableScanning(true, false); if (fromState.equals(DISABLED_STATE_STRING)) { verify(mBatteryStats).noteWifiOn(); @@ -258,6 +258,9 @@ public class ActiveModeWardenTest extends WifiBaseTest { */ private void enterSoftApActiveMode(SoftApModeConfiguration softApConfig) throws Exception { String fromState = mActiveModeWarden.getCurrentMode(); + int softApRole = softApConfig.getTargetMode() == WifiManager.IFACE_IP_MODE_TETHERED + ? ROLE_SOFTAP_TETHERED : ROLE_SOFTAP_LOCAL_ONLY; + when(mSoftApManager.getRole()).thenReturn(softApRole); mActiveModeWarden.startSoftAp(softApConfig); mLooper.dispatchAll(); mSoftApListener.onStarted(); @@ -266,6 +269,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); assertThat(softApConfig).isEqualTo(mSoftApConfig); verify(mSoftApManager).start(); + verify(mSoftApManager).setRole(softApRole); if (fromState.equals(DISABLED_STATE_STRING)) { verify(mBatteryStats).noteWifiOn(); } @@ -499,7 +503,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { reset(mBatteryStats, mScanRequestProxy); enterClientModeActiveState(); mLooper.dispatchAll(); - verify(mClientModeManager).switchToConnectMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_PRIMARY); assertInEnabledState(); } @@ -509,11 +513,13 @@ public class ActiveModeWardenTest extends WifiBaseTest { @Test public void testReenterClientModeActiveStateIsNop() throws Exception { enterClientModeActiveState(); - reset(mClientModeManager); + verify(mClientModeManager, times(1)).start(); + when(mSettingsStore.isWifiToggleEnabled()).thenReturn(true); mActiveModeWarden.wifiToggled(); mLooper.dispatchAll(); - verify(mClientModeManager, never()).start(); + // Should not start again. + verify(mClientModeManager, times(1)).start(); } /** @@ -909,7 +915,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_LOCAL_ONLY, lohsConfigWC); // mock SoftAPManagers - when(mSoftApManager.getIpMode()).thenReturn(WifiManager.IFACE_IP_MODE_TETHERED); + when(mSoftApManager.getRole()).thenReturn(ROLE_SOFTAP_TETHERED); doAnswer(new Answer() { public SoftApManager answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); @@ -920,6 +926,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { any(WifiManager.SoftApCallback.class), eq(tetherConfig)); // make a second softap manager SoftApManager lohsSoftapManager = mock(SoftApManager.class); + when(lohsSoftapManager.getRole()).thenReturn(ROLE_SOFTAP_LOCAL_ONLY); GeneralUtil.Mutable lohsSoftApListener = new GeneralUtil.Mutable<>(); doAnswer(new Answer() { @@ -975,7 +982,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { mActiveModeWarden.scanAlwaysModeChanged(); mLooper.dispatchAll(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToScanOnlyMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_SCAN_ONLY); assertInEnabledState(); verify(mClientModeManager, never()).stop(); } @@ -1008,7 +1015,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToConnectMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_PRIMARY); } /** @@ -1861,7 +1868,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToScanOnlyMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_SCAN_ONLY); mActiveModeWarden.recoveryRestartWifi(SelfRecovery.REASON_WIFINATIVE_FAILURE); mLooper.dispatchAll(); @@ -1875,7 +1882,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mClientModeManager, times(2)).start(); - verify(mClientModeManager, times(2)).switchToScanOnlyMode(); + verify(mClientModeManager, times(2)).setRole(ROLE_CLIENT_SCAN_ONLY); assertInEnabledState(); } @@ -1926,9 +1933,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { enableWifi(); assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).getScanMode(); - verify(mClientModeManager).isInScanOnlyMode(); - verify(mClientModeManager).switchToConnectMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_PRIMARY); when(mFacade.getConfigWiFiDisableInECBM(mContext)).thenReturn(true); assertEnteredEcmMode(() -> { @@ -1940,6 +1945,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEmergencyMode(); assertInDisabledState(); verify(mClientModeManager).stop(); + verify(mClientModeManager, atLeastOnce()).getRole(); mActiveModeWarden.recoveryRestartWifi(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); mLooper.dispatchAll(); @@ -1962,6 +1968,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { WifiManager.IFACE_IP_MODE_LOCAL_ONLY, null)); mLooper.dispatchAll(); verify(mSoftApManager).start(); + verify(mSoftApManager).setRole(ROLE_SOFTAP_LOCAL_ONLY); assertWifiShutDown(() -> { mActiveModeWarden.recoveryRestartWifi(SelfRecovery.REASON_STA_IFACE_DOWN); @@ -2011,7 +2018,7 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); verify(mClientModeManager).start(); - verify(mClientModeManager).switchToScanOnlyMode(); + verify(mClientModeManager).setRole(ROLE_CLIENT_SCAN_ONLY); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java index e94d307b9..8bbfc399e 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java @@ -118,7 +118,7 @@ public class ClientModeManagerTest extends WifiBaseTest { ClientModeImpl.SCAN_ONLY_MODE, TEST_INTERFACE_NAME); mLooper.dispatchAll(); - mClientModeManager.switchToConnectMode(); + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_PRIMARY); mLooper.dispatchAll(); verify(mWifiNative).switchClientInterfaceToConnectivityMode(TEST_INTERFACE_NAME); @@ -208,7 +208,7 @@ public class ClientModeManagerTest extends WifiBaseTest { when(mWifiNative.switchClientInterfaceToConnectivityMode(any())) .thenReturn(true); - mClientModeManager.switchToConnectMode(); + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_PRIMARY); mLooper.dispatchAll(); verify(mSarManager).setScanOnlyWifiState(WIFI_STATE_DISABLED); @@ -242,7 +242,7 @@ public class ClientModeManagerTest extends WifiBaseTest { when(mWifiNative.switchClientInterfaceToScanMode(any())) .thenReturn(true); - mClientModeManager.switchToScanOnlyMode(); + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_SCAN_ONLY); mLooper.dispatchAll(); verifyConnectModeNotificationsForCleanShutdown(WIFI_STATE_ENABLED); @@ -273,7 +273,7 @@ public class ClientModeManagerTest extends WifiBaseTest { mClientModeManager.start(); mLooper.dispatchAll(); - mClientModeManager.switchToConnectMode(); + mClientModeManager.setRole(ActiveModeManager.ROLE_CLIENT_PRIMARY); mLooper.dispatchAll(); ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); -- cgit v1.2.3 From bda99994b4efd25d0b59af53ee10cceedc2b061c Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 25 Oct 2019 12:35:58 -0700 Subject: ActiveModeWarden: Remove redundant SoftApCallback Bug: 139157226 Test: atest com.android.server.wifi Change-Id: I3b31a5e2b1b054c6931e1c00d1f0a7a49e3fb201 --- .../android/server/wifi/ActiveModeWardenTest.java | 34 ---------------------- 1 file changed, 34 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java index 8510807a8..f332ce272 100644 --- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java @@ -643,23 +643,6 @@ public class ActiveModeWardenTest extends WifiBaseTest { verify(mSoftApStateMachineCallback, never()).onConnectedClientsChanged(any()); } - /** - * Verifies that triggering a state change update will not crash if the callback to - * WifiServiceImpl is null. - */ - @Test - public void testNullCallbackToWifiServiceImplForStateChange() throws Exception { - //set the callback to null - mActiveModeWarden.registerSoftApCallback(null); - - enterSoftApActiveMode(); - - mSoftApManagerCallback.onStateChanged(WifiManager.WIFI_AP_STATE_DISABLING, 0); - mLooper.dispatchAll(); - - verify(mSoftApStateMachineCallback, never()).onStateChanged(anyInt(), anyInt()); - } - /** * Verifies that NumClientsChanged event is being passed from SoftApManager to WifiServiceImpl */ @@ -673,23 +656,6 @@ public class ActiveModeWardenTest extends WifiBaseTest { verify(mSoftApStateMachineCallback).onConnectedClientsChanged(testClients); } - /** - * Verifies that triggering a number of clients changed update will not crash if the callback to - * WifiServiceImpl is null. - */ - @Test - public void testNullCallbackToWifiServiceImplForConnectedClientsChanged() throws Exception { - final List testClients = new ArrayList(); - - //set the callback to null - mActiveModeWarden.registerSoftApCallback(null); - - enterSoftApActiveMode(); - mSoftApManagerCallback.onConnectedClientsChanged(testClients); - - verify(mSoftApStateMachineCallback, never()).onConnectedClientsChanged(any()); - } - /** * Test that we remain in the active state when we get a state change update that scan mode is * active. -- cgit v1.2.3