summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2020-07-06 19:17:34 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-06 19:17:34 +0000
commitd7a879742d066e8271b9de198c41a29379c3d8bc (patch)
tree02488826624c317469c60a0f218df66f3ac66a82
parent87ab8ddfc56c80fc4288f84dcbeb6a2554387973 (diff)
parent2887f918bde2ae9ae56cf6873987358efc88a296 (diff)
Merge "Fix quickly toggling airplane mode on then off could leave Wifi disabled" into rvc-dev am: 4d67769d06 am: 2887f918bd
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/net/wifi/+/12052906 Change-Id: I2f28f7e82a695a5ccb81b4ff978a3d7c6e8f3e9f
-rw-r--r--service/java/com/android/server/wifi/ActiveModeWarden.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ActiveModeWardenTest.java37
2 files changed, 47 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/ActiveModeWarden.java b/service/java/com/android/server/wifi/ActiveModeWarden.java
index e0a0a3d29..cf54e328b 100644
--- a/service/java/com/android/server/wifi/ActiveModeWarden.java
+++ b/service/java/com/android/server/wifi/ActiveModeWarden.java
@@ -850,6 +850,9 @@ public class ActiveModeWarden {
}
class EnabledState extends BaseState {
+
+ private boolean mIsDisablingDueToAirplaneMode;
+
@Override
public void enter() {
log("EnabledState.enter()");
@@ -857,6 +860,7 @@ public class ActiveModeWarden {
if (!hasAnyModeManager()) {
Log.e(TAG, "Entered EnabledState, but no active mode managers");
}
+ mIsDisablingDueToAirplaneMode = false;
}
@Override
@@ -894,11 +898,15 @@ public class ActiveModeWarden {
case CMD_AIRPLANE_TOGGLED:
// airplane mode toggled on is handled in the default state
if (mSettingsStore.isAirplaneModeOn()) {
+ mIsDisablingDueToAirplaneMode = true;
return NOT_HANDLED;
} else {
- if (hasAnyModeManagerStopping()) {
- // previous airplane mode toggle on is being processed, defer the
+ if (mIsDisablingDueToAirplaneMode) {
+ // Previous airplane mode toggle on is being processed, defer the
// message toggle off until previous processing is completed.
+ // Once previous airplane mode toggle is complete, we should
+ // transition to DisabledState. There, we will process the deferred
+ // airplane mode toggle message to disable airplane mode.
deferMessage(msg);
} else {
// when airplane mode is toggled off, but wifi is on, we can keep it
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
@@ -2240,6 +2240,43 @@ public class ActiveModeWardenTest extends WifiBaseTest {
}
@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 {
enterClientModeActiveState();