Merge "Update Wi-Fi Wakeup setting to check whether the feature is available." into oc-dev
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 9963da1..01ccfee 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -853,11 +853,18 @@
private void setAdditionalSettingsSummaries() {
mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
- 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));
+ 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);
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 2c33fc5..9eea74a 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -70,7 +70,10 @@
@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
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
index ba82835..565aff9 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/SettingsShadowResources.java
@@ -127,6 +127,16 @@
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 {
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 7df5c9a..61981c4 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -18,10 +18,9 @@
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.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.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 @@
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();
}