From 3bf621a5e611eb5b7585464d0453a87b688f7a4e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 1 Jun 2016 14:16:23 +0200 Subject: BlueZ5: Prevent premature abortion of device discovery This may happen when the device discovery agent is quickly started and stopped and started again. If the stop-start combination is happening quicker than dbus can deliver the Discovering flag of the Adapter1 BlueZ interface, BlueZ's stop response will override the new start discovery request. Task-number: QTBUG-53715 Change-Id: I6a03fc525c7f390db009fc68a5313352ebba7f79 Reviewed-by: Frank Meerkoetter Reviewed-by: Alex Blasche --- src/bluetooth/bluez/bluez5_helper.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/bluez') diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp index 14e064e1..d77e8fb6 100644 --- a/src/bluetooth/bluez/bluez5_helper.cpp +++ b/src/bluetooth/bluez/bluez5_helper.cpp @@ -260,8 +260,24 @@ void QtBluezDiscoveryManager::PropertiesChanged(const QString &interface, && d->references.contains(propIface->path()) && changed_properties.contains(QStringLiteral("Discovering"))) { bool isDiscovering = changed_properties.value(QStringLiteral("Discovering")).toBool(); - if (!isDiscovering) - removeAdapterFromMonitoring(propIface->path()); + if (!isDiscovering) { + + /* + Once we stop the Discovering flag will switch a few ms later. This comes through this code + path. If a new device discovery is started while we are still + waiting for the flag change signal, then the new device discovery will be aborted prematurely. + To compensate we check whether there was renewed interest. + */ + + AdapterData *data = d->references[propIface->path()]; + if (!data) { + removeAdapterFromMonitoring(propIface->path()); + } else { + OrgBluezAdapter1Interface iface(QStringLiteral("org.bluez"), propIface->path(), + QDBusConnection::systemBus()); + iface.StartDiscovery(); + } + } } } -- cgit v1.2.3