Merge changes from topics "ap_shutdown_timeout_flag", "scan_always_available_API"

* changes:
  WifiOemMigrationHook: Migrate Settings global values
  WifiManager: Add API for scan always available toggle
  SoftApConfiguration: Add shutdown enabled method
This commit is contained in:
Roshan Pius
2020-02-19 16:28:43 +00:00
committed by Android (Google) Code Review
9 changed files with 415 additions and 38 deletions

View File

@@ -40585,13 +40585,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";
}

View File

@@ -7536,6 +7536,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
@@ -7549,14 +7550,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<android.net.MacAddress>, @NonNull java.util.List<android.net.MacAddress>);
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);
}
@@ -7750,6 +7752,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);
@@ -7897,6 +7900,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 {
@@ -7914,6 +7918,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<android.net.wifi.WifiOemMigrationHook.SettingsMigrationData> 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);
@@ -9720,18 +9749,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";
}

View File

@@ -9093,26 +9093,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;
/**
@@ -10206,7 +10214,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";
@@ -10236,7 +10246,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";
/**
@@ -10247,8 +10259,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";
@@ -10257,8 +10269,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";
@@ -10267,8 +10279,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";
/**
@@ -10313,6 +10325,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";
@@ -10352,13 +10365,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";
/**
@@ -10460,8 +10471,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";
@@ -10486,8 +10497,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";
@@ -10529,8 +10540,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";
/**

View File

@@ -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);

View File

@@ -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<MacAddress> 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<MacAddress> blockedList,
@NonNull List<MacAddress> allowedList) {
@SecurityType int securityType, int maxNumberOfClients, boolean shutdownTimeoutEnabled,
int shutdownTimeoutMillis, boolean clientControlByUser,
@NonNull List<MacAddress> blockedList, @NonNull List<MacAddress> 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<MacAddress> 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.
*
* <p>
* <li>If not set, defaults to true</li>
*
* @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 {
*
* <p>
* <li>If not set, defaults to 0</li>
* <li>The shut down timout will apply when
* {@link Settings.Global.SOFT_AP_TIMEOUT_ENABLED} is true</li>
* <li>The shut down timeout will apply when {@link #setAutoShutdownEnabled(boolean)} is
* set to true</li>
*
* @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");
}

View File

@@ -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.
*

View File

@@ -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.
* <p>
@@ -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<SettingsMigrationData> CREATOR =
new Parcelable.Creator<SettingsMigrationData>() {
@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.
*
* <p>
* Note:
* <li> 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.
* </li>
*
* @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();
}
}

View File

@@ -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);

View File

@@ -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();
}
}