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:
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -25,14 +26,16 @@ import com.android.settings.core.BasePreferenceController;
|
|||||||
|
|
||||||
public class LocationScanningPreferenceController extends BasePreferenceController {
|
public class LocationScanningPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private final WifiManager mWifiManager;
|
||||||
|
|
||||||
public LocationScanningPreferenceController(Context context, String key) {
|
public LocationScanningPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
|
mWifiManager = context.getSystemService(WifiManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
final boolean wifiScanOn = Settings.Global.getInt(mContext.getContentResolver(),
|
final boolean wifiScanOn = mWifiManager.isScanAlwaysAvailable();
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
|
||||||
final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(),
|
final boolean bleScanOn = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
||||||
int resId;
|
int resId;
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
@@ -26,9 +26,11 @@ public class WifiScanningPreferenceController extends AbstractPreferenceControll
|
|||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin {
|
||||||
|
|
||||||
private static final String KEY_WIFI_SCAN_ALWAYS_AVAILABLE = "wifi_always_scanning";
|
private static final String KEY_WIFI_SCAN_ALWAYS_AVAILABLE = "wifi_always_scanning";
|
||||||
|
private final WifiManager mWifiManager;
|
||||||
|
|
||||||
public WifiScanningPreferenceController(Context context) {
|
public WifiScanningPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mWifiManager = context.getSystemService(WifiManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,17 +45,13 @@ public class WifiScanningPreferenceController extends AbstractPreferenceControll
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
((SwitchPreference) preference).setChecked(
|
((SwitchPreference) preference).setChecked(mWifiManager.isScanAlwaysAvailable());
|
||||||
Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (KEY_WIFI_SCAN_ALWAYS_AVAILABLE.equals(preference.getKey())) {
|
if (KEY_WIFI_SCAN_ALWAYS_AVAILABLE.equals(preference.getKey())) {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
mWifiManager.setScanAlwaysAvailable(((SwitchPreference) preference).isChecked());
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
|
|
||||||
((SwitchPreference) preference).isChecked() ? 1 : 0);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -24,7 +24,6 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@@ -80,8 +79,7 @@ public class WifiScanModeActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doPositiveClick() {
|
private void doPositiveClick() {
|
||||||
Settings.Global.putInt(getContentResolver(),
|
getApplicationContext().getSystemService(WifiManager.class).setScanAlwaysAvailable(true);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,8 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -69,8 +69,7 @@ public class WifiScanningRequiredFragment extends InstrumentedDialogFragment imp
|
|||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
switch(which) {
|
switch(which) {
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
Settings.Global.putInt(contentResolver,
|
context.getSystemService(WifiManager.class).setScanAlwaysAvailable(true);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context,
|
||||||
context.getString(R.string.wifi_settings_scanning_required_enabled),
|
context.getString(R.string.wifi_settings_scanning_required_enabled),
|
||||||
|
@@ -1048,8 +1048,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||||
final ContentResolver contentResolver = context.getContentResolver();
|
final ContentResolver contentResolver = context.getContentResolver();
|
||||||
return mWifiManager.isAutoWakeupEnabled()
|
return mWifiManager.isAutoWakeupEnabled()
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& mWifiManager.isScanAlwaysAvailable()
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& Settings.Global.getInt(contentResolver,
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
||||||
&& !powerManager.isPowerSaveMode();
|
&& !powerManager.isPowerSaveMode();
|
||||||
@@ -1060,8 +1059,8 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
||||||
// read the system settings directly. Because when the device is in Airplane mode, even if
|
// read the system settings directly. Because when the device is in Airplane mode, even if
|
||||||
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
||||||
final boolean wifiScanningMode = Settings.Global.getInt(getActivity().getContentResolver(),
|
// TODO(b/149421497): Fix this?
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
final boolean wifiScanningMode = mWifiManager.isScanAlwaysAvailable();
|
||||||
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
||||||
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
||||||
final LinkifyUtils.OnClickListener clickListener =
|
final LinkifyUtils.OnClickListener clickListener =
|
||||||
|
@@ -852,8 +852,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
final PowerManager powerManager = context.getSystemService(PowerManager.class);
|
||||||
final ContentResolver contentResolver = context.getContentResolver();
|
final ContentResolver contentResolver = context.getContentResolver();
|
||||||
return mWifiManager.isAutoWakeupEnabled()
|
return mWifiManager.isAutoWakeupEnabled()
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& mWifiManager.isScanAlwaysAvailable()
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
|
|
||||||
&& Settings.Global.getInt(contentResolver,
|
&& Settings.Global.getInt(contentResolver,
|
||||||
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
Settings.Global.AIRPLANE_MODE_ON, 0) == 0
|
||||||
&& !powerManager.isPowerSaveMode();
|
&& !powerManager.isPowerSaveMode();
|
||||||
@@ -864,8 +863,8 @@ public class WifiSettings2 extends RestrictedSettingsFragment
|
|||||||
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
// Don't use WifiManager.isScanAlwaysAvailable() to check the Wi-Fi scanning mode. Instead,
|
||||||
// read the system settings directly. Because when the device is in Airplane mode, even if
|
// read the system settings directly. Because when the device is in Airplane mode, even if
|
||||||
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
// Wi-Fi scanning mode is on, WifiManager.isScanAlwaysAvailable() still returns "off".
|
||||||
final boolean wifiScanningMode = Settings.Global.getInt(getActivity().getContentResolver(),
|
// TODO(b/149421497): Fix this?
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
final boolean wifiScanningMode = mWifiManager.isScanAlwaysAvailable();
|
||||||
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
final CharSequence description = wifiScanningMode ? getText(R.string.wifi_scan_notify_text)
|
||||||
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
: getText(R.string.wifi_scan_notify_text_scanning_off);
|
||||||
final LinkifyUtils.OnClickListener clickListener =
|
final LinkifyUtils.OnClickListener clickListener =
|
||||||
|
@@ -153,8 +153,7 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getWifiScanningEnabled() {
|
private boolean getWifiScanningEnabled() {
|
||||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
return mWifiManager.isScanAlwaysAvailable();
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showScanningDialog() {
|
private void showScanningDialog() {
|
||||||
|
@@ -18,7 +18,11 @@ package com.android.settings.location;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.content.Context;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -26,18 +30,24 @@ import com.android.settings.R;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class LocationScanningPreferenceControllerTest {
|
public class LocationScanningPreferenceControllerTest {
|
||||||
|
@Mock
|
||||||
|
private WifiManager mWifiManager;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LocationScanningPreferenceController mController;
|
private LocationScanningPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
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");
|
mController = new LocationScanningPreferenceController(mContext, "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +58,7 @@ public class LocationScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationScanning_WifiOnBleOn() {
|
public void testLocationScanning_WifiOnBleOn() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
assertThat(mController.getSummary()).isEqualTo(
|
||||||
@@ -58,8 +67,7 @@ public class LocationScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationScanning_WifiOnBleOff() {
|
public void testLocationScanning_WifiOnBleOff() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
assertThat(mController.getSummary()).isEqualTo(
|
||||||
@@ -68,8 +76,7 @@ public class LocationScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationScanning_WifiOffBleOn() {
|
public void testLocationScanning_WifiOffBleOn() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
assertThat(mController.getSummary()).isEqualTo(
|
||||||
@@ -78,8 +85,7 @@ public class LocationScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationScanning_WifiOffBleOff() {
|
public void testLocationScanning_WifiOffBleOff() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
assertThat(mController.getSummary()).isEqualTo(
|
||||||
|
@@ -15,14 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.location;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.provider.Settings;
|
import android.content.Context;
|
||||||
import android.provider.Settings.Global;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
@@ -39,7 +38,10 @@ public class WifiScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SwitchPreference mPreference;
|
private SwitchPreference mPreference;
|
||||||
|
@Mock
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private WifiScanningPreferenceController mController;
|
private WifiScanningPreferenceController mController;
|
||||||
|
|
||||||
@@ -47,13 +49,16 @@ public class WifiScanningPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
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());
|
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_wifiScanningEnabled_shouldCheckedPreference() {
|
public void updateState_wifiScanningEnabled_shouldCheckedPreference() {
|
||||||
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -62,7 +67,7 @@ public class WifiScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_wifiScanningDisabled_shouldUncheckedPreference() {
|
public void updateState_wifiScanningDisabled_shouldUncheckedPreference() {
|
||||||
Settings.Global.putInt(mContentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -75,9 +80,7 @@ public class WifiScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.handlePreferenceTreeClick(mPreference);
|
mController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
final int scanAlways =
|
verify(mWifiManager).setScanAlwaysAvailable(true);
|
||||||
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
|
||||||
assertThat(scanAlways).isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -86,8 +89,6 @@ public class WifiScanningPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.handlePreferenceTreeClick(mPreference);
|
mController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
final int scanAlways =
|
verify(mWifiManager).setScanAlwaysAvailable(false);
|
||||||
Settings.Global.getInt(mContentResolver, Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
|
||||||
assertThat(scanAlways).isEqualTo(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.isNull;
|
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.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@@ -53,6 +53,8 @@ public class WifiScanningRequiredFragmentTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ContentResolver mResolver;
|
private ContentResolver mResolver;
|
||||||
@Mock
|
@Mock
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
@Mock
|
||||||
private Fragment mCallbackFragment;
|
private Fragment mCallbackFragment;
|
||||||
@Mock
|
@Mock
|
||||||
private AlertDialog.Builder mBuilder;
|
private AlertDialog.Builder mBuilder;
|
||||||
@@ -61,12 +63,13 @@ public class WifiScanningRequiredFragmentTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFragment = spy(WifiScanningRequiredFragment.newInstance());
|
mFragment = spy(WifiScanningRequiredFragment.newInstance());
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||||
mResolver = mContext.getContentResolver();
|
mResolver = mContext.getContentResolver();
|
||||||
|
|
||||||
doReturn(mContext).when(mFragment).getContext();
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
mFragment.setTargetFragment(mCallbackFragment, 1000);
|
mFragment.setTargetFragment(mCallbackFragment, 1000);
|
||||||
Settings.Global.putInt(mResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -74,8 +77,7 @@ public class WifiScanningRequiredFragmentTest {
|
|||||||
throws Settings.SettingNotFoundException {
|
throws Settings.SettingNotFoundException {
|
||||||
mFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
|
mFragment.onClick(null, DialogInterface.BUTTON_POSITIVE);
|
||||||
|
|
||||||
assertThat(Settings.Global.getInt(mResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE))
|
verify(mWifiManager).setScanAlwaysAvailable(false);
|
||||||
.isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -163,7 +163,7 @@ public class WifiSettings2Test {
|
|||||||
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
||||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
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);
|
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||||
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
||||||
|
|
||||||
|
@@ -248,7 +248,7 @@ public class WifiSettingsTest {
|
|||||||
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
|
||||||
final ContentResolver contentResolver = mContext.getContentResolver();
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
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);
|
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
|
||||||
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
|
||||||
|
|
||||||
|
@@ -16,22 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi;
|
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 com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -69,14 +64,14 @@ public class WifiWakeupPreferenceControllerTest {
|
|||||||
mController.mPreference = mPreference;
|
mController.mPreference = mPreference;
|
||||||
mController.mWifiManager = mWifiManager;
|
mController.mWifiManager = mWifiManager;
|
||||||
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||||
doReturn(true).when(mLocationManager).isLocationEnabled();
|
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
|
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
|
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();
|
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||||
|
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
@@ -88,7 +83,7 @@ public class WifiWakeupPreferenceControllerTest {
|
|||||||
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
|
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
|
||||||
final SwitchPreference preference = new SwitchPreference(mContext);
|
final SwitchPreference preference = new SwitchPreference(mContext);
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
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();
|
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
@@ -102,7 +97,7 @@ public class WifiWakeupPreferenceControllerTest {
|
|||||||
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
|
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
|
||||||
final SwitchPreference preference = new SwitchPreference(mContext);
|
final SwitchPreference preference = new SwitchPreference(mContext);
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
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();
|
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
@@ -128,7 +123,7 @@ public class WifiWakeupPreferenceControllerTest {
|
|||||||
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
|
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
|
||||||
final SwitchPreference preference = new SwitchPreference(mContext);
|
final SwitchPreference preference = new SwitchPreference(mContext);
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
@@ -165,7 +160,7 @@ public class WifiWakeupPreferenceControllerTest {
|
|||||||
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
|
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
|
||||||
final SwitchPreference preference = new SwitchPreference(mContext);
|
final SwitchPreference preference = new SwitchPreference(mContext);
|
||||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
|
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();
|
doReturn(false).when(mLocationManager).isLocationEnabled();
|
||||||
|
|
||||||
mController.updateState(preference);
|
mController.updateState(preference);
|
||||||
|
Reference in New Issue
Block a user