Ignore SDP failure while bonding if SDP was not attempted

When bonding, there is an ACL_UP event to the upper layers and some apps
may want to fetch SDP in return. This can break pairing. In cases SDP fails,
it causes the procedure to be finished before the LinkKey is generated.
And thus the LinkKey is not committed to NVRAM and the device is not paired.

Bug: 111189110
Test: : Pair / Unpair BT accessories manually
Change-Id: Iaefbe8b6c1fc3e78f0f120220992df84699a2eb8
Merged-In: Iaefbe8b6c1fc3e78f0f120220992df84699a2eb8
(cherry picked from commit 5492af2d0ee3a9c810f001cfc9a29283a76b4438)
diff --git a/btif/src/btif_dm.cc b/btif/src/btif_dm.cc
index d1bb61c..dd9b813 100644
--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -1395,10 +1395,15 @@
       if ((p_data->disc_res.result != BTA_SUCCESS) &&
           (pairing_cb.state == BT_BOND_STATE_BONDING) &&
           (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) {
-        BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting",
-                           __func__);
-        pairing_cb.sdp_attempts++;
-        btif_dm_get_remote_services(bd_addr);
+        if (pairing_cb.sdp_attempts) {
+          BTIF_TRACE_WARNING("%s: SDP failed after bonding re-attempting",
+                             __func__);
+          pairing_cb.sdp_attempts++;
+          btif_dm_get_remote_services(bd_addr);
+        } else {
+          BTIF_TRACE_WARNING("%s: SDP triggered by someone failed when bonding",
+                             __func__);
+        }
         return;
       }
       prop.type = BT_PROPERTY_UUIDS;