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

Commit 00a03d31 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Faster LE Audio device pairing

LE Audio related profiles take long time to connect. Most of this time
is spent waiting on GATT operations waiting to be sent / received.

Currently, we use high connection parameters just for service discovery,
and relax them immediately after that.

After this patch, we would use high speed connection parameters once we
find device might be LE Audio capable. The parameters are relaxed after
LE Audio profile is connected. In case LE Audio is disabled, we start a
timer that would disable parameters 15 seconds after service discovery
is finished.

Test: Bond wiht LE Audio capable device, note profile connection time
      reduction.
Bug: 319405267
Bug: 296836982
Change-Id: Id238ca459333e82581cf71952ce8abc9a2b8aafe
parent f196bb02
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -819,6 +819,7 @@ cc_test {
        ":TestCommonMockFunctions",
        ":TestMockBtaLeAudioHalVerifier",
        ":TestMockMainShim",
        ":TestMockStackL2cap",
        ":TestStubOsi",
        "le_audio/audio_hal_client/asrc_tables.cc",
        "le_audio/audio_hal_client/audio_hal_client_test.cc",
@@ -911,6 +912,7 @@ cc_test {
        ":TestCommonMockFunctions",
        ":TestMockBtaLeAudioHalVerifier",
        ":TestMockMainShim",
        ":TestMockStackL2cap",
        ":TestStubOsi",
        "gatt/database.cc",
        "gatt/database_builder.cc",
+5 −3
Original line number Diff line number Diff line
@@ -801,7 +801,7 @@ void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {

void bta_gattc_start_discover_internal(tBTA_GATTC_CLCB* p_clcb) {
  if (p_clcb->transport == BT_TRANSPORT_LE)
    L2CA_EnableUpdateBleConnParams(p_clcb->p_srcb->server_bda, false);
    L2CA_LockBleConnParamsForServiceDiscovery(p_clcb->p_srcb->server_bda, true);

  bta_gattc_init_cache(p_clcb->p_srcb);
  p_clcb->status = bta_gattc_discover_pri_service(
@@ -935,8 +935,10 @@ void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB* p_clcb,

  VLOG(1) << __func__ << ": conn_id=" << loghex(p_clcb->bta_conn_id);

  if (p_clcb->transport == BT_TRANSPORT_LE)
    L2CA_EnableUpdateBleConnParams(p_clcb->p_srcb->server_bda, true);
  if (p_clcb->transport == BT_TRANSPORT_LE) {
    L2CA_LockBleConnParamsForServiceDiscovery(p_clcb->p_srcb->server_bda,
                                              false);
  }
  p_clcb->p_srcb->state = BTA_GATTC_SERV_IDLE;
  p_clcb->disc_active = false;

+5 −0
Original line number Diff line number Diff line
@@ -3156,6 +3156,11 @@ class LeAudioClientImpl : public LeAudioClient {
    LOG_DEBUG("%s,  %s", ADDRESS_TO_LOGGABLE_CSTR(leAudioDevice->address_),
              bluetooth::common::ToString(leAudioDevice->GetConnectionState())
                  .c_str());

    if (IS_FLAG_ENABLED(le_audio_fast_bond_params)) {
      L2CA_LockBleConnParamsForProfileConnection(leAudioDevice->address_,
                                                 false);
    }
    callbacks_->OnConnectionState(ConnectionState::CONNECTED,
                                  leAudioDevice->address_);

+25 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@

#include "btif_dm.h"

#include <android_bluetooth_flags.h>
#include <base/functional/bind.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
@@ -50,7 +51,6 @@
#include <mutex>
#include <optional>

#include <android_bluetooth_flags.h>
#include "advertise_data_parser.h"
#include "android_bluetooth_flags.h"
#include "bta/dm/bta_dm_disc.h"
@@ -72,6 +72,7 @@
#include "internal_include/bt_target.h"
#include "internal_include/stack_config.h"
#include "main/shim/le_advertising_manager.h"
#include "main_thread.h"
#include "os/log.h"
#include "os/logging/log_adapter.h"
#include "osi/include/allocator.h"
@@ -1893,6 +1894,22 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
            LOG_DEBUG("clearing pairing_cb");
            pairing_cb = {};
          }

          if (IS_FLAG_ENABLED(le_audio_fast_bond_params) && lea_supported) {
            /* LE Audio profile should relax parameters when it connects. If
             * profile is not enabled, relax parameters after timeout. */
            LOG_DEBUG("Scheduling conn params unlock for %s",
                      ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
            do_in_main_thread_delayed(
                FROM_HERE,
                base::BindOnce(
                    [](RawAddress bd_addr) {
                      L2CA_LockBleConnParamsForProfileConnection(bd_addr,
                                                                 false);
                    },
                    bd_addr),
                std::chrono::seconds(15));
          }
        }
      } else {
        LOG_DEBUG("New GATT over SDP UUIDs for %s:",
@@ -2390,6 +2407,13 @@ void btif_dm_acl_evt(tBTA_DM_ACL_EVT event, tBTA_DM_ACL* p_data) {
              ? bt_conn_direction_t::BT_CONN_DIRECTION_OUTGOING
              : bt_conn_direction_t::BT_CONN_DIRECTION_INCOMING,
          p_data->link_up.acl_handle);

      if (IS_FLAG_ENABLED(le_audio_fast_bond_params) &&
          p_data->link_up.transport_link_type == BT_TRANSPORT_LE &&
          pairing_cb.bd_addr == bd_addr &&
          is_device_le_audio_capable(bd_addr)) {
        L2CA_LockBleConnParamsForProfileConnection(bd_addr, true);
      }
      break;

    case BTA_DM_LINK_UP_FAILED_EVT:
+12 −17
Original line number Diff line number Diff line
@@ -390,10 +390,6 @@ void L2CA_LeConnectionUpdate(const RawAddress& rem_bda, uint16_t min_int,
                             uint16_t timeout, uint16_t min_ce_len,
                             uint16_t max_ce_len);

// When GATT discovery is in progress, use the minimal connection interval, and
// reject remote connection updates, until done.
bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable);

/*******************************************************************************
 *
 * Function         L2CA_SetLeGattTimeout
@@ -419,20 +415,19 @@ bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, uint16_t min_int,
                              uint16_t max_int, uint16_t latency,
                              uint16_t timeout, uint16_t min_ce_len,
                              uint16_t max_ce_len);
/* When called with lock=true, LE connection parameters will be locked on
 * fastest value, and we won't accept request to change it from remote. When
 * called with lock=false, parameters are relaxed.
 */
void L2CA_LockBleConnParamsForServiceDiscovery(const RawAddress& rem_bda,
                                               bool lock);

/*******************************************************************************
 *
 *  Function        L2CA_EnableUpdateBleConnParams
 *
 *  Description     Update BLE connection parameters.
 *
 *  Parameters:     BD Address of remote
 *                  enable flag
 *
 *  Return value:   true if update started
 *
 ******************************************************************************/
bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable);
/* When called with lock=true, LE connection parameters will be locked on
 * fastest value, and we won't accept request to change it from remote. When
 * called with lock=false, parameters are relaxed.
 */
void L2CA_LockBleConnParamsForProfileConnection(const RawAddress& rem_bda,
                                                bool lock);

/*******************************************************************************
 *
Loading