From c161203b5dd91ace4b14d46542c49115e8de8d92 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 4 Apr 2019 14:26:04 +0300 Subject: Check the reverted UUID when filtering Change-Id: Idb12d3bb116d6c5b34f1ca145f473b118b58d5ee Reviewed-by: Alex Blasche --- .../qbluetoothservicediscoveryagent_android.cpp | 6 ++- src/bluetooth/qbluetoothsocket_android.cpp | 50 +++++++++++----------- src/bluetooth/qbluetoothsocket_android_p.h | 2 + 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index ddc53421..e607a27e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -47,6 +47,7 @@ #include #include "qbluetoothservicediscoveryagent_p.h" +#include "qbluetoothsocket_android_p.h" #include "android/servicediscoverybroadcastreceiver_p.h" #include "android/localdevicebroadcastreceiver_p.h" @@ -449,8 +450,11 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB //Check if the service is in the uuidFilter if (!uuidFilter.isEmpty()) { bool match = uuidFilter.contains(serviceInfo.serviceUuid()); - for (const auto &uuid : qAsConst(uuidFilter)) + match |= uuidFilter.contains(QBluetoothSocketPrivateAndroid::reverseUuid(serviceInfo.serviceUuid())); + for (const auto &uuid : qAsConst(uuidFilter)) { match |= serviceInfo.serviceClassUuids().contains(uuid); + match |= serviceInfo.serviceClassUuids().contains(QBluetoothSocketPrivateAndroid::reverseUuid(uuid)); + } if (!match) continue; diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index d7f17d17..46bd4a23 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -182,30 +182,6 @@ private: QPointer workerPointer; }; -/* - * This function is part of a workaround for QTBUG-61392 - * - * Returns null uuid if the given \a serviceUuid is not a uuid - * derived from the Bluetooth base uuid. - */ -static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid) -{ - if (serviceUuid.isNull()) - return QBluetoothUuid(); - - bool isBaseUuid = false; - serviceUuid.toUInt32(&isBaseUuid); - if (isBaseUuid) - return serviceUuid; - - const quint128 original = serviceUuid.toUInt128(); - quint128 reversed; - for (int i = 0; i < 16; i++) - reversed.data[15-i] = original.data[i]; - - return QBluetoothUuid(reversed); -} - QBluetoothSocketPrivateAndroid::QBluetoothSocketPrivateAndroid() : inputThread(0) @@ -942,6 +918,32 @@ qint64 QBluetoothSocketPrivateAndroid::bytesToWrite() const return 0; // nothing because always unbuffered } +/* + * This function is part of a workaround for QTBUG-61392 + * + * Returns null uuid if the given \a serviceUuid is not a uuid + * derived from the Bluetooth base uuid. + */ +QBluetoothUuid QBluetoothSocketPrivateAndroid::reverseUuid(const QBluetoothUuid &serviceUuid) +{ + if (QtAndroid::androidSdkVersion() < 23) + return serviceUuid; + + if (serviceUuid.isNull()) + return QBluetoothUuid(); + + bool isBaseUuid = false; + serviceUuid.toUInt32(&isBaseUuid); + if (isBaseUuid) + return serviceUuid; + + const quint128 original = serviceUuid.toUInt128(); + quint128 reversed; + for (int i = 0; i < 16; i++) + reversed.data[15-i] = original.data[i]; + return QBluetoothUuid{reversed}; +} + bool QBluetoothSocketPrivateAndroid::canReadLine() const { // We cannot access buffer directly as it is part of different thread diff --git a/src/bluetooth/qbluetoothsocket_android_p.h b/src/bluetooth/qbluetoothsocket_android_p.h index 7bf42e32..042e1bcd 100644 --- a/src/bluetooth/qbluetoothsocket_android_p.h +++ b/src/bluetooth/qbluetoothsocket_android_p.h @@ -112,6 +112,8 @@ public: bool canReadLine() const override; qint64 bytesToWrite() const override; + static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid); + QAndroidJniObject adapter; QAndroidJniObject socketObject; QAndroidJniObject remoteDevice; -- cgit v1.2.3