diff --git a/android/bluetooth.c b/android/bluetooth.c
index 89212e3..7d678ba 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
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)) {
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) {
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,