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

Commit f0e97ea8 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Read device name on connection with new LE devices

Android Bluetooth stack does not actively tries to find device name over
LE transport before pairing. It relies on name found during device
discovery. As a result, pairing dialog box for LE pairing without prior
device discovery don't show remote device name. This also happens if the
the remote device name was not found in the device discovery.

Test: mmm packages/modules/Bluetooth
Test: Manual | Start connectable advertising on DUT, initiate LE pairing
from another phone, pairing prompt on DUT must show the remote device
name
Flag: com.android.bluetooth.flags.name_discovery_for_le_pairing
Bug: 346365430
Bug: 355095011

Change-Id: Iea59ec9ba19148a5012cac8f3a5d2fd7304056fd
parent bec39c84
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@
#include "rust/src/core/ffi/types.h"
#include "stack/acl/acl.h"
#include "stack/acl/peer_packet_types.h"
#include "stack/btm/btm_ble_int.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/btm_sco.h"
@@ -1003,6 +1004,8 @@ void StackAclBtmAcl::btm_establish_continue(tACL_CONN* p_acl) {
                 default_packet_type_mask, p_acl->RemoteAddress());
    }
    btm_set_link_policy(p_acl, btm_cb.acl_cb_.DefaultLinkPolicy());
  } else if (p_acl->is_transport_ble()) {
    btm_ble_connection_established(p_acl->remote_addr);
  }
  NotifyAclLinkUp(*p_acl);
}
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ void btm_ble_free();
void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode, uint8_t role,
                       tBLE_ADDR_TYPE addr_type, bool addr_matched,
                       bool can_read_discoverable_characteristics);
void btm_ble_connection_established(const RawAddress& bda);

/* acceptlist function */
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
+24 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <android_bluetooth_sysprop.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <cstddef>
#include <cstdint>
@@ -65,6 +66,7 @@ using namespace bluetooth;
extern tBTM_CB btm_cb;

bool btm_ble_init_pseudo_addr(tBTM_SEC_DEV_REC* p_dev_rec, const RawAddress& new_pseudo_addr);
tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda, tBTM_NAME_CMPL_CB* p_cb);

namespace {
constexpr char kBtmLogTag[] = "SEC";
@@ -1481,8 +1483,7 @@ static tBTM_STATUS btm_ble_br_keys_req(tBTM_SEC_DEV_REC* p_dev_rec, tBTM_LE_IO_R
 *
 * Function         btm_ble_connected
 *
 * Description      This function is when a LE connection to the peer device is
 *                  establsihed
 * Description      This function is called on LE connection
 *
 * Returns          void
 *
@@ -1517,6 +1518,27 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t /* enc_mo
  btm_cb.ble_ctr_cb.inq_var.directed_conn = BTM_BLE_ADV_IND_EVT;
}

/*******************************************************************************
 *
 * Function         btm_ble_connection_established
 *
 * Description      This function when LE connection is established
 *
 * Returns          void
 *
 ******************************************************************************/
void btm_ble_connection_established(const RawAddress& bda) {
  if (!com::android::bluetooth::flags::name_discovery_for_le_pairing()) {
    return;
  }

  // Read device name if it is not known already, we may need it for pairing
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
  if (p_dev_rec != nullptr && !p_dev_rec->sec_rec.is_name_known()) {
    btm_ble_read_remote_name(bda, nullptr);
  }
}

/*****************************************************************************
 *  Function        btm_proc_smp_cback
 *
+5 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ struct BTM_SecAddBleDevice BTM_SecAddBleDevice;
struct BTM_SecAddBleKey BTM_SecAddBleKey;
struct BTM_SecurityGrant BTM_SecurityGrant;
struct btm_ble_connected btm_ble_connected;
struct btm_ble_connection_established btm_ble_connection_established;
struct btm_ble_get_acl_remote_addr btm_ble_get_acl_remote_addr;
struct btm_ble_get_enc_key_type btm_ble_get_enc_key_type;
struct btm_ble_link_encrypted btm_ble_link_encrypted;
@@ -198,6 +199,10 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
  test::mock::stack_btm_ble::btm_ble_connected(bda, handle, enc_mode, role, addr_type, addr_matched,
                                               can_read_discoverable_characteristics);
}
void btm_ble_connection_established(const RawAddress& bda) {
  inc_func_call_count(__func__);
  test::mock::stack_btm_ble::btm_ble_connection_established(bda);
}
bool btm_ble_get_acl_remote_addr(uint16_t hci_handle, RawAddress& conn_addr,
                                 tBLE_ADDR_TYPE* p_addr_type) {
  inc_func_call_count(__func__);
+10 −1
Original line number Diff line number Diff line
@@ -278,7 +278,8 @@ extern struct BTM_SecurityGrant BTM_SecurityGrant;

// Name: btm_ble_connected
// Params: const RawAddress& bda, uint16_t handle, uint8_t enc_mode, uint8_t
// role, tBLE_ADDR_TYPE addr_type, bool addr_matched Return: void
// role, tBLE_ADDR_TYPE addr_type, bool addr_matched, bool can_read_discoverable_characteristics
// Return: void
struct btm_ble_connected {
  std::function<void(const RawAddress& bda, uint16_t handle, uint8_t enc_mode, uint8_t role,
                     tBLE_ADDR_TYPE addr_type, bool addr_matched,
@@ -295,6 +296,14 @@ struct btm_ble_connected {
};
extern struct btm_ble_connected btm_ble_connected;

// Name: btm_ble_connection_established
// Params: const RawAddress& bda Return: void
struct btm_ble_connection_established {
  std::function<void(const RawAddress& bda)> body{[](const RawAddress& /* bda */) {}};
  void operator()(const RawAddress& bda) { body(bda); }
};
extern struct btm_ble_connection_established btm_ble_connection_established;

// Name: btm_ble_get_acl_remote_addr
// Params: uint16_t hci_handle, RawAddress& conn_addr, tBLE_ADDR_TYPE*
// p_addr_type Return: bool