summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp8
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp34
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h2
3 files changed, 38 insertions, 6 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index 02ea30d1..5f142f1a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -333,13 +333,19 @@ void QBluetoothDeviceDiscoveryAgent::start()
}
/*!
- Start Bluetooth device discovery, if it is not already started and the provided
+ Starts Bluetooth device discovery, if it is not already started and the provided
\a methods are supported.
The discovery \a methods limit the scope of the device search.
For example, if the target service or device is a Bluetooth Low Energy device,
this function could be used to limit the search to Bluetooth Low Energy devices and
thereby reduces the discovery time significantly.
+ \note \a methods only determines the type of discovery and does not imply
+ the filtering of the results. For example, the search may still contain classic bluetooth devices
+ despite \a methods being set to \l {QBluetoothDeviceDiscoveryAgent::LowEnergyMethod}
+ {LowEnergyMethod} only. This may happen due to previously cached search results
+ which may be incorporated into the search results.
+
\since 5.8
*/
void QBluetoothDeviceDiscoveryAgent::start(DiscoveryMethods methods)
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index f2ca4233..3cc3354a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -125,7 +125,7 @@ QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent:
return (ClassicMethod | LowEnergyMethod);
}
-void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods /*methods*/)
+void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
{
// Currently both BlueZ backends do not distinguish discovery methods.
// The DBus API's always return both device types. Therefore we ignore
@@ -139,7 +139,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
discoveredDevices.clear();
if (managerBluez5) {
- startBluez5();
+ startBluez5(methods);
return;
}
@@ -228,11 +228,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
}
}
-void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
+void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
{
Q_Q(QBluetoothDeviceDiscoveryAgent);
-
bool ok = false;
const QString adapterPath = findAdapterForAddress(m_adapterAddress, &ok);
if (!ok || adapterPath.isEmpty()) {
@@ -257,6 +256,33 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
return;
}
+ QVariantMap map;
+ if (methods == (QBluetoothDeviceDiscoveryAgent::LowEnergyMethod|QBluetoothDeviceDiscoveryAgent::ClassicMethod))
+ map.insert(QStringLiteral("Transport"), QStringLiteral("auto"));
+ else if (methods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)
+ map.insert(QStringLiteral("Transport"), QStringLiteral("le"));
+ else
+ map.insert(QStringLiteral("Transport"), QStringLiteral("bredr"));
+
+ // older BlueZ 5.x versions don't have this function
+ // filterReply returns UnknownMethod which we ignore
+ QDBusPendingReply<> filterReply = adapterBluez5->SetDiscoveryFilter(map);
+ filterReply.waitForFinished();
+ if (filterReply.isError()) {
+ if (filterReply.error().type() == QDBusError::Other
+ && filterReply.error().name() == QStringLiteral("org.bluez.Error.Failed")) {
+ qCDebug(QT_BT_BLUEZ) << "Discovery method" << methods << "not supported";
+ lastError = QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod;
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("One or more device discovery methods "
+ "are not supported on this platform");
+ delete adapterBluez5;
+ adapterBluez5 = 0;
+ emit q->error(lastError);
+ return;
+ } else if (filterReply.error().type() != QDBusError::UnknownMethod) {
+ qCDebug(QT_BT_BLUEZ) << "SetDiscoveryFilter failed:" << filterReply.error();
+ }
+ }
QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)),
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 7b57abb2..13d85a94 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -153,7 +153,7 @@ private:
QList<OrgFreedesktopDBusPropertiesInterface *> propertyMonitors;
void deviceFoundBluez5(const QString& devicePath);
- void startBluez5();
+ void startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods);
bool useExtendedDiscovery;
QTimer extendedDiscoveryTimer;