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

Commit f614cd39 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

Floss: |ack_stream_suspended| in all cases after setting command

In aosp/2191602 we tried to mitigate the issue where the audio stack
could send |StopRequest| without knowing that the peripheral is already
disconnected and block further commands, by ignoring |StopRequest| when
the audio state is not |Started|.

However, it turned out insufficient as the audio state callback does not
update reliably in between the timings of stream stopped and
|StopRequest| coming from the audio stack.

In this CL, we ensure that whenever the command is blocked, there will
be a subsequent |ack_stream_suspended| even if the state transitioned to
off (due to subtle timings of the worker thread), so that the pending
command is guaranteed to be cleared.

Bug: 255908888
Tag: #floss
Test: Build and verify
Change-Id: Iad634ec0725a8a012c07a78675b36f4ebb8cc530
parent b0f9bc19
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -710,8 +710,6 @@ void btif_a2dp_source_on_idle(void) {
void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
  LOG_INFO("%s: state=%s", __func__, btif_a2dp_source_cb.StateStr().c_str());

  if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return;

  // allow using this API for other (acknowledgement and stopping media task)
  // than suspend
  if (p_av_suspend != nullptr && p_av_suspend->status != BTA_AV_SUCCESS) {
@@ -725,11 +723,13 @@ void btif_a2dp_source_on_stopped(tBTA_AV_SUSPEND* p_av_suspend) {
        btif_a2dp_command_ack(A2DP_CTRL_ACK_FAILURE);
      }
    }
  } else if (btif_av_is_a2dp_offload_running()) {
  } else {
    bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS);
    return;
  }

  if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateOff) return;

  // ensure tx frames are immediately suspended
  btif_a2dp_source_cb.tx_flush = true;
  // ensure tx frames are immediately flushed