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

Commit d26f2419 authored by Łukasz Rymanowski (xWF)'s avatar Łukasz Rymanowski (xWF) Committed by Gerrit Code Review
Browse files

Merge changes I7e5c6e3d,Ic0dffd52 into main

* changes:
  leaudio: Minor cleanups around state machine mocks
  leaudio: Minor cleanup
parents 57b26681 a1b76d5a
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -233,11 +233,11 @@ public:
    alarm_free(suspend_timeout_);
    alarm_free(suspend_timeout_);
  }
  }


  LeAudioClientImpl(bluetooth::le_audio::LeAudioClientCallbacks* callbacks_,
  LeAudioClientImpl(bluetooth::le_audio::LeAudioClientCallbacks* callbacks,
                    LeAudioGroupStateMachine::Callbacks* state_machine_callbacks_,
                    LeAudioGroupStateMachine::Callbacks* state_machine_callbacks,
                    base::Closure initCb)
                    base::Closure initCb)
      : gatt_if_(0),
      : gatt_if_(0),
        callbacks_(callbacks_),
        callbacks_(callbacks),
        active_group_id_(bluetooth::groups::kGroupUnknown),
        active_group_id_(bluetooth::groups::kGroupUnknown),
        configuration_context_type_(LeAudioContextType::UNINITIALIZED),
        configuration_context_type_(LeAudioContextType::UNINITIALIZED),
        in_call_metadata_context_types_({.sink = AudioContexts(), .source = AudioContexts()}),
        in_call_metadata_context_types_({.sink = AudioContexts(), .source = AudioContexts()}),
@@ -256,7 +256,7 @@ public:
        close_vbc_timeout_(alarm_new("LeAudioCloseVbcTimeout")),
        close_vbc_timeout_(alarm_new("LeAudioCloseVbcTimeout")),
        suspend_timeout_(alarm_new("LeAudioSuspendTimeout")),
        suspend_timeout_(alarm_new("LeAudioSuspendTimeout")),
        disable_timer_(alarm_new("LeAudioDisableTimer")) {
        disable_timer_(alarm_new("LeAudioDisableTimer")) {
    LeAudioGroupStateMachine::Initialize(state_machine_callbacks_);
    LeAudioGroupStateMachine::Initialize(state_machine_callbacks);
    groupStateMachine_ = LeAudioGroupStateMachine::Get();
    groupStateMachine_ = LeAudioGroupStateMachine::Get();


    log::info("Reconnection mode: TARGETED_ANNOUNCEMENTS");
    log::info("Reconnection mode: TARGETED_ANNOUNCEMENTS");
+134 −126
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@
#include "common/message_loop_thread.h"
#include "common/message_loop_thread.h"
#include "fake_osi.h"
#include "fake_osi.h"
#include "gatt/database_builder.h"
#include "gatt/database_builder.h"
#include "gmock/gmock.h"
#include "hardware/bt_gatt_types.h"
#include "hardware/bt_gatt_types.h"
#include "hardware/bt_le_audio.h"
#include "hardware/bt_le_audio.h"
#include "hci/controller_interface_mock.h"
#include "hci/controller_interface_mock.h"
@@ -850,16 +849,15 @@ protected:
            .WillByDefault(SaveArg<0>(&state_machine_callbacks_));
            .WillByDefault(SaveArg<0>(&state_machine_callbacks_));
    ON_CALL(mock_state_machine_, ConfigureStream(_, _, _, _))
    ON_CALL(mock_state_machine_, ConfigureStream(_, _, _, _))
            .WillByDefault(
            .WillByDefault([this](LeAudioDeviceGroup* group, types::LeAudioContextType context_type,
                    [this](LeAudioDeviceGroup* group, types::LeAudioContextType context_type,
                                  types::BidirectionalPair<types::AudioContexts>
                           types::BidirectionalPair<types::AudioContexts> metadata_context_types,
                                          metadata_context_types,
                                  types::BidirectionalPair<std::vector<uint8_t>> ccid_lists) {
                                  types::BidirectionalPair<std::vector<uint8_t>> ccid_lists) {
              bool isReconfiguration = group->IsPendingConfiguration();
              bool isReconfiguration = group->IsPendingConfiguration();
                      /* This shall be called only for user reconfiguration */
              log::info("ConfigureStream: group_id {}, context_type {} isReconfiguration {}",
                      if (!isReconfiguration) {
                        group->group_id_, bluetooth::common::ToString(context_type),
                        return false;
                        isReconfiguration);
                      }
              /* Do what ReleaseCisIds(group) does: start */
              /* Do what ReleaseCisIds(group) does: start */
              LeAudioDevice* leAudioDevice = group->GetFirstDevice();
              LeAudioDevice* leAudioDevice = group->GetFirstDevice();
@@ -873,7 +871,7 @@ protected:
              /* end */
              /* end */
              if (!group->Configure(context_type, metadata_context_types, ccid_lists)) {
              if (!group->Configure(context_type, metadata_context_types, ccid_lists)) {
                        log::error("Could not configure ASEs for group {} content type {}",
                log::error("ConfigureStream: Could not configure ASEs for group {} content type {}",
                           group->group_id_, int(context_type));
                           group->group_id_, int(context_type));
                return false;
                return false;
@@ -881,6 +879,9 @@ protected:
              group->cig.GenerateCisIds(context_type);
              group->cig.GenerateCisIds(context_type);
              types::AseState config_state =
                      types::AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED;
              for (LeAudioDevice* device = group->GetFirstDevice(); device != nullptr;
              for (LeAudioDevice* device = group->GetFirstDevice(); device != nullptr;
                   device = group->GetNextDevice(device)) {
                   device = group->GetNextDevice(device)) {
                if (!group->cig.AssignCisIds(device)) {
                if (!group->cig.AssignCisIds(device)) {
@@ -892,21 +893,22 @@ protected:
                }
                }
                for (auto& ase : device->ases_) {
                for (auto& ase : device->ases_) {
                  if (!ase.active) {
                    continue;
                  }
                  ase.cis_state = types::CisState::IDLE;
                  ase.cis_state = types::CisState::IDLE;
                  ase.data_path_state = types::DataPathState::IDLE;
                  ase.data_path_state = types::DataPathState::IDLE;
                          ase.active = false;
                  ase.state = config_state;
                          ase.state = types::AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED;
                }
                }
              }
              }
              // Inject the state
              // Inject the state
                      group->SetTargetState(
              group->SetTargetState(config_state);
                              types::AseState::BTA_LE_AUDIO_ASE_STATE_CODEC_CONFIGURED);
              group->SetState(group->GetTargetState());
              group->SetState(group->GetTargetState());
              group->ClearPendingConfiguration();
              group->ClearPendingConfiguration();
              do_in_main_thread(base::BindOnce(
              do_in_main_thread(base::BindOnce(
                              [](int group_id,
                      [](int group_id, bluetooth::le_audio::LeAudioGroupStateMachine::Callbacks*
                                 bluetooth::le_audio::LeAudioGroupStateMachine::Callbacks*
                                               state_machine_callbacks) {
                                               state_machine_callbacks) {
                        state_machine_callbacks->StatusReportCb(
                        state_machine_callbacks->StatusReportCb(
                                group_id, GroupStreamStatus::CONFIGURED_BY_USER);
                                group_id, GroupStreamStatus::CONFIGURED_BY_USER);
@@ -918,6 +920,12 @@ protected:
    ON_CALL(mock_state_machine_, AttachToStream(_, _, _))
    ON_CALL(mock_state_machine_, AttachToStream(_, _, _))
            .WillByDefault([this](LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice,
            .WillByDefault([this](LeAudioDeviceGroup* group, LeAudioDevice* leAudioDevice,
                                  types::BidirectionalPair<std::vector<uint8_t>> ccids) {
                                  types::BidirectionalPair<std::vector<uint8_t>> ccids) {
              log::info(
                      "AttachToStream: group_id {}, address {}, current_state {}, target_state {}",
                      group->group_id_, leAudioDevice->address_,
                      bluetooth::common::ToString(group->GetState()),
                      bluetooth::common::ToString(group->GetTargetState()));
              if (group->GetState() != types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
              if (group->GetState() != types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
                if (group->GetTargetState() == types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
                if (group->GetTargetState() == types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING) {
                  attach_to_stream_scheduled = true;
                  attach_to_stream_scheduled = true;
@@ -964,7 +972,8 @@ protected:
                    stream_conf->stream_params.source.num_of_channels += ase.channel_count;
                    stream_conf->stream_params.source.num_of_channels += ase.channel_count;
                    log::info(
                    log::info(
                            "Added Source Stream Configuration. CIS Connection Handle: "
                            "AttachToStream: Added Source Stream Configuration. CIS Connection "
                            "Handle: "
                            "{}, Audio Channel Allocation: {}, Source Number Of "
                            "{}, Audio Channel Allocation: {}, Source Number Of "
                            "Devices: {}, Source Number Of Channels: {}",
                            "Devices: {}, Source Number Of Channels: {}",
                            ase.cis_conn_hdl, *core_config.audio_channel_allocation,
                            ase.cis_conn_hdl, *core_config.audio_channel_allocation,
@@ -985,7 +994,8 @@ protected:
                    stream_conf->stream_params.sink.num_of_channels += ase.channel_count;
                    stream_conf->stream_params.sink.num_of_channels += ase.channel_count;
                    log::info(
                    log::info(
                            "Added Sink Stream Configuration. CIS Connection Handle: "
                            "AttachToStream: Added Sink Stream Configuration. CIS Connection "
                            "Handle: "
                            "{}, Audio Channel Allocation: {}, Sink Number Of Devices: "
                            "{}, Audio Channel Allocation: {}, Sink Number Of Devices: "
                            "{}, Sink Number Of Channels: {}",
                            "{}, Sink Number Of Channels: {}",
                            ase.cis_conn_hdl, *core_config.audio_channel_allocation,
                            ase.cis_conn_hdl, *core_config.audio_channel_allocation,
@@ -1004,7 +1014,7 @@ protected:
                                          metadata_context_types,
                                          metadata_context_types,
                                  types::BidirectionalPair<std::vector<uint8_t>> ccid_lists) {
                                  types::BidirectionalPair<std::vector<uint8_t>> ccid_lists) {
              auto group_state = group->GetState();
              auto group_state = group->GetState();
              log::info("group {} state {}, context type {}", group->group_id_,
              log::info("StartStream: group {} state {}, context type {}", group->group_id_,
                        bluetooth::common::ToString(group_state),
                        bluetooth::common::ToString(group_state),
                        bluetooth::common::ToString(context_type));
                        bluetooth::common::ToString(context_type));
@@ -1015,6 +1025,10 @@ protected:
                return true;
                return true;
              }
              }
              // Inject the state
              group->SetTargetState(types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
              if (group_state != types::AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED) {
                /* Do what ReleaseCisIds(group) does: start */
                /* Do what ReleaseCisIds(group) does: start */
                LeAudioDevice* leAudioDevice = group->GetFirstDevice();
                LeAudioDevice* leAudioDevice = group->GetFirstDevice();
                while (leAudioDevice != nullptr) {
                while (leAudioDevice != nullptr) {
@@ -1027,7 +1041,7 @@ protected:
                /* end */
                /* end */
                if (!group->Configure(context_type, metadata_context_types, ccid_lists)) {
                if (!group->Configure(context_type, metadata_context_types, ccid_lists)) {
                log::error("failed to set ASE configuration");
                  log::error("StartStream: failed to set ASE configuration");
                  return false;
                  return false;
                }
                }
@@ -1048,6 +1062,7 @@ protected:
                    group->AssignCisConnHandlesToAses(device);
                    group->AssignCisConnHandlesToAses(device);
                  }
                  }
                }
                }
              }
              auto* stream_conf = &group->stream_conf;
              auto* stream_conf = &group->stream_conf;
@@ -1095,7 +1110,7 @@ protected:
                      } else {
                      } else {
                        log::assert_that(stream_conf->stream_params.source.sample_frequency_hz ==
                        log::assert_that(stream_conf->stream_params.source.sample_frequency_hz ==
                                                 core_config.GetSamplingFrequencyHz(),
                                                 core_config.GetSamplingFrequencyHz(),
                                         "sample freq mismatch: {}!={}",
                                         "StartStream: sample freq mismatch: {}!={}",
                                         stream_conf->stream_params.source.sample_frequency_hz,
                                         stream_conf->stream_params.source.sample_frequency_hz,
                                         core_config.GetSamplingFrequencyHz());
                                         core_config.GetSamplingFrequencyHz());
                      }
                      }
@@ -1106,7 +1121,7 @@ protected:
                      } else {
                      } else {
                        log::assert_that(stream_conf->stream_params.source.octets_per_codec_frame ==
                        log::assert_that(stream_conf->stream_params.source.octets_per_codec_frame ==
                                                 *core_config.octets_per_codec_frame,
                                                 *core_config.octets_per_codec_frame,
                                         "octets per frame mismatch: {}!={}",
                                         "StartStream: octets per frame mismatch: {}!={}",
                                         stream_conf->stream_params.source.octets_per_codec_frame,
                                         stream_conf->stream_params.source.octets_per_codec_frame,
                                         *core_config.octets_per_codec_frame);
                                         *core_config.octets_per_codec_frame);
                      }
                      }
@@ -1120,13 +1135,13 @@ protected:
                        log::assert_that(
                        log::assert_that(
                                stream_conf->stream_params.source.codec_frames_blocks_per_sdu ==
                                stream_conf->stream_params.source.codec_frames_blocks_per_sdu ==
                                        *core_config.codec_frames_blocks_per_sdu,
                                        *core_config.codec_frames_blocks_per_sdu,
                                "codec_frames_blocks_per_sdu: {}!={}",
                                "StartStream: codec_frames_blocks_per_sdu: {}!={}",
                                stream_conf->stream_params.source.codec_frames_blocks_per_sdu,
                                stream_conf->stream_params.source.codec_frames_blocks_per_sdu,
                                *core_config.codec_frames_blocks_per_sdu);
                                *core_config.codec_frames_blocks_per_sdu);
                      }
                      }
                      log::info(
                      log::info(
                              "Added Source Stream Configuration. CIS Connection "
                              "StartStream: Added Source Stream Configuration. CIS Connection "
                              "Handle: {}, Audio Channel Allocation: {}, Source Number "
                              "Handle: {}, Audio Channel Allocation: {}, Source Number "
                              "Of Devices: {}, Source Number Of Channels: {}",
                              "Of Devices: {}, Source Number Of Channels: {}",
                              ase.cis_conn_hdl, *core_config.audio_channel_allocation,
                              ase.cis_conn_hdl, *core_config.audio_channel_allocation,
@@ -1155,7 +1170,7 @@ protected:
                      } else {
                      } else {
                        log::assert_that(stream_conf->stream_params.sink.sample_frequency_hz ==
                        log::assert_that(stream_conf->stream_params.sink.sample_frequency_hz ==
                                                 core_config.GetSamplingFrequencyHz(),
                                                 core_config.GetSamplingFrequencyHz(),
                                         "sample freq mismatch: {}!={}",
                                         "StartStream: sample freq mismatch: {}!={}",
                                         stream_conf->stream_params.sink.sample_frequency_hz,
                                         stream_conf->stream_params.sink.sample_frequency_hz,
                                         core_config.GetSamplingFrequencyHz());
                                         core_config.GetSamplingFrequencyHz());
                      }
                      }
@@ -1166,7 +1181,7 @@ protected:
                      } else {
                      } else {
                        log::assert_that(stream_conf->stream_params.sink.octets_per_codec_frame ==
                        log::assert_that(stream_conf->stream_params.sink.octets_per_codec_frame ==
                                                 *core_config.octets_per_codec_frame,
                                                 *core_config.octets_per_codec_frame,
                                         "octets per frame mismatch: {}!={}",
                                         "StartStream: octets per frame mismatch: {}!={}",
                                         stream_conf->stream_params.sink.octets_per_codec_frame,
                                         stream_conf->stream_params.sink.octets_per_codec_frame,
                                         *core_config.octets_per_codec_frame);
                                         *core_config.octets_per_codec_frame);
                      }
                      }
@@ -1180,13 +1195,14 @@ protected:
                        log::assert_that(
                        log::assert_that(
                                stream_conf->stream_params.sink.codec_frames_blocks_per_sdu ==
                                stream_conf->stream_params.sink.codec_frames_blocks_per_sdu ==
                                        *core_config.codec_frames_blocks_per_sdu,
                                        *core_config.codec_frames_blocks_per_sdu,
                                "codec_frames_blocks_per_sdu: {}!={}",
                                "StartStream: codec_frames_blocks_per_sdu: {}!={}",
                                stream_conf->stream_params.sink.codec_frames_blocks_per_sdu,
                                stream_conf->stream_params.sink.codec_frames_blocks_per_sdu,
                                *core_config.codec_frames_blocks_per_sdu);
                                *core_config.codec_frames_blocks_per_sdu);
                      }
                      }
                      log::info(
                      log::info(
                              "Added Sink Stream Configuration. CIS Connection Handle: "
                              "StartStream: Added Sink Stream Configuration. CIS Connection "
                              "Handle: "
                              "{}, Audio Channel Allocation: {}, Sink Number Of "
                              "{}, Audio Channel Allocation: {}, Sink Number Of "
                              "Devices: {}, Sink Number Of Channels: {}",
                              "Devices: {}, Sink Number Of Channels: {}",
                              ase.cis_conn_hdl, *core_config.audio_channel_allocation,
                              ase.cis_conn_hdl, *core_config.audio_channel_allocation,
@@ -1195,22 +1211,14 @@ protected:
                    }
                    }
                  }
                  }
                }
                }
              }
              // Inject the state
              group->SetTargetState(types::AseState::BTA_LE_AUDIO_ASE_STATE_STREAMING);
              if (block_qos_config) {
                return true;
              }
                group->SetState(types::AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED);
                group->SetState(types::AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED);
              streaming_groups[group->group_id_] = group;
                /* Assume CIG is created */
                /* Assume CIG is created */
                group->cig.SetState(bluetooth::le_audio::types::CigState::CREATED);
                group->cig.SetState(bluetooth::le_audio::types::CigState::CREATED);
              }
              if (block_streaming_state_callback) {
              streaming_groups[group->group_id_] = group;
              if (stay_at_qos_config_in_start_stream) {
                return true;
                return true;
              }
              }
@@ -1231,7 +1239,6 @@ protected:
           device = group->GetNextDevice(device)) {
           device = group->GetNextDevice(device)) {
        for (auto& ase : device->ases_) {
        for (auto& ase : device->ases_) {
          ase.cis_state = types::CisState::CONNECTED;
          ase.cis_state = types::CisState::CONNECTED;
          ase.active = false;
          ase.state = types::AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED;
          ase.state = types::AseState::BTA_LE_AUDIO_ASE_STATE_QOS_CONFIGURED;
        }
        }
      }
      }
@@ -1444,8 +1451,7 @@ protected:
    SetUpMockGatt();
    SetUpMockGatt();
    SetUpMockCodecManager(codec_location);
    SetUpMockCodecManager(codec_location);
    block_streaming_state_callback = false;
    stay_at_qos_config_in_start_stream = false;
    block_qos_config = false;
    available_snk_context_types_ = 0xffff;
    available_snk_context_types_ = 0xffff;
    available_src_context_types_ = 0xffff;
    available_src_context_types_ = 0xffff;
@@ -1668,8 +1674,8 @@ protected:
  void SyncOnMainLoop() {
  void SyncOnMainLoop() {
    // Wait for the main loop to flush
    // Wait for the main loop to flush
    // WARNING: Not tested with Timers pushing periodic tasks to the main loop
    // WARNING: Not tested with Timers pushing periodic tasks to the main loop
    while (num_async_tasks > 0)
    while (num_async_tasks > 0) {
      ;
    }
  }
  }
  void ConnectLeAudio(const RawAddress& address, bool isEncrypted = true,
  void ConnectLeAudio(const RawAddress& address, bool isEncrypted = true,
@@ -2667,8 +2673,7 @@ protected:
  uint16_t global_conn_id = 1;
  uint16_t global_conn_id = 1;
  bluetooth::le_audio::LeAudioGroupStateMachine::Callbacks* state_machine_callbacks_;
  bluetooth::le_audio::LeAudioGroupStateMachine::Callbacks* state_machine_callbacks_;
  std::map<int, LeAudioDeviceGroup*> streaming_groups;
  std::map<int, LeAudioDeviceGroup*> streaming_groups;
  bool block_streaming_state_callback = false;
  bool stay_at_qos_config_in_start_stream = false;
  bool block_qos_config = false;
  bool attach_to_stream_scheduled = false;
  bool attach_to_stream_scheduled = false;
@@ -4406,7 +4411,7 @@ TEST_F(UnicastTest, DoubleResumeFromAF) {
  types::BidirectionalPair<std::vector<uint8_t>> ccids = {.sink = {gmcs_ccid}, .source = {}};
  types::BidirectionalPair<std::vector<uint8_t>> ccids = {.sink = {gmcs_ccid}, .source = {}};
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, ccids)).Times(1);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, ccids)).Times(1);
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  LocalAudioSourceResume(false);
  LocalAudioSourceResume(false);
@@ -4464,7 +4469,7 @@ TEST_F(UnicastTest, DoubleResumeFromAFOnLocalSink) {
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSinkMetadata(AUDIO_SOURCE_MIC);
  UpdateLocalSinkMetadata(AUDIO_SOURCE_MIC);
  LocalAudioSinkResume();
  LocalAudioSinkResume();
@@ -4832,7 +4837,7 @@ TEST_F(UnicastTest, GroupSetActive_and_InactiveDuringStreamConfiguration) {
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  block_qos_config = true;
  stay_at_qos_config_in_start_stream = true;
  LeAudioClient::Get()->GroupSetActive(group_id);
  LeAudioClient::Get()->GroupSetActive(group_id);
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id, AUDIO_SOURCE_INVALID, false,
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id, AUDIO_SOURCE_INVALID, false,
@@ -5840,40 +5845,43 @@ TEST_F(UnicastTest, EarbudsTwsStyleStreaming) {
              OnGroupNodeStatus(test_address0, _, GroupNodeStatus::ADDED))
              OnGroupNodeStatus(test_address0, _, GroupNodeStatus::ADDED))
          .WillOnce(DoAll(SaveArg<1>(&group_id)));
          .WillOnce(DoAll(SaveArg<1>(&group_id)));
  log::info("Connect device");
  ConnectLeAudio(test_address0);
  ConnectLeAudio(test_address0);
  ASSERT_NE(group_id, bluetooth::groups::kGroupUnknown);
  ASSERT_NE(group_id, bluetooth::groups::kGroupUnknown);
  // Start streaming
  // Expected CIS count on streaming
  uint8_t cis_count_out = 2;
  uint8_t cis_count_out = 2;
  uint8_t cis_count_in = 0;
  uint8_t cis_count_in = 0;
  log::info("Group is getting Active");
  // Audio sessions are started only when device gets active
  // Audio sessions are started only when device gets active
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_sink_hal_client_, Start(_, _, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_sink_hal_client_, Start(_, _, _)).Times(1);
  LeAudioClient::Get()->GroupSetActive(group_id);
  LeAudioClient::Get()->GroupSetActive(group_id);
  SyncOnMainLoop();
  SyncOnMainLoop();
  log::info("Start stream");
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  SyncOnMainLoop();
  SyncOnMainLoop();
  // Verify Data transfer on one audio source cis
  log::info("Verify Data transfer on one audio source cis");
  TestAudioDataTransfer(group_id, cis_count_out, cis_count_in, 1920);
  TestAudioDataTransfer(group_id, cis_count_out, cis_count_in, 1920);
  // Suspend
  log::info("Suspend");
  /*TODO Need a way to verify STOP */
  EXPECT_CALL(mock_state_machine_, SuspendStream(_)).Times(1);
  LeAudioClient::Get()->GroupSuspend(group_id);
  LeAudioClient::Get()->GroupSuspend(group_id);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  // Resume
  log::info("Resume");
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  // Stop
  log::info("Stop");
  StopStreaming(group_id);
  StopStreaming(group_id);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
@@ -8507,7 +8515,7 @@ TEST_F(UnicastTest, LateStreamConnectBasedOnContextType) {
  InjectAvailableContextTypes(test_address1, 2, types::AudioContexts(0), types::AudioContexts(0));
  InjectAvailableContextTypes(test_address1, 2, types::AudioContexts(0), types::AudioContexts(0));
  // Block streaming state
  // Block streaming state
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  LocalAudioSourceResume(false);
  LocalAudioSourceResume(false);
@@ -8590,7 +8598,7 @@ TEST_F(UnicastTest, LateStreamConnectBasedOnContextTypeNotFullyConnected) {
  device1->SetConnectionState(DeviceConnectState::CONNECTED_AUTOCONNECT_GETTING_READY);
  device1->SetConnectionState(DeviceConnectState::CONNECTED_AUTOCONNECT_GETTING_READY);
  // Resume but block the final streaming state - keep the group in transition
  // Resume but block the final streaming state - keep the group in transition
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  LocalAudioSourceResume(false);
  LocalAudioSourceResume(false);
@@ -8642,7 +8650,7 @@ TEST_F(UnicastTest, CheckDeviceIsNotAttachedToStreamWhenNotNeeded) {
  SyncOnMainLoop();
  SyncOnMainLoop();
  // Block streaming state
  // Block streaming state
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  LocalAudioSourceResume(false);
  LocalAudioSourceResume(false);
@@ -12324,7 +12332,7 @@ TEST_F(UnicastTest, CodecFrameBlocks2) {
  types::BidirectionalPair<std::vector<uint8_t>> ccids = {.sink = {gmcs_ccid}, .source = {}};
  types::BidirectionalPair<std::vector<uint8_t>> ccids = {.sink = {gmcs_ccid}, .source = {}};
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, ccids)).Times(1);
  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, ccids)).Times(1);
  block_streaming_state_callback = true;
  stay_at_qos_config_in_start_stream = true;
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC);
  LocalAudioSourceResume(false);
  LocalAudioSourceResume(false);
+2 −2
Original line number Original line Diff line number Diff line
@@ -133,8 +133,8 @@ LeAudioGroupStateMachineImpl* instance;


class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
public:
public:
  LeAudioGroupStateMachineImpl(Callbacks* state_machine_callbacks_)
  LeAudioGroupStateMachineImpl(Callbacks* state_machine_callbacks)
      : state_machine_callbacks_(state_machine_callbacks_),
      : state_machine_callbacks_(state_machine_callbacks),
        watchdog_(alarm_new("LeAudioStateMachineTimer")) {
        watchdog_(alarm_new("LeAudioStateMachineTimer")) {
    log_history_ = LeAudioLogHistory::Get();
    log_history_ = LeAudioLogHistory::Get();
  }
  }