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

Commit 24d5d774 authored by Rahul Arya's avatar Rahul Arya
Browse files

Always send BTA_DM_GATT_OVER_LE_RES_EVT

If doing gatt discovery, we should always send this event to the upper
layer on its conclusion. Otherwise we get the pairing_cb stuck.

Bug: 263050668
Test: manual
(cherry picked from https://android-review.googlesource.com/q/commit:3380f3ddf0dedc8d0cb3ca7256711bff5c2aee98)
Merged-In: I65aa5cddc3fe5a9f5c8b9e2d43d676bf3d9082b7
Change-Id: I07621dd098ad887c82927a3af9f41ac2b31c15b0
parent 4e73b33c
Loading
Loading
Loading
Loading
+42 −31
Original line number Diff line number Diff line
@@ -1308,26 +1308,33 @@ void bta_dm_search_cmpl() {

  uint16_t conn_id = bta_dm_search_cb.conn_id;

  tBTA_DM_SEARCH result;
  std::vector<Uuid> gatt_services;
  result.disc_ble_res.services = &gatt_services;
  result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
  strlcpy((char*)result.disc_ble_res.bd_name, (char*)bta_dm_search_cb.peer_name,
          BD_NAME_LEN + 1);

  bool send_gatt_results =
      bluetooth::common::init_flags::
              always_send_services_if_gatt_disc_done_is_enabled()
          ? bta_dm_search_cb.gatt_disc_active
          : false;

  /* no BLE connection, i.e. Classic service discovery end */
  if (conn_id == GATT_INVALID_CONN_ID) {
    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
    bta_dm_execute_queued_request();
    return;
    if (bta_dm_search_cb.gatt_disc_active) {
      LOG_WARN(
          "GATT active but no BLE connection, likely disconnected midway "
          "through");
    } else {
      LOG_INFO("No BLE connection, processing classic results");
    }

  } else {
    btgatt_db_element_t* db = NULL;
    int count = 0;
    BTA_GATTC_GetGattDb(conn_id, 0x0000, 0xFFFF, &db, &count);

  if (count == 0) {
    LOG_INFO("Empty GATT database - no BLE services discovered");
    bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
    bta_dm_execute_queued_request();
    return;
  }

  std::vector<Uuid> gatt_services;

    if (count != 0) {
      for (int i = 0; i < count; i++) {
        // we process service entries only
        if (db[i].type == BTGATT_DB_PRIMARY_SERVICE) {
@@ -1335,18 +1342,23 @@ void bta_dm_search_cmpl() {
        }
      }
      osi_free(db);
      LOG_INFO(
          "GATT services discovered using LE Transport, will always send to "
          "upper layer");
      send_gatt_results = true;
    } else {
      LOG_WARN("Empty GATT database - no BLE services discovered");
    }
  }

  tBTA_DM_SEARCH result;
  result.disc_ble_res.services = &gatt_services;
  result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr;
  strlcpy((char*)result.disc_ble_res.bd_name, (char*)bta_dm_search_cb.peer_name,
          BD_NAME_LEN + 1);

  LOG_INFO("GATT services discovered using LE Transport");
  // send all result back to app
  if (send_gatt_results) {
    LOG_INFO("Sending GATT results to upper layer");
    bta_dm_search_cb.p_search_cback(BTA_DM_GATT_OVER_LE_RES_EVT, &result);
  }

  bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, nullptr);
  bta_dm_search_cb.gatt_disc_active = false;

  bta_dm_execute_queued_request();
}
@@ -4028,7 +4040,6 @@ static void bta_dm_gatt_disc_complete(uint16_t conn_id, tGATT_STATUS status) {
      bta_dm_search_cb.conn_id = GATT_INVALID_CONN_ID;
    }
  }
  bta_dm_search_cb.gatt_disc_active = false;
}

/*******************************************************************************
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ table InitFlagsData {
    gd_hci_enabled:bool (privacy:"Any");
    gd_controller_enabled:bool (privacy:"Any");

    always_send_services_if_gatt_disc_done_is_enabled:bool (private:"Any");
    asynchronously_start_l2cap_coc_is_enabled:bool (privacy:"Any");
    btaa_hci_is_enabled:bool (privacy:"Any");
    bta_dm_clear_conn_id_on_client_close_is_enabled:bool (privacy:"Any");
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ flatbuffers::Offset<bluetooth::common::InitFlagsData> bluetooth::dumpsys::InitFl
  builder.add_gd_hci_enabled(true);
  builder.add_gd_controller_enabled(true);

  builder.add_always_send_services_if_gatt_disc_done_is_enabled(
      initFlags::always_send_services_if_gatt_disc_done_is_enabled());
  builder.add_asynchronously_start_l2cap_coc_is_enabled(initFlags::asynchronously_start_l2cap_coc_is_enabled());
  builder.add_btaa_hci_is_enabled(initFlags::btaa_hci_is_enabled());
  builder.add_bta_dm_clear_conn_id_on_client_close_is_enabled(
+1 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ fn parse_hci_adapter(flags: &mut InitFlags, values: Vec<&str>) {
init_flags!(
    // LINT.IfChange
    flags: {
        always_send_services_if_gatt_disc_done = true,
        asynchronously_start_l2cap_coc = true,
        btaa_hci = true,
        bta_dm_clear_conn_id_on_client_close = true,
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ mod ffi {
        fn load(flags: Vec<String>);
        fn set_all_for_testing();

        fn always_send_services_if_gatt_disc_done_is_enabled() -> bool;
        fn asynchronously_start_l2cap_coc_is_enabled() -> bool;
        fn btaa_hci_is_enabled() -> bool;
        fn bta_dm_clear_conn_id_on_client_close_is_enabled() -> bool;