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

Commit 5abc4618 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

has: Allow to connect profile only when device is bonded

Fixing a race, when profile Connect message reach the native stack just
after device got unbonded.

Bug: 329781005
Test: atest bluetooth_has_test
Flag: Exempt, Fixing race which will happen only on the stress tests
Change-Id: I39cd67348f149307c276bef29acf0a1b3c1bdc14
parent bfd8de08
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -150,7 +150,14 @@ class HasClientImpl : public HasClient {
  ~HasClientImpl() override = default;

  void Connect(const RawAddress& address) override {
    DLOG(INFO) << __func__ << ": " <<  ADDRESS_TO_LOGGABLE_STR(address);
    log::info("{}", ADDRESS_TO_LOGGABLE_CSTR(address));

    if (!BTM_IsLinkKeyKnown(address, BT_TRANSPORT_LE)) {
      log::error("Connecting  {} when not bonded",
                 ADDRESS_TO_LOGGABLE_CSTR(address));
      callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, address);
      return;
    }

    std::vector<RawAddress> addresses = {address};
    auto csis_api = CsisClient::Get();
+24 −0
Original line number Diff line number Diff line
@@ -663,6 +663,9 @@ class HasClientTestBase : public ::testing::Test {

    encryption_result = true;

    ON_CALL(btm_interface, IsLinkKeyKnown(_, _))
        .WillByDefault(DoAll(Return(true)));

    ON_CALL(btm_interface, SetEncryption(_, _, _, _, _))
        .WillByDefault(
            Invoke([this](const RawAddress& bd_addr, tBT_TRANSPORT transport,
@@ -1231,6 +1234,27 @@ TEST_F(HasClientTest, test_add_from_storage) {
  TestAddFromStorage(GetTestAddress(2), 0, false);
}

TEST_F(HasClientTest, test_connect_after_remove) {
  const RawAddress test_address = GetTestAddress(1);

  /* Override the default action to prevent us sendind the connected event */
  EXPECT_CALL(gatt_interface,
              Open(gatt_if, test_address, BTM_BLE_DIRECT_CONNECTION, _))
      .WillOnce(Return());
  HasClient::Get()->Connect(test_address);
  TestDisconnect(test_address, GATT_INVALID_CONN_ID);
  Mock::VerifyAndClearExpectations(&gatt_interface);

  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::DISCONNECTED, test_address));

  // Device has no Link Key
  ON_CALL(btm_interface, IsLinkKeyKnown(test_address, _))
      .WillByDefault(DoAll(Return(true)));
  HasClient::Get()->Connect(test_address);
  Mock::VerifyAndClearExpectations(&callbacks);
}

TEST_F(HasClientTest, test_disconnect_non_connected) {
  const RawAddress test_address = GetTestAddress(1);