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

Commit 135b4799 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Merge "leaudio: Handle OnGattConnect for already connected device" into main

parents a8e566a2 a2cfff78
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1909,6 +1909,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);
@@ -1947,6 +1953,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
@@ -1972,8 +1981,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
@@ -4111,6 +4111,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);
@@ -4135,6 +4136,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_,
@@ -4142,8 +4144,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_);
@@ -4155,6 +4157,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);