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

Commit 8ea94495 authored by Chris Manton's avatar Chris Manton
Browse files

dumpsys: Add search_module state

Bug: 281763015
Test: Manual

Change-Id: I320d7ed678028df3014c338a85504a4e231cd4ee
parent a09b2ec5
Loading
Loading
Loading
Loading
+50 −1
Original line number Diff line number Diff line
@@ -21,9 +21,13 @@
 *  This is the main implementation file for the BTA device manager.
 *
 ******************************************************************************/
#include <base/strings/stringprintf.h>
#include <stddef.h>

#include "bt_trace.h"
#include "bta/dm/bta_dm_int.h"
#include "gd/common/circular_buffer.h"
#include "gd/common/strings.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_types.h"

@@ -31,10 +35,38 @@
 * Constants and types
 ****************************************************************************/

namespace {
constexpr size_t kSearchStateHistorySize = 50;
constexpr char kTimeFormatString[] = "%Y-%m-%d %H:%M:%S";

constexpr unsigned MillisPerSecond = 1000;
std::string EpochMillisToString(long long time_ms) {
  time_t time_sec = time_ms / MillisPerSecond;
  struct tm tm;
  localtime_r(&time_sec, &tm);
  std::string s = bluetooth::common::StringFormatTime(kTimeFormatString, tm);
  return base::StringPrintf(
      "%s.%03u", s.c_str(),
      static_cast<unsigned int>(time_ms % MillisPerSecond));
}
}  // namespace

tBTA_DM_CB bta_dm_cb;
tBTA_DM_SEARCH_CB bta_dm_search_cb;
tBTA_DM_DI_CB bta_dm_di_cb;

struct tSEARCH_STATE_HISTORY {
  const tBTA_DM_STATE state;
  const tBTA_DM_EVT event;
  std::string ToString() const {
    return base::StringPrintf("state:%25s event:%s",
                              bta_dm_state_text(state).c_str(),
                              bta_dm_event_text(event).c_str());
  }
};
bluetooth::common::TimestampedCircularBuffer<tSEARCH_STATE_HISTORY>
    search_state_history_(kSearchStateHistorySize);

/*******************************************************************************
 *
 * Function         bta_dm_sm_search_disable
@@ -62,7 +94,10 @@ bool bta_dm_search_sm_execute(BT_HDR_RIGID* p_msg) {
  LOG_INFO("state:%s, event:%s[0x%x]",
           bta_dm_state_text(bta_dm_search_get_state()).c_str(),
           bta_dm_event_text(event).c_str(), event);

  search_state_history_.Push({
      .state = bta_dm_search_get_state(),
      .event = event,
  });
  tBTA_DM_MSG* message = (tBTA_DM_MSG*)p_msg;
  switch (bta_dm_search_get_state()) {
    case BTA_DM_SEARCH_IDLE:
@@ -194,3 +229,17 @@ bool bta_dm_search_sm_execute(BT_HDR_RIGID* p_msg) {
  }
  return true;
}

#define DUMPSYS_TAG "shim::legacy::bta::dm"
void DumpsysBtaDm(int fd) {
  LOG_DUMPSYS_TITLE(fd, DUMPSYS_TAG);
  auto copy = search_state_history_.Pull();
  LOG_DUMPSYS(fd, " last %zu search state transitions", copy.size());
  for (const auto& it : copy) {
    LOG_DUMPSYS(fd, "   %s %s", EpochMillisToString(it.timestamp).c_str(),
                it.entry.ToString().c_str());
  }
  LOG_DUMPSYS(fd, " current bta_dm_search_state:%s",
              bta_dm_state_text(bta_dm_search_get_state()).c_str());
}
#undef DUMPSYS_TAG
+3 −0
Original line number Diff line number Diff line
@@ -1412,4 +1412,7 @@ void BTA_DmBleSubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min,
 *
 ******************************************************************************/
bool BTA_DmCheckLeAudioCapable(const RawAddress& address);

void DumpsysBtaDm(int fd);

#endif /* BTA_API_H */
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@

#include "audio_hal_interface/a2dp_encoding.h"
#include "bta/hh/bta_hh_int.h"  // for HID HACK profile methods
#include "bta/include/bta_api.h"
#include "bta/include/bta_ar_api.h"
#include "bta/include/bta_csis_api.h"
#include "bta/include/bta_has_api.h"
@@ -807,6 +808,7 @@ static void dump(int fd, const char** arguments) {
  bluetooth::bqr::DebugDump(fd);
  PAN_Dumpsys(fd);
  DumpsysHid(fd);
  DumpsysBtaDm(fd);
  bluetooth::shim::Dump(fd, arguments);
}