Merge changes from topics "ap_shutdown_timeout_flag", "scan_always_available_API"
* changes: Settings: Use new API for setting wifi scan always on Settings: Use new API for tethering auto shutdown
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);
|
||||
}
|
||||
}
|
||||
|
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
@@ -27,10 +25,12 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -53,6 +53,8 @@ public class WifiScanningRequiredFragmentTest {
|
||||
private Context mContext;
|
||||
private ContentResolver mResolver;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private Fragment mCallbackFragment;
|
||||
@Mock
|
||||
private AlertDialog.Builder mBuilder;
|
||||
@@ -61,12 +63,13 @@ public class WifiScanningRequiredFragmentTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFragment = spy(WifiScanningRequiredFragment.newInstance());
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
mResolver = mContext.getContentResolver();
|
||||
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.setTargetFragment(mCallbackFragment, 1000);
|
||||
Settings.Global.putInt(mResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,8 +77,7 @@ public class WifiScanningRequiredFragmentTest {
|
||||
throws Settings.SettingNotFoundException {
|
||||
mFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
|
||||
|
||||
assertThat(Settings.Global.getInt(mResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE))
|
||||
.isEqualTo(1);
|
||||
verify(mWifiManager).setScanAlwaysAvailable(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -163,7 +163,7 @@ public class WifiSettings2Test {
|
||||
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
||||
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
||||
|
||||
|
@@ -248,7 +248,7 @@ public class WifiSettingsTest {
|
||||
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
||||
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -18,14 +18,21 @@ package com.android.settings.wifi.tether;
|
||||
|
||||
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.Context;
|
||||
import android.provider.Settings;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -34,17 +41,23 @@ import org.robolectric.RuntimeEnvironment;
|
||||
public class WifiTetherAutoOffPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_PREF = "wifi_tether_auto_off";
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
private Context mContext;
|
||||
private WifiTetherAutoOffPreferenceController mController;
|
||||
private SwitchPreference mSwitchPreference;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
private SoftApConfiguration mSoftApConfiguration;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
|
||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||
mSoftApConfiguration = new SoftApConfiguration.Builder().build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
||||
|
||||
mController = new WifiTetherAutoOffPreferenceController(mContext, KEY_PREF);
|
||||
mSwitchPreference = new SwitchPreference(mContext);
|
||||
}
|
||||
@@ -53,19 +66,19 @@ public class WifiTetherAutoOffPreferenceControllerTest {
|
||||
public void testOnPreferenceChange_toggleOn_settingsOn() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
assertThat(getAutoOffSetting()).isEqualTo(ON);
|
||||
assertThat(getAutoOffSetting()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_toggleOff_settingsOff() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(getAutoOffSetting()).isEqualTo(OFF);
|
||||
assertThat(getAutoOffSetting()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_settingsOn_toggleOn() {
|
||||
setAutoOffSetting(ON);
|
||||
setAutoOffSetting(true);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
@@ -74,7 +87,7 @@ public class WifiTetherAutoOffPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateState_settingsOff_toggleOff() {
|
||||
setAutoOffSetting(OFF);
|
||||
setAutoOffSetting(false);
|
||||
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
@@ -88,13 +101,18 @@ public class WifiTetherAutoOffPreferenceControllerTest {
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
private int getAutoOffSetting() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.SOFT_AP_TIMEOUT_ENABLED, OFF);
|
||||
private boolean getAutoOffSetting() {
|
||||
ArgumentCaptor<SoftApConfiguration> softApConfigCaptor =
|
||||
ArgumentCaptor.forClass(SoftApConfiguration.class);
|
||||
verify(mWifiManager).setSoftApConfiguration(softApConfigCaptor.capture());
|
||||
return softApConfigCaptor.getValue().isAutoShutdownEnabled();
|
||||
}
|
||||
|
||||
private void setAutoOffSetting(int config) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.SOFT_AP_TIMEOUT_ENABLED, config);
|
||||
private void setAutoOffSetting(boolean config) {
|
||||
mSoftApConfiguration =
|
||||
new SoftApConfiguration.Builder(mSoftApConfiguration)
|
||||
.setAutoShutdownEnabled(config)
|
||||
.build();
|
||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(mSoftApConfiguration);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user