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

Commit 6721901c authored by Etan Cohen's avatar Etan Cohen Committed by android-build-merger
Browse files

Merge "[AWARE] Add discovery window period configuration" am: 17532ec0 am: f8637d5c

am: 2fd54ee2

Change-Id: Iba971429f57c90e0397e06f4d679ef2e3e660f41
parents 12054fdc 2fd54ee2
Loading
Loading
Loading
Loading
+78 −15
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.net.wifi.aware;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Arrays;

/**
 * Defines a request object to configure a Wi-Fi Aware network. Built using
 * {@link ConfigRequest.Builder}. Configuration is requested using
@@ -40,6 +42,18 @@ public final class ConfigRequest implements Parcelable {
     */
    public static final int CLUSTER_ID_MAX = 0xFFFF;

    /**
     * Indices for configuration variables which are specified per band.
     */
    public static final int NAN_BAND_24GHZ = 0;
    public static final int NAN_BAND_5GHZ = 1;

    /**
     * Magic values for Discovery Window (DW) interval configuration
     */
    public static final int DW_INTERVAL_NOT_INIT = -1;
    public static final int DW_DISABLE = 0; // only valid for 5GHz

    /**
     * Indicates whether 5G band support is requested.
     */
@@ -62,19 +76,26 @@ public final class ConfigRequest implements Parcelable {
     */
    public final int mClusterHigh;

    /**
     * Specifies the discovery window interval for the device on NAN_BAND_*.
     */
    public final int mDiscoveryWindowInterval[];

    private ConfigRequest(boolean support5gBand, int masterPreference, int clusterLow,
            int clusterHigh) {
            int clusterHigh, int discoveryWindowInterval[]) {
        mSupport5gBand = support5gBand;
        mMasterPreference = masterPreference;
        mClusterLow = clusterLow;
        mClusterHigh = clusterHigh;
        mDiscoveryWindowInterval = discoveryWindowInterval;
    }

    @Override
    public String toString() {
        return "ConfigRequest [mSupport5gBand=" + mSupport5gBand + ", mMasterPreference="
                + mMasterPreference + ", mClusterLow=" + mClusterLow + ", mClusterHigh="
                + mClusterHigh + "]";
                + mClusterHigh + ", mDiscoveryWindowInterval="
                + Arrays.toString(mDiscoveryWindowInterval) + "]";
    }

    @Override
@@ -88,6 +109,7 @@ public final class ConfigRequest implements Parcelable {
        dest.writeInt(mMasterPreference);
        dest.writeInt(mClusterLow);
        dest.writeInt(mClusterHigh);
        dest.writeIntArray(mDiscoveryWindowInterval);
    }

    public static final Creator<ConfigRequest> CREATOR = new Creator<ConfigRequest>() {
@@ -102,7 +124,10 @@ public final class ConfigRequest implements Parcelable {
            int masterPreference = in.readInt();
            int clusterLow = in.readInt();
            int clusterHigh = in.readInt();
            return new ConfigRequest(support5gBand, masterPreference, clusterLow, clusterHigh);
            int discoveryWindowInterval[] = in.createIntArray();

            return new ConfigRequest(support5gBand, masterPreference, clusterLow, clusterHigh,
                    discoveryWindowInterval);
        }
    };

@@ -119,17 +144,8 @@ public final class ConfigRequest implements Parcelable {
        ConfigRequest lhs = (ConfigRequest) o;

        return mSupport5gBand == lhs.mSupport5gBand && mMasterPreference == lhs.mMasterPreference
                && mClusterLow == lhs.mClusterLow && mClusterHigh == lhs.mClusterHigh;
    }

    /**
     * Checks whether the configuration's settings are non-default.
     *
     * @return true if any of the settings are non-default.
     */
    public boolean isNonDefault() {
        return mSupport5gBand || mMasterPreference != 0 || mClusterLow != CLUSTER_ID_MIN
                || mClusterHigh != CLUSTER_ID_MAX;
                && mClusterLow == lhs.mClusterLow && mClusterHigh == lhs.mClusterHigh
                && Arrays.equals(mDiscoveryWindowInterval, lhs.mDiscoveryWindowInterval);
    }

    @Override
@@ -140,6 +156,7 @@ public final class ConfigRequest implements Parcelable {
        result = 31 * result + mMasterPreference;
        result = 31 * result + mClusterLow;
        result = 31 * result + mClusterHigh;
        result = 31 * result + Arrays.hashCode(mDiscoveryWindowInterval);

        return result;
    }
@@ -173,6 +190,23 @@ public final class ConfigRequest implements Parcelable {
            throw new IllegalArgumentException(
                    "Invalid argument combination - must have Cluster Low <= Cluster High");
        }
        if (mDiscoveryWindowInterval.length != 2) {
            throw new IllegalArgumentException(
                    "Invalid discovery window interval: must have 2 elements (2.4 & 5");
        }
        if (mDiscoveryWindowInterval[NAN_BAND_24GHZ] != DW_INTERVAL_NOT_INIT &&
                (mDiscoveryWindowInterval[NAN_BAND_24GHZ] < 1 // valid for 2.4GHz: [1-5]
                || mDiscoveryWindowInterval[NAN_BAND_24GHZ] > 5)) {
            throw new IllegalArgumentException(
                    "Invalid discovery window interval for 2.4GHz: valid is UNSET or [1,5]");
        }
        if (mDiscoveryWindowInterval[NAN_BAND_5GHZ] != DW_INTERVAL_NOT_INIT &&
                (mDiscoveryWindowInterval[NAN_BAND_5GHZ] < 0 // valid for 5GHz: [0-5]
                || mDiscoveryWindowInterval[NAN_BAND_5GHZ] > 5)) {
            throw new IllegalArgumentException(
                "Invalid discovery window interval for 5GHz: valid is UNSET or [0,5]");
        }

    }

    /**
@@ -183,6 +217,7 @@ public final class ConfigRequest implements Parcelable {
        private int mMasterPreference = 0;
        private int mClusterLow = CLUSTER_ID_MIN;
        private int mClusterHigh = CLUSTER_ID_MAX;
        private int mDiscoveryWindowInterval[] = {DW_INTERVAL_NOT_INIT, DW_INTERVAL_NOT_INIT};

        /**
         * Specify whether 5G band support is required in this request. Disabled by default.
@@ -270,6 +305,33 @@ public final class ConfigRequest implements Parcelable {
            return this;
        }

        /**
         * The discovery window interval specifies the discovery windows in which the device will be
         * awake. The configuration enables trading off latency vs. power (higher interval means
         * higher discovery latency but lower power).
         *
         * @param band Either {@link #NAN_BAND_24GHZ} or {@link #NAN_BAND_5GHZ}.
         * @param interval A value of 1, 2, 3, 4, or 5 indicating an interval of 2^(interval-1). For
         *                 the 5GHz band a value of 0 indicates that the device will not be awake
         *                 for any discovery windows.
         *
         * @return The builder itself to facilitate chaining operations
         *         {@code builder.setDiscoveryWindowInterval(...).setMasterPreference(...)}.
         */
        public Builder setDiscoveryWindowInterval(int band, int interval) {
            if (band != NAN_BAND_24GHZ && band != NAN_BAND_5GHZ) {
                throw new IllegalArgumentException("Invalid band value");
            }
            if ((band == NAN_BAND_24GHZ && (interval < 1 || interval > 5))
                    || (band == NAN_BAND_5GHZ && (interval < 0 || interval > 5))) {
                throw new IllegalArgumentException(
                        "Invalid interval value: 2.4 GHz [1,5] or 5GHz [0,5]");
            }

            mDiscoveryWindowInterval[band] = interval;
            return this;
        }

        /**
         * Build {@link ConfigRequest} given the current requests made on the
         * builder.
@@ -280,7 +342,8 @@ public final class ConfigRequest implements Parcelable {
                        "Invalid argument combination - must have Cluster Low <= Cluster High");
            }

            return new ConfigRequest(mSupport5gBand, mMasterPreference, mClusterLow, mClusterHigh);
            return new ConfigRequest(mSupport5gBand, mMasterPreference, mClusterLow, mClusterHigh,
                    mDiscoveryWindowInterval);
        }
    }
}
+42 −0
Original line number Diff line number Diff line
@@ -566,6 +566,12 @@ public class WifiAwareManagerTest {
        collector.checkThat("mMasterPreference", 0,
                equalTo(configRequest.mMasterPreference));
        collector.checkThat("mSupport5gBand", false, equalTo(configRequest.mSupport5gBand));
        collector.checkThat("mDiscoveryWindowInterval.length", 2,
                equalTo(configRequest.mDiscoveryWindowInterval.length));
        collector.checkThat("mDiscoveryWindowInterval[2.4GHz]", ConfigRequest.DW_INTERVAL_NOT_INIT,
                equalTo(configRequest.mDiscoveryWindowInterval[ConfigRequest.NAN_BAND_24GHZ]));
        collector.checkThat("mDiscoveryWindowInterval[5Hz]", ConfigRequest.DW_INTERVAL_NOT_INIT,
                equalTo(configRequest.mDiscoveryWindowInterval[ConfigRequest.NAN_BAND_5GHZ]));
    }

    @Test
@@ -574,10 +580,12 @@ public class WifiAwareManagerTest {
        final int clusterLow = 5;
        final int masterPreference = 55;
        final boolean supportBand5g = true;
        final int dwWindow5GHz = 3;

        ConfigRequest configRequest = new ConfigRequest.Builder().setClusterHigh(clusterHigh)
                .setClusterLow(clusterLow).setMasterPreference(masterPreference)
                .setSupport5gBand(supportBand5g)
                .setDiscoveryWindowInterval(ConfigRequest.NAN_BAND_5GHZ, dwWindow5GHz)
                .build();

        collector.checkThat("mClusterHigh", clusterHigh, equalTo(configRequest.mClusterHigh));
@@ -585,6 +593,12 @@ public class WifiAwareManagerTest {
        collector.checkThat("mMasterPreference", masterPreference,
                equalTo(configRequest.mMasterPreference));
        collector.checkThat("mSupport5gBand", supportBand5g, equalTo(configRequest.mSupport5gBand));
        collector.checkThat("mDiscoveryWindowInterval.length", 2,
                equalTo(configRequest.mDiscoveryWindowInterval.length));
        collector.checkThat("mDiscoveryWindowInterval[2.4GHz]", ConfigRequest.DW_INTERVAL_NOT_INIT,
                equalTo(configRequest.mDiscoveryWindowInterval[ConfigRequest.NAN_BAND_24GHZ]));
        collector.checkThat("mDiscoveryWindowInterval[5GHz]", dwWindow5GHz,
                equalTo(configRequest.mDiscoveryWindowInterval[ConfigRequest.NAN_BAND_5GHZ]));
    }

    @Test(expected = IllegalArgumentException.class)
@@ -633,16 +647,44 @@ public class WifiAwareManagerTest {
        new ConfigRequest.Builder().setClusterLow(100).setClusterHigh(5).build();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConfigRequestBuilderDwIntervalInvalidBand() {
        new ConfigRequest.Builder().setDiscoveryWindowInterval(5, 1).build();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConfigRequestBuilderDwIntervalInvalidValueZero() {
        new ConfigRequest.Builder().setDiscoveryWindowInterval(ConfigRequest.NAN_BAND_24GHZ,
                0).build();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConfigRequestBuilderDwIntervalInvalidValueLarge() {
        new ConfigRequest.Builder().setDiscoveryWindowInterval(ConfigRequest.NAN_BAND_5GHZ,
                6).build();
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConfigRequestBuilderDwIntervalInvalidValueLargeValidate() {
        ConfigRequest cr = new ConfigRequest.Builder().build();
        cr.mDiscoveryWindowInterval[ConfigRequest.NAN_BAND_5GHZ] = 6;
        cr.validate();
    }

    @Test
    public void testConfigRequestParcel() {
        final int clusterHigh = 189;
        final int clusterLow = 25;
        final int masterPreference = 177;
        final boolean supportBand5g = true;
        final int dwWindow24GHz = 1;
        final int dwWindow5GHz = 5;

        ConfigRequest configRequest = new ConfigRequest.Builder().setClusterHigh(clusterHigh)
                .setClusterLow(clusterLow).setMasterPreference(masterPreference)
                .setSupport5gBand(supportBand5g)
                .setDiscoveryWindowInterval(ConfigRequest.NAN_BAND_24GHZ, dwWindow24GHz)
                .setDiscoveryWindowInterval(ConfigRequest.NAN_BAND_5GHZ, dwWindow5GHz)
                .build();

        Parcel parcelW = Parcel.obtain();