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

Commit 7a64e3a9 authored by Bao Do's avatar Bao Do
Browse files

Add checking for active ISO channels before starting A2DP stream.

This will help prevent race conditions when changing from LEA active
device to A2DP for music streaming cases.

Bug: 346475618
Bug: 341219050
Test: mmm packages/modules/Bluetooth/
Change-Id: Ib6e25a600e4766f1aab1088e72477069411dd0dc
parent f6c19d19
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "a2dp_encoding_aidl.h"

#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <vector>

@@ -26,6 +27,7 @@
#include "audio_aidl_interfaces.h"
#include "bta/av/bta_av_int.h"
#include "btif/include/btif_common.h"
#include "btm_iso_api.h"
#include "codec_status_aidl.h"
#include "transport_instance.h"

@@ -97,6 +99,14 @@ BluetoothAudioCtrlAck A2dpTransport::StartRequest(bool is_low_latency) {
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_INCALL_FAILURE);
  }

  if (com::android::bluetooth::flags::a2dp_check_lea_iso_channel()) {
    // Don't send START request to stack while LEA sessions are in use
    if (hci::IsoManager::GetInstance()->GetNumberOfActiveIso() > 0) {
      log::error("LEA currently has active ISO channels");
      return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_FAILURE);
    }
  }

  if (btif_av_stream_started_ready(A2dpType::kSource)) {
    // Already started, ACK back immediately.
    return a2dp_ack_to_bt_audio_ctrl_ack(A2DP_CTRL_ACK_SUCCESS);
+4 −0
Original line number Diff line number Diff line
@@ -90,6 +90,10 @@ void IsoManager::DisconnectCis(uint16_t cis_handle, uint8_t reason) {
  pimpl_->iso_impl_->disconnect_cis(cis_handle, reason);
}

int IsoManager::GetNumberOfActiveIso() {
  return pimpl_->iso_impl_->get_number_of_active_iso();
}

void IsoManager::SetupIsoDataPath(
    uint16_t iso_handle, struct iso_manager::iso_data_path_params path_params) {
  pimpl_->iso_impl_->setup_iso_data_path(iso_handle, std::move(path_params));
+6 −0
Original line number Diff line number Diff line
@@ -342,6 +342,12 @@ struct iso_impl {
                       hci_reason_code_text((tHCI_REASON)(reason)).c_str()));
  }

  int get_number_of_active_iso() {
    int num_iso = conn_hdl_to_cis_map_.size() + conn_hdl_to_bis_map_.size();
    log::info("Current number of active_iso is {}", num_iso);
    return num_iso;
  }

  void on_setup_iso_data_path(uint8_t* stream, uint16_t /* len */) {
    uint8_t status;
    uint16_t conn_handle;
+5 −0
Original line number Diff line number Diff line
@@ -226,6 +226,11 @@ class IsoManager {
  virtual void HandleHciEvent(uint8_t sub_code, uint8_t* params,
                              uint16_t length);

  /**
   * Return the current number of ISO channels
   */
  virtual int GetNumberOfActiveIso();

  /**
   * Starts the IsoManager module
   */
+4 −0
Original line number Diff line number Diff line
@@ -157,6 +157,10 @@ void IsoManager::Stop() {
  mock_pimpl_ = nullptr;
}

int IsoManager::GetNumberOfActiveIso() {
  return pimpl_->GetNumberOfActiveIso();
}

void IsoManager::Dump(int /* fd */) {}

IsoManager::~IsoManager() = default;
Loading