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
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
index 9febba3..5ea9b3c 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSwitchBarController.java
@@ -58,6 +58,9 @@
private final WifiManager mWifiManager;
@VisibleForTesting
+ boolean mIsSwitchBusy;
+
+ @VisibleForTesting
DataSaverBackend mDataSaverBackend;
@VisibleForTesting
final ConnectivityManager.OnStartTetheringCallback mOnStartTetheringCallback =
@@ -102,8 +105,8 @@
@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 @@
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 @@
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 0982f26..32e3a61 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 @@
}
@Test
- public void onSwitchChanged_switchNotEnabled_doNothingForTethering() {
- when(mSwitch.isEnabled()).thenReturn(false);
+ public void onSwitchChanged_switchIsBusy_doNothingForTethering() {
+ mController.mIsSwitchBusy = true;
mController.onCheckedChanged(mSwitch, true);