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

Commit 545b5519 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/bta/jv: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: I9840e87bc61854ac5a8d45ec5b9564c1d3af0deb
parent 782e770b
Loading
Loading
Loading
Loading
+131 −142

File changed.

Preview size limit exceeded, changes collapsed.

+30 −29
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <base/functional/bind.h>
#include <base/location.h>
#include <base/logging.h>
#include <bluetooth/log.h>

#include <cstdint>
#include <memory>
@@ -43,6 +44,7 @@

using base::Bind;
using bluetooth::Uuid;
using namespace bluetooth;

namespace {
bool bta_jv_enabled = false;
@@ -63,9 +65,9 @@ bool bta_jv_enabled = false;
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
  LOG_VERBOSE("");
  log::verbose("");
  if (!p_cback || bta_jv_enabled) {
    LOG(ERROR) << __func__ << ": failure";
    log::error("failure");
    return BTA_JV_FAILURE;
  }

@@ -85,7 +87,7 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {

/** Disable the Java I/F */
void BTA_JvDisable(void) {
  VLOG(2) << __func__;
  log::verbose("");

  bta_jv_enabled = false;

@@ -115,7 +117,7 @@ void BTA_JvDisable(void) {
 *
 ******************************************************************************/
void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
  LOG_VERBOSE("conn_type:%d, id:%u, channel:%u", conn_type, id, channel);
  log::verbose("conn_type:{}, id:{}, channel:{}", conn_type, id, channel);

  if (conn_type != BTA_JV_CONN_TYPE_RFCOMM &&
      conn_type != BTA_JV_CONN_TYPE_L2CAP &&
@@ -142,7 +144,7 @@ void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
  LOG_VERBOSE("channel:%u, conn_type:%d", channel, conn_type);
  log::verbose("channel:{}, conn_type:{}", channel, conn_type);

  do_in_main_thread(FROM_HERE, Bind(&bta_jv_free_scn, conn_type, channel));
  return BTA_JV_SUCCESS;
@@ -164,7 +166,7 @@ tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
                                    uint16_t num_uuid, const Uuid* p_uuid_list,
                                    uint32_t rfcomm_slot_id) {
  LOG_VERBOSE("bd_addr:%s, rfcomm_slot_id:%u, num_uuid:%u",
  log::verbose("bd_addr:{}, rfcomm_slot_id:{}, num_uuid:{}",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr), rfcomm_slot_id, num_uuid);

  Uuid* uuid_list_copy = new Uuid[num_uuid];
@@ -189,7 +191,7 @@ tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
  LOG_VERBOSE("rfcomm_slot_id: %u", rfcomm_slot_id);
  log::verbose("rfcomm_slot_id: {}", rfcomm_slot_id);

  do_in_main_thread(FROM_HERE, Bind(&bta_jv_create_record, rfcomm_slot_id));
  return BTA_JV_SUCCESS;
@@ -206,7 +208,7 @@ tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
  LOG_VERBOSE("handle:%u", handle);
  log::verbose("handle:{}", handle);

  do_in_main_thread(FROM_HERE, Bind(&bta_jv_delete_record, handle));
  return BTA_JV_SUCCESS;
@@ -231,9 +233,9 @@ void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                        const RawAddress& peer_bd_addr,
                        tBTA_JV_L2CAP_CBACK* p_cback,
                        uint32_t l2cap_socket_id) {
  LOG_VERBOSE(
      "conn_type:%d, role:%u, remote_psm:%u, peer_bd_addr:%s, "
      "l2cap_socket_id:%u",
  log::verbose(
      "conn_type:{}, role:{}, remote_psm:{}, peer_bd_addr:{}, "
      "l2cap_socket_id:{}",
      conn_type, role, remote_psm, ADDRESS_TO_LOGGABLE_CSTR(peer_bd_addr),
      l2cap_socket_id);
  CHECK(p_cback);
@@ -255,7 +257,7 @@ void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle) {
  LOG_VERBOSE("handle:%u", handle);
  log::verbose("handle:{}", handle);

  if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
    return BTA_JV_FAILURE;
@@ -285,7 +287,7 @@ void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                            std::unique_ptr<tL2CAP_CFG_INFO> cfg,
                            tBTA_JV_L2CAP_CBACK* p_cback,
                            uint32_t l2cap_socket_id) {
  LOG_VERBOSE("conn_type:%d, role:%u, local_psm:%u, l2cap_socket_id:%u",
  log::verbose("conn_type:{}, role:{}, local_psm:{}, l2cap_socket_id:{}",
               conn_type, role, local_psm, l2cap_socket_id);
  CHECK(p_cback);

@@ -308,7 +310,7 @@ void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
                                     uint32_t l2cap_socket_id) {
  LOG_VERBOSE("local_psm:%u, l2cap_socket_id:%u", local_psm, l2cap_socket_id);
  log::verbose("local_psm:{}, l2cap_socket_id:{}", local_psm, l2cap_socket_id);

  do_in_main_thread(
      FROM_HERE, Bind(&bta_jv_l2cap_stop_server, local_psm, l2cap_socket_id));
@@ -329,7 +331,7 @@ tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
                               uint8_t* p_data, uint16_t len) {
  LOG_VERBOSE("handle:%u, req_id:%u, len:%u", handle, req_id, len);
  log::verbose("handle:{}, req_id:{}, len:{}", handle, req_id, len);

  if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
    return BTA_JV_FAILURE;
@@ -364,7 +366,7 @@ tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
  tBTA_JV_STATUS status = BTA_JV_FAILURE;

  LOG_VERBOSE("handle:%u", handle);
  log::verbose("handle:{}", handle);
  if (p_data_size && handle < BTA_JV_MAX_L2C_CONN &&
      bta_jv_cb.l2c_cb[handle].p_cback) {
    *p_data_size = 0;
@@ -393,7 +395,7 @@ tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
                                uint32_t user_id) {
  LOG_VERBOSE("handle:%u, user_id:%u", handle, user_id);
  log::verbose("handle:{}, user_id:{}", handle, user_id);

  if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback) {
    osi_free(msg);
@@ -426,7 +428,7 @@ tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                                   const RawAddress& peer_bd_addr,
                                   tBTA_JV_RFCOMM_CBACK* p_cback,
                                   uint32_t rfcomm_slot_id) {
  LOG_VERBOSE("remote_scn:%u, peer_bd_addr:%s, rfcomm_slot_id:%u", remote_scn,
  log::verbose("remote_scn:{}, peer_bd_addr:{}, rfcomm_slot_id:{}", remote_scn,
               ADDRESS_TO_LOGGABLE_CSTR(peer_bd_addr), rfcomm_slot_id);

  if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
@@ -451,7 +453,7 @@ tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
  uint32_t hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
  uint32_t si = BTA_JV_RFC_HDL_TO_SIDX(handle);

  LOG_VERBOSE("handle:%u, rfcomm_slot_id:%u", handle, rfcomm_slot_id);
  log::verbose("handle:{}, rfcomm_slot_id:{}", handle, rfcomm_slot_id);

  if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
      si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
@@ -481,14 +483,13 @@ tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                                       uint8_t local_scn, uint8_t max_session,
                                       tBTA_JV_RFCOMM_CBACK* p_cback,
                                       uint32_t rfcomm_slot_id) {
  LOG_VERBOSE("local_scn:%u, rfcomm_slot_id:%u", local_scn, rfcomm_slot_id);
  log::verbose("local_scn:{}, rfcomm_slot_id:{}", local_scn, rfcomm_slot_id);

  if (p_cback == NULL) return BTA_JV_FAILURE; /* Nothing to do */

  if (max_session == 0) max_session = 1;
  if (max_session > BTA_JV_MAX_RFC_SR_SESSION) {
    LOG(INFO) << __func__ << "max_session is too big. use max "
              << BTA_JV_MAX_RFC_SR_SESSION;
    log::info("max_session is too big. use max {}", BTA_JV_MAX_RFC_SR_SESSION);
    max_session = BTA_JV_MAX_RFC_SR_SESSION;
  }

@@ -511,7 +512,7 @@ tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
                                      uint32_t rfcomm_slot_id) {
  LOG_VERBOSE("handle:%u, rfcomm_slot_id:%u", handle, rfcomm_slot_id);
  log::verbose("handle:{}, rfcomm_slot_id:{}", handle, rfcomm_slot_id);

  do_in_main_thread(FROM_HERE,
                    Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
@@ -552,13 +553,13 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
  uint32_t hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
  uint32_t si = BTA_JV_RFC_HDL_TO_SIDX(handle);

  LOG_VERBOSE("handle:%u, req_id:%u, hi:%u, si:%u", handle, req_id, hi, si);
  log::verbose("handle:{}, req_id:{}, hi:{}, si:{}", handle, req_id, hi, si);
  if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
      si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si]) {
    return BTA_JV_FAILURE;
  }

  LOG_VERBOSE("write ok");
  log::verbose("write ok");

  tBTA_JV_RFC_CB* p_cb = &bta_jv_cb.rfc_cb[hi];
  do_in_main_thread(FROM_HERE, Bind(&bta_jv_rfcomm_write, handle, req_id, p_cb,
@@ -591,7 +592,7 @@ tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
                                  tBTA_JV_CONN_STATE init_st) {
  LOG_VERBOSE("handle:%u, app_id:%u, init_st:%u", handle, app_id, handle);
  log::verbose("handle:{}, app_id:{}, init_st:{}", handle, app_id, handle);

  do_in_main_thread(FROM_HERE,
                    Bind(&bta_jv_set_pm_profile, handle, app_id, init_st));