Skip to content

Commit

Permalink
New startScan API for 6Ghz RNR support
Browse files Browse the repository at this point in the history
Need this new API to configure whether RNR should be activated.

Bug: 158335433
Test: atest android.net.wifi

Change-Id: Id3c1350b59e578081d8937b8140ed20ee8b551a6
  • Loading branch information
xshu committed Jan 27, 2021
1 parent 1ee0214 commit 1bccf82
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
4 changes: 3 additions & 1 deletion core/api/system-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7756,11 +7756,13 @@ package android.net.wifi.nl80211 {
method public boolean setupInterfaceForSoftApMode(@NonNull String);
method @Nullable public android.net.wifi.nl80211.WifiNl80211Manager.SignalPollResult signalPoll(@NonNull String);
method public boolean startPnoScan(@NonNull String, @NonNull android.net.wifi.nl80211.PnoSettings, @NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.nl80211.WifiNl80211Manager.PnoScanRequestCallback);
method public boolean startScan(@NonNull String, int, @Nullable java.util.Set<java.lang.Integer>, @Nullable java.util.List<byte[]>);
method @Deprecated public boolean startScan(@NonNull String, int, @Nullable java.util.Set<java.lang.Integer>, @Nullable java.util.List<byte[]>);
method public boolean startScan(@NonNull String, int, @Nullable java.util.Set<java.lang.Integer>, @Nullable java.util.List<byte[]>, @Nullable android.os.Bundle);
method public boolean stopPnoScan(@NonNull String);
method public boolean tearDownClientInterface(@NonNull String);
method public boolean tearDownInterfaces();
method public boolean tearDownSoftApInterface(@NonNull String);
field public static final String SCANNING_PARAM_ENABLE_6GHZ_RNR = "android.net.wifi.nl80211.SCANNING_PARAM_ENABLE_6GHZ_RNR";
field public static final int SCAN_TYPE_PNO_SCAN = 1; // 0x1
field public static final int SCAN_TYPE_SINGLE_SCAN = 0; // 0x0
field public static final int SEND_MGMT_FRAME_ERROR_ALREADY_STARTED = 5; // 0x5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SingleScanSettings implements Parcelable {
private static final String TAG = "SingleScanSettings";

public int scanType;
public boolean enable6GhzRnr;
public ArrayList<ChannelSettings> channelSettings;
public ArrayList<HiddenNetwork> hiddenNetworks;

Expand All @@ -50,14 +51,15 @@ public boolean equals(Object rhs) {
return false;
}
return scanType == settings.scanType
&& enable6GhzRnr == settings.enable6GhzRnr
&& channelSettings.equals(settings.channelSettings)
&& hiddenNetworks.equals(settings.hiddenNetworks);
}

/** override hash code */
@Override
public int hashCode() {
return Objects.hash(scanType, channelSettings, hiddenNetworks);
return Objects.hash(scanType, channelSettings, hiddenNetworks, enable6GhzRnr);
}


Expand All @@ -83,6 +85,7 @@ public void writeToParcel(Parcel out, int flags) {
Log.wtf(TAG, "Invalid scan type " + scanType);
}
out.writeInt(scanType);
out.writeBoolean(enable6GhzRnr);
out.writeTypedList(channelSettings);
out.writeTypedList(hiddenNetworks);
}
Expand All @@ -100,6 +103,7 @@ public SingleScanSettings createFromParcel(Parcel in) {
if (!isValidScanType(result.scanType)) {
Log.wtf(TAG, "Invalid scan type " + result.scanType);
}
result.enable6GhzRnr = in.readBoolean();
result.channelSettings = new ArrayList<ChannelSettings>();
in.readTypedList(result.channelSettings, ChannelSettings.CREATOR);
result.hiddenNetworks = new ArrayList<HiddenNetwork>();
Expand Down
21 changes: 20 additions & 1 deletion wifi/java/src/android/net/wifi/nl80211/WifiNl80211Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.net.wifi.WifiAnnotations;
import android.net.wifi.WifiScanner;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
Expand Down Expand Up @@ -90,6 +91,10 @@ public class WifiNl80211Manager {
*/
public static final int SCAN_TYPE_PNO_SCAN = 1;

// Extra scanning parameter used to enable 6Ghz RNR (Reduced Neighbour Support).
public static final String SCANNING_PARAM_ENABLE_6GHZ_RNR =
"android.net.wifi.nl80211.SCANNING_PARAM_ENABLE_6GHZ_RNR";

private AlarmManager mAlarmManager;
private Handler mEventHandler;

Expand Down Expand Up @@ -910,6 +915,15 @@ private static int getScanType(@WifiAnnotations.ScanType int scanType) {
}
}

/**
* @deprecated replaced by {@link #startScan(String, int, Set, List, Bundle)}
**/
@Deprecated
public boolean startScan(@NonNull String ifaceName, @WifiAnnotations.ScanType int scanType,
@Nullable Set<Integer> freqs, @Nullable List<byte[]> hiddenNetworkSSIDs) {
return startScan(ifaceName, scanType, freqs, hiddenNetworkSSIDs, null);
}

/**
* Start a scan using the specified parameters. A scan is an asynchronous operation. The
* result of the operation is returned in the {@link ScanEventCallback} registered when
Expand All @@ -929,11 +943,13 @@ private static int getScanType(@WifiAnnotations.ScanType int scanType) {
* @param freqs list of frequencies to scan for, if null scan all supported channels.
* @param hiddenNetworkSSIDs List of hidden networks to be scanned for, a null indicates that
* no hidden frequencies will be scanned for.
* @param extraScanningParams bundle of extra scanning parameters.
* @return Returns true on success, false on failure (e.g. when called before the interface
* has been set up).
*/
public boolean startScan(@NonNull String ifaceName, @WifiAnnotations.ScanType int scanType,
@Nullable Set<Integer> freqs, @Nullable List<byte[]> hiddenNetworkSSIDs) {
@Nullable Set<Integer> freqs, @Nullable List<byte[]> hiddenNetworkSSIDs,
@Nullable Bundle extraScanningParams) {
IWifiScannerImpl scannerImpl = getScannerImpl(ifaceName);
if (scannerImpl == null) {
Log.e(TAG, "No valid wificond scanner interface handler for iface=" + ifaceName);
Expand All @@ -948,6 +964,9 @@ public boolean startScan(@NonNull String ifaceName, @WifiAnnotations.ScanType in
}
settings.channelSettings = new ArrayList<>();
settings.hiddenNetworks = new ArrayList<>();
if (extraScanningParams != null) {
settings.enable6GhzRnr = extraScanningParams.getBoolean(SCANNING_PARAM_ENABLE_6GHZ_RNR);
}

if (freqs != null) {
for (Integer freq : freqs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void canSerializeAndDeserialize() {
new ArrayList<>(Arrays.asList(mChannelSettings1, mChannelSettings2));
scanSettings.hiddenNetworks =
new ArrayList<>(Arrays.asList(mHiddenNetwork1, mHiddenNetwork2));
scanSettings.enable6GhzRnr = true;

Parcel parcel = Parcel.obtain();
scanSettings.writeToParcel(parcel, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiScanner;
import android.net.wifi.util.HexEncoding;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
Expand Down Expand Up @@ -506,7 +507,51 @@ public void testScan() throws Exception {
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST));
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST)));
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, false)));
}

/**
* Verify the new startScan() API can convert input parameters to SingleScanSettings correctly.
*/
@Test
public void testScanWithBundle() throws Exception {
when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true);
Bundle bundle = new Bundle();
bundle.putBoolean(WifiNl80211Manager.SCANNING_PARAM_ENABLE_6GHZ_RNR, true);
assertTrue(mWificondControl.startScan(
TEST_INTERFACE_NAME, WifiScanner.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, bundle));
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, true)));
}

/**
* Verify default values in SingleScanSettings when the input Bundle to startScan is null.
*/
@Test
public void testScanWithNullBundle() throws Exception {
when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true);
assertTrue(mWificondControl.startScan(
TEST_INTERFACE_NAME, WifiScanner.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, null));
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, false)));
}

/**
* Verify default values in SingleScanSettings when the input Bundle to startScan is empty.
*/
@Test
public void testScanWithEmptyBundle() throws Exception {
when(mWifiScannerImpl.scan(any(SingleScanSettings.class))).thenReturn(true);
assertTrue(mWificondControl.startScan(
TEST_INTERFACE_NAME, WifiScanner.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, new Bundle()));
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, false)));
}

/**
Expand All @@ -527,7 +572,7 @@ public void testScanWithDuplicateHiddenSsids() throws Exception {
// But the argument passed down should have the duplicate removed.
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_LOW_POWER,
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST)));
SCAN_FREQ_SET, SCAN_HIDDEN_NETWORK_SSID_LIST, false)));
}

/**
Expand All @@ -539,7 +584,7 @@ public void testScanNullParameters() throws Exception {
assertTrue(mWificondControl.startScan(
TEST_INTERFACE_NAME, WifiScanner.SCAN_TYPE_HIGH_ACCURACY, null, null));
verify(mWifiScannerImpl).scan(argThat(new ScanMatcher(
IWifiScannerImpl.SCAN_TYPE_HIGH_ACCURACY, null, null)));
IWifiScannerImpl.SCAN_TYPE_HIGH_ACCURACY, null, null, false)));
}

/**
Expand Down Expand Up @@ -1068,18 +1113,24 @@ private class ScanMatcher implements ArgumentMatcher<SingleScanSettings> {
int mExpectedScanType;
private final Set<Integer> mExpectedFreqs;
private final List<byte[]> mExpectedSsids;
private final boolean mExpectedEnable6GhzRnr;

ScanMatcher(int expectedScanType, Set<Integer> expectedFreqs, List<byte[]> expectedSsids) {
ScanMatcher(int expectedScanType, Set<Integer> expectedFreqs, List<byte[]> expectedSsids,
boolean expectedEnable6GhzRnr) {
this.mExpectedScanType = expectedScanType;
this.mExpectedFreqs = expectedFreqs;
this.mExpectedSsids = expectedSsids;
this.mExpectedEnable6GhzRnr = expectedEnable6GhzRnr;
}

@Override
public boolean matches(SingleScanSettings settings) {
if (settings.scanType != mExpectedScanType) {
return false;
}
if (settings.enable6GhzRnr != mExpectedEnable6GhzRnr) {
return false;
}
ArrayList<ChannelSettings> channelSettings = settings.channelSettings;
ArrayList<HiddenNetwork> hiddenNetworks = settings.hiddenNetworks;
if (mExpectedFreqs != null) {
Expand Down

0 comments on commit 1bccf82

Please sign in to comment.