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

Commit 55c0719c authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudio: Change the initial configuration

Let's start with the UNSPECIFIED configuration, which is technically
the same as MEDIA, but allows otherwise not reconfiguring scenarios
to actually properly reconfigure for that use case, instead of assumming
some scenario without the knowledge of the actual past scenarios.

Additionally this will allow to properly unit-test the scearios which
would not reconfigure from MEDIA due to our reconfiguration-minimizing
policy. Once the initial configuration is applied, this policy will
be applied as usual.

Bug: 285647765
Test: atest bluetooth_le_audio_test bluetooth_le_audio_client_test
Change-Id: Iaccaa3b70233a518071c7a82e22b26e827d17f27
parent d68705ce
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -1228,8 +1228,9 @@ class LeAudioClientImpl : public LeAudioClient {
     */
     */
    LeAudioContextType default_context_type = configuration_context_type_;
    LeAudioContextType default_context_type = configuration_context_type_;
    if (!group->IsAudioSetConfigurationAvailable(default_context_type)) {
    if (!group->IsAudioSetConfigurationAvailable(default_context_type)) {
      if (group->IsAudioSetConfigurationAvailable(LeAudioContextType::MEDIA)) {
      if (group->IsAudioSetConfigurationAvailable(
        default_context_type = LeAudioContextType::MEDIA;
              LeAudioContextType::UNSPECIFIED)) {
        default_context_type = LeAudioContextType::UNSPECIFIED;
      } else {
      } else {
        for (LeAudioContextType context_type : kLeAudioContextAllTypesArray) {
        for (LeAudioContextType context_type : kLeAudioContextAllTypesArray) {
          if (group->IsAudioSetConfigurationAvailable(context_type)) {
          if (group->IsAudioSetConfigurationAvailable(context_type)) {
+20 −19
Original line number Original line Diff line number Diff line
@@ -75,6 +75,9 @@ using le_audio::LeAudioSourceAudioHalClient;
extern struct fake_osi_alarm_set_on_mloop fake_osi_alarm_set_on_mloop_;
extern struct fake_osi_alarm_set_on_mloop fake_osi_alarm_set_on_mloop_;


constexpr int max_num_of_ases = 5;
constexpr int max_num_of_ases = 5;
constexpr le_audio::types::LeAudioContextType
    kLeAudioDefaultConfigurationContext =
        le_audio::types::LeAudioContextType::UNSPECIFIED;


static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
static constexpr char kNotifyUpperLayerAboutGroupBeingInIdleDuringCall[] =
    "persist.bluetooth.leaudio.notify.idle.during.call";
    "persist.bluetooth.leaudio.notify.idle.during.call";
@@ -4390,12 +4393,12 @@ TEST_F(UnicastTest, SpeakerStreamingNonDefault) {
  /* When session is closed, the hal client mocks are freed - get new ones */
  /* When session is closed, the hal client mocks are freed - get new ones */
  SetUpMockAudioHal();
  SetUpMockAudioHal();
  /* Expect the previous release to clear the old audio session metadata */
  /* Expect the previous release to clear the old audio session metadata */
  auto default_impl_context = types::LeAudioContextType::MEDIA;
  LeAudioClient::Get()->GroupSetActive(group_id);
  LeAudioClient::Get()->GroupSetActive(group_id);
  EXPECT_CALL(mock_state_machine_,
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, types::LeAudioContextType::VOICEASSISTANTS, _, _))
              StartStream(_, types::LeAudioContextType::VOICEASSISTANTS, _, _))
      .Times(0);
      .Times(0);
  EXPECT_CALL(mock_state_machine_, StartStream(_, default_impl_context, _, _))
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, _, _))
      .Times(1);
      .Times(1);
  LocalAudioSourceResume();
  LocalAudioSourceResume();
}
}
@@ -4567,7 +4570,7 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
      .sink = types::AudioContexts(types::LeAudioContextType::NOTIFICATIONS),
      .sink = types::AudioContexts(types::LeAudioContextType::NOTIFICATIONS),
      .source = types::AudioContexts()};
      .source = types::AudioContexts()};
  EXPECT_CALL(mock_state_machine_,
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, types::LeAudioContextType::MEDIA, contexts, _))
              StartStream(_, kLeAudioDefaultConfigurationContext, contexts, _))
      .Times(1);
      .Times(1);


  StartStreaming(AUDIO_USAGE_NOTIFICATION, AUDIO_CONTENT_TYPE_UNKNOWN,
  StartStreaming(AUDIO_USAGE_NOTIFICATION, AUDIO_CONTENT_TYPE_UNKNOWN,
@@ -4578,15 +4581,14 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
  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_);


  // Do a metadata content switch to ALERTS but stay on MEDIA configuration
  // Do a metadata content switch to ALERTS but stay on previous configuration
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start).Times(0);
  contexts = {.sink = types::AudioContexts(types::LeAudioContextType::ALERTS),
  contexts = {.sink = types::AudioContexts(types::LeAudioContextType::ALERTS),
              .source = types::AudioContexts()};
              .source = types::AudioContexts()};
  EXPECT_CALL(
  EXPECT_CALL(mock_state_machine_,
      mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, contexts, _))
      StartStream(_, le_audio::types::LeAudioContextType::MEDIA, contexts, _))
      .Times(1);
      .Times(1);
  UpdateLocalSourceMetadata(AUDIO_USAGE_ALARM, AUDIO_CONTENT_TYPE_UNKNOWN);
  UpdateLocalSourceMetadata(AUDIO_USAGE_ALARM, AUDIO_CONTENT_TYPE_UNKNOWN);


@@ -4595,7 +4597,8 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
  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_);


  // Do a metadata content switch to EMERGENCY but stay on MEDIA configuration
  // Do a metadata content switch to EMERGENCY but stay on previous
  // configuration
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start).Times(0);
@@ -4603,9 +4606,8 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
  contexts = {
  contexts = {
      .sink = types::AudioContexts(types::LeAudioContextType::EMERGENCYALARM),
      .sink = types::AudioContexts(types::LeAudioContextType::EMERGENCYALARM),
      .source = types::AudioContexts()};
      .source = types::AudioContexts()};
  EXPECT_CALL(
  EXPECT_CALL(mock_state_machine_,
      mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, contexts, _))
      StartStream(_, le_audio::types::LeAudioContextType::MEDIA, contexts, _))
      .Times(1);
      .Times(1);
  UpdateLocalSourceMetadata(AUDIO_USAGE_EMERGENCY, AUDIO_CONTENT_TYPE_UNKNOWN);
  UpdateLocalSourceMetadata(AUDIO_USAGE_EMERGENCY, AUDIO_CONTENT_TYPE_UNKNOWN);


@@ -4613,7 +4615,7 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
  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_);


  // Do a metadata content switch to INSTRUCTIONAL but stay on MEDIA
  // Do a metadata content switch to INSTRUCTIONAL but stay on previous
  // configuration
  // configuration
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, OnDestroyed()).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Stop).Times(0);
@@ -4621,9 +4623,8 @@ TEST_F(UnicastTest, TwoEarbudsStreamingContextSwitchNoReconfigure) {
  contexts = {
  contexts = {
      .sink = types::AudioContexts(types::LeAudioContextType::INSTRUCTIONAL),
      .sink = types::AudioContexts(types::LeAudioContextType::INSTRUCTIONAL),
      .source = types::AudioContexts()};
      .source = types::AudioContexts()};
  EXPECT_CALL(
  EXPECT_CALL(mock_state_machine_,
      mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, contexts, _))
      StartStream(_, le_audio::types::LeAudioContextType::MEDIA, contexts, _))
      .Times(1);
      .Times(1);
  UpdateLocalSourceMetadata(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
  UpdateLocalSourceMetadata(AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
                            AUDIO_CONTENT_TYPE_UNKNOWN);
                            AUDIO_CONTENT_TYPE_UNKNOWN);
@@ -5566,12 +5567,12 @@ TEST_F(UnicastTest, StartNotAvailableContextType) {
  // Expect configuring to the default config since the EMERGENCYALARM is
  // Expect configuring to the default config since the EMERGENCYALARM is
  // not on the list of supported contexts and UNSPECIFIED will be used in
  // not on the list of supported contexts and UNSPECIFIED will be used in
  // the metadata.
  // the metadata.
  auto default_config = types::LeAudioContextType::MEDIA;
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _)).Times(1);
  types::BidirectionalPair<types::AudioContexts> metadata = {
  types::BidirectionalPair<types::AudioContexts> metadata = {
      .sink = types::AudioContexts(types::LeAudioContextType::UNSPECIFIED),
      .sink = types::AudioContexts(types::LeAudioContextType::UNSPECIFIED),
      .source = types::AudioContexts()};
      .source = types::AudioContexts()};
  EXPECT_CALL(mock_state_machine_, StartStream(_, default_config, metadata, _))
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, metadata, _))
      .Times(1);
      .Times(1);


  LeAudioClient::Get()->GroupSetActive(group_id);
  LeAudioClient::Get()->GroupSetActive(group_id);
@@ -5624,12 +5625,12 @@ TEST_F(UnicastTest, StartNotAvailableUnsupportedContextTypeUnspecifiedAvail) {
  // Expect configuring to the default config since the EMERGENCYALARM is
  // Expect configuring to the default config since the EMERGENCYALARM is
  // not on the list of supported contexts and UNSPECIFIED will be used in
  // not on the list of supported contexts and UNSPECIFIED will be used in
  // the metadata.
  // the metadata.
  auto default_config = types::LeAudioContextType::MEDIA;
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _)).Times(1);
  EXPECT_CALL(*mock_le_audio_source_hal_client_, Start(_, _)).Times(1);
  types::BidirectionalPair<types::AudioContexts> metadata = {
  types::BidirectionalPair<types::AudioContexts> metadata = {
      .sink = types::AudioContexts(types::LeAudioContextType::UNSPECIFIED),
      .sink = types::AudioContexts(types::LeAudioContextType::UNSPECIFIED),
      .source = types::AudioContexts()};
      .source = types::AudioContexts()};
  EXPECT_CALL(mock_state_machine_, StartStream(_, default_config, metadata, _))
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, kLeAudioDefaultConfigurationContext, metadata, _))
      .Times(1);
      .Times(1);


  LeAudioClient::Get()->GroupSetActive(group_id);
  LeAudioClient::Get()->GroupSetActive(group_id);