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

Commit 3cc3e96b authored by Palash Ahuja's avatar Palash Ahuja
Browse files

[BluetoothMetrics] This covers the case for Direct LE-ACL Connection

Success Rate as per go/bluetooth-le-connection-metrics.

Unit Tests:
- Successful
- Failure
- Timeout
- Cancellation

Test: atest bluetooth_test_gd_unit:LEConnectionMetricsRemoteDeviceTest --host
Change-Id: I7b8618c30d5f1e4dc5b9665e056934c2db888271
Merged-In: I7b8618c30d5f1e4dc5b9665e056934c2db888271
parent 06a99616
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@


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


#include "address_obfuscator.h"
#include "address_obfuscator.h"
#include "bluetooth/metrics/bluetooth.pb.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 "leaky_bonded_queue.h"
#include "metric_id_allocator.h"
#include "metric_id_allocator.h"
#include "osi/include/osi.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::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
using bluetooth::hci::Address;


static float combine_averages(float avg_a, int64_t ct_a, float avg_b,
static float combine_averages(float avg_a, int64_t ct_a, float avg_b,
                              int64_t ct_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 common


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


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


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


namespace bluetooth {
namespace bluetooth {


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


void LogLeAudioBroadcastSessionReported(int64_t duration_nanos);
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 common


}  // namespace bluetooth
}  // namespace bluetooth
+1 −0
Original line number Original line Diff line number Diff line
@@ -426,6 +426,7 @@ cc_test {
        "libbt_callbacks_cxx",
        "libbt_callbacks_cxx",
        "libbt_shim_bridge",
        "libbt_shim_bridge",
        "libbt_shim_ffi",
        "libbt_shim_ffi",
        "libbt-platform-protos-lite"
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libcrypto",
        "libcrypto",
+44 −3
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@
#include "hci/le_address_manager.h"
#include "hci/le_address_manager.h"
#include "os/alarm.h"
#include "os/alarm.h"
#include "os/handler.h"
#include "os/handler.h"
#include "os/metrics.h"
#include "os/system_properties.h"
#include "os/system_properties.h"
#include "packet/packet_view.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 remote_address(address, peer_address_type);
    AddressWithType local_address = le_address_manager_->GetInitiatorAddress();
    AddressWithType local_address = le_address_manager_->GetInitiatorAddress();
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    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) {
    if (role == hci::Role::CENTRAL) {
      connectability_state_ = ConnectabilityState::DISARMED;
      connectability_state_ = ConnectabilityState::DISARMED;
@@ -485,6 +496,16 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    }
    }
    AddressWithType remote_address(address, remote_address_type);
    AddressWithType remote_address(address, remote_address_type);
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    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) {
    if (role == hci::Role::CENTRAL) {
      connectability_state_ = ConnectabilityState::DISARMED;
      connectability_state_ = ConnectabilityState::DISARMED;
@@ -982,6 +1003,15 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  }
  }


  void disarm_connectability() {
  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_) {
    switch (connectability_state_) {
      case ConnectabilityState::ARMED:
      case ConnectabilityState::ARMED:
        LOG_INFO("Disarming LE connection state machine with create connection cancel");
        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()) {
    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_.at(address_with_type).Cancel();
      create_connection_timeout_alarms_.erase(address_with_type);
      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()) {
      if (background_connections_.find(address_with_type) != background_connections_.end()) {
        direct_connections_.erase(address_with_type);
        direct_connections_.erase(address_with_type);
        disarm_connectability();
        disarm_connectability();
+3 −0
Original line number Original line Diff line number Diff line
@@ -11,6 +11,8 @@ filegroup {
    name: "BluetoothMetricsSources",
    name: "BluetoothMetricsSources",
    srcs: [
    srcs: [
        "counter_metrics.cc",
        "counter_metrics.cc",
        "metrics_state.cc",
        "utils.cc"
    ],
    ],
}
}


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