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

Commit 430443d3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Propagate the bluetooth activity attribution hci log flag to the native...

Merge "Propagate the bluetooth activity attribution hci log flag to the native layer." am: f8f6e7b7

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1461222

Change-Id: I68dce9e519a2a7700d8e949dd145739fe5cdac2d
parents f454f452 f8f6e7b7
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
namespace bluetooth {
namespace bluetooth {
namespace common {
namespace common {


bool InitFlags::btaa_hci_log_enabled = false;
bool InitFlags::gd_core_enabled = false;
bool InitFlags::gd_core_enabled = false;
bool InitFlags::gd_advertising_enabled = false;
bool InitFlags::gd_advertising_enabled = false;
bool InitFlags::gd_security_enabled = false;
bool InitFlags::gd_security_enabled = false;
@@ -67,6 +68,7 @@ void InitFlags::Load(const char** flags) {
    ParseBoolFlag(flag_pair, "INIT_gd_controller", &gd_controller_enabled);
    ParseBoolFlag(flag_pair, "INIT_gd_controller", &gd_controller_enabled);
    ParseBoolFlag(flag_pair, "INIT_gatt_robust_caching", &gatt_robust_caching_enabled);
    ParseBoolFlag(flag_pair, "INIT_gatt_robust_caching", &gatt_robust_caching_enabled);
    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    ParseBoolFlag(flag_pair, "INIT_btaa_hci", &btaa_hci_log_enabled);
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
      auto tags = StringSplit(flag_pair[1], ",");
      auto tags = StringSplit(flag_pair[1], ",");
      for (const auto& tag : tags) {
      for (const auto& tag : tags) {
@@ -111,7 +113,7 @@ void InitFlags::Load(const char** flags) {
  LOG_INFO(
  LOG_INFO(
      "Flags loaded: gd_advertising_enabled=%s, gd_security_enabled=%s, gd_acl_enabled=%s, gd_hci_enabled=%s, "
      "Flags loaded: gd_advertising_enabled=%s, gd_security_enabled=%s, gd_acl_enabled=%s, gd_hci_enabled=%s, "
      "gd_controller_enabled=%s, gd_core_enabled=%s, logging_debug_enabled_for_all=%s, "
      "gd_controller_enabled=%s, gd_core_enabled=%s, logging_debug_enabled_for_all=%s, "
      "logging_debug_enabled_tags=%s, logging_debug_disabled_tags=%s",
      "logging_debug_enabled_tags=%s, logging_debug_disabled_tags=%s, btaa_hci_log_enabled=%s",
      ToString(gd_advertising_enabled).c_str(),
      ToString(gd_advertising_enabled).c_str(),
      ToString(gd_security_enabled).c_str(),
      ToString(gd_security_enabled).c_str(),
      ToString(gd_acl_enabled).c_str(),
      ToString(gd_acl_enabled).c_str(),
@@ -120,7 +122,8 @@ void InitFlags::Load(const char** flags) {
      ToString(gd_core_enabled).c_str(),
      ToString(gd_core_enabled).c_str(),
      ToString(logging_debug_enabled_for_all).c_str(),
      ToString(logging_debug_enabled_for_all).c_str(),
      StringJoin(logging_debug_enabled_tags, ",").c_str(),
      StringJoin(logging_debug_enabled_tags, ",").c_str(),
      StringJoin(logging_debug_disabled_tags, ",").c_str());
      StringJoin(logging_debug_disabled_tags, ",").c_str(),
      ToString(btaa_hci_log_enabled).c_str());
}
}


void InitFlags::SetAll(bool value) {
void InitFlags::SetAll(bool value) {
+5 −0
Original line number Original line Diff line number Diff line
@@ -66,6 +66,10 @@ class InitFlags final {
    return logging_debug_enabled_for_all;
    return logging_debug_enabled_for_all;
  }
  }


  static bool BtaaHciLogEnabled() {
    return btaa_hci_log_enabled;
  }

  static void SetAllForTesting();
  static void SetAllForTesting();


 private:
 private:
@@ -80,6 +84,7 @@ class InitFlags final {
  static bool logging_debug_enabled_for_all;
  static bool logging_debug_enabled_for_all;
  // save both log allow list and block list in the map to save hashing time
  // save both log allow list and block list in the map to save hashing time
  static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings;
  static std::unordered_map<std::string, bool> logging_debug_explicit_tag_settings;
  static bool btaa_hci_log_enabled;
};
};


}  // namespace common
}  // namespace common
+12 −0
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ TEST(InitFlagsTest, test_load_core) {
  ASSERT_TRUE(InitFlags::GdCoreEnabled());
  ASSERT_TRUE(InitFlags::GdCoreEnabled());
  ASSERT_TRUE(InitFlags::GdControllerEnabled());
  ASSERT_TRUE(InitFlags::GdControllerEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_FALSE(InitFlags::BtaaHciLogEnabled());
}
}


TEST(InitFlagsTest, test_load_controller) {
TEST(InitFlagsTest, test_load_controller) {
@@ -53,6 +54,7 @@ TEST(InitFlagsTest, test_load_controller) {
  ASSERT_FALSE(InitFlags::GdCoreEnabled());
  ASSERT_FALSE(InitFlags::GdCoreEnabled());
  ASSERT_TRUE(InitFlags::GdControllerEnabled());
  ASSERT_TRUE(InitFlags::GdControllerEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_FALSE(InitFlags::BtaaHciLogEnabled());
}
}


TEST(InitFlagsTest, test_load_hci) {
TEST(InitFlagsTest, test_load_hci) {
@@ -61,6 +63,7 @@ TEST(InitFlagsTest, test_load_hci) {
  ASSERT_FALSE(InitFlags::GdCoreEnabled());
  ASSERT_FALSE(InitFlags::GdCoreEnabled());
  ASSERT_FALSE(InitFlags::GdControllerEnabled());
  ASSERT_FALSE(InitFlags::GdControllerEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_TRUE(InitFlags::GdHciEnabled());
  ASSERT_FALSE(InitFlags::BtaaHciLogEnabled());
}
}


TEST(InitFlagsTest, test_load_gatt_robust_caching) {
TEST(InitFlagsTest, test_load_gatt_robust_caching) {
@@ -109,3 +112,12 @@ TEST(InitFlagsTest, test_debug_logging_multiple_flags) {
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
}
}

TEST(InitFlagsTest, test_load_btaa_hci_log) {
  const char* input[] = {"INIT_btaa_hci=true", nullptr};
  InitFlags::Load(input);
  ASSERT_TRUE(InitFlags::BtaaHciLogEnabled());
  ASSERT_FALSE(InitFlags::GdCoreEnabled());
  ASSERT_FALSE(InitFlags::GdControllerEnabled());
  ASSERT_FALSE(InitFlags::GdHciEnabled());
}
+7 −0
Original line number Original line Diff line number Diff line
@@ -27,10 +27,17 @@
typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t* p_data,
typedef void (*btsnoop_data_cb)(const uint16_t type, const uint8_t* p_data,
                                const size_t len, const uint64_t timestamp_us);
                                const size_t len, const uint64_t timestamp_us);


// Callback invoked for each HCI packet when activity attribution is enabled.
typedef void (*activity_attribution_cb)(const uint16_t type,
                                        const uint8_t* p_data, const size_t len,
                                        const uint64_t timestamp_us);

// This call sets the (one and only) callback that will
// This call sets the (one and only) callback that will
// be invoked once for each HCI packet/event.
// be invoked once for each HCI packet/event.
void btsnoop_mem_set_callback(btsnoop_data_cb cb);
void btsnoop_mem_set_callback(btsnoop_data_cb cb);


void activity_attribution_set_callback(activity_attribution_cb cb);

// This function is invoked every time an HCI packet
// This function is invoked every time an HCI packet
// is sent/received. Packets will be filtered  and then
// is sent/received. Packets will be filtered  and then
// forwarded to the |btsnoop_data_cb|.
// forwarded to the |btsnoop_data_cb|.
+13 −2
Original line number Original line Diff line number Diff line
@@ -18,14 +18,20 @@


#include <base/logging.h>
#include <base/logging.h>


#include "gd/common/init_flags.h"
#include "hci/include/btsnoop_mem.h"
#include "hci/include/btsnoop_mem.h"


static btsnoop_data_cb data_callback = NULL;
static btsnoop_data_cb data_callback = NULL;
static activity_attribution_cb attribution_callback = NULL;


void btsnoop_mem_set_callback(btsnoop_data_cb cb) { data_callback = cb; }
void btsnoop_mem_set_callback(btsnoop_data_cb cb) { data_callback = cb; }


void activity_attribution_set_callback(activity_attribution_cb cb) {
  attribution_callback = cb;
}

void btsnoop_mem_capture(const BT_HDR* packet, uint64_t timestamp_us) {
void btsnoop_mem_capture(const BT_HDR* packet, uint64_t timestamp_us) {
  if (!data_callback) return;
  if (!data_callback && !attribution_callback) return;


  CHECK(packet);
  CHECK(packet);


@@ -53,5 +59,10 @@ void btsnoop_mem_capture(const BT_HDR* packet, uint64_t timestamp_us) {
      break;
      break;
  }
  }


  if (length) (*data_callback)(type, data, length, timestamp_us);
  if (length && data_callback)
    (*data_callback)(type, data, length, timestamp_us);
  if (length && attribution_callback &&
      bluetooth::common::InitFlags::BtaaHciLogEnabled()) {
    (*attribution_callback)(type, data, length, timestamp_us);
  }
}
}