Merge "wifi: Add supported channel list in SoftApCapability"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3d8cacd117
@@ -7047,6 +7047,7 @@ package android.net.wifi {
|
||||
method public boolean areFeaturesSupported(long);
|
||||
method public int describeContents();
|
||||
method public int getMaxSupportedClients();
|
||||
method @NonNull public int[] getSupportedChannelList(int);
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.SoftApCapability> CREATOR;
|
||||
field public static final long SOFTAP_FEATURE_ACS_OFFLOAD = 1L; // 0x1L
|
||||
|
||||
@@ -241,6 +241,7 @@ package android.net.wifi {
|
||||
method public boolean areFeaturesSupported(long);
|
||||
method public int describeContents();
|
||||
method public int getMaxSupportedClients();
|
||||
method @NonNull public int[] getSupportedChannelList(int);
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.SoftApCapability> CREATOR;
|
||||
field public static final long SOFTAP_FEATURE_ACS_OFFLOAD = 1L; // 0x1L
|
||||
|
||||
@@ -20,11 +20,14 @@ import android.annotation.LongDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.net.wifi.SoftApConfiguration.BandType;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -36,6 +39,8 @@ import java.util.Objects;
|
||||
@SystemApi
|
||||
public final class SoftApCapability implements Parcelable {
|
||||
|
||||
private static final String TAG = "SoftApCapability";
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
/**
|
||||
* Support for automatic channel selection in driver (ACS).
|
||||
* Driver will auto select best channel based on interference to optimize performance.
|
||||
@@ -82,6 +87,21 @@ public final class SoftApCapability implements Parcelable {
|
||||
|
||||
private int mMaximumSupportedClientNumber;
|
||||
|
||||
/**
|
||||
* A list storing supported 2.4G channels.
|
||||
*/
|
||||
private int[] mSupportedChannelListIn24g = EMPTY_INT_ARRAY;
|
||||
|
||||
/**
|
||||
* A list storing supported 5G channels.
|
||||
*/
|
||||
private int[] mSupportedChannelListIn5g = EMPTY_INT_ARRAY;
|
||||
|
||||
/**
|
||||
* A list storing supported 6G channels.
|
||||
*/
|
||||
private int[] mSupportedChannelListIn6g = EMPTY_INT_ARRAY;
|
||||
|
||||
/**
|
||||
* Get the maximum supported client numbers which AP resides on.
|
||||
*/
|
||||
@@ -110,6 +130,67 @@ public final class SoftApCapability implements Parcelable {
|
||||
return (mSupportedFeatures & features) == features;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set supported channel list in target band type.
|
||||
*
|
||||
* @param band One of the following band types:
|
||||
* {@link SoftApConfiguation#BAND_2GHZ}, {@link SoftApConfiguation#BAND_5GHZ} or
|
||||
* {@link SoftApConfiguation#BAND_6GHZ}.
|
||||
* @param supportedChannelList supported channel list in target band
|
||||
* @return true if band and supportedChannelList are valid, otherwise false.
|
||||
*
|
||||
* @throws IllegalArgumentException when band type is invalid.
|
||||
* @hide
|
||||
*/
|
||||
public boolean setSupportedChannelList(@BandType int band,
|
||||
@Nullable int[] supportedChannelList) {
|
||||
if (supportedChannelList == null) return false;
|
||||
switch (band) {
|
||||
case SoftApConfiguration.BAND_2GHZ:
|
||||
mSupportedChannelListIn24g = supportedChannelList;
|
||||
break;
|
||||
case SoftApConfiguration.BAND_5GHZ:
|
||||
mSupportedChannelListIn5g = supportedChannelList;
|
||||
break;
|
||||
case SoftApConfiguration.BAND_6GHZ:
|
||||
mSupportedChannelListIn6g = supportedChannelList;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid band: " + band);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of the supported channels in the given band.
|
||||
* The result depends on the on the country code that has been set.
|
||||
* Can be used to set the channel of the AP with the
|
||||
* {@link SoftapConfiguration.Builder#setChannel(int, int)} API.
|
||||
*
|
||||
* @param band One of the following band types:
|
||||
* {@link SoftApConfiguation#BAND_2GHZ}, {@link SoftApConfiguation#BAND_5GHZ} or
|
||||
* {@link SoftApConfiguation#BAND_6GHZ}.
|
||||
* @return List of supported channels for the band.
|
||||
*
|
||||
* @throws IllegalArgumentException when band type is invalid.
|
||||
*/
|
||||
@NonNull
|
||||
public int[] getSupportedChannelList(@BandType int band) {
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
switch (band) {
|
||||
case SoftApConfiguration.BAND_2GHZ:
|
||||
return mSupportedChannelListIn24g;
|
||||
case SoftApConfiguration.BAND_5GHZ:
|
||||
return mSupportedChannelListIn5g;
|
||||
case SoftApConfiguration.BAND_6GHZ:
|
||||
return mSupportedChannelListIn6g;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid band: " + band);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -117,6 +198,9 @@ public final class SoftApCapability implements Parcelable {
|
||||
if (source != null) {
|
||||
mSupportedFeatures = source.mSupportedFeatures;
|
||||
mMaximumSupportedClientNumber = source.mMaximumSupportedClientNumber;
|
||||
mSupportedChannelListIn24g = source.mSupportedChannelListIn24g;
|
||||
mSupportedChannelListIn5g = source.mSupportedChannelListIn5g;
|
||||
mSupportedChannelListIn6g = source.mSupportedChannelListIn6g;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,15 +228,20 @@ public final class SoftApCapability implements Parcelable {
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeLong(mSupportedFeatures);
|
||||
dest.writeInt(mMaximumSupportedClientNumber);
|
||||
dest.writeIntArray(mSupportedChannelListIn24g);
|
||||
dest.writeIntArray(mSupportedChannelListIn5g);
|
||||
dest.writeIntArray(mSupportedChannelListIn6g);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
/** Implement the Parcelable interface */
|
||||
public static final Creator<SoftApCapability> CREATOR = new Creator<SoftApCapability>() {
|
||||
public SoftApCapability createFromParcel(Parcel in) {
|
||||
long supportedFeatures = in.readLong();
|
||||
SoftApCapability capability = new SoftApCapability(supportedFeatures);
|
||||
SoftApCapability capability = new SoftApCapability(in.readLong());
|
||||
capability.mMaximumSupportedClientNumber = in.readInt();
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, in.createIntArray());
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, in.createIntArray());
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_6GHZ, in.createIntArray());
|
||||
return capability;
|
||||
}
|
||||
|
||||
@@ -167,6 +256,10 @@ public final class SoftApCapability implements Parcelable {
|
||||
StringBuilder sbuf = new StringBuilder();
|
||||
sbuf.append("SupportedFeatures=").append(mSupportedFeatures);
|
||||
sbuf.append("MaximumSupportedClientNumber=").append(mMaximumSupportedClientNumber);
|
||||
sbuf.append("SupportedChannelListIn24g")
|
||||
.append(Arrays.toString(mSupportedChannelListIn24g));
|
||||
sbuf.append("SupportedChannelListIn5g").append(Arrays.toString(mSupportedChannelListIn5g));
|
||||
sbuf.append("SupportedChannelListIn6g").append(Arrays.toString(mSupportedChannelListIn6g));
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
@@ -176,11 +269,17 @@ public final class SoftApCapability implements Parcelable {
|
||||
if (!(o instanceof SoftApCapability)) return false;
|
||||
SoftApCapability capability = (SoftApCapability) o;
|
||||
return mSupportedFeatures == capability.mSupportedFeatures
|
||||
&& mMaximumSupportedClientNumber == capability.mMaximumSupportedClientNumber;
|
||||
&& mMaximumSupportedClientNumber == capability.mMaximumSupportedClientNumber
|
||||
&& Arrays.equals(mSupportedChannelListIn24g, capability.mSupportedChannelListIn24g)
|
||||
&& Arrays.equals(mSupportedChannelListIn5g, capability.mSupportedChannelListIn5g)
|
||||
&& Arrays.equals(mSupportedChannelListIn6g, capability.mSupportedChannelListIn6g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mSupportedFeatures, mMaximumSupportedClientNumber);
|
||||
return Objects.hash(mSupportedFeatures, mMaximumSupportedClientNumber,
|
||||
Arrays.hashCode(mSupportedChannelListIn24g),
|
||||
Arrays.hashCode(mSupportedChannelListIn5g),
|
||||
Arrays.hashCode(mSupportedChannelListIn6g));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,6 +824,9 @@ public final class SoftApConfiguration implements Parcelable {
|
||||
* Specifies the channel and associated band for the AP.
|
||||
*
|
||||
* The channel which AP resides on. Valid channels are country dependent.
|
||||
* The {@link SoftApCapability#getSupportedChannelList(int)} can be used to obtain
|
||||
* valid channels.
|
||||
*
|
||||
* <p>
|
||||
* The default for the channel is a the special value 0 to have the framework
|
||||
* auto-select a valid channel from the band configured with
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net.wifi;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -37,8 +38,12 @@ public class SoftApCapabilityTest {
|
||||
public void testCopyOperator() throws Exception {
|
||||
long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
|
||||
| SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
|
||||
int[] testSupported2Glist = {1, 2, 3, 4};
|
||||
int[] testSupported5Glist = {36, 149};
|
||||
SoftApCapability capability = new SoftApCapability(testSoftApFeature);
|
||||
capability.setMaxSupportedClients(10);
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
|
||||
|
||||
SoftApCapability copiedCapability = new SoftApCapability(capability);
|
||||
|
||||
@@ -55,6 +60,11 @@ public class SoftApCapabilityTest {
|
||||
| SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
|
||||
SoftApCapability capability = new SoftApCapability(testSoftApFeature);
|
||||
capability.setMaxSupportedClients(10);
|
||||
int[] testSupported2Glist = {1, 2, 3, 4};
|
||||
int[] testSupported5Glist = {36, 149};
|
||||
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
|
||||
capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
capability.writeToParcel(parcelW, 0);
|
||||
@@ -70,4 +80,26 @@ public class SoftApCapabilityTest {
|
||||
assertEquals(capability.hashCode(), fromParcel.hashCode());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetSupportedChannelListWithInvalidBand() {
|
||||
long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
|
||||
| SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
|
||||
SoftApCapability capability = new SoftApCapability(testSoftApFeature);
|
||||
capability.setSupportedChannelList(
|
||||
SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, new int[0]);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetSupportedChannelListWithInvalidBand() {
|
||||
long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
|
||||
| SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
|
||||
SoftApCapability capability = new SoftApCapability(testSoftApFeature);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
|
||||
capability.getSupportedChannelList(
|
||||
SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ);
|
||||
} else {
|
||||
throw new IllegalArgumentException("API doesn't support in current SDK version");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user