Verify the device before calling connectGatt

BONDED events will come twice and with different bluetooth address while
pairing with a dual mode device. We need to check the device address when
connectGatt() was called after received BONDED event.

Test: CtsVerifier

bug: 214417497

Signed-off-by: Sajjad Mosharraf <sajjad.mosharraf@gm.com>
Change-Id: Ic5cd2066e62f0cd165df1d8b64485bdb80816dc8
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: