Merge "Snap for 8878538 from 12511dee72ea158ebf9f8be321a79f9e41847800 to android11-tests-release" into android11-tests-release
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleCocClientService.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleCocClientService.java
index f2eb30d..01644c9 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleCocClientService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleCocClientService.java
@@ -483,6 +483,7 @@
                     stopScan();
 
                     BluetoothDevice device = result.getDevice();
+                    mDevice = device;
                     if (DEBUG) {
                         Log.d(TAG, "onScanResult: Found ADV with CoC UUID on device="
                               + device);
@@ -493,12 +494,10 @@
                                 notifyError("Failed to call create bond");
                             }
                         } else {
-                            mDevice = device;
                             mBluetoothGatt = connectGatt(result.getDevice(), BleCocClientService.this, false,
                                                          mSecure, mGattCallbacks);
                         }
                     } else {
-                        mDevice = device;
                         mBluetoothGatt = connectGatt(result.getDevice(), BleCocClientService.this, false, mSecure,
                                                      mGattCallbacks);
                     }
@@ -707,17 +706,18 @@
                 switch (state) {
                     case BluetoothDevice.BOND_BONDED:
                         if (mBluetoothGatt == null) {
-                            if (DEBUG) {
-                                Log.d(TAG, "onReceive:BOND_BONDED: calling connectGatt. device="
-                                             + device + ", mSecure=" + mSecure
-                                             + ", mDevice=" + mDevice);
+                            if(mDevice != null && mDevice.equals(device)) {
+                                if (DEBUG) {
+                                    Log.d(TAG, "onReceive:BOND_BONDED: calling connectGatt. device="
+                                             + device + ", mSecure=" + mSecure);
+                                }
+                                mBluetoothGatt = connectGatt(device, BleCocClientService.this, false, mSecure,
+                                                         mGattCallbacks);
+                            } else {
+                                if (DEBUG) {
+                                    Log.d(TAG, "Another device bonded, device= " + device);
+                                }
                             }
-                            if (mDevice == null) {
-                                mDevice = device;
-                            }
-
-                            mBluetoothGatt = connectGatt(mDevice, BleCocClientService.this, false,
-                                                         mSecure, mGattCallbacks);
                         }
                         break;
                     case BluetoothDevice.BOND_NONE:
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
index 62948a5..6eed910 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
@@ -386,7 +386,7 @@
                         mNetworkCallback);
                 // Wait for the request to reach the wifi stack before kick-starting the UI
                 // interactions.
-                Thread.sleep(100);
+                Thread.sleep(1_000);
                 // Start the UI interactions.
                 uiThread.run();
                 // now wait for callback