From f7b799f5c072722d276c3bb053fc02e5e0a39fca Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Fri, 18 Apr 2014 12:41:54 +0200 Subject: [PATCH] android/bluetooth: Fix sending discovery state changed events Those events should be send only if discovery was started/stoped from bluetooth HAL. --- android/bluetooth.c | 46 +++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 89212e389..7d678bae2 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -1064,11 +1064,37 @@ static bool start_discovery(uint8_t type) return false; } +/* + * Send discovery state change event only if it is related to dual type + * discovery session (triggered by start/cancel discovery commands) + */ +static void check_discovery_state(uint8_t new_type, uint8_t old_type) +{ + struct hal_ev_discovery_state_changed ev; + + DBG("%u %u", new_type, old_type); + + if (new_type == get_adapter_discovering_type()) { + g_slist_foreach(bonded_devices, clear_device_found, NULL); + g_slist_foreach(cached_devices, clear_device_found, NULL); + ev.state = HAL_DISCOVERY_STATE_STARTED; + goto done; + } + + if (old_type != get_adapter_discovering_type()) + return; + + ev.state = HAL_DISCOVERY_STATE_STOPPED; + +done: + ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, + HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(ev), &ev); +} + static void mgmt_discovering_event(uint16_t index, uint16_t length, const void *param, void *user_data) { const struct mgmt_ev_discovering *ev = param; - struct hal_ev_discovery_state_changed cp; uint8_t type; if (length < sizeof(*ev)) { @@ -1081,18 +1107,14 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length, if (!!adapter.cur_discovery_type == !!ev->discovering) return; - if (ev->discovering) { - adapter.cur_discovery_type = ev->type; - cp.state = HAL_DISCOVERY_STATE_STARTED; + type = ev->discovering ? ev->type : SCAN_TYPE_NONE; - goto done; - } + check_discovery_state(type, adapter.cur_discovery_type); - adapter.cur_discovery_type = SCAN_TYPE_NONE; - cp.state = HAL_DISCOVERY_STATE_STOPPED; + adapter.cur_discovery_type = type; - g_slist_foreach(bonded_devices, clear_device_found, NULL); - g_slist_foreach(cached_devices, clear_device_found, NULL); + if (ev->discovering) + return; /* One shot notification about discovery stopped */ if (gatt_discovery_stopped_cb) { @@ -1108,10 +1130,6 @@ static void mgmt_discovering_event(uint16_t index, uint16_t length, if (type != SCAN_TYPE_NONE) start_discovery(type); - -done: - ipc_send_notif(hal_ipc, HAL_SERVICE_ID_BLUETOOTH, - HAL_EV_DISCOVERY_STATE_CHANGED, sizeof(cp), &cp); } static void confirm_device_name_cb(uint8_t status, uint16_t length, -- 2.47.3