[AWARE] Check for RTT feature presence for Aware discovery with ranging
When configuring Aware discovery with ranging validate that the RTT
feature is present on the device.
Bug: 63906015
Test: unit tests, integration tests
Change-Id: I74680c4dc83ae8ed16a3c457ec13cc2c40710166
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java
index 421d9ac..738b0c5 100644
--- a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java
+++ b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java
@@ -242,7 +242,8 @@
if (publishConfig == null) {
throw new IllegalArgumentException("PublishConfig must not be null");
}
- publishConfig.assertValid(mStateManager.getCharacteristics());
+ publishConfig.assertValid(mStateManager.getCharacteristics(),
+ mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT));
int uid = getMockableCallingUid();
enforceClientValidity(uid, clientId);
@@ -262,7 +263,8 @@
if (publishConfig == null) {
throw new IllegalArgumentException("PublishConfig must not be null");
}
- publishConfig.assertValid(mStateManager.getCharacteristics());
+ publishConfig.assertValid(mStateManager.getCharacteristics(),
+ mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT));
int uid = getMockableCallingUid();
enforceClientValidity(uid, clientId);
@@ -287,7 +289,8 @@
if (subscribeConfig == null) {
throw new IllegalArgumentException("SubscribeConfig must not be null");
}
- subscribeConfig.assertValid(mStateManager.getCharacteristics());
+ subscribeConfig.assertValid(mStateManager.getCharacteristics(),
+ mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT));
int uid = getMockableCallingUid();
enforceClientValidity(uid, clientId);
@@ -307,7 +310,8 @@
if (subscribeConfig == null) {
throw new IllegalArgumentException("SubscribeConfig must not be null");
}
- subscribeConfig.assertValid(mStateManager.getCharacteristics());
+ subscribeConfig.assertValid(mStateManager.getCharacteristics(),
+ mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI_RTT));
int uid = getMockableCallingUid();
enforceClientValidity(uid, clientId);
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
index f323110..a0abf16 100644
--- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java
@@ -120,6 +120,8 @@
when(mContextMock.getPackageManager()).thenReturn(mPackageManagerMock);
when(mPackageManagerMock.hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE))
.thenReturn(true);
+ when(mPackageManagerMock.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT))
+ .thenReturn(true);
when(mAwareStateManagerMock.getCharacteristics()).thenReturn(getCharacteristics());
mDut = new WifiAwareServiceImplSpy(mContextMock);
@@ -238,6 +240,41 @@
}
/**
+ * Validate that the RTT feature support is checked when attempting a Publish with ranging.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testFailOnPublishRangingWithoutRttFeature() throws Exception {
+ when(mPackageManagerMock.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)).thenReturn(
+ false);
+
+ PublishConfig publishConfig = new PublishConfig.Builder().setServiceName("something.valid")
+ .setRangingEnabled(true).build();
+ int clientId = doConnect();
+ IWifiAwareDiscoverySessionCallback mockCallback = mock(
+ IWifiAwareDiscoverySessionCallback.class);
+
+ mDut.publish(clientId, publishConfig, mockCallback);
+ }
+
+ /**
+ * Validate that the RTT feature support is checked when attempting a Subscribe with ranging.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testFailOnSubscribeRangingWithoutRttFeature() throws Exception {
+ when(mPackageManagerMock.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)).thenReturn(
+ false);
+
+ SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName(
+ "something.valid").setMaxDistanceMm(100).build();
+ int clientId = doConnect();
+ IWifiAwareDiscoverySessionCallback mockCallback = mock(
+ IWifiAwareDiscoverySessionCallback.class);
+
+ mDut.subscribe(clientId, subscribeConfig, mockCallback);
+ }
+
+
+ /**
* Validates that on binder death we get a disconnect().
*/
@Test
@@ -295,7 +332,7 @@
@Test
public void testPublish() {
PublishConfig publishConfig = new PublishConfig.Builder().setServiceName("something.valid")
- .build();
+ .setRangingEnabled(true).build();
int clientId = doConnect();
IWifiAwareDiscoverySessionCallback mockCallback = mock(
IWifiAwareDiscoverySessionCallback.class);
@@ -390,7 +427,7 @@
@Test
public void testSubscribe() {
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder()
- .setServiceName("something.valid").build();
+ .setServiceName("something.valid").setMaxDistanceMm(100).build();
int clientId = doConnect();
IWifiAwareDiscoverySessionCallback mockCallback = mock(
IWifiAwareDiscoverySessionCallback.class);