Settings: Use new API for wifi wakeup feature toggle

Bug: 148514485
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi
Test: Verified wifi wakeup feature toggle in wifi settings.
Change-Id: I1e7c0b3ca053a9b7d6105cad16362df38517b51e
This commit is contained in:
Roshan Pius
2020-02-07 09:21:24 -08:00
parent c1313b41a5
commit 65291297a9
6 changed files with 33 additions and 23 deletions

View File

@@ -17,15 +17,17 @@
package com.android.settings.wifi;
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
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;
@@ -53,6 +55,8 @@ public class WifiWakeupPreferenceControllerTest {
@Mock
private LocationManager mLocationManager;
@Mock
private WifiManager mWifiManager;
@Mock
private SwitchPreference mPreference;
@Before
@@ -63,6 +67,7 @@ public class WifiWakeupPreferenceControllerTest {
mController.setFragment(mFragment);
mController.mLocationManager = mLocationManager;
mController.mPreference = mPreference;
mController.mWifiManager = mWifiManager;
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -70,20 +75,19 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.setChecked(true);
assertThat(Settings.Global.getInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0))
.isEqualTo(1);
verify(mWifiManager).setAutoWakeupEnabled(true);
}
@Test
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -97,7 +101,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -111,7 +115,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mController.updateState(preference);
@@ -123,7 +127,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(preference);
@@ -134,7 +138,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingEnabledNoLocation() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -147,7 +151,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -160,7 +164,7 @@ public class WifiWakeupPreferenceControllerTest {
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(false).when(mLocationManager).isLocationEnabled();