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

Commit db35cef7 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

vc: 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_vc_test
Flag: Exempt, Fixing race which will happen only on the stress tests
Change-Id: Iece0175b7c4894fdf5254625c8f6d289e1f42c87
parent a3621575
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -117,6 +117,12 @@ class VolumeControlImpl : public VolumeControl {

    auto device = volume_control_devices_.FindByAddress(address);
    if (!device) {
      if (!BTM_IsLinkKeyKnown(address, BT_TRANSPORT_LE)) {
        log::error("Connecting  {} when not bonded",
                   ADDRESS_TO_LOGGABLE_CSTR(address));
        callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, address);
        return;
      }
      volume_control_devices_.Add(address, true);
    } else {
      device->connecting_actively = true;
@@ -675,6 +681,7 @@ class VolumeControlImpl : public VolumeControl {
    BTA_GATTC_CancelOpen(gatt_if_, address, false);

    Disconnect(address);
    volume_control_devices_.Remove(address);
  }

  void OnGattDisconnected(uint16_t connection_id, tGATT_IF /*client_if*/,
+31 −0
Original line number Diff line number Diff line
@@ -246,6 +246,9 @@ class VolumeControlTest : public ::testing::Test {
    gatt::SetMockBtaGattQueue(&gatt_queue);
    callbacks.reset(new MockVolumeControlCallbacks());

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

    // default action for GetCharacteristic function call
    ON_CALL(gatt_interface, GetCharacteristic(_, _))
        .WillByDefault(
@@ -568,6 +571,34 @@ TEST_F(VolumeControlTest, test_connect) {
  TestAppUnregister();
}

TEST_F(VolumeControlTest, test_connect_after_remove) {
  TestAppRegister();

  const RawAddress test_address = GetTestAddress(0);
  uint16_t conn_id = 1;

  TestConnect(test_address);
  GetConnectedEvent(test_address, conn_id);
  Mock::VerifyAndClearExpectations(callbacks.get());

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

  TestRemove(test_address, conn_id);
  Mock::VerifyAndClearExpectations(callbacks.get());

  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::DISCONNECTED, test_address))
      .Times(1);
  ON_CALL(btm_interface, IsLinkKeyKnown(_, _))
      .WillByDefault(DoAll(Return(false)));

  VolumeControl::Get()->Connect(test_address);
  Mock::VerifyAndClearExpectations(callbacks.get());
  TestAppUnregister();
}

TEST_F(VolumeControlTest, test_reconnect_after_interrupted_discovery) {
  const RawAddress test_address = GetTestAddress(0);