Merge changes I7ca4c3af,Idb8e2806 into rvc-dev

* changes:
  Add test for SubscribeConfig.Builder().setMinDistanceMm(int)
  Add Cts test for createNetworkSpecifierPmk
This commit is contained in:
Nate Jiang
2020-03-20 16:09:23 +00:00
committed by Android (Google) Code Review

View File

@@ -64,6 +64,9 @@ public class SingleDeviceTest extends AndroidTestCase {
// wait for Wi-Fi Aware state changes & network requests callbacks
static private final int WAIT_FOR_AWARE_CHANGE_SECS = 10; // 10 seconds
private static final int MIN_DISTANCE_MM = 1 * 1000;
private static final int MAX_DISTANCE_MM = 3 * 1000;
private static final byte[] PMK_VALID = "01234567890123456789012345678901".getBytes();
private final Object mLock = new Object();
private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest");
@@ -615,7 +618,8 @@ public class SingleDeviceTest extends AndroidTestCase {
// 2. update-subscribe
subscribeConfig = new SubscribeConfig.Builder().setServiceName(
serviceName).setServiceSpecificInfo("extras".getBytes()).build();
serviceName).setServiceSpecificInfo("extras".getBytes())
.setMinDistanceMm(MIN_DISTANCE_MM).build();
discoverySession.updateSubscribe(subscribeConfig);
assertTrue("Subscribe update", discoveryCb.waitForCallback(
DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED));
@@ -741,7 +745,8 @@ public class SingleDeviceTest extends AndroidTestCase {
}
/**
* Request an Aware data-path (encrypted) as a Responder with an arbitrary peer MAC address.
* Request an Aware data-path (encrypted with Passphrase) as a Responder with an arbitrary peer
* MAC address.
* Validate that receive an onUnavailable() callback.
*/
public void testDataPathPassphraseOutOfBandFail() {
@@ -773,6 +778,40 @@ public class SingleDeviceTest extends AndroidTestCase {
session.close();
}
/**
* Request an Aware data-path (encrypted with PMK) as a Responder with an arbitrary peer MAC
* address.
* Validate that receive an onUnavailable() callback.
*/
public void testDataPathPmkOutOfBandFail() {
if (!TestUtils.shouldTestWifiAware(getContext())) {
return;
}
MacAddress mac = MacAddress.fromString("00:01:02:03:04:05");
// 1. initialize Aware: only purpose is to make sure it is available for OOB data-path
WifiAwareSession session = attachAndGetSession();
PublishConfig publishConfig = new PublishConfig.Builder().setServiceName(
"ValidName").build();
DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest();
session.publish(publishConfig, discoveryCb, mHandler);
assertTrue("Publish started",
discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_PUBLISH_STARTED));
// 2. request an AWARE network
NetworkCallbackTest networkCb = new NetworkCallbackTest();
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
NetworkCapabilities.TRANSPORT_WIFI_AWARE).setNetworkSpecifier(
session.createNetworkSpecifierPmk(
WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR, mac.toByteArray(),
PMK_VALID)).build();
mConnectivityManager.requestNetwork(nr, networkCb);
assertTrue("OnUnavailable not received", networkCb.waitForOnUnavailable());
session.close();
}
// local utilities
private WifiAwareSession attachAndGetSession() {