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
This commit is contained in:
@@ -57,6 +57,9 @@ public class WifiTetherSwitchBarController implements
|
|||||||
private final ConnectivityManager mConnectivityManager;
|
private final ConnectivityManager mConnectivityManager;
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mIsSwitchBusy;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
DataSaverBackend mDataSaverBackend;
|
DataSaverBackend mDataSaverBackend;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -102,8 +105,8 @@ public class WifiTetherSwitchBarController implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
// Filter out unnecessary callbacks when switch is disabled.
|
// Filter out inappropriate callbacks when switch is busy.
|
||||||
if (!buttonView.isEnabled()) return;
|
if (mIsSwitchBusy) return;
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
startTether();
|
startTether();
|
||||||
@@ -115,14 +118,14 @@ public class WifiTetherSwitchBarController implements
|
|||||||
void stopTether() {
|
void stopTether() {
|
||||||
if (!isWifiApActivated()) return;
|
if (!isWifiApActivated()) return;
|
||||||
|
|
||||||
mSwitchBar.setEnabled(false);
|
mIsSwitchBusy = true;
|
||||||
mConnectivityManager.stopTethering(TETHERING_WIFI);
|
mConnectivityManager.stopTethering(TETHERING_WIFI);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startTether() {
|
void startTether() {
|
||||||
if (isWifiApActivated()) return;
|
if (isWifiApActivated()) return;
|
||||||
|
|
||||||
mSwitchBar.setEnabled(false);
|
mIsSwitchBusy = true;
|
||||||
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
|
mConnectivityManager.startTethering(TETHERING_WIFI, true /* showProvisioningUi */,
|
||||||
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
@@ -159,6 +162,7 @@ public class WifiTetherSwitchBarController implements
|
|||||||
|
|
||||||
private void updateWifiSwitch() {
|
private void updateWifiSwitch() {
|
||||||
mSwitchBar.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
|
mSwitchBar.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
|
||||||
|
mIsSwitchBusy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -147,8 +147,8 @@ public class WifiTetherSwitchBarControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSwitchChanged_switchNotEnabled_doNothingForTethering() {
|
public void onSwitchChanged_switchIsBusy_doNothingForTethering() {
|
||||||
when(mSwitch.isEnabled()).thenReturn(false);
|
mController.mIsSwitchBusy = true;
|
||||||
|
|
||||||
mController.onCheckedChanged(mSwitch, true);
|
mController.onCheckedChanged(mSwitch, true);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user