Settings: Use new API for setting wifi scan always on

Bug: 148514485
Test: Manually verified the toggle from Settings
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi
Change-Id: I0a55b7212c97c11d50b0a05eec743e8ebe9ea6d8
This commit is contained in:
Roshan Pius
2020-02-12 14:17:49 -08:00
parent a023de72a9
commit a7e96dd80e
13 changed files with 66 additions and 67 deletions

View File

@@ -16,22 +16,17 @@
package com.android.settings.wifi;
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.location.LocationManager;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
@@ -69,14 +64,14 @@ public class WifiWakeupPreferenceControllerTest {
mController.mPreference = mPreference;
mController.mWifiManager = mWifiManager;
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
doReturn(true).when(mLocationManager).isLocationEnabled();
}
@Test
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.setChecked(true);
@@ -88,7 +83,7 @@ public class WifiWakeupPreferenceControllerTest {
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -102,7 +97,7 @@ public class WifiWakeupPreferenceControllerTest {
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -128,7 +123,7 @@ public class WifiWakeupPreferenceControllerTest {
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
mController.updateState(preference);
@@ -165,7 +160,7 @@ public class WifiWakeupPreferenceControllerTest {
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);