From c81430b704e17d2f2eb5445e261ab3753bef3328 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 12 Feb 2020 15:50:37 +0100 Subject: Ensure that a failing classic discovery doesn't prevent LE scan When the classic scan does not start properly we immediately error out. If the user has requested LE discovery in addition to the classic discovery, we should continue with LE discovery. By convention, we only bother the user with an error signal if none of the two methods succeed. Task-number: QTBUG-81875 Change-Id: Id867892210fbef6da0e4937c2aef20f726ba9a2a Reviewed-by: Konstantin Ritt Reviewed-by: Timur Pocheptsov --- .../qbluetoothdevicediscoveryagent_android.cpp | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index 4b9e2032..fd17faee 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -239,17 +239,25 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent if (requestedMethods & QBluetoothDeviceDiscoveryAgent::ClassicMethod) { const bool success = adapter.callMethod("startDiscovery"); if (!success) { - lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; - errorString = QBluetoothDeviceDiscoveryAgent::tr("Classic Discovery cannot be started"); - emit q->error(lastError); + qCDebug(QT_BT_ANDROID) << "Classic Discovery cannot be started"; + if (requestedMethods == QBluetoothDeviceDiscoveryAgent::ClassicMethod) { + //only classic discovery requested -> error out + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; + errorString = QBluetoothDeviceDiscoveryAgent::tr("Classic Discovery cannot be started"); + + emit q->error(lastError); + return; + } // else fall through to LE discovery + } else { + m_active = SDPScanActive; + qCDebug(QT_BT_ANDROID) + << "QBluetoothDeviceDiscoveryAgentPrivate::start() - Classic search successfully started."; return; } + } - m_active = SDPScanActive; - qCDebug(QT_BT_ANDROID) - << "QBluetoothDeviceDiscoveryAgentPrivate::start() - Classic search successfully started."; - } else { - // LE search only requested + if (requestedMethods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod) { + // LE search only requested or classic discovery failed but lets try LE scan anyway Q_ASSERT(requestedMethods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod); if (QtAndroidPrivate::androidSdkVersion() < 18) { -- cgit v1.2.3