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

Commit 7c5c2fc9 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

reset hfp_pending_cmd_ to handle retry logic

1. when a new session start, reset
2. when startStream failed, reset hfp_pending_cmd_ to allow retry
3. after suspendStream, reset hfp_pending_cmd_ to avoid stuck in pending suspend when SCO already disconnected

Bug: 367479598
Bug: 315234036
Flag: com::android::bluetooth::flags::is_sco_managed_by_audio and HFP session type only enabled when flag is enabled
Test: atest HeadsetStateMachineTest
Change-Id: I21f7091cf8965aed19c02da61e6c91bbd9f85172
parent a007dcd3
Loading
Loading
Loading
Loading
+37 −4
Original line number Diff line number Diff line
@@ -45,6 +45,31 @@ std::map<bt_status_t, BluetoothAudioCtrlAck> status_to_ack_map = {
        {BT_STATUS_UNSUPPORTED, BluetoothAudioCtrlAck::FAILURE_UNSUPPORTED},
};

std::string command_to_text(tHFP_CTRL_CMD cmd) {
  switch (cmd) {
    case HFP_CTRL_CMD_NONE:
      return "none";
    case HFP_CTRL_CMD_CHECK_READY:
      return "check ready";
    case HFP_CTRL_CMD_START:
      return "start";
    case HFP_CTRL_CMD_STOP:
      return "stop";
    case HFP_CTRL_CMD_SUSPEND:
      return "suspend";
    case HFP_CTRL_GET_INPUT_AUDIO_CONFIG:
      return "get input audio config";
    case HFP_CTRL_GET_OUTPUT_AUDIO_CONFIG:
      return "get output audio config";
    case HFP_CTRL_SET_OUTPUT_AUDIO_CONFIG:
      return "set output audio config";
    case HFP_CTRL_GET_PRESENTATION_POSITION:
      return "get presentation position";
    default:
      return "undefined";
  }
}

tBTA_AG_SCB* get_hfp_active_device_callback() {
  const RawAddress& addr = bta_ag_get_active_device();
  if (addr.IsEmpty()) {
@@ -77,7 +102,7 @@ BluetoothAudioCtrlAck HfpTransport::StartRequest() {
    log::info("HFP_CTRL_CMD_START in progress");
    return BluetoothAudioCtrlAck::PENDING;
  } else if (hfp_pending_cmd_ != HFP_CTRL_CMD_NONE) {
    log::warn("busy in pending_cmd={}", hfp_pending_cmd_);
    log::warn("busy in pending_cmd={}, {}", hfp_pending_cmd_, command_to_text(hfp_pending_cmd_));
    return BluetoothAudioCtrlAck::FAILURE_BUSY;
  }

@@ -108,9 +133,11 @@ BluetoothAudioCtrlAck HfpTransport::StartRequest() {
  auto ctrl_ack = status_to_ack_map.find(status);
  if (ctrl_ack == status_to_ack_map.end()) {
    log::warn("Unmapped status={}", status);
    hfp_pending_cmd_ = HFP_CTRL_CMD_NONE;
    return BluetoothAudioCtrlAck::FAILURE;
  }
  if (ctrl_ack->second != BluetoothAudioCtrlAck::SUCCESS_FINISHED) {
    hfp_pending_cmd_ = HFP_CTRL_CMD_NONE;
    return ctrl_ack->second;
  }
  return BluetoothAudioCtrlAck::PENDING;
@@ -140,7 +167,7 @@ void HfpTransport::LogBytesProcessed(size_t bytes_read) {}
BluetoothAudioCtrlAck HfpTransport::SuspendRequest() {
  log::info("handling");
  if (hfp_pending_cmd_ != HFP_CTRL_CMD_NONE) {
    log::warn("busy in pending_cmd={}", hfp_pending_cmd_);
    log::warn("busy in pending_cmd={}, {}", hfp_pending_cmd_, command_to_text(hfp_pending_cmd_));
    return BluetoothAudioCtrlAck::FAILURE_BUSY;
  }

@@ -158,8 +185,14 @@ BluetoothAudioCtrlAck HfpTransport::SuspendRequest() {
  }
  auto status = instance->DisconnectAudio(&addr);
  log::info("DisconnectAudio status = {} - {}", status, bt_status_text(status));
  return status == BT_STATUS_SUCCESS ? BluetoothAudioCtrlAck::SUCCESS_FINISHED
                                     : BluetoothAudioCtrlAck::FAILURE;
  // once disconnect audio is queued, not waiting on that
  // because disconnect audio request can come when audio is disconnected
  hfp_pending_cmd_ = HFP_CTRL_CMD_NONE;
  if (status == BT_STATUS_SUCCESS) {
    return BluetoothAudioCtrlAck::SUCCESS_FINISHED;
  } else {
    return BluetoothAudioCtrlAck::FAILURE;
  }
}

void HfpTransport::SetLatencyMode(LatencyMode latency_mode) {}
+9 −3
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ void HfpClientInterface::Decode::StartSession() {
    log::error("cannot update audio config to HAL");
    return;
  }
  auto instance = aidl::hfp::HfpEncodingTransport::instance_;
  instance->ResetPendingCmd();
  get_decode_client_interface()->StartSession();
}

@@ -441,7 +443,11 @@ void HfpClientInterface::Offload::StartSession() {
    log::error("cannot update audio config to HAL");
    return;
  }
  get_encode_client_interface()->StartSession();
  if (get_encode_client_interface()->StartSession() == 0) {
    log::info("session started");
  } else {
    log::warn("session not started");
  }
}

void HfpClientInterface::Offload::StopSession() {
@@ -496,8 +502,8 @@ void HfpClientInterface::Offload::CancelStreamingRequest() {
      instance->ResetPendingCmd();
      return;
    case aidl::hfp::HFP_CTRL_CMD_NONE:
      log::warn("no pending start stream request");
      return;
      log::info("no pending start stream request");
      [[fallthrough]];
    case aidl::hfp::HFP_CTRL_CMD_SUSPEND:
      log::info("suspends");
      aidl::hfp::HfpEncodingTransport::offloading_hal_interface->StreamSuspended(