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

Commit fc41a25b authored by Palash Ahuja's avatar Palash Ahuja
Browse files

Revert "Revert "[BluetoothMetrics] This covers the case for Direct LE-AC...""

This reverts commit 5a00b850.

Reason for revert: Adding the fix for the floss build

Change-Id: Ia02811feed9403643dc8d415903bfeea229c0ebb
parent 5a00b850
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <base/base64.h>
#include <base/logging.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/le/enums.pb.h>
#include <include/hardware/bt_av.h>
#include <statslog_bt.h>
#include <unistd.h>
@@ -35,6 +36,9 @@

#include "address_obfuscator.h"
#include "bluetooth/metrics/bluetooth.pb.h"
#include "gd/metrics/metrics_state.h"
#include "gd/hci/address.h"
#include "gd/os/metrics.h"
#include "leaky_bonded_queue.h"
#include "metric_id_allocator.h"
#include "osi/include/osi.h"
@@ -68,6 +72,7 @@ using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
using bluetooth::hci::Address;

static float combine_averages(float avg_a, int64_t ct_a, float avg_b,
                              int64_t ct_b) {
@@ -969,6 +974,19 @@ void LogLeAudioBroadcastSessionReported(int64_t duration_nanos) {
  }
}

void LogLeBluetoothConnectionMetricEventReported(
    const Address& address,
    android::bluetooth::le::LeConnectionOriginType origin_type,
    android::bluetooth::le::LeConnectionType connection_type,
    android::bluetooth::le::LeConnectionState transaction_state,
    std::vector<std::pair<os::ArgumentType, int>>
        argument_list) {
  // Log the events for the State Management
  metrics::MetricsCollector::GetLEConnectionMetricsCollector()
      ->AddStateChangedEvent(address, origin_type, connection_type,
                             transaction_state, argument_list);
}

}  // namespace common

}  // namespace bluetooth
+11 −0
Original line number Diff line number Diff line
@@ -21,13 +21,16 @@
#include <bta/include/bta_api.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/le/enums.pb.h>
#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "gd/os/metrics.h"
#include "types/raw_address.h"
#include "hci/address.h"

namespace bluetooth {

@@ -520,6 +523,14 @@ void LogLeAudioConnectionSessionReported(

void LogLeAudioBroadcastSessionReported(int64_t duration_nanos);

void LogLeBluetoothConnectionMetricEventReported(
    const RawAddress& raw_address,
    android::bluetooth::le::LeConnectionOriginType origin_type,
    android::bluetooth::le::LeConnectionType connection_type,
    android::bluetooth::le::LeConnectionState transaction_state,
    std::vector<std::pair<os::ArgumentType, int>>
        argument_list);

}  // namespace common

}  // namespace bluetooth
+1 −0
Original line number Diff line number Diff line
@@ -426,6 +426,7 @@ cc_test {
        "libbt_callbacks_cxx",
        "libbt_shim_bridge",
        "libbt_shim_ffi",
        "libbt-platform-protos-lite"
    ],
    shared_libs: [
        "libcrypto",
+44 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "hci/le_address_manager.h"
#include "os/alarm.h"
#include "os/handler.h"
#include "os/metrics.h"
#include "os/system_properties.h"
#include "packet/packet_view.h"

@@ -342,6 +343,16 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    AddressWithType remote_address(address, peer_address_type);
    AddressWithType local_address = le_address_manager_->GetInitiatorAddress();
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    auto argument_list = std::vector<std::pair<bluetooth::os::ArgumentType, int>>();
    argument_list.push_back(
        std::make_pair(os::ArgumentType::ACL_STATUS_CODE, static_cast<int>(status)));

    bluetooth::os::LogMetricBluetoothLEConnectionMetricEvent(
        address,
        android::bluetooth::le::LeConnectionOriginType::ORIGIN_NATIVE,
        android::bluetooth::le::LeConnectionType::CONNECTION_TYPE_LE_ACL,
        android::bluetooth::le::LeConnectionState::STATE_LE_ACL_END,
        argument_list);

    if (role == hci::Role::CENTRAL) {
      connectability_state_ = ConnectabilityState::DISARMED;
@@ -485,6 +496,16 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    }
    AddressWithType remote_address(address, remote_address_type);
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    auto argument_list = std::vector<std::pair<bluetooth::os::ArgumentType, int>>();
    argument_list.push_back(
        std::make_pair(os::ArgumentType::ACL_STATUS_CODE, static_cast<int>(status)));

    bluetooth::os::LogMetricBluetoothLEConnectionMetricEvent(
        address,
        android::bluetooth::le::LeConnectionOriginType::ORIGIN_NATIVE,
        android::bluetooth::le::LeConnectionType::CONNECTION_TYPE_LE_ACL,
        android::bluetooth::le::LeConnectionState::STATE_LE_ACL_END,
        argument_list);

    if (role == hci::Role::CENTRAL) {
      connectability_state_ = ConnectabilityState::DISARMED;
@@ -982,6 +1003,15 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  }

  void disarm_connectability() {

    auto argument_list = std::vector<std::pair<os::ArgumentType, int>>();
    bluetooth::os::LogMetricBluetoothLEConnectionMetricEvent(
        Address::kEmpty,
        os::LeConnectionOriginType::ORIGIN_UNSPECIFIED,
        os::LeConnectionType::CONNECTION_TYPE_LE_ACL,
        os::LeConnectionState::STATE_LE_ACL_CANCEL,
        argument_list);

    switch (connectability_state_) {
      case ConnectabilityState::ARMED:
        LOG_INFO("Disarming LE connection state machine with create connection cancel");
@@ -1078,6 +1108,17 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
      create_connection_timeout_alarms_.at(address_with_type).Cancel();
      create_connection_timeout_alarms_.erase(address_with_type);
      auto argument_list = std::vector<std::pair<os::ArgumentType, int>>();
      argument_list.push_back(std::make_pair(
          os::ArgumentType::ACL_STATUS_CODE,
          static_cast<int>(android::bluetooth::hci::StatusEnum::STATUS_CONNECTION_TOUT)));
      bluetooth::os::LogMetricBluetoothLEConnectionMetricEvent(
          address_with_type.GetAddress(),
          android::bluetooth::le::LeConnectionOriginType::ORIGIN_NATIVE,
          android::bluetooth::le::LeConnectionType::CONNECTION_TYPE_LE_ACL,
          android::bluetooth::le::LeConnectionState::STATE_LE_ACL_TIMEOUT,
          argument_list);

      if (background_connections_.find(address_with_type) != background_connections_.end()) {
        direct_connections_.erase(address_with_type);
        disarm_connectability();
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ filegroup {
    name: "BluetoothMetricsSources",
    srcs: [
        "counter_metrics.cc",
        "metrics_state.cc",
        "utils.cc"
    ],
}

@@ -18,5 +20,6 @@ filegroup {
    name: "BluetoothMetricsTestSources",
    srcs: [
        "counter_metrics_unittest.cc",
        "metrics_state_unittest.cc"
    ],
}
Loading