[Wi-Fi] Control Wi-Fi Hotspot Settings using onClick instead of onSwitchToggled

In the current Settings framework onSwitchToggled has been implemented
to monitor the change in Settings done by user but its getting called
even when Settings is changed using setChecked where under certain
condition like rotation during config changed,
Tether Settings is disabled and then enabled and later before Rotation
Settings remained false due to stop Tethering with Tether Enabled
After Rotation when settings is initialized it is set as disabled
and even after receiving the Tether Enabled it remains Off.
Hence used onClick to monitor user ON/OFF Settings

Bug: 142625203
Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherSwitchBarControllerTest.java
Test: Manual
1. Go to Wifi Hotspot Settings
2. Turn ON
3. Change SSID and save
4. Rotate screen soon after saving
Result: Hotspot does not turn ON, remains in OFF state.
Signed-off-by:JeiFeng Lee <linger.lee@mediatek.com>

Change-Id: Ibddacdf35eb3196f40cdb2c240efa902f9123646
This commit is contained in:
Arc Wang
2020-03-05 18:04:30 +08:00
parent 4a76598ba5
commit ac5e1acfba
3 changed files with 28 additions and 31 deletions

View File

@@ -32,10 +32,8 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkPolicyManager;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import org.junit.Before;
import org.junit.Test;
@@ -70,10 +68,9 @@ public class WifiTetherSwitchBarControllerTest {
when(mContext.getSystemService(Context.NETWORK_POLICY_SERVICE)).thenReturn(
mNetworkPolicyManager);
mController = new WifiTetherSwitchBarController(mContext,
new SwitchBarController(mSwitchBar));
mController = new WifiTetherSwitchBarController(mContext, mSwitchBar);
}
@Test
public void startTether_fail_resetSwitchBar() {
when(mNetworkPolicyManager.getRestrictBackground()).thenReturn(false);
@@ -103,12 +100,12 @@ public class WifiTetherSwitchBarControllerTest {
@Test
public void onSwitchToggled_onlyStartsTetherWhenNeeded() {
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
mController.onSwitchToggled(true);
mController.onClick(mSwitchBar.getSwitch());
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
doReturn(false).when(mWifiManager).isWifiApEnabled();
mController.onSwitchToggled(true);
mController.onClick(mSwitchBar.getSwitch());
verify(mConnectivityManager, times(1))
.startTethering(anyInt(), anyBoolean(), any(), any());