From: Szymon Janc <szymon.janc@xxxxxxxxx> Bonded devices are permament until unbondedn. Non-bonded devices will be held in (size limited) cache based on timestamp property so split list to ease separation. --- android/bluetooth.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 4849dab..8f08122 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -132,6 +132,8 @@ static const uint16_t uuid_list[] = { static uint16_t option_index = MGMT_INDEX_NONE; static struct mgmt *mgmt_if = NULL; + +static GSList *bonded_devices = NULL; static GSList *devices = NULL; /* This list contains addresses which are asked for records */ @@ -283,6 +285,10 @@ static struct device *find_device(const bdaddr_t *bdaddr) { GSList *l; + l = g_slist_find_custom(bonded_devices, bdaddr, device_match); + if (l) + return l->data; + l = g_slist_find_custom(devices, bdaddr, device_match); if (l) return l->data; @@ -559,12 +565,30 @@ static void set_device_bond_state(const bdaddr_t *addr, uint8_t status, if (!dev) return; - if (dev->bond_state != state) { - dev->bond_state = state; - send_bond_state_change(&dev->bdaddr, status, state); + if (dev->bond_state == state) + return; - store_device_info(dev); + switch (state) { + case HAL_BOND_STATE_NONE: + if (dev->bond_state == HAL_BOND_STATE_BONDED) { + bonded_devices = g_slist_remove(bonded_devices, dev); + devices = g_slist_prepend(devices, dev); + } + break; + case HAL_BOND_STATE_BONDED: + devices = g_slist_remove(devices, dev); + bonded_devices = g_slist_prepend(bonded_devices, dev); + break; + case HAL_BOND_STATE_BONDING: + default: + break; } + + dev->bond_state = state; + + store_device_info(dev); + + send_bond_state_change(&dev->bdaddr, status, state); } static void send_device_property(const bdaddr_t *bdaddr, uint8_t type, @@ -2128,18 +2152,15 @@ static uint8_t get_adapter_scan_mode(void) static uint8_t get_adapter_bonded_devices(void) { - uint8_t buf[sizeof(bdaddr_t) * g_slist_length(devices)]; + uint8_t buf[sizeof(bdaddr_t) * g_slist_length(bonded_devices)]; int i = 0; GSList *l; DBG(""); - for (l = devices; l; l = g_slist_next(l)) { + for (l = bonded_devices; l; l = g_slist_next(l)) { struct device *dev = l->data; - if (dev->bond_state != HAL_BOND_STATE_BONDED) - continue; - bdaddr2android(&dev->bdaddr, buf + (i * sizeof(bdaddr_t))); i++; } @@ -2691,11 +2712,10 @@ static void send_bonded_devices_props(void) { GSList *l; - for (l = devices; l; l = g_slist_next(l)) { + for (l = bonded_devices; l; l = g_slist_next(l)) { struct device *dev = l->data; - if (dev->bond_state == HAL_BOND_STATE_BONDED) - get_remote_device_props(dev); + get_remote_device_props(dev); } } @@ -3093,6 +3113,9 @@ void bt_bluetooth_unregister(void) { DBG(""); + g_slist_free_full(bonded_devices, (GDestroyNotify) free_device); + bonded_devices = NULL; + g_slist_free_full(devices, (GDestroyNotify) free_device); devices = NULL; -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html