From 259d3a47c8c210801eb3f40f5d70c0639cc7266e Mon Sep 17 00:00:00 2001 From: Weng Su Date: Wed, 23 Oct 2024 04:35:13 +0800 Subject: [PATCH] Avoid disabling the Wi-Fi hotspot switch causing Talkback confusion - Use local variables to filter inappropriate callbacks when the switch is busy Bug: 374234537 Flag: EXEMPT bugfix Test: Manual testing atest -c WifiTetherSwitchBarControllerTest Change-Id: If5237230c73cae5a6230a6d3fdaa65a8511bdcd8 --- .../wifi/tether/WifiTetherSwitchBarController.java | 12 ++++++++---- .../tether/WifiTetherSwitchBarControllerTest.java | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java index 9febba3b7d0..5ea9b3c8756 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java @@ -57,6 +57,9 @@ public class WifiTetherSwitchBarController implements private final ConnectivityManager mConnectivityManager; private final WifiManager mWifiManager; + @VisibleForTesting + boolean mIsSwitchBusy; + @VisibleForTesting DataSaverBackend mDataSaverBackend; @VisibleForTesting @@ -102,8 +105,8 @@ public class WifiTetherSwitchBarController implements @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - // Filter out unnecessary callbacks when switch is disabled. - if (!buttonView.isEnabled()) return; + // Filter out inappropriate callbacks when switch is busy. + if (mIsSwitchBusy) return; if (isChecked) { startTether(); @@ -115,14 +118,14 @@ public class WifiTetherSwitchBarController implements void stopTether() { if (!isWifiApActivated()) return; - mSwitchBar.setEnabled(false); + mIsSwitchBusy = true; mConnectivityManager.stopTethering(TETHERING_WIFI); } void startTether() { if (isWifiApActivated()) return; - mSwitchBar.setEnabled(false); + mIsSwitchBusy = true; mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */, mOnStartTetheringCallback, new Handler(Looper.getMainLooper())); } @@ -159,6 +162,7 @@ public class WifiTetherSwitchBarController implements private void updateWifiSwitch() { mSwitchBar.setEnabled(!mDataSaverBackend.isDataSaverEnabled()); + mIsSwitchBusy = false; } @Override diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java index 0982f26d76c..32e3a61c860 100644 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSwitchBarControllerTest.java @@ -147,8 +147,8 @@ public class WifiTetherSwitchBarControllerTest { } @Test - public void onSwitchChanged_switchNotEnabled_doNothingForTethering() { - when(mSwitch.isEnabled()).thenReturn(false); + public void onSwitchChanged_switchIsBusy_doNothingForTethering() { + mController.mIsSwitchBusy = true; mController.onCheckedChanged(mSwitch, true);