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

Commit 6b3ff5aa authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

LE Audio: metadata parsing in native am: 01a30197

parents 7576e359 01a30197
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@
#include "btif_sdp.h"
#include "btif_storage.h"
#include "btif_util.h"
#include "common/lru.h"
#include "common/metrics.h"
#include "device/include/controller.h"
#include "device/include/interop.h"
@@ -200,6 +201,10 @@ typedef struct {

typedef struct { unsigned int manufact_id; } skip_sdp_entry_t;

typedef struct {
  bluetooth::common::LruCache<RawAddress, std::vector<uint8_t>> le_audio_cache;
} btif_dm_metadata_cb_t;

typedef enum {
  BTIF_DM_FUNC_CREATE_BOND,
  BTIF_DM_FUNC_CANCEL_BOND,
@@ -254,6 +259,7 @@ static void btif_dm_remove_ble_bonding_keys(void);
static void btif_dm_save_ble_bonding_keys(RawAddress& bd_addr);
static btif_dm_pairing_cb_t pairing_cb;
static btif_dm_oob_cb_t oob_cb;
static btif_dm_metadata_cb_t metadata_cb{.le_audio_cache{40}};
static void btif_dm_cb_create_bond(const RawAddress bd_addr,
                                   tBT_TRANSPORT transport);
static void btif_update_remote_properties(const RawAddress& bd_addr,
@@ -676,6 +682,7 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
static bool is_device_le_audio_capable(const RawAddress bd_addr) {
  if (!LeAudioClient::IsLeAudioClientRunning() ||
      !check_cod_le_audio(bd_addr)) {
    /* If LE Audio profile is not enabled, do nothing. */
    return false;
  }

@@ -683,6 +690,9 @@ static bool is_device_le_audio_capable(const RawAddress bd_addr) {
  tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
  BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &addr_type);
  if (tmp_dev_type & BT_DEVICE_TYPE_BLE) {
    /* LE Audio capable device is discoverable over both LE and Classic using
     * same address. Prefer to use LE transport, as we don't know if it can do
     * CTKD from Classic to LE */
    return true;
  }

@@ -705,7 +715,7 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);

  if (transport == BT_TRANSPORT_AUTO && is_device_le_audio_capable(bd_addr)) {
    LOG_INFO("LE Audio && advertising over LE, use LE transport for Bonding");
    LOG_INFO("LE Audio capable, forcing LE transport for Bonding");
    transport = BT_TRANSPORT_LE;
  }

@@ -1511,7 +1521,8 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
          LeAudioClient::IsLeAudioClientRunning() &&
          pairing_cb.gatt_over_le !=
              btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED &&
          check_cod_le_audio(bd_addr)) {
          (check_cod_le_audio(bd_addr) ||
           metadata_cb.le_audio_cache.contains(bd_addr))) {
        skip_reporting_wait_for_le = true;
      }

@@ -1566,7 +1577,7 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
        if (skip_reporting_wait_for_le) {
          LOG_INFO(
              "Bonding LE Audio sink - must wait for le services discovery "
              "to pass all services to java %s:",
              "to pass all services to java %s",
              PRIVATE_ADDRESS(bd_addr));
          /* For LE Audio capable devices, we care more about passing GATT LE
           * services than about just finishing pairing. Service discovery
@@ -3620,4 +3631,11 @@ void btif_dm_clear_event_filter() {
}

void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key,
                              std::vector<uint8_t> value) {}
                              std::vector<uint8_t> value) {
  static const int METADATA_LE_AUDIO = 26;
  /* If METADATA_LE_AUDIO is present, device is LE Audio capable */
  if (key == METADATA_LE_AUDIO) {
    LOG_INFO("Device is LE Audio Capable %s", PRIVATE_ADDRESS(remote_bd_addr));
    metadata_cb.le_audio_cache.insert_or_assign(remote_bd_addr, value);
  }
}