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

Commit 69f3e0ae authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BluetoothMetrics: Add logging to L2CAP and SDP code paths using counter metrics"

parents ad78590d b61f4b83
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ cc_library_static {
    static_libs: [
        "avrcp-target-service",
        "lib-bt-packets",
        "libbt-platform-protos-lite",
    ],
    shared_libs: [
        "android.hardware.bluetooth.audio@2.0",
+7 −0
Original line number Diff line number Diff line
@@ -20,12 +20,15 @@
 *  This file contains action functions for SDP search.
 ******************************************************************************/

#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <hardware/bt_sdp.h>

#include <cstdint>

#include "bta/include/bta_sdp_api.h"
#include "bta/sdp/bta_sdp_int.h"
#include "btif/include/btif_sock_sdp.h"
#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "stack/include/sdp_api.h"
#include "types/bluetooth/uuid.h"
@@ -435,6 +438,8 @@ static void bta_sdp_search_cback(tSDP_RESULT result, const void* user_data) {
  tBTA_SDP bta_sdp;
  bta_sdp.sdp_search_comp = evt_data;
  bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, &bta_sdp, (void*)&uuid);
  bluetooth::shim::CountCounterMetrics(
      android::bluetooth::CodePathCounterKeyEnum::SDP_SUCCESS, 1);
  osi_free(const_cast<void*>(
      user_data));  // We no longer need the user data to track the search
}
@@ -513,6 +518,8 @@ void bta_sdp_search(const RawAddress bd_addr, const bluetooth::Uuid uuid) {
      tBTA_SDP bta_sdp;
      bta_sdp.sdp_search_comp = result;
      bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, &bta_sdp, NULL);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::SDP_FAILURE, 1);
    }
  }
  /*
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <gtest/gtest.h>

#include "bta/sdp/bta_sdp_act.cc"
#include "main/shim/metrics_api.h"
#include "stack/sdp/sdp_api.cc"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
@@ -49,6 +50,10 @@ static void sdp_dm_cback(tBTA_SDP_EVT event, tBTA_SDP* p_data,
  return;
}

bool bluetooth::shim::CountCounterMetrics(int32_t key, int64_t count) {
  return true;
}

class BtaDipTest : public ::testing::Test {
 protected:
  void SetUp() override {
+1 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ cc_library_static {
    static_libs: [
        "libbt-hci",
        "libFraunhoferAAC",
        "libbt-platform-protos-lite",
    ],
    shared_libs: [
        "libcutils",
+53 −2
Original line number Diff line number Diff line
@@ -23,20 +23,22 @@
 ******************************************************************************/
#define LOG_TAG "l2c_csm"

#include <base/logging.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>

#include <string>

#include "bt_target.h"
#include "common/time_util.h"
#include "l2c_int.h"
#include "l2cdefs.h"
#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/acl_api.h"
#include "stack/include/bt_hdr.h"

#include <base/logging.h>

/******************************************************************************/
/*            L O C A L    F U N C T I O N     P R O T O T Y P E S            */
/******************************************************************************/
@@ -218,6 +220,10 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
      } else {
        l2cu_release_ccb(p_ccb);
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
        bluetooth::shim::CountCounterMetrics(
            android::bluetooth::CodePathCounterKeyEnum::
                L2CAP_CONNECT_CONFIRM_NEG,
            1);
      }
      break;

@@ -252,6 +258,10 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
          l2cu_release_ccb(p_ccb);
          (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid,
                                              L2CAP_CONN_OTHER_ERROR);
          bluetooth::shim::CountCounterMetrics(
              android::bluetooth::CodePathCounterKeyEnum::
                  L2CAP_NO_COMPATIBLE_CHANNEL_AT_CSM_CLOSED,
              1);
        } else {
          l2cu_send_peer_connect_req(p_ccb);
          alarm_set_on_mloop(p_ccb->l2c_ccb_timer,
@@ -264,6 +274,10 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
    case L2CEVT_SEC_COMP_NEG: /* something is really bad with security */
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_SECURITY_NEG_AT_CSM_CLOSED,
          1);
      break;

    case L2CEVT_L2CAP_CREDIT_BASED_CONNECT_REQ: /* Peer connect request */
@@ -316,6 +330,10 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
    case L2CEVT_TIMEOUT:
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_TIMEOUT_AT_CSM_CLOSED,
          1);
      break;

    case L2CEVT_L2CAP_DATA:      /* Peer data packet rcvd    */
@@ -392,6 +410,10 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,
            l2cu_release_ccb(p_ccb);
            (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid,
                                                L2CAP_CONN_OTHER_ERROR);
            bluetooth::shim::CountCounterMetrics(
                android::bluetooth::CodePathCounterKeyEnum::
                    L2CAP_NO_COMPATIBLE_CHANNEL_AT_W4_SEC,
                1);
          } else {
            alarm_set_on_mloop(p_ccb->l2c_ccb_timer,
                               L2CAP_CHNL_CONNECT_TIMEOUT_MS,
@@ -412,6 +434,10 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, tL2CEVT event,

      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_SECURITY_NEG_AT_W4_SEC,
          1);
      break;

    case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */
@@ -660,6 +686,10 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
          "cid %d, result 0x%04x",
          local_cid, p_ci->l2cap_result);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, p_ci->l2cap_result);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::
              L2CAP_CREDIT_BASED_CONNECT_RSP_NEG,
          1);

      l2cu_release_ccb(p_ccb);
      break;
@@ -670,6 +700,8 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
                   << ", reason=" << loghex(p_ci->l2cap_result);
      l2cu_release_ccb(p_ccb);
      (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
      bluetooth::shim::CountCounterMetrics(
          android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONNECT_RSP_NEG, 1);
      break;

    case L2CEVT_TIMEOUT:
@@ -682,6 +714,10 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
          LOG(WARNING) << __func__ << ": lcid= " << loghex(cid);
          (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid,
                                              L2CAP_CONN_TIMEOUT);
          bluetooth::shim::CountCounterMetrics(
              android::bluetooth::CodePathCounterKeyEnum::
                  L2CAP_TIMEOUT_AT_CONNECT_RSP,
              1);
          l2cu_release_ccb(temp_p_ccb);
        }
        p_lcb->pending_ecoc_conn_cnt = 0;
@@ -692,6 +728,10 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
        LOG(WARNING) << __func__ << ": lcid= " << loghex(p_ccb->local_cid);
        l2cu_release_ccb(p_ccb);
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
        bluetooth::shim::CountCounterMetrics(
            android::bluetooth::CodePathCounterKeyEnum::
                L2CAP_CONN_OTHER_ERROR_AT_CONNECT_RSP,
            1);
      }
      break;

@@ -723,6 +763,10 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, tL2CEVT event,
      if (!l2c_fcr_chk_chan_modes(p_ccb)) {
        l2cu_release_ccb(p_ccb);
        (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR);
        bluetooth::shim::CountCounterMetrics(
            android::bluetooth::CodePathCounterKeyEnum::
                L2CAP_INFO_NO_COMPATIBLE_CHANNEL_AT_RSP,
            1);
      } else {
        /* We have feature info, so now send peer connect request */
        alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS,
@@ -944,6 +988,10 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
            if (p_ccb->connection_initiator == L2CAP_INITIATOR_LOCAL) {
              (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid,
                                                  L2CAP_CFG_FAILED_NO_REASON);
              bluetooth::shim::CountCounterMetrics(
                  android::bluetooth::CodePathCounterKeyEnum::
                      L2CAP_CONFIG_REQ_FAILURE,
                  1);
            }
          }
        }
@@ -1038,6 +1086,9 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, tL2CEVT event, void* p_data) {
        if (p_ccb->connection_initiator == L2CAP_INITIATOR_LOCAL) {
          (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid,
                                              L2CAP_CFG_FAILED_NO_REASON);
          bluetooth::shim::CountCounterMetrics(
              android::bluetooth::CodePathCounterKeyEnum::L2CAP_CONFIG_RSP_NEG,
              1);
        }
      }
      break;