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:
@@ -18,7 +18,11 @@ package com.android.settings.location;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -26,18 +30,24 @@ import com.android.settings.R;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LocationScanningPreferenceControllerTest {
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
private Context mContext;
|
||||
private LocationScanningPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
mController = new LocationScanningPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@@ -48,8 +58,7 @@ public class LocationScanningPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testLocationScanning_WifiOnBleOn() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
@@ -58,8 +67,7 @@ public class LocationScanningPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testLocationScanning_WifiOnBleOff() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
@@ -68,8 +76,7 @@ public class LocationScanningPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testLocationScanning_WifiOffBleOn() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
@@ -78,8 +85,7 @@ public class LocationScanningPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testLocationScanning_WifiOffBleOff() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
assertThat(mController.getSummary()).isEqualTo(
|
||||
|
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package com.android.settings.location;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@@ -39,7 +38,10 @@ public class WifiScanningPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private WifiScanningPreferenceController mController;
|
||||
|
||||
@@ -47,13 +49,16 @@ public class WifiScanningPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||
mController = new WifiScanningPreferenceController(RuntimeEnvironment.application);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
|
||||
mController = new WifiScanningPreferenceController(mContext);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_wifiScanningEnabled_shouldCheckedPreference() {
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -62,7 +67,7 @@ public class WifiScanningPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_wifiScanningDisabled_shouldUncheckedPreference() {
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -75,9 +80,7 @@ public class WifiScanningPreferenceControllerTest {
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final int scanAlways =
|
||||
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
assertThat(scanAlways).isEqualTo(1);
|
||||
verify(mWifiManager).setScanAlwaysAvailable(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,8 +89,6 @@ public class WifiScanningPreferenceControllerTest {
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final int scanAlways =
|
||||
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
assertThat(scanAlways).isEqualTo(0);
|
||||
verify(mWifiManager).setScanAlwaysAvailable(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user