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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-09-29 14:58:13 -07:00
parent 5b48585092
commit 4608beaee4

View file

@ -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;