From 9e80c7bb6a53d2a4ba1df348ea36b43707167840 Mon Sep 17 00:00:00 2001 From: David Su Date: Tue, 30 Jun 2020 17:52:18 -0700 Subject: Fix quickly toggling airplane mode on then off could leave Wifi disabled If Wifi is enabled, and we toggle airplane mode on then off quickly, afterwards wifi could be stuck in the disabled state, even though the expected behavior is that Wifi return to enabled state. This is due to a race between CMD_AIRPLANE_TOGGLED and ClientListener.onStopped(). To fix this, defer CMD_AIRPLANE_TOGGLED if we are still processing a previous CMD_AIRPLANE_TOGGLED. Bug: 160105640 Test: atest ActiveModeWardenTest Test: manually toggle airplane mode on then off quickly while wifi is enabled Change-Id: I8f40dbba0be170a5eca38f0221b4b722cb4b96a4 --- .../android/server/wifi/ActiveModeWardenTest.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (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 ceaf76dc8..8294bdb04 100644 --- a/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java @@ -2239,6 +2239,43 @@ public class ActiveModeWardenTest extends WifiBaseTest { assertInEnabledState(); } + @Test + public void airplaneModeToggleOffIsDeferredWhileProcessingToggleOnWithOneModeManager2() + 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(); + // This test is identical to + // airplaneModeToggleOffIsDeferredWhileProcessingToggleOnWithOneModeManager, except the + // dispatchAll() here is removed. There could be a race between airplaneModeToggled and + // mClientListener.onStopped(). See b/160105640#comment5. + + 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 { -- cgit v1.2.3