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

Commit b3941fa5 authored by shihchienc's avatar shihchienc Committed by Patrick Chang
Browse files

leaudio: set preferred codec config with context switch test part 3

scenario: idle -> media -> conv(*) -> media

Adding unit test for api:SetCodecConfigPreference for all use cases
during `*`

Bug: 259191520
Bug: 353909820
Flag: TEST_ONLY
Test: atest bluetooth_le_audio_test bluetooth_le_audio_client_test
Change-Id: Ic4ffb1a9d8d97366e24e9d969e3fec9505504ea6
parent e72aad3c
Loading
Loading
Loading
Loading
+196 −0
Original line number Diff line number Diff line
@@ -7245,6 +7245,202 @@ TEST_F(UnicastTest, TwoEarbudsSetPreferenceWhenMediaNotForBothMediaAndConv) {
            false);
}
TEST_F(UnicastTest, TwoEarbudsSetPreferenceWhenConvForBothMediaAndConv) {
  com::android::bluetooth::flags::provider_->leaudio_set_codec_config_preference(true);
  int group_id = 2;
  TestSetupRemoteDevices(group_id);
  bool set_before_media = false;
  bool set_while_media = false;
  bool is_using_set_before_media_codec_during_media = false;
  bool is_using_set_while_media_codec_during_media = false;
  bool is_reconfig = false;
  TestSetCodecPreference(nullptr, nullptr, LeAudioContextType::MEDIA, group_id, set_before_media,
                         set_while_media, is_using_set_before_media_codec_during_media,
                         is_using_set_while_media_codec_during_media, is_reconfig);
  // simulate suspend timeout passed, alarm executing
  fake_osi_alarm_set_on_mloop_.cb(fake_osi_alarm_set_on_mloop_.data);
  SyncOnMainLoop();
  // This codec can be used by media and conv
  btle_audio_codec_config_t preferred_codec_config_during_conv = {
          .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
          .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_16000HZ,
          .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
          .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_1,
          .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
          .octets_per_frame = 40};
  // SetInCall is used by GTBS - and only then we can expect CCID to be set.
  LeAudioClient::Get()->SetInCall(true);
  bool set_before_conv = false;
  bool set_while_conv = true;
  bool is_using_set_before_conv_codec_during_conv = false;
  bool is_using_set_while_conv_codec_during_conv = true;
  // should use preferred codec and reconfig
  is_reconfig = true;
  TestSetCodecPreference(nullptr, &preferred_codec_config_during_conv,
                         LeAudioContextType::CONVERSATIONAL, group_id, set_before_conv,
                         set_while_conv, is_using_set_before_conv_codec_during_conv,
                         is_using_set_while_conv_codec_during_conv, is_reconfig);
  LeAudioClient::Get()->SetInCall(false);
  // should use preferred codec when switching back to media
  ASSERT_EQ(LeAudioClient::Get()->IsUsingPreferredCodecConfig(
                    group_id, static_cast<int>(types::LeAudioContextType::MEDIA)),
            true);
}
TEST_F(UnicastTest, TwoEarbudsSetPreferenceWhenConvForMediaNotForConv) {
  com::android::bluetooth::flags::provider_->leaudio_set_codec_config_preference(true);
  int group_id = 2;
  TestSetupRemoteDevices(group_id);
  bool set_before_media = false;
  bool set_while_media = false;
  bool is_using_set_before_media_codec_during_media = false;
  bool is_using_set_while_media_codec_during_media = false;
  bool is_reconfig = false;
  TestSetCodecPreference(nullptr, nullptr, LeAudioContextType::MEDIA, group_id, set_before_media,
                         set_while_media, is_using_set_before_media_codec_during_media,
                         is_using_set_while_media_codec_during_media, is_reconfig);
  // simulate suspend timeout passed, alarm executing
  fake_osi_alarm_set_on_mloop_.cb(fake_osi_alarm_set_on_mloop_.data);
  SyncOnMainLoop();
  // This codec can be used by media but not by conv
  btle_audio_codec_config_t preferred_codec_config_during_conv = {
          .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
          .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_24000HZ,
          .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
          .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_1,
          .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
          .octets_per_frame = 60};
  // SetInCall is used by GTBS - and only then we can expect CCID to be set.
  LeAudioClient::Get()->SetInCall(true);
  bool set_before_conv = false;
  bool set_while_conv = true;
  bool is_using_set_before_conv_codec_during_conv = false;
  bool is_using_set_while_conv_codec_during_conv = false;
  // should use legacy codec
  is_reconfig = false;
  TestSetCodecPreference(nullptr, &preferred_codec_config_during_conv,
                         LeAudioContextType::CONVERSATIONAL, group_id, set_before_conv,
                         set_while_conv, is_using_set_before_conv_codec_during_conv,
                         is_using_set_while_conv_codec_during_conv, is_reconfig);
  LeAudioClient::Get()->SetInCall(false);
  // should use preferred codec when switching back to media
  ASSERT_EQ(LeAudioClient::Get()->IsUsingPreferredCodecConfig(
                    group_id, static_cast<int>(types::LeAudioContextType::MEDIA)),
            true);
}
TEST_F(UnicastTest, TwoEarbudsSetPreferenceWhenConvNotForMediaForConv) {
  com::android::bluetooth::flags::provider_->leaudio_set_codec_config_preference(true);
  int group_id = 2;
  TestSetupRemoteDevices(group_id);
  bool set_before_media = false;
  bool set_while_media = false;
  bool is_using_set_before_media_codec_during_media = false;
  bool is_using_set_while_media_codec_during_media = false;
  bool is_reconfig = false;
  TestSetCodecPreference(nullptr, nullptr, LeAudioContextType::MEDIA, group_id, set_before_media,
                         set_while_media, is_using_set_before_media_codec_during_media,
                         is_using_set_while_media_codec_during_media, is_reconfig);
  // simulate suspend timeout passed, alarm executing
  fake_osi_alarm_set_on_mloop_.cb(fake_osi_alarm_set_on_mloop_.data);
  SyncOnMainLoop();
  // This codec can not be used by media but by conv
  btle_audio_codec_config_t preferred_codec_config_during_conv = {
          .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
          .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_32000HZ,
          .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
          .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_1,
          .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
          .octets_per_frame = 80};
  // SetInCall is used by GTBS - and only then we can expect CCID to be set.
  LeAudioClient::Get()->SetInCall(true);
  bool set_before_conv = false;
  bool set_while_conv = true;
  bool is_using_set_before_conv_codec_during_conv = false;
  bool is_using_set_while_conv_codec_during_conv = true;
  // should use preferred codec but not reconfig
  is_reconfig = false;
  TestSetCodecPreference(nullptr, &preferred_codec_config_during_conv,
                         LeAudioContextType::CONVERSATIONAL, group_id, set_before_conv,
                         set_while_conv, is_using_set_before_conv_codec_during_conv,
                         is_using_set_while_conv_codec_during_conv, is_reconfig);
  LeAudioClient::Get()->SetInCall(false);
  // should use legacy codec when switching back to media
  ASSERT_EQ(LeAudioClient::Get()->IsUsingPreferredCodecConfig(
                    group_id, static_cast<int>(types::LeAudioContextType::MEDIA)),
            false);
}
TEST_F(UnicastTest, TwoEarbudsSetPreferenceWhenConvNotForBothMediaAndConv) {
  com::android::bluetooth::flags::provider_->leaudio_set_codec_config_preference(true);
  int group_id = 2;
  TestSetupRemoteDevices(group_id);
  bool set_before_media = false;
  bool set_while_media = false;
  bool is_using_set_before_media_codec_during_media = false;
  bool is_using_set_while_media_codec_during_media = false;
  bool is_reconfig = false;
  TestSetCodecPreference(nullptr, nullptr, LeAudioContextType::MEDIA, group_id, set_before_media,
                         set_while_media, is_using_set_before_media_codec_during_media,
                         is_using_set_while_media_codec_during_media, is_reconfig);
  // simulate suspend timeout passed, alarm executing
  fake_osi_alarm_set_on_mloop_.cb(fake_osi_alarm_set_on_mloop_.data);
  SyncOnMainLoop();
  // This codec can not be used by media and conv
  btle_audio_codec_config_t preferred_codec_config_during_conv = {
          .codec_type = LE_AUDIO_CODEC_INDEX_SOURCE_LC3,
          .sample_rate = LE_AUDIO_SAMPLE_RATE_INDEX_24000HZ,
          .bits_per_sample = LE_AUDIO_BITS_PER_SAMPLE_INDEX_16,
          .channel_count = LE_AUDIO_CHANNEL_COUNT_INDEX_1,
          .frame_duration = LE_AUDIO_FRAME_DURATION_INDEX_10000US,
          .octets_per_frame = 70};
  // SetInCall is used by GTBS - and only then we can expect CCID to be set.
  LeAudioClient::Get()->SetInCall(true);
  bool set_before_conv = false;
  bool set_while_conv = true;
  bool is_using_set_before_conv_codec_during_conv = false;
  bool is_using_set_while_conv_codec_during_conv = false;
  // should use legacy codec
  is_reconfig = false;
  TestSetCodecPreference(nullptr, &preferred_codec_config_during_conv,
                         LeAudioContextType::CONVERSATIONAL, group_id, set_before_conv,
                         set_while_conv, is_using_set_before_conv_codec_during_conv,
                         is_using_set_while_conv_codec_during_conv, is_reconfig);
  LeAudioClient::Get()->SetInCall(false);
  // should use legacy codec when switching back to media
  ASSERT_EQ(LeAudioClient::Get()->IsUsingPreferredCodecConfig(
                    group_id, static_cast<int>(types::LeAudioContextType::MEDIA)),
            false);
}
TEST_F(UnicastTest, StreamingVxAospSampleSound) {
  uint8_t group_size = 2;
  int group_id = 2;