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

Commit 3ad5b1bc authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Remove entire storage section when the device is unbonded

Every bonded device property is stored under a section corresponding to
the device. BTIF storage function for removing the device removes the
individual properties. However as the properties are added in the BT
stack, chances of some properties left alone during device removal
increases.
For example, "AddrType" property is not removed when a device is
removed. As a result, when reconnecting/repairing with such device, this
old property unintentionally gets assigned to the device.

Test: m com.android.btservices
Bug: 298479810
Change-Id: I5c1bceb708727e17771cb222abe79f986e55a573
parent 018b0ba5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ bool btif_config_set_bin(const std::string& section, const std::string& key,
                         const uint8_t* value, size_t length);
bool btif_config_remove(const std::string& section, const std::string& key);

void btif_config_remove_device(const std::string& section);

size_t btif_config_get_bin_length(const std::string& section,
                                  const std::string& key);

+5 −0
Original line number Diff line number Diff line
@@ -337,6 +337,11 @@ bool btif_config_remove(const std::string& section, const std::string& key) {
  return bluetooth::shim::BtifConfigInterface::RemoveProperty(section, key);
}

void btif_config_remove_device(const std::string& section) {
  CHECK(bluetooth::shim::is_gd_stack_started_up());
  bluetooth::shim::BtifConfigInterface::RemoveSection(section);
}

bool btif_config_clear(void) {
  CHECK(bluetooth::shim::is_gd_stack_started_up());
  bluetooth::shim::BtifConfigInterface::Clear();
+3 −22
Original line number Diff line number Diff line
@@ -881,27 +881,7 @@ bt_status_t btif_storage_remove_bonded_device(
  LOG_INFO("Removing bonded device addr:%s",
           ADDRESS_TO_LOGGABLE_CSTR(*remote_bd_addr));

  btif_storage_remove_ble_bonding_keys(remote_bd_addr);

  int ret = 1;
  if (btif_config_exist(bdstr, "LinkKeyType"))
    ret &= btif_config_remove(bdstr, "LinkKeyType");
  if (btif_config_exist(bdstr, "PinLength"))
    ret &= btif_config_remove(bdstr, "PinLength");
  if (btif_config_exist(bdstr, "LinkKey"))
    ret &= btif_config_remove(bdstr, "LinkKey");
  if (btif_config_exist(bdstr, BTIF_STORAGE_PATH_REMOTE_ALIASE)) {
    ret &= btif_config_remove(bdstr, BTIF_STORAGE_PATH_REMOTE_ALIASE);
  }
  if (btif_config_exist(bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED)) {
    ret &= btif_config_remove(bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_SUPPORTED);
  }
  if (btif_config_exist(bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_DB_HASH)) {
    ret &= btif_config_remove(bdstr, BTIF_STORAGE_KEY_GATT_CLIENT_DB_HASH);
  }
  if (btif_config_exist(bdstr, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED)) {
    ret &= btif_config_remove(bdstr, BTIF_STORAGE_KEY_GATT_SERVER_SUPPORTED);
  }
  btif_config_remove_device(bdstr);

  /* Check the length of the paired devices, and if 0 then reset IRK */
  auto paired_devices = btif_config_get_paired_devices();
@@ -910,7 +890,8 @@ bt_status_t btif_storage_remove_bonded_device(
    LOG_INFO("Last paired device removed, resetting IRK");
    BTA_DmBleResetId();
  }
  return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;

  return BT_STATUS_SUCCESS;
}

/* Some devices hardcode sample LTK value from spec, instead of generating one.
+4 −0
Original line number Diff line number Diff line
@@ -143,6 +143,10 @@ bool BtifConfigInterface::RemoveProperty(const std::string& section,
  return GetStorage()->RemoveProperty(section, property);
}

void BtifConfigInterface::RemoveSection(const std::string& section) {
  GetStorage()->RemoveSection(section);
}

std::vector<std::string> BtifConfigInterface::GetPersistentDevices() {
  return GetStorage()->GetPersistentSections();
}
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ class BtifConfigInterface {
                     const uint8_t* value, size_t length);
  static bool RemoveProperty(const std::string& section,
                             const std::string& key);
  static void RemoveSection(const std::string& section);
  static std::vector<std::string> GetPersistentDevices();
  static void ConvertEncryptOrDecryptKeyIfNeeded();
  static void Clear();
Loading