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

Commit 88aaa412 authored by Chris Manton's avatar Chris Manton
Browse files

Move and add stack/acl/acl::power_mode_state_text

Towards loggable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run --host

Change-Id: I2a63399e186f2e25f83b3288d6407f79d5a1e021
parent ac0ad97c
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -211,6 +211,29 @@ enum : uint8_t {
};
typedef uint8_t tBTM_PM_STATE;

inline std::string power_mode_state_text(tBTM_PM_STATE state) {
  std::string s =
      std::string((state & BTM_PM_STORED_MASK) ? "stored:" : "immediate:");
  switch (state & ~BTM_PM_STORED_MASK) {
    case BTM_PM_ST_ACTIVE:
      return s + std::string("active");
    case BTM_PM_ST_HOLD:
      return s + std::string("hold");
    case BTM_PM_ST_SNIFF:
      return s + std::string("sniff");
    case BTM_PM_ST_PARK:
      return s + std::string("park");
    case BTM_PM_ST_UNUSED:
      return s + std::string("WARN:UNUSED");
    case BTM_PM_ST_PENDING:
      return s + std::string("pending");
    case BTM_PM_ST_INVALID:
      return s + std::string("invalid");
    default:
      return s + std::string("UNKNOWN");
  }
}

typedef struct {
  bool chg_ind;
  tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1];
+5 −20
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ const uint8_t

        BTM_PM_GET_MD1,  BTM_PM_GET_MD2,  BTM_PM_GET_COMP};

static const char* mode_to_string(const tBTM_PM_MODE mode);
static void send_sniff_subrating(const tACL_CONN& p_acl, uint16_t max_lat,
                                 uint16_t min_rmt_to, uint16_t min_loc_to) {
  btsnd_hcic_sniff_sub_rate(p_acl.hci_handle, max_lat, min_rmt_to, min_loc_to);
@@ -521,8 +520,8 @@ tBTM_STATUS StackAclBtmPm::btm_pm_snd_md_req(uint8_t pm_id, int link_ind,
  btm_cb.pm_pend_id = pm_id;

  LOG_INFO("switching from %s(0x%x) to %s(0x%x), link_ind: %d",
           mode_to_string(p_cb->state), p_cb->state,
           mode_to_string(md_res.mode), md_res.mode, link_ind);
           power_mode_state_text(p_cb->state).c_str(), p_cb->state,
           power_mode_state_text(md_res.mode).c_str(), md_res.mode, link_ind);

  switch (md_res.mode) {
    case BTM_PM_MD_ACTIVE:
@@ -681,8 +680,9 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle,
  p_cb->state = mode;
  p_cb->interval = interval;

  LOG_INFO("switched from [%s] to [%s].", mode_to_string(old_state),
           mode_to_string(p_cb->state));
  LOG_INFO("Power mode switched from %s[%hhu] to %s[%hhu]",
           power_mode_state_text(old_state).c_str(), old_state,
           power_mode_state_text(p_cb->state).c_str(), p_cb->state);

  if ((p_cb->state == BTM_PM_ST_ACTIVE) || (p_cb->state == BTM_PM_ST_SNIFF)) {
    l2c_OnHciModeChangeSendPendingPackets(bd_addr);
@@ -848,21 +848,6 @@ tBTM_CONTRL_STATE BTM_PM_ReadControllerState(void) {
    return BTM_CONTRL_IDLE;
}

static const char* mode_to_string(const tBTM_PM_MODE mode) {
  switch (mode) {
    case BTM_PM_MD_ACTIVE:
      return "ACTIVE";
    case BTM_PM_MD_SNIFF:
      return "SNIFF";
    case BTM_PM_MD_PARK:
      return "PARK";
    case BTM_PM_MD_HOLD:
      return "HOLD";
    default:
      return "UNKNOWN";
  }
}

void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
                           tHCI_MODE current_mode, uint16_t interval) {
  btm_sco_chk_pend_unpark(status, handle);
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#define BTM_API_TYPES_H

#include <cstdint>
#include <string>

#include "device/include/esco_parameters.h"
#include "internal_include/bt_target.h"