Revert "[RTT] Modify CTS tests to use associated AP information"

This reverts commit 47d58e2a69c7438c95b4ed72a450a80066bd399c.

The revert restores the older method of test AP selction: hard
code the name of the test AP. Subsequent CLs will update to
preferred test AP selection method.

Bug: 74518964
Test: atest WifiRttTest (with rest of CL stack)
Change-Id: Iab71978607aeaf37babdb1afdaeca5c114ccdbf7
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
index adbe0f6..b235d96 100644
--- a/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java
+++ b/tests/cts/net/src/android/net/wifi/rtt/cts/TestBase.java
@@ -21,9 +21,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.location.LocationManager;
-import android.net.NetworkInfo;
 import android.net.wifi.ScanResult;
-import android.net.wifi.SupplicantState;
 import android.net.wifi.WifiManager;
 import android.net.wifi.rtt.RangingResult;
 import android.net.wifi.rtt.RangingResultCallback;
@@ -45,8 +43,9 @@
 public class TestBase extends AndroidTestCase {
     protected static final String TAG = "WifiRttCtsTests";
 
-    // wait for Wi-Fi to enable and/or connect
-    private static final int WAIT_FOR_WIFI_ENABLE_SECS = 10;
+    // The SSID of the test AP which supports IEEE 802.11mc
+    // TODO b/74518964: finalize correct method to refer to an AP in the test lab
+    static final String SSID_OF_TEST_AP = "standalone_rtt";
 
     // wait for Wi-Fi RTT to become available
     private static final int WAIT_FOR_RTT_CHANGE_SECS = 10;
@@ -59,10 +58,6 @@
     private LocationManager mLocationManager;
     private WifiManager.WifiLock mWifiLock;
 
-    protected IntentFilter mRttIntent;
-    protected IntentFilter mWifiStateIntent;
-    protected IntentFilter mWifiConnectedIntent;
-
     private final HandlerThread mHandlerThread = new HandlerThread("SingleDeviceTest");
     protected final Executor mExecutor;
     {
@@ -98,43 +93,22 @@
                 Context.WIFI_RTT_RANGING_SERVICE);
         assertNotNull("Wi-Fi RTT Manager", mWifiRttManager);
 
-        mRttIntent = new IntentFilter();
-        mRttIntent.addAction(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED);
-
-        mWifiStateIntent = new IntentFilter();
-        mWifiStateIntent.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
-
-        mWifiConnectedIntent = new IntentFilter();
-        mWifiConnectedIntent.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
-
         mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
         assertNotNull("Wi-Fi Manager", mWifiManager);
         mWifiLock = mWifiManager.createWifiLock(TAG);
         mWifiLock.acquire();
-        assertTrue("Location scans must be enabled", mWifiManager.isScanAlwaysAvailable());
         if (!mWifiManager.isWifiEnabled()) {
             mWifiManager.setWifiEnabled(true);
-            WifiEnableBroadcastReceiver receiver = new WifiEnableBroadcastReceiver(true);
-            mContext.registerReceiver(receiver, mWifiStateIntent);
-            receiver.waitForDesiredState();
-            mContext.unregisterReceiver(receiver);
         }
 
-        if (!mWifiManager.getConnectionInfo().getSupplicantState().equals(
-                SupplicantState.COMPLETED)) {
-            WifiConnectedBroadcastReceiver receiver = new WifiConnectedBroadcastReceiver();
-            mContext.registerReceiver(receiver, mWifiConnectedIntent);
-            receiver.waitForConnected();
-            mContext.unregisterReceiver(receiver);
-        }
-
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED);
+        WifiRttBroadcastReceiver receiver = new WifiRttBroadcastReceiver();
+        mContext.registerReceiver(receiver, intentFilter);
         if (!mWifiRttManager.isAvailable()) {
-            WifiRttBroadcastReceiver receiver = new WifiRttBroadcastReceiver();
-            mContext.registerReceiver(receiver, mRttIntent);
             assertTrue("Timeout waiting for Wi-Fi RTT to change status",
                     receiver.waitForStateChange());
             assertTrue("Wi-Fi RTT is not available (should be)", mWifiRttManager.isAvailable());
-            mContext.unregisterReceiver(receiver);
         }
     }
 
@@ -148,77 +122,33 @@
         super.tearDown();
     }
 
-    private class SyncBroadcastReceiver extends BroadcastReceiver {
+    class WifiRttBroadcastReceiver extends BroadcastReceiver {
         private CountDownLatch mBlocker = new CountDownLatch(1);
-        private String mAction;
-        private int mTimeout;
-
-        SyncBroadcastReceiver(String action, int timeout) {
-            mAction = action;
-            mTimeout = timeout;
-        }
 
         @Override
         public void onReceive(Context context, Intent intent) {
-            if (mAction.equals(intent.getAction())) {
+            if (WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED.equals(intent.getAction())) {
                 mBlocker.countDown();
             }
         }
 
         boolean waitForStateChange() throws InterruptedException {
-            return mBlocker.await(mTimeout, TimeUnit.SECONDS);
-        }
-    };
-
-    class WifiEnableBroadcastReceiver extends BroadcastReceiver {
-        private CountDownLatch mBlocker = new CountDownLatch(1);
-        private boolean mDesiredState;
-
-        WifiEnableBroadcastReceiver(boolean desiredState) {
-            mDesiredState = desiredState;
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
-                if (mWifiManager.isWifiEnabled() == mDesiredState) {
-                    mBlocker.countDown();
-                }
-            }
-        }
-
-        boolean waitForDesiredState() throws InterruptedException {
-            return mBlocker.await(WAIT_FOR_WIFI_ENABLE_SECS, TimeUnit.SECONDS);
+            return mBlocker.await(WAIT_FOR_RTT_CHANGE_SECS, TimeUnit.SECONDS);
         }
     }
 
-    class WifiConnectedBroadcastReceiver extends BroadcastReceiver {
+    class WifiScansBroadcastReceiver extends BroadcastReceiver {
         private CountDownLatch mBlocker = new CountDownLatch(1);
 
         @Override
         public void onReceive(Context context, Intent intent) {
-            if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
-                NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
-                if (ni.getState() == NetworkInfo.State.CONNECTED) {
-                    mBlocker.countDown();
-                }
+            if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())) {
+                mBlocker.countDown();
             }
         }
 
-        boolean waitForConnected() throws InterruptedException {
-            return mBlocker.await(WAIT_FOR_WIFI_ENABLE_SECS, TimeUnit.SECONDS);
-        }
-    }
-
-    class WifiRttBroadcastReceiver extends SyncBroadcastReceiver {
-        WifiRttBroadcastReceiver() {
-            super(WifiRttManager.ACTION_WIFI_RTT_STATE_CHANGED, WAIT_FOR_RTT_CHANGE_SECS);
-        }
-    }
-
-    class WifiScansBroadcastReceiver extends SyncBroadcastReceiver {
-        WifiScansBroadcastReceiver() {
-            super(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION, WAIT_FOR_SCAN_RESULTS_SECS);
+        boolean waitForStateChange() throws InterruptedException {
+            return mBlocker.await(WAIT_FOR_SCAN_RESULTS_SECS, TimeUnit.SECONDS);
         }
     }
 
@@ -287,10 +217,10 @@
      *
      * Returns null if test AP is not found in the specified number of scans.
      *
-     * @param bssid The BSSID of the test AP
+     * @param ssid The SSID of the test AP
      * @param maxScanRetries Maximum number of scans retries (in addition to first scan).
      */
-    protected ScanResult scanForTestAp(String bssid, int maxScanRetries)
+    protected ScanResult scanForTestAp(String ssid, int maxScanRetries)
             throws InterruptedException {
         int scanCount = 0;
         while (scanCount <= maxScanRetries) {
@@ -298,7 +228,7 @@
                 if (!scanResult.is80211mcResponder()) {
                     continue;
                 }
-                if (!bssid.equals(scanResult.BSSID)) {
+                if (!ssid.equals(scanResult.SSID)) {
                     continue;
                 }
 
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
index 8c59a57..d0b0d6d 100644
--- a/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java
+++ b/tests/cts/net/src/android/net/wifi/rtt/cts/WifiRttTest.java
@@ -16,9 +16,11 @@
 
 package android.net.wifi.rtt.cts;
 
+import android.content.IntentFilter;
 import android.net.wifi.ScanResult;
 import android.net.wifi.rtt.RangingRequest;
 import android.net.wifi.rtt.RangingResult;
+import android.net.wifi.rtt.WifiRttManager;
 
 import com.android.compatibility.common.util.DeviceReportLog;
 import com.android.compatibility.common.util.ResultType;
@@ -60,18 +62,10 @@
             return;
         }
 
-        // Find the associated AP: get BSSID and disable Wi-Fi
-        String bssid = mWifiManager.getConnectionInfo().getBSSID();
-        assertNotNull("Null BSSID - must be associated!", bssid);
-        assertTrue("Cannot disable Wi-Fi (to disassociate)", mWifiManager.setWifiEnabled(false));
-        WifiEnableBroadcastReceiver receiver = new WifiEnableBroadcastReceiver(false);
-        mContext.registerReceiver(receiver, mWifiStateIntent);
-        receiver.waitForDesiredState();
-        mContext.unregisterReceiver(receiver);
-
         // Scan for IEEE 802.11mc supporting APs
-        ScanResult testAp = scanForTestAp(bssid, MAX_NUM_SCAN_RETRIES_SEARCHING_FOR_IEEE80211MC_AP);
-        assertTrue("Cannot find test AP: bssid=" + bssid, testAp != null);
+        ScanResult testAp = scanForTestAp(SSID_OF_TEST_AP,
+                MAX_NUM_SCAN_RETRIES_SEARCHING_FOR_IEEE80211MC_AP);
+        assertTrue("Cannot find test AP", testAp != null);
 
         // Perform RTT operations
         RangingRequest request = new RangingRequest.Builder().addAccessPoint(testAp).build();