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

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

Merge "leaudio: Fix possible race on closing stream" into main

parents 738b2635 e661c676
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -1959,6 +1959,17 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
          return;
        }

        {
          auto activeDevice = group->GetFirstActiveDevice();
          if (activeDevice) {
            LOG_DEBUG(
                "There is at least one active device %s, wait to become "
                "inactive",
                ADDRESS_TO_LOGGABLE_CSTR(activeDevice->address_));
            return;
          }
        }

        /* Last node is in releasing state*/
        group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);
        /* Remote device has cache and keep staying in configured state after
+26 −4
Original line number Diff line number Diff line
@@ -3771,15 +3771,26 @@ TEST_F(StateMachineTest, testHandlingCachedCodecConfig2Devices) {

  testing::Mock::VerifyAndClearExpectations(&mock_callbacks_);

  /* Single disconnect as it is bidirectional Cis*/
  /* Two disconnect as it is two bidirectional Cises */
  EXPECT_CALL(*mock_iso_manager_, DisconnectCis(_, _)).Times(2);

  LOG_ERROR("STOP");
  // Validate initial GroupStreamStatus
  EXPECT_CALL(mock_callbacks_,
              StatusReportCb(leaudio_group_id,
                             bluetooth::le_audio::GroupStreamStatus::RELEASING))
      .Times(1);
  EXPECT_CALL(
      mock_callbacks_,
      StatusReportCb(
          leaudio_group_id,
          bluetooth::le_audio::GroupStreamStatus::CONFIGURED_AUTONOMOUS))
      .Times(0);

  // Stop the stream
  LeAudioGroupStateMachine::Get()->StopStream(group);

  for (auto& ase : firstDevice->ases_) {
    LOG_ERROR("%s , %d, %s", ADDRESS_TO_LOGGABLE_CSTR(firstDevice->address_),
    LOG_DEBUG("%s , %d, %s", ADDRESS_TO_LOGGABLE_CSTR(firstDevice->address_),
              ase.id, bluetooth::common::ToString(ase.state).c_str());
    ASSERT_EQ(ase.state, types::AseState::BTA_LE_AUDIO_ASE_STATE_RELEASING);
    // Simulate autonomus configured state.
@@ -3788,8 +3799,17 @@ TEST_F(StateMachineTest, testHandlingCachedCodecConfig2Devices) {
                               &cached_codec_configuration_map_[ase.id]);
  }

  testing::Mock::VerifyAndClearExpectations(&mock_callbacks_);

  /* When ALL devices got inactive, we should got the proper group status */
  EXPECT_CALL(
      mock_callbacks_,
      StatusReportCb(
          leaudio_group_id,
          bluetooth::le_audio::GroupStreamStatus::CONFIGURED_AUTONOMOUS))
      .Times(1);
  for (auto& ase : secondDevice->ases_) {
    LOG_ERROR("%s , %d, %s", ADDRESS_TO_LOGGABLE_CSTR(firstDevice->address_),
    LOG_DEBUG("%s , %d, %s", ADDRESS_TO_LOGGABLE_CSTR(firstDevice->address_),
              ase.id, bluetooth::common::ToString(ase.state).c_str());
    ASSERT_EQ(ase.state, types::AseState::BTA_LE_AUDIO_ASE_STATE_RELEASING);
    // Simulate autonomus configured state.
@@ -3797,6 +3817,8 @@ TEST_F(StateMachineTest, testHandlingCachedCodecConfig2Devices) {
                               ascs::kAseStateCodecConfigured,
                               &cached_codec_configuration_map_[ase.id]);
  }

  testing::Mock::VerifyAndClearExpectations(&mock_callbacks_);
}

TEST_F(StateMachineTest, testStateTransitionTimeoutOnIdleState) {