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
This commit is contained in:
@@ -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<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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user