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

Commit 51f551c7 authored by Bidhya Sharma's avatar Bidhya Sharma Committed by Automerger Merge Worker
Browse files

Merge "Get device type using adv flag data" am: 3c0408ab

parents b1ca4655 3c0408ab
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -95,7 +95,9 @@ MutationEntry Device::RemoveFromTempConfig() {
LeDevice Device::Le() {
  auto device_type = GetDeviceType();
  ASSERT(device_type);
  ASSERT(device_type == DeviceType::LE || device_type == DeviceType::DUAL);
  ASSERT(
      device_type == DeviceType::LE || device_type == DeviceType::DUAL ||
      device_type == DeviceType::UNKNOWN);
  return LeDevice(config_, memory_only_config_, section_);
}

+2 −1
Original line number Diff line number Diff line
@@ -144,7 +144,8 @@ class BleScannerInterfaceImpl : public ::BleScannerInterface,
      bluetooth::hci::AdvertisingPacketContentFilterCommand&
          advertising_packet_content_filter_command,
      ApcfCommand apcf_command);
  void handle_remote_properties(RawAddress bd_addr, tBLE_ADDR_TYPE addr_type,
  void handle_remote_properties(uint16_t event_type, RawAddress bd_addr,
                                tBLE_ADDR_TYPE addr_type,
                                std::vector<uint8_t> advertising_data);

  class AddressCache {
+26 −8
Original line number Diff line number Diff line
@@ -513,8 +513,8 @@ void BleScannerInterfaceImpl::OnScanResult(
  do_in_jni_thread(
      FROM_HERE,
      base::BindOnce(&BleScannerInterfaceImpl::handle_remote_properties,
                     base::Unretained(this), raw_address, ble_addr_type,
                     advertising_data));
                     base::Unretained(this), event_type, raw_address,
                     ble_addr_type, advertising_data));

  do_in_jni_thread(
      FROM_HERE,
@@ -726,7 +726,7 @@ bool BleScannerInterfaceImpl::parse_filter_command(
}

void BleScannerInterfaceImpl::handle_remote_properties(
    RawAddress bd_addr, tBLE_ADDR_TYPE addr_type,
    uint16_t event_type, RawAddress bd_addr, tBLE_ADDR_TYPE addr_type,
    std::vector<uint8_t> advertising_data) {
  if (!bluetooth::shim::is_gd_stack_started_up()) {
    LOG_WARN("Gd stack is stopped, return");
@@ -738,15 +738,33 @@ void BleScannerInterfaceImpl::handle_remote_properties(
    return;
  }

  auto device_type = bluetooth::hci::DeviceType::LE;
  uint8_t flag_len;
  const uint8_t* p_flag = AdvertiseDataParser::GetFieldByType(
      advertising_data, BTM_BLE_AD_TYPE_FLAG, &flag_len);
  if (p_flag != NULL && flag_len != 0) {
    if ((BTM_BLE_BREDR_NOT_SPT & *p_flag) == 0) {
  bluetooth::hci::DeviceType device_type;
  bool is_adv_connectable = event_type & (1 << BLE_EVT_CONNECTABLE_BIT);
  // 1. If adv is connectable and flag data is not present, device type is
  // DUAL mode.
  if (is_adv_connectable && p_flag == nullptr) {
    device_type = bluetooth::hci::DeviceType::DUAL;
  }
  }
  // 2. If adv is not connectable and flag data is not present, device type is
  // UNKNOWN.
  else if (!is_adv_connectable && p_flag == nullptr) {
    device_type = bluetooth::hci::DeviceType::UNKNOWN;
  }
  // 3. If flag data is present, use `BR/EDR Not Supported` bit to find device
  // type.
  else {
    device_type = (BTM_BLE_BREDR_NOT_SPT & *p_flag)
                      ? bluetooth::hci::DeviceType::LE
                      : bluetooth::hci::DeviceType::DUAL;
  }
  LOG_DEBUG(
      "%s event_type: %d, is_adv_connectable: %d, flag data: %d, device_type: "
      "%d",
      __func__, event_type, is_adv_connectable, (p_flag ? *p_flag : 0),
      device_type);

  uint8_t remote_name_len;
  const uint8_t* p_eir_remote_name = AdvertiseDataParser::GetFieldByType(