WifiManager: Add API for auto wakeup feature toggle
Needed for moving away from using Settings.Global values as pseudo APIs.
Bug: 148514485
Test: atest android.net.wifi
Test: Verified wifi wakeup feature toggle in wifi settings.
Change-Id: I999d1cf835743e6e56e9bdeeeb67579c8ba48c1c
diff --git a/api/current.txt b/api/current.txt
index 826d409..c481a64 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -31280,6 +31280,7 @@
method public int getWifiState();
method public boolean is5GHzBandSupported();
method public boolean is6GHzBandSupported();
+ method @RequiresPermission(android.Manifest.permission.ACCESS_WIFI_STATE) public boolean isAutoWakeupEnabled();
method @Deprecated public boolean isDeviceToApRttSupported();
method public boolean isEasyConnectSupported();
method public boolean isEnhancedOpenSupported();
diff --git a/api/system-current.txt b/api/system-current.txt
index 88027289..27c59e1 100755
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -7717,6 +7717,7 @@
method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public byte[] retrieveBackupData();
method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public byte[] retrieveSoftApBackupData();
method @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_SETTINGS, android.Manifest.permission.NETWORK_SETUP_WIZARD, android.Manifest.permission.NETWORK_STACK}) public void save(@NonNull android.net.wifi.WifiConfiguration, @Nullable android.net.wifi.WifiManager.ActionListener);
+ method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setAutoWakeupEnabled(boolean);
method @RequiresPermission(android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE) public void setDeviceMobilityState(int);
method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setMacRandomizationSettingPasspointEnabled(@NonNull String, boolean);
method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setMeteredOverridePasspoint(@NonNull String, int);
@@ -9694,7 +9695,7 @@
field public static final String WIFI_SCAN_THROTTLE_ENABLED = "wifi_scan_throttle_enabled";
field public static final String WIFI_SCORE_PARAMS = "wifi_score_params";
field public static final String WIFI_VERBOSE_LOGGING_ENABLED = "wifi_verbose_logging_enabled";
- field public static final String WIFI_WAKEUP_ENABLED = "wifi_wakeup_enabled";
+ field @Deprecated public static final String WIFI_WAKEUP_ENABLED = "wifi_wakeup_enabled";
}
public static final class Settings.Secure extends android.provider.Settings.NameValueTable {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 1c8527d..ea0afa9 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -10207,7 +10207,9 @@
*
* Type: int (0 for false, 1 for true)
* @hide
+ * @deprecated Use {@link WifiManager#isAutoWakeupEnabled()} instead.
*/
+ @Deprecated
@SystemApi
public static final String WIFI_WAKEUP_ENABLED = "wifi_wakeup_enabled";
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index d4e024d..1c330e2 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -272,4 +272,8 @@
boolean isScanThrottleEnabled();
Map getAllMatchingPasspointProfilesForScanResults(in List<ScanResult> scanResult);
+
+ void setAutoWakeupEnabled(boolean enable);
+
+ boolean isAutoWakeupEnabled();
}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index fb30910c..b6f4490 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -6163,4 +6163,50 @@
throw e.rethrowFromSystemServer();
}
}
+
+ /**
+ * Enable/disable wifi auto wakeup feature.
+ *
+ * <p>
+ * The feature is described in
+ * <a href="Wi-Fi Turn on automatically">
+ * https://source.android.com/devices/tech/connect/wifi-infrastructure
+ * #turn_on_wi-fi_automatically
+ * </a>
+ *
+ * @param enable true to enable, false to disable.
+ * @hide
+ */
+ @SystemApi
+ @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
+ public void setAutoWakeupEnabled(boolean enable) {
+ try {
+ mService.setAutoWakeupEnabled(enable);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Get the persisted Wi-Fi auto wakeup feature state. Defaults to false, unless changed by the
+ * user via Settings.
+ *
+ * <p>
+ * The feature is described in
+ * <a href="Wi-Fi Turn on automatically">
+ * https://source.android.com/devices/tech/connect/wifi-infrastructure
+ * #turn_on_wi-fi_automatically
+ * </a>
+ *
+ * @return true to indicate that wakeup feature is enabled, false to indicate that wakeup
+ * feature is disabled.
+ */
+ @RequiresPermission(ACCESS_WIFI_STATE)
+ public boolean isAutoWakeupEnabled() {
+ try {
+ return mService.isAutoWakeupEnabled();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
}
diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java
index 847040c..853212a 100644
--- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java
@@ -2391,4 +2391,14 @@
assertFalse(mWifiManager.isScanThrottleEnabled());
verify(mWifiService).isScanThrottleEnabled();
}
+
+ @Test
+ public void testAutoWakeup() throws Exception {
+ mWifiManager.setAutoWakeupEnabled(true);
+ verify(mWifiService).setAutoWakeupEnabled(true);
+
+ when(mWifiService.isAutoWakeupEnabled()).thenReturn(false);
+ assertFalse(mWifiManager.isAutoWakeupEnabled());
+ verify(mWifiService).isAutoWakeupEnabled();
+ }
}