OSDN Git Service

Streamline stack/btm/btm_sco::btm_sco_connected
authorChris Manton <cmanton@google.com>
Wed, 6 Jan 2021 22:32:05 +0000 (14:32 -0800)
committerChris Manton <cmanton@google.com>
Fri, 29 Jan 2021 16:31:39 +0000 (08:31 -0800)
Towards readable and loggable code

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

Change-Id: Ie23d0a1fe9d97f5ea600a5d1e41ed4b3851235a5

stack/btm/btm_sco.cc

index 774a136..89e030f 100644 (file)
@@ -697,30 +697,50 @@ void btm_sco_connected(tHCI_STATUS hci_status, const RawAddress& bda,
       if (hci_status != HCI_SUCCESS) {
         /* Report the error if originator, otherwise remain in Listen mode */
         if (p->is_orig) {
-          /* If role switch is pending, we need try again after role switch is
-           * complete */
-          if (hci_status == HCI_ERR_ROLE_SWITCH_PENDING) {
-            BTM_TRACE_API("Role Change pending for HCI handle 0x%04x",
-                          hci_handle);
-            p->state = SCO_ST_PEND_ROLECHANGE;
-          }
-          /* avoid calling disconnect callback because of sco creation race */
-          else if (hci_status != HCI_ERR_LMP_ERR_TRANS_COLLISION) {
-            p->state = SCO_ST_UNUSED;
-            (*p->p_disc_cb)(xx);
+          LOG_DEBUG("SCO initiating connection failed handle:0x%04x reason:%s",
+                    hci_handle, hci_error_code_text(hci_status).c_str());
+          switch (hci_status) {
+            case HCI_ERR_ROLE_SWITCH_PENDING:
+              /* If role switch is pending, we need try again after role switch
+               * is complete */
+              p->state = SCO_ST_PEND_ROLECHANGE;
+              break;
+            case HCI_ERR_LMP_ERR_TRANS_COLLISION:
+              /* Avoid calling disconnect callback because of sco creation race
+               */
+              break;
+            default: /* Notify client about SCO failure */
+              p->state = SCO_ST_UNUSED;
+              (*p->p_disc_cb)(xx);
           }
+          BTM_LogHistory(
+              kBtmLogTag, bda, "Connection failed",
+              base::StringPrintf(
+                  "locally_initiated reason:%s",
+                  hci_reason_code_text(static_cast<tHCI_REASON>(hci_status))
+                      .c_str()));
         } else {
-          /* Notify the upper layer that incoming sco connection has failed. */
+          LOG_DEBUG("SCO terminating connection failed handle:0x%04x reason:%s",
+                    hci_handle, hci_error_code_text(hci_status).c_str());
           if (p->state == SCO_ST_CONNECTING) {
             p->state = SCO_ST_UNUSED;
             (*p->p_disc_cb)(xx);
           } else
             p->state = SCO_ST_LISTENING;
+          BTM_LogHistory(
+              kBtmLogTag, bda, "Connection failed",
+              base::StringPrintf(
+                  "remote_initiated reason:%s",
+                  hci_reason_code_text(static_cast<tHCI_REASON>(hci_status))
+                      .c_str()));
         }
-
         return;
       }
 
+      BTM_LogHistory(
+          kBtmLogTag, bda, "Connection created",
+          base::StringPrintf("sco_idx:%hu handle:0x%04x ", xx, hci_handle));
+
       if (p->state == SCO_ST_LISTENING) spt = true;
 
       p->state = SCO_ST_CONNECTED;