Disable the wifi wakeup preference when wifi scanning is disabled
Bug: 36033488 Test: Manual testing on the device, make RunSettingsRoboTests Change-Id: I0abfe69a8a84dc9c5e78f1debce7748c92b47e04
This commit is contained in:
@@ -1628,6 +1628,8 @@
|
||||
<string name="wifi_wakeup">Turn on Wi\u2011Fi automatically</string>
|
||||
<!-- Checkbox summary for option to enable Wi-Fi when high quality saved networks are nearby-->
|
||||
<string name="wifi_wakeup_summary">Wi\u2011Fi will turn back on near high\u2011quality saved networks, like your home network</string>
|
||||
<!-- Checkbox summary for Wi-Fi wakeup option to explain that Wi-Fi wakeup is disabled because Wi-Fi scanning is turned off -->
|
||||
<string name="wifi_wakeup_summary_scanning_disabled">Unavailable because Wi\u2011Fi scanning is turned off</string>
|
||||
<!-- Checkbox title for option to toggle poor network detection -->
|
||||
<string name="wifi_poor_network_detection">Avoid poor connections</string>
|
||||
<!-- Checkbox summary for option to toggle poor network detection -->
|
||||
|
@@ -26,6 +26,7 @@ import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
@@ -97,10 +98,20 @@ public class WifiWakeupPreferenceController extends PreferenceController impleme
|
||||
return;
|
||||
}
|
||||
final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
|
||||
|
||||
enableWifiWakeup.setChecked(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1);
|
||||
enableWifiWakeup.setEnabled(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1);
|
||||
|
||||
boolean wifiScanningEnabled = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1;
|
||||
boolean networkRecommendationsEnabled = Settings.Global.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0) == 1;
|
||||
enableWifiWakeup.setEnabled(networkRecommendationsEnabled && wifiScanningEnabled);
|
||||
|
||||
enableWifiWakeup.setSummary(wifiScanningEnabled ?
|
||||
R.string.wifi_wakeup_summary :
|
||||
R.string.wifi_wakeup_summary_scanning_disabled);
|
||||
}
|
||||
|
||||
class SettingObserver extends ContentObserver {
|
||||
|
@@ -17,6 +17,7 @@
|
||||
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_ENABLED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -29,6 +30,7 @@ import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
@@ -52,6 +54,7 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,6 +98,7 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
verify(preference).setEnabled(true);
|
||||
verify(preference).setSummary(R.string.wifi_wakeup_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,5 +111,20 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
|
||||
verify(preference).setChecked(false);
|
||||
verify(preference).setEnabled(false);
|
||||
verify(preference).setSummary(R.string.wifi_wakeup_summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedAndSetDisabledWhenWifiScanningDisabled() {
|
||||
final SwitchPreference preference = mock(SwitchPreference.class);
|
||||
Settings.System.putInt(mContext.getContentResolver(), NETWORK_RECOMMENDATIONS_ENABLED, 1);
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
|
||||
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setChecked(true);
|
||||
verify(preference).setEnabled(false);
|
||||
verify(preference).setSummary(R.string.wifi_wakeup_summary_scanning_disabled);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user