Bluetooth: Do not initiate inquiry during pairing/SDP

Retry SDP if it gets cancelled in BONDING state.
If SDP search initiated after the pairing gets cancelled, re-initiate
SDP search from the BTIF layer to ensure completion of the bonding
process.

While pairing/SDP discovery of the bonded device is in progress,
do not initiate inquiry.

Bug: 19417758
Change-Id: I2d80883999771c53b58cc3017a63b17e3564bc57
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
old mode 100755
new mode 100644
index 64b4452..dd2368f
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java
@@ -527,7 +527,11 @@
     void onUuidChanged() {
         updateProfiles();
         ParcelUuid[] uuids = mDevice.getUuids();
+
         long timeout = MAX_UUID_DELAY_FOR_AUTO_CONNECT;
+        if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Hogp)) {
+            timeout = MAX_HOGP_DELAY_FOR_AUTO_CONNECT;
+        }
 
         if (DEBUG) {
             Log.d(TAG, "onUuidChanged: Time since last connect"
@@ -535,14 +539,12 @@
         }
 
         /*
-         * If a connect was attempted earlier without any UUID, we will do the
-         * connect now.
+         * If a connect was attempted earlier without any UUID, we will do the connect now.
+         * Otherwise, allow the connect on UUID change.
          */
-        if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Hogp)) {
-            timeout = MAX_HOGP_DELAY_FOR_AUTO_CONNECT;
-        }
         if (!mProfiles.isEmpty()
-                && (mConnectAttempted + timeout) > SystemClock.elapsedRealtime()) {
+                && ((mConnectAttempted + timeout) > SystemClock.elapsedRealtime()
+                || (mConnectAttempted == 0))) {
             connectWithoutResettingTimer(false);
         }
         dispatchAttributesChanged();