From cd00ce1a7128cf11fa59e7a03bec49ea69425f54 Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 13 Dec 2015 03:45:51 +0100 Subject: Establish an HFP connection using Bluez on Sailfish --- rpm/sapd.yaml | 1 + sapbtlistener.cc | 37 ++++++++++++++++++++++++++++++++----- sapd.pro | 4 ++-- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/rpm/sapd.yaml b/rpm/sapd.yaml index 59681f6..c7798eb 100644 --- a/rpm/sapd.yaml +++ b/rpm/sapd.yaml @@ -20,6 +20,7 @@ PkgConfigBR: - openssl - dbus-1 - timed-qt5 + - bluez-qt5 PkgBR: # Workaround current sailfish qt5connectivity packaging bug diff --git a/sapbtlistener.cc b/sapbtlistener.cc index 40c7ac6..2265516 100644 --- a/sapbtlistener.cc +++ b/sapbtlistener.cc @@ -4,6 +4,12 @@ #include "sapbtlistener.h" #include "sapbtpeer.h" +#ifdef SAILFISH +#include +#include +#include +#include +#endif #ifdef DESKTOP #include "hfpag.h" #endif @@ -111,17 +117,38 @@ void SAPBTListener::nudge(const QBluetoothAddress &address) qDebug() << "Nudging" << address.toString(); + // First, set up HFP/Headset connection to watch +#if SAILFISH + QDBusConnection bus = QDBusConnection::systemBus(); + OrgBluezManagerInterface manager("org.bluez", "/", bus); + QDBusReply defaultAdapter = manager.DefaultAdapter(); + if (!defaultAdapter.isValid()) { + qWarning() << "Could not get default Bluez adapter:" << defaultAdapter.error().message(); + } + OrgBluezAdapterInterface adapter("org.bluez", defaultAdapter.value().path(), bus); + QList list = adapter.ListDevices(); + foreach (QDBusObjectPath item, list) { + OrgBluezDeviceInterface device("org.bluez", item.path(), bus); + QVariantMap properties = device.GetProperties(); + QBluetoothAddress devAddress(properties["Address"].toString()); + qDebug() << "Found bluez device with address" << devAddress.toString(); + if (devAddress == address) { + OrgBluezHeadsetInterface headset("org.bluez", item.path(), bus); + qDebug() << "Creating HFP connection to" << devAddress.toString(); + headset.Connect(); + } + } +#elif DESKTOP + new HfpAg(address, this); +#endif + + // After that, start normal connection. #if SAILFISH // For some reason, using UUIDs here fails on SailfishOS socket->connectToService(address, 1); #else socket->connectToService(address, SAProtocol::nudgeServiceUuid); #endif - -#if DESKTOP - // At the same time set up and HFP connection to the watch. - new HfpAg(address, this); -#endif } void SAPBTListener::acceptConnection() diff --git a/sapd.pro b/sapd.pro index d29aca3..829254f 100644 --- a/sapd.pro +++ b/sapd.pro @@ -6,10 +6,10 @@ CONFIG += console c++11 CONFIG += link_pkgconfig PKGCONFIG += openssl -exists(/usr/lib/libsailfishapp.so) { +exists(/usr/lib/pkgconfig/sailfishapp.pc) { # Building for Jolla Sailfish, Qt5, Bluez4(?) DEFINES += SAILFISH - PKGCONFIG += dbus-1 timed-qt5 + PKGCONFIG += dbus-1 timed-qt5 bluez-qt5 SOURCES += libwatchfish/notificationmonitor.cpp libwatchfish/notification.cpp \ libwatchfish/walltimemonitor.cpp HEADERS += libwatchfish/notificationmonitor.h libwatchfish/notificationmonitor_p.h libwatchfish/notification.h \ -- cgit v1.2.3