From 53bc7c3a501d41db02a9a2300740d98261934bd4 Mon Sep 17 00:00:00 2001 From: David Su Date: Thu, 19 Mar 2020 21:59:37 -0700 Subject: [PATCH] CTS: Split Wifi tests out of CtsNetTestCases Create CtsWifiTestCases. (dirty cherry-pick from internal branch) Bug: 129133376 Test: atest CtsWifiTestCases Change-Id: Iaa51f7ec86e6b4bfe64dcb26a8d8b818dd356608 Merged-In: Iaa51f7ec86e6b4bfe64dcb26a8d8b818dd356608 --- tests/cts/net/src/android/net/wifi/OWNERS | 5 - .../net/wifi/aware/cts/SingleDeviceTest.java | 787 ------------ .../android/net/wifi/aware/cts/TestUtils.java | 69 -- .../android/net/wifi/cts/ConcurrencyTest.java | 461 ------- .../net/wifi/cts/ConfigParserTest.java | 114 -- .../src/android/net/wifi/cts/FakeKeys.java | 257 ---- .../net/wifi/cts/MulticastLockTest.java | 79 -- .../android/net/wifi/cts/NsdManagerTest.java | 592 --------- .../android/net/wifi/cts/PpsMoParserTest.java | 131 -- .../android/net/wifi/cts/ScanResultTest.java | 233 ---- .../net/wifi/cts/SupplicantStateTest.java | 42 - .../net/wifi/cts/WifiConfigurationTest.java | 51 - .../wifi/cts/WifiEnterpriseConfigTest.java | 796 ------------- .../src/android/net/wifi/cts/WifiFeature.java | 32 - .../android/net/wifi/cts/WifiInfoTest.java | 170 --- .../android/net/wifi/cts/WifiLockTest.java | 90 -- .../android/net/wifi/cts/WifiManagerTest.java | 1056 ----------------- .../net/wifi/p2p/cts/WifiP2pConfigTest.java | 62 - .../android/net/wifi/rtt/cts/TestBase.java | 237 ---- .../android/net/wifi/rtt/cts/WifiRttTest.java | 214 ---- 20 files changed, 5478 deletions(-) delete mode 100644 tests/cts/net/src/android/net/wifi/OWNERS delete mode 100644 tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/aware/cts/TestUtils.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/ConcurrencyTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/ConfigParserTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/FakeKeys.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/MulticastLockTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/PpsMoParserTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/SupplicantStateTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiConfigurationTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiFeature.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java delete mode 100644 tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java delete mode 100644 tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java diff --git a/tests/cts/net/src/android/net/wifi/OWNERS b/tests/cts/net/src/android/net/wifi/OWNERS deleted file mode 100644 index 4a6001bcfe..0000000000 --- a/tests/cts/net/src/android/net/wifi/OWNERS +++ /dev/null @@ -1,5 +0,0 @@ -etancohen@google.com -lorenzo@google.com -mplass@google.com -rpius@google.com -satk@google.com diff --git a/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java b/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java deleted file mode 100644 index 1901f02cdc..0000000000 --- a/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java +++ /dev/null @@ -1,787 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware.cts; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.location.LocationManager; -import android.net.ConnectivityManager; -import android.net.MacAddress; -import android.net.NetworkCapabilities; -import android.net.NetworkRequest; -import android.net.wifi.WifiManager; -import android.net.wifi.aware.AttachCallback; -import android.net.wifi.aware.Characteristics; -import android.net.wifi.aware.DiscoverySessionCallback; -import android.net.wifi.aware.IdentityChangedListener; -import android.net.wifi.aware.PeerHandle; -import android.net.wifi.aware.PublishConfig; -import android.net.wifi.aware.PublishDiscoverySession; -import android.net.wifi.aware.SubscribeConfig; -import android.net.wifi.aware.SubscribeDiscoverySession; -import android.net.wifi.aware.WifiAwareManager; -import android.net.wifi.aware.WifiAwareSession; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.SystemClock; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -import com.android.compatibility.common.util.SystemUtil; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * Wi-Fi Aware CTS test suite: single device testing. Performs tests on a single - * device to validate Wi-Fi Aware. - */ -@AppModeFull(reason = "Cannot get WifiAwareManager in instant app mode") -public class SingleDeviceTest extends AndroidTestCase { - private static final String TAG = "WifiAwareCtsTests"; - - // wait for Wi-Fi Aware state changes & network requests callbacks - static private final int WAIT_FOR_AWARE_CHANGE_SECS = 10; // 10 seconds - - private final Object mLock = new Object(); - private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest"); - private final Handler mHandler; - { - mHandlerThread.start(); - mHandler = new Handler(mHandlerThread.getLooper()); - } - - private WifiAwareManager mWifiAwareManager; - private WifiManager mWifiManager; - private WifiManager.WifiLock mWifiLock; - private ConnectivityManager mConnectivityManager; - - // used to store any WifiAwareSession allocated during tests - will clean-up after tests - private List mSessions = new ArrayList<>(); - - private class WifiAwareBroadcastReceiver extends BroadcastReceiver { - private CountDownLatch mBlocker = new CountDownLatch(1); - - @Override - public void onReceive(Context context, Intent intent) { - if (WifiAwareManager.ACTION_WIFI_AWARE_STATE_CHANGED.equals(intent.getAction())) { - mBlocker.countDown(); - } - } - - boolean waitForStateChange() throws InterruptedException { - return mBlocker.await(WAIT_FOR_AWARE_CHANGE_SECS, TimeUnit.SECONDS); - } - } - - private class AttachCallbackTest extends AttachCallback { - static final int ATTACHED = 0; - static final int ATTACH_FAILED = 1; - static final int ERROR = 2; // no callback: timeout, interruption - - private CountDownLatch mBlocker = new CountDownLatch(1); - private int mCallbackCalled = ERROR; // garbage init - private WifiAwareSession mSession = null; - - @Override - public void onAttached(WifiAwareSession session) { - mCallbackCalled = ATTACHED; - mSession = session; - synchronized (mLock) { - mSessions.add(session); - } - mBlocker.countDown(); - } - - @Override - public void onAttachFailed() { - mCallbackCalled = ATTACH_FAILED; - mBlocker.countDown(); - } - - /** - * Waits for any of the callbacks to be called - or an error (timeout, interruption). - * Returns one of the ATTACHED, ATTACH_FAILED, or ERROR values. - */ - int waitForAnyCallback() { - try { - boolean noTimeout = mBlocker.await(WAIT_FOR_AWARE_CHANGE_SECS, TimeUnit.SECONDS); - if (noTimeout) { - return mCallbackCalled; - } else { - return ERROR; - } - } catch (InterruptedException e) { - return ERROR; - } - } - - /** - * Access the session created by a callback. Only useful to be called after calling - * waitForAnyCallback() and getting the ATTACHED code back. - */ - WifiAwareSession getSession() { - return mSession; - } - } - - private class IdentityChangedListenerTest extends IdentityChangedListener { - private CountDownLatch mBlocker = new CountDownLatch(1); - private byte[] mMac = null; - - @Override - public void onIdentityChanged(byte[] mac) { - mMac = mac; - mBlocker.countDown(); - } - - /** - * Waits for the listener callback to be called - or an error (timeout, interruption). - * Returns true on callback called, false on error (timeout, interruption). - */ - boolean waitForListener() { - try { - return mBlocker.await(WAIT_FOR_AWARE_CHANGE_SECS, TimeUnit.SECONDS); - } catch (InterruptedException e) { - return false; - } - } - - /** - * Returns the MAC address of the discovery interface supplied to the triggered callback. - */ - byte[] getMac() { - return mMac; - } - } - - private class DiscoverySessionCallbackTest extends DiscoverySessionCallback { - static final int ON_PUBLISH_STARTED = 0; - static final int ON_SUBSCRIBE_STARTED = 1; - static final int ON_SESSION_CONFIG_UPDATED = 2; - static final int ON_SESSION_CONFIG_FAILED = 3; - static final int ON_SESSION_TERMINATED = 4; - static final int ON_SERVICE_DISCOVERED = 5; - static final int ON_MESSAGE_SEND_SUCCEEDED = 6; - static final int ON_MESSAGE_SEND_FAILED = 7; - static final int ON_MESSAGE_RECEIVED = 8; - - private final Object mLocalLock = new Object(); - - private CountDownLatch mBlocker; - private int mCurrentWaitForCallback; - private ArrayDeque mCallbackQueue = new ArrayDeque<>(); - - private PublishDiscoverySession mPublishDiscoverySession; - private SubscribeDiscoverySession mSubscribeDiscoverySession; - - private void processCallback(int callback) { - synchronized (mLocalLock) { - if (mBlocker != null && mCurrentWaitForCallback == callback) { - mBlocker.countDown(); - } else { - mCallbackQueue.addLast(callback); - } - } - } - - @Override - public void onPublishStarted(PublishDiscoverySession session) { - mPublishDiscoverySession = session; - processCallback(ON_PUBLISH_STARTED); - } - - @Override - public void onSubscribeStarted(SubscribeDiscoverySession session) { - mSubscribeDiscoverySession = session; - processCallback(ON_SUBSCRIBE_STARTED); - } - - @Override - public void onSessionConfigUpdated() { - processCallback(ON_SESSION_CONFIG_UPDATED); - } - - @Override - public void onSessionConfigFailed() { - processCallback(ON_SESSION_CONFIG_FAILED); - } - - @Override - public void onSessionTerminated() { - processCallback(ON_SESSION_TERMINATED); - } - - @Override - public void onServiceDiscovered(PeerHandle peerHandle, byte[] serviceSpecificInfo, - List matchFilter) { - processCallback(ON_SERVICE_DISCOVERED); - } - - @Override - public void onMessageSendSucceeded(int messageId) { - processCallback(ON_MESSAGE_SEND_SUCCEEDED); - } - - @Override - public void onMessageSendFailed(int messageId) { - processCallback(ON_MESSAGE_SEND_FAILED); - } - - @Override - public void onMessageReceived(PeerHandle peerHandle, byte[] message) { - processCallback(ON_MESSAGE_RECEIVED); - } - - /** - * Wait for the specified callback - any of the ON_* constants. Returns a true - * on success (specified callback triggered) or false on failure (timed-out or - * interrupted while waiting for the requested callback). - * - * Note: other callbacks happening while while waiting for the specified callback will - * be queued. - */ - boolean waitForCallback(int callback) { - return waitForCallback(callback, WAIT_FOR_AWARE_CHANGE_SECS); - } - - /** - * Wait for the specified callback - any of the ON_* constants. Returns a true - * on success (specified callback triggered) or false on failure (timed-out or - * interrupted while waiting for the requested callback). - * - * Same as waitForCallback(int callback) execpt that allows specifying a custom timeout. - * The default timeout is a short value expected to be sufficient for all behaviors which - * should happen relatively quickly. Specifying a custom timeout should only be done for - * those cases which are known to take a specific longer period of time. - * - * Note: other callbacks happening while while waiting for the specified callback will - * be queued. - */ - boolean waitForCallback(int callback, int timeoutSec) { - synchronized (mLocalLock) { - boolean found = mCallbackQueue.remove(callback); - if (found) { - return true; - } - - mCurrentWaitForCallback = callback; - mBlocker = new CountDownLatch(1); - } - - try { - return mBlocker.await(timeoutSec, TimeUnit.SECONDS); - } catch (InterruptedException e) { - return false; - } - } - - /** - * Indicates whether the specified callback (any of the ON_* constants) has already - * happened and in the queue. Useful when the order of events is important. - */ - boolean hasCallbackAlreadyHappened(int callback) { - synchronized (mLocalLock) { - return mCallbackQueue.contains(callback); - } - } - - /** - * Returns the last created publish discovery session. - */ - PublishDiscoverySession getPublishDiscoverySession() { - PublishDiscoverySession session = mPublishDiscoverySession; - mPublishDiscoverySession = null; - return session; - } - - /** - * Returns the last created subscribe discovery session. - */ - SubscribeDiscoverySession getSubscribeDiscoverySession() { - SubscribeDiscoverySession session = mSubscribeDiscoverySession; - mSubscribeDiscoverySession = null; - return session; - } - } - - private class NetworkCallbackTest extends ConnectivityManager.NetworkCallback { - private CountDownLatch mBlocker = new CountDownLatch(1); - - @Override - public void onUnavailable() { - mBlocker.countDown(); - } - - /** - * Wait for the onUnavailable() callback to be triggered. Returns true if triggered, - * otherwise (timed-out, interrupted) returns false. - */ - boolean waitForOnUnavailable() { - try { - return mBlocker.await(WAIT_FOR_AWARE_CHANGE_SECS, TimeUnit.SECONDS); - } catch (InterruptedException e) { - return false; - } - } - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - assertTrue("Wi-Fi Aware requires Location to be Enabled", - ((LocationManager) getContext().getSystemService( - Context.LOCATION_SERVICE)).isLocationEnabled()); - - mWifiAwareManager = (WifiAwareManager) getContext().getSystemService( - Context.WIFI_AWARE_SERVICE); - assertNotNull("Wi-Fi Aware Manager", mWifiAwareManager); - - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull("Wi-Fi Manager", mWifiManager); - mWifiLock = mWifiManager.createWifiLock(TAG); - mWifiLock.acquire(); - if (!mWifiManager.isWifiEnabled()) { - SystemUtil.runShellCommand("svc wifi enable"); - } - - mConnectivityManager = (ConnectivityManager) getContext().getSystemService( - Context.CONNECTIVITY_SERVICE); - assertNotNull("Connectivity Manager", mConnectivityManager); - - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiAwareManager.ACTION_WIFI_AWARE_STATE_CHANGED); - WifiAwareBroadcastReceiver receiver = new WifiAwareBroadcastReceiver(); - mContext.registerReceiver(receiver, intentFilter); - if (!mWifiAwareManager.isAvailable()) { - assertTrue("Timeout waiting for Wi-Fi Aware to change status", - receiver.waitForStateChange()); - assertTrue("Wi-Fi Aware is not available (should be)", mWifiAwareManager.isAvailable()); - } - } - - @Override - protected void tearDown() throws Exception { - if (!TestUtils.shouldTestWifiAware(getContext())) { - super.tearDown(); - return; - } - - synchronized (mLock) { - for (WifiAwareSession session : mSessions) { - // no damage from destroying twice (i.e. ok if test cleaned up after itself already) - session.close(); - } - mSessions.clear(); - } - - super.tearDown(); - } - - /** - * Validate: - * - Characteristics are available - * - Characteristics values are legitimate. Not in the CDD. However, the tested values are - * based on the Wi-Fi Aware protocol. - */ - public void testCharacteristics() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - Characteristics characteristics = mWifiAwareManager.getCharacteristics(); - assertNotNull("Wi-Fi Aware characteristics are null", characteristics); - assertEquals("Service Name Length", characteristics.getMaxServiceNameLength(), 255); - assertEquals("Service Specific Information Length", - characteristics.getMaxServiceSpecificInfoLength(), 255); - assertEquals("Match Filter Length", characteristics.getMaxMatchFilterLength(), 255); - } - - /** - * Validate that on Wi-Fi Aware availability change we get a broadcast + the API returns - * correct status. - */ - public void testAvailabilityStatusChange() throws Exception { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiAwareManager.ACTION_WIFI_AWARE_STATE_CHANGED); - - // 1. Disable Wi-Fi - WifiAwareBroadcastReceiver receiver1 = new WifiAwareBroadcastReceiver(); - mContext.registerReceiver(receiver1, intentFilter); - SystemUtil.runShellCommand("svc wifi disable"); - - assertTrue("Timeout waiting for Wi-Fi Aware to change status", - receiver1.waitForStateChange()); - assertFalse("Wi-Fi Aware is available (should not be)", mWifiAwareManager.isAvailable()); - - // 2. Enable Wi-Fi - WifiAwareBroadcastReceiver receiver2 = new WifiAwareBroadcastReceiver(); - mContext.registerReceiver(receiver2, intentFilter); - SystemUtil.runShellCommand("svc wifi enable"); - - assertTrue("Timeout waiting for Wi-Fi Aware to change status", - receiver2.waitForStateChange()); - assertTrue("Wi-Fi Aware is not available (should be)", mWifiAwareManager.isAvailable()); - } - - /** - * Validate that can attach to Wi-Fi Aware. - */ - public void testAttachNoIdentity() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - WifiAwareSession session = attachAndGetSession(); - session.close(); - } - - /** - * Validate that can attach to Wi-Fi Aware and get identity information. Use the identity - * information to validate that MAC address changes on every attach. - * - * Note: relies on no other entity using Wi-Fi Aware during the CTS test. Since if it is used - * then the attach/destroy will not correspond to enable/disable and will not result in a new - * MAC address being generated. - */ - public void testAttachDiscoveryAddressChanges() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - final int numIterations = 10; - Set macs = new HashSet<>(); - - for (int i = 0; i < numIterations; ++i) { - AttachCallbackTest attachCb = new AttachCallbackTest(); - IdentityChangedListenerTest identityL = new IdentityChangedListenerTest(); - mWifiAwareManager.attach(attachCb, identityL, mHandler); - assertEquals("Wi-Fi Aware attach: iteration " + i, AttachCallbackTest.ATTACHED, - attachCb.waitForAnyCallback()); - assertTrue("Wi-Fi Aware attach: iteration " + i, identityL.waitForListener()); - - WifiAwareSession session = attachCb.getSession(); - assertNotNull("Wi-Fi Aware session: iteration " + i, session); - - byte[] mac = identityL.getMac(); - assertNotNull("Wi-Fi Aware discovery MAC: iteration " + i, mac); - - session.close(); - - macs.add(new TestUtils.MacWrapper(mac)); - } - - assertEquals("", numIterations, macs.size()); - } - - /** - * Validate a successful publish discovery session lifetime: publish, update publish, destroy. - */ - public void testPublishDiscoverySuccess() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - final String serviceName = "ValidName"; - - WifiAwareSession session = attachAndGetSession(); - - PublishConfig publishConfig = new PublishConfig.Builder().setServiceName( - serviceName).build(); - DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); - - // 1. publish - session.publish(publishConfig, discoveryCb, mHandler); - assertTrue("Publish started", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_PUBLISH_STARTED)); - PublishDiscoverySession discoverySession = discoveryCb.getPublishDiscoverySession(); - assertNotNull("Publish session", discoverySession); - - // 2. update-publish - publishConfig = new PublishConfig.Builder().setServiceName( - serviceName).setServiceSpecificInfo("extras".getBytes()).build(); - discoverySession.updatePublish(publishConfig); - assertTrue("Publish update", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - // 3. destroy - assertFalse("Publish not terminated", discoveryCb.hasCallbackAlreadyHappened( - DiscoverySessionCallbackTest.ON_SESSION_TERMINATED)); - discoverySession.close(); - - // 4. try update post-destroy: should time-out waiting for cb - discoverySession.updatePublish(publishConfig); - assertFalse("Publish update post destroy", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - session.close(); - } - - /** - * Validate that publish with a Time To Live (TTL) setting expires within the specified - * time (and validates that the terminate callback is triggered). - */ - public void testPublishLimitedTtlSuccess() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - final String serviceName = "ValidName"; - final int ttlSec = 5; - - WifiAwareSession session = attachAndGetSession(); - - PublishConfig publishConfig = new PublishConfig.Builder().setServiceName( - serviceName).setTtlSec(ttlSec).setTerminateNotificationEnabled(true).build(); - DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); - - // 1. publish - session.publish(publishConfig, discoveryCb, mHandler); - assertTrue("Publish started", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_PUBLISH_STARTED)); - PublishDiscoverySession discoverySession = discoveryCb.getPublishDiscoverySession(); - assertNotNull("Publish session", discoverySession); - - // 2. wait for terminate within 'ttlSec'. - assertTrue("Publish terminated", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_SESSION_TERMINATED, - ttlSec + 5)); - - // 3. try update post-termination: should time-out waiting for cb - publishConfig = new PublishConfig.Builder().setServiceName( - serviceName).setServiceSpecificInfo("extras".getBytes()).build(); - discoverySession.updatePublish(publishConfig); - assertFalse("Publish update post terminate", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - session.close(); - } - - /** - * Validate a successful subscribe discovery session lifetime: subscribe, update subscribe, - * destroy. - */ - public void testSubscribeDiscoverySuccess() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - final String serviceName = "ValidName"; - - WifiAwareSession session = attachAndGetSession(); - - SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName( - serviceName).build(); - DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); - - // 1. subscribe - session.subscribe(subscribeConfig, discoveryCb, mHandler); - assertTrue("Subscribe started", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_SUBSCRIBE_STARTED)); - SubscribeDiscoverySession discoverySession = discoveryCb.getSubscribeDiscoverySession(); - assertNotNull("Subscribe session", discoverySession); - - // 2. update-subscribe - subscribeConfig = new SubscribeConfig.Builder().setServiceName( - serviceName).setServiceSpecificInfo("extras".getBytes()).build(); - discoverySession.updateSubscribe(subscribeConfig); - assertTrue("Subscribe update", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - // 3. destroy - assertFalse("Subscribe not terminated", discoveryCb.hasCallbackAlreadyHappened( - DiscoverySessionCallbackTest.ON_SESSION_TERMINATED)); - discoverySession.close(); - - // 4. try update post-destroy: should time-out waiting for cb - discoverySession.updateSubscribe(subscribeConfig); - assertFalse("Subscribe update post destroy", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - session.close(); - } - - /** - * Validate that subscribe with a Time To Live (TTL) setting expires within the specified - * time (and validates that the terminate callback is triggered). - */ - public void testSubscribeLimitedTtlSuccess() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - final String serviceName = "ValidName"; - final int ttlSec = 5; - - WifiAwareSession session = attachAndGetSession(); - - SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().setServiceName( - serviceName).setTtlSec(ttlSec).setTerminateNotificationEnabled(true).build(); - DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); - - // 1. subscribe - session.subscribe(subscribeConfig, discoveryCb, mHandler); - assertTrue("Subscribe started", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_SUBSCRIBE_STARTED)); - SubscribeDiscoverySession discoverySession = discoveryCb.getSubscribeDiscoverySession(); - assertNotNull("Subscribe session", discoverySession); - - // 2. wait for terminate within 'ttlSec'. - assertTrue("Subscribe terminated", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_SESSION_TERMINATED, - ttlSec + 5)); - - // 3. try update post-termination: should time-out waiting for cb - subscribeConfig = new SubscribeConfig.Builder().setServiceName( - serviceName).setServiceSpecificInfo("extras".getBytes()).build(); - discoverySession.updateSubscribe(subscribeConfig); - assertFalse("Subscribe update post terminate", discoveryCb.waitForCallback( - DiscoverySessionCallbackTest.ON_SESSION_CONFIG_UPDATED)); - - session.close(); - } - - /** - * Test the send message flow. Since testing single device cannot send to a real peer - - * validate that sending to a bogus peer fails. - */ - public void testSendMessageFail() { - if (!TestUtils.shouldTestWifiAware(getContext())) { - return; - } - - WifiAwareSession session = attachAndGetSession(); - - PublishConfig publishConfig = new PublishConfig.Builder().setServiceName( - "ValidName").build(); - DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); - - // 1. publish - session.publish(publishConfig, discoveryCb, mHandler); - assertTrue("Publish started", - discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_PUBLISH_STARTED)); - PublishDiscoverySession discoverySession = discoveryCb.getPublishDiscoverySession(); - assertNotNull("Publish session", discoverySession); - - // 2. send a message with a null peer-handle - expect exception - try { - discoverySession.sendMessage(null, -1290, "some message".getBytes()); - fail("Expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // empty - } - - discoverySession.close(); - session.close(); - } - - /** - * Request an Aware data-path (open) as a Responder with an arbitrary peer MAC address. Validate - * that receive an onUnavailable() callback. - */ - public void testDataPathOpenOutOfBandFail() { - 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.createNetworkSpecifierOpen( - WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR, - mac.toByteArray())).build(); - mConnectivityManager.requestNetwork(nr, networkCb); - assertTrue("OnUnavailable not received", networkCb.waitForOnUnavailable()); - - session.close(); - } - - /** - * Request an Aware data-path (encrypted) as a Responder with an arbitrary peer MAC address. - * Validate that receive an onUnavailable() callback. - */ - public void testDataPathPassphraseOutOfBandFail() { - 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.createNetworkSpecifierPassphrase( - WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR, mac.toByteArray(), - "abcdefghihk")).build(); - mConnectivityManager.requestNetwork(nr, networkCb); - assertTrue("OnUnavailable not received", networkCb.waitForOnUnavailable()); - - session.close(); - } - - // local utilities - - private WifiAwareSession attachAndGetSession() { - AttachCallbackTest attachCb = new AttachCallbackTest(); - mWifiAwareManager.attach(attachCb, mHandler); - int cbCalled = attachCb.waitForAnyCallback(); - assertEquals("Wi-Fi Aware attach", AttachCallbackTest.ATTACHED, cbCalled); - - WifiAwareSession session = attachCb.getSession(); - assertNotNull("Wi-Fi Aware session", session); - - return session; - } -} diff --git a/tests/cts/net/src/android/net/wifi/aware/cts/TestUtils.java b/tests/cts/net/src/android/net/wifi/aware/cts/TestUtils.java deleted file mode 100644 index a12c8bb0d2..0000000000 --- a/tests/cts/net/src/android/net/wifi/aware/cts/TestUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.aware.cts; - -import android.content.Context; -import android.content.pm.PackageManager; - -import java.util.Arrays; - -/** - * Test utilities for Wi-Fi Aware CTS test suite. - */ -class TestUtils { - static final String TAG = "WifiAwareCtsTests"; - - /** - * Returns a flag indicating whether or not Wi-Fi Aware should be tested. Wi-Fi Aware - * should be tested if the feature is supported on the current device. - */ - static boolean shouldTestWifiAware(Context context) { - final PackageManager pm = context.getPackageManager(); - return pm.hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE); - } - - /** - * Wraps a byte[] (MAC address representation). Intended to provide hash and equality operators - * so that the MAC address can be used in containers. - */ - static class MacWrapper { - private byte[] mMac; - - MacWrapper(byte[] mac) { - mMac = mac; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof MacWrapper)) { - return false; - } - - MacWrapper lhs = (MacWrapper) o; - return Arrays.equals(mMac, lhs.mMac); - } - - @Override - public int hashCode() { - return Arrays.hashCode(mMac); - } - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/ConcurrencyTest.java b/tests/cts/net/src/android/net/wifi/cts/ConcurrencyTest.java deleted file mode 100644 index ba0832f8b6..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/ConcurrencyTest.java +++ /dev/null @@ -1,461 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import static org.junit.Assert.assertNotEquals; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.net.ConnectivityManager; -import android.net.ConnectivityManager.NetworkCallback; -import android.net.Network; -import android.net.NetworkCapabilities; -import android.net.NetworkInfo; -import android.net.NetworkRequest; -import android.net.wifi.WifiManager; -import android.net.wifi.p2p.WifiP2pManager; -import android.provider.Settings; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; -import android.util.Log; - -import com.android.compatibility.common.util.SystemUtil; - -import java.util.Arrays; -import java.util.BitSet; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class ConcurrencyTest extends AndroidTestCase { - private class MySync { - static final int WIFI_STATE = 0; - static final int P2P_STATE = 1; - static final int DISCOVERY_STATE = 2; - static final int NETWORK_INFO = 3; - - public BitSet pendingSync = new BitSet(); - - public int expectedWifiState; - public int expectedP2pState; - public int expectedDiscoveryState; - public NetworkInfo expectedNetworkInfo; - } - - private class MyResponse { - public boolean valid = false; - - public boolean success; - public int p2pState; - public int discoveryState; - public NetworkInfo networkInfo; - } - - private WifiManager mWifiManager; - private WifiP2pManager mWifiP2pManager; - private WifiP2pManager.Channel mWifiP2pChannel; - private MySync mMySync = new MySync(); - private MyResponse mMyResponse = new MyResponse(); - - private static final String TAG = "ConcurrencyTest"; - private static final int TIMEOUT_MSEC = 6000; - private static final int WAIT_MSEC = 60; - private static final int DURATION = 10000; - private IntentFilter mIntentFilter; - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.pendingSync.set(MySync.WIFI_STATE); - mMySync.expectedWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, - WifiManager.WIFI_STATE_DISABLED); - mMySync.notify(); - } - } else if(action.equals(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.pendingSync.set(MySync.P2P_STATE); - mMySync.expectedP2pState = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, - WifiP2pManager.WIFI_P2P_STATE_DISABLED); - mMySync.notify(); - } - } else if (action.equals(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.pendingSync.set(MySync.DISCOVERY_STATE); - mMySync.expectedDiscoveryState = intent.getIntExtra( - WifiP2pManager.EXTRA_DISCOVERY_STATE, - WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED); - mMySync.notify(); - } - } else if (action.equals(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.pendingSync.set(MySync.NETWORK_INFO); - mMySync.expectedNetworkInfo = (NetworkInfo) intent.getExtra( - WifiP2pManager.EXTRA_NETWORK_INFO, null); - mMySync.notify(); - } - } - } - }; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (!WifiFeature.isWifiSupported(getContext()) && - !WifiFeature.isP2pSupported(getContext())) { - // skip the test if WiFi && p2p are not supported - return; - } - mIntentFilter = new IntentFilter(); - mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); - - mContext.registerReceiver(mReceiver, mIntentFilter); - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - if (mWifiManager.isWifiEnabled()) { - SystemUtil.runShellCommand("svc wifi disable"); - Thread.sleep(DURATION); - } - assertTrue(!mWifiManager.isWifiEnabled()); - mMySync.expectedWifiState = WifiManager.WIFI_STATE_DISABLED; - mMySync.expectedP2pState = WifiP2pManager.WIFI_P2P_STATE_DISABLED; - mMySync.expectedDiscoveryState = WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED; - mMySync.expectedNetworkInfo = null; - } - - @Override - protected void tearDown() throws Exception { - if (!WifiFeature.isWifiSupported(getContext()) && - !WifiFeature.isP2pSupported(getContext())) { - // skip the test if WiFi and p2p are not supported - super.tearDown(); - return; - } - mContext.unregisterReceiver(mReceiver); - - enableWifi(); - super.tearDown(); - } - - private boolean waitForBroadcasts(List waitSyncList) { - synchronized (mMySync) { - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (System.currentTimeMillis() < timeout) { - List handledSyncList = waitSyncList.stream() - .filter(w -> mMySync.pendingSync.get(w)) - .collect(Collectors.toList()); - handledSyncList.forEach(w -> mMySync.pendingSync.clear(w)); - waitSyncList.removeAll(handledSyncList); - if (waitSyncList.isEmpty()) { - break; - } - try { - mMySync.wait(WAIT_MSEC); - } catch (InterruptedException e) { } - } - if (!waitSyncList.isEmpty()) { - Log.i(TAG, "Missing broadcast: " + waitSyncList); - } - return waitSyncList.isEmpty(); - } - } - - private boolean waitForBroadcasts(int waitSingleSync) { - return waitForBroadcasts( - new LinkedList(Arrays.asList(waitSingleSync))); - } - - private boolean waitForServiceResponse(MyResponse waitResponse) { - synchronized (waitResponse) { - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (System.currentTimeMillis() < timeout) { - try { - waitResponse.wait(WAIT_MSEC); - } catch (InterruptedException e) { } - - if (waitResponse.valid) { - return true; - } - } - return false; - } - } - - // Return true if location is enabled. - private boolean isLocationEnabled() { - return Settings.Secure.getInt(getContext().getContentResolver(), - Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF) - != Settings.Secure.LOCATION_MODE_OFF; - } - - // Returns true if the device has location feature. - private boolean hasLocationFeature() { - return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION); - } - - private void resetResponse(MyResponse responseObj) { - synchronized (responseObj) { - responseObj.valid = false; - responseObj.networkInfo = null; - } - } - - /* - * Enables Wifi and block until connection is established. - */ - private void enableWifi() throws InterruptedException { - if (!mWifiManager.isWifiEnabled()) { - SystemUtil.runShellCommand("svc wifi enable"); - } - - ConnectivityManager cm = - (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkRequest request = - new NetworkRequest.Builder().addTransportType(NetworkCapabilities.TRANSPORT_WIFI) - .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - .build(); - final CountDownLatch latch = new CountDownLatch(1); - NetworkCallback networkCallback = new NetworkCallback() { - @Override - public void onAvailable(Network network) { - latch.countDown(); - } - }; - cm.registerNetworkCallback(request, networkCallback); - latch.await(DURATION, TimeUnit.MILLISECONDS); - - cm.unregisterNetworkCallback(networkCallback); - } - - private boolean setupWifiP2p() { - // Cannot support p2p alone - if (!WifiFeature.isWifiSupported(getContext())) { - assertTrue(!WifiFeature.isP2pSupported(getContext())); - return false; - } - - if (!WifiFeature.isP2pSupported(getContext())) { - // skip the test if p2p is not supported - return false; - } - - if (!hasLocationFeature()) { - Log.d(TAG, "Skipping test as location is not supported"); - return false; - } - if (!isLocationEnabled()) { - fail("Please enable location for this test - since P-release WiFi Direct" - + " needs Location enabled."); - } - - mWifiP2pManager = - (WifiP2pManager) getContext().getSystemService(Context.WIFI_P2P_SERVICE); - mWifiP2pChannel = mWifiP2pManager.initialize( - getContext(), getContext().getMainLooper(), null); - - assertNotNull(mWifiP2pManager); - assertNotNull(mWifiP2pChannel); - - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (!mWifiManager.isWifiEnabled() && System.currentTimeMillis() < timeout) { - try { - enableWifi(); - } catch (InterruptedException e) { } - } - - assertTrue(mWifiManager.isWifiEnabled()); - - assertTrue(waitForBroadcasts( - new LinkedList( - Arrays.asList(MySync.WIFI_STATE, MySync.P2P_STATE)))); - - assertEquals(WifiManager.WIFI_STATE_ENABLED, mMySync.expectedWifiState); - assertEquals(WifiP2pManager.WIFI_P2P_STATE_ENABLED, mMySync.expectedP2pState); - - assertTrue(waitForBroadcasts(MySync.NETWORK_INFO)); - // wait for changing to EnabledState - assertNotNull(mMySync.expectedNetworkInfo); - - return true; - } - - public void testConcurrency() { - if (!setupWifiP2p()) { - return; - } - - resetResponse(mMyResponse); - mWifiP2pManager.requestP2pState(mWifiP2pChannel, new WifiP2pManager.P2pStateListener() { - @Override - public void onP2pStateAvailable(int state) { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.p2pState = state; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertEquals(WifiP2pManager.WIFI_P2P_STATE_ENABLED, mMyResponse.p2pState); - } - - public void testRequestDiscoveryState() { - if (!setupWifiP2p()) { - return; - } - - resetResponse(mMyResponse); - mWifiP2pManager.requestDiscoveryState( - mWifiP2pChannel, new WifiP2pManager.DiscoveryStateListener() { - @Override - public void onDiscoveryStateAvailable(int state) { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.discoveryState = state; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertEquals(WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED, mMyResponse.discoveryState); - - resetResponse(mMyResponse); - mWifiP2pManager.discoverPeers(mWifiP2pChannel, new WifiP2pManager.ActionListener() { - @Override - public void onSuccess() { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.success = true; - mMyResponse.notify(); - } - } - - @Override - public void onFailure(int reason) { - synchronized (mMyResponse) { - Log.d(TAG, "discoveryPeers failure reason: " + reason); - mMyResponse.valid = true; - mMyResponse.success = false; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertTrue(mMyResponse.success); - assertTrue(waitForBroadcasts(MySync.DISCOVERY_STATE)); - - resetResponse(mMyResponse); - mWifiP2pManager.requestDiscoveryState(mWifiP2pChannel, - new WifiP2pManager.DiscoveryStateListener() { - @Override - public void onDiscoveryStateAvailable(int state) { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.discoveryState = state; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertEquals(WifiP2pManager.WIFI_P2P_DISCOVERY_STARTED, mMyResponse.discoveryState); - - mWifiP2pManager.stopPeerDiscovery(mWifiP2pChannel, null); - } - - public void testRequestNetworkInfo() { - if (!setupWifiP2p()) { - return; - } - - resetResponse(mMyResponse); - mWifiP2pManager.requestNetworkInfo(mWifiP2pChannel, - new WifiP2pManager.NetworkInfoListener() { - @Override - public void onNetworkInfoAvailable(NetworkInfo info) { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.networkInfo = info; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertNotNull(mMyResponse.networkInfo); - // The state might be IDLE, DISCONNECTED, FAILED before a connection establishment. - // Just ensure the state is NOT CONNECTED. - assertNotEquals(NetworkInfo.DetailedState.CONNECTED, - mMySync.expectedNetworkInfo.getDetailedState()); - - resetResponse(mMyResponse); - mWifiP2pManager.createGroup(mWifiP2pChannel, new WifiP2pManager.ActionListener() { - @Override - public void onSuccess() { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.success = true; - mMyResponse.notify(); - } - } - - @Override - public void onFailure(int reason) { - synchronized (mMyResponse) { - Log.d(TAG, "createGroup failure reason: " + reason); - mMyResponse.valid = true; - mMyResponse.success = false; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertTrue(mMyResponse.success); - assertTrue(waitForBroadcasts(MySync.NETWORK_INFO)); - assertNotNull(mMySync.expectedNetworkInfo); - assertEquals(NetworkInfo.DetailedState.CONNECTED, - mMySync.expectedNetworkInfo.getDetailedState()); - - resetResponse(mMyResponse); - mWifiP2pManager.requestNetworkInfo(mWifiP2pChannel, - new WifiP2pManager.NetworkInfoListener() { - @Override - public void onNetworkInfoAvailable(NetworkInfo info) { - synchronized (mMyResponse) { - mMyResponse.valid = true; - mMyResponse.networkInfo = info; - mMyResponse.notify(); - } - } - }); - assertTrue(waitForServiceResponse(mMyResponse)); - assertNotNull(mMyResponse.networkInfo); - assertEquals(NetworkInfo.DetailedState.CONNECTED, - mMyResponse.networkInfo.getDetailedState()); - - mWifiP2pManager.removeGroup(mWifiP2pChannel, null); - } - -} diff --git a/tests/cts/net/src/android/net/wifi/cts/ConfigParserTest.java b/tests/cts/net/src/android/net/wifi/cts/ConfigParserTest.java deleted file mode 100644 index 52ed2a6d73..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/ConfigParserTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package android.net.wifi.cts; - -import android.net.wifi.hotspot2.ConfigParser; -import android.net.wifi.hotspot2.PasspointConfiguration; -import android.net.wifi.hotspot2.pps.Credential; -import android.net.wifi.hotspot2.pps.HomeSp; -import android.test.AndroidTestCase; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Arrays; - -/** - * CTS tests for Hotspot 2.0 Release 1 installation file parsing API. - */ -public class ConfigParserTest extends AndroidTestCase { - /** - * Hotspot 2.0 Release 1 installation file that contains a Passpoint profile and a - * CA (Certificate Authority) X.509 certificate {@link FakeKeys#CA_CERT0}. - */ - private static final String PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT = - "assets/HSR1ProfileWithCACert.base64"; - - /** - * Read the content of the given resource file into a String. - * - * @param filename String name of the file - * @return String - * @throws IOException - */ - private String loadResourceFile(String filename) throws IOException { - InputStream in = getClass().getClassLoader().getResourceAsStream(filename); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - StringBuilder builder = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - builder.append(line).append("\n"); - } - - return builder.toString(); - } - - /** - * Generate a {@link PasspointConfiguration} that matches the configuration specified in the - * XML file {@link #PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT}. - * - * @return {@link PasspointConfiguration} - */ - private PasspointConfiguration generateConfigurationFromProfile() { - PasspointConfiguration config = new PasspointConfiguration(); - - // HomeSP configuration. - HomeSp homeSp = new HomeSp(); - homeSp.setFriendlyName("Century House"); - homeSp.setFqdn("mi6.co.uk"); - homeSp.setRoamingConsortiumOis(new long[] {0x112233L, 0x445566L}); - config.setHomeSp(homeSp); - - // Credential configuration. - Credential credential = new Credential(); - credential.setRealm("shaken.stirred.com"); - Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setUsername("james"); - userCredential.setPassword("Ym9uZDAwNw=="); - userCredential.setEapType(21); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); - credential.setUserCredential(userCredential); - Credential.CertificateCredential certCredential = new Credential.CertificateCredential(); - certCredential.setCertType("x509v3"); - byte[] certSha256Fingerprint = new byte[32]; - Arrays.fill(certSha256Fingerprint, (byte)0x1f); - certCredential.setCertSha256Fingerprint(certSha256Fingerprint); - credential.setCertCredential(certCredential); - Credential.SimCredential simCredential = new Credential.SimCredential(); - simCredential.setImsi("imsi"); - simCredential.setEapType(24); - credential.setSimCredential(simCredential); - credential.setCaCertificate(FakeKeys.CA_CERT0); - config.setCredential(credential); - return config; - } - - /** - * Verify a valid installation file is parsed successfully with the matching contents. - * - * @throws Exception - */ - public void testParseConfigFile() throws Exception { - String configStr = loadResourceFile(PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT); - PasspointConfiguration expectedConfig = generateConfigurationFromProfile(); - PasspointConfiguration actualConfig = - ConfigParser.parsePasspointConfig( - "application/x-wifi-config", configStr.getBytes()); - assertTrue(actualConfig.equals(expectedConfig)); - } -} \ No newline at end of file diff --git a/tests/cts/net/src/android/net/wifi/cts/FakeKeys.java b/tests/cts/net/src/android/net/wifi/cts/FakeKeys.java deleted file mode 100644 index f8753017db..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/FakeKeys.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package android.net.wifi.cts; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.PKCS8EncodedKeySpec; - -/** - * A class containing test certificates and private keys. - */ -public class FakeKeys { - private static final String CA_CERT0_STRING = "-----BEGIN CERTIFICATE-----\n" + - "MIIDKDCCAhCgAwIBAgIJAILlFdwzLVurMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + - "BAMTB0VBUCBDQTEwHhcNMTYwMTEyMTE1MDE1WhcNMjYwMTA5MTE1MDE1WjASMRAw\n" + - "DgYDVQQDEwdFQVAgQ0ExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + - "znAPUz26Msae4ws43czR41/J2QtrSIZUKmVUsVumDbYHrPNvTXKSMXAcewORDQYX\n" + - "RqvHvpn8CscB1+oGXZvHwxj4zV0WKoK2zeXkau3vcyl3HIKupJfq2TEACefVjj0t\n" + - "JW+X35PGWp9/H5zIUNVNVjS7Ums84IvKhRB8512PB9UyHagXYVX5GWpAcVpyfrlR\n" + - "FI9Qdhh+Pbk0uyktdbf/CdfgHOoebrTtwRljM0oDtX+2Cv6j0wBK7hD8pPvf1+uy\n" + - "GzczigAU/4Kw7eZqydf9B+5RupR+IZipX41xEiIrKRwqi517WWzXcjaG2cNbf451\n" + - "xpH5PnV3i1tq04jMGQUzFwIDAQABo4GAMH4wHQYDVR0OBBYEFIwX4vs8BiBcScod\n" + - "5noZHRM8E4+iMEIGA1UdIwQ7MDmAFIwX4vs8BiBcScod5noZHRM8E4+ioRakFDAS\n" + - "MRAwDgYDVQQDEwdFQVAgQ0ExggkAguUV3DMtW6swDAYDVR0TBAUwAwEB/zALBgNV\n" + - "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAFfQqOTA7Rv7K+luQ7pnas4BYwHE\n" + - "9GEP/uohv6KOy0TGQFbrRTjFoLVNB9BZ1ymMDZ0/TIwIUc7wi7a8t5mEqYH153wW\n" + - "aWooiSjyLLhuI4sNrNCOtisdBq2r2MFXt6h0mAQYOPv8R8K7/fgSxGFqzhyNmmVL\n" + - "1qBJldx34SpwsTALQVPb4hGwJzZfr1PcpEQx6xMnTl8xEWZE3Ms99uaUxbQqIwRu\n" + - "LgAOkNCmY2m89VhzaHJ1uV85AdM/tD+Ysmlnnjt9LRCejbBipjIGjOXrg1JP+lxV\n" + - "muM4vH+P/mlmxsPPz0d65b+EGmJZpoLkO/tdNNvCYzjJpTEWpEsO6NMhKYo=\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CA_CERT0 = loadCertificate(CA_CERT0_STRING); - - private static final String CA_CERT1_STRING = "-----BEGIN CERTIFICATE-----\n" + - "MIIDKDCCAhCgAwIBAgIJAOM5SzKO2pzCMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + - "BAMTB0VBUCBDQTAwHhcNMTYwMTEyMDAxMDQ3WhcNMjYwMTA5MDAxMDQ3WjASMRAw\n" + - "DgYDVQQDEwdFQVAgQ0EwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + - "89ug+IEKVQXnJGKg5g4uVHg6J/8iRUxR5k2eH5o03hrJNMfN2D+cBe/wCiZcnWbI\n" + - "GbGZACWm2nQth2wy9Zgm2LOd3b4ocrHYls3XLq6Qb5Dd7a0JKU7pdGufiNVEkrmF\n" + - "EB+N64wgwH4COTvCiN4erp5kyJwkfqAl2xLkZo0C464c9XoyQOXbmYD9A8v10wZu\n" + - "jyNsEo7Nr2USyw+qhjWSbFbEirP77Tvx+7pJQJwdtk1V9Tn73T2dGF2WHYejei9S\n" + - "mcWpdIUqsu9etYH+zDmtu7I1xlkwiaVsNr2+D+qaCJyOYqrDTKVNK5nmbBPXDWZc\n" + - "NoDbTOoqquX7xONpq9M6jQIDAQABo4GAMH4wHQYDVR0OBBYEFAZ3A2S4qJZZwuNY\n" + - "wkJ6mAdc0gVdMEIGA1UdIwQ7MDmAFAZ3A2S4qJZZwuNYwkJ6mAdc0gVdoRakFDAS\n" + - "MRAwDgYDVQQDEwdFQVAgQ0EwggkA4zlLMo7anMIwDAYDVR0TBAUwAwEB/zALBgNV\n" + - "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAHmdMwEhtys4d0E+t7owBmoVR+lU\n" + - "hMCcRtWs8YKX5WIM2kTweT0h/O1xwE1mWmRv/IbDAEb8od4BjAQLhIcolStr2JaO\n" + - "9ZzyxjOnNzqeErh/1DHDbb/moPpqfeJ8YiEz7nH/YU56Q8iCPO7TsgS0sNNE7PfN\n" + - "IUsBW0yHRgpQ4OxWmiZG2YZWiECRzAC0ecPzo59N5iH4vLQIMTMYquiDeMPQnn1e\n" + - "NDGxG8gCtDKIaS6tMg3a28MvWB094pr2ETou8O1C8Ji0Y4hE8QJmSdT7I4+GZjgW\n" + - "g94DZ5RiL7sdp3vC48CXOmeT61YBIvhGUsE1rPhXqkpqQ3Z3C4TFF0jXZZc=\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CA_CERT1 = loadCertificate(CA_CERT1_STRING); - - private static final String CA_PUBLIC_CERT_STRING = "-----BEGIN CERTIFICATE-----\n" + - "MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkGA1UEBhMCQkUx\n" + - "GTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jvb3QgQ0ExGzAZBgNVBAMTEkds\n" + - "b2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAwMDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNV\n" + - "BAYTAkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMRAwDgYDVQQLEwdSb290IENBMRswGQYD\n" + - "VQQDExJHbG9iYWxTaWduIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDa\n" + - "DuaZjc6j40+Kfvvxi4Mla+pIH/EqsLmVEQS98GPR4mdmzxzdzxtIK+6NiY6arymAZavpxy0Sy6sc\n" + - "THAHoT0KMM0VjU/43dSMUBUc71DuxC73/OlS8pF94G3VNTCOXkNz8kHp1Wrjsok6Vjk4bwY8iGlb\n" + - "Kk3Fp1S4bInMm/k8yuX9ifUSPJJ4ltbcdG6TRGHRjcdGsnUOhugZitVtbNV4FpWi6cgKOOvyJBNP\n" + - "c1STE4U6G7weNLWLBYy5d4ux2x8gkasJU26Qzns3dLlwR5EiUWMWea6xrkEmCMgZK9FGqkjWZCrX\n" + - "gzT/LCrBbBlDSgeF59N89iFo7+ryUp9/k5DPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV\n" + - "HRMBAf8EBTADAQH/MB0GA1UdDgQWBBRge2YaRQ2XyolQL30EzTSo//z9SzANBgkqhkiG9w0BAQUF\n" + - "AAOCAQEA1nPnfE920I2/7LqivjTFKDK1fPxsnCwrvQmeU79rXqoRSLblCKOzyj1hTdNGCbM+w6Dj\n" + - "Y1Ub8rrvrTnhQ7k4o+YviiY776BQVvnGCv04zcQLcFGUl5gE38NflNUVyRRBnMRddWQVDf9VMOyG\n" + - "j/8N7yy5Y0b2qvzfvGn9LhJIZJrglfCm7ymPAbEVtQwdpf5pLGkkeB6zpxxxYu7KyJesF12KwvhH\n" + - "hm4qxFYxldBniYUr+WymXUadDKqC5JlR3XC321Y9YeRq4VzW9v493kHMB65jUr9TU/Qr6cf9tveC\n" + - "X4XSQRjbgbMEHMUfpIBvFSDJ3gyICh3WZlXi/EjJKSZp4A==\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CA_PUBLIC_CERT = loadCertificate(CA_PUBLIC_CERT_STRING); - - private static final String CLIENT_CERT_STR = "-----BEGIN CERTIFICATE-----\n" + - "MIIE/DCCAuQCAQEwDQYJKoZIhvcNAQELBQAwRDELMAkGA1UEBhMCVVMxCzAJBgNV\n" + - "BAgMAkNBMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRAwDgYDVQQKDAdUZXN0aW5n\n" + - "MB4XDTE2MDkzMDIwNTQyOFoXDTE3MDkzMDIwNTQyOFowRDELMAkGA1UEBhMCVVMx\n" + - "CzAJBgNVBAgMAkNBMRYwFAYDVQQHDA1Nb3VudGFpbiBWaWV3MRAwDgYDVQQKDAdU\n" + - "ZXN0aW5nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnpmcbuaeHfnJ\n" + - "k+2QNvxmdVFTawyFMNk0USCq5sexscwmxbewG/Rb8YnixwJWS44v2XkSujB67z5C\n" + - "s2qudFEhRXKdEuC6idbAuA97KjipHh0AAniWMsyv61fvbgsUC0b0canx3LiDq81p\n" + - "y28NNGmAvoazLZUZ4AhBRiwYZY6FKk723gmZoGbEIeG7J1dlXPusc1662rIjz4eU\n" + - "zlmmlvqyHfNqnNk8L14Vug6Xh+lOEGN85xhu1YHAEKGrS89kZxs5rum/cZU8KH2V\n" + - "v6eKnY03kxjiVLQtnLpm/7VUEoCMGHyruRj+p3my4+DgqMsmsH52RZCBsjyGlpbU\n" + - "NOwOTIX6xh+Rqloduz4AnrMYYIiIw2s8g+2zJM7VbcVKx0fGS26BKdrxgrXWfmNE\n" + - "nR0/REQ5AxDGw0jfTUvtdTkXAf+K4MDjcNLEZ+MA4rHfAfQWZtUR5BkHCQYxNpJk\n" + - "pA0gyk+BpKdC4WdzI14NSWsu5sRCmBCFqH6BTOSEq/V1cNorBxNwLSSTwFFqUDqx\n" + - "Y5nQLXygkJf9WHZWtSKeSjtOYgilz7UKzC2s3CsjmIyGFe+SwpuHJnuE4Uc8Z5Cb\n" + - "bjNGHPzqL6XnmzZHJp7RF8kBdKdjGC7dCUltzOfICZeKlzOOq+Kw42T/nXjuXvpb\n" + - "nkXNxg741Nwd6RecykXJbseFwm3EYxkCAwEAATANBgkqhkiG9w0BAQsFAAOCAgEA\n" + - "Ga1mGwI9aXkL2fTPXO9YkAPzoGeX8aeuVYSQaSkNq+5vnogYCyAt3YDHjRG+ewTT\n" + - "WbnPA991xRAPac+biJeXWmwvgGj0YuT7e79phAiGkTTnbAjFHGfYnBy/tI/v7btO\n" + - "hRNElA5yTJ1m2fVbBEKXzMR83jrT9iyI+YLRN86zUZIaC86xxSbqnrdWN2jOK6MX\n" + - "dS8Arp9tPQjC/4gW+2Ilxv68jiYh+5auWHQZVjppWVY//iu4mAbkq1pTwQEhZ8F8\n" + - "Zrmh9DHh60hLFcfSuhIAwf/NMzppwdkjy1ruKVrpijhGKGp4OWu8nvOUgHSzxc7F\n" + - "PwpVZ5N2Ku4L8MLO6BG2VasRJK7l17TzDXlfLZHJjkuryOFxVaQKt8ZNFgTOaCXS\n" + - "E+gpTLksKU7riYckoiP4+H1sn9qcis0e8s4o/uf1UVc8GSdDw61ReGM5oZEDm1u8\n" + - "H9x20QU6igLqzyBpqvCKv7JNgU1uB2PAODHH78zJiUfnKd1y+o+J1iWzaGj3EFji\n" + - "T8AXksbTP733FeFXfggXju2dyBH+Z1S5BBTEOd1brWgXlHSAZGm97MKZ94r6/tkX\n" + - "qfv3fCos0DKz0oV7qBxYS8wiYhzrRVxG6ITAoH8uuUVVQaZF+G4nJ2jEqNbfuKyX\n" + - "ATQsVNjNNlDA0J33GobPMjT326wa4YAWMx8PI5PJZ3g=\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CLIENT_CERT = loadCertificate(CLIENT_CERT_STR); - - private static final byte[] FAKE_RSA_KEY_1 = new byte[] { - (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x78, (byte) 0x02, (byte) 0x01, - (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x82, - (byte) 0x02, (byte) 0x62, (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x5e, - (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, - (byte) 0x00, (byte) 0xce, (byte) 0x29, (byte) 0xeb, (byte) 0xf6, (byte) 0x5b, - (byte) 0x25, (byte) 0xdc, (byte) 0xa1, (byte) 0xa6, (byte) 0x2c, (byte) 0x66, - (byte) 0xcb, (byte) 0x20, (byte) 0x90, (byte) 0x27, (byte) 0x86, (byte) 0x8a, - (byte) 0x44, (byte) 0x71, (byte) 0x50, (byte) 0xda, (byte) 0xd3, (byte) 0x02, - (byte) 0x77, (byte) 0x55, (byte) 0xe9, (byte) 0xe8, (byte) 0x08, (byte) 0xf3, - (byte) 0x36, (byte) 0x9a, (byte) 0xae, (byte) 0xab, (byte) 0x04, (byte) 0x6d, - (byte) 0x00, (byte) 0x99, (byte) 0xbf, (byte) 0x7d, (byte) 0x0f, (byte) 0x67, - (byte) 0x8b, (byte) 0x1d, (byte) 0xd4, (byte) 0x2b, (byte) 0x7c, (byte) 0xcb, - (byte) 0xcd, (byte) 0x33, (byte) 0xc7, (byte) 0x84, (byte) 0x30, (byte) 0xe2, - (byte) 0x45, (byte) 0x21, (byte) 0xb3, (byte) 0x75, (byte) 0xf5, (byte) 0x79, - (byte) 0x02, (byte) 0xda, (byte) 0x50, (byte) 0xa3, (byte) 0x8b, (byte) 0xce, - (byte) 0xc3, (byte) 0x8e, (byte) 0x0f, (byte) 0x25, (byte) 0xeb, (byte) 0x08, - (byte) 0x2c, (byte) 0xdd, (byte) 0x1c, (byte) 0xcf, (byte) 0xff, (byte) 0x3b, - (byte) 0xde, (byte) 0xb6, (byte) 0xaa, (byte) 0x2a, (byte) 0xa9, (byte) 0xc4, - (byte) 0x8a, (byte) 0x24, (byte) 0x24, (byte) 0xe6, (byte) 0x29, (byte) 0x0d, - (byte) 0x98, (byte) 0x4c, (byte) 0x32, (byte) 0xa1, (byte) 0x7b, (byte) 0x23, - (byte) 0x2b, (byte) 0x42, (byte) 0x30, (byte) 0xee, (byte) 0x78, (byte) 0x08, - (byte) 0x47, (byte) 0xad, (byte) 0xf2, (byte) 0x96, (byte) 0xd5, (byte) 0xf1, - (byte) 0x62, (byte) 0x42, (byte) 0x2d, (byte) 0x35, (byte) 0x19, (byte) 0xb4, - (byte) 0x3c, (byte) 0xc9, (byte) 0xc3, (byte) 0x5f, (byte) 0x03, (byte) 0x16, - (byte) 0x3a, (byte) 0x23, (byte) 0xac, (byte) 0xcb, (byte) 0xce, (byte) 0x9e, - (byte) 0x51, (byte) 0x2e, (byte) 0x6d, (byte) 0x02, (byte) 0x03, (byte) 0x01, - (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x16, - (byte) 0x59, (byte) 0xc3, (byte) 0x24, (byte) 0x1d, (byte) 0x33, (byte) 0x98, - (byte) 0x9c, (byte) 0xc9, (byte) 0xc8, (byte) 0x2c, (byte) 0x88, (byte) 0xbf, - (byte) 0x0a, (byte) 0x01, (byte) 0xce, (byte) 0xfb, (byte) 0x34, (byte) 0x7a, - (byte) 0x58, (byte) 0x7a, (byte) 0xb0, (byte) 0xbf, (byte) 0xa6, (byte) 0xb2, - (byte) 0x60, (byte) 0xbe, (byte) 0x70, (byte) 0x21, (byte) 0xf5, (byte) 0xfc, - (byte) 0x85, (byte) 0x0d, (byte) 0x33, (byte) 0x58, (byte) 0xa1, (byte) 0xe5, - (byte) 0x09, (byte) 0x36, (byte) 0x84, (byte) 0xb2, (byte) 0x04, (byte) 0x0a, - (byte) 0x02, (byte) 0xd3, (byte) 0x88, (byte) 0x1f, (byte) 0x0c, (byte) 0x2b, - (byte) 0x1d, (byte) 0xe9, (byte) 0x3d, (byte) 0xe7, (byte) 0x79, (byte) 0xf9, - (byte) 0x32, (byte) 0x5c, (byte) 0x8a, (byte) 0x75, (byte) 0x49, (byte) 0x12, - (byte) 0xe4, (byte) 0x05, (byte) 0x26, (byte) 0xd4, (byte) 0x2e, (byte) 0x9e, - (byte) 0x1f, (byte) 0xcc, (byte) 0x54, (byte) 0xad, (byte) 0x33, (byte) 0x8d, - (byte) 0x99, (byte) 0x00, (byte) 0xdc, (byte) 0xf5, (byte) 0xb4, (byte) 0xa2, - (byte) 0x2f, (byte) 0xba, (byte) 0xe5, (byte) 0x62, (byte) 0x30, (byte) 0x6d, - (byte) 0xe6, (byte) 0x3d, (byte) 0xeb, (byte) 0x24, (byte) 0xc2, (byte) 0xdc, - (byte) 0x5f, (byte) 0xb7, (byte) 0x16, (byte) 0x35, (byte) 0xa3, (byte) 0x98, - (byte) 0x98, (byte) 0xa8, (byte) 0xef, (byte) 0xe8, (byte) 0xc4, (byte) 0x96, - (byte) 0x6d, (byte) 0x38, (byte) 0xab, (byte) 0x26, (byte) 0x6d, (byte) 0x30, - (byte) 0xc2, (byte) 0xa0, (byte) 0x44, (byte) 0xe4, (byte) 0xff, (byte) 0x7e, - (byte) 0xbe, (byte) 0x7c, (byte) 0x33, (byte) 0xa5, (byte) 0x10, (byte) 0xad, - (byte) 0xd7, (byte) 0x1e, (byte) 0x13, (byte) 0x20, (byte) 0xb3, (byte) 0x1f, - (byte) 0x41, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xf1, (byte) 0x89, - (byte) 0x07, (byte) 0x0f, (byte) 0xe8, (byte) 0xcf, (byte) 0xab, (byte) 0x13, - (byte) 0x2a, (byte) 0x8f, (byte) 0x88, (byte) 0x80, (byte) 0x11, (byte) 0x9a, - (byte) 0x79, (byte) 0xb6, (byte) 0x59, (byte) 0x3a, (byte) 0x50, (byte) 0x6e, - (byte) 0x57, (byte) 0x37, (byte) 0xab, (byte) 0x2a, (byte) 0xd2, (byte) 0xaa, - (byte) 0xd9, (byte) 0x72, (byte) 0x73, (byte) 0xff, (byte) 0x8b, (byte) 0x47, - (byte) 0x76, (byte) 0xdd, (byte) 0xdc, (byte) 0xf5, (byte) 0x97, (byte) 0x44, - (byte) 0x3a, (byte) 0x78, (byte) 0xbe, (byte) 0x17, (byte) 0xb4, (byte) 0x22, - (byte) 0x6f, (byte) 0xe5, (byte) 0x23, (byte) 0x70, (byte) 0x1d, (byte) 0x10, - (byte) 0x5d, (byte) 0xba, (byte) 0x16, (byte) 0x81, (byte) 0xf1, (byte) 0x45, - (byte) 0xce, (byte) 0x30, (byte) 0xb4, (byte) 0xab, (byte) 0x80, (byte) 0xe4, - (byte) 0x98, (byte) 0x31, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xda, - (byte) 0x82, (byte) 0x9d, (byte) 0x3f, (byte) 0xca, (byte) 0x2f, (byte) 0xe1, - (byte) 0xd4, (byte) 0x86, (byte) 0x77, (byte) 0x48, (byte) 0xa6, (byte) 0xab, - (byte) 0xab, (byte) 0x1c, (byte) 0x42, (byte) 0x5c, (byte) 0xd5, (byte) 0xc7, - (byte) 0x46, (byte) 0x59, (byte) 0x91, (byte) 0x3f, (byte) 0xfc, (byte) 0xcc, - (byte) 0xec, (byte) 0xc2, (byte) 0x40, (byte) 0x12, (byte) 0x2c, (byte) 0x8d, - (byte) 0x1f, (byte) 0xa2, (byte) 0x18, (byte) 0x88, (byte) 0xee, (byte) 0x82, - (byte) 0x4a, (byte) 0x5a, (byte) 0x5e, (byte) 0x88, (byte) 0x20, (byte) 0xe3, - (byte) 0x7b, (byte) 0xe0, (byte) 0xd8, (byte) 0x3a, (byte) 0x52, (byte) 0x9a, - (byte) 0x26, (byte) 0x6a, (byte) 0x04, (byte) 0xec, (byte) 0xe8, (byte) 0xb9, - (byte) 0x48, (byte) 0x40, (byte) 0xe1, (byte) 0xe1, (byte) 0x83, (byte) 0xa6, - (byte) 0x67, (byte) 0xa6, (byte) 0xfd, (byte) 0x02, (byte) 0x41, (byte) 0x00, - (byte) 0x89, (byte) 0x72, (byte) 0x3e, (byte) 0xb0, (byte) 0x90, (byte) 0xfd, - (byte) 0x4c, (byte) 0x0e, (byte) 0xd6, (byte) 0x13, (byte) 0x63, (byte) 0xcb, - (byte) 0xed, (byte) 0x38, (byte) 0x88, (byte) 0xb6, (byte) 0x79, (byte) 0xc4, - (byte) 0x33, (byte) 0x6c, (byte) 0xf6, (byte) 0xf8, (byte) 0xd8, (byte) 0xd0, - (byte) 0xbf, (byte) 0x9d, (byte) 0x35, (byte) 0xac, (byte) 0x69, (byte) 0xd2, - (byte) 0x2b, (byte) 0xc1, (byte) 0xf9, (byte) 0x24, (byte) 0x7b, (byte) 0xce, - (byte) 0xcd, (byte) 0xcb, (byte) 0xa7, (byte) 0xb2, (byte) 0x7a, (byte) 0x0a, - (byte) 0x27, (byte) 0x19, (byte) 0xc9, (byte) 0xaf, (byte) 0x0d, (byte) 0x21, - (byte) 0x89, (byte) 0x88, (byte) 0x7c, (byte) 0xad, (byte) 0x9e, (byte) 0x8d, - (byte) 0x47, (byte) 0x6d, (byte) 0x3f, (byte) 0xce, (byte) 0x7b, (byte) 0xa1, - (byte) 0x74, (byte) 0xf1, (byte) 0xa0, (byte) 0xa1, (byte) 0x02, (byte) 0x41, - (byte) 0x00, (byte) 0xd9, (byte) 0xa8, (byte) 0xf5, (byte) 0xfe, (byte) 0xce, - (byte) 0xe6, (byte) 0x77, (byte) 0x6b, (byte) 0xfe, (byte) 0x2d, (byte) 0xe0, - (byte) 0x1e, (byte) 0xb6, (byte) 0x2e, (byte) 0x12, (byte) 0x4e, (byte) 0x40, - (byte) 0xaf, (byte) 0x6a, (byte) 0x7b, (byte) 0x37, (byte) 0x49, (byte) 0x2a, - (byte) 0x96, (byte) 0x25, (byte) 0x83, (byte) 0x49, (byte) 0xd4, (byte) 0x0c, - (byte) 0xc6, (byte) 0x78, (byte) 0x25, (byte) 0x24, (byte) 0x90, (byte) 0x90, - (byte) 0x06, (byte) 0x15, (byte) 0x9e, (byte) 0xfe, (byte) 0xf9, (byte) 0xdf, - (byte) 0x5b, (byte) 0xf3, (byte) 0x7e, (byte) 0x38, (byte) 0x70, (byte) 0xeb, - (byte) 0x57, (byte) 0xd0, (byte) 0xd9, (byte) 0xa7, (byte) 0x0e, (byte) 0x14, - (byte) 0xf7, (byte) 0x95, (byte) 0x68, (byte) 0xd5, (byte) 0xc8, (byte) 0xab, - (byte) 0x9d, (byte) 0x3a, (byte) 0x2b, (byte) 0x51, (byte) 0xf9, (byte) 0x02, - (byte) 0x41, (byte) 0x00, (byte) 0x96, (byte) 0xdf, (byte) 0xe9, (byte) 0x67, - (byte) 0x6c, (byte) 0xdc, (byte) 0x90, (byte) 0x14, (byte) 0xb4, (byte) 0x1d, - (byte) 0x22, (byte) 0x33, (byte) 0x4a, (byte) 0x31, (byte) 0xc1, (byte) 0x9d, - (byte) 0x2e, (byte) 0xff, (byte) 0x9a, (byte) 0x2a, (byte) 0x95, (byte) 0x4b, - (byte) 0x27, (byte) 0x74, (byte) 0xcb, (byte) 0x21, (byte) 0xc3, (byte) 0xd2, - (byte) 0x0b, (byte) 0xb2, (byte) 0x46, (byte) 0x87, (byte) 0xf8, (byte) 0x28, - (byte) 0x01, (byte) 0x8b, (byte) 0xd8, (byte) 0xb9, (byte) 0x4b, (byte) 0xcd, - (byte) 0x9a, (byte) 0x96, (byte) 0x41, (byte) 0x0e, (byte) 0x36, (byte) 0x6d, - (byte) 0x40, (byte) 0x42, (byte) 0xbc, (byte) 0xd9, (byte) 0xd3, (byte) 0x7b, - (byte) 0xbc, (byte) 0xa7, (byte) 0x92, (byte) 0x90, (byte) 0xdd, (byte) 0xa1, - (byte) 0x9c, (byte) 0xce, (byte) 0xa1, (byte) 0x87, (byte) 0x11, (byte) 0x51 - }; - public static final PrivateKey RSA_KEY1 = loadPrivateRSAKey(FAKE_RSA_KEY_1); - - private static X509Certificate loadCertificate(String blob) { - try { - final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - InputStream stream = new ByteArrayInputStream(blob.getBytes(StandardCharsets.UTF_8)); - - return (X509Certificate) certFactory.generateCertificate(stream); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - private static PrivateKey loadPrivateRSAKey(byte[] fakeKey) { - try { - KeyFactory kf = KeyFactory.getInstance("RSA"); - return kf.generatePrivate(new PKCS8EncodedKeySpec(fakeKey)); - } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { - return null; - } - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/MulticastLockTest.java b/tests/cts/net/src/android/net/wifi/cts/MulticastLockTest.java deleted file mode 100644 index 71f04a33c1..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/MulticastLockTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.content.Context; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.MulticastLock; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class MulticastLockTest extends AndroidTestCase { - - private static final String WIFI_TAG = "MulticastLockTest"; - - /** - * Verify acquire and release of Multicast locks - */ - public void testMulticastLock() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - WifiManager wm = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - MulticastLock mcl = wm.createMulticastLock(WIFI_TAG); - - mcl.setReferenceCounted(true); - assertFalse(mcl.isHeld()); - mcl.acquire(); - assertTrue(mcl.isHeld()); - mcl.release(); - assertFalse(mcl.isHeld()); - mcl.acquire(); - mcl.acquire(); - assertTrue(mcl.isHeld()); - mcl.release(); - assertTrue(mcl.isHeld()); - mcl.release(); - assertFalse(mcl.isHeld()); - assertNotNull(mcl.toString()); - try { - mcl.release(); - fail("should throw out exception because release is called" - +" a greater number of times than acquire"); - } catch (RuntimeException e) { - // expected - } - - mcl = wm.createMulticastLock(WIFI_TAG); - mcl.setReferenceCounted(false); - assertFalse(mcl.isHeld()); - mcl.acquire(); - assertTrue(mcl.isHeld()); - mcl.release(); - assertFalse(mcl.isHeld()); - mcl.acquire(); - mcl.acquire(); - assertTrue(mcl.isHeld()); - mcl.release(); - assertFalse(mcl.isHeld()); - assertNotNull(mcl.toString()); - // releasing again after release: but ignored for non-referenced locks - mcl.release(); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java deleted file mode 100644 index f2a2b48267..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/NsdManagerTest.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.content.Context; -import android.net.nsd.NsdManager; -import android.net.nsd.NsdServiceInfo; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; -import android.util.Log; - -import java.io.IOException; -import java.net.ServerSocket; -import java.util.Arrays; -import java.util.Random; -import java.util.List; -import java.util.ArrayList; - -@AppModeFull(reason = "Socket cannot bind in instant app mode") -public class NsdManagerTest extends AndroidTestCase { - - private static final String TAG = "NsdManagerTest"; - private static final String SERVICE_TYPE = "_nmt._tcp"; - private static final int TIMEOUT = 2000; - - private static final boolean DBG = false; - - NsdManager mNsdManager; - - NsdManager.RegistrationListener mRegistrationListener; - NsdManager.DiscoveryListener mDiscoveryListener; - NsdManager.ResolveListener mResolveListener; - private NsdServiceInfo mResolvedService; - - public NsdManagerTest() { - initRegistrationListener(); - initDiscoveryListener(); - initResolveListener(); - } - - private void initRegistrationListener() { - mRegistrationListener = new NsdManager.RegistrationListener() { - @Override - public void onRegistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { - setEvent("onRegistrationFailed", errorCode); - } - - @Override - public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { - setEvent("onUnregistrationFailed", errorCode); - } - - @Override - public void onServiceRegistered(NsdServiceInfo serviceInfo) { - setEvent("onServiceRegistered", serviceInfo); - } - - @Override - public void onServiceUnregistered(NsdServiceInfo serviceInfo) { - setEvent("onServiceUnregistered", serviceInfo); - } - }; - } - - private void initDiscoveryListener() { - mDiscoveryListener = new NsdManager.DiscoveryListener() { - @Override - public void onStartDiscoveryFailed(String serviceType, int errorCode) { - setEvent("onStartDiscoveryFailed", errorCode); - } - - @Override - public void onStopDiscoveryFailed(String serviceType, int errorCode) { - setEvent("onStopDiscoveryFailed", errorCode); - } - - @Override - public void onDiscoveryStarted(String serviceType) { - NsdServiceInfo info = new NsdServiceInfo(); - info.setServiceType(serviceType); - setEvent("onDiscoveryStarted", info); - } - - @Override - public void onDiscoveryStopped(String serviceType) { - NsdServiceInfo info = new NsdServiceInfo(); - info.setServiceType(serviceType); - setEvent("onDiscoveryStopped", info); - } - - @Override - public void onServiceFound(NsdServiceInfo serviceInfo) { - setEvent("onServiceFound", serviceInfo); - } - - @Override - public void onServiceLost(NsdServiceInfo serviceInfo) { - setEvent("onServiceLost", serviceInfo); - } - }; - } - - private void initResolveListener() { - mResolveListener = new NsdManager.ResolveListener() { - @Override - public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) { - setEvent("onResolveFailed", errorCode); - } - - @Override - public void onServiceResolved(NsdServiceInfo serviceInfo) { - mResolvedService = serviceInfo; - setEvent("onServiceResolved", serviceInfo); - } - }; - } - - - - private final class EventData { - EventData(String callbackName, NsdServiceInfo info) { - mCallbackName = callbackName; - mSucceeded = true; - mErrorCode = 0; - mInfo = info; - } - EventData(String callbackName, int errorCode) { - mCallbackName = callbackName; - mSucceeded = false; - mErrorCode = errorCode; - mInfo = null; - } - private final String mCallbackName; - private final boolean mSucceeded; - private final int mErrorCode; - private final NsdServiceInfo mInfo; - } - - private final List mEventCache = new ArrayList(); - - private void setEvent(String callbackName, int errorCode) { - if (DBG) Log.d(TAG, callbackName + " failed with " + String.valueOf(errorCode)); - EventData eventData = new EventData(callbackName, errorCode); - synchronized (mEventCache) { - mEventCache.add(eventData); - mEventCache.notify(); - } - } - - private void setEvent(String callbackName, NsdServiceInfo info) { - if (DBG) Log.d(TAG, "Received event " + callbackName + " for " + info.getServiceName()); - EventData eventData = new EventData(callbackName, info); - synchronized (mEventCache) { - mEventCache.add(eventData); - mEventCache.notify(); - } - } - - void clearEventCache() { - synchronized(mEventCache) { - mEventCache.clear(); - } - } - - int eventCacheSize() { - synchronized(mEventCache) { - return mEventCache.size(); - } - } - - private int mWaitId = 0; - private EventData waitForCallback(String callbackName) { - - synchronized(mEventCache) { - - mWaitId ++; - if (DBG) Log.d(TAG, "Waiting for " + callbackName + ", id=" + String.valueOf(mWaitId)); - - try { - long startTime = android.os.SystemClock.uptimeMillis(); - long elapsedTime = 0; - int index = 0; - while (elapsedTime < TIMEOUT ) { - // first check if we've received that event - for (; index < mEventCache.size(); index++) { - EventData e = mEventCache.get(index); - if (e.mCallbackName.equals(callbackName)) { - if (DBG) Log.d(TAG, "exiting wait id=" + String.valueOf(mWaitId)); - return e; - } - } - - // Not yet received, just wait - mEventCache.wait(TIMEOUT - elapsedTime); - elapsedTime = android.os.SystemClock.uptimeMillis() - startTime; - } - // we exited the loop because of TIMEOUT; fail the call - if (DBG) Log.d(TAG, "timed out waiting id=" + String.valueOf(mWaitId)); - return null; - } catch (InterruptedException e) { - return null; // wait timed out! - } - } - } - - private EventData waitForNewEvents() throws InterruptedException { - if (DBG) Log.d(TAG, "Waiting for a bit, id=" + String.valueOf(mWaitId)); - - long startTime = android.os.SystemClock.uptimeMillis(); - long elapsedTime = 0; - synchronized (mEventCache) { - int index = mEventCache.size(); - while (elapsedTime < TIMEOUT ) { - // first check if we've received that event - for (; index < mEventCache.size(); index++) { - EventData e = mEventCache.get(index); - return e; - } - - // Not yet received, just wait - mEventCache.wait(TIMEOUT - elapsedTime); - elapsedTime = android.os.SystemClock.uptimeMillis() - startTime; - } - } - - return null; - } - - private String mServiceName; - - @Override - public void setUp() { - if (DBG) Log.d(TAG, "Setup test ..."); - mNsdManager = (NsdManager) getContext().getSystemService(Context.NSD_SERVICE); - - Random rand = new Random(); - mServiceName = new String("NsdTest"); - for (int i = 0; i < 4; i++) { - mServiceName = mServiceName + String.valueOf(rand.nextInt(10)); - } - } - - @Override - public void tearDown() { - if (DBG) Log.d(TAG, "Tear down test ..."); - } - - public void testNDSManager() throws Exception { - EventData lastEvent = null; - - if (DBG) Log.d(TAG, "Starting test ..."); - - NsdServiceInfo si = new NsdServiceInfo(); - si.setServiceType(SERVICE_TYPE); - si.setServiceName(mServiceName); - - byte testByteArray[] = new byte[] {-128, 127, 2, 1, 0, 1, 2}; - String String256 = "1_________2_________3_________4_________5_________6_________" + - "7_________8_________9_________10________11________12________13________" + - "14________15________16________17________18________19________20________" + - "21________22________23________24________25________123456"; - - // Illegal attributes - try { - si.setAttribute(null, (String) null); - fail("Could set null key"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute("", (String) null); - fail("Could set empty key"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute(String256, (String) null); - fail("Could set key with 255 characters"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute("key", String256.substring(3)); - fail("Could set key+value combination with more than 255 characters"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute("key", String256.substring(4)); - fail("Could set key+value combination with 255 characters"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute(new String(new byte[]{0x19}), (String) null); - fail("Could set key with invalid character"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute("=", (String) null); - fail("Could set key with invalid character"); - } catch (IllegalArgumentException e) { - // expected - } - - try { - si.setAttribute(new String(new byte[]{0x7F}), (String) null); - fail("Could set key with invalid character"); - } catch (IllegalArgumentException e) { - // expected - } - - // Allowed attributes - si.setAttribute("booleanAttr", (String) null); - si.setAttribute("keyValueAttr", "value"); - si.setAttribute("keyEqualsAttr", "="); - si.setAttribute(" whiteSpaceKeyValueAttr ", " value "); - si.setAttribute("binaryDataAttr", testByteArray); - si.setAttribute("nullBinaryDataAttr", (byte[]) null); - si.setAttribute("emptyBinaryDataAttr", new byte[]{}); - si.setAttribute("longkey", String256.substring(9)); - - ServerSocket socket; - int localPort; - - try { - socket = new ServerSocket(0); - localPort = socket.getLocalPort(); - si.setPort(localPort); - } catch (IOException e) { - if (DBG) Log.d(TAG, "Could not open a local socket"); - assertTrue(false); - return; - } - - if (DBG) Log.d(TAG, "Port = " + String.valueOf(localPort)); - - clearEventCache(); - - mNsdManager.registerService(si, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener); - lastEvent = waitForCallback("onServiceRegistered"); // id = 1 - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - assertTrue(eventCacheSize() == 1); - - // We may not always get the name that we tried to register; - // This events tells us the name that was registered. - String registeredName = lastEvent.mInfo.getServiceName(); - si.setServiceName(registeredName); - - clearEventCache(); - - mNsdManager.discoverServices(SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, - mDiscoveryListener); - - // Expect discovery started - lastEvent = waitForCallback("onDiscoveryStarted"); // id = 2 - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - - // Remove this event, so accounting becomes easier later - synchronized (mEventCache) { - mEventCache.remove(lastEvent); - } - - // Expect a service record to be discovered (and filter the ones - // that are unrelated to this test) - boolean found = false; - for (int i = 0; i < 32; i++) { - - lastEvent = waitForCallback("onServiceFound"); // id = 3 - if (lastEvent == null) { - // no more onServiceFound events are being reported! - break; - } - - assertTrue(lastEvent.mSucceeded); - - if (DBG) Log.d(TAG, "id = " + String.valueOf(mWaitId) + ": ServiceName = " + - lastEvent.mInfo.getServiceName()); - - if (lastEvent.mInfo.getServiceName().equals(registeredName)) { - // Save it, as it will get overwritten with new serviceFound events - si = lastEvent.mInfo; - found = true; - } - - // Remove this event from the event cache, so it won't be found by subsequent - // calls to waitForCallback - synchronized (mEventCache) { - mEventCache.remove(lastEvent); - } - } - - assertTrue(found); - - // We've removed all serviceFound events, and we've removed the discoveryStarted - // event as well, so now the event cache should be empty! - assertTrue(eventCacheSize() == 0); - - // Resolve the service - clearEventCache(); - mNsdManager.resolveService(si, mResolveListener); - lastEvent = waitForCallback("onServiceResolved"); // id = 4 - - assertNotNull(mResolvedService); - - // Check Txt attributes - assertEquals(8, mResolvedService.getAttributes().size()); - assertTrue(mResolvedService.getAttributes().containsKey("booleanAttr")); - assertNull(mResolvedService.getAttributes().get("booleanAttr")); - assertEquals("value", new String(mResolvedService.getAttributes().get("keyValueAttr"))); - assertEquals("=", new String(mResolvedService.getAttributes().get("keyEqualsAttr"))); - assertEquals(" value ", new String(mResolvedService.getAttributes() - .get(" whiteSpaceKeyValueAttr "))); - assertEquals(String256.substring(9), new String(mResolvedService.getAttributes() - .get("longkey"))); - assertTrue(Arrays.equals(testByteArray, - mResolvedService.getAttributes().get("binaryDataAttr"))); - assertTrue(mResolvedService.getAttributes().containsKey("nullBinaryDataAttr")); - assertNull(mResolvedService.getAttributes().get("nullBinaryDataAttr")); - assertTrue(mResolvedService.getAttributes().containsKey("emptyBinaryDataAttr")); - assertNull(mResolvedService.getAttributes().get("emptyBinaryDataAttr")); - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - - if (DBG) Log.d(TAG, "id = " + String.valueOf(mWaitId) + ": Port = " + - String.valueOf(lastEvent.mInfo.getPort())); - - assertTrue(lastEvent.mInfo.getPort() == localPort); - assertTrue(eventCacheSize() == 1); - - checkForAdditionalEvents(); - clearEventCache(); - - // Unregister the service - mNsdManager.unregisterService(mRegistrationListener); - lastEvent = waitForCallback("onServiceUnregistered"); // id = 5 - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - - // Expect a callback for service lost - lastEvent = waitForCallback("onServiceLost"); // id = 6 - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName)); - - // Register service again to see if we discover it - checkForAdditionalEvents(); - clearEventCache(); - - si = new NsdServiceInfo(); - si.setServiceType(SERVICE_TYPE); - si.setServiceName(mServiceName); - si.setPort(localPort); - - // Create a new registration listener and register same service again - initRegistrationListener(); - - mNsdManager.registerService(si, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener); - - lastEvent = waitForCallback("onServiceRegistered"); // id = 7 - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - - registeredName = lastEvent.mInfo.getServiceName(); - - // Expect a record to be discovered - // Expect a service record to be discovered (and filter the ones - // that are unrelated to this test) - found = false; - for (int i = 0; i < 32; i++) { - - lastEvent = waitForCallback("onServiceFound"); // id = 8 - if (lastEvent == null) { - // no more onServiceFound events are being reported! - break; - } - - assertTrue(lastEvent.mSucceeded); - - if (DBG) Log.d(TAG, "id = " + String.valueOf(mWaitId) + ": ServiceName = " + - lastEvent.mInfo.getServiceName()); - - if (lastEvent.mInfo.getServiceName().equals(registeredName)) { - // Save it, as it will get overwritten with new serviceFound events - si = lastEvent.mInfo; - found = true; - } - - // Remove this event from the event cache, so it won't be found by subsequent - // calls to waitForCallback - synchronized (mEventCache) { - mEventCache.remove(lastEvent); - } - } - - assertTrue(found); - - // Resolve the service - clearEventCache(); - mNsdManager.resolveService(si, mResolveListener); - lastEvent = waitForCallback("onServiceResolved"); // id = 9 - - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - - if (DBG) Log.d(TAG, "id = " + String.valueOf(mWaitId) + ": ServiceName = " + - lastEvent.mInfo.getServiceName()); - - assertTrue(lastEvent.mInfo.getServiceName().equals(registeredName)); - - assertNotNull(mResolvedService); - - // Check that we don't have any TXT records - assertEquals(0, mResolvedService.getAttributes().size()); - - checkForAdditionalEvents(); - clearEventCache(); - - mNsdManager.stopServiceDiscovery(mDiscoveryListener); - lastEvent = waitForCallback("onDiscoveryStopped"); // id = 10 - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - assertTrue(checkCacheSize(1)); - - checkForAdditionalEvents(); - clearEventCache(); - - mNsdManager.unregisterService(mRegistrationListener); - - lastEvent = waitForCallback("onServiceUnregistered"); // id = 11 - assertTrue(lastEvent != null); - assertTrue(lastEvent.mSucceeded); - assertTrue(checkCacheSize(1)); - } - - boolean checkCacheSize(int size) { - synchronized (mEventCache) { - int cacheSize = mEventCache.size(); - if (cacheSize != size) { - Log.d(TAG, "id = " + mWaitId + ": event cache size = " + cacheSize); - for (int i = 0; i < cacheSize; i++) { - EventData e = mEventCache.get(i); - String sname = (e.mInfo != null) ? "(" + e.mInfo.getServiceName() + ")" : ""; - Log.d(TAG, "eventName is " + e.mCallbackName + sname); - } - } - return (cacheSize == size); - } - } - - boolean checkForAdditionalEvents() { - try { - EventData e = waitForNewEvents(); - if (e != null) { - String sname = (e.mInfo != null) ? "(" + e.mInfo.getServiceName() + ")" : ""; - Log.d(TAG, "ignoring unexpected event " + e.mCallbackName + sname); - } - return (e == null); - } - catch (InterruptedException ex) { - return false; - } - } -} - diff --git a/tests/cts/net/src/android/net/wifi/cts/PpsMoParserTest.java b/tests/cts/net/src/android/net/wifi/cts/PpsMoParserTest.java deleted file mode 100644 index feafd434a7..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/PpsMoParserTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.net.wifi.hotspot2.PasspointConfiguration; -import android.net.wifi.hotspot2.omadm.PpsMoParser; -import android.net.wifi.hotspot2.pps.Credential; -import android.net.wifi.hotspot2.pps.HomeSp; -import android.test.AndroidTestCase; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * CTS tests for PPS MO (PerProviderSubscription Management Object) XML string parsing API. - */ -public class PpsMoParserTest extends AndroidTestCase { - private static final String PPS_MO_XML_FILE = "assets/PerProviderSubscription.xml"; - - /** - * Read the content of the given resource file into a String. - * - * @param filename String name of the file - * @return String - * @throws IOException - */ - private String loadResourceFile(String filename) throws IOException { - InputStream in = getClass().getClassLoader().getResourceAsStream(filename); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - StringBuilder builder = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - builder.append(line).append("\n"); - } - return builder.toString(); - } - - /** - * Generate a {@link PasspointConfiguration} that matches the configuration specified in the - * XML file {@link #PPS_MO_XML_FILE}. - * - * @return {@link PasspointConfiguration} - */ - private PasspointConfiguration generateConfigurationFromPPSMOTree() throws Exception { - DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - byte[] certFingerprint = new byte[32]; - Arrays.fill(certFingerprint, (byte) 0x1f); - - PasspointConfiguration config = new PasspointConfiguration(); - - // HomeSP configuration. - HomeSp homeSp = new HomeSp(); - homeSp.setFriendlyName("Century House"); - assertEquals("Century House", homeSp.getFriendlyName()); - homeSp.setFqdn("mi6.co.uk"); - assertEquals("mi6.co.uk", homeSp.getFqdn()); - homeSp.setRoamingConsortiumOis(new long[] {0x112233L, 0x445566L}); - assertTrue(Arrays.equals(new long[] {0x112233L, 0x445566L}, - homeSp.getRoamingConsortiumOis())); - config.setHomeSp(homeSp); - assertEquals(homeSp, config.getHomeSp()); - - // Credential configuration. - Credential credential = new Credential(); - credential.setRealm("shaken.stirred.com"); - assertEquals("shaken.stirred.com", credential.getRealm()); - Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setUsername("james"); - assertEquals("james", userCredential.getUsername()); - userCredential.setPassword("Ym9uZDAwNw=="); - assertEquals("Ym9uZDAwNw==", userCredential.getPassword()); - userCredential.setEapType(21); - assertEquals(21, userCredential.getEapType()); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); - assertEquals("MS-CHAP-V2", userCredential.getNonEapInnerMethod()); - credential.setUserCredential(userCredential); - assertEquals(userCredential, credential.getUserCredential()); - Credential.CertificateCredential certCredential = new Credential.CertificateCredential(); - certCredential.setCertType("x509v3"); - assertEquals("x509v3", certCredential.getCertType()); - certCredential.setCertSha256Fingerprint(certFingerprint); - assertTrue(Arrays.equals(certFingerprint, certCredential.getCertSha256Fingerprint())); - credential.setCertCredential(certCredential); - assertEquals(certCredential, credential.getCertCredential()); - Credential.SimCredential simCredential = new Credential.SimCredential(); - simCredential.setImsi("imsi"); - assertEquals("imsi", simCredential.getImsi()); - simCredential.setEapType(24); - assertEquals(24, simCredential.getEapType()); - credential.setSimCredential(simCredential); - assertEquals(simCredential, credential.getSimCredential()); - config.setCredential(credential); - assertEquals(credential, config.getCredential()); - return config; - } - - /** - * Parse and verify all supported fields under PPS MO tree. - * - * @throws Exception - */ - public void testParsePPSMOTree() throws Exception { - String ppsMoTree = loadResourceFile(PPS_MO_XML_FILE); - PasspointConfiguration expectedConfig = generateConfigurationFromPPSMOTree(); - PasspointConfiguration actualConfig = PpsMoParser.parseMoText(ppsMoTree); - assertTrue(actualConfig.equals(expectedConfig)); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java b/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java deleted file mode 100644 index 9bd1226f52..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/ScanResultTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import java.util.List; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.WifiLock; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; -import android.util.Log; - -import com.android.compatibility.common.util.SystemUtil; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class ScanResultTest extends AndroidTestCase { - private static class MySync { - int expectedState = STATE_NULL; - } - - private WifiManager mWifiManager; - private WifiLock mWifiLock; - private static MySync mMySync; - - private static final int STATE_NULL = 0; - private static final int STATE_WIFI_CHANGING = 1; - private static final int STATE_WIFI_CHANGED = 2; - private static final int STATE_START_SCAN = 3; - private static final int STATE_SCAN_RESULTS_AVAILABLE = 4; - private static final int STATE_SCAN_FAILURE = 5; - - private static final String TAG = "WifiInfoTest"; - private static final int TIMEOUT_MSEC = 6000; - private static final int WAIT_MSEC = 60; - private static final int ENABLE_WAIT_MSEC = 10000; - private static final int SCAN_WAIT_MSEC = 10000; - private static final int SCAN_MAX_RETRY_COUNT = 6; - private static final int SCAN_FIND_BSSID_MAX_RETRY_COUNT = 5; - private static final long SCAN_FIND_BSSID_WAIT_MSEC = 5_000L; - private IntentFilter mIntentFilter; - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.expectedState = STATE_WIFI_CHANGED; - mMySync.notify(); - } - } else if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { - synchronized (mMySync) { - if (intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false)) { - mMySync.expectedState = STATE_SCAN_RESULTS_AVAILABLE; - } else { - mMySync.expectedState = STATE_SCAN_FAILURE; - } - mMySync.notify(); - } - } - } - }; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - mMySync = new MySync(); - mIntentFilter = new IntentFilter(); - mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); - mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); - mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK); - - mContext.registerReceiver(mReceiver, mIntentFilter); - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - mWifiLock = mWifiManager.createWifiLock(TAG); - mWifiLock.acquire(); - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - Thread.sleep(ENABLE_WAIT_MSEC); - assertTrue(mWifiManager.isWifiEnabled()); - mMySync.expectedState = STATE_NULL; - } - - @Override - protected void tearDown() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - super.tearDown(); - return; - } - mWifiLock.release(); - mContext.unregisterReceiver(mReceiver); - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - Thread.sleep(ENABLE_WAIT_MSEC); - super.tearDown(); - } - - private void setWifiEnabled(boolean enable) throws Exception { - synchronized (mMySync) { - mMySync.expectedState = STATE_WIFI_CHANGING; - if (enable) { - SystemUtil.runShellCommand("svc wifi enable"); - } else { - SystemUtil.runShellCommand("svc wifi disable"); - } - waitForBroadcast(TIMEOUT_MSEC, STATE_WIFI_CHANGED); - } - } - - private boolean waitForBroadcast(long timeout, int expectedState) throws Exception { - long waitTime = System.currentTimeMillis() + timeout; - while (System.currentTimeMillis() < waitTime - && mMySync.expectedState != expectedState) - mMySync.wait(WAIT_MSEC); - return mMySync.expectedState == expectedState; - } - - public void testScanResultProperties() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - List scanResults = mWifiManager.getScanResults(); - // this test case should in Wifi environment - for (int i = 0; i < scanResults.size(); i++) { - ScanResult mScanResult = scanResults.get(i); - assertNotNull(mScanResult.toString()); - } - } - - /* Multiple scans to ensure bssid is updated */ - private void scanAndWait() throws Exception { - synchronized (mMySync) { - for (int retry = 0; retry < SCAN_MAX_RETRY_COUNT; retry++) { - mMySync.expectedState = STATE_START_SCAN; - mWifiManager.startScan(); - if (waitForBroadcast(SCAN_WAIT_MSEC, STATE_SCAN_RESULTS_AVAILABLE)) { - break; - } - } - } - } - - public void testScanResultTimeStamp() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - - long timestamp = 0; - String BSSID = null; - - scanAndWait(); - - List scanResults = mWifiManager.getScanResults(); - for (ScanResult result : scanResults) { - BSSID = result.BSSID; - timestamp = result.timestamp; - assertTrue(timestamp != 0); - break; - } - - scanAndWait(); - - scanResults = mWifiManager.getScanResults(); - for (ScanResult result : scanResults) { - if (result.BSSID.equals(BSSID)) { - long timeDiff = (result.timestamp - timestamp) / 1000; - assertTrue (timeDiff > 0); - assertTrue (timeDiff < 6 * SCAN_WAIT_MSEC); - } - } - - } - - public void testScanResultMatchesWifiInfo() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - - // This test case should run while connected to Wifi - final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); - assertNotNull(wifiInfo); - - ScanResult currentNetwork = null; - for (int i = 0; i < SCAN_FIND_BSSID_MAX_RETRY_COUNT; i++) { - scanAndWait(); - final List scanResults = mWifiManager.getScanResults(); - currentNetwork = scanResults.stream().filter(r -> r.BSSID.equals(wifiInfo.getBSSID())) - .findAny().orElse(null); - - if (currentNetwork != null) { - break; - } - Thread.sleep(SCAN_FIND_BSSID_WAIT_MSEC); - } - assertNotNull("Current network not found in scan results", currentNetwork); - - assertEquals(wifiInfo.getWifiSsid(), currentNetwork.wifiSsid); - assertEquals(wifiInfo.getFrequency(), currentNetwork.frequency); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/SupplicantStateTest.java b/tests/cts/net/src/android/net/wifi/cts/SupplicantStateTest.java deleted file mode 100644 index 11edf7395b..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/SupplicantStateTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.net.wifi.SupplicantState; -import android.test.AndroidTestCase; - -public class SupplicantStateTest extends AndroidTestCase { - - public void testIsValidState() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - assertTrue(SupplicantState.isValidState(SupplicantState.DISCONNECTED)); - assertTrue(SupplicantState.isValidState(SupplicantState.INACTIVE)); - assertTrue(SupplicantState.isValidState(SupplicantState.SCANNING)); - assertTrue(SupplicantState.isValidState(SupplicantState.ASSOCIATING)); - assertTrue(SupplicantState.isValidState(SupplicantState.ASSOCIATED)); - assertTrue(SupplicantState.isValidState(SupplicantState.FOUR_WAY_HANDSHAKE)); - assertTrue(SupplicantState.isValidState(SupplicantState.GROUP_HANDSHAKE)); - assertTrue(SupplicantState.isValidState(SupplicantState.COMPLETED)); - assertTrue(SupplicantState.isValidState(SupplicantState.DORMANT)); - assertFalse(SupplicantState.isValidState(SupplicantState.UNINITIALIZED)); - assertFalse(SupplicantState.isValidState(SupplicantState.INVALID)); - } - -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiConfigurationTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiConfigurationTest.java deleted file mode 100644 index a59c85e5ab..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiConfigurationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import java.util.List; - -import android.content.Context; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiManager; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiConfigurationTest extends AndroidTestCase { - private WifiManager mWifiManager; - @Override - protected void setUp() throws Exception { - super.setUp(); - mWifiManager = (WifiManager) mContext - .getSystemService(Context.WIFI_SERVICE); - } - - public void testWifiConfiguration() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - List wifiConfigurations = mWifiManager.getConfiguredNetworks(); - if (wifiConfigurations != null) { - for (int i = 0; i < wifiConfigurations.size(); i++) { - WifiConfiguration wifiConfiguration = wifiConfigurations.get(i); - assertNotNull(wifiConfiguration); - assertNotNull(wifiConfiguration.toString()); - } - } - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java deleted file mode 100644 index e4c4b006dc..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiEnterpriseConfigTest.java +++ /dev/null @@ -1,796 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.content.Context; -import android.content.pm.PackageManager; -import android.net.wifi.WifiEnterpriseConfig; -import android.net.wifi.WifiEnterpriseConfig.Eap; -import android.net.wifi.WifiEnterpriseConfig.Phase2; -import android.net.wifi.WifiManager; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -import com.android.compatibility.common.util.SystemUtil; - -import java.io.ByteArrayInputStream; -import java.security.KeyFactory; -import java.security.PrivateKey; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.spec.PKCS8EncodedKeySpec; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiEnterpriseConfigTest extends AndroidTestCase { - private WifiManager mWifiManager; - - private static final String SSID = "\"TestSSID\""; - private static final String IDENTITY = "identity"; - private static final String PASSWORD = "password"; - private static final String SUBJECT_MATCH = "subjectmatch"; - private static final String ALT_SUBJECT_MATCH = "altsubjectmatch"; - private static final String DOM_SUBJECT_MATCH = "domsubjectmatch"; - private static final String PLMN = "plmn"; - private static final String REALM = "realm"; - private static final String ANON_IDENTITY = "anonidentity"; - private static final int ENABLE_DELAY = 10000; - - /* - * The keys and certificates below are generated with: - * - * openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem - * openssl ecparam -name prime256v1 -out ecparam.pem - * openssl req -newkey ec:ecparam.pem -keyout userkey.pem -nodes -days 3650 -out userkey.req - * mkdir -p demoCA/newcerts - * touch demoCA/index.txt - * echo "01" > demoCA/serial - * openssl ca -out usercert.pem -in userkey.req -cert cacert.pem -keyfile cakey.pem -days 3650 - */ - - /** - * Generated from above and converted with: - * - * openssl x509 -outform d -in cacert.pem | xxd -i | sed 's/0x/(byte) 0x/g' - */ - - private static final byte[] FAKE_EC_1 = { - (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x2f, (byte) 0x30, (byte) 0x82, - (byte) 0x03, (byte) 0x17, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, - (byte) 0x02, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0xa7, (byte) 0xe4, - (byte) 0x70, (byte) 0x50, (byte) 0x9b, (byte) 0xd2, (byte) 0x68, (byte) 0x68, - (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, - (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, - (byte) 0x0b, (byte) 0x05, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xad, - (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, - (byte) 0x55, (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, - (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, - (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x12, - (byte) 0x30, (byte) 0x10, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x07, (byte) 0x0c, (byte) 0x09, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, - (byte) 0x65, (byte) 0x2d, (byte) 0x43, (byte) 0x69, (byte) 0x74, (byte) 0x79, - (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x0c, (byte) 0x53, - (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x43, (byte) 0x6f, - (byte) 0x6d, (byte) 0x70, (byte) 0x61, (byte) 0x6e, (byte) 0x79, (byte) 0x31, - (byte) 0x10, (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x07, (byte) 0x53, (byte) 0x65, - (byte) 0x63, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x31, - (byte) 0x21, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x18, (byte) 0x57, (byte) 0x69, - (byte) 0x66, (byte) 0x69, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x65, - (byte) 0x72, (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x73, (byte) 0x65, - (byte) 0x43, (byte) 0x6f, (byte) 0x6e, (byte) 0x66, (byte) 0x69, (byte) 0x67, - (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x31, (byte) 0x29, - (byte) 0x30, (byte) 0x27, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, - (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x09, - (byte) 0x01, (byte) 0x16, (byte) 0x1a, (byte) 0x61, (byte) 0x6e, (byte) 0x2d, - (byte) 0x65, (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6c, (byte) 0x2d, - (byte) 0x61, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, - (byte) 0x40, (byte) 0x64, (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x69, - (byte) 0x6e, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, - (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x31, (byte) 0x36, (byte) 0x30, - (byte) 0x31, (byte) 0x31, (byte) 0x35, (byte) 0x31, (byte) 0x31, (byte) 0x31, - (byte) 0x38, (byte) 0x35, (byte) 0x31, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, - (byte) 0x32, (byte) 0x36, (byte) 0x30, (byte) 0x31, (byte) 0x31, (byte) 0x32, - (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x38, (byte) 0x35, (byte) 0x31, - (byte) 0x5a, (byte) 0x30, (byte) 0x81, (byte) 0xad, (byte) 0x31, (byte) 0x0b, - (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, (byte) 0x55, (byte) 0x31, - (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, (byte) 0x53, (byte) 0x6f, - (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x74, (byte) 0x61, - (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x12, (byte) 0x30, (byte) 0x10, - (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x07, (byte) 0x0c, - (byte) 0x09, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, - (byte) 0x43, (byte) 0x69, (byte) 0x74, (byte) 0x79, (byte) 0x31, (byte) 0x15, - (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x0a, (byte) 0x0c, (byte) 0x0c, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, - (byte) 0x65, (byte) 0x2d, (byte) 0x43, (byte) 0x6f, (byte) 0x6d, (byte) 0x70, - (byte) 0x61, (byte) 0x6e, (byte) 0x79, (byte) 0x31, (byte) 0x10, (byte) 0x30, - (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, - (byte) 0x0c, (byte) 0x07, (byte) 0x53, (byte) 0x65, (byte) 0x63, (byte) 0x74, - (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x31, (byte) 0x21, (byte) 0x30, - (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x03, - (byte) 0x0c, (byte) 0x18, (byte) 0x57, (byte) 0x69, (byte) 0x66, (byte) 0x69, - (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, (byte) 0x70, - (byte) 0x72, (byte) 0x69, (byte) 0x73, (byte) 0x65, (byte) 0x43, (byte) 0x6f, - (byte) 0x6e, (byte) 0x66, (byte) 0x69, (byte) 0x67, (byte) 0x54, (byte) 0x65, - (byte) 0x73, (byte) 0x74, (byte) 0x31, (byte) 0x29, (byte) 0x30, (byte) 0x27, - (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, - (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x09, (byte) 0x01, (byte) 0x16, - (byte) 0x1a, (byte) 0x61, (byte) 0x6e, (byte) 0x2d, (byte) 0x65, (byte) 0x6d, - (byte) 0x61, (byte) 0x69, (byte) 0x6c, (byte) 0x2d, (byte) 0x61, (byte) 0x64, - (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x40, (byte) 0x64, - (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6e, (byte) 0x2e, - (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, (byte) 0x82, (byte) 0x01, - (byte) 0x22, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, - (byte) 0x01, (byte) 0x0f, (byte) 0x00, (byte) 0x30, (byte) 0x82, (byte) 0x01, - (byte) 0x0a, (byte) 0x02, (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x00, - (byte) 0xb4, (byte) 0x6e, (byte) 0x66, (byte) 0x24, (byte) 0xe7, (byte) 0x5c, - (byte) 0xd8, (byte) 0x6f, (byte) 0x08, (byte) 0xd3, (byte) 0x80, (byte) 0xa3, - (byte) 0xb9, (byte) 0xaf, (byte) 0x90, (byte) 0xef, (byte) 0x1c, (byte) 0x2a, - (byte) 0x5f, (byte) 0x39, (byte) 0x0b, (byte) 0xbd, (byte) 0x75, (byte) 0x0d, - (byte) 0x3e, (byte) 0x19, (byte) 0x2e, (byte) 0x47, (byte) 0x1e, (byte) 0x14, - (byte) 0xc2, (byte) 0x1a, (byte) 0x59, (byte) 0xcc, (byte) 0x1b, (byte) 0xb6, - (byte) 0x9b, (byte) 0x46, (byte) 0x1f, (byte) 0x7f, (byte) 0x71, (byte) 0xdd, - (byte) 0x38, (byte) 0xbe, (byte) 0x89, (byte) 0x30, (byte) 0xba, (byte) 0x88, - (byte) 0xfb, (byte) 0x3f, (byte) 0x57, (byte) 0x35, (byte) 0xe7, (byte) 0xa7, - (byte) 0x2f, (byte) 0x2c, (byte) 0x8d, (byte) 0x7c, (byte) 0xe2, (byte) 0xd8, - (byte) 0x0c, (byte) 0x0a, (byte) 0xe6, (byte) 0x62, (byte) 0x46, (byte) 0x8c, - (byte) 0xf4, (byte) 0x51, (byte) 0xfc, (byte) 0x6a, (byte) 0x79, (byte) 0xdd, - (byte) 0x0a, (byte) 0x41, (byte) 0x23, (byte) 0xd3, (byte) 0xe9, (byte) 0x5e, - (byte) 0x91, (byte) 0xcd, (byte) 0xbd, (byte) 0x55, (byte) 0x28, (byte) 0x71, - (byte) 0xec, (byte) 0x52, (byte) 0x19, (byte) 0x85, (byte) 0x0c, (byte) 0x1b, - (byte) 0xfa, (byte) 0xbf, (byte) 0xfe, (byte) 0xae, (byte) 0x5c, (byte) 0x3b, - (byte) 0x99, (byte) 0x42, (byte) 0xd4, (byte) 0xe7, (byte) 0x17, (byte) 0xec, - (byte) 0x41, (byte) 0x22, (byte) 0x2c, (byte) 0x1e, (byte) 0x7b, (byte) 0x53, - (byte) 0xad, (byte) 0x02, (byte) 0xfd, (byte) 0xf6, (byte) 0x4a, (byte) 0xb1, - (byte) 0x6e, (byte) 0x6c, (byte) 0x87, (byte) 0xf5, (byte) 0x7d, (byte) 0x9b, - (byte) 0x34, (byte) 0x0e, (byte) 0x3b, (byte) 0x0e, (byte) 0xaa, (byte) 0xc5, - (byte) 0xc4, (byte) 0xef, (byte) 0xf2, (byte) 0x5a, (byte) 0xa9, (byte) 0xac, - (byte) 0x19, (byte) 0xce, (byte) 0x5f, (byte) 0xc5, (byte) 0xcc, (byte) 0x0d, - (byte) 0xee, (byte) 0x7f, (byte) 0x32, (byte) 0xb4, (byte) 0xfe, (byte) 0xc1, - (byte) 0xca, (byte) 0x9b, (byte) 0x3f, (byte) 0xad, (byte) 0x2c, (byte) 0x7a, - (byte) 0xc5, (byte) 0x8d, (byte) 0x48, (byte) 0xa1, (byte) 0xc9, (byte) 0x74, - (byte) 0xfe, (byte) 0x8a, (byte) 0xe3, (byte) 0xb0, (byte) 0x92, (byte) 0xee, - (byte) 0x73, (byte) 0x09, (byte) 0x0a, (byte) 0xbc, (byte) 0xc8, (byte) 0x63, - (byte) 0xba, (byte) 0x0e, (byte) 0x26, (byte) 0xab, (byte) 0x1e, (byte) 0xff, - (byte) 0xbc, (byte) 0x24, (byte) 0x12, (byte) 0x26, (byte) 0x11, (byte) 0xe0, - (byte) 0x04, (byte) 0xcb, (byte) 0x96, (byte) 0x7d, (byte) 0x41, (byte) 0xf7, - (byte) 0x79, (byte) 0x32, (byte) 0x05, (byte) 0x33, (byte) 0x19, (byte) 0x6e, - (byte) 0xb9, (byte) 0x75, (byte) 0xf3, (byte) 0x50, (byte) 0xa4, (byte) 0xc3, - (byte) 0x55, (byte) 0x9d, (byte) 0x8f, (byte) 0xb6, (byte) 0xab, (byte) 0x97, - (byte) 0xe7, (byte) 0xe2, (byte) 0xe8, (byte) 0x15, (byte) 0xfc, (byte) 0x35, - (byte) 0xbd, (byte) 0xce, (byte) 0x17, (byte) 0xbe, (byte) 0xe3, (byte) 0x73, - (byte) 0xd4, (byte) 0x88, (byte) 0x39, (byte) 0x27, (byte) 0x7e, (byte) 0x6d, - (byte) 0xa2, (byte) 0x27, (byte) 0xfa, (byte) 0x96, (byte) 0xe3, (byte) 0x38, - (byte) 0xc0, (byte) 0xa1, (byte) 0x55, (byte) 0xc6, (byte) 0xf3, (byte) 0x20, - (byte) 0xea, (byte) 0x50, (byte) 0x8d, (byte) 0x6c, (byte) 0x94, (byte) 0x9a, - (byte) 0x43, (byte) 0x74, (byte) 0xc0, (byte) 0xfa, (byte) 0xef, (byte) 0xe0, - (byte) 0xb1, (byte) 0x1c, (byte) 0x6d, (byte) 0x5e, (byte) 0x44, (byte) 0x08, - (byte) 0xef, (byte) 0xd5, (byte) 0x80, (byte) 0xad, (byte) 0x02, (byte) 0x03, - (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3, (byte) 0x50, (byte) 0x30, - (byte) 0x4e, (byte) 0x30, (byte) 0x1d, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, (byte) 0x04, (byte) 0x14, - (byte) 0xe9, (byte) 0xd0, (byte) 0x9e, (byte) 0x0e, (byte) 0x62, (byte) 0x31, - (byte) 0x02, (byte) 0x9a, (byte) 0x33, (byte) 0xd7, (byte) 0x4a, (byte) 0x93, - (byte) 0x0d, (byte) 0xf3, (byte) 0xd6, (byte) 0x74, (byte) 0xce, (byte) 0x69, - (byte) 0xe1, (byte) 0xef, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, (byte) 0x18, (byte) 0x30, - (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0xe9, (byte) 0xd0, (byte) 0x9e, - (byte) 0x0e, (byte) 0x62, (byte) 0x31, (byte) 0x02, (byte) 0x9a, (byte) 0x33, - (byte) 0xd7, (byte) 0x4a, (byte) 0x93, (byte) 0x0d, (byte) 0xf3, (byte) 0xd6, - (byte) 0x74, (byte) 0xce, (byte) 0x69, (byte) 0xe1, (byte) 0xef, (byte) 0x30, - (byte) 0x0c, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x13, - (byte) 0x04, (byte) 0x05, (byte) 0x30, (byte) 0x03, (byte) 0x01, (byte) 0x01, - (byte) 0xff, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x01, (byte) 0x0b, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, - (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x52, (byte) 0x70, (byte) 0xb6, - (byte) 0x10, (byte) 0x7f, (byte) 0xaa, (byte) 0x86, (byte) 0x8f, (byte) 0x02, - (byte) 0xb0, (byte) 0x97, (byte) 0x89, (byte) 0xb9, (byte) 0x04, (byte) 0x1d, - (byte) 0x79, (byte) 0xa3, (byte) 0x74, (byte) 0x7c, (byte) 0xdf, (byte) 0xad, - (byte) 0x87, (byte) 0xe4, (byte) 0x00, (byte) 0xd3, (byte) 0x3a, (byte) 0x5c, - (byte) 0x48, (byte) 0x3b, (byte) 0xfe, (byte) 0x77, (byte) 0xfd, (byte) 0xbe, - (byte) 0xce, (byte) 0x5b, (byte) 0xd2, (byte) 0xea, (byte) 0x3e, (byte) 0x7f, - (byte) 0xef, (byte) 0x20, (byte) 0x0d, (byte) 0x0b, (byte) 0xc7, (byte) 0xc4, - (byte) 0x25, (byte) 0x20, (byte) 0xe1, (byte) 0x8f, (byte) 0xc5, (byte) 0x19, - (byte) 0x37, (byte) 0x9c, (byte) 0xa0, (byte) 0x9d, (byte) 0x02, (byte) 0x30, - (byte) 0x5f, (byte) 0x49, (byte) 0x4e, (byte) 0x56, (byte) 0xc4, (byte) 0xab, - (byte) 0xcb, (byte) 0x5c, (byte) 0xe6, (byte) 0x40, (byte) 0x93, (byte) 0x92, - (byte) 0xee, (byte) 0xa1, (byte) 0x69, (byte) 0x7d, (byte) 0x10, (byte) 0x6b, - (byte) 0xd4, (byte) 0xf7, (byte) 0xec, (byte) 0xd9, (byte) 0xa5, (byte) 0x29, - (byte) 0x63, (byte) 0x29, (byte) 0xd9, (byte) 0x27, (byte) 0x2d, (byte) 0x5e, - (byte) 0x34, (byte) 0x37, (byte) 0xa9, (byte) 0xba, (byte) 0x0a, (byte) 0x7b, - (byte) 0x99, (byte) 0x1a, (byte) 0x7d, (byte) 0xa7, (byte) 0xa7, (byte) 0xf0, - (byte) 0xbf, (byte) 0x40, (byte) 0x29, (byte) 0x5d, (byte) 0x2f, (byte) 0x2e, - (byte) 0x0f, (byte) 0x35, (byte) 0x90, (byte) 0xb5, (byte) 0xc3, (byte) 0xfd, - (byte) 0x1e, (byte) 0xe2, (byte) 0xb3, (byte) 0xae, (byte) 0xf9, (byte) 0xde, - (byte) 0x9d, (byte) 0x76, (byte) 0xe1, (byte) 0x20, (byte) 0xf5, (byte) 0x1c, - (byte) 0x30, (byte) 0x42, (byte) 0x80, (byte) 0x2a, (byte) 0x4f, (byte) 0x85, - (byte) 0x5c, (byte) 0xb4, (byte) 0x49, (byte) 0x68, (byte) 0x6c, (byte) 0x7c, - (byte) 0x2a, (byte) 0xc8, (byte) 0xbc, (byte) 0x15, (byte) 0xed, (byte) 0x88, - (byte) 0xfd, (byte) 0x8a, (byte) 0x63, (byte) 0xe0, (byte) 0x93, (byte) 0xfd, - (byte) 0x86, (byte) 0xab, (byte) 0xa9, (byte) 0xf6, (byte) 0x63, (byte) 0xa5, - (byte) 0x29, (byte) 0xaf, (byte) 0xdc, (byte) 0x8f, (byte) 0xca, (byte) 0xc2, - (byte) 0x28, (byte) 0xe7, (byte) 0x26, (byte) 0x89, (byte) 0x75, (byte) 0xf1, - (byte) 0x3e, (byte) 0x2e, (byte) 0x86, (byte) 0x11, (byte) 0x8b, (byte) 0xfa, - (byte) 0xf5, (byte) 0xb4, (byte) 0xb4, (byte) 0x04, (byte) 0x02, (byte) 0xa3, - (byte) 0x85, (byte) 0x81, (byte) 0xad, (byte) 0xb3, (byte) 0xec, (byte) 0x2d, - (byte) 0x4b, (byte) 0x40, (byte) 0x59, (byte) 0x61, (byte) 0x0d, (byte) 0x59, - (byte) 0x09, (byte) 0x09, (byte) 0xee, (byte) 0xc7, (byte) 0x51, (byte) 0xef, - (byte) 0x6f, (byte) 0xd6, (byte) 0x9a, (byte) 0xa5, (byte) 0x45, (byte) 0xa2, - (byte) 0x89, (byte) 0xc2, (byte) 0x97, (byte) 0x93, (byte) 0xbc, (byte) 0x5b, - (byte) 0x37, (byte) 0x55, (byte) 0x73, (byte) 0x55, (byte) 0x0c, (byte) 0x9c, - (byte) 0xcb, (byte) 0x10, (byte) 0xec, (byte) 0x76, (byte) 0xfe, (byte) 0xa7, - (byte) 0x70, (byte) 0x4e, (byte) 0x9a, (byte) 0xa2, (byte) 0xf9, (byte) 0x40, - (byte) 0xdd, (byte) 0x96, (byte) 0x7d, (byte) 0x67, (byte) 0x5c, (byte) 0x8e, - (byte) 0x43, (byte) 0x1a, (byte) 0x26, (byte) 0xaa, (byte) 0xee, (byte) 0x38, - (byte) 0x11, (byte) 0x26, (byte) 0x3d, (byte) 0x69, (byte) 0xc7, (byte) 0x6a, - (byte) 0xe7, (byte) 0xbd, (byte) 0x67, (byte) 0x70, (byte) 0x35, (byte) 0xff, - (byte) 0x72, (byte) 0x2c, (byte) 0x87, (byte) 0x82, (byte) 0x68, (byte) 0x3f, - (byte) 0x8d - }; - - private static final byte[] FAKE_EC_2 = { - (byte) 0x30, (byte) 0x82, (byte) 0x04, (byte) 0x4f, (byte) 0x30, (byte) 0x82, - (byte) 0x03, (byte) 0x37, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, - (byte) 0x02, (byte) 0x02, (byte) 0x09, (byte) 0x00, (byte) 0xd9, (byte) 0xc4, - (byte) 0xe1, (byte) 0xfc, (byte) 0x3d, (byte) 0x02, (byte) 0x21, (byte) 0x1f, - (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, - (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, - (byte) 0x0b, (byte) 0x05, (byte) 0x00, (byte) 0x30, (byte) 0x81, (byte) 0xbd, - (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x41, - (byte) 0x55, (byte) 0x31, (byte) 0x13, (byte) 0x30, (byte) 0x11, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x0a, - (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, - (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x31, (byte) 0x12, - (byte) 0x30, (byte) 0x10, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x07, (byte) 0x0c, (byte) 0x09, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, - (byte) 0x65, (byte) 0x2d, (byte) 0x43, (byte) 0x69, (byte) 0x74, (byte) 0x79, - (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x12, (byte) 0x53, - (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x4f, (byte) 0x74, - (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x2d, (byte) 0x43, (byte) 0x6f, - (byte) 0x6d, (byte) 0x70, (byte) 0x61, (byte) 0x6e, (byte) 0x79, (byte) 0x31, - (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x0c, (byte) 0x53, (byte) 0x6f, - (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, (byte) 0x65, (byte) 0x63, - (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, (byte) 0x31, (byte) 0x21, - (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x03, (byte) 0x0c, (byte) 0x18, (byte) 0x57, (byte) 0x69, (byte) 0x66, - (byte) 0x69, (byte) 0x45, (byte) 0x6e, (byte) 0x74, (byte) 0x65, (byte) 0x72, - (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x73, (byte) 0x65, (byte) 0x43, - (byte) 0x6f, (byte) 0x6e, (byte) 0x66, (byte) 0x69, (byte) 0x67, (byte) 0x54, - (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x31, (byte) 0x2e, (byte) 0x30, - (byte) 0x2c, (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, - (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x09, (byte) 0x01, - (byte) 0x16, (byte) 0x1f, (byte) 0x61, (byte) 0x6e, (byte) 0x2d, (byte) 0x65, - (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6c, (byte) 0x2d, (byte) 0x61, - (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x40, - (byte) 0x73, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x64, - (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6e, (byte) 0x2e, - (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, (byte) 0x1e, (byte) 0x17, - (byte) 0x0d, (byte) 0x31, (byte) 0x36, (byte) 0x30, (byte) 0x31, (byte) 0x31, - (byte) 0x35, (byte) 0x31, (byte) 0x31, (byte) 0x33, (byte) 0x32, (byte) 0x34, - (byte) 0x36, (byte) 0x5a, (byte) 0x17, (byte) 0x0d, (byte) 0x32, (byte) 0x36, - (byte) 0x30, (byte) 0x31, (byte) 0x31, (byte) 0x32, (byte) 0x31, (byte) 0x31, - (byte) 0x33, (byte) 0x32, (byte) 0x34, (byte) 0x36, (byte) 0x5a, (byte) 0x30, - (byte) 0x81, (byte) 0xbd, (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, - (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, (byte) 0x13, - (byte) 0x02, (byte) 0x41, (byte) 0x55, (byte) 0x31, (byte) 0x13, (byte) 0x30, - (byte) 0x11, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x08, - (byte) 0x0c, (byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, - (byte) 0x2d, (byte) 0x53, (byte) 0x74, (byte) 0x61, (byte) 0x74, (byte) 0x65, - (byte) 0x31, (byte) 0x12, (byte) 0x30, (byte) 0x10, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x07, (byte) 0x0c, (byte) 0x09, (byte) 0x53, - (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x43, (byte) 0x69, - (byte) 0x74, (byte) 0x79, (byte) 0x31, (byte) 0x1b, (byte) 0x30, (byte) 0x19, - (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, - (byte) 0x12, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, - (byte) 0x4f, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x2d, - (byte) 0x43, (byte) 0x6f, (byte) 0x6d, (byte) 0x70, (byte) 0x61, (byte) 0x6e, - (byte) 0x79, (byte) 0x31, (byte) 0x15, (byte) 0x30, (byte) 0x13, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x0c, - (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x2d, (byte) 0x53, - (byte) 0x65, (byte) 0x63, (byte) 0x74, (byte) 0x69, (byte) 0x6f, (byte) 0x6e, - (byte) 0x31, (byte) 0x21, (byte) 0x30, (byte) 0x1f, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x18, (byte) 0x57, - (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x45, (byte) 0x6e, (byte) 0x74, - (byte) 0x65, (byte) 0x72, (byte) 0x70, (byte) 0x72, (byte) 0x69, (byte) 0x73, - (byte) 0x65, (byte) 0x43, (byte) 0x6f, (byte) 0x6e, (byte) 0x66, (byte) 0x69, - (byte) 0x67, (byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x31, - (byte) 0x2e, (byte) 0x30, (byte) 0x2c, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x09, (byte) 0x01, (byte) 0x16, (byte) 0x1f, (byte) 0x61, (byte) 0x6e, - (byte) 0x2d, (byte) 0x65, (byte) 0x6d, (byte) 0x61, (byte) 0x69, (byte) 0x6c, - (byte) 0x2d, (byte) 0x61, (byte) 0x64, (byte) 0x72, (byte) 0x65, (byte) 0x73, - (byte) 0x73, (byte) 0x40, (byte) 0x73, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, - (byte) 0x2d, (byte) 0x64, (byte) 0x6f, (byte) 0x6d, (byte) 0x61, (byte) 0x69, - (byte) 0x6e, (byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x30, - (byte) 0x82, (byte) 0x01, (byte) 0x22, (byte) 0x30, (byte) 0x0d, (byte) 0x06, - (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, - (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, - (byte) 0x03, (byte) 0x82, (byte) 0x01, (byte) 0x0f, (byte) 0x00, (byte) 0x30, - (byte) 0x82, (byte) 0x01, (byte) 0x0a, (byte) 0x02, (byte) 0x82, (byte) 0x01, - (byte) 0x01, (byte) 0x00, (byte) 0xa9, (byte) 0xa3, (byte) 0x21, (byte) 0xfd, - (byte) 0xa6, (byte) 0xc1, (byte) 0x04, (byte) 0x48, (byte) 0xc2, (byte) 0xc8, - (byte) 0x44, (byte) 0x50, (byte) 0xc4, (byte) 0x6d, (byte) 0x35, (byte) 0x24, - (byte) 0xf0, (byte) 0x6d, (byte) 0x69, (byte) 0xfb, (byte) 0xd1, (byte) 0xfc, - (byte) 0xde, (byte) 0xe9, (byte) 0xdb, (byte) 0xca, (byte) 0xee, (byte) 0x24, - (byte) 0x3d, (byte) 0x85, (byte) 0x8d, (byte) 0x84, (byte) 0xb4, (byte) 0x73, - (byte) 0xd1, (byte) 0x09, (byte) 0x37, (byte) 0x16, (byte) 0x80, (byte) 0x70, - (byte) 0x6b, (byte) 0x61, (byte) 0xcc, (byte) 0xf2, (byte) 0x98, (byte) 0xbd, - (byte) 0x53, (byte) 0x3a, (byte) 0x68, (byte) 0x60, (byte) 0x02, (byte) 0xba, - (byte) 0x0c, (byte) 0x53, (byte) 0x96, (byte) 0xfb, (byte) 0x80, (byte) 0xd1, - (byte) 0x5b, (byte) 0xc3, (byte) 0xcb, (byte) 0x7a, (byte) 0x81, (byte) 0x00, - (byte) 0x5d, (byte) 0x20, (byte) 0x72, (byte) 0xc0, (byte) 0xe4, (byte) 0x48, - (byte) 0x0e, (byte) 0xa2, (byte) 0xcd, (byte) 0xa2, (byte) 0x63, (byte) 0x8c, - (byte) 0x05, (byte) 0x7c, (byte) 0x63, (byte) 0x5b, (byte) 0xda, (byte) 0x0e, - (byte) 0xa7, (byte) 0x05, (byte) 0x09, (byte) 0x6d, (byte) 0xd5, (byte) 0xe4, - (byte) 0x3a, (byte) 0x4e, (byte) 0xa1, (byte) 0xf5, (byte) 0xfd, (byte) 0x47, - (byte) 0xee, (byte) 0x7b, (byte) 0xa3, (byte) 0x4c, (byte) 0x8c, (byte) 0xd3, - (byte) 0xbb, (byte) 0x58, (byte) 0x0f, (byte) 0x1c, (byte) 0x56, (byte) 0x80, - (byte) 0x80, (byte) 0xb5, (byte) 0xf9, (byte) 0x80, (byte) 0xc2, (byte) 0xd1, - (byte) 0x1d, (byte) 0x3f, (byte) 0xe8, (byte) 0x2a, (byte) 0x63, (byte) 0x0b, - (byte) 0x54, (byte) 0x5f, (byte) 0xd4, (byte) 0xcb, (byte) 0xb7, (byte) 0x94, - (byte) 0xe2, (byte) 0x35, (byte) 0x65, (byte) 0x59, (byte) 0xd1, (byte) 0x72, - (byte) 0xa4, (byte) 0xb8, (byte) 0xee, (byte) 0x82, (byte) 0x11, (byte) 0x7a, - (byte) 0x4c, (byte) 0x26, (byte) 0x66, (byte) 0x9b, (byte) 0x27, (byte) 0x3d, - (byte) 0x14, (byte) 0x4b, (byte) 0x4b, (byte) 0xc8, (byte) 0xf0, (byte) 0x6e, - (byte) 0x43, (byte) 0x8f, (byte) 0xee, (byte) 0x1f, (byte) 0xeb, (byte) 0x20, - (byte) 0xe2, (byte) 0x4c, (byte) 0x79, (byte) 0xbf, (byte) 0x21, (byte) 0x0d, - (byte) 0x36, (byte) 0xed, (byte) 0x5f, (byte) 0xcc, (byte) 0x70, (byte) 0x68, - (byte) 0x8a, (byte) 0x05, (byte) 0x7c, (byte) 0x2f, (byte) 0x1b, (byte) 0xe9, - (byte) 0xec, (byte) 0x83, (byte) 0x6e, (byte) 0x9a, (byte) 0x78, (byte) 0x31, - (byte) 0x3d, (byte) 0xf4, (byte) 0xde, (byte) 0x1b, (byte) 0xd2, (byte) 0x76, - (byte) 0x32, (byte) 0x6c, (byte) 0x1e, (byte) 0xc9, (byte) 0x90, (byte) 0x7f, - (byte) 0xc4, (byte) 0x30, (byte) 0xc0, (byte) 0xae, (byte) 0xab, (byte) 0x70, - (byte) 0x08, (byte) 0x78, (byte) 0xbf, (byte) 0x2e, (byte) 0x8b, (byte) 0x07, - (byte) 0xab, (byte) 0x8f, (byte) 0x03, (byte) 0xc5, (byte) 0xd3, (byte) 0xeb, - (byte) 0x98, (byte) 0x19, (byte) 0x50, (byte) 0x83, (byte) 0x52, (byte) 0xf7, - (byte) 0xff, (byte) 0xf5, (byte) 0x89, (byte) 0xe6, (byte) 0xe7, (byte) 0xa7, - (byte) 0xcb, (byte) 0xdf, (byte) 0x96, (byte) 0x9d, (byte) 0x14, (byte) 0x04, - (byte) 0x5e, (byte) 0x45, (byte) 0x82, (byte) 0xf7, (byte) 0x23, (byte) 0x1a, - (byte) 0xb6, (byte) 0x64, (byte) 0x57, (byte) 0xe8, (byte) 0x7e, (byte) 0xa1, - (byte) 0xaf, (byte) 0x58, (byte) 0x68, (byte) 0x70, (byte) 0xc5, (byte) 0x0f, - (byte) 0x8d, (byte) 0x54, (byte) 0xf3, (byte) 0x49, (byte) 0xa3, (byte) 0x97, - (byte) 0x32, (byte) 0xa7, (byte) 0x2a, (byte) 0x79, (byte) 0xbe, (byte) 0xcd, - (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xa3, - (byte) 0x50, (byte) 0x30, (byte) 0x4e, (byte) 0x30, (byte) 0x1d, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, - (byte) 0x04, (byte) 0x14, (byte) 0xac, (byte) 0xf3, (byte) 0x73, (byte) 0x9a, - (byte) 0x25, (byte) 0x08, (byte) 0x01, (byte) 0x07, (byte) 0x86, (byte) 0x8b, - (byte) 0xc4, (byte) 0xed, (byte) 0xb1, (byte) 0x6b, (byte) 0x53, (byte) 0xa3, - (byte) 0x21, (byte) 0xb4, (byte) 0xb4, (byte) 0x46, (byte) 0x30, (byte) 0x1f, - (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, - (byte) 0x18, (byte) 0x30, (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0xac, - (byte) 0xf3, (byte) 0x73, (byte) 0x9a, (byte) 0x25, (byte) 0x08, (byte) 0x01, - (byte) 0x07, (byte) 0x86, (byte) 0x8b, (byte) 0xc4, (byte) 0xed, (byte) 0xb1, - (byte) 0x6b, (byte) 0x53, (byte) 0xa3, (byte) 0x21, (byte) 0xb4, (byte) 0xb4, - (byte) 0x46, (byte) 0x30, (byte) 0x0c, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x1d, (byte) 0x13, (byte) 0x04, (byte) 0x05, (byte) 0x30, (byte) 0x03, - (byte) 0x01, (byte) 0x01, (byte) 0xff, (byte) 0x30, (byte) 0x0d, (byte) 0x06, - (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, - (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x0b, (byte) 0x05, (byte) 0x00, - (byte) 0x03, (byte) 0x82, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x16, - (byte) 0xf6, (byte) 0xd0, (byte) 0xe1, (byte) 0x14, (byte) 0x2d, (byte) 0x52, - (byte) 0x47, (byte) 0xa2, (byte) 0x89, (byte) 0xe6, (byte) 0x7f, (byte) 0xac, - (byte) 0x88, (byte) 0x04, (byte) 0x15, (byte) 0x21, (byte) 0x00, (byte) 0x72, - (byte) 0xf9, (byte) 0xee, (byte) 0xb2, (byte) 0x1b, (byte) 0x8e, (byte) 0x46, - (byte) 0x8b, (byte) 0x90, (byte) 0x20, (byte) 0x4f, (byte) 0xa7, (byte) 0xae, - (byte) 0x30, (byte) 0xb6, (byte) 0x24, (byte) 0xc5, (byte) 0x54, (byte) 0xaf, - (byte) 0x6c, (byte) 0x1e, (byte) 0xd6, (byte) 0x73, (byte) 0x22, (byte) 0x48, - (byte) 0x07, (byte) 0xb5, (byte) 0x13, (byte) 0x35, (byte) 0xbb, (byte) 0x9e, - (byte) 0xd9, (byte) 0x19, (byte) 0x79, (byte) 0xda, (byte) 0x76, (byte) 0x7f, - (byte) 0xf7, (byte) 0x87, (byte) 0xc9, (byte) 0xc3, (byte) 0x0b, (byte) 0x38, - (byte) 0x20, (byte) 0x26, (byte) 0xfc, (byte) 0x7f, (byte) 0x32, (byte) 0x2a, - (byte) 0xd5, (byte) 0x09, (byte) 0x87, (byte) 0xda, (byte) 0x23, (byte) 0x1f, - (byte) 0x71, (byte) 0x83, (byte) 0x00, (byte) 0x17, (byte) 0xf6, (byte) 0xb9, - (byte) 0x57, (byte) 0x21, (byte) 0xdf, (byte) 0x29, (byte) 0xcc, (byte) 0xdb, - (byte) 0xe9, (byte) 0x2c, (byte) 0xba, (byte) 0x86, (byte) 0x34, (byte) 0x53, - (byte) 0x29, (byte) 0x09, (byte) 0xc7, (byte) 0x3c, (byte) 0x8e, (byte) 0xa3, - (byte) 0x86, (byte) 0x81, (byte) 0x26, (byte) 0x7b, (byte) 0xa1, (byte) 0xbe, - (byte) 0xbc, (byte) 0xc9, (byte) 0x83, (byte) 0xb5, (byte) 0x36, (byte) 0x65, - (byte) 0x51, (byte) 0xb4, (byte) 0x41, (byte) 0xf0, (byte) 0x05, (byte) 0x78, - (byte) 0x3a, (byte) 0xa6, (byte) 0xad, (byte) 0x4b, (byte) 0x08, (byte) 0xd1, - (byte) 0xe4, (byte) 0xf1, (byte) 0x2e, (byte) 0xc7, (byte) 0x23, (byte) 0x6d, - (byte) 0xf0, (byte) 0x9d, (byte) 0x60, (byte) 0x6d, (byte) 0xe7, (byte) 0x11, - (byte) 0xaf, (byte) 0x41, (byte) 0x68, (byte) 0xee, (byte) 0x06, (byte) 0x76, - (byte) 0x82, (byte) 0x48, (byte) 0xee, (byte) 0x41, (byte) 0xc4, (byte) 0xf8, - (byte) 0xe1, (byte) 0x83, (byte) 0xbc, (byte) 0xa8, (byte) 0xbd, (byte) 0x9c, - (byte) 0x17, (byte) 0x45, (byte) 0xf4, (byte) 0x36, (byte) 0x67, (byte) 0x47, - (byte) 0x0e, (byte) 0x32, (byte) 0x13, (byte) 0x6e, (byte) 0xc1, (byte) 0x1e, - (byte) 0x08, (byte) 0xef, (byte) 0x10, (byte) 0xdf, (byte) 0x45, (byte) 0xbf, - (byte) 0x5a, (byte) 0xc4, (byte) 0x44, (byte) 0x4c, (byte) 0xd0, (byte) 0xd5, - (byte) 0x23, (byte) 0xde, (byte) 0xd7, (byte) 0x83, (byte) 0x1e, (byte) 0xb0, - (byte) 0x27, (byte) 0x4d, (byte) 0x57, (byte) 0xa3, (byte) 0xe8, (byte) 0x36, - (byte) 0x52, (byte) 0x1c, (byte) 0x48, (byte) 0x0a, (byte) 0xc4, (byte) 0xd8, - (byte) 0x32, (byte) 0xfc, (byte) 0xd0, (byte) 0x26, (byte) 0x6f, (byte) 0xa4, - (byte) 0x61, (byte) 0x2c, (byte) 0x3a, (byte) 0xa9, (byte) 0xfe, (byte) 0xa4, - (byte) 0x7a, (byte) 0x58, (byte) 0x54, (byte) 0x58, (byte) 0x96, (byte) 0x2b, - (byte) 0x6e, (byte) 0x9c, (byte) 0xc9, (byte) 0x00, (byte) 0xda, (byte) 0xc6, - (byte) 0xbb, (byte) 0x97, (byte) 0xc4, (byte) 0x95, (byte) 0x32, (byte) 0x6b, - (byte) 0x03, (byte) 0x6f, (byte) 0x33, (byte) 0x59, (byte) 0xd4, (byte) 0xa4, - (byte) 0x4a, (byte) 0x29, (byte) 0x29, (byte) 0x9a, (byte) 0xf4, (byte) 0x87, - (byte) 0x26, (byte) 0xe6, (byte) 0xee, (byte) 0x5c, (byte) 0x0b, (byte) 0xe9, - (byte) 0x98, (byte) 0x5d, (byte) 0xab, (byte) 0x31, (byte) 0xa1, (byte) 0x63, - (byte) 0xaa, (byte) 0x1a, (byte) 0xea, (byte) 0x61, (byte) 0x27, (byte) 0x5e, - (byte) 0x9e, (byte) 0x34, (byte) 0x73 - }; - - /** - * Client certificate generated from above and converted with: - * - * openssl x509 -outform d -in usercert.pem | xxd -i | sed 's/0x/(byte) 0x/g' - */ - private static final byte[] FAKE_EC_3 = { - (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0xdf, (byte) 0x30, (byte) 0x82, - (byte) 0x01, (byte) 0xc7, (byte) 0xa0, (byte) 0x03, (byte) 0x02, (byte) 0x01, - (byte) 0x02, (byte) 0x02, (byte) 0x01, (byte) 0x01, (byte) 0x30, (byte) 0x0d, - (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, - (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x0b, (byte) 0x05, - (byte) 0x00, (byte) 0x30, (byte) 0x64, (byte) 0x31, (byte) 0x0b, (byte) 0x30, - (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x06, - (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53, (byte) 0x31, (byte) 0x0b, - (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x08, (byte) 0x0c, (byte) 0x02, (byte) 0x43, (byte) 0x41, (byte) 0x31, - (byte) 0x16, (byte) 0x30, (byte) 0x14, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x07, (byte) 0x0c, (byte) 0x0d, (byte) 0x4d, (byte) 0x6f, - (byte) 0x75, (byte) 0x6e, (byte) 0x74, (byte) 0x61, (byte) 0x69, (byte) 0x6e, - (byte) 0x20, (byte) 0x56, (byte) 0x69, (byte) 0x65, (byte) 0x77, (byte) 0x31, - (byte) 0x0f, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x06, (byte) 0x47, (byte) 0x6f, - (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x31, (byte) 0x10, - (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x0b, (byte) 0x0c, (byte) 0x07, (byte) 0x41, (byte) 0x6e, (byte) 0x64, - (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x31, (byte) 0x0d, - (byte) 0x30, (byte) 0x0b, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x04, - (byte) 0x03, (byte) 0x0c, (byte) 0x04, (byte) 0x54, (byte) 0x45, (byte) 0x53, - (byte) 0x54, (byte) 0x30, (byte) 0x1e, (byte) 0x17, (byte) 0x0d, (byte) 0x31, - (byte) 0x37, (byte) 0x30, (byte) 0x31, (byte) 0x32, (byte) 0x37, (byte) 0x31, - (byte) 0x37, (byte) 0x35, (byte) 0x38, (byte) 0x31, (byte) 0x32, (byte) 0x5a, - (byte) 0x17, (byte) 0x0d, (byte) 0x32, (byte) 0x37, (byte) 0x30, (byte) 0x31, - (byte) 0x32, (byte) 0x35, (byte) 0x31, (byte) 0x37, (byte) 0x35, (byte) 0x38, - (byte) 0x31, (byte) 0x32, (byte) 0x5a, (byte) 0x30, (byte) 0x50, (byte) 0x31, - (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, - (byte) 0x04, (byte) 0x06, (byte) 0x13, (byte) 0x02, (byte) 0x55, (byte) 0x53, - (byte) 0x31, (byte) 0x0b, (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x08, (byte) 0x0c, (byte) 0x02, (byte) 0x43, - (byte) 0x41, (byte) 0x31, (byte) 0x0f, (byte) 0x30, (byte) 0x0d, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x04, (byte) 0x0a, (byte) 0x0c, (byte) 0x06, - (byte) 0x47, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, - (byte) 0x31, (byte) 0x10, (byte) 0x30, (byte) 0x0e, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x0b, (byte) 0x0c, (byte) 0x07, (byte) 0x41, - (byte) 0x6e, (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, - (byte) 0x31, (byte) 0x11, (byte) 0x30, (byte) 0x0f, (byte) 0x06, (byte) 0x03, - (byte) 0x55, (byte) 0x04, (byte) 0x03, (byte) 0x0c, (byte) 0x08, (byte) 0x54, - (byte) 0x45, (byte) 0x53, (byte) 0x54, (byte) 0x2d, (byte) 0x55, (byte) 0x53, - (byte) 0x52, (byte) 0x30, (byte) 0x59, (byte) 0x30, (byte) 0x13, (byte) 0x06, - (byte) 0x07, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0xce, (byte) 0x3d, - (byte) 0x02, (byte) 0x01, (byte) 0x06, (byte) 0x08, (byte) 0x2a, (byte) 0x86, - (byte) 0x48, (byte) 0xce, (byte) 0x3d, (byte) 0x03, (byte) 0x01, (byte) 0x07, - (byte) 0x03, (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x4a, (byte) 0xb8, - (byte) 0x60, (byte) 0x17, (byte) 0x40, (byte) 0x91, (byte) 0x30, (byte) 0xf7, - (byte) 0xdf, (byte) 0x36, (byte) 0x83, (byte) 0x31, (byte) 0xb5, (byte) 0x3a, - (byte) 0xf4, (byte) 0xd4, (byte) 0xa1, (byte) 0xce, (byte) 0xd5, (byte) 0x54, - (byte) 0x97, (byte) 0x93, (byte) 0x7e, (byte) 0x7b, (byte) 0x08, (byte) 0x63, - (byte) 0x37, (byte) 0x62, (byte) 0xf1, (byte) 0x4e, (byte) 0x6a, (byte) 0x2e, - (byte) 0x35, (byte) 0x4e, (byte) 0x9f, (byte) 0x48, (byte) 0xcd, (byte) 0x09, - (byte) 0x17, (byte) 0xb3, (byte) 0xc1, (byte) 0x58, (byte) 0x02, (byte) 0x49, - (byte) 0x7b, (byte) 0x4c, (byte) 0xf7, (byte) 0x9b, (byte) 0xbb, (byte) 0x1b, - (byte) 0x2b, (byte) 0x9c, (byte) 0xe9, (byte) 0x36, (byte) 0xc4, (byte) 0x00, - (byte) 0x81, (byte) 0x2c, (byte) 0x28, (byte) 0xd9, (byte) 0x6b, (byte) 0xad, - (byte) 0xe3, (byte) 0xe8, (byte) 0xa3, (byte) 0x7b, (byte) 0x30, (byte) 0x79, - (byte) 0x30, (byte) 0x09, (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, - (byte) 0x13, (byte) 0x04, (byte) 0x02, (byte) 0x30, (byte) 0x00, (byte) 0x30, - (byte) 0x2c, (byte) 0x06, (byte) 0x09, (byte) 0x60, (byte) 0x86, (byte) 0x48, - (byte) 0x01, (byte) 0x86, (byte) 0xf8, (byte) 0x42, (byte) 0x01, (byte) 0x0d, - (byte) 0x04, (byte) 0x1f, (byte) 0x16, (byte) 0x1d, (byte) 0x4f, (byte) 0x70, - (byte) 0x65, (byte) 0x6e, (byte) 0x53, (byte) 0x53, (byte) 0x4c, (byte) 0x20, - (byte) 0x47, (byte) 0x65, (byte) 0x6e, (byte) 0x65, (byte) 0x72, (byte) 0x61, - (byte) 0x74, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x43, (byte) 0x65, - (byte) 0x72, (byte) 0x74, (byte) 0x69, (byte) 0x66, (byte) 0x69, (byte) 0x63, - (byte) 0x61, (byte) 0x74, (byte) 0x65, (byte) 0x30, (byte) 0x1d, (byte) 0x06, - (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x0e, (byte) 0x04, (byte) 0x16, - (byte) 0x04, (byte) 0x14, (byte) 0xef, (byte) 0xf0, (byte) 0x15, (byte) 0xd7, - (byte) 0xc9, (byte) 0x3e, (byte) 0x9a, (byte) 0x73, (byte) 0xfa, (byte) 0x38, - (byte) 0xc5, (byte) 0x81, (byte) 0x84, (byte) 0x74, (byte) 0xd3, (byte) 0x83, - (byte) 0x74, (byte) 0x26, (byte) 0xf1, (byte) 0x0b, (byte) 0x30, (byte) 0x1f, - (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1d, (byte) 0x23, (byte) 0x04, - (byte) 0x18, (byte) 0x30, (byte) 0x16, (byte) 0x80, (byte) 0x14, (byte) 0x38, - (byte) 0x6a, (byte) 0x9b, (byte) 0xf8, (byte) 0x3c, (byte) 0x0d, (byte) 0x54, - (byte) 0x9f, (byte) 0xdf, (byte) 0xf8, (byte) 0x53, (byte) 0x32, (byte) 0xa8, - (byte) 0xf7, (byte) 0x09, (byte) 0x15, (byte) 0x08, (byte) 0x76, (byte) 0xab, - (byte) 0x8d, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x01, (byte) 0x0b, (byte) 0x05, (byte) 0x00, (byte) 0x03, (byte) 0x82, - (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0xa6, (byte) 0x6c, (byte) 0x18, - (byte) 0xa9, (byte) 0x67, (byte) 0x16, (byte) 0x6a, (byte) 0x9e, (byte) 0x23, - (byte) 0xb3, (byte) 0x2a, (byte) 0xb8, (byte) 0x16, (byte) 0x7b, (byte) 0xb4, - (byte) 0xc8, (byte) 0xbc, (byte) 0x51, (byte) 0xe0, (byte) 0x6f, (byte) 0x05, - (byte) 0x66, (byte) 0xa1, (byte) 0x6f, (byte) 0x96, (byte) 0xde, (byte) 0x5b, - (byte) 0x41, (byte) 0x60, (byte) 0xe5, (byte) 0x29, (byte) 0x99, (byte) 0x12, - (byte) 0xfc, (byte) 0xa9, (byte) 0x91, (byte) 0x23, (byte) 0xb7, (byte) 0x9e, - (byte) 0x00, (byte) 0x5f, (byte) 0x93, (byte) 0xd4, (byte) 0xf7, (byte) 0x27, - (byte) 0x29, (byte) 0x77, (byte) 0xfb, (byte) 0x53, (byte) 0x09, (byte) 0xdc, - (byte) 0xe9, (byte) 0xd0, (byte) 0x5c, (byte) 0x92, (byte) 0x6d, (byte) 0xb7, - (byte) 0xcf, (byte) 0x04, (byte) 0xab, (byte) 0xf1, (byte) 0x39, (byte) 0xb9, - (byte) 0x49, (byte) 0x23, (byte) 0x7c, (byte) 0x0f, (byte) 0x15, (byte) 0x27, - (byte) 0xcd, (byte) 0x65, (byte) 0x3c, (byte) 0x6b, (byte) 0x91, (byte) 0x42, - (byte) 0x5a, (byte) 0xfe, (byte) 0xbe, (byte) 0xb8, (byte) 0xa2, (byte) 0xfd, - (byte) 0x67, (byte) 0x43, (byte) 0x4b, (byte) 0xc9, (byte) 0x28, (byte) 0x65, - (byte) 0x1b, (byte) 0x82, (byte) 0x5b, (byte) 0x25, (byte) 0x20, (byte) 0x9b, - (byte) 0xea, (byte) 0x99, (byte) 0xbb, (byte) 0x66, (byte) 0xc1, (byte) 0x8e, - (byte) 0x46, (byte) 0x0b, (byte) 0x4e, (byte) 0x06, (byte) 0xdd, (byte) 0x50, - (byte) 0x51, (byte) 0x64, (byte) 0xe8, (byte) 0x83, (byte) 0x99, (byte) 0x8e, - (byte) 0x53, (byte) 0xe9, (byte) 0x48, (byte) 0x47, (byte) 0x0e, (byte) 0x08, - (byte) 0x5e, (byte) 0x0d, (byte) 0x4a, (byte) 0x54, (byte) 0x17, (byte) 0xc1, - (byte) 0xf8, (byte) 0xcf, (byte) 0xba, (byte) 0x5c, (byte) 0x38, (byte) 0x70, - (byte) 0x33, (byte) 0x31, (byte) 0x22, (byte) 0x03, (byte) 0x6f, (byte) 0x54, - (byte) 0x3c, (byte) 0x41, (byte) 0xf0, (byte) 0x89, (byte) 0x85, (byte) 0xbc, - (byte) 0x77, (byte) 0x3c, (byte) 0xe8, (byte) 0xec, (byte) 0xb4, (byte) 0x35, - (byte) 0x7a, (byte) 0xcc, (byte) 0x8c, (byte) 0x5f, (byte) 0xa1, (byte) 0xed, - (byte) 0xa6, (byte) 0x28, (byte) 0x14, (byte) 0xc7, (byte) 0x8a, (byte) 0xef, - (byte) 0x56, (byte) 0x26, (byte) 0x35, (byte) 0x46, (byte) 0xab, (byte) 0xb0, - (byte) 0x97, (byte) 0xd2, (byte) 0xbd, (byte) 0xa9, (byte) 0x6a, (byte) 0xe4, - (byte) 0x3e, (byte) 0x87, (byte) 0xfb, (byte) 0xe1, (byte) 0x09, (byte) 0x8d, - (byte) 0x33, (byte) 0x12, (byte) 0xcf, (byte) 0xf0, (byte) 0xc0, (byte) 0xb8, - (byte) 0x9b, (byte) 0x9f, (byte) 0xb1, (byte) 0xcb, (byte) 0xac, (byte) 0x76, - (byte) 0xa8, (byte) 0x05, (byte) 0x6b, (byte) 0xcc, (byte) 0x41, (byte) 0xd2, - (byte) 0x26, (byte) 0x73, (byte) 0xfa, (byte) 0x69, (byte) 0xd3, (byte) 0x1f, - (byte) 0xa9, (byte) 0x0c, (byte) 0x6a, (byte) 0xd6, (byte) 0xc9, (byte) 0x35, - (byte) 0xc5, (byte) 0xad, (byte) 0xa1, (byte) 0x98, (byte) 0xc9, (byte) 0x78, - (byte) 0xa0, (byte) 0xe8, (byte) 0x02, (byte) 0x69, (byte) 0x80, (byte) 0x44, - (byte) 0xd9, (byte) 0xe6, (byte) 0xe5, (byte) 0x26, (byte) 0x4f, (byte) 0xcf, - (byte) 0x38, (byte) 0xcb, (byte) 0x55, (byte) 0x8c, (byte) 0x7d, (byte) 0x3c, - (byte) 0xa8, (byte) 0x82, (byte) 0x69, (byte) 0xa3, (byte) 0xdf, (byte) 0x0a, - (byte) 0x79, (byte) 0x7b, (byte) 0xdd, (byte) 0x24, (byte) 0x6a, (byte) 0x21, - (byte) 0x7b, (byte) 0x20, (byte) 0x94, (byte) 0xcd, (byte) 0x15, (byte) 0x92, - (byte) 0xad, (byte) 0x4a, (byte) 0x72, (byte) 0x0b, (byte) 0x0e, (byte) 0xb2, - (byte) 0xc9 - }; - - private static final byte[] FAKE_KEY_3 = { - (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x78, (byte) 0x02, (byte) 0x01, - (byte) 0x00, (byte) 0x30, (byte) 0x0d, (byte) 0x06, (byte) 0x09, (byte) 0x2a, - (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, - (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, (byte) 0x04, (byte) 0x82, - (byte) 0x02, (byte) 0x62, (byte) 0x30, (byte) 0x82, (byte) 0x02, (byte) 0x5e, - (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x81, (byte) 0x81, - (byte) 0x00, (byte) 0xce, (byte) 0x29, (byte) 0xeb, (byte) 0xf6, (byte) 0x5b, - (byte) 0x25, (byte) 0xdc, (byte) 0xa1, (byte) 0xa6, (byte) 0x2c, (byte) 0x66, - (byte) 0xcb, (byte) 0x20, (byte) 0x90, (byte) 0x27, (byte) 0x86, (byte) 0x8a, - (byte) 0x44, (byte) 0x71, (byte) 0x50, (byte) 0xda, (byte) 0xd3, (byte) 0x02, - (byte) 0x77, (byte) 0x55, (byte) 0xe9, (byte) 0xe8, (byte) 0x08, (byte) 0xf3, - (byte) 0x36, (byte) 0x9a, (byte) 0xae, (byte) 0xab, (byte) 0x04, (byte) 0x6d, - (byte) 0x00, (byte) 0x99, (byte) 0xbf, (byte) 0x7d, (byte) 0x0f, (byte) 0x67, - (byte) 0x8b, (byte) 0x1d, (byte) 0xd4, (byte) 0x2b, (byte) 0x7c, (byte) 0xcb, - (byte) 0xcd, (byte) 0x33, (byte) 0xc7, (byte) 0x84, (byte) 0x30, (byte) 0xe2, - (byte) 0x45, (byte) 0x21, (byte) 0xb3, (byte) 0x75, (byte) 0xf5, (byte) 0x79, - (byte) 0x02, (byte) 0xda, (byte) 0x50, (byte) 0xa3, (byte) 0x8b, (byte) 0xce, - (byte) 0xc3, (byte) 0x8e, (byte) 0x0f, (byte) 0x25, (byte) 0xeb, (byte) 0x08, - (byte) 0x2c, (byte) 0xdd, (byte) 0x1c, (byte) 0xcf, (byte) 0xff, (byte) 0x3b, - (byte) 0xde, (byte) 0xb6, (byte) 0xaa, (byte) 0x2a, (byte) 0xa9, (byte) 0xc4, - (byte) 0x8a, (byte) 0x24, (byte) 0x24, (byte) 0xe6, (byte) 0x29, (byte) 0x0d, - (byte) 0x98, (byte) 0x4c, (byte) 0x32, (byte) 0xa1, (byte) 0x7b, (byte) 0x23, - (byte) 0x2b, (byte) 0x42, (byte) 0x30, (byte) 0xee, (byte) 0x78, (byte) 0x08, - (byte) 0x47, (byte) 0xad, (byte) 0xf2, (byte) 0x96, (byte) 0xd5, (byte) 0xf1, - (byte) 0x62, (byte) 0x42, (byte) 0x2d, (byte) 0x35, (byte) 0x19, (byte) 0xb4, - (byte) 0x3c, (byte) 0xc9, (byte) 0xc3, (byte) 0x5f, (byte) 0x03, (byte) 0x16, - (byte) 0x3a, (byte) 0x23, (byte) 0xac, (byte) 0xcb, (byte) 0xce, (byte) 0x9e, - (byte) 0x51, (byte) 0x2e, (byte) 0x6d, (byte) 0x02, (byte) 0x03, (byte) 0x01, - (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x81, (byte) 0x80, (byte) 0x16, - (byte) 0x59, (byte) 0xc3, (byte) 0x24, (byte) 0x1d, (byte) 0x33, (byte) 0x98, - (byte) 0x9c, (byte) 0xc9, (byte) 0xc8, (byte) 0x2c, (byte) 0x88, (byte) 0xbf, - (byte) 0x0a, (byte) 0x01, (byte) 0xce, (byte) 0xfb, (byte) 0x34, (byte) 0x7a, - (byte) 0x58, (byte) 0x7a, (byte) 0xb0, (byte) 0xbf, (byte) 0xa6, (byte) 0xb2, - (byte) 0x60, (byte) 0xbe, (byte) 0x70, (byte) 0x21, (byte) 0xf5, (byte) 0xfc, - (byte) 0x85, (byte) 0x0d, (byte) 0x33, (byte) 0x58, (byte) 0xa1, (byte) 0xe5, - (byte) 0x09, (byte) 0x36, (byte) 0x84, (byte) 0xb2, (byte) 0x04, (byte) 0x0a, - (byte) 0x02, (byte) 0xd3, (byte) 0x88, (byte) 0x1f, (byte) 0x0c, (byte) 0x2b, - (byte) 0x1d, (byte) 0xe9, (byte) 0x3d, (byte) 0xe7, (byte) 0x79, (byte) 0xf9, - (byte) 0x32, (byte) 0x5c, (byte) 0x8a, (byte) 0x75, (byte) 0x49, (byte) 0x12, - (byte) 0xe4, (byte) 0x05, (byte) 0x26, (byte) 0xd4, (byte) 0x2e, (byte) 0x9e, - (byte) 0x1f, (byte) 0xcc, (byte) 0x54, (byte) 0xad, (byte) 0x33, (byte) 0x8d, - (byte) 0x99, (byte) 0x00, (byte) 0xdc, (byte) 0xf5, (byte) 0xb4, (byte) 0xa2, - (byte) 0x2f, (byte) 0xba, (byte) 0xe5, (byte) 0x62, (byte) 0x30, (byte) 0x6d, - (byte) 0xe6, (byte) 0x3d, (byte) 0xeb, (byte) 0x24, (byte) 0xc2, (byte) 0xdc, - (byte) 0x5f, (byte) 0xb7, (byte) 0x16, (byte) 0x35, (byte) 0xa3, (byte) 0x98, - (byte) 0x98, (byte) 0xa8, (byte) 0xef, (byte) 0xe8, (byte) 0xc4, (byte) 0x96, - (byte) 0x6d, (byte) 0x38, (byte) 0xab, (byte) 0x26, (byte) 0x6d, (byte) 0x30, - (byte) 0xc2, (byte) 0xa0, (byte) 0x44, (byte) 0xe4, (byte) 0xff, (byte) 0x7e, - (byte) 0xbe, (byte) 0x7c, (byte) 0x33, (byte) 0xa5, (byte) 0x10, (byte) 0xad, - (byte) 0xd7, (byte) 0x1e, (byte) 0x13, (byte) 0x20, (byte) 0xb3, (byte) 0x1f, - (byte) 0x41, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xf1, (byte) 0x89, - (byte) 0x07, (byte) 0x0f, (byte) 0xe8, (byte) 0xcf, (byte) 0xab, (byte) 0x13, - (byte) 0x2a, (byte) 0x8f, (byte) 0x88, (byte) 0x80, (byte) 0x11, (byte) 0x9a, - (byte) 0x79, (byte) 0xb6, (byte) 0x59, (byte) 0x3a, (byte) 0x50, (byte) 0x6e, - (byte) 0x57, (byte) 0x37, (byte) 0xab, (byte) 0x2a, (byte) 0xd2, (byte) 0xaa, - (byte) 0xd9, (byte) 0x72, (byte) 0x73, (byte) 0xff, (byte) 0x8b, (byte) 0x47, - (byte) 0x76, (byte) 0xdd, (byte) 0xdc, (byte) 0xf5, (byte) 0x97, (byte) 0x44, - (byte) 0x3a, (byte) 0x78, (byte) 0xbe, (byte) 0x17, (byte) 0xb4, (byte) 0x22, - (byte) 0x6f, (byte) 0xe5, (byte) 0x23, (byte) 0x70, (byte) 0x1d, (byte) 0x10, - (byte) 0x5d, (byte) 0xba, (byte) 0x16, (byte) 0x81, (byte) 0xf1, (byte) 0x45, - (byte) 0xce, (byte) 0x30, (byte) 0xb4, (byte) 0xab, (byte) 0x80, (byte) 0xe4, - (byte) 0x98, (byte) 0x31, (byte) 0x02, (byte) 0x41, (byte) 0x00, (byte) 0xda, - (byte) 0x82, (byte) 0x9d, (byte) 0x3f, (byte) 0xca, (byte) 0x2f, (byte) 0xe1, - (byte) 0xd4, (byte) 0x86, (byte) 0x77, (byte) 0x48, (byte) 0xa6, (byte) 0xab, - (byte) 0xab, (byte) 0x1c, (byte) 0x42, (byte) 0x5c, (byte) 0xd5, (byte) 0xc7, - (byte) 0x46, (byte) 0x59, (byte) 0x91, (byte) 0x3f, (byte) 0xfc, (byte) 0xcc, - (byte) 0xec, (byte) 0xc2, (byte) 0x40, (byte) 0x12, (byte) 0x2c, (byte) 0x8d, - (byte) 0x1f, (byte) 0xa2, (byte) 0x18, (byte) 0x88, (byte) 0xee, (byte) 0x82, - (byte) 0x4a, (byte) 0x5a, (byte) 0x5e, (byte) 0x88, (byte) 0x20, (byte) 0xe3, - (byte) 0x7b, (byte) 0xe0, (byte) 0xd8, (byte) 0x3a, (byte) 0x52, (byte) 0x9a, - (byte) 0x26, (byte) 0x6a, (byte) 0x04, (byte) 0xec, (byte) 0xe8, (byte) 0xb9, - (byte) 0x48, (byte) 0x40, (byte) 0xe1, (byte) 0xe1, (byte) 0x83, (byte) 0xa6, - (byte) 0x67, (byte) 0xa6, (byte) 0xfd, (byte) 0x02, (byte) 0x41, (byte) 0x00, - (byte) 0x89, (byte) 0x72, (byte) 0x3e, (byte) 0xb0, (byte) 0x90, (byte) 0xfd, - (byte) 0x4c, (byte) 0x0e, (byte) 0xd6, (byte) 0x13, (byte) 0x63, (byte) 0xcb, - (byte) 0xed, (byte) 0x38, (byte) 0x88, (byte) 0xb6, (byte) 0x79, (byte) 0xc4, - (byte) 0x33, (byte) 0x6c, (byte) 0xf6, (byte) 0xf8, (byte) 0xd8, (byte) 0xd0, - (byte) 0xbf, (byte) 0x9d, (byte) 0x35, (byte) 0xac, (byte) 0x69, (byte) 0xd2, - (byte) 0x2b, (byte) 0xc1, (byte) 0xf9, (byte) 0x24, (byte) 0x7b, (byte) 0xce, - (byte) 0xcd, (byte) 0xcb, (byte) 0xa7, (byte) 0xb2, (byte) 0x7a, (byte) 0x0a, - (byte) 0x27, (byte) 0x19, (byte) 0xc9, (byte) 0xaf, (byte) 0x0d, (byte) 0x21, - (byte) 0x89, (byte) 0x88, (byte) 0x7c, (byte) 0xad, (byte) 0x9e, (byte) 0x8d, - (byte) 0x47, (byte) 0x6d, (byte) 0x3f, (byte) 0xce, (byte) 0x7b, (byte) 0xa1, - (byte) 0x74, (byte) 0xf1, (byte) 0xa0, (byte) 0xa1, (byte) 0x02, (byte) 0x41, - (byte) 0x00, (byte) 0xd9, (byte) 0xa8, (byte) 0xf5, (byte) 0xfe, (byte) 0xce, - (byte) 0xe6, (byte) 0x77, (byte) 0x6b, (byte) 0xfe, (byte) 0x2d, (byte) 0xe0, - (byte) 0x1e, (byte) 0xb6, (byte) 0x2e, (byte) 0x12, (byte) 0x4e, (byte) 0x40, - (byte) 0xaf, (byte) 0x6a, (byte) 0x7b, (byte) 0x37, (byte) 0x49, (byte) 0x2a, - (byte) 0x96, (byte) 0x25, (byte) 0x83, (byte) 0x49, (byte) 0xd4, (byte) 0x0c, - (byte) 0xc6, (byte) 0x78, (byte) 0x25, (byte) 0x24, (byte) 0x90, (byte) 0x90, - (byte) 0x06, (byte) 0x15, (byte) 0x9e, (byte) 0xfe, (byte) 0xf9, (byte) 0xdf, - (byte) 0x5b, (byte) 0xf3, (byte) 0x7e, (byte) 0x38, (byte) 0x70, (byte) 0xeb, - (byte) 0x57, (byte) 0xd0, (byte) 0xd9, (byte) 0xa7, (byte) 0x0e, (byte) 0x14, - (byte) 0xf7, (byte) 0x95, (byte) 0x68, (byte) 0xd5, (byte) 0xc8, (byte) 0xab, - (byte) 0x9d, (byte) 0x3a, (byte) 0x2b, (byte) 0x51, (byte) 0xf9, (byte) 0x02, - (byte) 0x41, (byte) 0x00, (byte) 0x96, (byte) 0xdf, (byte) 0xe9, (byte) 0x67, - (byte) 0x6c, (byte) 0xdc, (byte) 0x90, (byte) 0x14, (byte) 0xb4, (byte) 0x1d, - (byte) 0x22, (byte) 0x33, (byte) 0x4a, (byte) 0x31, (byte) 0xc1, (byte) 0x9d, - (byte) 0x2e, (byte) 0xff, (byte) 0x9a, (byte) 0x2a, (byte) 0x95, (byte) 0x4b, - (byte) 0x27, (byte) 0x74, (byte) 0xcb, (byte) 0x21, (byte) 0xc3, (byte) 0xd2, - (byte) 0x0b, (byte) 0xb2, (byte) 0x46, (byte) 0x87, (byte) 0xf8, (byte) 0x28, - (byte) 0x01, (byte) 0x8b, (byte) 0xd8, (byte) 0xb9, (byte) 0x4b, (byte) 0xcd, - (byte) 0x9a, (byte) 0x96, (byte) 0x41, (byte) 0x0e, (byte) 0x36, (byte) 0x6d, - (byte) 0x40, (byte) 0x42, (byte) 0xbc, (byte) 0xd9, (byte) 0xd3, (byte) 0x7b, - (byte) 0xbc, (byte) 0xa7, (byte) 0x92, (byte) 0x90, (byte) 0xdd, (byte) 0xa1, - (byte) 0x9c, (byte) 0xce, (byte) 0xa1, (byte) 0x87, (byte) 0x11, (byte) 0x51 - }; - - private boolean hasWifi() { - return getContext().getPackageManager().hasSystemFeature( - PackageManager.FEATURE_WIFI); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - if(!hasWifi()) { - return; - } - mWifiManager = (WifiManager) mContext - .getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - SystemUtil.runShellCommand("svc wifi enable"); - Thread.sleep(ENABLE_DELAY); - if (hasWifi()) { - assertTrue(mWifiManager.isWifiEnabled()); - } - } - - public void testSettersAndGetters() throws Exception { - if (!hasWifi()) { - return; - } - - WifiEnterpriseConfig config = new WifiEnterpriseConfig(); - assertTrue(config.getEapMethod() == Eap.NONE); - config.setEapMethod(Eap.PEAP); - assertTrue(config.getEapMethod() == Eap.PEAP); - config.setEapMethod(Eap.PWD); - assertTrue(config.getEapMethod() == Eap.PWD); - config.setEapMethod(Eap.TLS); - assertTrue(config.getEapMethod() == Eap.TLS); - config.setEapMethod(Eap.TTLS); - assertTrue(config.getEapMethod() == Eap.TTLS); - assertTrue(config.getPhase2Method() == Phase2.NONE); - config.setPhase2Method(Phase2.PAP); - assertTrue(config.getPhase2Method() == Phase2.PAP); - config.setPhase2Method(Phase2.MSCHAP); - assertTrue(config.getPhase2Method() == Phase2.MSCHAP); - config.setPhase2Method(Phase2.MSCHAPV2); - assertTrue(config.getPhase2Method() == Phase2.MSCHAPV2); - config.setPhase2Method(Phase2.GTC); - assertTrue(config.getPhase2Method() == Phase2.GTC); - config.setIdentity(IDENTITY); - assertTrue(config.getIdentity().equals(IDENTITY)); - config.setAnonymousIdentity(ANON_IDENTITY); - assertTrue(config.getAnonymousIdentity().equals(ANON_IDENTITY)); - config.setPassword(PASSWORD); - assertTrue(config.getPassword().equals(PASSWORD)); - CertificateFactory factory = CertificateFactory.getInstance("X.509"); - X509Certificate cert1 = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(FAKE_EC_1)); - X509Certificate cert2 = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(FAKE_EC_2)); - config.setCaCertificate(cert1); - assertTrue(config.getCaCertificate().getSerialNumber().equals(cert1.getSerialNumber())); - config.setCaCertificates(new X509Certificate[]{cert1, cert2}); - X509Certificate[] certs = config.getCaCertificates(); - assertTrue(cert1.getSerialNumber().equals(certs[0].getSerialNumber())); - assertTrue(cert2.getSerialNumber().equals(certs[1].getSerialNumber())); - - X509Certificate clientCert = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(FAKE_EC_3)); - KeyFactory kf = KeyFactory.getInstance("RSA"); - PrivateKey clientKey = kf.generatePrivate(new PKCS8EncodedKeySpec(FAKE_KEY_3)); - - config.setClientKeyEntry(clientKey, clientCert); - X509Certificate testClientCert = config.getClientCertificate(); - X509Certificate[] testClientCertChain = config.getClientCertificateChain(); - assertTrue(clientCert.getSerialNumber().equals(testClientCert.getSerialNumber())); - assertTrue(testClientCertChain.length == 1); - assertTrue(testClientCertChain[0] == testClientCert); - - config.setClientKeyEntry(null, null); - assertTrue(config.getClientCertificate() == null); - assertTrue(config.getClientCertificateChain() == null); - - config.setClientKeyEntryWithCertificateChain(clientKey, - new X509Certificate[]{clientCert, cert1}); - testClientCert = config.getClientCertificate(); - testClientCertChain = config.getClientCertificateChain(); - assertTrue(clientCert.getSerialNumber().equals(testClientCert.getSerialNumber())); - assertTrue(testClientCertChain.length == 2); - assertTrue(testClientCertChain[0] == testClientCert); - assertTrue(testClientCertChain[1] == cert1); - - config.setSubjectMatch(SUBJECT_MATCH); - assertTrue(config.getSubjectMatch().equals(SUBJECT_MATCH)); - // Hotspot 2.0 related attributes - config.setPlmn(PLMN); - assertTrue(config.getPlmn().equals(PLMN)); - config.setRealm(REALM); - assertTrue(config.getRealm().equals(REALM)); - config.setAltSubjectMatch(ALT_SUBJECT_MATCH); - assertTrue(config.getAltSubjectMatch().equals(ALT_SUBJECT_MATCH)); - config.setDomainSuffixMatch(DOM_SUBJECT_MATCH); - assertTrue(config.getDomainSuffixMatch().equals(DOM_SUBJECT_MATCH)); - } - - public void testEnterpriseConfigDoesNotPrintPassword() { - if(!hasWifi()) { - return; - } - WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); - final String identity = "IdentityIsOkayToBeDisplayedHere"; - final String password = "PasswordIsNotOkayToBeDisplayedHere"; - enterpriseConfig.setIdentity(identity); - enterpriseConfig.setPassword(password); - final String stringRepresentation = enterpriseConfig.toString(); - assertTrue(stringRepresentation.contains(identity)); - assertFalse(stringRepresentation.contains(password)); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiFeature.java b/tests/cts/net/src/android/net/wifi/cts/WifiFeature.java deleted file mode 100644 index 63fa1dd94c..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiFeature.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.content.Context; -import android.content.pm.PackageManager; - -public class WifiFeature { - static boolean isWifiSupported(Context context) { - PackageManager packageManager = context.getPackageManager(); - return packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI); - } - - static boolean isP2pSupported(Context context) { - PackageManager packageManager = context.getPackageManager(); - return packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java deleted file mode 100644 index 9d9b2a3902..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiInfoTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.wifi.SupplicantState; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.WifiLock; -import android.net.wifi.WifiSsid; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -import com.android.compatibility.common.util.PollingCheck; -import com.android.compatibility.common.util.SystemUtil; - -import java.util.concurrent.Callable; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiInfoTest extends AndroidTestCase { - private static class MySync { - int expectedState = STATE_NULL; - } - - private WifiManager mWifiManager; - private WifiLock mWifiLock; - private static MySync mMySync; - - private static final int STATE_NULL = 0; - private static final int STATE_WIFI_CHANGING = 1; - private static final int STATE_WIFI_CHANGED = 2; - - private static final String TAG = "WifiInfoTest"; - private static final int TIMEOUT_MSEC = 6000; - private static final int WAIT_MSEC = 60; - private static final int DURATION = 10000; - private IntentFilter mIntentFilter; - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { - synchronized (mMySync) { - mMySync.expectedState = STATE_WIFI_CHANGED; - mMySync.notify(); - } - } - } - }; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - mMySync = new MySync(); - mIntentFilter = new IntentFilter(); - mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - - mContext.registerReceiver(mReceiver, mIntentFilter); - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - mWifiLock = mWifiManager.createWifiLock(TAG); - mWifiLock.acquire(); - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - Thread.sleep(DURATION); - assertTrue(mWifiManager.isWifiEnabled()); - mMySync.expectedState = STATE_NULL; - } - - @Override - protected void tearDown() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - super.tearDown(); - return; - } - mWifiLock.release(); - mContext.unregisterReceiver(mReceiver); - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - Thread.sleep(DURATION); - super.tearDown(); - } - - private void setWifiEnabled(boolean enable) throws Exception { - synchronized (mMySync) { - mMySync.expectedState = STATE_WIFI_CHANGING; - if (enable) { - SystemUtil.runShellCommand("svc wifi enable"); - } else { - SystemUtil.runShellCommand("svc wifi disable"); - } - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (System.currentTimeMillis() < timeout - && mMySync.expectedState == STATE_WIFI_CHANGING) - mMySync.wait(WAIT_MSEC); - } - } - - public void testWifiInfoProperties() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - // this test case should in Wifi environment - WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); - - assertNotNull(wifiInfo); - assertNotNull(wifiInfo.toString()); - SupplicantState.isValidState(wifiInfo.getSupplicantState()); - WifiInfo.getDetailedStateOf(SupplicantState.DISCONNECTED); - String ssid = wifiInfo.getSSID(); - if (!ssid.startsWith("0x") && !ssid.equals(WifiSsid.NONE)) { - // Non-hex string should be quoted - assertTrue(ssid.charAt(0) == '"'); - assertTrue(ssid.charAt(ssid.length() - 1) == '"'); - } - - wifiInfo.getBSSID(); - wifiInfo.getFrequency(); - wifiInfo.getIpAddress(); - wifiInfo.getLinkSpeed(); - wifiInfo.getPasspointFqdn(); - wifiInfo.getPasspointProviderFriendlyName(); - wifiInfo.getTxLinkSpeedMbps(); - wifiInfo.getRxLinkSpeedMbps(); - wifiInfo.getRssi(); - wifiInfo.getHiddenSSID(); - wifiInfo.getMacAddress(); - setWifiEnabled(false); - - PollingCheck.check("getNetworkId not -1", 20000, new Callable() { - @Override - public Boolean call() throws Exception { - WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); - return wifiInfo.getNetworkId() == -1; - } - }); - - PollingCheck.check("getWifiState not disabled", 20000, new Callable() { - @Override - public Boolean call() throws Exception { - return mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED; - } - }); - } - -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java deleted file mode 100644 index 6ac92d409c..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - -import android.content.Context; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.WifiLock; -import android.platform.test.annotations.AppModeFull; -import android.test.AndroidTestCase; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiLockTest extends AndroidTestCase { - - private static final String WIFI_TAG = "WifiLockTest"; - - /** - * Verify acquire and release of High Performance wifi locks - */ - public void testHiPerfWifiLock() { - testWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF); - } - - /** - * Verify acquire and release of Low latency wifi locks - */ - public void testLowLatencyWifiLock() { - testWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY); - } - - private void testWifiLock(int lockType) { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - WifiManager wm = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - WifiLock wl = wm.createWifiLock(lockType, WIFI_TAG); - - wl.setReferenceCounted(true); - assertFalse(wl.isHeld()); - wl.acquire(); - assertTrue(wl.isHeld()); - wl.release(); - assertFalse(wl.isHeld()); - wl.acquire(); - wl.acquire(); - assertTrue(wl.isHeld()); - wl.release(); - assertTrue(wl.isHeld()); - wl.release(); - assertFalse(wl.isHeld()); - assertNotNull(wl.toString()); - try { - wl.release(); - fail("should throw out exception because release is called" - +" a greater number of times than acquire"); - } catch (RuntimeException e) { - // expected - } - - wl = wm.createWifiLock(lockType, WIFI_TAG); - wl.setReferenceCounted(false); - assertFalse(wl.isHeld()); - wl.acquire(); - assertTrue(wl.isHeld()); - wl.release(); - assertFalse(wl.isHeld()); - wl.acquire(); - wl.acquire(); - assertTrue(wl.isHeld()); - wl.release(); - assertFalse(wl.isHeld()); - assertNotNull(wl.toString()); - // releasing again after release: but ignored for non-referenced locks - wl.release(); - } -} diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java deleted file mode 100644 index 5b8a8d5cc4..0000000000 --- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java +++ /dev/null @@ -1,1056 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.cts; - - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiManager.TxPacketCountListener; -import android.net.wifi.WifiManager.WifiLock; -import android.net.wifi.hotspot2.PasspointConfiguration; -import android.net.wifi.hotspot2.pps.Credential; -import android.net.wifi.hotspot2.pps.HomeSp; -import android.os.Process; -import android.os.SystemClock; -import android.os.UserHandle; -import android.platform.test.annotations.AppModeFull; -import android.provider.Settings; -import android.support.test.uiautomator.UiDevice; -import android.test.AndroidTestCase; -import android.text.TextUtils; -import android.util.ArraySet; -import android.util.Log; - -import androidx.test.InstrumentationRegistry; - -import com.android.compatibility.common.util.SystemUtil; - -import java.lang.StringBuilder; -import java.net.HttpURLConnection; -import java.net.URL; -import java.security.MessageDigest; -import java.security.cert.X509Certificate; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiManagerTest extends AndroidTestCase { - private static class MySync { - int expectedState = STATE_NULL; - } - - private WifiManager mWifiManager; - private WifiLock mWifiLock; - private static MySync mMySync; - private List mScanResults = null; - private NetworkInfo mNetworkInfo; - private Object mLOHSLock = new Object(); - private UiDevice mUiDevice; - - // Please refer to WifiManager - private static final int MIN_RSSI = -100; - private static final int MAX_RSSI = -55; - - private static final int STATE_NULL = 0; - private static final int STATE_WIFI_CHANGING = 1; - private static final int STATE_WIFI_ENABLED = 2; - private static final int STATE_WIFI_DISABLED = 3; - private static final int STATE_SCANNING = 4; - private static final int STATE_SCAN_DONE = 5; - - private static final String TAG = "WifiManagerTest"; - private static final String SSID1 = "\"WifiManagerTest\""; - // A full single scan duration is about 6-7 seconds if country code is set - // to US. If country code is set to world mode (00), we would expect a scan - // duration of roughly 8 seconds. So we set scan timeout as 9 seconds here. - private static final int SCAN_TIMEOUT_MSEC = 9000; - private static final int TIMEOUT_MSEC = 6000; - private static final int WAIT_MSEC = 60; - private static final int DURATION = 10000; - private static final int DURATION_SCREEN_TOGGLE = 2000; - private static final int WIFI_SCAN_TEST_INTERVAL_MILLIS = 60 * 1000; - private static final int WIFI_SCAN_TEST_CACHE_DELAY_MILLIS = 3 * 60 * 1000; - private static final int WIFI_SCAN_TEST_ITERATIONS = 5; - - private static final int ENFORCED_NUM_NETWORK_SUGGESTIONS_PER_APP = 50; - - private static final String TEST_PAC_URL = "http://www.example.com/proxy.pac"; - private static final String MANAGED_PROVISIONING_PACKAGE_NAME - = "com.android.managedprovisioning"; - - private IntentFilter mIntentFilter; - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String action = intent.getAction(); - if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { - - synchronized (mMySync) { - if (intent.getBooleanExtra(WifiManager.EXTRA_RESULTS_UPDATED, false)) { - mScanResults = mWifiManager.getScanResults(); - } else { - mScanResults = null; - } - mMySync.expectedState = STATE_SCAN_DONE; - mMySync.notifyAll(); - } - } else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { - int newState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, - WifiManager.WIFI_STATE_UNKNOWN); - synchronized (mMySync) { - if (newState == WifiManager.WIFI_STATE_ENABLED) { - Log.d(TAG, "*** New WiFi state is ENABLED ***"); - mMySync.expectedState = STATE_WIFI_ENABLED; - mMySync.notifyAll(); - } else if (newState == WifiManager.WIFI_STATE_DISABLED) { - Log.d(TAG, "*** New WiFi state is DISABLED ***"); - mMySync.expectedState = STATE_WIFI_DISABLED; - mMySync.notifyAll(); - } - } - } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { - synchronized (mMySync) { - mNetworkInfo = - (NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); - if (mNetworkInfo.getState() == NetworkInfo.State.CONNECTED) - mMySync.notifyAll(); - } - } - } - }; - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - mMySync = new MySync(); - mIntentFilter = new IntentFilter(); - mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); - mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); - mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION); - mIntentFilter.addAction(WifiManager.ACTION_PICK_WIFI_NETWORK); - - mContext.registerReceiver(mReceiver, mIntentFilter); - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - mWifiLock = mWifiManager.createWifiLock(TAG); - mWifiLock.acquire(); - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); - turnScreenOnNoDelay(); - Thread.sleep(DURATION); - assertTrue(mWifiManager.isWifiEnabled()); - synchronized (mMySync) { - mMySync.expectedState = STATE_NULL; - } - } - - @Override - protected void tearDown() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - super.tearDown(); - return; - } - if (!mWifiManager.isWifiEnabled()) - setWifiEnabled(true); - mWifiLock.release(); - mContext.unregisterReceiver(mReceiver); - Thread.sleep(DURATION); - super.tearDown(); - } - - private void setWifiEnabled(boolean enable) throws Exception { - synchronized (mMySync) { - if (mWifiManager.isWifiEnabled() != enable) { - // the new state is different, we expect it to change - mMySync.expectedState = STATE_WIFI_CHANGING; - } else { - mMySync.expectedState = (enable ? STATE_WIFI_ENABLED : STATE_WIFI_DISABLED); - } - // now trigger the change using shell commands. - SystemUtil.runShellCommand("svc wifi " + (enable ? "enable" : "disable")); - waitForExpectedWifiState(enable); - } - } - - private void waitForExpectedWifiState(boolean enabled) throws InterruptedException { - synchronized (mMySync) { - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - int expected = (enabled ? STATE_WIFI_ENABLED : STATE_WIFI_DISABLED); - while (System.currentTimeMillis() < timeout - && mMySync.expectedState != expected) { - mMySync.wait(WAIT_MSEC); - } - } - } - - // Get the current scan status from sticky broadcast. - private boolean isScanCurrentlyAvailable() { - boolean isAvailable = false; - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiManager.WIFI_SCAN_AVAILABLE); - Intent intent = mContext.registerReceiver(null, intentFilter); - assertNotNull(intent); - if (intent.getAction().equals(WifiManager.WIFI_SCAN_AVAILABLE)) { - int state = intent.getIntExtra( - WifiManager.EXTRA_SCAN_AVAILABLE, WifiManager.WIFI_STATE_UNKNOWN); - if (state == WifiManager.WIFI_STATE_ENABLED) { - isAvailable = true; - } else if (state == WifiManager.WIFI_STATE_DISABLED) { - isAvailable = false; - } - } - return isAvailable; - } - - private void startScan() throws Exception { - synchronized (mMySync) { - mMySync.expectedState = STATE_SCANNING; - mScanResults = null; - assertTrue(mWifiManager.startScan()); - long timeout = System.currentTimeMillis() + SCAN_TIMEOUT_MSEC; - while (System.currentTimeMillis() < timeout && mMySync.expectedState == STATE_SCANNING) - mMySync.wait(WAIT_MSEC); - } - } - - private void connectWifi() throws Exception { - synchronized (mMySync) { - if (mNetworkInfo.getState() == NetworkInfo.State.CONNECTED) return; - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (System.currentTimeMillis() < timeout - && mNetworkInfo.getState() != NetworkInfo.State.CONNECTED) - mMySync.wait(WAIT_MSEC); - assertTrue(mNetworkInfo.getState() == NetworkInfo.State.CONNECTED); - } - } - - private boolean existSSID(String ssid) { - for (final WifiConfiguration w : mWifiManager.getConfiguredNetworks()) { - if (w.SSID.equals(ssid)) - return true; - } - return false; - } - - private int findConfiguredNetworks(String SSID, List networks) { - for (final WifiConfiguration w : networks) { - if (w.SSID.equals(SSID)) - return networks.indexOf(w); - } - return -1; - } - - /** - * Test creation of WifiManager Lock. - */ - public void testWifiManagerLock() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - final String TAG = "Test"; - assertNotNull(mWifiManager.createWifiLock(TAG)); - assertNotNull(mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG)); - } - - /** - * Test wifi scanning when location scan is turned off. - */ - public void testWifiManagerScanWhenWifiOffLocationTurnedOn() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - if (!hasLocationFeature()) { - Log.d(TAG, "Skipping test as location is not supported"); - return; - } - if (!isLocationEnabled()) { - fail("Please enable location for this test - since Marshmallow WiFi scan results are" - + " empty when location is disabled!"); - } - setWifiEnabled(false); - Thread.sleep(DURATION); - startScan(); - if (mWifiManager.isScanAlwaysAvailable() && isScanCurrentlyAvailable()) { - // Make sure at least one AP is found. - assertNotNull("mScanResult should not be null!", mScanResults); - assertFalse("empty scan results!", mScanResults.isEmpty()); - } else { - // Make sure no scan results are available. - assertNull("mScanResult should be null!", mScanResults); - } - final String TAG = "Test"; - assertNotNull(mWifiManager.createWifiLock(TAG)); - assertNotNull(mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, TAG)); - } - - /** - * test point of wifiManager properties: - * 1.enable properties - * 2.DhcpInfo properties - * 3.wifi state - * 4.ConnectionInfo - */ - public void testWifiManagerProperties() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - setWifiEnabled(true); - assertTrue(mWifiManager.isWifiEnabled()); - assertNotNull(mWifiManager.getDhcpInfo()); - assertEquals(WifiManager.WIFI_STATE_ENABLED, mWifiManager.getWifiState()); - mWifiManager.getConnectionInfo(); - setWifiEnabled(false); - assertFalse(mWifiManager.isWifiEnabled()); - } - - /** - * Test WiFi scan timestamp - fails when WiFi scan timestamps are inconsistent with - * {@link SystemClock#elapsedRealtime()} on device.

- * To run this test in cts-tradefed: - * run cts --class android.net.wifi.cts.WifiManagerTest --method testWifiScanTimestamp - */ - public void testWifiScanTimestamp() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - Log.d(TAG, "Skipping test as WiFi is not supported"); - return; - } - if (!hasLocationFeature()) { - Log.d(TAG, "Skipping test as location is not supported"); - return; - } - if (!isLocationEnabled()) { - fail("Please enable location for this test - since Marshmallow WiFi scan results are" - + " empty when location is disabled!"); - } - if (!mWifiManager.isWifiEnabled()) { - setWifiEnabled(true); - } - // Scan multiple times to make sure scan timestamps increase with device timestamp. - for (int i = 0; i < WIFI_SCAN_TEST_ITERATIONS; ++i) { - startScan(); - // Make sure at least one AP is found. - assertTrue("mScanResult should not be null. This may be due to a scan timeout", - mScanResults != null); - assertFalse("empty scan results!", mScanResults.isEmpty()); - long nowMillis = SystemClock.elapsedRealtime(); - // Keep track of how many APs are fresh in one scan. - int numFreshAps = 0; - for (ScanResult result : mScanResults) { - long scanTimeMillis = TimeUnit.MICROSECONDS.toMillis(result.timestamp); - if (Math.abs(nowMillis - scanTimeMillis) < WIFI_SCAN_TEST_CACHE_DELAY_MILLIS) { - numFreshAps++; - } - } - // At least half of the APs in the scan should be fresh. - int numTotalAps = mScanResults.size(); - String msg = "Stale AP count: " + (numTotalAps - numFreshAps) + ", fresh AP count: " - + numFreshAps; - assertTrue(msg, numFreshAps * 2 >= mScanResults.size()); - if (i < WIFI_SCAN_TEST_ITERATIONS - 1) { - // Wait before running next iteration. - Thread.sleep(WIFI_SCAN_TEST_INTERVAL_MILLIS); - } - } - } - - // Return true if location is enabled. - private boolean isLocationEnabled() { - return Settings.Secure.getInt(getContext().getContentResolver(), - Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF) != - Settings.Secure.LOCATION_MODE_OFF; - } - - // Returns true if the device has location feature. - private boolean hasLocationFeature() { - return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION); - } - - private boolean hasAutomotiveFeature() { - return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); - } - - public void testSignal() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - final int numLevels = 9; - int expectLevel = 0; - assertEquals(expectLevel, WifiManager.calculateSignalLevel(MIN_RSSI, numLevels)); - assertEquals(numLevels - 1, WifiManager.calculateSignalLevel(MAX_RSSI, numLevels)); - expectLevel = 4; - assertEquals(expectLevel, WifiManager.calculateSignalLevel((MIN_RSSI + MAX_RSSI) / 2, - numLevels)); - int rssiA = 4; - int rssiB = 5; - assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) < 0); - rssiB = 4; - assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) == 0); - rssiA = 5; - rssiB = 4; - assertTrue(WifiManager.compareSignalLevel(rssiA, rssiB) > 0); - } - - private int getTxPacketCount() throws Exception { - final AtomicInteger ret = new AtomicInteger(-1); - - mWifiManager.getTxPacketCount(new TxPacketCountListener() { - @Override - public void onSuccess(int count) { - ret.set(count); - } - @Override - public void onFailure(int reason) { - ret.set(0); - } - }); - - long timeout = System.currentTimeMillis() + TIMEOUT_MSEC; - while (ret.get() < 0 && System.currentTimeMillis() < timeout) - Thread.sleep(WAIT_MSEC); - assertTrue(ret.get() >= 0); - return ret.get(); - } - - /** - * The new WiFi watchdog requires kernel/driver to export some packet loss - * counters. This CTS tests whether those counters are correctly exported. - * To pass this CTS test, a connected WiFi link is required. - */ - public void testWifiWatchdog() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - // Make sure WiFi is enabled - if (!mWifiManager.isWifiEnabled()) { - setWifiEnabled(true); - Thread.sleep(DURATION); - } - assertTrue(mWifiManager.isWifiEnabled()); - - // give the test a chance to autoconnect - Thread.sleep(DURATION); - if (mNetworkInfo.getState() != NetworkInfo.State.CONNECTED) { - // this test requires a connectable network be configured - fail("This test requires a wifi network connection."); - } - - // This will generate a distinct stack trace if the initial connection fails. - connectWifi(); - - int i = 0; - for (; i < 15; i++) { - // Wait for a WiFi connection - connectWifi(); - - // Read TX packet counter - int txcount1 = getTxPacketCount(); - - // Do some network operations - HttpURLConnection connection = null; - try { - URL url = new URL("http://www.google.com/"); - connection = (HttpURLConnection) url.openConnection(); - connection.setInstanceFollowRedirects(false); - connection.setConnectTimeout(TIMEOUT_MSEC); - connection.setReadTimeout(TIMEOUT_MSEC); - connection.setUseCaches(false); - connection.getInputStream(); - } catch (Exception e) { - // ignore - } finally { - if (connection != null) connection.disconnect(); - } - - // Read TX packet counter again and make sure it increases - int txcount2 = getTxPacketCount(); - - if (txcount2 > txcount1) { - break; - } else { - Thread.sleep(DURATION); - } - } - assertTrue(i < 15); - } - - public class TestLocalOnlyHotspotCallback extends WifiManager.LocalOnlyHotspotCallback { - Object hotspotLock; - WifiManager.LocalOnlyHotspotReservation reservation = null; - boolean onStartedCalled = false; - boolean onStoppedCalled = false; - boolean onFailedCalled = false; - int failureReason = -1; - - TestLocalOnlyHotspotCallback(Object lock) { - hotspotLock = lock; - } - - @Override - public void onStarted(WifiManager.LocalOnlyHotspotReservation r) { - synchronized (hotspotLock) { - reservation = r; - onStartedCalled = true; - hotspotLock.notify(); - } - } - - @Override - public void onStopped() { - synchronized (hotspotLock) { - onStoppedCalled = true; - hotspotLock.notify(); - } - } - - @Override - public void onFailed(int reason) { - synchronized (hotspotLock) { - onFailedCalled = true; - failureReason = reason; - hotspotLock.notify(); - } - } - } - - private TestLocalOnlyHotspotCallback startLocalOnlyHotspot() { - // Location mode must be enabled for this test - if (!isLocationEnabled()) { - fail("Please enable location for this test"); - } - - TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(mLOHSLock); - synchronized (mLOHSLock) { - try { - mWifiManager.startLocalOnlyHotspot(callback, null); - // now wait for callback - mLOHSLock.wait(DURATION); - } catch (InterruptedException e) { - } - // check if we got the callback - assertTrue(callback.onStartedCalled); - assertNotNull(callback.reservation.getWifiConfiguration()); - if (!hasAutomotiveFeature()) { - assertEquals( - WifiConfiguration.AP_BAND_2GHZ, - callback.reservation.getWifiConfiguration().apBand); - } - assertFalse(callback.onFailedCalled); - assertFalse(callback.onStoppedCalled); - } - return callback; - } - - private void stopLocalOnlyHotspot(TestLocalOnlyHotspotCallback callback, boolean wifiEnabled) { - synchronized (mMySync) { - // we are expecting a new state - mMySync.expectedState = STATE_WIFI_CHANGING; - - // now shut down LocalOnlyHotspot - callback.reservation.close(); - - try { - waitForExpectedWifiState(wifiEnabled); - } catch (InterruptedException e) {} - } - } - - /** - * Verify that calls to startLocalOnlyHotspot succeed with proper permissions. - * - * Note: Location mode must be enabled for this test. - */ - public void testStartLocalOnlyHotspotSuccess() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - // check that softap mode is supported by the device - if (!mWifiManager.isPortableHotspotSupported()) { - return; - } - - boolean wifiEnabled = mWifiManager.isWifiEnabled(); - - TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot(); - - // add sleep to avoid calling stopLocalOnlyHotspot before TetherController initialization. - // TODO: remove this sleep as soon as b/124330089 is fixed. - try { - Log.d(TAG, "Sleep for 2 seconds"); - Thread.sleep(2000); - } catch (InterruptedException e) { - Log.d(TAG, "Thread InterruptedException!"); - } - - stopLocalOnlyHotspot(callback, wifiEnabled); - - // wifi should either stay on, or come back on - assertEquals(wifiEnabled, mWifiManager.isWifiEnabled()); - } - - /** - * Verify calls to deprecated API's all fail for non-settings apps targeting >= Q SDK. - */ - public void testDeprecatedApis() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - setWifiEnabled(true); - connectWifi(); // ensures that there is at-least 1 saved network on the device. - - WifiConfiguration wifiConfiguration = new WifiConfiguration(); - wifiConfiguration.SSID = SSID1; - wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); - - assertEquals(WifiConfiguration.INVALID_NETWORK_ID, - mWifiManager.addNetwork(wifiConfiguration)); - assertEquals(WifiConfiguration.INVALID_NETWORK_ID, - mWifiManager.updateNetwork(wifiConfiguration)); - assertFalse(mWifiManager.enableNetwork(0, true)); - assertFalse(mWifiManager.disableNetwork(0)); - assertFalse(mWifiManager.removeNetwork(0)); - assertFalse(mWifiManager.disconnect()); - assertFalse(mWifiManager.reconnect()); - assertFalse(mWifiManager.reassociate()); - assertTrue(mWifiManager.getConfiguredNetworks().isEmpty()); - - boolean wifiEnabled = mWifiManager.isWifiEnabled(); - // now we should fail to toggle wifi state. - assertFalse(mWifiManager.setWifiEnabled(!wifiEnabled)); - Thread.sleep(DURATION); - assertEquals(wifiEnabled, mWifiManager.isWifiEnabled()); - } - - /** - * Verify that applications can only have one registered LocalOnlyHotspot request at a time. - * - * Note: Location mode must be enabled for this test. - */ - public void testStartLocalOnlyHotspotSingleRequestByApps() { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - // check that softap mode is supported by the device - if (!mWifiManager.isPortableHotspotSupported()) { - return; - } - - boolean caughtException = false; - - boolean wifiEnabled = mWifiManager.isWifiEnabled(); - - TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot(); - - // now make a second request - this should fail. - TestLocalOnlyHotspotCallback callback2 = new TestLocalOnlyHotspotCallback(mLOHSLock); - try { - mWifiManager.startLocalOnlyHotspot(callback2, null); - } catch (IllegalStateException e) { - Log.d(TAG, "Caught the IllegalStateException we expected: called startLOHS twice"); - caughtException = true; - } - if (!caughtException) { - // second start did not fail, should clean up the hotspot. - stopLocalOnlyHotspot(callback2, wifiEnabled); - } - assertTrue(caughtException); - - // add sleep to avoid calling stopLocalOnlyHotspot before TetherController initialization. - // TODO: remove this sleep as soon as b/124330089 is fixed. - try { - Log.d(TAG, "Sleep for 2 seconds"); - Thread.sleep(2000); - } catch (InterruptedException e) { - Log.d(TAG, "Thread InterruptedException!"); - } - - stopLocalOnlyHotspot(callback, wifiEnabled); - } - - /** - * Verify that the {@link android.Manifest.permission#NETWORK_STACK} permission is never held by - * any package. - *

- * No apps should ever attempt to acquire this permission, since it would give those - * apps extremely broad access to connectivity functionality. - */ - public void testNetworkStackPermission() { - final PackageManager pm = getContext().getPackageManager(); - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.NETWORK_STACK - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - for (PackageInfo pi : holding) { - fail("The NETWORK_STACK permission must not be held by " + pi.packageName - + " and must be revoked for security reasons"); - } - } - - /** - * Verify that the {@link android.Manifest.permission#NETWORK_SETTINGS} permission is - * never held by any package. - *

- * Only Settings, SysUi, NetworkStack and shell apps should ever attempt to acquire - * this permission, since it would give those apps extremely broad access to connectivity - * functionality. The permission is intended to be granted to only those apps with direct user - * access and no others. - */ - public void testNetworkSettingsPermission() { - final PackageManager pm = getContext().getPackageManager(); - - final ArraySet allowedPackages = new ArraySet(); - final ArraySet allowedUIDs = new ArraySet(); - // explicitly add allowed UIDs - allowedUIDs.add(Process.SYSTEM_UID); - allowedUIDs.add(Process.SHELL_UID); - allowedUIDs.add(Process.PHONE_UID); - allowedUIDs.add(Process.NETWORK_STACK_UID); - allowedUIDs.add(Process.NFC_UID); - - // only quick settings is allowed to bind to the BIND_QUICK_SETTINGS_TILE permission, using - // this fact to determined allowed package name for sysui. This is a signature permission, - // so allow any package with this permission. - final List sysuiPackages = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.BIND_QUICK_SETTINGS_TILE - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - for (PackageInfo info : sysuiPackages) { - allowedPackages.add(info.packageName); - } - - // the captive portal flow also currently holds the NETWORK_SETTINGS permission - final Intent intent = new Intent(ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN); - final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS); - if (ri != null) { - allowedPackages.add(ri.activityInfo.packageName); - } - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.NETWORK_SETTINGS - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - StringBuilder stringBuilder = new StringBuilder(); - for (PackageInfo pi : holding) { - String packageName = pi.packageName; - - // this is an explicitly allowed package - if (allowedPackages.contains(packageName)) continue; - - // now check if the packages are from allowed UIDs - int uid = -1; - try { - uid = pm.getPackageUidAsUser(packageName, UserHandle.USER_SYSTEM); - } catch (PackageManager.NameNotFoundException e) { - continue; - } - if (!allowedUIDs.contains(uid)) { - stringBuilder.append("The NETWORK_SETTINGS permission must not be held by " - + packageName + ":" + uid + " and must be revoked for security reasons\n"); - } - } - if (stringBuilder.length() > 0) { - fail(stringBuilder.toString()); - } - } - - /** - * Verify that the {@link android.Manifest.permission#NETWORK_SETUP_WIZARD} permission is - * only held by the device setup wizard application. - *

- * Only the SetupWizard app should ever attempt to acquire this - * permission, since it would give those apps extremely broad access to connectivity - * functionality. The permission is intended to be granted to only the device setup wizard. - */ - public void testNetworkSetupWizardPermission() { - final ArraySet allowedPackages = new ArraySet(); - - final PackageManager pm = getContext().getPackageManager(); - - final Intent intent = new Intent(Intent.ACTION_MAIN); - intent.addCategory(Intent.CATEGORY_SETUP_WIZARD); - final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS); - String validPkg = ""; - if (ri != null) { - allowedPackages.add(ri.activityInfo.packageName); - validPkg = ri.activityInfo.packageName; - } - - final Intent preIntent = new Intent("com.android.setupwizard.OEM_PRE_SETUP"); - preIntent.addCategory(Intent.CATEGORY_DEFAULT); - final ResolveInfo preRi = pm - .resolveActivity(preIntent, PackageManager.MATCH_DISABLED_COMPONENTS); - String prePackageName = ""; - if (null != preRi) { - prePackageName = preRi.activityInfo.packageName; - } - - final Intent postIntent = new Intent("com.android.setupwizard.OEM_POST_SETUP"); - postIntent.addCategory(Intent.CATEGORY_DEFAULT); - final ResolveInfo postRi = pm - .resolveActivity(postIntent, PackageManager.MATCH_DISABLED_COMPONENTS); - String postPackageName = ""; - if (null != postRi) { - postPackageName = postRi.activityInfo.packageName; - } - if (!TextUtils.isEmpty(prePackageName) && !TextUtils.isEmpty(postPackageName) - && prePackageName.equals(postPackageName)) { - allowedPackages.add(prePackageName); - } - - final List holding = pm.getPackagesHoldingPermissions(new String[]{ - android.Manifest.permission.NETWORK_SETUP_WIZARD - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - for (PackageInfo pi : holding) { - if (!allowedPackages.contains(pi.packageName)) { - fail("The NETWORK_SETUP_WIZARD permission must not be held by " + pi.packageName - + " and must be revoked for security reasons [" + validPkg + "]"); - } - } - } - - /** - * Verify that the {@link android.Manifest.permission#NETWORK_MANAGED_PROVISIONING} permission - * is only held by the device managed provisioning application. - *

- * Only the ManagedProvisioning app should ever attempt to acquire this - * permission, since it would give those apps extremely broad access to connectivity - * functionality. The permission is intended to be granted to only the device managed - * provisioning. - */ - public void testNetworkManagedProvisioningPermission() { - final PackageManager pm = getContext().getPackageManager(); - - // TODO(b/115980767): Using hardcoded package name. Need a better mechanism to find the - // managed provisioning app. - // Ensure that the package exists. - final Intent intent = new Intent(Intent.ACTION_MAIN); - intent.setPackage(MANAGED_PROVISIONING_PACKAGE_NAME); - final ResolveInfo ri = pm.resolveActivity(intent, PackageManager.MATCH_DISABLED_COMPONENTS); - String validPkg = ""; - if (ri != null) { - validPkg = ri.activityInfo.packageName; - } - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.NETWORK_MANAGED_PROVISIONING - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - for (PackageInfo pi : holding) { - if (!Objects.equals(pi.packageName, validPkg)) { - fail("The NETWORK_MANAGED_PROVISIONING permission must not be held by " - + pi.packageName + " and must be revoked for security reasons [" - + validPkg +"]"); - } - } - } - - /** - * Verify that the {@link android.Manifest.permission#WIFI_SET_DEVICE_MOBILITY_STATE} permission - * is held by at most one application. - */ - public void testWifiSetDeviceMobilityStatePermission() { - final PackageManager pm = getContext().getPackageManager(); - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.WIFI_SET_DEVICE_MOBILITY_STATE - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - - List uniquePackageNames = holding - .stream() - .map(pi -> pi.packageName) - .distinct() - .collect(Collectors.toList()); - - if (uniquePackageNames.size() > 1) { - fail("The WIFI_SET_DEVICE_MOBILITY_STATE permission must not be held by more than one " - + "application, but is held by " + uniquePackageNames.size() + " applications: " - + String.join(", ", uniquePackageNames)); - } - } - - /** - * Verify that the {@link android.Manifest.permission#NETWORK_CARRIER_PROVISIONING} permission - * is held by at most one application. - */ - public void testNetworkCarrierProvisioningPermission() { - final PackageManager pm = getContext().getPackageManager(); - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.NETWORK_CARRIER_PROVISIONING - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - - List uniquePackageNames = holding - .stream() - .map(pi -> pi.packageName) - .distinct() - .collect(Collectors.toList()); - - if (uniquePackageNames.size() > 2) { - fail("The NETWORK_CARRIER_PROVISIONING permission must not be held by more than two " - + "applications, but is held by " + uniquePackageNames.size() + " applications: " - + String.join(", ", uniquePackageNames)); - } - } - - /** - * Verify that the {@link android.Manifest.permission#WIFI_UPDATE_USABILITY_STATS_SCORE} - * permission is held by at most one application. - */ - public void testUpdateWifiUsabilityStatsScorePermission() { - final PackageManager pm = getContext().getPackageManager(); - - final List holding = pm.getPackagesHoldingPermissions(new String[] { - android.Manifest.permission.WIFI_UPDATE_USABILITY_STATS_SCORE - }, PackageManager.MATCH_UNINSTALLED_PACKAGES); - - List uniquePackageNames = holding - .stream() - .map(pi -> pi.packageName) - .distinct() - .collect(Collectors.toList()); - - if (uniquePackageNames.size() > 1) { - fail("The WIFI_UPDATE_USABILITY_STATS_SCORE permission must not be held by more than " - + "one application, but is held by " + uniquePackageNames.size() + " applications: " - + String.join(", ", uniquePackageNames)); - } - } - - private void turnScreenOnNoDelay() throws Exception { - mUiDevice.executeShellCommand("input keyevent KEYCODE_WAKEUP"); - mUiDevice.executeShellCommand("wm dismiss-keyguard"); - } - - private void turnScreenOn() throws Exception { - turnScreenOnNoDelay(); - // Since the screen on/off intent is ordered, they will not be sent right now. - Thread.sleep(DURATION_SCREEN_TOGGLE); - } - - private void turnScreenOff() throws Exception { - mUiDevice.executeShellCommand("input keyevent KEYCODE_SLEEP"); - // Since the screen on/off intent is ordered, they will not be sent right now. - Thread.sleep(DURATION_SCREEN_TOGGLE); - } - - /** - * Verify that Wi-Fi scanning is not turned off when the screen turns off while wifi is disabled - * but location is on. - * @throws Exception - */ - public void testScreenOffDoesNotTurnOffWifiScanningWhenWifiDisabled() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - if (!hasLocationFeature()) { - // skip the test if location is not supported - return; - } - if (!isLocationEnabled()) { - fail("Please enable location for this test - since Marshmallow WiFi scan results are" - + " empty when location is disabled!"); - } - if(!mWifiManager.isScanAlwaysAvailable()) { - fail("Please enable Wi-Fi scanning for this test!"); - } - setWifiEnabled(false); - turnScreenOn(); - assertWifiScanningIsOn(); - // Toggle screen and verify Wi-Fi scanning is still on. - turnScreenOff(); - assertWifiScanningIsOn(); - turnScreenOn(); - assertWifiScanningIsOn(); - } - - /** - * Verify that Wi-Fi scanning is not turned off when the screen turns off while wifi is enabled. - * @throws Exception - */ - public void testScreenOffDoesNotTurnOffWifiScanningWhenWifiEnabled() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - if (!hasLocationFeature()) { - // skip the test if location is not supported - return; - } - if (!isLocationEnabled()) { - fail("Please enable location for this test - since Marshmallow WiFi scan results are" - + " empty when location is disabled!"); - } - if(!mWifiManager.isScanAlwaysAvailable()) { - fail("Please enable Wi-Fi scanning for this test!"); - } - setWifiEnabled(true); - turnScreenOn(); - assertWifiScanningIsOn(); - // Toggle screen and verify Wi-Fi scanning is still on. - turnScreenOff(); - assertWifiScanningIsOn(); - turnScreenOn(); - assertWifiScanningIsOn(); - } - - /** - * Verify that the platform supports a reasonable number of suggestions per app. - * @throws Exception - */ - public void testMaxNumberOfNetworkSuggestionsPerApp() throws Exception { - if (!WifiFeature.isWifiSupported(getContext())) { - // skip the test if WiFi is not supported - return; - } - assertTrue(mWifiManager.getMaxNumberOfNetworkSuggestionsPerApp() - > ENFORCED_NUM_NETWORK_SUGGESTIONS_PER_APP); - } - - private void assertWifiScanningIsOn() { - if(!mWifiManager.isScanAlwaysAvailable()) { - fail("Wi-Fi scanning should be on."); - } - } -} diff --git a/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java b/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java deleted file mode 100644 index 639db8a7c3..0000000000 --- a/tests/cts/net/src/android/net/wifi/p2p/cts/WifiP2pConfigTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.p2p.cts; - -import android.net.MacAddress; -import android.net.wifi.p2p.WifiP2pConfig; -import android.net.wifi.p2p.WifiP2pGroup; -import android.test.AndroidTestCase; - -public class WifiP2pConfigTest extends AndroidTestCase { - static final String TEST_NETWORK_NAME = "DIRECT-xy-Hello"; - static final String TEST_PASSPHRASE = "8etterW0r1d"; - static final int TEST_OWNER_BAND = WifiP2pConfig.GROUP_OWNER_BAND_5GHZ; - static final int TEST_OWNER_FREQ = 2447; - static final String TEST_DEVICE_ADDRESS = "aa:bb:cc:dd:ee:ff"; - - public void testWifiP2pConfigBuilderForPersist() { - WifiP2pConfig.Builder builder = new WifiP2pConfig.Builder(); - builder.setNetworkName(TEST_NETWORK_NAME) - .setPassphrase(TEST_PASSPHRASE) - .setGroupOperatingBand(TEST_OWNER_BAND) - .setDeviceAddress(MacAddress.fromString(TEST_DEVICE_ADDRESS)) - .enablePersistentMode(true); - WifiP2pConfig config = builder.build(); - - assertTrue(config.deviceAddress.equals(TEST_DEVICE_ADDRESS)); - assertTrue(config.networkName.equals(TEST_NETWORK_NAME)); - assertTrue(config.passphrase.equals(TEST_PASSPHRASE)); - assertEquals(config.groupOwnerBand, TEST_OWNER_BAND); - assertEquals(config.netId, WifiP2pGroup.PERSISTENT_NET_ID); - } - - public void testWifiP2pConfigBuilderForNonPersist() { - WifiP2pConfig.Builder builder = new WifiP2pConfig.Builder(); - builder.setNetworkName(TEST_NETWORK_NAME) - .setPassphrase(TEST_PASSPHRASE) - .setGroupOperatingFrequency(TEST_OWNER_FREQ) - .setDeviceAddress(MacAddress.fromString(TEST_DEVICE_ADDRESS)) - .enablePersistentMode(false); - WifiP2pConfig config = builder.build(); - - assertTrue(config.deviceAddress.equals(TEST_DEVICE_ADDRESS)); - assertTrue(config.networkName.equals(TEST_NETWORK_NAME)); - assertTrue(config.passphrase.equals(TEST_PASSPHRASE)); - assertEquals(config.groupOwnerBand, TEST_OWNER_FREQ); - assertEquals(config.netId, WifiP2pGroup.TEMPORARY_NET_ID); - } -} diff --git a/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java b/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java deleted file mode 100644 index 07d5718044..0000000000 --- a/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.rtt.cts; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.location.LocationManager; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiManager; -import android.net.wifi.rtt.RangingResult; -import android.net.wifi.rtt.RangingResultCallback; -import android.net.wifi.rtt.WifiRttManager; -import android.os.Handler; -import android.os.HandlerExecutor; -import android.os.HandlerThread; -import android.test.AndroidTestCase; - -import com.android.compatibility.common.util.SystemUtil; - -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.TimeUnit; - -/** - * Base class for Wi-Fi RTT CTS test cases. Provides a uniform configuration and event management - * facility. - */ -public class TestBase extends AndroidTestCase { - protected static final String TAG = "WifiRttCtsTests"; - - // wait for Wi-Fi RTT to become available - private static final int WAIT_FOR_RTT_CHANGE_SECS = 10; - - // wait for Wi-Fi scan results to become available - private static final int WAIT_FOR_SCAN_RESULTS_SECS = 20; - - protected WifiRttManager mWifiRttManager; - protected WifiManager mWifiManager; - private LocationManager mLocationManager; - private WifiManager.WifiLock mWifiLock; - - private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest"); - protected final Executor mExecutor; - { - mHandlerThread.start(); - mExecutor = new HandlerExecutor(new Handler(mHandlerThread.getLooper())); - } - - /** - * Returns a flag indicating whether or not Wi-Fi RTT should be tested. Wi-Fi RTT - * should be tested if the feature is supported on the current device. - */ - static boolean shouldTestWifiRtt(Context context) { - final PackageManager pm = context.getPackageManager(); - return pm.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - if (!shouldTestWifiRtt(getContext())) { - return; - } - - mLocationManager = (LocationManager) getContext().getSystemService( - Context.LOCATION_SERVICE); - assertTrue("RTT testing requires Location to be enabled", - mLocationManager.isLocationEnabled()); - - mWifiRttManager = (WifiRttManager) getContext().getSystemService( - Context.WIFI_RTT_RANGING_SERVICE); - assertNotNull("Wi-Fi RTT Manager", mWifiRttManager); - - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull("Wi-Fi Manager", mWifiManager); - mWifiLock = mWifiManager.createWifiLock(TAG); - mWifiLock.acquire(); - if (!mWifiManager.isWifiEnabled()) { - SystemUtil.runShellCommand("svc wifi enable"); - } - - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED); - WifiRttBroadcastReceiver receiver = new WifiRttBroadcastReceiver(); - mContext.registerReceiver(receiver, intentFilter); - if (!mWifiRttManager.isAvailable()) { - assertTrue("Timeout waiting for Wi-Fi RTT to change status", - receiver.waitForStateChange()); - assertTrue("Wi-Fi RTT is not available (should be)", mWifiRttManager.isAvailable()); - } - } - - @Override - protected void tearDown() throws Exception { - if (!shouldTestWifiRtt(getContext())) { - super.tearDown(); - return; - } - - super.tearDown(); - } - - class WifiRttBroadcastReceiver extends BroadcastReceiver { - private CountDownLatch mBlocker = new CountDownLatch(1); - - @Override - public void onReceive(Context context, Intent intent) { - if (WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED.equals(intent.getAction())) { - mBlocker.countDown(); - } - } - - boolean waitForStateChange() throws InterruptedException { - return mBlocker.await(WAIT_FOR_RTT_CHANGE_SECS, TimeUnit.SECONDS); - } - } - - class WifiScansBroadcastReceiver extends BroadcastReceiver { - private CountDownLatch mBlocker = new CountDownLatch(1); - - @Override - public void onReceive(Context context, Intent intent) { - if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())) { - mBlocker.countDown(); - } - } - - boolean waitForStateChange() throws InterruptedException { - return mBlocker.await(WAIT_FOR_SCAN_RESULTS_SECS, TimeUnit.SECONDS); - } - } - - class ResultCallback extends RangingResultCallback { - private CountDownLatch mBlocker = new CountDownLatch(1); - private int mCode; // 0: success, otherwise RangingResultCallback STATUS_CODE_*. - private List mResults; - - @Override - public void onRangingFailure(int code) { - mCode = code; - mResults = null; // not necessary since intialized to null - but for completeness - mBlocker.countDown(); - } - - @Override - public void onRangingResults(List results) { - mCode = 0; // not necessary since initialized to 0 - but for completeness - mResults = results; - mBlocker.countDown(); - } - - /** - * Waits for the listener callback to be called - or an error (timeout, interruption). - * Returns true on callback called, false on error (timeout, interruption). - */ - boolean waitForCallback() throws InterruptedException { - return mBlocker.await(WAIT_FOR_RTT_CHANGE_SECS, TimeUnit.SECONDS); - } - - /** - * Returns the code of the callback operation. Will be 0 for success (onRangingResults - * called), else (if onRangingFailure called) will be one of the STATUS_CODE_* values. - */ - int getCode() { - return mCode; - } - - /** - * Returns the list of ranging results. In cases of error (getCode() != 0) will return null. - */ - List getResults() { - return mResults; - } - } - - /** - * Start a scan and return a list of observed ScanResults (APs). - */ - protected List scanAps() throws InterruptedException { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); - WifiScansBroadcastReceiver receiver = new WifiScansBroadcastReceiver(); - mContext.registerReceiver(receiver, intentFilter); - - mWifiManager.startScan(); - receiver.waitForStateChange(); - mContext.unregisterReceiver(receiver); - return mWifiManager.getScanResults(); - } - - /** - * Start a scan and return a test AP which supports IEEE 802.11mc and which has the highest - * RSSI. Will perform N (parameterized) scans and get the best AP across both scans. - * - * Returns null if test AP is not found in the specified number of scans. - * - * @param numScanRetries Maximum number of scans retries (in addition to first scan). - */ - protected ScanResult scanForTestAp(int numScanRetries) - throws InterruptedException { - int scanCount = 0; - ScanResult bestTestAp = null; - while (scanCount <= numScanRetries) { - for (ScanResult scanResult : scanAps()) { - if (!scanResult.is80211mcResponder()) { - continue; - } - if (bestTestAp == null || scanResult.level > bestTestAp.level) { - bestTestAp = scanResult; - } - } - - scanCount++; - } - - return bestTestAp; - } -} diff --git a/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java b/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java deleted file mode 100644 index f71cadba7e..0000000000 --- a/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi.rtt.cts; - -import android.net.wifi.ScanResult; -import android.net.wifi.rtt.RangingRequest; -import android.net.wifi.rtt.RangingResult; -import android.platform.test.annotations.AppModeFull; - -import com.android.compatibility.common.util.DeviceReportLog; -import com.android.compatibility.common.util.ResultType; -import com.android.compatibility.common.util.ResultUnit; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Wi-Fi RTT CTS test: range to all available Access Points which support IEEE 802.11mc. - */ -@AppModeFull(reason = "Cannot get WifiManager in instant app mode") -public class WifiRttTest extends TestBase { - // Number of scans to do while searching for APs supporting IEEE 802.11mc - private static final int NUM_SCANS_SEARCHING_FOR_IEEE80211MC_AP = 2; - - // Number of RTT measurements per AP - private static final int NUM_OF_RTT_ITERATIONS = 10; - - // Maximum failure rate of RTT measurements (percentage) - private static final int MAX_FAILURE_RATE_PERCENT = 10; - - // Maximum variation from the average measurement (measures consistency) - private static final int MAX_VARIATION_FROM_AVERAGE_DISTANCE_MM = 1000; - - // Minimum valid RSSI value - private static final int MIN_VALID_RSSI = -100; - - /** - * Test Wi-Fi RTT ranging operation: - * - Scan for visible APs for the test AP (which is validated to support IEEE 802.11mc) - * - Perform N (constant) RTT operations - * - Validate: - * - Failure ratio < threshold (constant) - * - Result margin < threshold (constant) - */ - public void testRangingToTestAp() throws InterruptedException { - if (!shouldTestWifiRtt(getContext())) { - return; - } - - // Scan for IEEE 802.11mc supporting APs - ScanResult testAp = scanForTestAp(NUM_SCANS_SEARCHING_FOR_IEEE80211MC_AP); - assertTrue( - "Cannot find any test APs which support RTT / IEEE 802.11mc - please verify that " - + "your test setup includes them!", - testAp != null); - - // Perform RTT operations - RangingRequest request = new RangingRequest.Builder().addAccessPoint(testAp).build(); - List allResults = new ArrayList<>(); - int numFailures = 0; - int distanceSum = 0; - int distanceMin = 0; - int distanceMax = 0; - int[] statuses = new int[NUM_OF_RTT_ITERATIONS]; - int[] distanceMms = new int[NUM_OF_RTT_ITERATIONS]; - int[] distanceStdDevMms = new int[NUM_OF_RTT_ITERATIONS]; - int[] rssis = new int[NUM_OF_RTT_ITERATIONS]; - int[] numAttempted = new int[NUM_OF_RTT_ITERATIONS]; - int[] numSuccessful = new int[NUM_OF_RTT_ITERATIONS]; - long[] timestampsMs = new long[NUM_OF_RTT_ITERATIONS]; - byte[] lastLci = null; - byte[] lastLcr = null; - for (int i = 0; i < NUM_OF_RTT_ITERATIONS; ++i) { - ResultCallback callback = new ResultCallback(); - mWifiRttManager.startRanging(request, mExecutor, callback); - assertTrue("Wi-Fi RTT results: no callback on iteration " + i, - callback.waitForCallback()); - - List currentResults = callback.getResults(); - assertTrue("Wi-Fi RTT results: null results (onRangingFailure) on iteration " + i, - currentResults != null); - assertTrue("Wi-Fi RTT results: unexpected # of results (expect 1) on iteration " + i, - currentResults.size() == 1); - RangingResult result = currentResults.get(0); - assertTrue("Wi-Fi RTT results: invalid result (wrong BSSID) entry on iteration " + i, - result.getMacAddress().toString().equals(testAp.BSSID)); - assertEquals( - "Wi-Fi RTT results: invalid result (non-null PeerHandle) entry on iteration " - + i, null, result.getPeerHandle()); - - allResults.add(result); - int status = result.getStatus(); - statuses[i] = status; - if (status == RangingResult.STATUS_SUCCESS) { - distanceSum += result.getDistanceMm(); - if (i == 0) { - distanceMin = result.getDistanceMm(); - distanceMax = result.getDistanceMm(); - } else { - distanceMin = Math.min(distanceMin, result.getDistanceMm()); - distanceMax = Math.max(distanceMax, result.getDistanceMm()); - } - - assertTrue("Wi-Fi RTT results: invalid RSSI on iteration " + i, - result.getRssi() >= MIN_VALID_RSSI); - - distanceMms[i - numFailures] = result.getDistanceMm(); - distanceStdDevMms[i - numFailures] = result.getDistanceStdDevMm(); - rssis[i - numFailures] = result.getRssi(); - numAttempted[i - numFailures] = result.getNumAttemptedMeasurements(); - numSuccessful[i - numFailures] = result.getNumSuccessfulMeasurements(); - timestampsMs[i - numFailures] = result.getRangingTimestampMillis(); - - byte[] currentLci = result.getLci(); - byte[] currentLcr = result.getLcr(); - if (i - numFailures > 0) { - assertTrue("Wi-Fi RTT results: invalid result (LCI mismatch) on iteration " + i, - Arrays.equals(currentLci, lastLci)); - assertTrue("Wi-Fi RTT results: invalid result (LCR mismatch) on iteration " + i, - Arrays.equals(currentLcr, lastLcr)); - } - lastLci = currentLci; - lastLcr = currentLcr; - } else { - numFailures++; - } - } - - // Save results to log - int numGoodResults = NUM_OF_RTT_ITERATIONS - numFailures; - DeviceReportLog reportLog = new DeviceReportLog(TAG, "testRangingToTestAp"); - reportLog.addValues("status_codes", statuses, ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.addValues("distance_mm", Arrays.copyOf(distanceMms, numGoodResults), - ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.addValues("distance_stddev_mm", Arrays.copyOf(distanceStdDevMms, numGoodResults), - ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.addValues("rssi_dbm", Arrays.copyOf(rssis, numGoodResults), ResultType.NEUTRAL, - ResultUnit.NONE); - reportLog.addValues("num_attempted", Arrays.copyOf(numAttempted, numGoodResults), - ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.addValues("num_successful", Arrays.copyOf(numSuccessful, numGoodResults), - ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.addValues("timestamps", Arrays.copyOf(timestampsMs, numGoodResults), - ResultType.NEUTRAL, ResultUnit.NONE); - reportLog.submit(); - - // Analyze results - assertTrue("Wi-Fi RTT failure rate exceeds threshold: FAIL=" + numFailures + ", ITERATIONS=" - + NUM_OF_RTT_ITERATIONS, - numFailures <= NUM_OF_RTT_ITERATIONS * MAX_FAILURE_RATE_PERCENT / 100); - if (numFailures != NUM_OF_RTT_ITERATIONS) { - double distanceAvg = distanceSum / (NUM_OF_RTT_ITERATIONS - numFailures); - assertTrue("Wi-Fi RTT: Variation (max direction) exceeds threshold", - (distanceMax - distanceAvg) <= MAX_VARIATION_FROM_AVERAGE_DISTANCE_MM); - assertTrue("Wi-Fi RTT: Variation (min direction) exceeds threshold", - (distanceAvg - distanceMin) <= MAX_VARIATION_FROM_AVERAGE_DISTANCE_MM); - for (int i = 0; i < numGoodResults; ++i) { - assertNotSame("Number of attempted measurements is 0", 0, numAttempted[i]); - assertNotSame("Number of successful measurements is 0", 0, numSuccessful[i]); - } - } - } - - /** - * Validate that when a request contains more range operations than allowed (by API) that we - * get an exception. - */ - public void testRequestTooLarge() { - if (!shouldTestWifiRtt(getContext())) { - return; - } - - ScanResult dummy = new ScanResult(); - dummy.BSSID = "00:01:02:03:04:05"; - - RangingRequest.Builder builder = new RangingRequest.Builder(); - for (int i = 0; i < RangingRequest.getMaxPeers() - 2; ++i) { - builder.addAccessPoint(dummy); - } - - List scanResults = new ArrayList<>(); - scanResults.add(dummy); - scanResults.add(dummy); - scanResults.add(dummy); - - builder.addAccessPoints(scanResults); - - try { - mWifiRttManager.startRanging(builder.build(), mExecutor, new ResultCallback()); - } catch (IllegalArgumentException e) { - return; - } - - assertTrue( - "Did not receive expected IllegalArgumentException when tried to range to too " - + "many peers", - false); - } -}