Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ceaf552 authored by Qasim Javed's avatar Qasim Javed
Browse files

Use SDP when SDP succeeds and EIR when SDP fails

Currently, we discover UUIDs through Extended Inquiry Response (EIR) as
well as SDP and we use the union of UUIDs discovered through both
methods to connect to the remote device.

This causes problems where a device has a different set of UUIDs as
reported in the EIR vs. SDP. Specifically, if a device advertises
support for HFP in EIR, but does not advertise HFP support in SDP, we
still try to connect the HFP profile. This can cause the Settings app to
display "Problem connecting. Turn device off & back on" under the
Bluetooth device.

Instead of using the union of UUIDs from EIR and SDP, if SDP succeeds we
only report UUIDs discovered through SDP to the higher layers. If SDP
fails, only then we report the UUIDs discovered through EIR to the
higher layers.

Bug: 230050560
Tag: #refactor
Test: manual tests locally using the JBL Flip 5. Also tested the EIR
reporting path by modifying the code such that SDP results are not
reported and only EIR UUIDs are reported to the stack.
Ignore-AOSP-First: Floss uses EIR UUIDs and they develop based on AOSP

Change-Id: I0ab83c0a13528f74455dac1c95fa76828b56242d
parent 210a297a
Loading
Loading
Loading
Loading
+26 −20
Original line number Diff line number Diff line
@@ -164,6 +164,8 @@ typedef struct {
  bool is_le_nc; /* LE Numeric comparison */
  btif_dm_ble_cb_t ble;
  uint8_t fail_reason;
  Uuid::UUID128Bit eir_uuids[32];
  uint8_t num_eir_uuids;
} btif_dm_pairing_cb_t;

// TODO(jpawlowski): unify ?
@@ -1296,19 +1298,17 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event,
                                   &(p_search_data->inq_res.include_rsi));
        num_properties++;

        /* EIR queried services */
        std::vector<Uuid> uuid128_list;
        /* Cache EIR queried services */
        if (num_uuids > 0) {
          uint16_t* p_uuid16 = (uint16_t*)uuid_list;
          pairing_cb.num_eir_uuids = 0;
          LOG_INFO("EIR UUIDS:");
          for (int i = 0; i < num_uuids; ++i) {
            Uuid uuid = Uuid::From16Bit(p_uuid16[i]);
            uuid128_list.push_back(uuid);
            LOG_INFO("        %s", uuid.ToString().c_str());
            pairing_cb.eir_uuids[i] = uuid.To128BitBE();
            pairing_cb.num_eir_uuids++;
          }

          BTIF_STORAGE_FILL_PROPERTY(
              &properties[num_properties], BT_PROPERTY_UUIDS,
              num_uuids * Uuid::kNumBytes128, uuid128_list.data());
          num_properties++;
        }

        status =
@@ -1408,28 +1408,34 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
        LOG_INFO("SDP search done for %s", bd_addr.ToString().c_str());
        pairing_cb.sdp_attempts = 0;

        // Both SDP and bonding are done, clear pairing control block in case
        // it is not already cleared
        pairing_cb = {};

        // Send one empty UUID to Java to unblock pairing intent when SDP failed
        // or no UUID is discovered
        // Send UUIDs discovered through EIR to Java to unblock pairing intent
        // when SDP failed or no UUID is discovered
        if (p_data->disc_res.result != BTA_SUCCESS ||
            p_data->disc_res.num_uuids == 0) {
          LOG_INFO("SDP failed, send empty UUID to unblock bonding %s",
                   bd_addr.ToString().c_str());
          LOG_INFO("SDP failed, send %d EIR UUIDs to unblock bonding %s",
                   pairing_cb.num_eir_uuids, bd_addr.ToString().c_str());
          bt_property_t prop_uuids;
          Uuid uuid = {};

          prop_uuids.type = BT_PROPERTY_UUIDS;
          if (pairing_cb.num_eir_uuids > 0) {
            prop_uuids.val = pairing_cb.eir_uuids;
            prop_uuids.len = pairing_cb.num_eir_uuids * Uuid::kNumBytes128;
          } else {
            prop_uuids.val = &uuid;
            prop_uuids.len = Uuid::kNumBytes128;
          }

          /* Send the event to the BTIF */
          /* Send the event to the BTIF
           * prop_uuids will be deep copied by this call
           */
          invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1,
                                             &prop_uuids);
          pairing_cb = {};
          break;
        }
        // Both SDP and bonding are done, clear pairing control block in case
        // it is not already cleared
        pairing_cb = {};
      }

      if (p_data->disc_res.num_uuids != 0) {