From: Chris Manton Date: Wed, 6 Jan 2021 22:32:05 +0000 (-0800) Subject: Streamline stack/btm/btm_sco::btm_sco_connected X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7a36a83db0b52872cdf67e376c575ff5314b7b9a;p=android-x86%2Fsystem-bt.git Streamline stack/btm/btm_sco::btm_sco_connected Towards readable and loggable code Bug: 163134718 Tag: #refactor Test: gd/cert/run Change-Id: Ie23d0a1fe9d97f5ea600a5d1e41ed4b3851235a5 --- diff --git a/stack/btm/btm_sco.cc b/stack/btm/btm_sco.cc index 774a1361e..89e030f98 100644 --- a/stack/btm/btm_sco.cc +++ b/stack/btm/btm_sco.cc @@ -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(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(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;