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

Commit 15ab20f3 authored by Yuyang Huang's avatar Yuyang Huang Committed by Gerrit Code Review
Browse files

Merge changes I21f7091c,I1ed8508d into main

* changes:
  reset hfp_pending_cmd_ to handle retry logic
  use snapshot instead of synchronized to simplify logic
parents bdb1347b 7c5c2fc9
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -1795,11 +1795,12 @@ class HeadsetStateMachine extends StateMachine {
     *     BluetoothHeadset#STATE_AUDIO_CONNECTING}, or {@link
     *     BluetoothHeadset#STATE_AUDIO_CONNECTING}, or {@link
     *     BluetoothHeadset#STATE_AUDIO_CONNECTED}
     *     BluetoothHeadset#STATE_AUDIO_CONNECTED}
     */
     */
    public synchronized int getAudioState() {
    public int getAudioState() {
        if (mCurrentState == null) {
        HeadsetStateBase state = mCurrentState;
        if (state == null) {
            return BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
            return BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
        }
        }
        return mCurrentState.getAudioStateInt();
        return state.getAudioStateInt();
    }
    }


    public long getConnectingTimestampMs() {
    public long getConnectingTimestampMs() {
+37 −4
Original line number Original line Diff line number Diff line
@@ -49,6 +49,31 @@ std::map<bt_status_t, BluetoothAudioCtrlAck> status_to_ack_map = {
        {BT_STATUS_UNSUPPORTED, BluetoothAudioCtrlAck::FAILURE_UNSUPPORTED},
        {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() {
tBTA_AG_SCB* get_hfp_active_device_callback() {
  const RawAddress& addr = bta_ag_get_active_device();
  const RawAddress& addr = bta_ag_get_active_device();
  if (addr.IsEmpty()) {
  if (addr.IsEmpty()) {
@@ -89,7 +114,7 @@ BluetoothAudioCtrlAck HfpTransport::StartRequest() {
    is_stream_active = true;
    is_stream_active = true;
    return BluetoothAudioCtrlAck::PENDING;
    return BluetoothAudioCtrlAck::PENDING;
  } else if (hfp_pending_cmd_ != HFP_CTRL_CMD_NONE) {
  } 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;
    return BluetoothAudioCtrlAck::FAILURE_BUSY;
  }
  }


@@ -121,9 +146,11 @@ BluetoothAudioCtrlAck HfpTransport::StartRequest() {
  auto ctrl_ack = status_to_ack_map.find(status);
  auto ctrl_ack = status_to_ack_map.find(status);
  if (ctrl_ack == status_to_ack_map.end()) {
  if (ctrl_ack == status_to_ack_map.end()) {
    log::warn("Unmapped status={}", status);
    log::warn("Unmapped status={}", status);
    hfp_pending_cmd_ = HFP_CTRL_CMD_NONE;
    return BluetoothAudioCtrlAck::FAILURE;
    return BluetoothAudioCtrlAck::FAILURE;
  }
  }
  if (ctrl_ack->second != BluetoothAudioCtrlAck::SUCCESS_FINISHED) {
  if (ctrl_ack->second != BluetoothAudioCtrlAck::SUCCESS_FINISHED) {
    hfp_pending_cmd_ = HFP_CTRL_CMD_NONE;
    return ctrl_ack->second;
    return ctrl_ack->second;
  }
  }
  is_stream_active = true;
  is_stream_active = true;
@@ -157,7 +184,7 @@ void HfpTransport::LogBytesProcessed(size_t bytes_read) {}
BluetoothAudioCtrlAck HfpTransport::SuspendRequest() {
BluetoothAudioCtrlAck HfpTransport::SuspendRequest() {
  log::info("handling");
  log::info("handling");
  if (hfp_pending_cmd_ != HFP_CTRL_CMD_NONE) {
  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;
    return BluetoothAudioCtrlAck::FAILURE_BUSY;
  }
  }


@@ -175,8 +202,14 @@ BluetoothAudioCtrlAck HfpTransport::SuspendRequest() {
  }
  }
  auto status = instance->DisconnectAudio(&addr);
  auto status = instance->DisconnectAudio(&addr);
  log::info("DisconnectAudio status = {} - {}", status, bt_status_text(status));
  log::info("DisconnectAudio status = {} - {}", status, bt_status_text(status));
  return status == BT_STATUS_SUCCESS ? BluetoothAudioCtrlAck::SUCCESS_FINISHED
  // once disconnect audio is queued, not waiting on that
                                     : BluetoothAudioCtrlAck::FAILURE;
  // 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) {}
void HfpTransport::SetLatencyMode(LatencyMode latency_mode) {}
+9 −3
Original line number Original line Diff line number Diff line
@@ -148,6 +148,8 @@ void HfpClientInterface::Decode::StartSession() {
    log::error("cannot update audio config to HAL");
    log::error("cannot update audio config to HAL");
    return;
    return;
  }
  }
  auto instance = aidl::hfp::HfpEncodingTransport::instance_;
  instance->ResetPendingCmd();
  get_decode_client_interface()->StartSession();
  get_decode_client_interface()->StartSession();
}
}


@@ -484,7 +486,11 @@ void HfpClientInterface::Offload::StartSession() {
    log::error("cannot update audio config to HAL");
    log::error("cannot update audio config to HAL");
    return;
    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() {
void HfpClientInterface::Offload::StopSession() {
@@ -545,8 +551,8 @@ void HfpClientInterface::Offload::CancelStreamingRequest() {
      instance->ResetPendingCmd();
      instance->ResetPendingCmd();
      return;
      return;
    case aidl::hfp::HFP_CTRL_CMD_NONE:
    case aidl::hfp::HFP_CTRL_CMD_NONE:
      log::warn("no pending start stream request");
      log::info("no pending start stream request");
      return;
      [[fallthrough]];
    case aidl::hfp::HFP_CTRL_CMD_SUSPEND:
    case aidl::hfp::HFP_CTRL_CMD_SUSPEND:
      log::info("suspends");
      log::info("suspends");
      aidl::hfp::HfpEncodingTransport::offloading_hal_interface->StreamSuspended(
      aidl::hfp::HfpEncodingTransport::offloading_hal_interface->StreamSuspended(