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

Commit cb75ebfc authored by Chen Chen's avatar Chen Chen
Browse files

BluetoothMetrics: Upload Bluetooth disconnection reason to Bluetooth metrics

Bug: 230027913
Test: Build
Change-Id: I55447ce7cf0d5faccb59c30fb0c31f186f4c47ab
(cherry picked from commit 0c81d4b7)
Merged-In: I55447ce7cf0d5faccb59c30fb0c31f186f4c47ab
parent 6206f57b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include "hci/acl_manager/event_checkers.h"
#include "hci/acl_manager/round_robin_scheduler.h"
#include "hci/controller.h"
#include "os/metrics.h"
#include "security/security_manager_listener.h"
#include "security/security_module.h"

@@ -209,6 +210,14 @@ struct classic_impl : public security::ISecurityManagerListener {
      }
      return kIllegalConnectionHandle;
    }
    Address get_address(uint16_t handle) const {
      std::unique_lock<std::mutex> lock(acl_connections_guard_);
      auto connection = acl_connections_.find(handle);
      if (connection == acl_connections_.end()) {
        return Address::kEmpty;
      }
      return connection->second.address_with_type_.GetAddress();
    }
    bool is_classic_link_already_connected(const Address& address) const {
      std::unique_lock<std::mutex> lock(acl_connections_guard_);
      for (const auto& connection : acl_connections_) {
@@ -411,6 +420,8 @@ struct classic_impl : public security::ISecurityManagerListener {
  static constexpr bool kRemoveConnectionAfterwards = true;
  void on_classic_disconnect(uint16_t handle, ErrorCode reason) {
    bool event_also_routes_to_other_receivers = connections.crash_on_unknown_handle_;
    bluetooth::os::LogMetricBluetoothDisconnectionReasonReported(
        static_cast<uint32_t>(reason), connections.get_address(handle), handle);
    connections.crash_on_unknown_handle_ = false;
    connections.execute(
        handle,
+18 −0
Original line number Diff line number Diff line
@@ -445,6 +445,24 @@ void LogMetricBluetoothLocalVersions(
  }
}
  
void LogMetricBluetoothDisconnectionReasonReported(
    uint32_t reason, const Address& address, uint32_t connection_handle) {
  int metric_id = 0;
  if (!address.IsEmpty()) {
    metric_id = MetricIdManager::GetInstance().AllocateId(address);
  }
  int ret = stats_write(BLUETOOTH_DISCONNECTION_REASON_REPORTED, reason, metric_id, connection_handle);
  if (ret < 0) {
    LOG_WARN(
        "Failed for LogMetricBluetoothDisconnectionReasonReported, "
        "reason %d, metric_id %d, connection_handle %d, error %d",
        reason,
        metric_id,
        connection_handle,
        ret);
  }
}

void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {
  int ret = stats_write(BLUETOOTH_CODE_PATH_COUNTER, key, count);
  if (ret < 0) {
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ void LogMetricBluetoothLocalVersions(
    uint8_t hci_version,
    uint32_t hci_reversion) {}

void LogMetricBluetoothDisconnectionReasonReported(
    uint32_t reason, const Address& address, uint32_t connection_handle) {}

void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {}
}  // namespace os
}  // namespace bluetooth
+3 −0
Original line number Diff line number Diff line
@@ -110,6 +110,9 @@ void LogMetricBluetoothLocalVersions(
    uint8_t hci_version,
    uint32_t hci_revision) {}

void LogMetricBluetoothDisconnectionReasonReported(
    uint32_t reason, const Address& address, uint32_t connection_handle) {}

void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count) {}

}  // namespace os
+3 −0
Original line number Diff line number Diff line
@@ -272,6 +272,9 @@ void LogMetricBluetoothLocalVersions(
    uint8_t hci_version,
    uint32_t hci_revision);

void LogMetricBluetoothDisconnectionReasonReported(
    uint32_t reason, const hci::Address& address, uint32_t connection_handle);

void LogMetricBluetoothCodePathCounterMetrics(int32_t key, int64_t count);
}  // namespace os