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

Commit 56cbc998 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add Qualcomm 3804 debug logging with base 64 format to btsnooz log when...

Merge "Add Qualcomm 3804 debug logging with base 64 format to btsnooz log when filtered is enabled." am: df45f778 am: 08238aa0 am: 40bf0cde

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



Change-Id: I3d2d41c818058358bca3cf278018db63fb01920b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 64e847ca 40bf0cde
Loading
Loading
Loading
Loading
+32 −2
Original line number Original line Diff line number Diff line
@@ -120,12 +120,16 @@ void delete_old_btsnooz_files(const std::string& log_path, const std::chrono::mi
  }
  }
}
}


size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::PacketType type) {
size_t get_btsnooz_packet_length_to_write(
    const HciPacket& packet, SnoopLogger::PacketType type, bool qualcomm_debug_log_enabled) {
  static const size_t kAclHeaderSize = 4;
  static const size_t kAclHeaderSize = 4;
  static const size_t kL2capHeaderSize = 4;
  static const size_t kL2capHeaderSize = 4;
  static const size_t kL2capCidOffset = (kAclHeaderSize + 2);
  static const size_t kL2capCidOffset = (kAclHeaderSize + 2);
  static const uint16_t kL2capSignalingCid = 0x0001;
  static const uint16_t kL2capSignalingCid = 0x0001;


  static const size_t kHciAclHandleOffset = 0;
  static const uint16_t kQualcommDebugLogHandle = 0xedc;

  // Maximum amount of ACL data to log.
  // Maximum amount of ACL data to log.
  // Enough for an RFCOMM frame up to the frame check;
  // Enough for an RFCOMM frame up to the frame check;
  // not enough for a HID report or audio data.
  // not enough for a HID report or audio data.
@@ -147,11 +151,19 @@ size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::
        uint16_t l2cap_cid =
        uint16_t l2cap_cid =
            static_cast<uint16_t>(packet[kL2capCidOffset]) |
            static_cast<uint16_t>(packet[kL2capCidOffset]) |
            static_cast<uint16_t>((static_cast<uint16_t>(packet[kL2capCidOffset + 1]) << static_cast<uint16_t>(8)));
            static_cast<uint16_t>((static_cast<uint16_t>(packet[kL2capCidOffset + 1]) << static_cast<uint16_t>(8)));
        uint16_t hci_acl_packet_handle = static_cast<uint16_t>(packet[kHciAclHandleOffset]) |
                                         static_cast<uint16_t>(
                                             (static_cast<uint16_t>(packet[kHciAclHandleOffset + 1])
                                              << static_cast<uint16_t>(8)));
        hci_acl_packet_handle &= 0x0fff;

        if (l2cap_cid == kL2capSignalingCid) {
        if (l2cap_cid == kL2capSignalingCid) {
          // For the signaling CID, take the full packet.
          // For the signaling CID, take the full packet.
          // That way, the PSM setup is captured, allowing decoding of PSMs down
          // That way, the PSM setup is captured, allowing decoding of PSMs down
          // the road.
          // the road.
          return packet.size();
          return packet.size();
        } else if (qualcomm_debug_log_enabled && hci_acl_packet_handle == kQualcommDebugLogHandle) {
          return packet.size();
        } else {
        } else {
          // Otherwise, return as much as we reasonably can
          // Otherwise, return as much as we reasonably can
          len_hci_acl = kMaxBtsnoozAclSize;
          len_hci_acl = kMaxBtsnoozAclSize;
@@ -175,11 +187,13 @@ size_t get_btsnooz_packet_length_to_write(const HciPacket& packet, SnoopLogger::
const std::string SnoopLogger::kBtSnoopLogModeDisabled = "disabled";
const std::string SnoopLogger::kBtSnoopLogModeDisabled = "disabled";
const std::string SnoopLogger::kBtSnoopLogModeFiltered = "filtered";
const std::string SnoopLogger::kBtSnoopLogModeFiltered = "filtered";
const std::string SnoopLogger::kBtSnoopLogModeFull = "full";
const std::string SnoopLogger::kBtSnoopLogModeFull = "full";
const std::string SnoopLogger::kSoCManufacturerQualcomm = "Qualcomm";


const std::string SnoopLogger::kBtSnoopMaxPacketsPerFileProperty = "persist.bluetooth.btsnoopsize";
const std::string SnoopLogger::kBtSnoopMaxPacketsPerFileProperty = "persist.bluetooth.btsnoopsize";
const std::string SnoopLogger::kIsDebuggableProperty = "ro.debuggable";
const std::string SnoopLogger::kIsDebuggableProperty = "ro.debuggable";
const std::string SnoopLogger::kBtSnoopLogModeProperty = "persist.bluetooth.btsnooplogmode";
const std::string SnoopLogger::kBtSnoopLogModeProperty = "persist.bluetooth.btsnooplogmode";
const std::string SnoopLogger::kBtSnoopDefaultLogModeProperty = "persist.bluetooth.btsnoopdefaultmode";
const std::string SnoopLogger::kBtSnoopDefaultLogModeProperty = "persist.bluetooth.btsnoopdefaultmode";
const std::string SnoopLogger::kSoCManufacturerProperty = "ro.soc.manufacturer";


SnoopLogger::SnoopLogger(
SnoopLogger::SnoopLogger(
    std::string snoop_log_path,
    std::string snoop_log_path,
@@ -187,12 +201,14 @@ SnoopLogger::SnoopLogger(
    size_t max_packets_per_file,
    size_t max_packets_per_file,
    size_t max_packets_per_buffer,
    size_t max_packets_per_buffer,
    const std::string& btsnoop_mode,
    const std::string& btsnoop_mode,
    bool qualcomm_debug_log_enabled,
    const std::chrono::milliseconds snooz_log_life_time,
    const std::chrono::milliseconds snooz_log_life_time,
    const std::chrono::milliseconds snooz_log_delete_alarm_interval)
    const std::chrono::milliseconds snooz_log_delete_alarm_interval)
    : snoop_log_path_(std::move(snoop_log_path)),
    : snoop_log_path_(std::move(snoop_log_path)),
      snooz_log_path_(std::move(snooz_log_path)),
      snooz_log_path_(std::move(snooz_log_path)),
      max_packets_per_file_(max_packets_per_file),
      max_packets_per_file_(max_packets_per_file),
      btsnooz_buffer_(max_packets_per_buffer),
      btsnooz_buffer_(max_packets_per_buffer),
      qualcomm_debug_log_enabled_(qualcomm_debug_log_enabled),
      snooz_log_life_time_(snooz_log_life_time),
      snooz_log_life_time_(snooz_log_life_time),
      snooz_log_delete_alarm_interval_(snooz_log_delete_alarm_interval) {
      snooz_log_delete_alarm_interval_(snooz_log_delete_alarm_interval) {
  if (false && btsnoop_mode == kBtSnoopLogModeFiltered) {
  if (false && btsnoop_mode == kBtSnoopLogModeFiltered) {
@@ -298,7 +314,8 @@ void SnoopLogger::Capture(const HciPacket& packet, Direction direction, PacketTy
    if (!is_enabled_) {
    if (!is_enabled_) {
      // btsnoop disabled, log in-memory btsnooz log only
      // btsnoop disabled, log in-memory btsnooz log only
      std::stringstream ss;
      std::stringstream ss;
      size_t included_length = get_btsnooz_packet_length_to_write(packet, type);
      size_t included_length =
          get_btsnooz_packet_length_to_write(packet, type, qualcomm_debug_log_enabled_);
      header.length_captured = htonl(included_length + /* type byte */ 1);
      header.length_captured = htonl(included_length + /* type byte */ 1);
      if (!ss.write(reinterpret_cast<const char*>(&header), sizeof(PacketHeaderType))) {
      if (!ss.write(reinterpret_cast<const char*>(&header), sizeof(PacketHeaderType))) {
        LOG_ERROR("Failed to write packet header for btsnooz, error: \"%s\"", strerror(errno));
        LOG_ERROR("Failed to write packet header for btsnooz, error: \"%s\"", strerror(errno));
@@ -450,6 +467,18 @@ std::string SnoopLogger::GetBtSnoopMode() {
  return btsnoop_mode;
  return btsnoop_mode;
}
}


bool SnoopLogger::IsQualcommDebugLogEnabled() {
  // Check system prop if the soc manufacturer is Qualcomm
  bool qualcomm_debug_log_enabled = false;
  {
    auto soc_manufacturer_prop = os::GetSystemProperty(kSoCManufacturerProperty);
    qualcomm_debug_log_enabled =
        soc_manufacturer_prop.has_value() &&
        common::StringTrim(soc_manufacturer_prop.value()) == kSoCManufacturerQualcomm;
  }
  return qualcomm_debug_log_enabled;
}

const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() {
const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() {
  return new SnoopLogger(
  return new SnoopLogger(
      os::ParameterProvider::SnoopLogFilePath(),
      os::ParameterProvider::SnoopLogFilePath(),
@@ -457,6 +486,7 @@ const ModuleFactory SnoopLogger::Factory = ModuleFactory([]() {
      GetMaxPacketsPerFile(),
      GetMaxPacketsPerFile(),
      GetMaxPacketsPerBuffer(),
      GetMaxPacketsPerBuffer(),
      GetBtSnoopMode(),
      GetBtSnoopMode(),
      IsQualcommDebugLogEnabled(),
      kBtSnoozLogLifeTime,
      kBtSnoozLogLifeTime,
      kBtSnoozLogDeleteRepeatingAlarmInterval);
      kBtSnoozLogDeleteRepeatingAlarmInterval);
});
});
+8 −0
Original line number Original line Diff line number Diff line
@@ -36,11 +36,13 @@ class SnoopLogger : public ::bluetooth::Module {
  static const std::string kBtSnoopLogModeDisabled;
  static const std::string kBtSnoopLogModeDisabled;
  static const std::string kBtSnoopLogModeFiltered;
  static const std::string kBtSnoopLogModeFiltered;
  static const std::string kBtSnoopLogModeFull;
  static const std::string kBtSnoopLogModeFull;
  static const std::string kSoCManufacturerQualcomm;


  static const std::string kBtSnoopMaxPacketsPerFileProperty;
  static const std::string kBtSnoopMaxPacketsPerFileProperty;
  static const std::string kIsDebuggableProperty;
  static const std::string kIsDebuggableProperty;
  static const std::string kBtSnoopLogModeProperty;
  static const std::string kBtSnoopLogModeProperty;
  static const std::string kBtSnoopDefaultLogModeProperty;
  static const std::string kBtSnoopDefaultLogModeProperty;
  static const std::string kSoCManufacturerProperty;


  // Put in header for test
  // Put in header for test
  struct PacketHeaderType {
  struct PacketHeaderType {
@@ -69,6 +71,10 @@ class SnoopLogger : public ::bluetooth::Module {
  // Changes to this values is only effective after restarting Bluetooth
  // Changes to this values is only effective after restarting Bluetooth
  static std::string GetBtSnoopMode();
  static std::string GetBtSnoopMode();


  // Returns whether the soc manufacturer is Qualcomm
  // Changes to this value is only effective after restarting Bluetooth
  static bool IsQualcommDebugLogEnabled();

  // Has to be defined from 1 to 4 per btsnoop format
  // Has to be defined from 1 to 4 per btsnoop format
  enum PacketType {
  enum PacketType {
    CMD = 1,
    CMD = 1,
@@ -101,6 +107,7 @@ class SnoopLogger : public ::bluetooth::Module {
      size_t max_packets_per_file,
      size_t max_packets_per_file,
      size_t max_packets_per_buffer,
      size_t max_packets_per_buffer,
      const std::string& btsnoop_mode,
      const std::string& btsnoop_mode,
      bool qualcomm_debug_log_enabled,
      const std::chrono::milliseconds snooz_log_life_time,
      const std::chrono::milliseconds snooz_log_life_time,
      const std::chrono::milliseconds snooz_log_delete_alarm_interval);
      const std::chrono::milliseconds snooz_log_delete_alarm_interval);
  void CloseCurrentSnoopLogFile();
  void CloseCurrentSnoopLogFile();
@@ -115,6 +122,7 @@ class SnoopLogger : public ::bluetooth::Module {
  bool is_filtered_ = false;
  bool is_filtered_ = false;
  size_t max_packets_per_file_;
  size_t max_packets_per_file_;
  common::CircularBuffer<std::string> btsnooz_buffer_;
  common::CircularBuffer<std::string> btsnooz_buffer_;
  bool qualcomm_debug_log_enabled_ = false;
  size_t packet_counter_ = 0;
  size_t packet_counter_ = 0;
  mutable std::recursive_mutex file_mutex_;
  mutable std::recursive_mutex file_mutex_;
  std::unique_ptr<os::RepeatingAlarm> alarm_;
  std::unique_ptr<os::RepeatingAlarm> alarm_;
+185 −47
Original line number Original line Diff line number Diff line
@@ -47,6 +47,10 @@ std::vector<uint8_t> kAvdtpSuspend = {0x02, 0x02, 0x00, 0x07, 0x00, 0x03, 0x00,
std::vector<uint8_t> kHfpAtNrec0 = {0x02, 0x02, 0x20, 0x13, 0x00, 0x0f, 0x00, 0x41, 0x00, 0x09, 0xff, 0x15,
std::vector<uint8_t> kHfpAtNrec0 = {0x02, 0x02, 0x20, 0x13, 0x00, 0x0f, 0x00, 0x41, 0x00, 0x09, 0xff, 0x15,
                                    0x01, 0x41, 0x54, 0x2b, 0x4e, 0x52, 0x45, 0x43, 0x3d, 0x30, 0x0d, 0x5c};
                                    0x01, 0x41, 0x54, 0x2b, 0x4e, 0x52, 0x45, 0x43, 0x3d, 0x30, 0x0d, 0x5c};


std::vector<uint8_t> kQualcommConnectionRequest = {0xdc, 0x2e, 0x54, 0x00, 0x50, 0x00, 0xff,
                                                   0x00, 0x00, 0x0a, 0x0f, 0x09, 0x01, 0x00,
                                                   0x5c, 0x93, 0x01, 0x00, 0x42, 0x00};

}  // namespace
}  // namespace


using bluetooth::TestModuleRegistry;
using bluetooth::TestModuleRegistry;
@@ -60,13 +64,15 @@ class TestSnoopLoggerModule : public SnoopLogger {
      std::string snoop_log_path,
      std::string snoop_log_path,
      std::string snooz_log_path,
      std::string snooz_log_path,
      size_t max_packets_per_file,
      size_t max_packets_per_file,
      const std::string& btsnoop_mode)
      const std::string& btsnoop_mode,
      bool qualcomm_debug_log_enabled)
      : SnoopLogger(
      : SnoopLogger(
            std::move(snoop_log_path),
            std::move(snoop_log_path),
            std::move(snooz_log_path),
            std::move(snooz_log_path),
            max_packets_per_file,
            max_packets_per_file,
            SnoopLogger::GetMaxPacketsPerBuffer(),
            SnoopLogger::GetMaxPacketsPerBuffer(),
            btsnoop_mode,
            btsnoop_mode,
            qualcomm_debug_log_enabled,
            20ms,
            20ms,
            5ms) {}
            5ms) {}


@@ -128,10 +134,14 @@ class SnoopLoggerModuleTest : public Test {


TEST_F(SnoopLoggerModuleTest, empty_snoop_log_test) {
TEST_F(SnoopLoggerModuleTest, empty_snoop_log_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeFull,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  test_registry.StopAll();
  test_registry.StopAll();


  // Verify states after test
  // Verify states after test
@@ -142,10 +152,14 @@ TEST_F(SnoopLoggerModuleTest, empty_snoop_log_test) {


TEST_F(SnoopLoggerModuleTest, disable_snoop_log_test) {
TEST_F(SnoopLoggerModuleTest, disable_snoop_log_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  test_registry.StopAll();
  test_registry.StopAll();


  // Verify states after test
  // Verify states after test
@@ -156,12 +170,17 @@ TEST_F(SnoopLoggerModuleTest, disable_snoop_log_test) {


TEST_F(SnoopLoggerModuleTest, capture_one_packet_test) {
TEST_F(SnoopLoggerModuleTest, capture_one_packet_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeFull,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_logger->Capture(
      kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);


  test_registry.StopAll();
  test_registry.StopAll();


@@ -175,13 +194,18 @@ TEST_F(SnoopLoggerModuleTest, capture_one_packet_test) {


TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {
TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_logger->Capture(
  snoop_looger->CallGetDumpsysData(builder_);
      kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  snoop_logger->CallGetDumpsysData(builder_);


  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
  ASSERT_EQ(
@@ -198,13 +222,18 @@ TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {


TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {
TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  snoop_looger->Capture(kSdpConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->Capture(
  snoop_looger->CallGetDumpsysData(builder_);
      kSdpConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);


  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
  ASSERT_EQ(
@@ -221,13 +250,18 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {


TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {
TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  snoop_looger->Capture(kAvdtpSuspend, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->Capture(
  snoop_looger->CallGetDumpsysData(builder_);
      kAvdtpSuspend, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);


  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
  ASSERT_EQ(
@@ -244,13 +278,18 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {


TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {
TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  snoop_looger->Capture(kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->Capture(
  snoop_looger->CallGetDumpsysData(builder_);
      kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);


  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
  ASSERT_EQ(
@@ -267,10 +306,14 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {


TEST_F(SnoopLoggerModuleTest, delete_old_snooz_log_files) {
TEST_F(SnoopLoggerModuleTest, delete_old_snooz_log_files) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeDisabled);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  std::filesystem::create_directories(temp_snooz_log_);
  std::filesystem::create_directories(temp_snooz_log_);


@@ -285,11 +328,16 @@ TEST_F(SnoopLoggerModuleTest, delete_old_snooz_log_files) {
TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {
TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {
  // Start once
  // Start once
  {
  {
    auto* snoop_looger = new TestSnoopLoggerModule(
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
        temp_snoop_log_.string(),
        temp_snooz_log_.string(),
        10,
        SnoopLogger::kBtSnoopLogModeFull,
        false);
    TestModuleRegistry test_registry;
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(
        kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.StopAll();
    test_registry.StopAll();
  }
  }


@@ -302,12 +350,18 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {


  // Start again
  // Start again
  {
  {
    auto* snoop_looger = new TestSnoopLoggerModule(
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
        temp_snoop_log_.string(),
        temp_snooz_log_.string(),
        10,
        SnoopLogger::kBtSnoopLogModeFull,
        false);
    TestModuleRegistry test_registry;
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
        kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(
        kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    test_registry.StopAll();
    test_registry.StopAll();
  }
  }


@@ -324,13 +378,18 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_at_new_session_test) {


TEST_F(SnoopLoggerModuleTest, rotate_file_after_full_test) {
TEST_F(SnoopLoggerModuleTest, rotate_file_after_full_test) {
  // Actual test
  // Actual test
  auto* snoop_looger = new TestSnoopLoggerModule(
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(), temp_snooz_log_.string(), 10, SnoopLogger::kBtSnoopLogModeFull);
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeFull,
      false);
  TestModuleRegistry test_registry;
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_looger);
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);


  for (int i = 0; i < 11; i++) {
  for (int i = 0; i < 11; i++) {
    snoop_looger->Capture(kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
    snoop_logger->Capture(
        kInformationRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
  }
  }


  test_registry.StopAll();
  test_registry.StopAll();
@@ -346,4 +405,83 @@ TEST_F(SnoopLoggerModuleTest, rotate_file_after_full_test) {
      sizeof(SnoopLogger::FileHeaderType) + (sizeof(SnoopLogger::PacketHeaderType) + kInformationRequest.size()) * 10);
      sizeof(SnoopLogger::FileHeaderType) + (sizeof(SnoopLogger::PacketHeaderType) + kInformationRequest.size()) * 10);
}
}


TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_test) {
  auto* snoop_logger = new TestSnoopLoggerModule(
      temp_snoop_log_.string(),
      temp_snooz_log_.string(),
      10,
      SnoopLogger::kBtSnoopLogModeDisabled,
      true);
  TestModuleRegistry test_registry;
  test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  snoop_logger->Capture(
      kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(
      std::filesystem::file_size(temp_snooz_log_),
      sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) +
          kQualcommConnectionRequest.size());

  test_registry.StopAll();

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));
}

TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_regression_test) {
  {
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(),
        temp_snooz_log_.string(),
        10,
        SnoopLogger::kBtSnoopLogModeDisabled,
        true);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(
        kHfpAtNrec0, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
        std::filesystem::file_size(temp_snooz_log_),
        sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) + 14);
    test_registry.StopAll();
  }

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));

  {
    auto* snoop_logger = new TestSnoopLoggerModule(
        temp_snoop_log_.string(),
        temp_snooz_log_.string(),
        10,
        SnoopLogger::kBtSnoopLogModeDisabled,
        false);
    TestModuleRegistry test_registry;
    test_registry.InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(
        kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
        std::filesystem::file_size(temp_snooz_log_),
        sizeof(SnoopLogger::FileHeaderType) + sizeof(SnoopLogger::PacketHeaderType) + 14);
    test_registry.StopAll();
  }

  // Verify states after test
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_));
  ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_last_));
  ASSERT_FALSE(std::filesystem::exists(temp_snooz_log_));
}

}  // namespace testing
}  // namespace testing