From 345c70fc8de91b869ccaff2a4edea274b4e0135f Mon Sep 17 00:00:00 2001 From: Hansong Zhang <hsz@google.com> Date: Tue, 3 Apr 2018 18:17:43 -0700 Subject: [PATCH] HID Device: remove "Cabled" flag when device is not used Remove the "HidDeviceCabled" flag from the config when the remote device is not currently being usec Bug: 77549256 Test: manual Change-Id: I2c88e972457608699c3f0344357828324a419b90 --- system/btif/src/btif_storage.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/system/btif/src/btif_storage.cc b/system/btif/src/btif_storage.cc index 109b37d5b1c..e40281201c9 100644 --- a/system/btif/src/btif_storage.cc +++ b/system/btif/src/btif_storage.cc @@ -1518,13 +1518,23 @@ bt_status_t btif_storage_load_hidd(void) { * * Function btif_storage_set_hidd * - * Description Stores hidd bonded device info in nvram. + * Description Stores currently used HIDD device info in nvram and remove + * the "HidDeviceCabled" flag from unused devices * * Returns BT_STATUS_SUCCESS * ******************************************************************************/ bt_status_t btif_storage_set_hidd(RawAddress* remote_bd_addr) { - btif_config_set_int(remote_bd_addr->ToString(), "HidDeviceCabled", 1); + std::string remote_device_address_string = remote_bd_addr->ToString(); + for (const section_t& section : btif_config_sections()) { + if (!RawAddress::IsValidAddress(section.name)) continue; + if (section.name == remote_device_address_string) continue; + if (btif_in_fetch_bonded_device(section.name) == BT_STATUS_SUCCESS) { + btif_config_remove(section.name, "HidDeviceCabled"); + } + } + + btif_config_set_int(remote_device_address_string, "HidDeviceCabled", 1); btif_config_save(); return BT_STATUS_SUCCESS; } -- GitLab