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

Commit f9106af9 authored by Hui Peng's avatar Hui Peng
Browse files

[Invisalign2] Add BTM_BleIsLinkKeyKnown and BTM_BleGetIdentityAddress

Use these APIs in csis_client.cc

Bug: 301661850
Test: m com.android.btservices
Change-Id: I4b214bc5debbfd692a1ddb3db19e1b496b9177f0
parent 7f0b5eef
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -1317,12 +1317,11 @@ class CsisClientImpl : public CsisClient {
    /* Make sure device is not already bonded which could
     * be a case for dual mode devices where
     */
    tBTM_SEC_DEV_REC* p_dev = btm_find_dev(result->bd_addr);
    if (p_dev && p_dev->is_le_link_key_known()) {
      LOG_VERBOSE(
          "Device %s already bonded. Identity address: %s",
    if (BTM_BleIsLinkKeyKnown(result->bd_addr)) {
      LOG_VERBOSE("Device %s already bonded. Identity address: %s",
                  ADDRESS_TO_LOGGABLE_CSTR(result->bd_addr),
          ADDRESS_TO_LOGGABLE_CSTR(p_dev->ble.identity_address_with_type));
                  ADDRESS_TO_LOGGABLE_CSTR(
                      *BTM_BleGetIdentityAddress(result->bd_addr)));
      return;
    }

@@ -1468,12 +1467,11 @@ class CsisClientImpl : public CsisClient {
    /* Make sure device is not already bonded which could
     * be a case for dual mode devices where
     */
    tBTM_SEC_DEV_REC* p_dev = btm_find_dev(result->bd_addr);
    if (p_dev && p_dev->is_le_link_key_known()) {
      LOG_VERBOSE(
          "Device %s already bonded. Identity address: %s",
    if (BTM_BleIsLinkKeyKnown(result->bd_addr)) {
      LOG_VERBOSE("Device %s already bonded. Identity address: %s",
                  ADDRESS_TO_LOGGABLE_CSTR(result->bd_addr),
          ADDRESS_TO_LOGGABLE_CSTR(p_dev->ble.identity_address_with_type));
                  ADDRESS_TO_LOGGABLE_CSTR(
                      *BTM_BleGetIdentityAddress(result->bd_addr)));
      return;
    }

+11 −0
Original line number Diff line number Diff line
@@ -117,3 +117,14 @@ std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->BTM_BleGetPeerIRK(address);
}

bool BTM_BleIsLinkKeyKnown(const RawAddress address) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->BTM_BleIsLinkKeyKnown(address);
}

std::optional<tBLE_BD_ADDR> BTM_BleGetIdentityAddress(
    const RawAddress address) {
  LOG_ASSERT(btm_interface) << "Mock btm interface not set!";
  return btm_interface->BTM_BleGetIdentityAddress(address);
}
+10 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "bt_octets.h"
#include "btm_api.h"
#include "stack/btm/security_device_record.h"
#include "types/ble_address_with_type.h"
#include "types/raw_address.h"

namespace bluetooth {
@@ -62,6 +63,10 @@ class BtmInterface {
  virtual std::optional<Octet16> BTM_BleGetPeerIRK(
      const RawAddress address) = 0;

  virtual bool BTM_BleIsLinkKeyKnown(const RawAddress address) = 0;
  virtual std::optional<tBLE_BD_ADDR> BTM_BleGetIdentityAddress(
      const RawAddress address) = 0;

  virtual ~BtmInterface() = default;
};

@@ -107,6 +112,11 @@ class MockBtmInterface : public BtmInterface {
              (const RawAddress address), (override));
  MOCK_METHOD((std::optional<Octet16>), BTM_BleGetPeerIRK,
              (const RawAddress address), (override));

  MOCK_METHOD((bool), BTM_BleIsLinkKeyKnown, (const RawAddress address),
              (override));
  MOCK_METHOD((std::optional<tBLE_BD_ADDR>), BTM_BleGetIdentityAddress,
              (const RawAddress address), (override));
};

/**
+15 −0
Original line number Diff line number Diff line
@@ -1961,3 +1961,18 @@ std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address) {

  return p_dev_rec->ble_keys.irk;
}

bool BTM_BleIsLinkKeyKnown(const RawAddress address) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address);
  return p_dev_rec != nullptr && p_dev_rec->is_le_link_key_known();
}

std::optional<tBLE_BD_ADDR> BTM_BleGetIdentityAddress(
    const RawAddress address) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address);
  if (p_dev_rec == nullptr) {
    return std::nullopt;
  }

  return p_dev_rec->ble.identity_address_with_type;
}
+31 −0
Original line number Diff line number Diff line
@@ -235,3 +235,34 @@ std::optional<Octet16> BTM_BleGetPeerLTK(const RawAddress address);
 *
 ******************************************************************************/
std::optional<Octet16> BTM_BleGetPeerIRK(const RawAddress address);

/*******************************************************************************
 *
 * Function         BTM_BleIsLinkKeyKnown
 *
 * Description      This function is used to check whether the link key
 *                  of a peer (LE) device is known or not
 *
 * Parameters:      address: address of the peer device
 *
 * Returns          true if the link key is known
 *                  false otherwise
 *
 ******************************************************************************/
bool BTM_BleIsLinkKeyKnown(const RawAddress address);

/*******************************************************************************
 *
 * Function         BTM_BleGetIdentityAddress
 *
 * Description      This function is called to get the identity address
 *                  (with type) of a peer (LE) device.
 *
 * Parameters:      address: address of the peer device
 *
 * Returns          the identity address in std::optional if the remote device
 *                  is present in security database
 *                  std::nullopt if the device is not present
 *
 ******************************************************************************/
std::optional<tBLE_BD_ADDR> BTM_BleGetIdentityAddress(const RawAddress address);