Merge "Avoid disabling the Wi-Fi hotspot switch causing Talkback confusion" into main

This commit is contained in:
Treehugger Robot
2024-10-28 05:38:51 +00:00
committed by Android (Google) Code Review
2 changed files with 10 additions and 6 deletions

View File

@@ -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

View File

@@ -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);