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

Commit 583d1838 authored by Henri Chataing's avatar Henri Chataing
Browse files

gd/hal/snoop_logger: Make explicit call to DumpSnoozLogToFile

Previously this method was indirectly called from the function
GetDumpsysData, which itself is indirectly called by the module
dumper; this entire chain of call is fragile.

This change makes to method DumpSnoozLogToFile public and calls
it directly from the dumpsys implementation.

Bug: 331817295
Test: m com.android.btservices
Test: manual, validate that snooz files are generated on dumpsys
Flag: EXEMPT, no logical change
Change-Id: I4ae1e6883b847b4e325e1e79a190c7eec0c7c324
parent d8fd433a
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -1214,8 +1214,10 @@ void SnoopLogger::Capture(const HciPacket& immutable_packet, Direction direction
  }
}

void SnoopLogger::DumpSnoozLogToFile(const std::vector<std::string>& data) const {
void SnoopLogger::DumpSnoozLogToFile() {
  std::lock_guard<std::recursive_mutex> lock(file_mutex_);
  std::vector<std::string> data = btsnooz_buffer_.Pull();

  if (btsnoop_mode_ != kBtSnoopLogModeDisabled) {
    log::debug("btsnoop log is enabled, skip dumping btsnooz log");
    return;
@@ -1312,12 +1314,6 @@ void SnoopLogger::Stop() {
  }
}

DumpsysDataFinisher SnoopLogger::GetDumpsysData(
        flatbuffers::FlatBufferBuilder* /* builder */) const {
  DumpSnoozLogToFile(btsnooz_buffer_.Pull());
  return EmptyDumpsysDataFinisher;
}

size_t SnoopLogger::GetMaxPacketsPerFile() {
  // Allow override max packet per file via system property
  auto max_packets_per_file = kDefaultBtSnoopMaxPacketsPerFile;
+3 −2
Original line number Diff line number Diff line
@@ -264,6 +264,9 @@ public:

  void RegisterSocket(SnoopLoggerSocketInterface* socket);

  // Dump the contents of the snooz buffer to a file.
  void DumpSnoozLogToFile();

protected:
  // Packet type length
  static const size_t PACKET_TYPE_LENGTH;
@@ -276,7 +279,6 @@ protected:
  void ListDependencies(ModuleList* list) const override;
  void Start() override;
  void Stop() override;
  DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override;
  std::string ToString() const override { return std::string("SnoopLogger"); }

  SnoopLogger(std::string snoop_log_path, std::string snooz_log_path, size_t max_packets_per_file,
@@ -286,7 +288,6 @@ protected:
              bool snoop_log_persists);
  void CloseCurrentSnoopLogFile();
  void OpenNextSnoopLogFile();
  void DumpSnoozLogToFile(const std::vector<std::string>& data) const;
  // Enable filters according to their sysprops
  void EnableFilters();
  // Disable all filters
+8 −10
Original line number Diff line number Diff line
@@ -120,8 +120,6 @@ public:

  std::string ToString() const override { return std::string("TestSnoopLoggerModule"); }

  void CallGetDumpsysData(flatbuffers::FlatBufferBuilder* builder) { GetDumpsysData(builder); }

  SnoopLoggerSocketThread* GetSocketThread() { return snoop_logger_socket_thread_.get(); }

  static uint32_t GetL2capHeaderSize() { return L2CAP_HEADER_SIZE; }
@@ -264,7 +262,7 @@ TEST_F(SnoopLoggerModuleTest, capture_hci_cmd_btsnooz_test) {

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

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -288,7 +286,7 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_signal_packet_btsnooz_test) {

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

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -312,7 +310,7 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_short_data_packet_btsnooz_test) {

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

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -336,7 +334,7 @@ TEST_F(SnoopLoggerModuleTest, capture_l2cap_long_data_packet_btsnooz_test) {

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

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -359,7 +357,7 @@ TEST_F(SnoopLoggerModuleTest, snoop_log_persists) {

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

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -477,7 +475,7 @@ TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_test) {
  test_registry->InjectTestModule(&SnoopLogger::Factory, snoop_logger);
  snoop_logger->Capture(kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING,
                        SnoopLogger::PacketType::ACL);
  snoop_logger->CallGetDumpsysData(builder_);
  snoop_logger->DumpSnoozLogToFile();

  ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
  ASSERT_EQ(std::filesystem::file_size(temp_snooz_log_),
@@ -500,7 +498,7 @@ TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_regression_test) {
    test_registry->InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kHfpAtNrec0, SnoopLogger::Direction::OUTGOING,
                          SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);
    snoop_logger->DumpSnoozLogToFile();

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
@@ -521,7 +519,7 @@ TEST_F(SnoopLoggerModuleTest, qualcomm_debug_log_regression_test) {
    test_registry->InjectTestModule(&SnoopLogger::Factory, snoop_logger);
    snoop_logger->Capture(kQualcommConnectionRequest, SnoopLogger::Direction::OUTGOING,
                          SnoopLogger::PacketType::ACL);
    snoop_logger->CallGetDumpsysData(builder_);
    snoop_logger->DumpSnoozLogToFile();

    ASSERT_TRUE(std::filesystem::exists(temp_snooz_log_));
    ASSERT_EQ(
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <string>

#include "dumpsys/filter.h"
#include "hal/snoop_logger.h"
#include "hci/acl_manager.h"
#include "hci/controller_interface.h"
#include "main/shim/entry.h"
@@ -137,6 +138,7 @@ void Dumpsys::impl::DumpWithArgsAsync(int fd, const char** /*args*/) const {
  const auto registry = dumpsys_module_.GetModuleRegistry();
  bluetooth::shim::GetController()->Dump(fd);
  bluetooth::shim::GetAclManager()->Dump(fd);
  bluetooth::shim::GetSnoopLogger()->DumpSnoozLogToFile();

  ModuleDumper dumper(fd, *registry, kDumpsysTitle);
  std::string dumpsys_data;