From 1861fa18bec911426c4645eb8a2236d328d47fa1 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Mon, 10 Feb 2020 11:53:26 -0800 Subject: [PATCH 1/3] SoftApConfiguration: Add shutdown enabled method This allows us to stop relying on the @hide Settings.Global value. Bug: 147779354 Bug: 148514485 Test: atest android.net.wifi Change-Id: Iacd5553f971cf5bfe1e794b01179e29cb65a1925 --- api/system-current.txt | 6 +- .../android/net/wifi/SoftApConfiguration.java | 71 +++++++++++++++---- .../net/wifi/SoftApConfigurationTest.java | 2 + 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 5b6bd21acede2..cbc63cedef86a 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -7534,6 +7534,7 @@ package android.net.wifi { method public int getChannel(); method public int getMaxNumberOfClients(); method public int getShutdownTimeoutMillis(); + method public boolean isAutoShutdownEnabled(); method public boolean isClientControlByUserEnabled(); method @Nullable public android.net.wifi.WifiConfiguration toWifiConfiguration(); field public static final int BAND_2GHZ = 1; // 0x1 @@ -7547,14 +7548,15 @@ package android.net.wifi { ctor public SoftApConfiguration.Builder(@NonNull android.net.wifi.SoftApConfiguration); method @NonNull public android.net.wifi.SoftApConfiguration build(); method @NonNull public android.net.wifi.SoftApConfiguration.Builder enableClientControlByUser(boolean); + method @NonNull public android.net.wifi.SoftApConfiguration.Builder setAutoShutdownEnabled(boolean); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setBand(int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setBssid(@Nullable android.net.MacAddress); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setChannel(int, int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setClientList(@NonNull java.util.List, @NonNull java.util.List); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setHiddenSsid(boolean); - method @NonNull public android.net.wifi.SoftApConfiguration.Builder setMaxNumberOfClients(int); + method @NonNull public android.net.wifi.SoftApConfiguration.Builder setMaxNumberOfClients(@IntRange(from=0) int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setPassphrase(@Nullable String, int); - method @NonNull public android.net.wifi.SoftApConfiguration.Builder setShutdownTimeoutMillis(int); + method @NonNull public android.net.wifi.SoftApConfiguration.Builder setShutdownTimeoutMillis(@IntRange(from=0) int); method @NonNull public android.net.wifi.SoftApConfiguration.Builder setSsid(@Nullable String); } diff --git a/wifi/java/android/net/wifi/SoftApConfiguration.java b/wifi/java/android/net/wifi/SoftApConfiguration.java index 0db3313ae1372..ae5bf7d5ae847 100644 --- a/wifi/java/android/net/wifi/SoftApConfiguration.java +++ b/wifi/java/android/net/wifi/SoftApConfiguration.java @@ -17,6 +17,7 @@ package android.net.wifi; import android.annotation.IntDef; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; @@ -201,6 +202,11 @@ public final class SoftApConfiguration implements Parcelable { */ private final List mAllowedClientList; + /** + * Whether auto shutdown of soft AP is enabled or not. + */ + private final boolean mAutoShutdownEnabled; + /** * Delay in milliseconds before shutting down soft AP when * there are no connected devices. @@ -240,9 +246,9 @@ public final class SoftApConfiguration implements Parcelable { /** Private constructor for Builder and Parcelable implementation. */ private SoftApConfiguration(@Nullable String ssid, @Nullable MacAddress bssid, @Nullable String passphrase, boolean hiddenSsid, @BandType int band, int channel, - @SecurityType int securityType, int maxNumberOfClients, int shutdownTimeoutMillis, - boolean clientControlByUser, @NonNull List blockedList, - @NonNull List allowedList) { + @SecurityType int securityType, int maxNumberOfClients, boolean shutdownTimeoutEnabled, + int shutdownTimeoutMillis, boolean clientControlByUser, + @NonNull List blockedList, @NonNull List allowedList) { mSsid = ssid; mBssid = bssid; mPassphrase = passphrase; @@ -251,6 +257,7 @@ public final class SoftApConfiguration implements Parcelable { mChannel = channel; mSecurityType = securityType; mMaxNumberOfClients = maxNumberOfClients; + mAutoShutdownEnabled = shutdownTimeoutEnabled; mShutdownTimeoutMillis = shutdownTimeoutMillis; mClientControlByUser = clientControlByUser; mBlockedClientList = new ArrayList<>(blockedList); @@ -274,6 +281,7 @@ public final class SoftApConfiguration implements Parcelable { && mChannel == other.mChannel && mSecurityType == other.mSecurityType && mMaxNumberOfClients == other.mMaxNumberOfClients + && mAutoShutdownEnabled == other.mAutoShutdownEnabled && mShutdownTimeoutMillis == other.mShutdownTimeoutMillis && mClientControlByUser == other.mClientControlByUser && Objects.equals(mBlockedClientList, other.mBlockedClientList) @@ -283,8 +291,9 @@ public final class SoftApConfiguration implements Parcelable { @Override public int hashCode() { return Objects.hash(mSsid, mBssid, mPassphrase, mHiddenSsid, - mBand, mChannel, mSecurityType, mMaxNumberOfClients, mShutdownTimeoutMillis, - mClientControlByUser, mBlockedClientList, mAllowedClientList); + mBand, mChannel, mSecurityType, mMaxNumberOfClients, mAutoShutdownEnabled, + mShutdownTimeoutMillis, mClientControlByUser, mBlockedClientList, + mAllowedClientList); } @Override @@ -299,6 +308,7 @@ public final class SoftApConfiguration implements Parcelable { sbuf.append(" \n Channel =").append(mChannel); sbuf.append(" \n SecurityType=").append(getSecurityType()); sbuf.append(" \n MaxClient=").append(mMaxNumberOfClients); + sbuf.append(" \n AutoShutdownEnabled=").append(mAutoShutdownEnabled); sbuf.append(" \n ShutdownTimeoutMillis=").append(mShutdownTimeoutMillis); sbuf.append(" \n ClientControlByUser=").append(mClientControlByUser); sbuf.append(" \n BlockedClientList=").append(mBlockedClientList); @@ -316,6 +326,7 @@ public final class SoftApConfiguration implements Parcelable { dest.writeInt(mChannel); dest.writeInt(mSecurityType); dest.writeInt(mMaxNumberOfClients); + dest.writeBoolean(mAutoShutdownEnabled); dest.writeInt(mShutdownTimeoutMillis); dest.writeBoolean(mClientControlByUser); dest.writeTypedList(mBlockedClientList); @@ -335,7 +346,7 @@ public final class SoftApConfiguration implements Parcelable { in.readString(), in.readParcelable(MacAddress.class.getClassLoader()), in.readString(), in.readBoolean(), in.readInt(), in.readInt(), in.readInt(), - in.readInt(), in.readInt(), in.readBoolean(), + in.readInt(), in.readBoolean(), in.readInt(), in.readBoolean(), in.createTypedArrayList(MacAddress.CREATOR), in.createTypedArrayList(MacAddress.CREATOR)); } @@ -428,6 +439,18 @@ public final class SoftApConfiguration implements Parcelable { return mMaxNumberOfClients; } + /** + * Returns whether auto shutdown is enabled or not. + * The Soft AP will shutdown when there are no devices associated to it for + * the timeout duration. See {@link Builder#setAutoShutdownEnabled(boolean)}. + * + * @hide + */ + @SystemApi + public boolean isAutoShutdownEnabled() { + return mAutoShutdownEnabled; + } + /** * Returns the shutdown timeout in milliseconds. * The Soft AP will shutdown when there are no devices associated to it for @@ -551,6 +574,7 @@ public final class SoftApConfiguration implements Parcelable { private int mChannel; private int mMaxNumberOfClients; private int mSecurityType; + private boolean mAutoShutdownEnabled; private int mShutdownTimeoutMillis; private boolean mClientControlByUser; private List mBlockedClientList; @@ -568,6 +592,7 @@ public final class SoftApConfiguration implements Parcelable { mChannel = 0; mMaxNumberOfClients = 0; mSecurityType = SECURITY_TYPE_OPEN; + mAutoShutdownEnabled = true; // enabled by default. mShutdownTimeoutMillis = 0; mClientControlByUser = false; mBlockedClientList = new ArrayList<>(); @@ -588,6 +613,7 @@ public final class SoftApConfiguration implements Parcelable { mChannel = other.mChannel; mMaxNumberOfClients = other.mMaxNumberOfClients; mSecurityType = other.mSecurityType; + mAutoShutdownEnabled = other.mAutoShutdownEnabled; mShutdownTimeoutMillis = other.mShutdownTimeoutMillis; mClientControlByUser = other.mClientControlByUser; mBlockedClientList = new ArrayList<>(other.mBlockedClientList); @@ -603,8 +629,8 @@ public final class SoftApConfiguration implements Parcelable { public SoftApConfiguration build() { return new SoftApConfiguration(mSsid, mBssid, mPassphrase, mHiddenSsid, mBand, mChannel, mSecurityType, mMaxNumberOfClients, - mShutdownTimeoutMillis, mClientControlByUser, mBlockedClientList, - mAllowedClientList); + mAutoShutdownEnabled, mShutdownTimeoutMillis, mClientControlByUser, + mBlockedClientList, mAllowedClientList); } /** @@ -789,7 +815,7 @@ public final class SoftApConfiguration implements Parcelable { * @return Builder for chaining. */ @NonNull - public Builder setMaxNumberOfClients(int maxNumberOfClients) { + public Builder setMaxNumberOfClients(@IntRange(from = 0) int maxNumberOfClients) { if (maxNumberOfClients < 0) { throw new IllegalArgumentException("maxNumberOfClients should be not negative"); } @@ -797,6 +823,25 @@ public final class SoftApConfiguration implements Parcelable { return this; } + /** + * Specifies whether auto shutdown is enabled or not. + * The Soft AP will shut down when there are no devices connected to it for + * the timeout duration. + * + *

+ *

  • If not set, defaults to true
  • + * + * @param enable true to enable, false to disable. + * @return Builder for chaining. + * + * @see #setShutdownTimeoutMillis(int) + */ + @NonNull + public Builder setAutoShutdownEnabled(boolean enable) { + mAutoShutdownEnabled = enable; + return this; + } + /** * Specifies the shutdown timeout in milliseconds. * The Soft AP will shut down when there are no devices connected to it for @@ -807,14 +852,16 @@ public final class SoftApConfiguration implements Parcelable { * *

    *

  • If not set, defaults to 0
  • - *
  • The shut down timout will apply when - * {@link Settings.Global.SOFT_AP_TIMEOUT_ENABLED} is true
  • + *
  • The shut down timeout will apply when {@link #setAutoShutdownEnabled(boolean)} is + * set to true
  • * * @param timeoutMillis milliseconds of the timeout delay. * @return Builder for chaining. + * + * @see #setAutoShutdownEnabled(boolean) */ @NonNull - public Builder setShutdownTimeoutMillis(int timeoutMillis) { + public Builder setShutdownTimeoutMillis(@IntRange(from = 0) int timeoutMillis) { if (timeoutMillis < 0) { throw new IllegalArgumentException("Invalid timeout value"); } diff --git a/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java b/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java index d9584885a0455..060ddf05b8d74 100644 --- a/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java +++ b/wifi/tests/src/android/net/wifi/SoftApConfigurationTest.java @@ -125,6 +125,7 @@ public class SoftApConfigurationTest { .setChannel(149, SoftApConfiguration.BAND_5GHZ) .setHiddenSsid(true) .setMaxNumberOfClients(10) + .setAutoShutdownEnabled(true) .setShutdownTimeoutMillis(500000) .enableClientControlByUser(true) .setClientList(testBlockedClientList, testAllowedClientList) @@ -136,6 +137,7 @@ public class SoftApConfigurationTest { assertThat(original.getChannel()).isEqualTo(149); assertThat(original.isHiddenSsid()).isEqualTo(true); assertThat(original.getMaxNumberOfClients()).isEqualTo(10); + assertThat(original.isAutoShutdownEnabled()).isEqualTo(true); assertThat(original.getShutdownTimeoutMillis()).isEqualTo(500000); assertThat(original.isClientControlByUserEnabled()).isEqualTo(true); assertThat(original.getBlockedClientList()).isEqualTo(testBlockedClientList); From 6398957728f963c04fa4f1b7379ebc140c8e5503 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Wed, 12 Feb 2020 12:48:00 -0800 Subject: [PATCH 2/3] WifiManager: Add API for scan always available toggle Needed for moving away from using Settings.Global values as pseudo APIs. Bug: 148514485 Test: atest android.net.wifi Test: Verified wifi wifi scan toggle in location settings. Change-Id: Iec75d331c7866180a55a327813466323c565319a --- api/system-current.txt | 1 + wifi/java/android/net/wifi/IWifiManager.aidl | 2 ++ wifi/java/android/net/wifi/WifiManager.java | 20 +++++++++++++++++++ .../src/android/net/wifi/WifiManagerTest.java | 11 ++++++++++ 4 files changed, 34 insertions(+) diff --git a/api/system-current.txt b/api/system-current.txt index cbc63cedef86a..9efefc59d75c5 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -7750,6 +7750,7 @@ package android.net.wifi { 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); + method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanAlwaysAvailable(boolean); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setScanThrottleEnabled(boolean); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public boolean setSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration); method @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) public void setVerboseLoggingEnabled(boolean); diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 1c330e263d7e0..3025caf740009 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -125,6 +125,8 @@ interface IWifiManager DhcpInfo getDhcpInfo(); + void setScanAlwaysAvailable(boolean isAvailable); + boolean isScanAlwaysAvailable(); boolean acquireWifiLock(IBinder lock, int lockType, String tag, in WorkSource ws); diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index f693315c6cfff..af2f2461ac948 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -2754,6 +2754,26 @@ public class WifiManager { } } + /** + * Set if scanning is always available. + * + * If set to {@code true}, apps can issue {@link #startScan} and fetch scan results + * even when Wi-Fi is turned off. + * + * @param isAvailable true to enable, false to disable. + * @hide + * @see #isScanAlwaysAvailable() + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) + public void setScanAlwaysAvailable(boolean isAvailable) { + try { + mService.setScanAlwaysAvailable(isAvailable); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Check if scanning is always available. * diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 853212aafcdfd..234d929fc05ad 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -2401,4 +2401,15 @@ public class WifiManagerTest { assertFalse(mWifiManager.isAutoWakeupEnabled()); verify(mWifiService).isAutoWakeupEnabled(); } + + + @Test + public void testScanAvailable() throws Exception { + mWifiManager.setScanAlwaysAvailable(true); + verify(mWifiService).setScanAlwaysAvailable(true); + + when(mWifiService.isScanAlwaysAvailable()).thenReturn(false); + assertFalse(mWifiManager.isScanAlwaysAvailable()); + verify(mWifiService).isScanAlwaysAvailable(); + } } From 6d4cb9cdc78cf920ec91ecac41a2b8f127706eb4 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 7 Feb 2020 06:57:14 -0800 Subject: [PATCH 3/3] WifiOemMigrationHook: Migrate Settings global values Changes: a) Add a method to migrate Settings values from platform. b) Marked all of those settings back to @hide. c) Also, deprecated couple of public Settings keys which are no longer used in the wifi stack. Bug: 148514485 Test: Compiles Test: TBD: Add unit tests for this class. Change-Id: I3566cdb53fc997fbb2cc5bceadd865ff8b01539b --- api/current.txt | 12 +- api/system-current.txt | 33 ++- core/java/android/provider/Settings.java | 29 +- .../net/wifi/WifiOemMigrationHook.java | 266 +++++++++++++++++- 4 files changed, 316 insertions(+), 24 deletions(-) diff --git a/api/current.txt b/api/current.txt index 24478f4d06d2b..7aef41b1aa2a8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -40577,13 +40577,13 @@ package android.provider { field public static final String WIFI_MAX_DHCP_RETRY_COUNT = "wifi_max_dhcp_retry_count"; field public static final String WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS = "wifi_mobile_data_transition_wakelock_timeout_ms"; field @Deprecated public static final String WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON = "wifi_networks_available_notification_on"; - field public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY = "wifi_networks_available_repeat_delay"; - field public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept"; + field @Deprecated public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY = "wifi_networks_available_repeat_delay"; + field @Deprecated public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept"; field public static final String WIFI_ON = "wifi_on"; - field public static final String WIFI_SLEEP_POLICY = "wifi_sleep_policy"; - field public static final int WIFI_SLEEP_POLICY_DEFAULT = 0; // 0x0 - field public static final int WIFI_SLEEP_POLICY_NEVER = 2; // 0x2 - field public static final int WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED = 1; // 0x1 + field @Deprecated public static final String WIFI_SLEEP_POLICY = "wifi_sleep_policy"; + field @Deprecated public static final int WIFI_SLEEP_POLICY_DEFAULT = 0; // 0x0 + field @Deprecated public static final int WIFI_SLEEP_POLICY_NEVER = 2; // 0x2 + field @Deprecated public static final int WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED = 1; // 0x1 field public static final String WIFI_WATCHDOG_ON = "wifi_watchdog_on"; field public static final String WINDOW_ANIMATION_SCALE = "window_animation_scale"; } diff --git a/api/system-current.txt b/api/system-current.txt index 9efefc59d75c5..6e14d5d418907 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -7898,6 +7898,7 @@ package android.net.wifi { public final class WifiOemMigrationHook { method @Nullable public static android.net.wifi.WifiOemMigrationHook.ConfigStoreMigrationData loadFromConfigStore(); + method @NonNull public static android.net.wifi.WifiOemMigrationHook.SettingsMigrationData loadFromSettings(@NonNull android.content.Context); } public static final class WifiOemMigrationHook.ConfigStoreMigrationData implements android.os.Parcelable { @@ -7915,6 +7916,31 @@ package android.net.wifi { method @NonNull public android.net.wifi.WifiOemMigrationHook.ConfigStoreMigrationData.Builder setUserSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration); } + public static final class WifiOemMigrationHook.SettingsMigrationData implements android.os.Parcelable { + method public int describeContents(); + method @Nullable public String getP2pDeviceName(); + method public boolean isP2pFactoryResetPending(); + method public boolean isScanAlwaysAvailable(); + method public boolean isScanThrottleEnabled(); + method public boolean isSoftApTimeoutEnabled(); + method public boolean isVerboseLoggingEnabled(); + method public boolean isWakeUpEnabled(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public static final class WifiOemMigrationHook.SettingsMigrationData.Builder { + ctor public WifiOemMigrationHook.SettingsMigrationData.Builder(); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData build(); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setP2pDeviceName(@Nullable String); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setP2pFactoryResetPending(boolean); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setScanAlwaysAvailable(boolean); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setScanThrottleEnabled(boolean); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setSoftApTimeoutEnabled(boolean); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setVerboseLoggingEnabled(boolean); + method @NonNull public android.net.wifi.WifiOemMigrationHook.SettingsMigrationData.Builder setWakeUpEnabled(boolean); + } + public class WifiScanner { method @Deprecated public void configureWifiChange(int, int, int, int, int, android.net.wifi.WifiScanner.BssidInfo[]); method @Deprecated public void configureWifiChange(android.net.wifi.WifiScanner.WifiChangeSettings); @@ -9721,18 +9747,11 @@ package android.provider { field public static final String INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS = "install_carrier_app_notification_sleep_millis"; field public static final String OTA_DISABLE_AUTOMATIC_UPDATE = "ota_disable_automatic_update"; field public static final String REQUIRE_PASSWORD_TO_DECRYPT = "require_password_to_decrypt"; - field public static final String SOFT_AP_TIMEOUT_ENABLED = "soft_ap_timeout_enabled"; field public static final String TETHER_OFFLOAD_DISABLED = "tether_offload_disabled"; field public static final String TETHER_SUPPORTED = "tether_supported"; field public static final String THEATER_MODE_ON = "theater_mode_on"; field public static final String WEBVIEW_MULTIPROCESS = "webview_multiprocess"; field public static final String WIFI_BADGING_THRESHOLDS = "wifi_badging_thresholds"; - field public static final String WIFI_P2P_DEVICE_NAME = "wifi_p2p_device_name"; - field public static final String WIFI_P2P_PENDING_FACTORY_RESET = "wifi_p2p_pending_factory_reset"; - field public static final String WIFI_SCAN_ALWAYS_AVAILABLE = "wifi_scan_always_enabled"; - 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 @Deprecated public static final String WIFI_WAKEUP_ENABLED = "wifi_wakeup_enabled"; } diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index f6072f977ea4e..a319bba886f6e 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -9084,26 +9084,34 @@ public final class Settings { * Set to one of {@link #WIFI_SLEEP_POLICY_DEFAULT}, * {@link #WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED}, or * {@link #WIFI_SLEEP_POLICY_NEVER}. + * @deprecated This is no longer used or set by the platform. */ + @Deprecated public static final String WIFI_SLEEP_POLICY = "wifi_sleep_policy"; /** * Value for {@link #WIFI_SLEEP_POLICY} to use the default Wi-Fi sleep * policy, which is to sleep shortly after the turning off * according to the {@link #STAY_ON_WHILE_PLUGGED_IN} setting. + * @deprecated This is no longer used by the platform. */ + @Deprecated public static final int WIFI_SLEEP_POLICY_DEFAULT = 0; /** * Value for {@link #WIFI_SLEEP_POLICY} to use the default policy when * the device is on battery, and never go to sleep when the device is * plugged in. + * @deprecated This is no longer used by the platform. */ + @Deprecated public static final int WIFI_SLEEP_POLICY_NEVER_WHILE_PLUGGED = 1; /** * Value for {@link #WIFI_SLEEP_POLICY} to never go to sleep. + * @deprecated This is no longer used by the platform. */ + @Deprecated public static final int WIFI_SLEEP_POLICY_NEVER = 2; /** @@ -10197,7 +10205,9 @@ public final class Settings { /** * Delay (in seconds) before repeating the Wi-Fi networks available notification. * Connecting to a network will reset the timer. + * @deprecated This is no longer used or set by the platform. */ + @Deprecated public static final String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY = "wifi_networks_available_repeat_delay"; @@ -10227,7 +10237,9 @@ public final class Settings { /** * When the number of open networks exceeds this number, the * least-recently-used excess networks will be removed. + * @deprecated This is no longer used or set by the platform. */ + @Deprecated public static final String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept"; /** @@ -10238,8 +10250,8 @@ public final class Settings { /** * Setting to allow scans to be enabled even wifi is turned off for connectivity. * @hide + * @deprecated To be removed. */ - @SystemApi public static final String WIFI_SCAN_ALWAYS_AVAILABLE = "wifi_scan_always_enabled"; @@ -10248,8 +10260,8 @@ public final class Settings { * * Type: int (0 for false, 1 for true) * @hide + * @deprecated To be removed. */ - @SystemApi public static final String WIFI_P2P_PENDING_FACTORY_RESET = "wifi_p2p_pending_factory_reset"; @@ -10258,8 +10270,8 @@ public final class Settings { * * Type: int (0 for false, 1 for true) * @hide + * @deprecated To be removed. */ - @SystemApi public static final String SOFT_AP_TIMEOUT_ENABLED = "soft_ap_timeout_enabled"; /** @@ -10304,6 +10316,7 @@ public final class Settings { * Most readers of this setting should simply check if value == 1 to determined the * enabled state. * @hide + * @deprecated To be removed. */ public static final String NETWORK_RECOMMENDATIONS_ENABLED = "network_recommendations_enabled"; @@ -10343,13 +10356,11 @@ public final class Settings { /** * Whether wifi scan throttle is enabled or not. - * This is intended to be used via adb commands or a menu in developer option to turn off - * the default wifi scan throttling mechanism for apps. * * Type: int (0 for false, 1 for true) * @hide + * @deprecated To be removed. */ - @SystemApi public static final String WIFI_SCAN_THROTTLE_ENABLED = "wifi_scan_throttle_enabled"; /** @@ -10451,8 +10462,8 @@ public final class Settings { * Setting to enable verbose logging in Wi-Fi; disabled by default, and setting to 1 * will enable it. In the future, additional values may be supported. * @hide + * @deprecated To be removed. */ - @SystemApi public static final String WIFI_VERBOSE_LOGGING_ENABLED = "wifi_verbose_logging_enabled"; @@ -10477,8 +10488,8 @@ public final class Settings { * Default values are provided by code or device configurations. * Errors in the parameters will cause the entire setting to be ignored. * @hide + * @deprecated This is no longer used or set by the platform. */ - @SystemApi public static final String WIFI_SCORE_PARAMS = "wifi_score_params"; @@ -10520,8 +10531,8 @@ public final class Settings { /** * The Wi-Fi peer-to-peer device name * @hide + * @deprecated To be removed. */ - @SystemApi public static final String WIFI_P2P_DEVICE_NAME = "wifi_p2p_device_name"; /** diff --git a/wifi/java/android/net/wifi/WifiOemMigrationHook.java b/wifi/java/android/net/wifi/WifiOemMigrationHook.java index 22d7786371016..44dbb98a8ab86 100755 --- a/wifi/java/android/net/wifi/WifiOemMigrationHook.java +++ b/wifi/java/android/net/wifi/WifiOemMigrationHook.java @@ -21,8 +21,10 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; +import android.content.Context; import android.os.Parcel; import android.os.Parcelable; +import android.provider.Settings; import java.util.List; @@ -33,6 +35,9 @@ import java.util.List; */ @SystemApi public final class WifiOemMigrationHook { + + private WifiOemMigrationHook() { } + /** * Container for all the wifi config data to migrate. */ @@ -152,8 +157,6 @@ public final class WifiOemMigrationHook { } } - private WifiOemMigrationHook() { } - /** * Load data from OEM's config store. *

    @@ -178,4 +181,263 @@ public final class WifiOemMigrationHook { // Note: OEM's should add code to parse data from their config store format here! return null; } + + /** + * Container for all the wifi settings data to migrate. + */ + public static final class SettingsMigrationData implements Parcelable { + private final boolean mScanAlwaysAvailable; + private final boolean mP2pFactoryResetPending; + private final String mP2pDeviceName; + private final boolean mSoftApTimeoutEnabled; + private final boolean mWakeupEnabled; + private final boolean mScanThrottleEnabled; + private final boolean mVerboseLoggingEnabled; + + private SettingsMigrationData(boolean scanAlwaysAvailable, boolean p2pFactoryResetPending, + @Nullable String p2pDeviceName, boolean softApTimeoutEnabled, boolean wakeupEnabled, + boolean scanThrottleEnabled, boolean verboseLoggingEnabled) { + mScanAlwaysAvailable = scanAlwaysAvailable; + mP2pFactoryResetPending = p2pFactoryResetPending; + mP2pDeviceName = p2pDeviceName; + mSoftApTimeoutEnabled = softApTimeoutEnabled; + mWakeupEnabled = wakeupEnabled; + mScanThrottleEnabled = scanThrottleEnabled; + mVerboseLoggingEnabled = verboseLoggingEnabled; + } + + public static final @NonNull Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public SettingsMigrationData createFromParcel(Parcel in) { + boolean scanAlwaysAvailable = in.readBoolean(); + boolean p2pFactoryResetPending = in.readBoolean(); + String p2pDeviceName = in.readString(); + boolean softApTimeoutEnabled = in.readBoolean(); + boolean wakeupEnabled = in.readBoolean(); + boolean scanThrottleEnabled = in.readBoolean(); + boolean verboseLoggingEnabled = in.readBoolean(); + return new SettingsMigrationData( + scanAlwaysAvailable, p2pFactoryResetPending, + p2pDeviceName, softApTimeoutEnabled, wakeupEnabled, + scanThrottleEnabled, verboseLoggingEnabled); + } + + @Override + public SettingsMigrationData[] newArray(int size) { + return new SettingsMigrationData[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeBoolean(mScanAlwaysAvailable); + dest.writeBoolean(mP2pFactoryResetPending); + dest.writeString(mP2pDeviceName); + dest.writeBoolean(mSoftApTimeoutEnabled); + dest.writeBoolean(mWakeupEnabled); + dest.writeBoolean(mScanThrottleEnabled); + dest.writeBoolean(mVerboseLoggingEnabled); + } + + /** + * @return True if scans are allowed even when wifi is toggled off, false otherwise. + */ + public boolean isScanAlwaysAvailable() { + return mScanAlwaysAvailable; + } + + /** + * @return indicate whether factory reset request is pending. + */ + public boolean isP2pFactoryResetPending() { + return mP2pFactoryResetPending; + } + + /** + * @return the Wi-Fi peer-to-peer device name + */ + public @Nullable String getP2pDeviceName() { + return mP2pDeviceName; + } + + /** + * @return Whether soft AP will shut down after a timeout period when no devices are + * connected. + */ + public boolean isSoftApTimeoutEnabled() { + return mSoftApTimeoutEnabled; + } + + /** + * @return whether Wi-Fi Wakeup feature is enabled. + */ + public boolean isWakeUpEnabled() { + return mWakeupEnabled; + } + + /** + * @return Whether wifi scan throttle is enabled or not. + */ + public boolean isScanThrottleEnabled() { + return mScanThrottleEnabled; + } + + /** + * @return Whether to enable verbose logging in Wi-Fi. + */ + public boolean isVerboseLoggingEnabled() { + return mVerboseLoggingEnabled; + } + + /** + * Builder to create instance of {@link SettingsMigrationData}. + */ + public static final class Builder { + private boolean mScanAlwaysAvailable; + private boolean mP2pFactoryResetPending; + private String mP2pDeviceName; + private boolean mSoftApTimeoutEnabled; + private boolean mWakeupEnabled; + private boolean mScanThrottleEnabled; + private boolean mVerboseLoggingEnabled; + + public Builder() { + } + + /** + * Setting to allow scans even when wifi is toggled off. + * + * @param available true if available, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setScanAlwaysAvailable(boolean available) { + mScanAlwaysAvailable = available; + return this; + } + + /** + * Indicate whether factory reset request is pending. + * + * @param pending true if pending, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setP2pFactoryResetPending(boolean pending) { + mP2pFactoryResetPending = pending; + return this; + } + + /** + * The Wi-Fi peer-to-peer device name + * + * @param name Name if set, null otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setP2pDeviceName(@Nullable String name) { + mP2pDeviceName = name; + return this; + } + + /** + * Whether soft AP will shut down after a timeout period when no devices are connected. + * + * @param enabled true if enabled, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setSoftApTimeoutEnabled(boolean enabled) { + mSoftApTimeoutEnabled = enabled; + return this; + } + + /** + * Value to specify if Wi-Fi Wakeup feature is enabled. + * + * @param enabled true if enabled, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setWakeUpEnabled(boolean enabled) { + mWakeupEnabled = enabled; + return this; + } + + /** + * Whether wifi scan throttle is enabled or not. + * + * @param enabled true if enabled, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setScanThrottleEnabled(boolean enabled) { + mScanThrottleEnabled = enabled; + return this; + } + + /** + * Setting to enable verbose logging in Wi-Fi. + * + * @param enabled true if enabled, false otherwise. + * @return Instance of {@link Builder} to enable chaining of the builder method. + */ + public @NonNull Builder setVerboseLoggingEnabled(boolean enabled) { + mVerboseLoggingEnabled = enabled; + return this; + } + + /** + * Build an instance of {@link SettingsMigrationData}. + * + * @return Instance of {@link SettingsMigrationData}. + */ + public @NonNull SettingsMigrationData build() { + return new SettingsMigrationData(mScanAlwaysAvailable, mP2pFactoryResetPending, + mP2pDeviceName, mSoftApTimeoutEnabled, mWakeupEnabled, mScanThrottleEnabled, + mVerboseLoggingEnabled); + } + } + } + + /** + * Load data from Settings.Global values. + * + *

    + * Note: + *

  • This is method is invoked once on the first bootup. OEM can safely delete these settings + * once the migration is complete. The first & only relevant invocation of + * {@link #loadFromSettings(Context)} ()} occurs when a previously released + * device upgrades to the wifi mainline module from an OEM implementation of the wifi stack. + *
  • + * + * @param context Context to use for loading the settings provider. + * @return Instance of {@link SettingsMigrationData} for migrating data. + */ + @NonNull + public static SettingsMigrationData loadFromSettings(@NonNull Context context) { + return new SettingsMigrationData.Builder() + .setScanAlwaysAvailable( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1) + .setP2pFactoryResetPending( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.WIFI_P2P_PENDING_FACTORY_RESET, 0) == 1) + .setP2pDeviceName( + Settings.Global.getString(context.getContentResolver(), + Settings.Global.WIFI_P2P_DEVICE_NAME)) + .setSoftApTimeoutEnabled( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1) == 1) + .setWakeUpEnabled( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.WIFI_WAKEUP_ENABLED, 0) == 1) + .setScanThrottleEnabled( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.WIFI_SCAN_THROTTLE_ENABLED, 1) == 1) + .setVerboseLoggingEnabled( + Settings.Global.getInt(context.getContentResolver(), + Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 1) == 1) + .build(); + } }