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

Commit f849da0c authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Fix ConfigureStream for device using Caching

This is a follow up fix for a corner case triggered behind the flag
`leaudio_improve_switch_during_phone_call`

Without this flag if feature behind the flag is triggered for the
devices using Configuration Caching, stream creation might not success
because client.cc is not notified about the configuration.

Bug: 382059519
Bug: 369322905
Flag: com::android::bluetooth:flags::leaudio_improve_switch_during_phone_call
Test: atest bluetooth_le_audio_test
Change-Id: I1ef80762afc246108a38b4384aed1dbd5f72a137
parent 811f3370
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2151,7 +2151,8 @@ private:
        /* Last node configured, process group to codec configured state */
        group->SetState(AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);

        if (group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
        if (group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING ||
            group->GetTargetState() == AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED) {
          if (group->cig.GetState() == CigState::CREATED) {
            /* It can happen on the earbuds switch scenario. When one device
             * is getting remove while other is adding to the stream and CIG is
+62 −0
Original line number Diff line number Diff line
@@ -7370,6 +7370,68 @@ TEST_F(StateMachineTest, StartStreamAfterConfigureToQoS) {
  testing::Mock::VerifyAndClearExpectations(&mock_callbacks_);
}

TEST_F(StateMachineTest, StartStreamAfterConfigureToQoS_ConfigurationCaching) {
  const auto context_type = kContextTypeMedia;
  const auto leaudio_group_id = 6;
  const auto num_devices = 2;

  ContentControlIdKeeper::GetInstance()->SetCcid(media_context, media_ccid);

  // Prepare multiple fake connected devices in a group
  auto* group = PrepareSingleTestDeviceGroup(leaudio_group_id, context_type, num_devices);
  ASSERT_EQ(group->Size(), num_devices);

  PrepareConfigureCodecHandler(group, 0, true);
  PrepareConfigureQosHandler(group);
  PrepareEnableHandler(group);
  PrepareDisableHandler(group);
  PrepareReleaseHandler(group);

  InjectInitialConfiguredNotification(group);

  auto* leAudioDevice = group->GetFirstDevice();
  auto expected_devices_written = 0;
  while (leAudioDevice) {
    /* Three Writes:
     * 1. Codec configure
     * 2: Codec QoS
     * 3: Enabling
     */
    EXPECT_CALL(gatt_queue,
                WriteCharacteristic(leAudioDevice->conn_id_, leAudioDevice->ctp_hdls_.val_hdl, _,
                                    GATT_WRITE_NO_RSP, _, _))
            .Times(3);
    expected_devices_written++;
    leAudioDevice = group->GetNextDevice(leAudioDevice);
  }
  ASSERT_EQ(expected_devices_written, num_devices);

  // Validate GroupStreamStatus
  EXPECT_CALL(mock_callbacks_,
              StatusReportCb(leaudio_group_id,
                             bluetooth::le_audio::GroupStreamStatus::CONFIGURED_BY_USER));

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

  testing::Mock::VerifyAndClearExpectations(&mock_callbacks_);
  ASSERT_EQ(1, get_func_call_count("alarm_cancel"));

  // Validate GroupStreamStatus
  EXPECT_CALL(mock_callbacks_,
              StatusReportCb(leaudio_group_id, bluetooth::le_audio::GroupStreamStatus::STREAMING));

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

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

TEST_F(StateMachineTest, StopStreamAfterConfigureToQoS) {
  const auto context_type = kContextTypeMedia;
  const auto leaudio_group_id = 6;