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

Commit 7407fa10 authored by Partha Sarathi Saha's avatar Partha Sarathi Saha Committed by Chris Manton
Browse files

leaudio: Fix LE_AUDIO profile re-connect

Bug: 218534441
Tag: #feature
Sponsor: rlukasz@
Test: atest --host bluetooth_le_audio_client_test

Issue: LE_AUDIO profile was not seen to reconnect automatically
even when the device is reachable after a remote initiated
disconnection or disconnection due to timeout. Other profile
(VC) re-connected fine in these scenarios.

Fix- Added background reconnection request during disconnect
handling (if the disconnection is not intended by local host).

This change will help with reconnect in below scenarios
1. Peer device went out of range and later came back in range
2. Peer device is put into cradle (lid closed) and later
   taken out of cradle.

Note: Restoration of below merged-and-reverted-later gerrit
Iac25b1f9c:le_audio : Fix issue of LE Audio not connecting af...



Change-Id: I31451ba3dbef0af2e75d82070ccb7234266094be
parent d2739627
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1258,6 +1258,11 @@ class LeAudioClientImpl : public LeAudioClient {
        group_remove_node(group, address, true);
      }
      leAudioDevices_.Remove(address);
      return;
    }
    /* Attempt background re-connect if disconnect was not intended locally */
    if (reason != GATT_CONN_TERMINATE_LOCAL_HOST) {
      BTA_GATTC_Open(gatt_if_, address, false, false);
    }
  }

+27 −2
Original line number Diff line number Diff line
@@ -264,7 +264,9 @@ class UnicastTestNoInit : public Test {
            base::Unretained(this->gatt_callback), event_data));
  }

  void InjectDisconnectedEvent(uint16_t conn_id) {
  void InjectDisconnectedEvent(
      uint16_t conn_id,
      tGATT_DISCONN_REASON reason = GATT_CONN_TERMINATE_LOCAL_HOST) {
    ASSERT_NE(conn_id, GATT_INVALID_CONN_ID);
    ASSERT_NE(peer_devices.count(conn_id), 0u);

@@ -273,7 +275,7 @@ class UnicastTestNoInit : public Test {
        .conn_id = conn_id,
        .client_if = gatt_if,
        .remote_bda = peer_devices.at(conn_id)->addr,
        .reason = GATT_CONN_TERMINATE_PEER_USER,
        .reason = reason,
    };

    peer_devices.at(conn_id)->connected = false;
@@ -1769,6 +1771,29 @@ TEST_F(UnicastTest, ConnectDisconnectOneEarbud) {
  DisconnectLeAudio(test_address0, 1);
}

/* same as above case except the disconnect is initiated by remote */
TEST_F(UnicastTest, ConnectRemoteDisconnectOneEarbud) {
  const RawAddress test_address0 = GetTestAddress(0);
  SetSampleDatabaseEarbudsValid(1, test_address0,
                                codec_spec_conf::kLeAudioLocationStereo,
                                codec_spec_conf::kLeAudioLocationStereo);
  EXPECT_CALL(mock_client_callbacks_,
              OnConnectionState(ConnectionState::CONNECTED, test_address0))
      .Times(1);
  ConnectLeAudio(test_address0);
  EXPECT_CALL(mock_client_callbacks_,
              OnConnectionState(ConnectionState::DISCONNECTED, test_address0))
      .Times(1);
  /* For remote disconnection, expect stack to try background re-connect */
  EXPECT_CALL(mock_gatt_interface_, Open(gatt_if, test_address0, false, _))
      .Times(1);
  global_conn_id = 1; /* Reset to keep conn_id same during re-connect */
  EXPECT_CALL(mock_client_callbacks_,
              OnConnectionState(ConnectionState::CONNECTED, test_address0))
      .Times(1);
  InjectDisconnectedEvent(1, GATT_CONN_TERMINATE_PEER_USER);
}

TEST_F(UnicastTest, ConnectTwoEarbudsCsisGrouped) {
  uint8_t group_size = 2;
  int group_id = 2;