OSDN Git Service

Re-log stack/gatt/connection_manager::direct_connect_
authorChris Manton <cmanton@google.com>
Thu, 24 Sep 2020 00:30:23 +0000 (17:30 -0700)
committerChris Manton <cmanton@google.com>
Fri, 9 Oct 2020 19:22:32 +0000 (19:22 +0000)
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

stack/gatt/connection_manager.cc

index 37a4108..8490104 100644 (file)
@@ -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);