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

Commit 9f73c114 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

csis: Improve handling connection timeout

Since CSIS 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_csis_test
Change-Id: Icc17d7f7a99a033db0b5fe66a2adab7f72a4c8db
parent e7b9c320
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1956,6 +1956,7 @@ class CsisClientImpl : public CsisClient {
        callbacks_->OnConnectionState(evt.remote_bda,
                                      ConnectionState::DISCONNECTED);
      DoDisconnectCleanUp(device);
      StartOpportunisticConnect(evt.remote_bda);
      return;
    }

+32 −7
Original line number Diff line number Diff line
@@ -580,9 +580,10 @@ class CsisClientTest : public ::testing::Test {
    gatt_callback(BTA_GATTC_ENC_CMPL_CB_EVT, (tBTA_GATTC*)&event_data);
  }

  void InjectConnectedEvent(const RawAddress& address, uint16_t conn_id) {
  void InjectConnectedEvent(const RawAddress& address, uint16_t conn_id,
                            tGATT_STATUS status = GATT_SUCCESS) {
    tBTA_GATTC_OPEN event_data = {
        .status = GATT_SUCCESS,
            .status = status,
            .conn_id = conn_id,
            .client_if = gatt_if,
            .remote_bda = address,
@@ -760,6 +761,30 @@ TEST_F(CsisClientTest, test_connect) {
  TestAppUnregister();
}

TEST_F(CsisClientTest, test_verify_opportunistic_connect_active_after_connect_timeout) {
  TestAppRegister();

  std::vector<uint8_t> no_set_info;

  DeviceGroups::AddFromStorage(test_address, no_set_info);
  CsisClient::AddFromStorage(test_address, no_set_info);

  Mock::VerifyAndClearExpectations(&gatt_interface);
  Mock::VerifyAndClearExpectations(callbacks.get());

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

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

  InjectConnectedEvent(test_address, 0, GATT_ERROR);
  Mock::VerifyAndClearExpectations(&gatt_interface);
  Mock::VerifyAndClearExpectations(callbacks.get());
  TestAppUnregister();
}

TEST_F(CsisClientTest, test_disconnect_non_connected) {
  TestAppRegister();
  TestConnect(test_address);