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

Commit 0b4e3186 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix setting disconnecting state for ASEs

Without this patch, when stream is canceled in Enabling state, when
CISes are not yet created and Data Path is not set, btm_iso
DisconnectCis could be called twice for bidirectional CIS and this could
lead to assert in btm_iso.

Bug: 376396494
Flag: Exempt, trivial and obvious fix.
Test: atest bluetooth_le_audio_test
Change-Id: I9df7b6e1c7bd706676a22c76e81c4b1e1cb29d2b
parent 19950429
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2946,6 +2946,11 @@ private:
      return CIS_STILL_NEEDED;
    }

    ase->cis_state = CisState::DISCONNECTING;
    if (bidirection_ase) {
      bidirection_ase->cis_state = CisState::DISCONNECTING;
    }

    group->RemoveCisFromStreamIfNeeded(leAudioDevice, ase->cis_conn_hdl);
    IsoManager::GetInstance()->DisconnectCis(ase->cis_conn_hdl, HCI_ERR_PEER_USER);
    log_history_->AddLogHistory(kLogStateMachineTag, group->group_id_, leAudioDevice->address_,
+48 −0
Original line number Diff line number Diff line
@@ -4920,6 +4920,54 @@ TEST_F(StateMachineTest, testStateTransitionTimeoutAndDisconnectWhenEnabling) {
  }
}

TEST_F(StateMachineTest, testInjectReleasingStateWhenEnabling) {
  const auto context_type = kContextTypeConversational;
  const int leaudio_group_id = 4;
  channel_count_ = kLeAudioCodecChannelCountSingleChannel;

  // Prepare fake connected device group
  auto* group = PrepareSingleTestDeviceGroup(leaudio_group_id, context_type);
  PrepareConfigureCodecHandler(group, 2);
  PrepareConfigureQosHandler(group, 2);
  PrepareEnableHandler(group, 0, true, false);

  InjectInitialConfiguredNotification(group);

  EXPECT_CALL(*mock_iso_manager_, CreateCig(_, _)).Times(1);
  EXPECT_CALL(*mock_iso_manager_, EstablishCis(_)).Times(1);
  EXPECT_CALL(*mock_iso_manager_, SetupIsoDataPath(_, _)).Times(0);
  EXPECT_CALL(*mock_iso_manager_, RemoveIsoDataPath(_, _)).Times(0);
  EXPECT_CALL(*mock_iso_manager_, DisconnectCis(_, _)).Times(0);
  EXPECT_CALL(*mock_iso_manager_, RemoveCig(_, _)).Times(0);

  // Stub Establish Cis and Remove CIG
  ON_CALL(*mock_iso_manager_, EstablishCis).WillByDefault(Return());
  ON_CALL(*mock_iso_manager_, RemoveCig).WillByDefault(Return());

  group->PrintDebugState();

  // Start the configuration and stream Media content
  ASSERT_TRUE(LeAudioGroupStateMachine::Get()->StartStream(
          group, context_type,
          {.sink = types::AudioContexts(context_type),
           .source = types::AudioContexts(context_type)}));

  testing::Mock::VerifyAndClearExpectations(mock_iso_manager_);

  group->PrintDebugState();

  log::info("Inject Release of all ASEs");

  EXPECT_CALL(*mock_iso_manager_, DisconnectCis(_, _)).Times(1);

  // Stub DisconnectCis to trigger the issue.
  ON_CALL(*mock_iso_manager_, DisconnectCis).WillByDefault(Return());

  InjectReleaseAndIdleStateForAGroup(group, true, false);

  testing::Mock::VerifyAndClearExpectations(mock_iso_manager_);
}

MATCHER_P(dataPathIsEq, expected, "") { return arg.data_path_id == expected; }

TEST_F(StateMachineTest, testConfigureDataPathForHost) {