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

Commit 25b2f1e8 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Android Build Coastguard Worker
Browse files

leaudio: Do not update local metadata if not needed

local_metadata_context_types_ should be updated only on MetadataUpdate
event. This will fix the problem, when offloader is changing source
metadata to converational and then back to media.
Without this patch, when context is changed to media, on the sink path
we still would keep conversational, which might afect future
configuration

Bug: 367894783
Bug: 352686917
Test: atest bluetooth_le_audio_client_test
Flag: com.android.bluetooth.flags.leaudio_speed_up_reconfiguration_between_call
(cherry picked from https://android-review.googlesource.com/q/commit:5ffa202285a79e40b157b24b9bfc8fa534182fd0)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:67ff4724f719ce61ab41729473d8fcb95a686f14)
Merged-In: I4a560ce73e49116df4f0179fd71592443ab50558
Change-Id: I4a560ce73e49116df4f0179fd71592443ab50558
parent 8da956fb
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -4703,8 +4703,6 @@ public:

    local_metadata_context_types_.sink =
            ChooseMetadataContextType(local_metadata_context_types_.sink);
    local_metadata_context_types_.source =
            ChooseMetadataContextType(local_metadata_context_types_.source);

    /* Reconfigure or update only if the stream is already started
     * otherwise wait for the local sink to resume.
@@ -4751,20 +4749,25 @@ public:
      SetInVoipCall(false);
    }

    BidirectionalPair<AudioContexts> remote_metadata = {
            .sink = local_metadata_context_types_.source,
            .source = local_metadata_context_types_.sink};

    /* Make sure we have CONVERSATIONAL when in a call and it is not mixed
     * with any other bidirectional context
     */
    if (IsInCall() || IsInVoipCall()) {
      log::debug("In Call preference used: {}, voip call: {}", IsInCall(), IsInVoipCall());
      local_metadata_context_types_.sink.unset_all(kLeAudioContextAllBidir);
      local_metadata_context_types_.source.unset_all(kLeAudioContextAllBidir);
      local_metadata_context_types_.sink.set(LeAudioContextType::CONVERSATIONAL);
      local_metadata_context_types_.source.set(LeAudioContextType::CONVERSATIONAL);
      remote_metadata.sink.unset_all(kLeAudioContextAllBidir);
      remote_metadata.source.unset_all(kLeAudioContextAllBidir);
      remote_metadata.sink.set(LeAudioContextType::CONVERSATIONAL);
      remote_metadata.source.set(LeAudioContextType::CONVERSATIONAL);
    }

    BidirectionalPair<AudioContexts> remote_metadata = {
            .sink = local_metadata_context_types_.source,
            .source = local_metadata_context_types_.sink};
    if (!com::android::bluetooth::flags::leaudio_speed_up_reconfiguration_between_call()) {
      local_metadata_context_types_.sink = remote_metadata.source;
      local_metadata_context_types_.source = remote_metadata.sink;
    }

    if (IsInVoipCall()) {
      log::debug("Unsetting RINGTONE from remote sink");
+20 −14
Original line number Diff line number Diff line
@@ -1004,9 +1004,13 @@ protected:
                                          metadata_context_types,
                                  types::BidirectionalPair<std::vector<uint8_t>> ccid_lists) {
              auto group_state = group->GetState();
              log::info("group {} state {}, context type {}", group->group_id_,
                        bluetooth::common::ToString(group_state),
                        bluetooth::common::ToString(context_type));
              log::info(
                      "StartStream: group {} state {}, context type {} sink metadata_ctx {}, "
                      "source metadata_ctx {}",
                      group->group_id_, bluetooth::common::ToString(group_state),
                      bluetooth::common::ToString(context_type),
                      bluetooth::common::ToString(metadata_context_types.sink),
                      bluetooth::common::ToString(metadata_context_types.source));
              /* Do nothing if already streaming - the implementation would
               * probably update the metadata.
@@ -10304,7 +10308,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  available_snk_context_types_ =
          (types::LeAudioContextType::CONVERSATIONAL | types::LeAudioContextType::RINGTONE |
           types::LeAudioContextType::GAME | types::LeAudioContextType::MEDIA |
           types::LeAudioContextType::LIVE)
           types::LeAudioContextType::LIVE | types::LeAudioContextType::NOTIFICATIONS)
                  .value();
  supported_snk_context_types_ =
          available_snk_context_types_ |
@@ -10335,7 +10339,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  LeAudioClient::Get()->GroupSetActive(group_id);
  SyncOnMainLoop();
  // 1) Start with the call first
  log::info("TESTPOINT 1: Start with the call first");
  // -----------------------------
  // CONVERSATIONAL is from In Call preference, and RINGTONE is from metadata
  LeAudioClient::Get()->SetInCall(true);
@@ -10361,7 +10365,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  uint8_t cis_count_in = 1;
  TestAudioDataTransfer(group_id, cis_count_out, cis_count_in, 1920, 40);
  // 2) Start MEDIA during the call, expect MEDIA only on the remote sink
  log::info("TESTPOINT 2: Start MEDIA during the call, expect MEDIA only on the remote sink");
  contexts = {.sink = types::AudioContexts(types::LeAudioContextType::CONVERSATIONAL |
                                           types::LeAudioContextType::MEDIA),
              .source = types::AudioContexts(types::LeAudioContextType::CONVERSATIONAL)};
@@ -10376,25 +10380,27 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_sink_hal_client_);
  // 2) Disable In Call preference but do not suspend the local sink
  // We should stay in CONVERSATIONAL until the local sink suspends
  log::info(
          "TESTPOINT 3: Disable In Call preference but do not suspend the local sink. Play "
          "notification on the same stream.");
  // Verify both context are sent as the metadata.
  // ---------------------------------------
  LeAudioClient::Get()->SetInCall(false);
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(0);
  contexts = {.sink = types::AudioContexts(types::LeAudioContextType::MEDIA |
  contexts = {.sink = types::AudioContexts(types::LeAudioContextType::NOTIFICATIONS |
                                           types::LeAudioContextType::CONVERSATIONAL),
              .source = types::AudioContexts(types::LeAudioContextType::CONVERSATIONAL)};
  EXPECT_CALL(mock_state_machine_,
              StartStream(_, types::LeAudioContextType::CONVERSATIONAL, contexts, _))
          .Times(1);
  UpdateLocalSourceMetadata(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC,
  UpdateLocalSourceMetadata(AUDIO_USAGE_NOTIFICATION, AUDIO_CONTENT_TYPE_UNKNOWN,
                            /*reconfigure=*/false);
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_sink_hal_client_);
  // 3) Disable call so we could go back to MEDIA
  log::info("TESTPOING 4: Disable call so we could go back to MEDIA");
  // ---------------------------------------
  // Suspend should stop the stream
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(1);
@@ -10421,7 +10427,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes) {
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_sink_hal_client_);
  // 4) Stop streaming
  log::info("TESTPOINT 5: Stop streaming");
  // ------------------
  StopStreaming(group_id);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
@@ -10445,7 +10451,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes_SpeedUpReconfigFlagEnabled) {
  available_snk_context_types_ =
          (types::LeAudioContextType::CONVERSATIONAL | types::LeAudioContextType::RINGTONE |
           types::LeAudioContextType::GAME | types::LeAudioContextType::MEDIA |
           types::LeAudioContextType::LIVE)
           types::LeAudioContextType::LIVE | types::LeAudioContextType::NOTIFICATIONS)
                  .value();
  supported_snk_context_types_ =
          available_snk_context_types_ |
@@ -10531,7 +10537,7 @@ TEST_F(UnicastTest, MusicDuringCallContextTypes_SpeedUpReconfigFlagEnabled) {
  Mock::VerifyAndClearExpectations(mock_le_audio_source_hal_client_);
  Mock::VerifyAndClearExpectations(mock_le_audio_sink_hal_client_);
  log::info("Step 2) Disable call so we could go back to MEDIA");
  log::info("Step 3) Disable call so we could go back to MEDIA");
  // ---------------------------------------
  // Suspend should stop the stream
  EXPECT_CALL(mock_state_machine_, StopStream(_)).Times(1);