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

Commit b2bc98c2 authored by Chen Chen's avatar Chen Chen Committed by Automerger Merge Worker
Browse files

Merge "BluetoothMetrics: Log rfcomm failure using counter metrics" am: 07c94756 am: c22683b0

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2029285

Change-Id: I3e52fd36cfdd788a57406f5549f071b6acadcada
parents 2fb5407f c22683b0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -303,6 +303,7 @@ cc_test {
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockHci",
        ":TestMockStackMetrics",
        "rfcomm/port_api.cc",
        "rfcomm/port_rfc.cc",
        "rfcomm/port_utils.cc",
+3 −0
Original line number Diff line number Diff line
@@ -49,3 +49,6 @@ void log_manufacturer_info(const RawAddress& address,
                           const std::string& model,
                           const std::string& hardware_version,
                           const std::string& software_version);

void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key,
                         int64_t value);
+5 −0
Original line number Diff line number Diff line
@@ -67,3 +67,8 @@ void log_manufacturer_info(const RawAddress& address,
      address, source_type, source_name, manufacturer, model, hardware_version,
      software_version);
}

void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key,
                         int64_t value) {
  bluetooth::shim::CountCounterMetrics(key, value);
}
+33 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
 ******************************************************************************/

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

#include <cstdint>
#include <string>
@@ -35,6 +36,7 @@
#include "osi/include/osi.h"  // UNUSED_ATTR
#include "stack/include/bt_hdr.h"
#include "stack/include/sdpdefs.h"
#include "stack/include/stack_metrics_logging.h"
#include "stack/rfcomm/port_int.h"
#include "stack/rfcomm/rfc_int.h"

@@ -165,8 +167,12 @@ void port_start_close(tPORT* p_port) {
  if ((p_mcb == NULL) || (p_port->rfc.state == RFC_STATE_CLOSED)) {
    /* Call management callback function before calling port_release_port() to
     * clear tPort */
    if (p_port->p_mgmt_callback)
    if (p_port->p_mgmt_callback) {
      p_port->p_mgmt_callback(PORT_CLOSED, p_port->handle);
      log_counter_metrics(
          android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CLOSE,
          1);
    }

    port_release_port(p_port);
  } else {
@@ -217,8 +223,10 @@ void PORT_StartCnf(tRFC_MCB* p_mcb, uint16_t result) {

        if (p_port->p_mgmt_callback) {
          p_port->p_mgmt_callback(PORT_START_FAILED, p_port->handle);
          log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                                  RFCOMM_PORT_START_CNF_FAILED,
                              1);
        }

        port_release_port(p_port);
      }
    }
@@ -449,8 +457,12 @@ void PORT_DlcEstablishInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu) {
  if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED))
    (p_port->p_callback)(PORT_EV_CONNECTED, p_port->handle);

  if (p_port->p_mgmt_callback)
  if (p_port->p_mgmt_callback) {
    p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
    log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                            RFCOMM_CONNECTION_SUCCESS_IND,
                        1);
  }

  p_port->state = PORT_STATE_OPENED;
}
@@ -477,6 +489,9 @@ void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu,
  if (result != RFCOMM_SUCCESS) {
    p_port->error = PORT_START_FAILED;
    port_rfc_closed(p_port, PORT_START_FAILED);
    log_counter_metrics(
        android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_FAILED,
        1);
    return;
  }

@@ -489,9 +504,12 @@ void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu,
  if (p_port->p_callback && (p_port->ev_mask & PORT_EV_CONNECTED))
    (p_port->p_callback)(PORT_EV_CONNECTED, p_port->handle);

  if (p_port->p_mgmt_callback)
  if (p_port->p_mgmt_callback) {
    p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);

    log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                            RFCOMM_CONNECTION_SUCCESS_CNF,
                        1);
  }
  p_port->state = PORT_STATE_OPENED;

  /* RPN is required only if we want to tell DTE how the port should be opened
@@ -561,6 +579,8 @@ void PORT_PortNegCnf(tRFC_MCB* p_mcb, uint8_t dlci,
    RFCOMM_DlcReleaseReq(p_mcb, p_port->dlci);

    port_rfc_closed(p_port, PORT_PORT_NEG_FAILED);
    log_counter_metrics(
        android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_NEG_FAILED, 1);
    return;
  }

@@ -698,6 +718,8 @@ void PORT_DlcReleaseInd(tRFC_MCB* p_mcb, uint8_t dlci) {
  tPORT* p_port = port_find_mcb_dlci_port(p_mcb, dlci);
  if (!p_port) return;
  port_rfc_closed(p_port, PORT_CLOSED);
  log_counter_metrics(
      android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_CLOSED, 1);
}

/*******************************************************************************
@@ -718,6 +740,9 @@ void PORT_CloseInd(tRFC_MCB* p_mcb) {
  for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
    if (p_port->rfc.p_mcb == p_mcb) {
      port_rfc_closed(p_port, PORT_PEER_CONNECTION_FAILED);
      log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
                              RFCOMM_PORT_PEER_CONNECTION_FAILED,
                          1);
    }
  }
  rfc_release_multiplexer_channel(p_mcb);
@@ -741,6 +766,9 @@ void Port_TimeOutCloseMux(tRFC_MCB* p_mcb) {
  for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
    if (p_port->rfc.p_mcb == p_mcb) {
      port_rfc_closed(p_port, PORT_PEER_TIMEOUT);
      log_counter_metrics(
          android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_TIMEOUT,
          1);
    }
  }
}
+7 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ struct log_link_layer_connection_event log_link_layer_connection_event;
struct log_smp_pairing_event log_smp_pairing_event;
struct log_sdp_attribute log_sdp_attribute;
struct log_manufacturer_info log_manufacturer_info;
struct log_counter_metrics log_counter_metrics;

}  // namespace stack_metrics_logging
}  // namespace mock
@@ -112,4 +113,10 @@ void log_manufacturer_info(const RawAddress& address,
      software_version);
}

void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key,
                         int64_t value) {
  mock_function_count_map[__func__]++;
  test::mock::stack_metrics_logging::log_counter_metrics(key, value);
}

// END mockcify generation
Loading