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

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

vc: Improve handling connection timeout

Since VC is using opportunistic connect, make sure to start if over when
gatt sends OPEN event with a status error, which is usually a case when
direct connect did not succeed.

Bug: 331775328
Flag: Exempt, regression tested with unit test, new test added
Test: atest bluetooth_vc_test

Change-Id: I0f4d76684dca50ce8ccbb44754a0f0dcec08780b
parent 9e5271d2
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -172,6 +172,7 @@ class VolumeControlImpl : public VolumeControl {
    if (status != GATT_SUCCESS) {
    if (status != GATT_SUCCESS) {
      log::info("Failed to connect to Volume Control device");
      log::info("Failed to connect to Volume Control device");
      device_cleanup_helper(device, device->connecting_actively);
      device_cleanup_helper(device, device->connecting_actively);
      StartOpportunisticConnect(address);
      return;
      return;
    }
    }


+27 −7
Original line number Original line Diff line number Diff line
@@ -422,9 +422,10 @@ class VolumeControlTest : public ::testing::Test {
    TestAppUnregister();
    TestAppUnregister();
  }
  }


  void GetConnectedEvent(const RawAddress& address, uint16_t conn_id) {
  void GetConnectedEvent(const RawAddress& address, uint16_t conn_id,
                         tGATT_STATUS status = GATT_SUCCESS) {
    tBTA_GATTC_OPEN event_data = {
    tBTA_GATTC_OPEN event_data = {
        .status = GATT_SUCCESS,
            .status = status,
            .conn_id = conn_id,
            .conn_id = conn_id,
            .client_if = gatt_if,
            .client_if = gatt_if,
            .remote_bda = address,
            .remote_bda = address,
@@ -650,6 +651,25 @@ TEST_F(VolumeControlTest, test_reconnect_after_interrupted_discovery) {
  TestAppUnregister();
  TestAppUnregister();
}
}


TEST_F(VolumeControlTest, test_verify_opportunistic_connect_active_after_connect_timeout) {
  const RawAddress address = GetTestAddress(0);

  TestAppRegister();
  TestAddFromStorage(address);
  Mock::VerifyAndClearExpectations(&gatt_interface);

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

  EXPECT_CALL(gatt_interface, CancelOpen(gatt_if, address, _)).Times(0);
  EXPECT_CALL(gatt_interface, Open(gatt_if, address, BTM_BLE_DIRECT_CONNECTION, true)).Times(1);

  GetConnectedEvent(address, 1, GATT_ERROR);
  Mock::VerifyAndClearExpectations(callbacks.get());
  Mock::VerifyAndClearExpectations(&gatt_interface);
  TestAppUnregister();
}

TEST_F(VolumeControlTest, test_reconnect_after_timeout) {
TEST_F(VolumeControlTest, test_reconnect_after_timeout) {
  const RawAddress address = GetTestAddress(0);
  const RawAddress address = GetTestAddress(0);