summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@viroteck.net>2015-08-20 08:56:24 +0000
committerRobin Burchell <robin.burchell@viroteck.net>2015-09-15 20:12:21 +0000
commitaa6cc482b09bf06d9baaaca1a02d600f8203c2a4 (patch)
tree8c9f10e641375a54629476f205ab5fdd93cb9e50 /src
parente9995b1199f8e488703a82cd7dfaffed9ad51087 (diff)
bluez: SDP: find a device before creating it.
To enable service discovery for known devices even if org.bluez.Adapter.CreateDevice has security restrictions, call org.bluez.Adapter.FindDevice first and CreateDevice only if the device isn't already known. The change is needed due to runtime security checks on Jolla devices, but reordering the calls does no harm when used with upstream bluetoothd. Change-Id: I8ad09808cec648f5b5949044c60173ff1ad46332 Task-number: MER#1225 Done-by: Hannu Mallat <hannu.mallat@jollamobile.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.h1
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp64
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_p.h2
3 files changed, 54 insertions, 13 deletions
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h
index cf756504..984a4084 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.h
@@ -114,6 +114,7 @@ private:
#ifdef QT_BLUEZ_BLUETOOTH
Q_PRIVATE_SLOT(d_func(), void _q_discoveredServices(QDBusPendingCallWatcher*))
Q_PRIVATE_SLOT(d_func(), void _q_createdDevice(QDBusPendingCallWatcher*))
+ Q_PRIVATE_SLOT(d_func(), void _q_foundDevice(QDBusPendingCallWatcher*))
Q_PRIVATE_SLOT(d_func(), void _q_sdpScannerDone(int,QProcess::ExitStatus))
#endif
#ifdef QT_ANDROID_BLUETOOTH
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index d186eafc..de12e6f2 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -127,13 +127,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
}
}
- QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter->CreateDevice(address.toString());
+ QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter->FindDevice(address.toString());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(deviceObjectPath, q);
watcher->setProperty("_q_BTaddress", QVariant::fromValue(address));
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
- q, SLOT(_q_createdDevice(QDBusPendingCallWatcher*)));
-
+ q, SLOT(_q_foundDevice(QDBusPendingCallWatcher*)));
}
// Bluez 5
@@ -352,7 +351,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::stop()
emit q->canceled();
}
-void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWatcher *watcher)
+void QBluetoothServiceDiscoveryAgentPrivate::_q_foundDevice(QDBusPendingCallWatcher *watcher)
{
if (!adapter) {
watcher->deleteLater();
@@ -363,22 +362,54 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
const QBluetoothAddress &address = watcher->property("_q_BTaddress").value<QBluetoothAddress>();
- qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "created" << address.toString();
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "found" << address.toString();
QDBusPendingReply<QDBusObjectPath> deviceObjectPath = *watcher;
watcher->deleteLater();
if (deviceObjectPath.isError()) {
- if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.AlreadyExists")) {
+ if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.DoesNotExist")) {
+ qCDebug(QT_BT_BLUEZ) << "Find device failed Error: " << error << deviceObjectPath.error().name();
delete adapter;
adapter = 0;
+ if (singleDevice) {
+ error = QBluetoothServiceDiscoveryAgent::InputOutputError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to access device");
+ emit q->error(error);
+ }
_q_serviceDiscoveryFinished();
- qCDebug(QT_BT_BLUEZ) << "Create device failed Error: " << error << deviceObjectPath.error().name();
return;
}
- deviceObjectPath = adapter->FindDevice(address.toString());
- deviceObjectPath.waitForFinished();
- if (deviceObjectPath.isError()) {
+ deviceObjectPath = adapter->CreateDevice(address.toString());
+ watcher = new QDBusPendingCallWatcher(deviceObjectPath, q);
+ watcher->setProperty("_q_BTaddress", QVariant::fromValue(address));
+ QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
+ q, SLOT(_q_createdDevice(QDBusPendingCallWatcher*)));
+ return;
+ }
+
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "path" << deviceObjectPath.value().path();
+ discoverServices(deviceObjectPath.value().path());
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWatcher *watcher)
+{
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
+ if (!adapter) {
+ watcher->deleteLater();
+ return;
+ }
+
+ const QBluetoothAddress &address = watcher->property("_q_BTaddress").value<QBluetoothAddress>();
+
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "created" << address.toString();
+
+ QDBusPendingReply<QDBusObjectPath> deviceObjectPath = *watcher;
+ watcher->deleteLater();
+ if (deviceObjectPath.isError()) {
+ if (deviceObjectPath.error().name() != QLatin1String("org.bluez.Error.AlreadyExists")) {
+ qCDebug(QT_BT_BLUEZ) << "Create device failed Error: " << error << deviceObjectPath.error().name();
delete adapter;
adapter = 0;
if (singleDevice) {
@@ -387,13 +418,20 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
emit q->error(error);
}
_q_serviceDiscoveryFinished();
- qCDebug(QT_BT_BLUEZ) << "Can't find device after creation Error: " << error << deviceObjectPath.error().name();
return;
}
}
+ qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "path" << deviceObjectPath.value().path();
+ discoverServices(deviceObjectPath.value().path());
+}
+
+void QBluetoothServiceDiscoveryAgentPrivate::discoverServices(const QString deviceObjectPath)
+{
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+
device = new OrgBluezDeviceInterface(QStringLiteral("org.bluez"),
- deviceObjectPath.value().path(),
+ deviceObjectPath,
QDBusConnection::systemBus());
delete adapter;
adapter = 0;
@@ -482,7 +520,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Discover restrictions:" << pattern;
QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern);
- watcher = new QDBusPendingCallWatcher(discoverReply, q);
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(discoverReply, q);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
q, SLOT(_q_discoveredServices(QDBusPendingCallWatcher*)));
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_p.h b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
index 4a35ffdb..c4d5017a 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_p.h
@@ -108,6 +108,7 @@ public:
#ifdef QT_BLUEZ_BLUETOOTH
void _q_discoveredServices(QDBusPendingCallWatcher *watcher);
void _q_createdDevice(QDBusPendingCallWatcher *watcher);
+ void _q_foundDevice(QDBusPendingCallWatcher *watcher);
//Slots below are used for discovering Bluetooth Low Energy devices. It will be used with Bluez 5.x version.
/*
void _g_discoveredGattService();
@@ -141,6 +142,7 @@ private:
QVariant readAttributeValue(QXmlStreamReader &xml);
QBluetoothServiceInfo parseServiceXml(const QString& xml);
void performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress);
+ void discoverServices(const QString deviceObjectPath);
#endif
public: