From 9b11226f3d23dfb4c6b8457f2a839584666cda6a Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 15 Apr 2014 14:18:12 +0200 Subject: Fix discovery hanging in unrecoverable state due to incorrect error handling The discovery of services happens in a sequentiali per-device order. Once the first device's services were found, the results are processed and the discovery is started on the next device. Unfortunately if the search didn't create any results due to the remote device refusing the SDP discovery or because the given remote Bluetooth address was not valid, the discovery agent didn't continue with the next device. Now the error handling ensures that the discovery process is continued with the next device (if there is any). Task-number: QTBUG-38362 Change-Id: Ie27bbc5327eadc4bcc31b589227c51dc4fa2c7c1 Reviewed-by: Fabian Bumberger --- src/bluetooth/android/servicediscoverybroadcastreceiver.cpp | 6 +++++- src/bluetooth/qbluetoothservicediscoveryagent_android.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp index 0a3f97f9..87564ce6 100644 --- a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp +++ b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp @@ -76,8 +76,10 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, "getParcelableArrayExtra", "(Ljava/lang/String;)[Landroid/os/Parcelable;", keyExtra.object()); - if (!parcelableUuids.isValid()) + if (!parcelableUuids.isValid()) { + emit uuidFetchFinished(QBluetoothAddress(), QList()); return; + } const QList result = ServiceDiscoveryBroadcastReceiver::convertParcelableArray(parcelableUuids); keyExtra = valueForStaticField(JavaNames::BluetoothDevice, JavaNames::ExtraDevice); @@ -89,6 +91,8 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, if (bluetoothDevice.isValid()) { address = QBluetoothAddress(bluetoothDevice.callObjectMethod("getAddress").toString()); emit uuidFetchFinished(address, result); + } else { + emit uuidFetchFinished(QBluetoothAddress(), QList()); } } } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index 4a8b62e7..2643d7a9 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -246,6 +246,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids( if (discoveredDevices.count() == 0) return; + //could not find any service for the current address/device -> go to next one + if (address.isNull() || uuids.isEmpty()) { + _q_serviceDiscoveryFinished(); + return; + } + if (QT_BT_ANDROID().isDebugEnabled()) { qCDebug(QT_BT_ANDROID) << "Found UUID for" << address.toString() << "\ncount: " << uuids.count(); -- cgit v1.2.3