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

Commit 261f360f authored by Andrew Cheng's avatar Andrew Cheng Committed by Andrew Cheng
Browse files

Surface ACL disconnect reasons from native to Java

HCI disconnect commands and events have an accompanying "reason"
parameter comprising of a HCI error code. This can be useful in both
debugging and re-connection logic at the Java level.

This CL grabs the HCI codes from native and passes it up to Java via an
extra parameter to existing ACL connection callbacks.

Tag: #feature
Bug: 177668957
Test: atest net_test_bluetooth # verify no regressions
Test: atest bluetoothtbd_test # verify no regressions
Test: atest bt_headless # verify test still builds
Test: manually disconnect local and remote devices and check logcats
from Java layer for disconnect reasons

Change-Id: Idcb1711345b515c5f60e55430352f5f4ff252d69
parent bec5baf6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,5 +23,5 @@ import android.bluetooth.BluetoothDevice;
 */
oneway interface IBluetoothConnectionCallback {
    void onDeviceConnected(in BluetoothDevice device);
    void onDeviceDisconnected(in BluetoothDevice device);
    void onDeviceDisconnected(in BluetoothDevice device, in int hciReason);
}
+1 −1
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ void invoke_ssp_request_cb(RawAddress bd_addr, bt_bdname_t bd_name,
void invoke_bond_state_changed_cb(bt_status_t status, RawAddress bd_addr,
                                  bt_bond_state_t state);
void invoke_acl_state_changed_cb(bt_status_t status, RawAddress bd_addr,
                                 bt_acl_state_t state);
                                 bt_acl_state_t state, bt_hci_error_code_t hci_reason);
void invoke_thread_evt_cb(bt_cb_thread_evt event);
void invoke_le_test_mode_cb(bt_status_t status, uint16_t count);
void invoke_energy_info_cb(bt_activity_energy_info energy_info,
+5 −4
Original line number Diff line number Diff line
@@ -724,15 +724,16 @@ void invoke_bond_state_changed_cb(bt_status_t status, RawAddress bd_addr,
}

void invoke_acl_state_changed_cb(bt_status_t status, RawAddress bd_addr,
                                 bt_acl_state_t state) {
                                 bt_acl_state_t state, bt_hci_error_code_t hci_reason) {
  do_in_jni_thread(
      FROM_HERE,
      base::BindOnce(
          [](bt_status_t status, RawAddress bd_addr, bt_acl_state_t state) {
          [](bt_status_t status, RawAddress bd_addr, bt_acl_state_t state,
             bt_hci_error_code_t hci_reason) {
            HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, status, &bd_addr,
                      state);
                      state, hci_reason);
          },
          status, bd_addr, state));
          status, bd_addr, state, hci_reason));
}

void invoke_thread_evt_cb(bt_cb_thread_evt event) {
+3 −2
Original line number Diff line number Diff line
@@ -1532,7 +1532,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
      btif_update_remote_version_property(&bd_addr);

      invoke_acl_state_changed_cb(BT_STATUS_SUCCESS, bd_addr,
                                  BT_ACL_STATE_CONNECTED);
                                  BT_ACL_STATE_CONNECTED, HCI_SUCCESS);
      break;

    case BTA_DM_LINK_DOWN_EVT:
@@ -1543,7 +1543,8 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
      BTIF_TRACE_DEBUG(
          "BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
      invoke_acl_state_changed_cb(BT_STATUS_SUCCESS, bd_addr,
                                  BT_ACL_STATE_DISCONNECTED);
                                  BT_ACL_STATE_DISCONNECTED,
                                  static_cast<bt_hci_error_code_t>(btm_get_acl_disc_reason_code()));
      break;

    case BTA_DM_BLE_KEY_EVT:
+6 −1
Original line number Diff line number Diff line
@@ -135,6 +135,10 @@ inline std::string bt_status_text(const bt_status_t& status) {
  }
}

/** Bluetooth HCI Error Codes */
/** Corresponding to [Vol 2] Part D, "Error Codes" of Core_v5.1 specs */
typedef uint8_t bt_hci_error_code_t;

/** Bluetooth PinKey Code */
typedef struct { uint8_t pin[16]; } __attribute__((packed)) bt_pin_code_t;

@@ -423,7 +427,8 @@ typedef void (*bond_state_changed_callback)(bt_status_t status,
/** Bluetooth ACL connection state changed callback */
typedef void (*acl_state_changed_callback)(bt_status_t status,
                                           RawAddress* remote_bd_addr,
                                           bt_acl_state_t state);
                                           bt_acl_state_t state,
                                           bt_hci_error_code_t hci_reason);

/** Bluetooth link quality report callback */
typedef void (*link_quality_report_callback)(
Loading