Merge "Fix "Turn on Wi-Fi scanning?" does not pop up when clicking "Turn on Wi-Fi automatically"" into qt-dev
am: 41656de5d4
Change-Id: I9c051a5ecce1e9f0b2d8b58c1df8fbc7721cb8d7
This commit is contained in:
@@ -97,15 +97,22 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
mFragment.startActivity(intent);
|
||||
} else if (getWifiWakeupEnabled()) {
|
||||
// TODO(b/132391311): WifiWakeupPreferenceController is essentially reimplementing
|
||||
// TogglePreferenceController. Refactor it into TogglePreferenceController.
|
||||
|
||||
// Toggle wifi-wakeup setting between 1/0 based on its current state, and some other checks.
|
||||
if (isWifiWakeupAvailable()) {
|
||||
setWifiWakeupEnabled(false);
|
||||
} else if (!getWifiScanningEnabled()) {
|
||||
showScanningDialog();
|
||||
} else {
|
||||
setWifiWakeupEnabled(true);
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
mFragment.startActivityForResult(intent, WIFI_WAKEUP_REQUEST_CODE);
|
||||
return true;
|
||||
} else if (!getWifiScanningEnabled()) {
|
||||
showScanningDialog();
|
||||
} else {
|
||||
setWifiWakeupEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
updateState(mPreference);
|
||||
@@ -124,9 +131,7 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
|
||||
}
|
||||
final SwitchPreference enableWifiWakeup = (SwitchPreference) preference;
|
||||
|
||||
enableWifiWakeup.setChecked(getWifiWakeupEnabled()
|
||||
&& getWifiScanningEnabled()
|
||||
&& mLocationManager.isLocationEnabled());
|
||||
enableWifiWakeup.setChecked(isWifiWakeupAvailable());
|
||||
if (!mLocationManager.isLocationEnabled()) {
|
||||
preference.setSummary(getNoLocationSummary());
|
||||
} else {
|
||||
@@ -145,7 +150,7 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
|
||||
if (requestCode != WIFI_WAKEUP_REQUEST_CODE) {
|
||||
return;
|
||||
}
|
||||
if (mLocationManager.isLocationEnabled()) {
|
||||
if (mLocationManager.isLocationEnabled() && getWifiScanningEnabled()) {
|
||||
setWifiWakeupEnabled(true);
|
||||
}
|
||||
updateState(mPreference);
|
||||
@@ -168,6 +173,15 @@ public class WifiWakeupPreferenceController extends AbstractPreferenceController
|
||||
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wifi wakeup is available only when both location and Wi-Fi scanning are enabled.
|
||||
*/
|
||||
private boolean isWifiWakeupAvailable() {
|
||||
return getWifiWakeupEnabled()
|
||||
&& getWifiScanningEnabled()
|
||||
&& mLocationManager.isLocationEnabled();
|
||||
}
|
||||
|
||||
private void setWifiWakeupEnabled(boolean enabled) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED,
|
||||
enabled ? 1 : 0);
|
||||
|
@@ -22,6 +22,7 @@ import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.LocationManager;
|
||||
@@ -95,6 +96,19 @@ public class WifiWakeupPreferenceControllerTest {
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_wifiWakeupEnableScanningDisable_wifiWakeupEnable() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
|
||||
doReturn(true).when(mLocationManager).isLocationEnabled();
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
final boolean isWifiWakeupEnabled = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
|
||||
|
||||
assertThat(isWifiWakeupEnabled).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
|
||||
final SwitchPreference preference = new SwitchPreference(mContext);
|
||||
|
Reference in New Issue
Block a user