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

Commit ec6f8bf8 authored by Ugo Yu's avatar Ugo Yu
Browse files

Fix bond list mismatch between Java and native

When a paired device is diconnected while authenticating, do not report
bond state change to Java since the stack does not remove the device in
this situation.

Bug: 142842685
Test: Manual
Change-Id: I308320b0c10387d1cce27f709c8b2348c14dc423
Merged-In: I308320b0c10387d1cce27f709c8b2348c14dc423
parent 56439da7
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -1152,6 +1152,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
    // Do not call bond_state_changed_cb yet. Wait until remote service
    // discovery is complete
  } else {
    bool is_bonded_device_removed = false;
    // Map the HCI fail reason  to  bt status
    switch (p_auth_cmpl->fail_reason) {
      case HCI_ERR_PAGE_TIMEOUT:
@@ -1170,14 +1171,16 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
        break;

      case HCI_ERR_PAIRING_NOT_ALLOWED:
        btif_storage_remove_bonded_device(&bd_addr);
        is_bonded_device_removed =
            (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
        status = BT_STATUS_AUTH_REJECTED;
        break;

      /* map the auth failure codes, so we can retry pairing if necessary */
      case HCI_ERR_AUTH_FAILURE:
      case HCI_ERR_KEY_MISSING:
        btif_storage_remove_bonded_device(&bd_addr);
        is_bonded_device_removed =
            (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
        [[fallthrough]];
      case HCI_ERR_HOST_REJECT_SECURITY:
      case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
@@ -1208,11 +1211,16 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
      /* Remove Device as bonded in nvram as authentication failed */
      BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram",
                       __func__);
      btif_storage_remove_bonded_device(&bd_addr);
      is_bonded_device_removed =
          (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
    }
    // Report bond state change to java only if we are bonding to a device or
    // a device is removed from the pairing list.
    if (pairing_cb.state == BT_BOND_STATE_BONDING || is_bonded_device_removed) {
      bond_state_changed(status, bd_addr, state);
    }
  }
}

/******************************************************************************
 *