From d4537ea1e887510cce1d42437b92f26b52e30d71 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 26 May 2014 15:24:45 +0200 Subject: Process Bluez5 URLs during SDP scan Bluez5 advertises the following SDP attributes - QBluetoothServiceInfo::DocumentationUrl - QBluetoothServiceInfo::ClientExecutableUrl - QBluetoothServiceInfo::IconUrl They come as xml tag but otherwise follow the syntax. So far this type of xml tag was unknown, a warning was printed and the service info didn't contain the relevant info. Although Bluez5 seems to be the first to advertise this attribute, Bluez4 has to be able to deal with it too. Hence this patch goes to Qt 5.3/stable. Change-Id: I216fdaee23c75b1ed86702086be2d95a0efe109e Reviewed-by: Aaron McCarthy --- src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index a842d3d9..08343a7d 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -310,7 +310,7 @@ QVariant QBluetoothServiceDiscoveryAgentPrivate::readAttributeValue(QXmlStreamRe } xml.skipCurrentElement(); return QVariant::fromValue(uuid); - } else if (xml.name() == QLatin1String("text")) { + } else if (xml.name() == QLatin1String("text") || xml.name() == QStringLiteral("url")) { QString value = xml.attributes().value(QLatin1String("value")).toString(); if (xml.attributes().value(QLatin1String("encoding")) == QLatin1String("hex")) value = QString::fromUtf8(QByteArray::fromHex(value.toLatin1())); -- cgit v1.2.3 From 00c7458831695ebf075c8e16a023e68cbefe1bc5 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 26 May 2014 14:47:51 +0200 Subject: Don't stop processing of Bluez services if one service is invalid This is a regression introduced during the Bluez5 port. During the service xml parsing we may encounter an invalid service info. This does not mean the next one is invalid too. This bug caused the service discovery to abort. Change-Id: If51e0f898d83e99ba0a279c13ccaa3e5947bb6bf Reviewed-by: Aaron McCarthy --- src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 5804d8b3..48967441 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -482,7 +482,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); if (!serviceInfo.isValid()) - return; + continue; // Don't need to apply uuidFilter because Bluez 4 applies // search pattern during DiscoverServices() call -- cgit v1.2.3 From b28dbaf82f1140420f60d9f26a637f365fac9bbf Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 19 May 2014 13:36:59 +0200 Subject: Bluez5: Simplify lookup of default adapter Change-Id: I59aa5241d33191a8ca8cc167263b63b024f52754 Reviewed-by: Aaron McCarthy Reviewed-by: Alex Blasche --- .../qbluetoothservicediscoveryagent_bluez.cpp | 29 +++------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 48967441..cd5562ac 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -143,38 +143,17 @@ void QBluetoothServiceDiscoveryAgentPrivate::startBluez5(const QBluetoothAddress if (foundHostAdapterPath.isEmpty()) { // check that we match adapter addresses or use first if it wasn't specified - QDBusPendingReply reply = managerBluez5->GetManagedObjects(); - reply.waitForFinished(); - if (reply.isError()) { + bool ok = false; + foundHostAdapterPath = findAdapterForAddress(m_deviceAdapterAddress, &ok); + if (!ok) { discoveredDevices.clear(); error = QBluetoothServiceDiscoveryAgent::InputOutputError; - errorString = reply.error().message(); + errorString = QBluetoothDeviceDiscoveryAgent::tr("Cannot access adapter during service discovery"); emit q->error(error); _q_serviceDiscoveryFinished(); return; } - const QString desiredAdapter = m_deviceAdapterAddress.toString(); - foreach (const QDBusObjectPath &path, reply.value().keys()) { - const InterfaceList ifaceList = reply.value().value(path); - foreach (const QString &iface, ifaceList.keys()) { - if (iface == QStringLiteral("org.bluez.Adapter1")) { - if (m_deviceAdapterAddress.isNull() - || desiredAdapter == ifaceList.value(iface). - value(QStringLiteral("Address")).toString()) { - // use first adapter or we just matched one - foundHostAdapterPath = path.path(); - } - - if (!foundHostAdapterPath.isEmpty()) - break; - } - } - - if (!foundHostAdapterPath.isEmpty()) - break; - } - if (foundHostAdapterPath.isEmpty()) { // Cannot find a local adapter // Abort any outstanding discoveries -- cgit v1.2.3 From bf1a06f6aaedf7709947eb284226348fb0385cc0 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 26 May 2014 15:49:12 +0200 Subject: Avoid empty service names Bluez doesn't seem to know the service class uuid 0x1200 which seems common on BB10 devices. Ensure that we set a name if Bluez did not provide a name. This was made possible by the recent addition of QBluetoothUuid::serviceClassToString(..). [ChangeLog][QtBluetooth][QBluetoothServiceDiscoveryAgent] Fixed cases where Bluez doesn't provide service names for given Bluetooth service class uuid. Change-Id: Ife56ab878f70ca6226e907f59972368c79318bec Reviewed-by: Fabian Bumberger --- src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp') diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index cd5562ac..177ce63e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -458,7 +458,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC qCDebug(QT_BT_BLUEZ) << "Parsing xml" << discoveredDevices.at(0).address().toString() << discoveredDevices.count() << map.count(); foreach (const QString &record, reply.value()) { - const QBluetoothServiceInfo serviceInfo = parseServiceXml(record); + QBluetoothServiceInfo serviceInfo = parseServiceXml(record); if (!serviceInfo.isValid()) continue; @@ -467,6 +467,20 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC // search pattern during DiscoverServices() call Q_Q(QBluetoothServiceDiscoveryAgent); + // Some service uuids are unknown to Bluez. In such cases we fall back + // to our own naming resolution. + if (serviceInfo.serviceName().isEmpty() + && !serviceInfo.serviceClassUuids().isEmpty()) { + foreach (const QBluetoothUuid &classUuid, serviceInfo.serviceClassUuids()) { + bool ok = false; + QBluetoothUuid::ServiceClassUuid clsId + = static_cast(classUuid.toUInt16(&ok)); + if (ok) { + serviceInfo.setServiceName(QBluetoothUuid::serviceClassToString(clsId)); + break; + } + } + } if (!isDuplicatedService(serviceInfo)) { discoveredServices.append(serviceInfo); -- cgit v1.2.3