summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2018-05-18 11:06:47 -0700
committerRebecca Silberstein <silberst@google.com>2018-05-23 10:10:17 -0700
commit6ecc9ff41652d29b6f5a8e8b1771dc673b0bf29a (patch)
tree6b92c50d9ee452d9275700075d4784fc9a447663 /service
parentf7814ce9117a6622dd1662cbe9396b1684447004 (diff)
WifiStateMachinePrime: discard messages from old managers
Discard updates from previous mode managers in Client and ScanOnly modes. Bug: 79532177 Test: toggle wifi quickly Test: WifiCrashTest Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I790baf5eb522b8aab37834920233d9e751ca0045
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachinePrime.java61
1 files changed, 54 insertions, 7 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachinePrime.java b/service/java/com/android/server/wifi/WifiStateMachinePrime.java
index fcb199eee..85ea001fb 100644
--- a/service/java/com/android/server/wifi/WifiStateMachinePrime.java
+++ b/service/java/com/android/server/wifi/WifiStateMachinePrime.java
@@ -351,16 +351,24 @@ public class WifiStateMachinePrime {
}
class ClientModeActiveState extends ModeActiveState {
+ ClientListener mListener;
private class ClientListener implements ClientModeManager.Listener {
@Override
public void onStateChanged(int state) {
- Log.d(TAG, "State changed from client mode.");
+ // make sure this listener is still active
+ if (this != mListener) {
+ Log.d(TAG, "Client mode state change from previous manager");
+ return;
+ }
+
+ Log.d(TAG, "State changed from client mode. state = " + state);
+
if (state == WifiManager.WIFI_STATE_UNKNOWN) {
// error while setting up client mode or an unexpected failure.
- mModeStateMachine.sendMessage(CMD_CLIENT_MODE_FAILED);
+ mModeStateMachine.sendMessage(CMD_CLIENT_MODE_FAILED, this);
} else if (state == WifiManager.WIFI_STATE_DISABLED) {
// client mode stopped
- mModeStateMachine.sendMessage(CMD_CLIENT_MODE_STOPPED);
+ mModeStateMachine.sendMessage(CMD_CLIENT_MODE_STOPPED, this);
} else if (state == WifiManager.WIFI_STATE_ENABLED) {
// client mode is ready to go
Log.d(TAG, "client mode active");
@@ -374,7 +382,8 @@ public class WifiStateMachinePrime {
public void enter() {
Log.d(TAG, "Entering ClientModeActiveState");
- mManager = mWifiInjector.makeClientModeManager(new ClientListener());
+ mListener = new ClientListener();
+ mManager = mWifiInjector.makeClientModeManager(mListener);
mManager.start();
mActiveModeManagers.add(mManager);
@@ -382,6 +391,12 @@ public class WifiStateMachinePrime {
}
@Override
+ public void exit() {
+ super.exit();
+ mListener = null;
+ }
+
+ @Override
public boolean processMessage(Message message) {
if (checkForAndHandleModeChange(message)) {
return HANDLED;
@@ -392,12 +407,21 @@ public class WifiStateMachinePrime {
Log.d(TAG, "Received CMD_START_CLIENT_MODE when active - drop");
break;
case CMD_CLIENT_MODE_FAILED:
+ if (mListener != message.obj) {
+ Log.d(TAG, "Client mode state change from previous manager");
+ return HANDLED;
+ }
Log.d(TAG, "ClientMode failed, return to WifiDisabledState.");
// notify WifiController that ClientMode failed
mClientModeCallback.onStateChanged(WifiManager.WIFI_STATE_UNKNOWN);
mModeStateMachine.transitionTo(mWifiDisabledState);
break;
case CMD_CLIENT_MODE_STOPPED:
+ if (mListener != message.obj) {
+ Log.d(TAG, "Client mode state change from previous manager");
+ return HANDLED;
+ }
+
Log.d(TAG, "ClientMode stopped, return to WifiDisabledState.");
// notify WifiController that ClientMode stopped
mClientModeCallback.onStateChanged(WifiManager.WIFI_STATE_DISABLED);
@@ -411,17 +435,23 @@ public class WifiStateMachinePrime {
}
class ScanOnlyModeActiveState extends ModeActiveState {
+ ScanOnlyListener mListener;
private class ScanOnlyListener implements ScanOnlyModeManager.Listener {
@Override
public void onStateChanged(int state) {
+ if (this != mListener) {
+ Log.d(TAG, "ScanOnly mode state change from previous manager");
+ return;
+ }
+
if (state == WifiManager.WIFI_STATE_UNKNOWN) {
Log.d(TAG, "ScanOnlyMode mode failed");
// error while setting up scan mode or an unexpected failure.
- mModeStateMachine.sendMessage(CMD_SCAN_ONLY_MODE_FAILED);
+ mModeStateMachine.sendMessage(CMD_SCAN_ONLY_MODE_FAILED, this);
} else if (state == WifiManager.WIFI_STATE_DISABLED) {
Log.d(TAG, "ScanOnlyMode stopped");
//scan only mode stopped
- mModeStateMachine.sendMessage(CMD_SCAN_ONLY_MODE_STOPPED);
+ mModeStateMachine.sendMessage(CMD_SCAN_ONLY_MODE_STOPPED, this);
} else if (state == WifiManager.WIFI_STATE_ENABLED) {
// scan mode is ready to go
Log.d(TAG, "scan mode active");
@@ -435,7 +465,8 @@ public class WifiStateMachinePrime {
public void enter() {
Log.d(TAG, "Entering ScanOnlyModeActiveState");
- mManager = mWifiInjector.makeScanOnlyModeManager(new ScanOnlyListener());
+ mListener = new ScanOnlyListener();
+ mManager = mWifiInjector.makeScanOnlyModeManager(mListener);
mManager.start();
mActiveModeManagers.add(mManager);
@@ -444,6 +475,12 @@ public class WifiStateMachinePrime {
}
@Override
+ public void exit() {
+ super.exit();
+ mListener = null;
+ }
+
+ @Override
public boolean processMessage(Message message) {
if (checkForAndHandleModeChange(message)) {
return HANDLED;
@@ -454,12 +491,22 @@ public class WifiStateMachinePrime {
Log.d(TAG, "Received CMD_START_SCAN_ONLY_MODE when active - drop");
break;
case CMD_SCAN_ONLY_MODE_FAILED:
+ if (mListener != message.obj) {
+ Log.d(TAG, "ScanOnly mode state change from previous manager");
+ return HANDLED;
+ }
+
Log.d(TAG, "ScanOnlyMode failed, return to WifiDisabledState.");
// notify WifiController that ScanOnlyMode failed
mScanOnlyCallback.onStateChanged(WifiManager.WIFI_STATE_UNKNOWN);
mModeStateMachine.transitionTo(mWifiDisabledState);
break;
case CMD_SCAN_ONLY_MODE_STOPPED:
+ if (mListener != message.obj) {
+ Log.d(TAG, "ScanOnly mode state change from previous manager");
+ return HANDLED;
+ }
+
Log.d(TAG, "ScanOnlyMode stopped, return to WifiDisabledState.");
// notify WifiController that ScanOnlyMode stopped
mScanOnlyCallback.onStateChanged(WifiManager.WIFI_STATE_DISABLED);