summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2019-01-07 14:55:21 +0100
committerAlex Blasche <alexander.blasche@qt.io>2019-01-09 08:12:29 +0000
commite957470ae0e61eea1afa96d76468dbdc87168421 (patch)
treee93eb251a0f03546a9dc49cc59363bd364a98547
parent45608abda7b9470ec0b3ea26e849ec71b637288d (diff)
Ensure custom uuids are returned by QBluetoothServiceInfo::serviceUuid()
QBluetoothServiceDiscoveryAgent::start(FullDiscovery) uses an external tool called sdpscanner to perform the SDP inquiry. The tool uses Bluez's own API to perform the task and is GPL. In case a remote device offers a custom service the service uuid is returned as serviceClassUuid. QBluetoothServiceInfo::serviceUuid() remains empty although it should be populated as per API contract. This patch ensures that the first custom uuid is shifted from the serviceClassUuid list to serviceUuid(). The fix is limited because it picks the first custom uuid and does not consider a secondary custom uuid. Such a case is extremely unlikely though and I have not come across it. Fixes: QTBUG-72800 Change-Id: I7256440bcb1c9b0b2fb75249f977c43fecf1d910 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index e16caff6..6a93143b 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -291,7 +291,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD
emit q->error(error);
} else if (!xmlRecords.isEmpty() && discoveryState() != Inactive) {
for (const QString &record : xmlRecords) {
- const QBluetoothServiceInfo serviceInfo = parseServiceXml(record);
+ QBluetoothServiceInfo serviceInfo = parseServiceXml(record);
//apply uuidFilter
if (!uuidFilter.isEmpty()) {
@@ -313,6 +313,22 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_finishSdpScan(QBluetoothServiceD
if (!serviceInfo.isValid())
continue;
+ // Bluez sdpscanner declares custom uuids into the service class uuid list.
+ // Let's move a potential custom uuid from QBluetoothServiceInfo::serviceClassUuids()
+ // to QBluetoothServiceInfo::serviceUuid(). If there is more than one, just move the first uuid
+ const QList<QBluetoothUuid> serviceClassUuids = serviceInfo.serviceClassUuids();
+ for (const QBluetoothUuid &id : serviceClassUuids) {
+ if (id.minimumSize() == 16) {
+ serviceInfo.setServiceUuid(id);
+ serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Custom Service"));
+ QBluetoothServiceInfo::Sequence modSeq =
+ serviceInfo.attribute(QBluetoothServiceInfo::ServiceClassIds).value<QBluetoothServiceInfo::Sequence>();
+ modSeq.removeOne(QVariant::fromValue(id));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, modSeq);
+ break;
+ }
+ }
+
if (!isDuplicatedService(serviceInfo)) {
discoveredServices.append(serviceInfo);
qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString()