From 4608beaee4176214aa13d561f6694376f400be8a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 29 Sep 2020 14:58:13 -0700 Subject: Android BLE discovery: use discovery agent Android can't scan for classic BT devices, so when BT support was first added, we simply didn't use the discovery agent at all and relied on the list of paired BT devices provided by Android. This still worked fine for a lot of BLE devices that allowed 'bonding' with the Android device - similar to pairing. But some BLE devices (like the Shearwater Peregrine) don't support bonding and so our Android code didn't see them at all. With this commit we start a BLE only scan on Android to add to the list of already paired devices. Fixes: #2974 Signed-off-by: Dirk Hohndel --- core/btdiscovery.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'core/btdiscovery.cpp') diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 6538ba117..73a0ab803 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -181,7 +181,7 @@ void BTDiscovery::BTDiscoveryReDiscover() if (1) { #endif m_btValid = true; -#if !defined(Q_OS_ANDROID) + if (discoveryAgent == nullptr) { discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); discoveryAgent->setLowEnergyDiscoveryTimeout(3 * 60 * 1000); // search for three minutes @@ -194,18 +194,22 @@ void BTDiscovery::BTDiscoveryReDiscover() }); qDebug() << "discovery methods" << (int)QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods(); } +#if defined(Q_OS_ANDROID) + // on Android, we cannot scan for classic devices - we just get the paired ones qDebug() << "starting BLE discovery"; - discoveryAgent->start(); -#else + discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); getBluetoothDevices(); // and add the paired devices to the internal data // So behaviour is same on Linux/Bluez stack and // Android/Java stack with respect to discovery for (int i = 0; i < btPairedDevices.length(); i++) btDeviceDiscoveredMain(btPairedDevices[i], true); -#endif +#else + qDebug() << "starting BT/BLE discovery"; + discoveryAgent->start(); for (int i = 0; i < btPairedDevices.length(); i++) qDebug() << "Paired =" << btPairedDevices[i].name << btPairedDevices[i].address; +#endif #if defined(Q_OS_IOS) || (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) QTimer timer; -- cgit v1.2.3-70-g09d2