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

Commit 1c3c61bd authored by Chris Manton's avatar Chris Manton
Browse files

Re-log stack/gatt/connection_manager::direct_connect_

Towards loggable code

Bug: 163134718
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink

Change-Id: I574c95f79111f06241f7eef97350b996be315915
parent 2f1e25b4
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -208,9 +208,9 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
  if (bluetooth::shim::is_gd_shim_enabled()) {
    return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address);
  }
  auto it = bgconn_dev.find(address);
  bool in_white_list = false;

  bool in_white_list = false;
  auto it = bgconn_dev.find(address);
  if (it != bgconn_dev.end()) {
    // app already trying to connect to this particular device
    if (it->second.doing_direct_conn.count(app_id)) {
@@ -221,6 +221,8 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) {

    // are we already in the white list ?
    if (anyone_connecting(it)) {
      LOG_WARN("Background connection attempt already in progress app_id=%x",
               app_id);
      in_white_list = true;
    }
  }
@@ -230,6 +232,7 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
  if (!in_white_list) {
    if (!BTM_WhiteListAdd(address)) {
      // if we can't add to white list, turn parameters back to slow.
      LOG_WARN("Unable to add le device to whitelist");
      if (params_changed) BTM_SetLeConnectionModeToSlow();
      return false;
    }
@@ -246,7 +249,7 @@ bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
  return true;
}

bool any_direct_connect_left() {
static bool any_direct_connect_left() {
  for (const auto& tmp : bgconn_dev) {
    if (!tmp.second.doing_direct_conn.empty()) return true;
  }
@@ -254,13 +257,17 @@ bool any_direct_connect_left() {
}

bool direct_connect_remove(uint8_t app_id, const RawAddress& address) {
  VLOG(2) << __func__ << ": "
          << "app_id: " << +app_id << ", address:" << address;
  auto it = bgconn_dev.find(address);
  if (it == bgconn_dev.end()) return false;
  if (it == bgconn_dev.end()) {
    LOG_WARN("Unable to find background connection to remove");
    return false;
  }

  auto app_it = it->second.doing_direct_conn.find(app_id);
  if (app_it == it->second.doing_direct_conn.end()) return false;
  if (app_it == it->second.doing_direct_conn.end()) {
    LOG_WARN("Unable to find direct connection to remove");
    return false;
  }

  // this will free the alarm
  it->second.doing_direct_conn.erase(app_it);
@@ -271,7 +278,9 @@ bool direct_connect_remove(uint8_t app_id, const RawAddress& address) {
    BTM_SetLeConnectionModeToSlow();
  }

  if (anyone_connecting(it)) return true;
  if (anyone_connecting(it)) {
    return true;
  }

  // no more apps interested - remove from whitelist
  BTM_WhiteListRemove(address);