diff options
author | Rebecca Silberstein <silberst@google.com> | 2018-04-19 09:57:33 -0700 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2018-04-19 11:01:44 -0700 |
commit | 080c2f856866353e300ec431acc106eb076bfeb6 (patch) | |
tree | e20f1d625692fc4a90dea3190ccdf304ad0e5b70 | |
parent | d5faea1644d2360f5c776cb833f2123e1c082f35 (diff) |
ModeManagers should stop their state machine
Mode managers need to stop their state machine when stop() is called.
This prevents other messages from being handled after they are disabled.
Bug: 78264111
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually verified toggle from Settings
Change-Id: I639ff02b794506d765ac3a4caf6320eb5b6ef8dc
6 files changed, 74 insertions, 9 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeManager.java b/service/java/com/android/server/wifi/ClientModeManager.java index bd82876df..4fd3c6e27 100644 --- a/service/java/com/android/server/wifi/ClientModeManager.java +++ b/service/java/com/android/server/wifi/ClientModeManager.java @@ -84,9 +84,7 @@ public class ClientModeManager implements ActiveModeManager { WifiManager.WIFI_STATE_ENABLING); } } - if (currentState != null) { - currentState.exit(); - } + mStateMachine.quitNow(); } /** diff --git a/service/java/com/android/server/wifi/ScanOnlyModeManager.java b/service/java/com/android/server/wifi/ScanOnlyModeManager.java index 4973de53d..ed08a20a4 100644 --- a/service/java/com/android/server/wifi/ScanOnlyModeManager.java +++ b/service/java/com/android/server/wifi/ScanOnlyModeManager.java @@ -75,9 +75,7 @@ public class ScanOnlyModeManager implements ActiveModeManager { public void stop() { IState currentState = mStateMachine.getCurrentState(); Log.d(TAG, " currentstate: " + currentState); - if (currentState != null) { - currentState.exit(); - } + mStateMachine.quitNow(); } /** diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 77c217ab2..a23d046e3 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -146,9 +146,7 @@ public class SoftApManager implements ActiveModeManager { WifiManager.WIFI_AP_STATE_ENABLING, 0); } } - if (currentState != null) { - currentState.exit(); - } + mStateMachine.quitNow(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java index 25987d305..c227f7ce8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeManagerTest.java @@ -298,4 +298,28 @@ public class ClientModeManagerTest { mLooper.dispatchAll(); verifyNotificationsForCleanShutdown(WIFI_STATE_ENABLED); } + + /** + * Verify that onDestroyed after client mode is stopped doesn't trigger a callback. + */ + @Test + public void noCallbackOnInterfaceDestroyedWhenAlreadyStopped() throws Exception { + startClientModeAndVerifyEnabled(); + + reset(mListener); + + mClientModeManager.stop(); + mLooper.dispatchAll(); + + verify(mListener).onStateChanged(WIFI_STATE_DISABLING); + verify(mListener).onStateChanged(WIFI_STATE_DISABLED); + + reset(mListener); + + // now trigger interface destroyed and make sure callback doesn't get called + mInterfaceCallbackCaptor.getValue().onDestroyed(TEST_INTERFACE_NAME); + mLooper.dispatchAll(); + + verifyNoMoreInteractions(mListener); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/ScanOnlyModeManagerTest.java b/tests/wifitests/src/com/android/server/wifi/ScanOnlyModeManagerTest.java index 3d70fa902..838bf7326 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScanOnlyModeManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScanOnlyModeManagerTest.java @@ -236,6 +236,29 @@ public class ScanOnlyModeManagerTest { } /** + * Verify that onDestroyed after scan mode is stopped doesn't trigger a callback. + */ + @Test + public void noCallbackOnInterfaceDestroyedWhenAlreadyStopped() throws Exception { + startScanOnlyModeAndVerifyEnabled(); + + reset(mListener); + + mScanOnlyModeManager.stop(); + mLooper.dispatchAll(); + + verify(mListener).onStateChanged(WIFI_STATE_DISABLED); + + reset(mListener); + + // now trigger interface destroyed and make sure callback doesn't get called + mInterfaceCallbackCaptor.getValue().onDestroyed(TEST_INTERFACE_NAME); + mLooper.dispatchAll(); + + verifyNoMoreInteractions(mListener); + } + + /** * Entering StartedState starts the WakeupController. */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index bce5e8e94..759d8dd0b 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -503,6 +503,30 @@ public class SoftApManagerTest { } /** + * Verify that onDestroyed after softap is stopped doesn't trigger a callback. + */ + @Test + public void noCallbackOnInterfaceDestroyedWhenAlreadyStopped() throws Exception { + SoftApModeConfiguration softApModeConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null); + startSoftApAndVerifyEnabled(softApModeConfig); + + mSoftApManager.stop(); + mLooper.dispatchAll(); + + verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLING, 0); + verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_DISABLED, 0); + + reset(mCallback); + + // now trigger interface destroyed and make sure callback doesn't get called + mWifiNativeInterfaceCallbackCaptor.getValue().onDestroyed(TEST_INTERFACE_NAME); + mLooper.dispatchAll(); + + verifyNoMoreInteractions(mCallback); + } + + /** * Verify that onDown is handled by SoftApManager. */ @Test |