diff options
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 |