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

Commit 3d640b45 authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

Merge "[LE Audio] Improve the reconnection performance by using direct connect...

Merge "[LE Audio] Improve the reconnection performance by using direct connect parameters" am: e26ffe33 am: 78ffdf73 am: 5219c8eb

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2505621



Change-Id: I2b20aa6fc4a5330132dcdfab9d4afec39082e21a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 112cddc8 5219c8eb
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -173,6 +173,13 @@ bool BTM_BackgroundConnectAddressKnown(const RawAddress& address) {
/** Adds the device into acceptlist. Returns false if acceptlist is full and
 * device can't be added, true otherwise. */
bool BTM_AcceptlistAdd(const RawAddress& address) {
  return BTM_AcceptlistAdd(address, false);
}

/** Adds the device into acceptlist and indicates whether to using direct
 * connect parameters. Returns false if acceptlist is full and device can't
 * be added, true otherwise. */
bool BTM_AcceptlistAdd(const RawAddress& address, bool is_direct) {
  if (!controller_get_interface()->supports_ble()) {
    LOG_WARN("Controller does not support Le");
    return false;
@@ -181,8 +188,7 @@ bool BTM_AcceptlistAdd(const RawAddress& address) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address);

  return bluetooth::shim::ACL_AcceptLeConnectionFrom(
      convert_to_address_with_type(address, p_dev_rec),
      /* is_direct */ false);
      convert_to_address_with_type(address, p_dev_rec), is_direct);
}

/** Removes the device from acceptlist */
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@
 * device can't be added, true otherwise. */
extern bool BTM_AcceptlistAdd(const RawAddress& address);

/** Adds the device into acceptlist and indicates whether to using direct
 * connect parameters. Returns false if acceptlist is full and device can't
 * be added, true otherwise. */
extern bool BTM_AcceptlistAdd(const RawAddress& address, bool is_direct);

/** Removes the device from acceptlist */
extern void BTM_AcceptlistRemove(const RawAddress& address);

+2 −2
Original line number Diff line number Diff line
@@ -464,7 +464,7 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) {
  direct_connect_remove(app_id, address);
}

/** Add a device to the direcgt connection list.  Returns true if device
/** Add a device to the direct connection list. Returns true if device
 * added to the list, false otherwise */
bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
  LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id),
@@ -492,7 +492,7 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
  }

  if (!in_acceptlist) {
    if (!BTM_AcceptlistAdd(address)) {
    if (!BTM_AcceptlistAdd(address, true)) {
      // if we can't add to acceptlist, turn parameters back to slow.
      LOG_WARN("Unable to add le device to acceptlist");
      return false;
+10 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ namespace {
class AcceptlistMock {
 public:
  MOCK_METHOD1(AcceptlistAdd, bool(const RawAddress&));
  MOCK_METHOD2(AcceptlistAdd, bool(const RawAddress&, bool is_direct));
  MOCK_METHOD1(AcceptlistRemove, void(const RawAddress&));
  MOCK_METHOD0(AcceptlistClear, void());
  MOCK_METHOD2(OnConnectionTimedOut, void(uint8_t, const RawAddress&));
@@ -57,6 +58,10 @@ bool BTM_AcceptlistAdd(const RawAddress& address) {
  return localAcceptlistMock->AcceptlistAdd(address);
}

bool BTM_AcceptlistAdd(const RawAddress& address, bool is_direct) {
  return localAcceptlistMock->AcceptlistAdd(address, is_direct);
}

void BTM_AcceptlistRemove(const RawAddress& address) {
  return localAcceptlistMock->AcceptlistRemove(address);
}
@@ -166,7 +171,7 @@ TEST_F(BleConnectionManager, test_background_connection_multiple_clients) {
TEST_F(BleConnectionManager, test_direct_connection_client) {
  // Direct connect attempt: use faster scan parameters, add to acceptlist,
  // start 30 timeout
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1))
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1, true))
      .WillOnce(Return(true));
  EXPECT_CALL(*localAcceptlistMock, AcceptlistRemove(_)).Times(0);
  EXPECT_CALL(*AlarmMock::Get(), AlarmNew(_)).Times(1);
@@ -195,7 +200,7 @@ TEST_F(BleConnectionManager, test_direct_connection_client) {
/** Verify direct connection timeout does remove device from acceptlist, and
 * lower the connection scan parameters */
TEST_F(BleConnectionManager, test_direct_connect_timeout) {
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1))
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1, true))
      .WillOnce(Return(true));
  EXPECT_CALL(*AlarmMock::Get(), AlarmNew(_)).Times(1);
  alarm_callback_t alarm_callback = nullptr;
@@ -223,7 +228,7 @@ TEST_F(BleConnectionManager, test_direct_connect_timeout) {

/** Verify that we properly handle successfull direct connection */
TEST_F(BleConnectionManager, test_direct_connection_success) {
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1))
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1, true))
      .WillOnce(Return(true));
  EXPECT_CALL(*AlarmMock::Get(), AlarmNew(_)).Times(1);
  EXPECT_CALL(*AlarmMock::Get(), AlarmSetOnMloop(_, _, _, _)).Times(1);
@@ -249,7 +254,7 @@ TEST_F(BleConnectionManager, test_app_unregister) {
   * - unregistration of Client2 should trigger address2 removal
   */

  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1))
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1, true))
      .WillOnce(Return(true));
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address2))
      .WillOnce(Return(true));
@@ -268,7 +273,7 @@ TEST_F(BleConnectionManager, test_app_unregister) {

/** Verify adding device to both direct connection and background connection. */
TEST_F(BleConnectionManager, test_direct_and_background_connect) {
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1))
  EXPECT_CALL(*localAcceptlistMock, AcceptlistAdd(address1, true))
      .WillOnce(Return(true));
  EXPECT_CALL(*localAcceptlistMock, AcceptlistRemove(_)).Times(0);
  EXPECT_CALL(*AlarmMock::Get(), AlarmNew(_)).Times(1);
+6 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ struct BTM_BackgroundConnectAddressKnown BTM_BackgroundConnectAddressKnown;
struct BTM_SetLeConnectionModeToFast BTM_SetLeConnectionModeToFast;
struct BTM_SetLeConnectionModeToSlow BTM_SetLeConnectionModeToSlow;
struct BTM_AcceptlistAdd BTM_AcceptlistAdd;
struct BTM_AcceptlistAddDirect BTM_AcceptlistAddDirect;
struct BTM_AcceptlistRemove BTM_AcceptlistRemove;
struct BTM_AcceptlistClear BTM_AcceptlistClear;

@@ -96,6 +97,11 @@ bool BTM_AcceptlistAdd(const RawAddress& address) {
  inc_func_call_count(__func__);
  return test::mock::stack_btm_ble_bgconn::BTM_AcceptlistAdd(address);
}
bool BTM_AcceptlistAdd(const RawAddress& address, bool is_direct) {
  inc_func_call_count(__func__);
  return test::mock::stack_btm_ble_bgconn::BTM_AcceptlistAddDirect(address,
                                                                   is_direct);
}
void BTM_AcceptlistRemove(const RawAddress& address) {
  inc_func_call_count(__func__);
  test::mock::stack_btm_ble_bgconn::BTM_AcceptlistRemove(address);
Loading