Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 057718d6 authored by Etan Cohen's avatar Etan Cohen Committed by android-build-merger
Browse files

Merge "[RTT] Update RTT preamble selection algorithm" into pi-dev

am: 51f3c448

Change-Id: I7922b6d07c6327a597f76f1002b3c7652af7d165
parents 61497399 51f3c448
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -402,12 +402,14 @@ public class ScanResult implements Parcelable {
        public static final int EID_TIM = 5;
        public static final int EID_BSS_LOAD = 11;
        public static final int EID_ERP = 42;
        public static final int EID_HT_CAPABILITIES = 45;
        public static final int EID_RSN = 48;
        public static final int EID_EXTENDED_SUPPORTED_RATES = 50;
        public static final int EID_HT_OPERATION = 61;
        public static final int EID_INTERWORKING = 107;
        public static final int EID_ROAMING_CONSORTIUM = 111;
        public static final int EID_EXTENDED_CAPS = 127;
        public static final int EID_VHT_CAPABILITIES = 191;
        public static final int EID_VHT_OPERATION = 192;
        public static final int EID_VSA = 221;

+28 −4
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package android.net.wifi.rtt;

import static android.net.wifi.ScanResult.InformationElement.EID_HT_CAPABILITIES;
import static android.net.wifi.ScanResult.InformationElement.EID_VHT_CAPABILITIES;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
@@ -24,6 +27,7 @@ import android.net.wifi.ScanResult;
import android.net.wifi.aware.PeerHandle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -40,6 +44,7 @@ import java.util.Objects;
 */
@SystemApi
public final class ResponderConfig implements Parcelable {
    private static final String TAG = "ResponderConfig";
    private static final int AWARE_BAND_2_DISCOVERY_CHANNEL = 2437;

    /** @hide */
@@ -297,13 +302,32 @@ public final class ResponderConfig implements Parcelable {
        int centerFreq0 = scanResult.centerFreq0;
        int centerFreq1 = scanResult.centerFreq1;

        // TODO: b/68936111 - extract preamble info from IE
        int preamble;
        if (scanResult.informationElements != null && scanResult.informationElements.length != 0) {
            boolean htCapabilitiesPresent = false;
            boolean vhtCapabilitiesPresent = false;
            for (ScanResult.InformationElement ie : scanResult.informationElements) {
                if (ie.id == EID_HT_CAPABILITIES) {
                    htCapabilitiesPresent = true;
                } else if (ie.id == EID_VHT_CAPABILITIES) {
                    vhtCapabilitiesPresent = true;
                }
            }
            if (vhtCapabilitiesPresent) {
                preamble = PREAMBLE_VHT;
            } else if (htCapabilitiesPresent) {
                preamble = PREAMBLE_HT;
            } else {
                preamble = PREAMBLE_LEGACY;
            }
        } else {
            Log.e(TAG, "Scan Results do not contain IEs - using backup method to select preamble");
            if (channelWidth == CHANNEL_WIDTH_80MHZ || channelWidth == CHANNEL_WIDTH_160MHZ) {
                preamble = PREAMBLE_VHT;
            } else {
                preamble = PREAMBLE_HT;
            }
        }

        return new ResponderConfig(macAddress, responderType, supports80211mc, channelWidth,
                frequency, centerFreq0, centerFreq1, preamble);
+92 −0
Original line number Diff line number Diff line
@@ -295,4 +295,96 @@ public class WifiRttManagerTest {

        assertEquals(rr1, rr2);
    }

    /**
     * Validate that ResponderConfig parcel works (produces same object on write/read).
     */
    @Test
    public void testResponderConfigParcel() {
        // ResponderConfig constructed with a MAC address
        ResponderConfig config = new ResponderConfig(MacAddress.fromString("00:01:02:03:04:05"),
                ResponderConfig.RESPONDER_AP, true, ResponderConfig.CHANNEL_WIDTH_80MHZ, 2134, 2345,
                2555, ResponderConfig.PREAMBLE_LEGACY);

        Parcel parcelW = Parcel.obtain();
        config.writeToParcel(parcelW, 0);
        byte[] bytes = parcelW.marshall();
        parcelW.recycle();

        Parcel parcelR = Parcel.obtain();
        parcelR.unmarshall(bytes, 0, bytes.length);
        parcelR.setDataPosition(0);
        ResponderConfig rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR);

        assertEquals(config, rereadConfig);

        // ResponderConfig constructed with a PeerHandle
        config = new ResponderConfig(new PeerHandle(10), ResponderConfig.RESPONDER_AWARE, false,
                ResponderConfig.CHANNEL_WIDTH_80MHZ_PLUS_MHZ, 5555, 6666, 7777,
                ResponderConfig.PREAMBLE_VHT);

        parcelW = Parcel.obtain();
        config.writeToParcel(parcelW, 0);
        bytes = parcelW.marshall();
        parcelW.recycle();

        parcelR = Parcel.obtain();
        parcelR.unmarshall(bytes, 0, bytes.length);
        parcelR.setDataPosition(0);
        rereadConfig = ResponderConfig.CREATOR.createFromParcel(parcelR);

        assertEquals(config, rereadConfig);
    }

    /**
     * Validate preamble selection from ScanResults.
     */
    @Test
    public void testResponderPreambleSelection() {
        ScanResult.InformationElement htCap = new ScanResult.InformationElement();
        htCap.id = ScanResult.InformationElement.EID_HT_CAPABILITIES;

        ScanResult.InformationElement vhtCap = new ScanResult.InformationElement();
        vhtCap.id = ScanResult.InformationElement.EID_VHT_CAPABILITIES;

        ScanResult.InformationElement vsa = new ScanResult.InformationElement();
        vsa.id = ScanResult.InformationElement.EID_VSA;

        // no IE
        ScanResult scan = new ScanResult();
        scan.BSSID = "00:01:02:03:04:05";
        scan.informationElements = null;
        scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_80MHZ;

        ResponderConfig config = ResponderConfig.fromScanResult(scan);

        assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble);

        // IE with HT & VHT
        scan.channelWidth = ResponderConfig.CHANNEL_WIDTH_40MHZ;

        scan.informationElements = new ScanResult.InformationElement[2];
        scan.informationElements[0] = htCap;
        scan.informationElements[1] = vhtCap;

        config = ResponderConfig.fromScanResult(scan);

        assertEquals(ResponderConfig.PREAMBLE_VHT, config.preamble);

        // IE with some entries but no HT or VHT
        scan.informationElements[0] = vsa;
        scan.informationElements[1] = vsa;

        config = ResponderConfig.fromScanResult(scan);

        assertEquals(ResponderConfig.PREAMBLE_LEGACY, config.preamble);

        // IE with HT
        scan.informationElements[0] = vsa;
        scan.informationElements[1] = htCap;

        config = ResponderConfig.fromScanResult(scan);

        assertEquals(ResponderConfig.PREAMBLE_HT, config.preamble);
    }
}