summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roy Want <roywant@google.com> 2020-12-14 05:13:40 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-12-14 05:13:40 +0000
commit2aab670722abbbbea84f209e3abcb8eeb648ecf8 (patch)
tree90487d2c07b6a37f3701a9ace3350fa4614456ae
parented4536c5acc18a60b87551503d8d7042c88c30b1 (diff)
parent0f5884ba690003f0e6098d2feaf9a3e8e4158de5 (diff)
Merge "Adding setter and getters for setRttBurstSize() in RangingRequest (client)"
-rw-r--r--wifi/api/current.txt5
-rw-r--r--wifi/api/system-current.txt4
-rw-r--r--wifi/java/android/net/wifi/rtt/RangingRequest.java123
-rw-r--r--wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java71
4 files changed, 196 insertions, 7 deletions
diff --git a/wifi/api/current.txt b/wifi/api/current.txt
index d1b96885482e..4b0d38df0260 100644
--- a/wifi/api/current.txt
+++ b/wifi/api/current.txt
@@ -1157,7 +1157,11 @@ package android.net.wifi.rtt {
public final class RangingRequest implements android.os.Parcelable {
method public int describeContents();
+ method public static int getDefaultRttBurstSize();
method public static int getMaxPeers();
+ method public static int getMaxRttBurstSize();
+ method public static int getMinRttBurstSize();
+ method public int getRttBurstSize();
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.rtt.RangingRequest> CREATOR;
}
@@ -1169,6 +1173,7 @@ package android.net.wifi.rtt {
method public android.net.wifi.rtt.RangingRequest.Builder addWifiAwarePeer(@NonNull android.net.MacAddress);
method public android.net.wifi.rtt.RangingRequest.Builder addWifiAwarePeer(@NonNull android.net.wifi.aware.PeerHandle);
method public android.net.wifi.rtt.RangingRequest build();
+ method @NonNull public android.net.wifi.rtt.RangingRequest.Builder setRttBurstSize(int);
}
public final class RangingResult implements android.os.Parcelable {
diff --git a/wifi/api/system-current.txt b/wifi/api/system-current.txt
index 74a9a64718f5..e15d0f132b87 100644
--- a/wifi/api/system-current.txt
+++ b/wifi/api/system-current.txt
@@ -964,6 +964,10 @@ package android.net.wifi.p2p {
package android.net.wifi.rtt {
+ public final class RangingRequest implements android.os.Parcelable {
+ method @NonNull public java.util.List<android.net.wifi.rtt.ResponderConfig> getRttPeers();
+ }
+
public static final class RangingRequest.Builder {
method public android.net.wifi.rtt.RangingRequest.Builder addResponder(@NonNull android.net.wifi.rtt.ResponderConfig);
}
diff --git a/wifi/java/android/net/wifi/rtt/RangingRequest.java b/wifi/java/android/net/wifi/rtt/RangingRequest.java
index 318efa61a110..04dfcf2f9cad 100644
--- a/wifi/java/android/net/wifi/rtt/RangingRequest.java
+++ b/wifi/java/android/net/wifi/rtt/RangingRequest.java
@@ -30,8 +30,11 @@ import android.os.Handler;
import android.os.Parcel;
import android.os.Parcelable;
+import com.android.modules.utils.build.SdkLevel;
+
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.StringJoiner;
/**
@@ -46,6 +49,9 @@ import java.util.StringJoiner;
*/
public final class RangingRequest implements Parcelable {
private static final int MAX_PEERS = 10;
+ private static final int DEFAULT_RTT_BURST_SIZE = 8;
+ private static final int MIN_RTT_BURST_SIZE = 2;
+ private static final int MAX_RTT_BURST_SIZE = 17;
/**
* Returns the maximum number of peers to range which can be specified in a single {@code
@@ -59,12 +65,80 @@ public final class RangingRequest implements Parcelable {
return MAX_PEERS;
}
+ /**
+ * Returns the default RTT burst size used to determine the average range.
+ *
+ * @return the RTT burst size used by default
+ */
+ public static int getDefaultRttBurstSize() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return DEFAULT_RTT_BURST_SIZE;
+ }
+
+ /**
+ * Returns the minimum RTT burst size that can be used to determine a average range.
+ *
+ * @return the minimum RTT burst size that can be used
+ */
+ public static int getMinRttBurstSize() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return MIN_RTT_BURST_SIZE;
+ }
+
+ /**
+ * Returns the minimum RTT burst size that can be used to determine a average range.
+ *
+ * @return the maximum RTT burst size that can be used
+ */
+ public static int getMaxRttBurstSize() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return MAX_RTT_BURST_SIZE;
+ }
+
/** @hide */
public final List<ResponderConfig> mRttPeers;
/** @hide */
- private RangingRequest(List<ResponderConfig> rttPeers) {
+ public final int mRttBurstSize;
+
+ /** @hide */
+ private RangingRequest(List<ResponderConfig> rttPeers, int rttBurstSize) {
mRttPeers = rttPeers;
+ mRttBurstSize = rttBurstSize;
+ }
+
+ /**
+ * Returns the list of RTT capable peers.
+ *
+ * @return the list of RTT capable peers in a common system representation
+ *
+ * @hide
+ */
+ @SystemApi
+ @NonNull
+ public List<ResponderConfig> getRttPeers() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return mRttPeers;
+ }
+
+ /**
+ * Returns the RTT burst size used to determine the average range.
+ *
+ * @return the RTT burst size used
+ */
+ public int getRttBurstSize() {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ return mRttBurstSize;
}
@Override
@@ -75,6 +149,7 @@ public final class RangingRequest implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(mRttPeers);
+ dest.writeInt(mRttBurstSize);
}
public static final @android.annotation.NonNull Creator<RangingRequest> CREATOR = new Creator<RangingRequest>() {
@@ -85,7 +160,7 @@ public final class RangingRequest implements Parcelable {
@Override
public RangingRequest createFromParcel(Parcel in) {
- return new RangingRequest(in.readArrayList(null));
+ return new RangingRequest(in.readArrayList(null), in.readInt());
}
};
@@ -105,12 +180,20 @@ public final class RangingRequest implements Parcelable {
throw new IllegalArgumentException(
"Ranging to too many peers requested. Use getMaxPeers() API to get limit.");
}
-
for (ResponderConfig peer: mRttPeers) {
if (!peer.isValid(awareSupported)) {
throw new IllegalArgumentException("Invalid Responder specification");
}
}
+ if (SdkLevel.isAtLeastS()) {
+ if (mRttBurstSize < getMinRttBurstSize() || mRttBurstSize > getMaxRttBurstSize()) {
+ throw new IllegalArgumentException("RTT burst size is out of range");
+ }
+ } else {
+ if (mRttBurstSize != DEFAULT_RTT_BURST_SIZE) {
+ throw new IllegalArgumentException("RTT burst size is not the default value");
+ }
+ }
}
/**
@@ -118,6 +201,32 @@ public final class RangingRequest implements Parcelable {
*/
public static final class Builder {
private List<ResponderConfig> mRttPeers = new ArrayList<>();
+ private int mRttBurstSize = DEFAULT_RTT_BURST_SIZE;
+
+ /**
+ * Set the RTT Burst size for the ranging request.
+ * <p>
+ * If not set, the default RTT burst size given by
+ * {@link #getDefaultRttBurstSize()} is used to determine the default value.
+ * If set, the value must be in the range {@link #getMinRttBurstSize()} and
+ * {@link #getMaxRttBurstSize()} inclusively, or a
+ * {@link java.lang.IllegalArgumentException} will be thrown.
+ *
+ * @param rttBurstSize The number of FTM packets used to estimate a range.
+ * @return The builder to facilitate chaining
+ * {@code builder.setXXX(..).setXXX(..)}.
+ */
+ @NonNull
+ public Builder setRttBurstSize(int rttBurstSize) {
+ if (!SdkLevel.isAtLeastS()) {
+ throw new UnsupportedOperationException();
+ }
+ if (rttBurstSize < MIN_RTT_BURST_SIZE || rttBurstSize > MAX_RTT_BURST_SIZE) {
+ throw new IllegalArgumentException("RTT burst size out of range.");
+ }
+ mRttBurstSize = rttBurstSize;
+ return this;
+ }
/**
* Add the device specified by the {@link ScanResult} to the list of devices with
@@ -241,7 +350,7 @@ public final class RangingRequest implements Parcelable {
* builder.
*/
public RangingRequest build() {
- return new RangingRequest(mRttPeers);
+ return new RangingRequest(mRttPeers, mRttBurstSize);
}
}
@@ -257,11 +366,13 @@ public final class RangingRequest implements Parcelable {
RangingRequest lhs = (RangingRequest) o;
- return mRttPeers.size() == lhs.mRttPeers.size() && mRttPeers.containsAll(lhs.mRttPeers);
+ return mRttPeers.size() == lhs.mRttPeers.size()
+ && mRttPeers.containsAll(lhs.mRttPeers)
+ && mRttBurstSize == lhs.mRttBurstSize;
}
@Override
public int hashCode() {
- return mRttPeers.hashCode();
+ return Objects.hash(mRttPeers, mRttBurstSize);
}
}
diff --git a/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java b/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
index e6eae416ba78..c8006fead55b 100644
--- a/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
@@ -16,6 +16,8 @@
package android.net.wifi.rtt;
+import static junit.framework.Assert.fail;
+
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -143,6 +145,7 @@ public class WifiRttManagerTest {
PeerHandle peerHandle1 = new PeerHandle(12);
RangingRequest.Builder builder = new RangingRequest.Builder();
+ builder.setRttBurstSize(4);
builder.addAccessPoint(scanResult1);
builder.addAccessPoints(scanResults2and3);
builder.addWifiAwarePeer(mac1);
@@ -163,6 +166,60 @@ public class WifiRttManagerTest {
}
/**
+ * Validate the rtt burst size is set correctly when in range.
+ */
+ @Test
+ public void testRangingRequestSetBurstSize() {
+ ScanResult scanResult = new ScanResult();
+ scanResult.BSSID = "AA:BB:CC:DD:EE:FF";
+
+ // create request
+ RangingRequest.Builder builder = new RangingRequest.Builder();
+ builder.setRttBurstSize(4);
+ builder.addAccessPoint(scanResult);
+ RangingRequest request = builder.build();
+
+ // confirm rtt burst size is set correctly to default value
+ assertEquals(request.getRttBurstSize(), 4);
+ }
+
+ /**
+ * Validate the rtt burst size cannot be smaller than the minimum.
+ */
+ @Test
+ public void testRangingRequestMinBurstSizeIsEnforced() {
+ ScanResult scanResult = new ScanResult();
+ scanResult.BSSID = "AA:BB:CC:DD:EE:FF";
+
+ // create request
+ try {
+ RangingRequest.Builder builder = new RangingRequest.Builder();
+ builder.setRttBurstSize(RangingRequest.getMinRttBurstSize() - 1);
+ fail("RTT burst size was smaller than min value.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Validate the rtt burst size cannot exceed the maximum.
+ */
+ @Test
+ public void testRangingRequestMaxBurstSizeIsEnforced() {
+ ScanResult scanResult = new ScanResult();
+ scanResult.BSSID = "AA:BB:CC:DD:EE:FF";
+
+ // create request
+ try {
+ RangingRequest.Builder builder = new RangingRequest.Builder();
+ builder.setRttBurstSize(RangingRequest.getMaxRttBurstSize() + 1);
+ fail("RTT Burst size exceeded max value.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
* Validate that can request as many range operation as the upper limit on number of requests.
*/
@Test
@@ -175,7 +232,7 @@ public class WifiRttManagerTest {
}
MacAddress mac1 = MacAddress.fromString("00:01:02:03:04:05");
- // create request
+ // create request using max RTT Peers
RangingRequest.Builder builder = new RangingRequest.Builder();
builder.addAccessPoint(scanResult);
builder.addAccessPoints(scanResultList);
@@ -185,6 +242,18 @@ public class WifiRttManagerTest {
// verify request
request.enforceValidity(true);
+ // confirm rtt burst size is set correctly to default value
+ assertEquals(request.getRttBurstSize(), RangingRequest.getDefaultRttBurstSize());
+ // confirm the number of peers in the request is the max number of peers
+ List<ResponderConfig> rttPeers = request.getRttPeers();
+ int numRttPeers = rttPeers.size();
+ assertEquals(RangingRequest.getMaxPeers(), numRttPeers);
+ // confirm each peer has the correct mac address
+ for (int i = 0; i < numRttPeers - 1; ++i) {
+ assertEquals("AA:BB:CC:DD:EE:FF", rttPeers.get(i).macAddress.toString().toUpperCase());
+ }
+ assertEquals("00:01:02:03:04:05",
+ rttPeers.get(numRttPeers - 1).macAddress.toString().toUpperCase());
}
/**