Settings: Use new API for wifi wakeup feature toggle
Bug: 148514485
Test: m RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi
Test: Verified wifi wakeup feature toggle in wifi settings.
Change-Id: I1e7c0b3ca053a9b7d6105cad16362df38517b51e
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 64814fa..9d075a7 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -1020,8 +1020,7 @@
final Context context = getContext();
final PowerManager powerManager = context.getSystemService(PowerManager.class);
final ContentResolver contentResolver = context.getContentResolver();
- return Settings.Global.getInt(contentResolver,
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
+ return mWifiManager.isAutoWakeupEnabled()
&& Settings.Global.getInt(contentResolver,
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
&& Settings.Global.getInt(contentResolver,
diff --git a/src/com/android/settings/wifi/WifiSettings2.java b/src/com/android/settings/wifi/WifiSettings2.java
index 1a7d572..86effea 100644
--- a/src/com/android/settings/wifi/WifiSettings2.java
+++ b/src/com/android/settings/wifi/WifiSettings2.java
@@ -851,8 +851,7 @@
final Context context = getContext();
final PowerManager powerManager = context.getSystemService(PowerManager.class);
final ContentResolver contentResolver = context.getContentResolver();
- return Settings.Global.getInt(contentResolver,
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1
+ return mWifiManager.isAutoWakeupEnabled()
&& Settings.Global.getInt(contentResolver,
Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1
&& Settings.Global.getInt(contentResolver,
diff --git a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
index 855b329..d2a4a98 100644
--- a/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiWakeupPreferenceController.java
@@ -24,6 +24,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
@@ -57,6 +58,9 @@
@VisibleForTesting
LocationManager mLocationManager;
+ @VisibleForTesting
+ WifiManager mWifiManager;
+
private final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -70,6 +74,7 @@
public WifiWakeupPreferenceController(Context context) {
super(context, KEY_ENABLE_WIFI_WAKEUP);
mLocationManager = (LocationManager) context.getSystemService(Service.LOCATION_SERVICE);
+ mWifiManager = context.getSystemService(WifiManager.class);
}
public void setFragment(Fragment hostFragment) {
@@ -160,13 +165,11 @@
}
private boolean getWifiWakeupEnabled() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1;
+ return mWifiManager.isAutoWakeupEnabled();
}
private void setWifiWakeupEnabled(boolean enabled) {
- Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFI_WAKEUP_ENABLED,
- enabled ? 1 : 0);
+ mWifiManager.setAutoWakeupEnabled(enabled);
}
@Override
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
index 320d767..e5b5eb1 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSettings2Test.java
@@ -33,6 +33,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.UserManager;
@@ -71,6 +72,8 @@
@Mock
private PowerManager mPowerManager;
@Mock
+ private WifiManager mWifiManager;
+ @Mock
private DataUsagePreference mDataUsagePreference;
private Context mContext;
private WifiSettings2 mWifiSettings2;
@@ -85,10 +88,12 @@
mWifiSettings2 = spy(new WifiSettings2());
doReturn(mContext).when(mWifiSettings2).getContext();
doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
+ doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
mWifiSettings2.mAddWifiNetworkPreference = new AddWifiNetworkPreference(mContext);
mWifiSettings2.mSavedNetworksPreference = new Preference(mContext);
mWifiSettings2.mConfigureWifiSettingsPreference = new Preference(mContext);
mWifiSettings2.mWifiPickerTracker = mMockWifiPickerTracker;
+ mWifiSettings2.mWifiManager = mWifiManager;
}
@Test
@@ -157,7 +162,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
@@ -171,7 +176,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupDisabled_displayOff() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mWifiSettings2.setAdditionalSettingsSummaries();
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
index 5145cc1..b72a747 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiSettingsTest.java
@@ -186,7 +186,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupEnabled_displayOn() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(contentResolver, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
Settings.Global.putInt(contentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
when(mPowerManager.isPowerSaveMode()).thenReturn(false);
@@ -200,7 +200,7 @@
@Test
public void setAdditionalSettingsSummaries_wifiWakeupDisabled_displayOff() {
final ContentResolver contentResolver = mContext.getContentResolver();
- Settings.Global.putInt(contentResolver, Settings.Global.WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mWifiSettings.setAdditionalSettingsSummaries();
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
index 4266c84..a41d7c8 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiWakeupPreferenceControllerTest.java
@@ -17,15 +17,17 @@
package com.android.settings.wifi;
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;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import android.content.Context;
import android.location.LocationManager;
+import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.text.TextUtils;
@@ -53,6 +55,8 @@
@Mock
private LocationManager mLocationManager;
@Mock
+ private WifiManager mWifiManager;
+ @Mock
private SwitchPreference mPreference;
@Before
@@ -63,6 +67,7 @@
mController.setFragment(mFragment);
mController.mLocationManager = mLocationManager;
mController.mPreference = mPreference;
+ mController.mWifiManager = mWifiManager;
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -70,20 +75,19 @@
@Test
public void setChecked_scanEnableLocationEnable_wifiWakeupEnable() {
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
mController.setChecked(true);
- assertThat(Settings.Global.getInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0))
- .isEqualTo(1);
+ verify(mWifiManager).setAutoWakeupEnabled(true);
}
@Test
public void updateState_wifiWakeupEnableScanningDisable_wifiWakeupDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -97,7 +101,7 @@
@Test
public void updateState_preferenceSetCheckedWhenWakeupSettingEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
doReturn(true).when(mLocationManager).isLocationEnabled();
@@ -111,7 +115,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
mController.updateState(preference);
@@ -123,7 +127,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
mController.updateState(preference);
@@ -134,7 +138,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingEnabledNoLocation() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -147,7 +151,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWakeupSettingDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 0);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(false);
doReturn(false).when(mLocationManager).isLocationEnabled();
mController.updateState(preference);
@@ -160,7 +164,7 @@
@Test
public void updateState_preferenceSetUncheckedWhenWifiScanningDisabledLocationEnabled() {
final SwitchPreference preference = new SwitchPreference(mContext);
- Settings.Global.putInt(mContext.getContentResolver(), WIFI_WAKEUP_ENABLED, 1);
+ when(mWifiManager.isAutoWakeupEnabled()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 0);
doReturn(false).when(mLocationManager).isLocationEnabled();