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

Commit 24d5c024 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Reset a2dp_cmd_pending as appropriate for A2DP HW offload HAL commands

Previously, the a2dp_cmd_pending was set to the last pending command,
but was never reset to A2DP_CTRL_CMD_NONE after the command processing
was completed.

Bug: 110712574
Test: Manual: Pair with two headsets, start/suspend/stop/switch active
      device
Change-Id: I464e6e9d41a221df44eba21e538b499a9ac1dcfb
parent de5ab0a6
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -339,6 +339,9 @@ void btif_a2dp_audio_on_started(tBTA_AV_STATUS status) {
  LOG_INFO(LOG_TAG, "%s: status = %d", __func__, status);
  if (btAudio != nullptr) {
    if (a2dp_cmd_pending == A2DP_CTRL_CMD_START) {
      if (status != A2DP_CTRL_ACK_PENDING) {
        a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
      }
      LOG_INFO(LOG_TAG, "%s: calling method onStarted", __func__);
      auto hal_status = mapToStatus(status);
      btAudio->streamStarted(hal_status);
@@ -353,6 +356,9 @@ void btif_a2dp_audio_on_suspended(tBTA_AV_STATUS status) {
  LOG_INFO(LOG_TAG, "%s: status = %d", __func__, status);
  if (btAudio != nullptr) {
    if (a2dp_cmd_pending == A2DP_CTRL_CMD_SUSPEND) {
      if (status != A2DP_CTRL_ACK_PENDING) {
        a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
      }
      LOG_INFO(LOG_TAG, "calling method onSuspended");
      auto hal_status = mapToStatus(status);
      btAudio->streamSuspended(hal_status);
@@ -366,6 +372,7 @@ void btif_a2dp_audio_on_suspended(tBTA_AV_STATUS status) {
void btif_a2dp_audio_on_stopped(tBTA_AV_STATUS status) {
  LOG_INFO(LOG_TAG, "%s: status = %d", __func__, status);
  if (btAudio != nullptr && a2dp_cmd_pending == A2DP_CTRL_CMD_START) {
    a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
    LOG_INFO(LOG_TAG, "%s: Remote disconnected when start under progress",
             __func__);
    btAudio->streamStarted(mapToStatus(A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS));
@@ -418,7 +425,6 @@ void btif_a2dp_audio_send_stop_req() {
uint8_t btif_a2dp_audio_process_request(uint8_t cmd) {
  LOG_INFO(LOG_TAG, "%s: cmd: %s", __func__,
           audio_a2dp_hw_dump_ctrl_event((tA2DP_CTRL_CMD)cmd));
  a2dp_cmd_pending = cmd;
  uint8_t status;
  switch (cmd) {
    case A2DP_CTRL_CMD_START:
@@ -461,7 +467,7 @@ uint8_t btif_a2dp_audio_process_request(uint8_t cmd) {
      APPL_TRACE_WARNING("%s: A2DP command %s while AV stream is not ready",
                         __func__,
                         audio_a2dp_hw_dump_ctrl_event((tA2DP_CTRL_CMD)cmd));
      return A2DP_CTRL_ACK_FAILURE;
      status = A2DP_CTRL_ACK_FAILURE;
      break;

    case A2DP_CTRL_CMD_STOP:
@@ -472,7 +478,7 @@ uint8_t btif_a2dp_audio_process_request(uint8_t cmd) {
        break;
      }
      btif_av_stream_stop(RawAddress::kEmpty);
      return A2DP_CTRL_ACK_SUCCESS;
      status = A2DP_CTRL_ACK_SUCCESS;
      break;

    case A2DP_CTRL_CMD_SUSPEND:
@@ -502,5 +508,10 @@ uint8_t btif_a2dp_audio_process_request(uint8_t cmd) {
  }
  LOG_INFO(LOG_TAG, "a2dp-ctrl-cmd : %s DONE returning status %d",
           audio_a2dp_hw_dump_ctrl_event((tA2DP_CTRL_CMD)cmd), status);
  if (status == A2DP_CTRL_ACK_PENDING) {
    a2dp_cmd_pending = cmd;
  } else {
    a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
  }
  return status;
}