From 636b3519ba904a53f52076ab8eca8d24b9311142 Mon Sep 17 00:00:00 2001 From: lesl Date: Wed, 5 Aug 2020 22:16:40 +0800 Subject: wifi: Move stop softap flow to looper thread WifiService will change state to enabling before SoftApManager running. If stop cmd executed(main thread) before start cmd(looper thread). It will cause state stuck in enabling Bug: 162714979 Test: atest FrameworksWifiTests Change-Id: Ibd309b669d10f917fbd3f6d3c1d9de6258cedac7 Merged-In: Ibd309b669d10f917fbd3f6d3c1d9de6258cedac7 --- .../com/android/server/wifi/SoftApManager.java | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/service/java/com/android/server/wifi/SoftApManager.java b/service/java/com/android/server/wifi/SoftApManager.java index 9ef52e796..b321a78a1 100644 --- a/service/java/com/android/server/wifi/SoftApManager.java +++ b/service/java/com/android/server/wifi/SoftApManager.java @@ -221,16 +221,7 @@ public class SoftApManager implements ActiveModeManager { public void stop() { Log.d(TAG, " currentstate: " + getCurrentStateName()); mTargetRole = ROLE_UNSPECIFIED; - if (mApInterfaceName != null) { - if (mIfaceIsUp) { - updateApState(WifiManager.WIFI_AP_STATE_DISABLING, - WifiManager.WIFI_AP_STATE_ENABLED, 0); - } else { - updateApState(WifiManager.WIFI_AP_STATE_DISABLING, - WifiManager.WIFI_AP_STATE_ENABLING, 0); - } - } - mStateMachine.quitNow(); + mStateMachine.sendMessage(SoftApStateMachine.CMD_STOP); } @Override @@ -517,6 +508,7 @@ public class SoftApManager implements ActiveModeManager { private class SoftApStateMachine extends StateMachine { // Commands for the state machine. public static final int CMD_START = 0; + public static final int CMD_STOP = 1; public static final int CMD_FAILURE = 2; public static final int CMD_INTERFACE_STATUS_CHANGED = 3; public static final int CMD_ASSOCIATED_STATIONS_CHANGED = 4; @@ -574,6 +566,9 @@ public class SoftApManager implements ActiveModeManager { @Override public boolean processMessage(Message message) { switch (message.what) { + case CMD_STOP: + mStateMachine.quitNow(); + break; case CMD_START: mApInterfaceName = mWifiNative.setupInterfaceForSoftApMode( mWifiNativeInterfaceCallback); @@ -908,6 +903,16 @@ public class SoftApManager implements ActiveModeManager { boolean isUp = message.arg1 == 1; onUpChanged(isUp); break; + case CMD_STOP: + if (mIfaceIsUp) { + updateApState(WifiManager.WIFI_AP_STATE_DISABLING, + WifiManager.WIFI_AP_STATE_ENABLED, 0); + } else { + updateApState(WifiManager.WIFI_AP_STATE_DISABLING, + WifiManager.WIFI_AP_STATE_ENABLING, 0); + } + transitionTo(mIdleState); + break; case CMD_START: // Already started, ignore this command. break; -- cgit v1.2.3