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

Commit 0835b4fe authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Jakub Pawłowski
Browse files

Read DIS info for Fast Pair Devices

Schedule DIS model name read before service discovery is scheduled.
Also move it to BTIF layer, which is more proper than gatt_main.cc

Bug: 337087330
Bug: 322464947
Test: pair using Fast Pair with LE Audio capable device
Flag: com.android.bluetooth.flags.read_model_num_fix
Change-Id: I7df16768f49f18c1e76c1722ef39075dd43bf37d
parent da9e1f6c
Loading
Loading
Loading
Loading
+53 −0
Original line number Original line Diff line number Diff line
@@ -98,6 +98,7 @@
#include "stack/include/btm_sec_api.h"
#include "stack/include/btm_sec_api.h"
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/smp_api.h"
#include "stack/include/smp_api.h"
#include "stack/include/srvc_api.h"  // tDIS_VALUE
#include "stack/sdp/sdpint.h"
#include "stack/sdp/sdpint.h"
#include "storage/config_keys.h"
#include "storage/config_keys.h"
#include "types/raw_address.h"
#include "types/raw_address.h"
@@ -4199,6 +4200,49 @@ void btif_dm_set_event_filter_inquiry_result_all_devices() {
  BTA_DmSetEventFilterInquiryResultAllDevices();
  BTA_DmSetEventFilterInquiryResultAllDevices();
}
}


static bool btif_model_name_known(const RawAddress& bd_addr) {
  bt_property_t prop;
  bt_bdname_t model_name;
  BTIF_STORAGE_FILL_PROPERTY(&prop, BT_PROPERTY_REMOTE_MODEL_NUM,
                             sizeof(model_name), &model_name);

  if (btif_storage_get_remote_device_property(&bd_addr, &prop) !=
          BT_STATUS_SUCCESS ||
      prop.len == 0) {
    log::info("Device {} no cached model name", bd_addr);
    return false;
  }

  return true;
}

static void read_dis_cback(const RawAddress& bd_addr, tDIS_VALUE* p_dis_value) {
  if (p_dis_value == nullptr) {
    log::warn("received unexpected/error DIS callback");
    return;
  }

  if (!(p_dis_value->attr_mask & DIS_ATTR_MODEL_NUM_BIT)) {
    log::warn("unknown bit, mask: {}", (int)p_dis_value->attr_mask);
    return;
  }

  for (int i = 0; i < DIS_MAX_STRING_DATA; i++) {
    if (p_dis_value->data_string[i] == nullptr) continue;

    bt_property_t prop;
    prop.type = BT_PROPERTY_REMOTE_MODEL_NUM;
    prop.val = p_dis_value->data_string[i];
    prop.len = strlen((char*)prop.val);

    log::info("Device {}, model name: {}", bd_addr, (char*)prop.val);

    btif_storage_set_remote_device_property(&bd_addr, &prop);
    GetInterfaceToProfiles()->events->invoke_remote_device_properties_cb(
        BT_STATUS_SUCCESS, bd_addr, 1, &prop);
  }
}

void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key,
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;
  static const int METADATA_LE_AUDIO = 26;
@@ -4206,6 +4250,15 @@ void btif_dm_metadata_changed(const RawAddress& remote_bd_addr, int key,
  if (key == METADATA_LE_AUDIO) {
  if (key == METADATA_LE_AUDIO) {
    log::info("Device is LE Audio Capable {}", remote_bd_addr);
    log::info("Device is LE Audio Capable {}", remote_bd_addr);
    metadata_cb.le_audio_cache.insert_or_assign(remote_bd_addr, value);
    metadata_cb.le_audio_cache.insert_or_assign(remote_bd_addr, value);

    if (com::android::bluetooth::flags::read_model_num_fix() &&
        !btif_model_name_known(remote_bd_addr)) {
      log::info("Read model name for le audio capable device");
      if (!DIS_ReadDISInfo(remote_bd_addr, read_dis_cback,
                           DIS_ATTR_MODEL_NUM_BIT)) {
        log::warn("Read DIS failed");
      }
    }
  }
  }
}
}