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

Commit 7d46c4fb authored by eric_kuang.rs's avatar eric_kuang.rs
Browse files

Insert new device to database by rssi with property.

If a BR/EDR hid device without name advertisement is found for the first inquiry,
it may be undiscovered sometimes when current BT device number exceeds the capacity of BTM_INQ_DB_SIZE.

Change-Id: Ie5576f715185a53ba7fe34d46b539d3635789707
Test: Manual test
Bug: 278502490
parent aaf77389
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -58,6 +58,10 @@
namespace {
constexpr char kBtmLogTag[] = "SCAN";

struct {
  bool inq_by_rssi{false};
} internal_;

void btm_log_history_scan_mode(uint8_t scan_mode) {
  static uint8_t scan_mode_cached_ = 0xff;
  if (scan_mode_cached_ == scan_mode) return;
@@ -129,6 +133,10 @@ using bluetooth::Uuid;
#define PROPERTY_INQ_SCAN_WINDOW "bluetooth.core.classic.inq_scan_window"
#endif

#ifndef PROPERTY_INQ_BY_RSSI
#define PROPERTY_INQ_BY_RSSI "persist.bluetooth.inq_by_rssi"
#endif

#define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10

/******************************************************************************/
@@ -959,6 +967,7 @@ void btm_inq_db_init(void) {
  btm_cb.btm_inq_vars.remote_name_timer =
      alarm_new("btm_inq.remote_name_timer");
  btm_cb.btm_inq_vars.no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
  internal_.inq_by_rssi = osi_property_get_bool(PROPERTY_INQ_BY_RSSI, false);
}

void btm_inq_db_free(void) {
@@ -1150,6 +1159,7 @@ tINQ_DB_ENT* btm_inq_db_find(const RawAddress& p_bda) {
tINQ_DB_ENT* btm_inq_db_new(const RawAddress& p_bda) {
  uint16_t xx;
  uint64_t ot = UINT64_MAX;
  int8_t i_rssi = 0;

  std::lock_guard<std::mutex> lock(inq_db_lock_);
  tINQ_DB_ENT* p_ent = inq_db_;
@@ -1164,11 +1174,18 @@ tINQ_DB_ENT* btm_inq_db_new(const RawAddress& p_bda) {
      return (p_ent);
    }

    if (internal_.inq_by_rssi) {
      if (p_ent->inq_info.results.rssi < i_rssi) {
        p_old = p_ent;
        i_rssi = p_ent->inq_info.results.rssi;
      }
    } else {
      if (p_ent->time_of_resp < ot) {
        p_old = p_ent;
        ot = p_ent->time_of_resp;
      }
    }
  }

  /* If here, no free entry found. Return the oldest. */