Update Wi-Fi Wakeup setting to check whether the feature is available.
Bug: 38037361 Test: make ROBOTEST_FILTER=WifiWakeupPreferenceControllerTest RunSettingsRoboTests -j40 Change-Id: I1c1b930546cc090d72f3047058a428acd1b2883a
This commit is contained in:
@@ -853,11 +853,18 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
private void setAdditionalSettingsSummaries() {
|
||||
mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
|
||||
final int defaultWakeupAvailable = getResources().getInteger(
|
||||
com.android.internal.R.integer.config_wifi_wakeup_available);
|
||||
boolean wifiWakeupAvailable = Settings.Global.getInt(
|
||||
getContentResolver(), Settings.Global.WIFI_WAKEUP_AVAILABLE, defaultWakeupAvailable)
|
||||
== 1;
|
||||
if (wifiWakeupAvailable) {
|
||||
boolean wifiWakeupEnabled = Settings.Global.getInt(
|
||||
getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
|
||||
mConfigureWifiSettingsPreference.setSummary(getString(wifiWakeupEnabled
|
||||
? R.string.wifi_configure_settings_preference_summary_wakeup_on
|
||||
: R.string.wifi_configure_settings_preference_summary_wakeup_off));
|
||||
}
|
||||
int numSavedNetworks = mWifiTracker.getNumSavedNetworks();
|
||||
if (numSavedNetworks > 0) {
|
||||
mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
|
||||
|
@@ -70,7 +70,10 @@ public class WifiWakeupPreferenceController extends PreferenceController impleme
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
final int defaultValue = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_wifi_wakeup_available);
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_WAKEUP_AVAILABLE, defaultValue) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -127,6 +127,16 @@ public class SettingsShadowResources extends ShadowResources {
|
||||
realResources, Resources.class, "getString", ClassParameter.from(int.class, id));
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getInteger(int id) {
|
||||
final Object override = sResourceOverrides.get(id);
|
||||
if (override instanceof Integer) {
|
||||
return (Integer) override;
|
||||
}
|
||||
return Shadow.directlyOn(
|
||||
realResources, Resources.class, "getInteger", ClassParameter.from(int.class, id));
|
||||
}
|
||||
|
||||
@Implements(Theme.class)
|
||||
public static class SettingsShadowTheme extends ShadowTheme {
|
||||
|
||||
|
@@ -18,10 +18,9 @@ package com.android.settings.wifi;
|
||||
|
||||
import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
|
||||
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
|
||||
import static android.provider.Settings.Global.WIFI_WAKEUP_AVAILABLE;
|
||||
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -34,7 +33,9 @@ import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -43,7 +44,10 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = { SettingsShadowResources.class })
|
||||
public class WifiWakeupPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -55,10 +59,24 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.integer.config_wifi_wakeup_available, 0);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_shouldAlwaysReturnTrue() {
|
||||
public void testIsAvailable_returnsFalseWhenSettingIsNotAvailable() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_AVAILABLE, 0);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_returnsTrueWhenSettingIsAvailable() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_AVAILABLE, 1);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user