Settings: Use new API for scan throttle toggle
Bug: 148514485 Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.development Test: Verified wifi scan throttle toggle in Developer options Change-Id: Ib42e3650abfb514e95ef8583131cd575c0ac049f
This commit is contained in:
@@ -17,9 +17,8 @@
|
|||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
@@ -29,13 +28,12 @@ import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
|||||||
public class WifiScanThrottlingPreferenceController extends DeveloperOptionsPreferenceController
|
public class WifiScanThrottlingPreferenceController extends DeveloperOptionsPreferenceController
|
||||||
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
|
||||||
private static final String WIFI_SCAN_THROTTLING_KEY = "wifi_scan_throttling";
|
private static final String WIFI_SCAN_THROTTLING_KEY = "wifi_scan_throttling";
|
||||||
@VisibleForTesting
|
|
||||||
static final int SETTING_THROTTLING_ENABLE_VALUE_ON = 1; // default is throttling enabled.
|
private final WifiManager mWifiManager;
|
||||||
@VisibleForTesting
|
|
||||||
static final int SETTING_THROTTLING_ENABLE_VALUE_OFF = 0;
|
|
||||||
|
|
||||||
public WifiScanThrottlingPreferenceController(Context context) {
|
public WifiScanThrottlingPreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mWifiManager = context.getSystemService(WifiManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,28 +44,19 @@ public class WifiScanThrottlingPreferenceController extends DeveloperOptionsPref
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean isEnabled = (Boolean) newValue;
|
final boolean isEnabled = (Boolean) newValue;
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
mWifiManager.setScanThrottleEnabled(isEnabled);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
|
|
||||||
isEnabled
|
|
||||||
? SETTING_THROTTLING_ENABLE_VALUE_ON
|
|
||||||
: SETTING_THROTTLING_ENABLE_VALUE_OFF);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
final int scanThrottleEnabled = Settings.Global.getInt(
|
((SwitchPreference) mPreference).setChecked(mWifiManager.isScanThrottleEnabled());
|
||||||
mContext.getContentResolver(), Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
|
|
||||||
SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
((SwitchPreference) mPreference).setChecked(
|
|
||||||
scanThrottleEnabled == SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDeveloperOptionsSwitchDisabled() {
|
protected void onDeveloperOptionsSwitchDisabled() {
|
||||||
super.onDeveloperOptionsSwitchDisabled();
|
super.onDeveloperOptionsSwitchDisabled();
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
mWifiManager.setScanThrottleEnabled(true);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
((SwitchPreference) mPreference).setChecked(true);
|
((SwitchPreference) mPreference).setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,16 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.development;
|
package com.android.settings.development;
|
||||||
|
|
||||||
import static com.android.settings.development.WifiScanThrottlingPreferenceController.SETTING_THROTTLING_ENABLE_VALUE_OFF;
|
|
||||||
import static com.android.settings.development.WifiScanThrottlingPreferenceController.SETTING_THROTTLING_ENABLE_VALUE_ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
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.provider.Settings;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
@@ -36,7 +31,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class WifiScanThrottlingPreferenceControllerTest {
|
public class WifiScanThrottlingPreferenceControllerTest {
|
||||||
@@ -45,14 +39,16 @@ public class WifiScanThrottlingPreferenceControllerTest {
|
|||||||
private SwitchPreference mPreference;
|
private SwitchPreference mPreference;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private WifiManager mWifiManager;
|
||||||
private WifiScanThrottlingPreferenceController mController;
|
private WifiScanThrottlingPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||||
mController = new WifiScanThrottlingPreferenceController(mContext);
|
mController = new WifiScanThrottlingPreferenceController(mContext);
|
||||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||||
.thenReturn(mPreference);
|
.thenReturn(mPreference);
|
||||||
@@ -63,27 +59,19 @@ public class WifiScanThrottlingPreferenceControllerTest {
|
|||||||
public void onPreferenceChanged_turnOnScanThrottling() {
|
public void onPreferenceChanged_turnOnScanThrottling() {
|
||||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||||
|
|
||||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
verify(mWifiManager).setScanThrottleEnabled(true);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
|
|
||||||
|
|
||||||
assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPreferenceChanged_turnOffScanThrottling() {
|
public void onPreferenceChanged_turnOffScanThrottling() {
|
||||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||||
|
|
||||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
verify(mWifiManager).setScanThrottleEnabled(false);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
|
|
||||||
|
|
||||||
assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_preferenceShouldBeChecked() {
|
public void updateState_preferenceShouldBeChecked() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanThrottleEnabled()).thenReturn(true);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
|
|
||||||
SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
verify(mPreference).setChecked(true);
|
verify(mPreference).setChecked(true);
|
||||||
@@ -91,9 +79,7 @@ public class WifiScanThrottlingPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_preferenceShouldNotBeChecked() {
|
public void updateState_preferenceShouldNotBeChecked() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
when(mWifiManager.isScanThrottleEnabled()).thenReturn(false);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED,
|
|
||||||
SETTING_THROTTLING_ENABLE_VALUE_OFF);
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
verify(mPreference).setChecked(false);
|
verify(mPreference).setChecked(false);
|
||||||
@@ -102,10 +88,7 @@ public class WifiScanThrottlingPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||||
mController.onDeveloperOptionsDisabled();
|
mController.onDeveloperOptionsDisabled();
|
||||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
verify(mWifiManager).setScanThrottleEnabled(true);
|
||||||
Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1 /* default */);
|
|
||||||
|
|
||||||
assertThat(mode).isEqualTo(SETTING_THROTTLING_ENABLE_VALUE_ON);
|
|
||||||
verify(mPreference).setEnabled(false);
|
verify(mPreference).setEnabled(false);
|
||||||
verify(mPreference).setChecked(true);
|
verify(mPreference).setChecked(true);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user