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

Commit 714651cb authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Fix state machine handling ACL disconnection

When the state machine is handling the disconnection state,
the device for a while still has the valid connection ID and
state. Configuration invalidation logic thinks the group still
has both devices connected and does not select the proper
configuration. This change moves the configuraiton cache
refresh after the connecion ID of the device is set to invalid.

Bug: 275154325
Test: atest --host bluetooth_le_audio_client_test bluetooth_le_audio_test --no-bazel-mode
Change-Id: Ie8a2147d7759defdb21e15a82a5a858386957d47
parent dfd3e73c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1923,8 +1923,6 @@ class LeAudioClientImpl : public LeAudioClient {
    BtaGattQueue::Clean(leAudioDevice->conn_id_);
    LeAudioDeviceGroup* group = aseGroups_.FindById(leAudioDevice->group_id_);

    groupStateMachine_->ProcessHciNotifAclDisconnected(group, leAudioDevice);

    DeregisterNotifications(leAudioDevice);

    callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, address);
@@ -1933,6 +1931,8 @@ class LeAudioClientImpl : public LeAudioClient {
    leAudioDevice->closing_stream_for_disconnection_ = false;
    leAudioDevice->encrypted_ = false;

    groupStateMachine_->ProcessHciNotifAclDisconnected(group, leAudioDevice);

    le_audio::MetricsCollector::Get()->OnConnectionStateChanged(
        leAudioDevice->group_id_, address, ConnectionState::DISCONNECTED,
        le_audio::ConnectionStatus::SUCCESS);
+15 −1
Original line number Diff line number Diff line
@@ -4050,10 +4050,12 @@ TEST_F(UnicastTest, TwoEarbuds2ndDisconnected) {
  LeAudioClient::Get()->GroupSetActive(group_id);

  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);
  auto group = streaming_groups.at(group_id);

  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_le_audio_source_hal_client_);
  SyncOnMainLoop();
  ASSERT_EQ(2, group->NumOfConnected());

  // Expect two iso channels to be fed with data
  uint8_t cis_count_out = 2;
@@ -4062,7 +4064,6 @@ TEST_F(UnicastTest, TwoEarbuds2ndDisconnected) {

  // Disconnect one device and expect the group to keep on streaming
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(0);
  auto group = streaming_groups.at(group_id);
  auto device = group->GetFirstDevice();
  for (auto& ase : device->ases_) {
    InjectCisDisconnected(group_id, ase.cis_conn_hdl);
@@ -4073,9 +4074,22 @@ TEST_F(UnicastTest, TwoEarbuds2ndDisconnected) {
                   BTM_BLE_BKG_CONNECT_TARGETED_ANNOUNCEMENTS, false))
      .Times(1);

  // Record NumOfConnected when groupStateMachine_ gets notified about the
  // disconnection
  int num_of_connected = 0;
  ON_CALL(mock_state_machine_, ProcessHciNotifAclDisconnected(_, _))
      .WillByDefault([&num_of_connected](LeAudioDeviceGroup* group,
                                         LeAudioDevice* leAudioDevice) {
        num_of_connected = group->NumOfConnected();
      });

  auto conn_id = device->conn_id_;
  InjectDisconnectedEvent(device->conn_id_, GATT_CONN_TERMINATE_PEER_USER);
  SyncOnMainLoop();

  // Make sure the state machine knows about the disconnected device
  ASSERT_EQ(1, num_of_connected);

  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);

  // Expect one channel ISO Data to be sent