Hide toggle to Turn on Wi-Fi automatically preference in Search settings
- If the location setting is enabled, keep the current design. that the user can switch the toggle directly in the search settings to the "Turn on Wi-Fi automatically" toggle preference.
- If the location setting is disabled, hide the switch toggle to "Turn on Wi-Fi automatically" preference to avoid unexpected behavior.
- The user can click the "Turn on Wi-Fi automatically" preference to jump to the Network preference settings, and see a reminder message in the summary to enable the location settings first before switching the toggle.
- Move the check for mFragment to a suitable location to avoid unnecessary checks.
Bug: 235421460
Test: manual test
make RunSettingsRoboTests ROBOTEST_FILTER=WifiWakeupPreferenceControllerTest
Change-Id: Ib2c6b90308606d32179334d13be91e308971084f
Merged-In: Ib2c6b90308606d32179334d13be91e308971084f
(cherry picked from commit 59403ef3f2
)
This commit is contained in:
@@ -89,6 +89,13 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
// Since mFragment is set only when entering Network preferences settings. So when
|
||||
// mFragment == null, we can assume that the object is created by Search settings.
|
||||
// When Search settings is called, if the dependent condition is not enabled, then
|
||||
// return DISABLED_DEPENDENT_SETTING to hide the toggle.
|
||||
if (mFragment == null && (!getLocationEnabled() || !getWifiScanningEnabled())) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@@ -96,17 +103,16 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
||||
public boolean isChecked() {
|
||||
return getWifiWakeupEnabled()
|
||||
&& getWifiScanningEnabled()
|
||||
&& mLocationManager.isLocationEnabled();
|
||||
&& getLocationEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
if (mFragment == null) {
|
||||
throw new IllegalStateException("No fragment to start activity");
|
||||
}
|
||||
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
if (!getLocationEnabled()) {
|
||||
if (mFragment == null) {
|
||||
throw new IllegalStateException("No fragment to start activity");
|
||||
}
|
||||
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
mFragment.startActivityForResult(intent, WIFI_WAKEUP_REQUEST_CODE);
|
||||
return false;
|
||||
@@ -128,7 +134,7 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
if (!getLocationEnabled()) {
|
||||
return getNoLocationSummary();
|
||||
} else {
|
||||
return mContext.getText(R.string.wifi_wakeup_summary);
|
||||
@@ -151,12 +157,16 @@ public class WifiWakeupPreferenceController extends TogglePreferenceController i
|
||||
if (requestCode != WIFI_WAKEUP_REQUEST_CODE) {
|
||||
return;
|
||||
}
|
||||
if (mLocationManager.isLocationEnabled() && getWifiScanningEnabled()) {
|
||||
if (getLocationEnabled() && getWifiScanningEnabled()) {
|
||||
setWifiWakeupEnabled(true);
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getLocationEnabled() {
|
||||
return mLocationManager.isLocationEnabled();
|
||||
}
|
||||
|
||||
private boolean getWifiScanningEnabled() {
|
||||
return mWifiManager.isScanAlwaysAvailable();
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
@@ -68,6 +71,41 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_fragmentIsNotNull_returnAvailable() {
|
||||
mController.setFragment(mFragment);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_fragmentIsNullAndLocationDisabled_returnDisabled() {
|
||||
mController.setFragment(null);
|
||||
when(mLocationManager.isLocationEnabled()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_fragmentIsNullAndWifiScanDisabled_returnDisabled() {
|
||||
mController.setFragment(null);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_mFragmentIsNullLocationEnable_wifiWakeupEnable() {
|
||||
mController.setFragment(null);
|
||||
when(mLocationManager.isLocationEnabled()).thenReturn(true);
|
||||
when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
|
||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
|
||||
|
||||
mController.setChecked(true);
|
||||
|
||||
verify(mWifiManager).setAutoWakeupEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
|
||||
when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
|
||||
|
Reference in New Issue
Block a user