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

Commit 6141b835 authored by Cheney Ni's avatar Cheney Ni
Browse files

Check A2DP UIPC state before feeding data

When using the new Bluetooth Audio HAL, A2DP UIPC won't be initialized
and can't be accessed. This change checks the UIPC is valid before
accessing, and prevents unexpected SIGSEGV.

Bug: 124645960
Test: Start / pause A2DP manually
Change-Id: I58ceea503d0c159817167bb3ca3b99b6f933bf23
parent 921aab07
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event);

/* We can have max one command pending */
static tA2DP_CTRL_CMD a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;
std::unique_ptr<tUIPC_STATE> a2dp_uipc;
std::unique_ptr<tUIPC_STATE> a2dp_uipc = nullptr;

void btif_a2dp_control_init(void) {
  a2dp_uipc = UIPC_Init();
@@ -57,8 +57,10 @@ void btif_a2dp_control_init(void) {

void btif_a2dp_control_cleanup(void) {
  /* This calls blocks until UIPC is fully closed */
  if (a2dp_uipc != nullptr) {
    UIPC_Close(*a2dp_uipc, UIPC_CH_ID_ALL);
  }
}

static void btif_a2dp_recv_ctrl_data(void) {
  tA2DP_CTRL_CMD cmd = A2DP_CTRL_CMD_NONE;
@@ -419,8 +421,10 @@ void btif_a2dp_command_ack(tA2DP_CTRL_ACK status) {
  a2dp_cmd_pending = A2DP_CTRL_CMD_NONE;

  /* Acknowledge start request */
  if (a2dp_uipc != nullptr) {
    UIPC_Send(*a2dp_uipc, UIPC_CH_ID_AV_CTRL, 0, &ack, sizeof(ack));
  }
}

void btif_a2dp_control_log_bytes_read(uint32_t bytes_read) {
  delay_report_stats.total_bytes_read += bytes_read;
+5 −5
Original line number Diff line number Diff line
@@ -800,7 +800,7 @@ static void btif_a2dp_source_audio_tx_stop_event(void) {
  if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
    btif_a2dp_control_log_bytes_read(
        bluetooth::audio::a2dp::read(p_buf, sizeof(p_buf)));
  } else {
  } else if (a2dp_uipc != nullptr) {
    btif_a2dp_control_log_bytes_read(UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO,
                                               &event, p_buf, sizeof(p_buf)));
  }
@@ -811,7 +811,7 @@ static void btif_a2dp_source_audio_tx_stop_event(void) {

  if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
    bluetooth::audio::a2dp::ack_stream_suspended(A2DP_CTRL_ACK_SUCCESS);
  } else {
  } else if (a2dp_uipc != nullptr) {
    UIPC_Close(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO);

    /*
@@ -869,11 +869,11 @@ static void btif_a2dp_source_audio_handle_timer(void) {

static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
  uint16_t event;
  uint32_t bytes_read;
  uint32_t bytes_read = 0;

  if (bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
    bytes_read = bluetooth::audio::a2dp::read(p_buf, len);
  } else {
  } else if (a2dp_uipc != nullptr) {
    bytes_read = UIPC_Read(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, &event, p_buf, len);
  }

@@ -1003,7 +1003,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) {
      bluetooth::common::time_get_os_boottime_us();
  fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);

  if (!bluetooth::audio::a2dp::is_hal_2_0_enabled()) {
  if (!bluetooth::audio::a2dp::is_hal_2_0_enabled() && a2dp_uipc != nullptr) {
    UIPC_Ioctl(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, nullptr);
  }
}