diff options
Diffstat (limited to 'tests')
3 files changed, 118 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java index db7b4e22f..ceaf76dc8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java @@ -2172,4 +2172,112 @@ public class ActiveModeWardenTest extends WifiBaseTest { when(mWifiNative.isStaApConcurrencySupported()).thenReturn(true); assertTrue(mActiveModeWarden.isStaApConcurrencySupported()); } + + @Test + public void airplaneModeToggleOnDisablesWifi() throws Exception { + enterClientModeActiveState(); + assertInEnabledState(); + + assertWifiShutDown(() -> { + when(mSettingsStore.isAirplaneModeOn()).thenReturn(true); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + }); + + mClientListener.onStopped(); + mLooper.dispatchAll(); + assertInDisabledState(); + } + + @Test + public void airplaneModeToggleOnDisablesSoftAp() throws Exception { + enterSoftApActiveMode(); + assertInEnabledState(); + + assertWifiShutDown(() -> { + when(mSettingsStore.isAirplaneModeOn()).thenReturn(true); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + }); + + mSoftApListener.onStopped(); + mLooper.dispatchAll(); + assertInDisabledState(); + } + + @Test + public void airplaneModeToggleOffIsDeferredWhileProcessingToggleOnWithOneModeManager() + throws Exception { + enterClientModeActiveState(); + assertInEnabledState(); + + // APM toggle on + assertWifiShutDown(() -> { + when(mSettingsStore.isAirplaneModeOn()).thenReturn(true); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + }); + + + // APM toggle off before the stop is complete. + assertInEnabledState(); + when(mClientModeManager.isStopping()).thenReturn(true); + when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + + mClientListener.onStopped(); + mLooper.dispatchAll(); + + verify(mClientModeManager, times(2)).start(); + verify(mClientModeManager, times(2)).setRole(ROLE_CLIENT_PRIMARY); + + mClientListener.onStarted(); + mLooper.dispatchAll(); + + // We should be back to enabled state. + assertInEnabledState(); + } + + @Test + public void airplaneModeToggleOffIsDeferredWhileProcessingToggleOnWithTwoModeManager() + throws Exception { + enterClientModeActiveState(); + enterSoftApActiveMode(); + assertInEnabledState(); + + // APM toggle on + assertWifiShutDown(() -> { + when(mSettingsStore.isAirplaneModeOn()).thenReturn(true); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + }); + + + // APM toggle off before the stop is complete. + assertInEnabledState(); + when(mClientModeManager.isStopping()).thenReturn(true); + when(mSoftApManager.isStopping()).thenReturn(true); + when(mSettingsStore.isAirplaneModeOn()).thenReturn(false); + mActiveModeWarden.airplaneModeToggled(); + mLooper.dispatchAll(); + + // AP stopped, should not process APM toggle. + mSoftApListener.onStopped(); + mLooper.dispatchAll(); + verify(mClientModeManager, times(1)).start(); + verify(mClientModeManager, times(1)).setRole(ROLE_CLIENT_PRIMARY); + + // STA also stopped, should process APM toggle. + mClientListener.onStopped(); + mLooper.dispatchAll(); + verify(mClientModeManager, times(2)).start(); + verify(mClientModeManager, times(2)).setRole(ROLE_CLIENT_PRIMARY); + + mClientListener.onStarted(); + mLooper.dispatchAll(); + + // We should be back to enabled state. + assertInEnabledState(); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java index b733ec0ac..1102d1f26 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java @@ -28,6 +28,7 @@ import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN; import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -469,8 +470,10 @@ public class ClientModeManagerTest extends WifiBaseTest { reset(mContext, mListener); setUpSystemServiceForContext(); mClientModeManager.stop(); + assertTrue(mClientModeManager.isStopping()); mLooper.dispatchAll(); verify(mListener).onStopped(); + assertFalse(mClientModeManager.isStopping()); verify(mImsMmTelManager, never()).registerImsRegistrationCallback(any(), any()); verify(mImsMmTelManager, never()).unregisterImsRegistrationCallback(any()); diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index ca7bc627c..99cd2db82 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -36,6 +36,8 @@ import static com.android.server.wifi.util.ApConfigUtil.DEFAULT_AP_CHANNEL; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyLong; @@ -676,6 +678,7 @@ public class SoftApManagerTest extends WifiBaseTest { InOrder order = inOrder(mCallback, mListener, mContext); mSoftApManager.stop(); + assertTrue(mSoftApManager.isStopping()); mLooper.dispatchAll(); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); @@ -694,6 +697,8 @@ public class SoftApManagerTest extends WifiBaseTest { checkApStateChangedBroadcast(intentCaptor.getValue(), WIFI_AP_STATE_DISABLED, WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, TEST_INTERFACE_NAME, softApModeConfig.getTargetMode()); + order.verify(mListener).onStopped(); + assertFalse(mSoftApManager.isStopping()); } /** @@ -729,6 +734,7 @@ public class SoftApManagerTest extends WifiBaseTest { WIFI_AP_STATE_DISABLING, HOTSPOT_NO_ERROR, TEST_INTERFACE_NAME, softApModeConfig.getTargetMode()); order.verify(mListener).onStopped(); + assertFalse(mSoftApManager.isStopping()); } /** @@ -1784,6 +1790,7 @@ public class SoftApManagerTest extends WifiBaseTest { mSoftApManager.start(); + mSoftApManager.setRole(ActiveModeManager.ROLE_SOFTAP_TETHERED); mLooper.dispatchAll(); verify(mFakeSoftApNotifier).dismissSoftApShutDownTimeoutExpiredNotification(); order.verify(mWifiNative).setupInterfaceForSoftApMode( |