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

Commit 208f9a48 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Read the Tx Power level when flushing the A2DP Tx queue

Also, minor renaming and cleanup (for consistency).

Test: Streaming A2DP headset and trigger audio stutter
Bug: 64038257
Change-Id: Id722342b596e0bf3c9c7664272b6d3e311bb82e9
parent 2cba2968
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ static void update_scheduling_stats(scheduling_stats_t* stats, uint64_t now_us,
static void btm_read_rssi_cb(void* data);
static void btm_read_failed_contact_counter_cb(void* data);
static void btm_read_automatic_flush_timeout_cb(void* data);
static void btm_read_tx_power_cb(void* data);

UNUSED_ATTR static const char* dump_media_event(uint16_t event) {
  switch (event) {
@@ -763,6 +764,12 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n) {
      LOG_WARN(LOG_TAG, "%s: Cannot read Automatic Flush Timeout: status %d",
               __func__, status);
    }
    status =
        BTM_ReadTxPower(peer_bda, BT_TRANSPORT_BR_EDR, btm_read_tx_power_cb);
    if (status != BTM_CMD_STARTED) {
      LOG_WARN(LOG_TAG, "%s: Cannot read Tx Power: status %d", __func__,
               status);
    }
  }

  /* Update the statistics */
@@ -1102,7 +1109,7 @@ static void btm_read_rssi_cb(void* data) {
    return;
  }

  tBTM_RSSI_RESULTS* result = (tBTM_RSSI_RESULTS*)data;
  tBTM_RSSI_RESULT* result = (tBTM_RSSI_RESULT*)data;
  if (result->status != BTM_SUCCESS) {
    LOG_ERROR(LOG_TAG, "%s unable to read remote RSSI (status %d)", __func__,
              result->status);
@@ -1150,3 +1157,20 @@ static void btm_read_automatic_flush_timeout_cb(void* data) {
  LOG_WARN(LOG_TAG, "%s device: %s, Automatic Flush Timeout: %u", __func__,
           result->rem_bda.ToString().c_str(), result->automatic_flush_timeout);
}

static void btm_read_tx_power_cb(void* data) {
  if (data == nullptr) {
    LOG_ERROR(LOG_TAG, "%s Read Tx Power request timed out", __func__);
    return;
  }

  tBTM_TX_POWER_RESULT* result = (tBTM_TX_POWER_RESULT*)data;
  if (result->status != BTM_SUCCESS) {
    LOG_ERROR(LOG_TAG, "%s unable to read Tx Power (status %d)", __func__,
              result->status);
    return;
  }

  LOG_WARN(LOG_TAG, "%s device: %s, Tx Power: %d", __func__,
           result->rem_bda.ToString().c_str(), result->tx_power);
}
+1 −1
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ void bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
  ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status);
}

void btm_read_rssi_cb(tBTM_RSSI_RESULTS* p_result) {
void btm_read_rssi_cb(tBTM_RSSI_RESULT* p_result) {
  if (!p_result) return;

  CLI_CBACK_IN_JNI(read_remote_rssi_cb, rssi_request_client_if,
+57 −53
Original line number Diff line number Diff line
@@ -1250,9 +1250,10 @@ tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda,
      btsnd_hcic_write_link_super_tout(LOCAL_BR_EDR_CONTROLLER_ID,
                                       p->hci_handle, timeout);
      return (BTM_CMD_STARTED);
    } else
    } else {
      return (BTM_SUCCESS);
    }
  }

  /* If here, no BD Addr found */
  return (BTM_UNKNOWN_ADDR);
@@ -1577,9 +1578,10 @@ bool BTM_FreeSCN(uint8_t scn) {
  if (scn <= BTM_MAX_SCN) {
    btm_cb.btm_scn[scn - 1] = false;
    return (true);
  } else
  } else {
    return (false); /* Illegal SCN passed in */
  }
}

/*******************************************************************************
 *
@@ -1887,7 +1889,7 @@ void btm_qos_setup_complete(uint8_t status, uint16_t handle,
 * Description      This function is called to read the link policy settings.
 *                  The address of link policy results are returned in the
 *                  callback.
 *                  (tBTM_RSSI_RESULTS)
 *                  (tBTM_RSSI_RESULT)
 *
 * Returns          BTM_CMD_STARTED if successfully initiated or error code
 *
@@ -2006,7 +2008,7 @@ tBTM_STATUS BTM_ReadAutomaticFlushTimeout(const RawAddress& remote_bda,
 *
 * Description      This function is called to read the link qulaity.
 *                  The value of the link quality is returned in the callback.
 *                  (tBTM_LINK_QUALITY_RESULTS)
 *                  (tBTM_LINK_QUALITY_RESULT)
 *
 * Returns          BTM_CMD_STARTED if successfully initiated or error code
 *
@@ -2040,7 +2042,7 @@ tBTM_STATUS BTM_ReadLinkQuality(const RawAddress& remote_bda,
 * Description      This function is called to read the current
 *                  TX power of the connection. The tx power level results
 *                  are returned in the callback.
 *                  (tBTM_RSSI_RESULTS)
 *                  (tBTM_RSSI_RESULT)
 *
 * Returns          BTM_CMD_STARTED if successfully initiated or error code
 *
@@ -2104,10 +2106,8 @@ void btm_read_tx_power_timeout(UNUSED_ATTR void* data) {
 ******************************************************************************/
void btm_read_tx_power_complete(uint8_t* p, bool is_ble) {
  tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
  tBTM_TX_POWER_RESULTS results;
  uint16_t handle;
  tBTM_TX_POWER_RESULT result;
  tACL_CONN* p_acl_cb = &btm_cb.acl_db[0];
  uint16_t index;

  BTM_TRACE_DEBUG("%s", __func__);
  alarm_cancel(btm_cb.devcb.read_tx_power_timer);
@@ -2115,32 +2115,34 @@ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) {

  /* If there was a registered callback, call it */
  if (p_cb) {
    STREAM_TO_UINT8(results.hci_status, p);
    STREAM_TO_UINT8(result.hci_status, p);

    if (results.hci_status == HCI_SUCCESS) {
      results.status = BTM_SUCCESS;
    if (result.hci_status == HCI_SUCCESS) {
      result.status = BTM_SUCCESS;

      if (!is_ble) {
        uint16_t handle;
        STREAM_TO_UINT16(handle, p);
        STREAM_TO_UINT8(results.tx_power, p);
        STREAM_TO_UINT8(result.tx_power, p);

        /* Search through the list of active channels for the correct BD Addr */
        for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
        for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
          if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) {
            results.rem_bda = p_acl_cb->remote_addr;
            result.rem_bda = p_acl_cb->remote_addr;
            break;
          }
        }
      } else {
        STREAM_TO_UINT8(results.tx_power, p);
        results.rem_bda = btm_cb.devcb.read_tx_pwr_addr;
        STREAM_TO_UINT8(result.tx_power, p);
        result.rem_bda = btm_cb.devcb.read_tx_pwr_addr;
      }
      BTM_TRACE_DEBUG("BTM TX power Complete: tx_power %d, hci status 0x%02x",
                      results.tx_power, results.hci_status);
    } else
      results.status = BTM_ERR_PROCESSING;
                      result.tx_power, result.hci_status);
    } else {
      result.status = BTM_ERR_PROCESSING;
    }

    (*p_cb)(&results);
    (*p_cb)(&result);
  }
}

@@ -2154,12 +2156,11 @@ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) {
 *
 ******************************************************************************/
void btm_read_rssi_timeout(UNUSED_ATTR void* data) {
  tBTM_RSSI_RESULTS  results;
  tBTM_RSSI_RESULT result;
  tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
  btm_cb.devcb.p_rssi_cmpl_cb = NULL;
  results.status = BTM_DEVICE_TIMEOUT;
  if (p_cb)
      (*p_cb)(&results);
  result.status = BTM_DEVICE_TIMEOUT;
  if (p_cb) (*p_cb)(&result);
}

/*******************************************************************************
@@ -2174,10 +2175,8 @@ void btm_read_rssi_timeout(UNUSED_ATTR void* data) {
 ******************************************************************************/
void btm_read_rssi_complete(uint8_t* p) {
  tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
  tBTM_RSSI_RESULTS results;
  uint16_t handle;
  tBTM_RSSI_RESULT result;
  tACL_CONN* p_acl_cb = &btm_cb.acl_db[0];
  uint16_t index;

  BTM_TRACE_DEBUG("%s", __func__);
  alarm_cancel(btm_cb.devcb.read_rssi_timer);
@@ -2185,28 +2184,30 @@ void btm_read_rssi_complete(uint8_t* p) {

  /* If there was a registered callback, call it */
  if (p_cb) {
    STREAM_TO_UINT8(results.hci_status, p);
    STREAM_TO_UINT8(result.hci_status, p);

    if (results.hci_status == HCI_SUCCESS) {
      results.status = BTM_SUCCESS;
    if (result.hci_status == HCI_SUCCESS) {
      uint16_t handle;
      result.status = BTM_SUCCESS;

      STREAM_TO_UINT16(handle, p);

      STREAM_TO_UINT8(results.rssi, p);
      STREAM_TO_UINT8(result.rssi, p);
      BTM_TRACE_DEBUG("BTM RSSI Complete: rssi %d, hci status 0x%02x",
                      results.rssi, results.hci_status);
                      result.rssi, result.hci_status);

      /* Search through the list of active channels for the correct BD Addr */
      for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
      for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
        if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) {
          results.rem_bda = p_acl_cb->remote_addr;
          result.rem_bda = p_acl_cb->remote_addr;
          break;
        }
      }
    } else
      results.status = BTM_ERR_PROCESSING;
    } else {
      result.status = BTM_ERR_PROCESSING;
    }

    (*p_cb)(&results);
    (*p_cb)(&result);
  }
}

@@ -2371,10 +2372,8 @@ void btm_read_link_quality_timeout(UNUSED_ATTR void* data) {
 ******************************************************************************/
void btm_read_link_quality_complete(uint8_t* p) {
  tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_link_qual_cmpl_cb;
  tBTM_LINK_QUALITY_RESULTS results;
  uint16_t handle;
  tBTM_LINK_QUALITY_RESULT result;
  tACL_CONN* p_acl_cb = &btm_cb.acl_db[0];
  uint16_t index;

  BTM_TRACE_DEBUG("%s", __func__);
  alarm_cancel(btm_cb.devcb.read_link_quality_timer);
@@ -2382,29 +2381,31 @@ void btm_read_link_quality_complete(uint8_t* p) {

  /* If there was a registered callback, call it */
  if (p_cb) {
    STREAM_TO_UINT8(results.hci_status, p);
    STREAM_TO_UINT8(result.hci_status, p);

    if (results.hci_status == HCI_SUCCESS) {
      results.status = BTM_SUCCESS;
    if (result.hci_status == HCI_SUCCESS) {
      uint16_t handle;
      result.status = BTM_SUCCESS;

      STREAM_TO_UINT16(handle, p);

      STREAM_TO_UINT8(results.link_quality, p);
      STREAM_TO_UINT8(result.link_quality, p);
      BTM_TRACE_DEBUG(
          "BTM Link Quality Complete: Link Quality %d, hci status 0x%02x",
          results.link_quality, results.hci_status);
          result.link_quality, result.hci_status);

      /* Search through the list of active channels for the correct BD Addr */
      for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
      for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) {
        if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) {
          results.rem_bda = p_acl_cb->remote_addr;
          result.rem_bda = p_acl_cb->remote_addr;
          break;
        }
      }
    } else
      results.status = BTM_ERR_PROCESSING;
    } else {
      result.status = BTM_ERR_PROCESSING;
    }

    (*p_cb)(&results);
    (*p_cb)(&result);
  }
}

@@ -2435,9 +2436,10 @@ tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr, tBT_TRANSPORT transport) {
    if (hci_handle != 0xFFFF && p_dev_rec &&
        p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) {
      btsnd_hcic_disconnect(hci_handle, HCI_ERR_PEER_USER);
    } else
    } else {
      status = BTM_UNKNOWN_ADDR;
    }
  }

  return status;
}
@@ -2528,9 +2530,10 @@ void btm_acl_resubmit_page(void) {
    memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);

    btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
  } else
  } else {
    btm_cb.paging = false;
  }
}

/*******************************************************************************
 *
@@ -2609,9 +2612,10 @@ bool btm_acl_notif_conn_collision(const RawAddress& bda) {
    evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
    (*btm_cb.p_bl_changed_cb)(&evt_data);
    return true;
  } else
  } else {
    return false;
  }
}

/*******************************************************************************
 *
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ static void btm_db_reset(void) {
    p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
    btm_cb.devcb.p_rssi_cmpl_cb = NULL;

    if (p_cb) (*p_cb)((tBTM_RSSI_RESULTS*)&status);
    if (p_cb) (*p_cb)((tBTM_RSSI_RESULT*)&status);
  }

  if (btm_cb.devcb.p_failed_contact_counter_cmpl_cb) {
+10 −9
Original line number Diff line number Diff line
@@ -2228,7 +2228,7 @@ void btm_read_inq_tx_power_timeout(UNUSED_ATTR void* data) {
 ******************************************************************************/
void btm_read_inq_tx_power_complete(uint8_t* p) {
  tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb;
  tBTM_INQ_TXPWR_RESULTS results;
  tBTM_INQ_TXPWR_RESULT result;

  BTM_TRACE_DEBUG("%s", __func__);
  alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer);
@@ -2236,19 +2236,20 @@ void btm_read_inq_tx_power_complete(uint8_t* p) {

  /* If there was a registered callback, call it */
  if (p_cb) {
    STREAM_TO_UINT8(results.hci_status, p);
    STREAM_TO_UINT8(result.hci_status, p);

    if (results.hci_status == HCI_SUCCESS) {
      results.status = BTM_SUCCESS;
    if (result.hci_status == HCI_SUCCESS) {
      result.status = BTM_SUCCESS;

      STREAM_TO_UINT8(results.tx_power, p);
      STREAM_TO_UINT8(result.tx_power, p);
      BTM_TRACE_EVENT(
          "BTM INQ TX POWER Complete: tx_power %d, hci status 0x%02x",
          results.tx_power, results.hci_status);
    } else
      results.status = BTM_ERR_PROCESSING;
          result.tx_power, result.hci_status);
    } else {
      result.status = BTM_ERR_PROCESSING;
    }

    (*p_cb)(&results);
    (*p_cb)(&result);
  }
}
/*******************************************************************************
Loading