From: Marcel Holtmann Date: Sun, 20 Jan 2013 03:13:49 +0000 (-0800) Subject: core: Handle existing start discovery gracefully X-Git-Tag: android-x86-4.4-r3~8723 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f0ccb6d471590e5110e1d65bd81b9e91a4b72d83;p=android-x86%2Fexternal-bluetooth-bluez.git core: Handle existing start discovery gracefully In case a discovery already exists, keep using it if is has the same type and only if not, stop it and start a new one. --- diff --git a/src/adapter.c b/src/adapter.c index b1ac71dbb..14fdc5700 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1123,18 +1123,50 @@ static gboolean start_discovery_timeout(gpointer user_data) { struct btd_adapter *adapter = user_data; struct mgmt_cp_start_discovery cp; + uint8_t new_type; DBG(""); adapter->discovery_idle_timeout = 0; if (adapter->current_settings & MGMT_SETTING_BREDR) - cp.type = (1 << BDADDR_BREDR); + new_type = (1 << BDADDR_BREDR); else - cp.type = 0; + new_type = 0; if (adapter->current_settings & MGMT_SETTING_LE) - cp.type |= (1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM); + new_type |= (1 << BDADDR_LE_PUBLIC) | (1 << BDADDR_LE_RANDOM); + + if (adapter->discovery_enable == 0x01) { + /* + * If there is an already running discovery and it has the + * same type, then just keep it. + */ + if (adapter->discovery_type == new_type) { + if (adapter->discovering) + return FALSE; + + adapter->discovering = true; + g_dbus_emit_property_changed(dbus_conn, adapter->path, + ADAPTER_INTERFACE, "Discovering"); + return FALSE; + } + + /* + * Otherwise the current discovery must be stopped. So + * queue up a stop discovery command. + * + * This can happen if a passive scanning for Low Energy + * devices is ongoing. + */ + cp.type = adapter->discovery_type; + + mgmt_send(adapter->mgmt, MGMT_OP_STOP_DISCOVERY, + adapter->dev_id, sizeof(cp), &cp, + NULL, NULL, NULL); + } + + cp.type = new_type; mgmt_send(adapter->mgmt, MGMT_OP_START_DISCOVERY, adapter->dev_id, sizeof(cp), &cp, @@ -1148,9 +1180,6 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay) DBG(""); - if (adapter->discovery_enable == 0x01) - return; - if (adapter->discovery_idle_timeout > 0) { g_source_remove(adapter->discovery_idle_timeout); adapter->discovery_idle_timeout = 0;