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

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

leaudio: Handle OnGattConnect for already connected device

This is minor regression after
35c5e00d leaudio: Improve TA reconnection

Basically when calling Open for TA in the OnGattConnected function will
trigger OPEN event from GATT, which should be ignored.

Fixed implementation uncovered issue in one unit test which is fixed
here as well.

Bug: 311578937
Test: atest bluetooth_le_audio_client_test
Tag: #feature
Change-Id: I20dc6029ec07a1a1d649f00c19113601ea5f3aea
parent f8190200
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1902,6 +1902,12 @@ class LeAudioClientImpl : public LeAudioClient {

    if (!leAudioDevice) return;

    if (leAudioDevice->conn_id_ != GATT_INVALID_CONN_ID) {
      LOG_DEBUG("Already connected %s, conn_id=0x%04x",
                ADDRESS_TO_LOGGABLE_CSTR(address), leAudioDevice->conn_id_);
      return;
    }

    if (status != GATT_SUCCESS) {
      /* Clear current connection request and let it be set again if needed */
      BTA_GATTC_CancelOpen(gatt_if_, address, false);
@@ -1940,6 +1946,9 @@ class LeAudioClientImpl : public LeAudioClient {
      }
    }

    leAudioDevice->conn_id_ = conn_id;
    leAudioDevice->mtu_ = mtu;

    /* Remove device from the background connect (it might be either Allow list
     * or TA) and add it again with reconnection_mode_. In case it is TA, we are
     * sure that device will not be in the allow list for other applications
@@ -1965,8 +1974,6 @@ class LeAudioClientImpl : public LeAudioClient {
          DeviceConnectState::CONNECTED_BY_USER_GETTING_READY);
    }

    leAudioDevice->conn_id_ = conn_id;
    leAudioDevice->mtu_ = mtu;
    /* Check if the device is in allow list and update the flag */
    leAudioDevice->UpdateDeviceAllowlistFlag();
    if (BTM_SecIsSecurityPending(address)) {
+10 −2
Original line number Diff line number Diff line
@@ -4105,6 +4105,7 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
      .Times(0);
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address1, _))
      .WillByDefault(DoAll(Return(true)));

  EXPECT_CALL(mock_gatt_interface_,
              Open(gatt_if, test_address1, BTM_BLE_DIRECT_CONNECTION, _))
      .Times(0);
@@ -4129,6 +4130,7 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
  SyncOnMainLoop();
  ASSERT_TRUE(LeAudioClient::IsLeAudioClientRunning());
  Mock::VerifyAndClearExpectations(&mock_gatt_interface_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);

  // Simulate device is not there and phone fallbacks to targeted announcements
  EXPECT_CALL(mock_gatt_interface_,
@@ -4136,8 +4138,8 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);

  // Devices not found
  InjectConnectedEvent(test_address0, 0, GATT_ERROR);
  // Devices 0 is connected. Disconnect it
  InjectDisconnectedEvent(1, GATT_CONN_TERMINATE_PEER_USER);

  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_gatt_interface_);
@@ -4149,6 +4151,12 @@ TEST_F(UnicastTestNoInit, LoadStoredEarbudsCsisGroupedDifferently) {
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, _))
      .Times(1);

  /* Keep device in Getting Ready state */
  ON_CALL(mock_btm_interface_, BTM_IsEncrypted(test_address0, _))
      .WillByDefault(DoAll(Return(false)));
  ON_CALL(mock_btm_interface_, SetEncryption(test_address0, _, _, _, _))
      .WillByDefault(Return(BTM_SUCCESS));

  /* For background connect, test needs to Inject Connected Event */
  InjectConnectedEvent(test_address0, 1);