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

Commit 8cfb12b4 authored by Chris Manton's avatar Chris Manton
Browse files

Provide SDP in log history

Bug: 260579060
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I46f978235417dcb61c5c75f5ed4efc3f14c99f30
parent 80150f5d
Loading
Loading
Loading
Loading
+42 −4
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@
#include "stack/include/bt_octets.h"
#include "stack/include/bt_types.h"
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_log_history.h"
#include "stack/include/btu.h"       // do_in_main_thread
#include "stack/include/srvc_api.h"  // DIS_ReadDISInfo
#include "types/bluetooth/uuid.h"
@@ -71,6 +72,10 @@

using bluetooth::Uuid;

namespace {
constexpr char kBtmLogTag[] = "SDP";
}

void BTIF_dm_disable();
void BTIF_dm_enable();
void btm_ble_adv_init(void);
@@ -1078,11 +1083,22 @@ void bta_dm_rmt_name(tBTA_DM_MSG* p_data) {
 *
 ******************************************************************************/
void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data) {
  tBTM_INQ_INFO* p_btm_inq_info;
  CHECK(p_data != nullptr);

  APPL_TRACE_DEBUG("bta_dm_disc_rmt_name");

  p_btm_inq_info = BTM_InqDbRead(p_data->rem_name.result.disc_res.bd_addr);
  const tBTA_DM_DISC_RES* disc_res = &p_data->rem_name.result.disc_res;

  BTM_LogHistory(
      kBtmLogTag, disc_res->bd_addr, "Remote name completed",
      base::StringPrintf(
          "status:%s name:\"%s\" service:0x%x device_type:%s num_uuids:%zu",
          bta_status_text(disc_res->result).c_str(), disc_res->bd_name,
          disc_res->services, DeviceTypeText(disc_res->device_type).c_str(),
          disc_res->num_uuids));

  tBTM_INQ_INFO* p_btm_inq_info =
      BTM_InqDbRead(p_data->rem_name.result.disc_res.bd_addr);
  if (p_btm_inq_info) {
    if (p_data->rem_name.result.disc_res.bd_name[0]) {
      p_btm_inq_info->appl_knows_rem_name = true;
@@ -1178,6 +1194,8 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {

  std::vector<Uuid> uuid_list;

  const tSDP_RESULT sdp_result = p_data->sdp_event.sdp_result;

  if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) ||
      (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) ||
      (p_data->sdp_event.sdp_result == SDP_DB_FULL)) {
@@ -1312,6 +1330,13 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
            &bta_dm_service_search_remname_cback);
      }

      BTM_LogHistory(
          kBtmLogTag, bta_dm_search_cb.peer_bdaddr, "Discovery completed",
          base::StringPrintf("Result:%s services_found:0x%x service_index:0x%d",
                             sdp_result_text(sdp_result).c_str(),
                             bta_dm_search_cb.services_found,
                             bta_dm_search_cb.service_index));

      p_msg = (tBTA_DM_MSG*)osi_calloc(sizeof(tBTA_DM_MSG));
      p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT;
      p_msg->disc_result.result.disc_res.result = BTA_SUCCESS;
@@ -1362,7 +1387,10 @@ void bta_dm_sdp_result(tBTA_DM_MSG* p_data) {
      bta_sys_sendmsg(p_msg);
    }
  } else {
    /* conn failed. No need for timer */
    BTM_LogHistory(
        kBtmLogTag, bta_dm_search_cb.peer_bdaddr, "Discovery failed",
        base::StringPrintf("Result:%s", sdp_result_text(sdp_result).c_str()));
    LOG_ERROR("SDP connection failed %s", sdp_status_text(sdp_result).c_str());
    if (p_data->sdp_event.sdp_result == SDP_CONN_FAILED)
      bta_dm_search_cb.wait_disc = false;

@@ -1861,10 +1889,16 @@ static void bta_dm_discover_device(const RawAddress& remote_bd_addr) {
    if (bta_dm_read_remote_device_name(bta_dm_search_cb.peer_bdaddr,
                                       transport)) {
      if (bta_dm_search_cb.state != BTA_DM_DISCOVER_ACTIVE) {
        /* Reset transport state for next discovery */
        LOG_DEBUG("Reset transport state for next discovery");
        bta_dm_search_cb.transport = BT_TRANSPORT_AUTO;
      }
      BTM_LogHistory(kBtmLogTag, bta_dm_search_cb.peer_bdaddr,
                     "Read remote name",
                     base::StringPrintf("Transport:%s",
                                        bt_transport_text(transport).c_str()));
      return;
    } else {
      LOG_ERROR("Unable to start read remote device name");
    }

    /* starting name discovery failed */
@@ -1876,6 +1910,10 @@ static void bta_dm_discover_device(const RawAddress& remote_bd_addr) {

  /* if application wants to discover service */
  if (bta_dm_search_cb.services) {
    BTM_LogHistory(kBtmLogTag, remote_bd_addr, "Discovery started ",
                   base::StringPrintf("Transport:%s",
                                      bt_transport_text(transport).c_str()));

    /* initialize variables */
    bta_dm_search_cb.service_index = 0;
    bta_dm_search_cb.services_found = 0;
+16 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@

#include <base/functional/bind.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/uuid.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_csis.h>
@@ -49,6 +50,7 @@
#include <mutex>

#include "advertise_data_parser.h"
#include "bta/include/bta_api.h"
#include "bta_csis_api.h"
#include "bta_dm_int.h"
#include "bta_gatt_api.h"
@@ -90,6 +92,11 @@
bool btif_get_device_type(const RawAddress& bda, int* p_device_type);

using bluetooth::Uuid;

namespace {
constexpr char kBtmLogTagSdp[] = "SDP";
}

/******************************************************************************
 *  Constants & Macros
 *****************************************************************************/
@@ -1516,7 +1523,6 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
    case BTA_DM_DISC_RES_EVT: {
      bt_property_t prop;
      uint32_t i = 0;
      bt_status_t ret;
      std::vector<uint8_t> property_value;
      std::set<Uuid> uuids;
      bool a2dp_sink_capable = false;
@@ -1646,9 +1652,17 @@ static void btif_dm_search_services_evt(tBTA_DM_SEARCH_EVT event,
        LOG_INFO("clearing btif pairing_cb");
      }

      const tBTA_STATUS bta_status = p_data->disc_res.result;
      BTM_LogHistory(
          kBtmLogTagSdp, bd_addr, "Discovered services",
          base::StringPrintf("bta_status:%s sdp_uuids:%zu eir_uuids:%zu",
                             bta_status_text(bta_status).c_str(),
                             p_data->disc_res.num_uuids, num_eir_uuids));

      if (p_data->disc_res.num_uuids != 0 || num_eir_uuids != 0) {
        /* Also write this to the NVRAM */
        ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
        const bt_status_t ret =
            btif_storage_set_remote_device_property(&bd_addr, &prop);
        ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed",
                ret);