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

Commit 92abe9f7 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Invalidate the bonded status when the device is deleted

When a connected device is removed, the security record is removed from the persistent storage immediately but not entirely from the control blocks. If the devices attempt to repair, the remnants of the device record in the control blocks lead the stack to believe that the device is bonded. This triggers the bond loss handling which attempts to remove the security record before the repairing is continued. Thus an unnecessary BOND_NONE bond state change event is generated.

Test: m com.android.btservices
Bug: 295441750

Change-Id: Ic76924e3329ff660ef5e7a5614e3ab572fbce284
parent 5400d131
Loading
Loading
Loading
Loading
+36 −31
Original line number Diff line number Diff line
@@ -159,15 +159,24 @@ void BTM_AcceptlistRemove(const RawAddress& address);
 * Returns true if removed OK, false if not found or ACL link is active.
 */
bool BTM_SecDeleteDevice(const RawAddress& bd_addr) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
    LOG_WARN("Unable to delete link key for unknown device %s",
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return true;
  }

  /* Invalidate bonded status */
  p_dev_rec->sec_flags &= ~BTM_SEC_LINK_KEY_KNOWN;
  p_dev_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_KNOWN;

  if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
      BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) {
    LOG_WARN("%s FAILED: Cannot Delete when connection to %s is active",
             __func__, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    LOG_WARN("FAILED: Cannot Delete when connection to %s is active",
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return false;
  }

  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec != NULL) {
  RawAddress bda = p_dev_rec->bd_addr;

  LOG_INFO("Remove device %s from filter accept list before delete record",
@@ -189,15 +198,11 @@ bool BTM_SecDeleteDevice(const RawAddress& bd_addr) {
  wipe_secrets_and_remove(p_dev_rec);
  /* Tell controller to get rid of the link key, if it has one stored */
  BTM_DeleteStoredLinkKey(&bda, NULL);
    LOG_INFO("%s %s complete", __func__, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  LOG_INFO("%s complete", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  BTM_LogHistory(kBtmLogTag, bd_addr, "Device removed",
                 base::StringPrintf("device_type:%s bond_type:%s",
                                    DeviceTypeText(device_type).c_str(),
                                    bond_type_text(bond_type).c_str()));
  } else {
    LOG_WARN("%s Unable to delete link key for unknown device %s", __func__,
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  }

  return true;
}