From db58c8691d9a0d6f9ee9226658b0fd6508a52c12 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 26 Apr 2018 08:59:00 +0200 Subject: Add missing emission of readChannelFinished() This fixes the problem for all supported platforms. Task-number: QTBUG-67672 Change-Id: I9cecfbe8a73df46070293eba1870ea3bee738b7b Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothsocket_android.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/bluetooth/qbluetoothsocket_android.cpp') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index d0b901ae..a70b95a2 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -779,6 +779,7 @@ void QBluetoothSocketPrivate::inputThreadError(int errorCode) q->setSocketState(QBluetoothSocket::UnconnectedState); q->setOpenMode(QIODevice::NotOpen); + emit q->readChannelFinished(); emit q->disconnected(); } -- cgit v1.2.1 From 28eeb7afc27e99deeb52eefe10cdd458c7621698 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 18 Jul 2018 11:03:53 +0200 Subject: Add runtime polymorphism for QBluetoothSocketPrivate This patch introduces a generic interface towards QBluetoothSocketPrivate. Later on, the QBluetoothSocketPrivate class will be split into platform specific overloads/interfaces. Ultimately, this will be needed to support runtime selection of the QBluetootSocket d-pointer on Linux. The Linux Bluez5 implementation is significantly different from the Bluez4 (raw socket) implementation. Since recent Bluez5 releases the raw socket implementation is no longer functional and/or the user has to have root permission and enable bluetooth --compat mode. Therefore a second QBluetoothSocket for the dbus socket API is needed. QBLuetoothSocket has to choose at runtime (during its instanciation) which implementation to use. Task-number: QTBUG-68550 Change-Id: I5d0b8e24b8acd1b149b897f52f0d82eade7f3823 Reviewed-by: Oliver Wolff Reviewed-by: Timur Pocheptsov Reviewed-by: Lubomir I. Ivanov --- src/bluetooth/qbluetoothsocket_android.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket_android.cpp') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index a70b95a2..9a81fc3a 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -205,15 +205,10 @@ static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid) } QBluetoothSocketPrivate::QBluetoothSocketPrivate() - : socket(-1), - socketType(QBluetoothServiceInfo::UnknownProtocol), - state(QBluetoothSocket::UnconnectedState), - socketError(QBluetoothSocket::NoSocketError), - connecting(false), - discoveryAgent(0), - secFlags(QBluetooth::Secure), + : inputThread(0) { + secFlags = QBluetooth::Secure; adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter", "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;"); -- cgit v1.2.1 From 40beb226dfe8c23f290d554d5449806e91227f7e Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 19 Jul 2018 17:37:40 +0200 Subject: Add QBluetoothSocketPrivate interface for Android Task-number: QTBUG-68550 Change-Id: Iac05cccd4f6e1b44a30568fb9b6c9171204b53fd Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_android.cpp | 68 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket_android.cpp') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 9a81fc3a..42fe4ff4 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ #include "qbluetoothsocket.h" -#include "qbluetoothsocket_p.h" +#include "qbluetoothsocket_android_p.h" #include "qbluetoothaddress.h" #include #include @@ -148,8 +148,8 @@ public: { } - // Runs in same thread as QBluetoothSocketPrivate - void setupWorker(QBluetoothSocketPrivate* d_ptr, const QAndroidJniObject& socketObject, + // Runs in same thread as QBluetoothSocketPrivateAndroid + void setupWorker(QBluetoothSocketPrivateAndroid* d_ptr, const QAndroidJniObject& socketObject, const QAndroidJniObject& uuidObject, bool useFallback, const QBluetoothUuid& qtUuid = QBluetoothUuid()) { @@ -159,18 +159,18 @@ public: connect(this, &QThread::finished, worker, &QObject::deleteLater); connect(this, &QThread::finished, this, &QObject::deleteLater); - connect(d_ptr, &QBluetoothSocketPrivate::connectJavaSocket, + connect(d_ptr, &QBluetoothSocketPrivateAndroid::connectJavaSocket, worker, &SocketConnectWorker::connectSocket); - connect(d_ptr, &QBluetoothSocketPrivate::closeJavaSocket, + connect(d_ptr, &QBluetoothSocketPrivateAndroid::closeJavaSocket, worker, &SocketConnectWorker::closeSocket); connect(worker, &SocketConnectWorker::socketConnectDone, - d_ptr, &QBluetoothSocketPrivate::socketConnectSuccess); + d_ptr, &QBluetoothSocketPrivateAndroid::socketConnectSuccess); if (useFallback) { connect(worker, &SocketConnectWorker::socketConnectFailed, - d_ptr, &QBluetoothSocketPrivate::fallbackSocketConnectFailed); + d_ptr, &QBluetoothSocketPrivateAndroid::fallbackSocketConnectFailed); } else { connect(worker, &SocketConnectWorker::socketConnectFailed, - d_ptr, &QBluetoothSocketPrivate::defaultSocketConnectFailed); + d_ptr, &QBluetoothSocketPrivateAndroid::defaultSocketConnectFailed); } workerPointer = worker; @@ -204,7 +204,7 @@ static QBluetoothUuid reverseUuid(const QBluetoothUuid &serviceUuid) return QBluetoothUuid(reversed); } -QBluetoothSocketPrivate::QBluetoothSocketPrivate() +QBluetoothSocketPrivateAndroid::QBluetoothSocketPrivateAndroid() : inputThread(0) { @@ -216,13 +216,13 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate() qRegisterMetaType(); } -QBluetoothSocketPrivate::~QBluetoothSocketPrivate() +QBluetoothSocketPrivateAndroid::~QBluetoothSocketPrivateAndroid() { if (state != QBluetoothSocket::UnconnectedState) emit closeJavaSocket(); } -bool QBluetoothSocketPrivate::ensureNativeSocket(QBluetoothServiceInfo::Protocol type) +bool QBluetoothSocketPrivateAndroid::ensureNativeSocket(QBluetoothServiceInfo::Protocol type) { socketType = type; if (socketType == QBluetoothServiceInfo::RfcommProtocol) @@ -231,7 +231,7 @@ bool QBluetoothSocketPrivate::ensureNativeSocket(QBluetoothServiceInfo::Protocol return false; } -bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channel) +bool QBluetoothSocketPrivateAndroid::fallBackConnect(QAndroidJniObject uuid, int channel) { qCWarning(QT_BT_ANDROID) << "Falling back to getServiceChannel() workaround."; @@ -350,7 +350,7 @@ bool QBluetoothSocketPrivate::fallBackConnect(QAndroidJniObject uuid, int channe /* * Workaround for QTBUG-61392 */ -bool QBluetoothSocketPrivate::fallBackReversedConnect(const QBluetoothUuid &uuid) +bool QBluetoothSocketPrivateAndroid::fallBackReversedConnect(const QBluetoothUuid &uuid) { Q_Q(QBluetoothSocket); @@ -420,7 +420,7 @@ bool QBluetoothSocketPrivate::fallBackReversedConnect(const QBluetoothUuid &uuid * 8. if threaded connect on fallback channel fails call fallbackSocketConnectFailed() * -> complete failure of entire connectToService() * */ -void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, +void QBluetoothSocketPrivateAndroid::connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, QIODevice::OpenMode openMode) { @@ -503,7 +503,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address, emit connectJavaSocket(); } -void QBluetoothSocketPrivate::socketConnectSuccess(const QAndroidJniObject &socket) +void QBluetoothSocketPrivateAndroid::socketConnectSuccess(const QAndroidJniObject &socket) { Q_Q(QBluetoothSocket); QAndroidJniEnvironment env; @@ -563,7 +563,7 @@ void QBluetoothSocketPrivate::socketConnectSuccess(const QAndroidJniObject &sock emit q->connected(); } -void QBluetoothSocketPrivate::defaultSocketConnectFailed( +void QBluetoothSocketPrivateAndroid::defaultSocketConnectFailed( const QAndroidJniObject &socket, const QAndroidJniObject &targetUuid, const QBluetoothUuid &qtTargetUuid) { @@ -592,7 +592,7 @@ void QBluetoothSocketPrivate::defaultSocketConnectFailed( } } -void QBluetoothSocketPrivate::fallbackSocketConnectFailed( +void QBluetoothSocketPrivateAndroid::fallbackSocketConnectFailed( const QAndroidJniObject &socket, const QAndroidJniObject &targetUuid) { Q_UNUSED(targetUuid); @@ -611,7 +611,7 @@ void QBluetoothSocketPrivate::fallbackSocketConnectFailed( q->setSocketState(QBluetoothSocket::UnconnectedState); } -void QBluetoothSocketPrivate::abort() +void QBluetoothSocketPrivateAndroid::abort() { if (state == QBluetoothSocket::UnconnectedState) return; @@ -624,7 +624,7 @@ void QBluetoothSocketPrivate::abort() * thread because inputStream.read() throws IOException * In turn the thread stops and throws an error which sets * new state, error and emits relevant signals. - * See QBluetoothSocketPrivate::inputThreadError() for details + * See QBluetoothSocketPrivateAndroid::inputThreadError() for details */ if (inputThread) @@ -653,7 +653,7 @@ void QBluetoothSocketPrivate::abort() } } -QString QBluetoothSocketPrivate::localName() const +QString QBluetoothSocketPrivateAndroid::localName() const { if (adapter.isValid()) return adapter.callObjectMethod("getName").toString(); @@ -661,7 +661,7 @@ QString QBluetoothSocketPrivate::localName() const return QString(); } -QBluetoothAddress QBluetoothSocketPrivate::localAddress() const +QBluetoothAddress QBluetoothSocketPrivateAndroid::localAddress() const { QString result; if (adapter.isValid()) @@ -670,13 +670,13 @@ QBluetoothAddress QBluetoothSocketPrivate::localAddress() const return QBluetoothAddress(result); } -quint16 QBluetoothSocketPrivate::localPort() const +quint16 QBluetoothSocketPrivateAndroid::localPort() const { // Impossible to get channel number with current Android API (Levels 5 to 19) return 0; } -QString QBluetoothSocketPrivate::peerName() const +QString QBluetoothSocketPrivateAndroid::peerName() const { if (!remoteDevice.isValid()) return QString(); @@ -684,7 +684,7 @@ QString QBluetoothSocketPrivate::peerName() const return remoteDevice.callObjectMethod("getName", "()Ljava/lang/String;").toString(); } -QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const +QBluetoothAddress QBluetoothSocketPrivateAndroid::peerAddress() const { if (!remoteDevice.isValid()) return QBluetoothAddress(); @@ -695,13 +695,13 @@ QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const return QBluetoothAddress(address); } -quint16 QBluetoothSocketPrivate::peerPort() const +quint16 QBluetoothSocketPrivateAndroid::peerPort() const { // Impossible to get channel number with current Android API (Levels 5 to 13) return 0; } -qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) +qint64 QBluetoothSocketPrivateAndroid::writeData(const char *data, qint64 maxSize) { //TODO implement buffered behavior (so far only unbuffered) Q_Q(QBluetoothSocket); @@ -731,7 +731,7 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize) return maxSize; } -qint64 QBluetoothSocketPrivate::readData(char *data, qint64 maxSize) +qint64 QBluetoothSocketPrivateAndroid::readData(char *data, qint64 maxSize) { Q_Q(QBluetoothSocket); if (state != QBluetoothSocket::ConnectedState || !inputThread) { @@ -744,7 +744,7 @@ qint64 QBluetoothSocketPrivate::readData(char *data, qint64 maxSize) return inputThread->readData(data, maxSize); } -void QBluetoothSocketPrivate::inputThreadError(int errorCode) +void QBluetoothSocketPrivateAndroid::inputThreadError(int errorCode) { Q_Q(QBluetoothSocket); @@ -778,7 +778,7 @@ void QBluetoothSocketPrivate::inputThreadError(int errorCode) emit q->disconnected(); } -void QBluetoothSocketPrivate::close() +void QBluetoothSocketPrivateAndroid::close() { /* This function is called by QBluetoothSocket::close and softer version QBluetoothSocket::disconnectFromService() which difference I do not quite fully understand. @@ -787,7 +787,7 @@ void QBluetoothSocketPrivate::close() abort(); } -bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, +bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType, QBluetoothSocket::SocketState socketState, QBluetoothSocket::OpenMode openMode) { Q_UNUSED(socketDescriptor); @@ -798,7 +798,7 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoo return false; } -bool QBluetoothSocketPrivate::setSocketDescriptor(const QAndroidJniObject &socket, QBluetoothServiceInfo::Protocol socketType_, +bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(const QAndroidJniObject &socket, QBluetoothServiceInfo::Protocol socketType_, QBluetoothSocket::SocketState socketState, QBluetoothSocket::OpenMode openMode) { Q_Q(QBluetoothSocket); @@ -866,7 +866,7 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(const QAndroidJniObject &socke return true; } -qint64 QBluetoothSocketPrivate::bytesAvailable() const +qint64 QBluetoothSocketPrivateAndroid::bytesAvailable() const { //We cannot access buffer directly as it is part of different thread if (inputThread) @@ -875,12 +875,12 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const return 0; } -qint64 QBluetoothSocketPrivate::bytesToWrite() const +qint64 QBluetoothSocketPrivateAndroid::bytesToWrite() const { return 0; // nothing because always unbuffered } -bool QBluetoothSocketPrivate::canReadLine() const +bool QBluetoothSocketPrivateAndroid::canReadLine() const { // We cannot access buffer directly as it is part of different thread if (inputThread) -- cgit v1.2.1 From 81de083e4f9fdee7f1ef7d2fffc7d2147ddbc1b0 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 20 Jul 2018 16:19:13 +0200 Subject: Rename QBluetoothSocketBasePrivate::connectToService() The goal is to move the various QBluetoothSocket::connectoService() implementations into the private classes. Common parts can be split into QBluetoothSocketBasePrivate and the platform specific code. The code becomes cleaner and has less ifdefs. However this creates a symbol clash with the currently existing private implementation as it has a function with the same signature but different purpose. This rename provides the foundation for future changes. Task-number: QTBUG-68550 Change-Id: I121f08d93e00790c1619c0449629f47bca8a964d Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_android.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket_android.cpp') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 42fe4ff4..109d3141 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -403,31 +403,31 @@ bool QBluetoothSocketPrivateAndroid::fallBackReversedConnect(const QBluetoothUui } /* - * The call order during a connectToService() is as follows: + * The call order during a connectToServiceHelper() is as follows: * - * 1. call connectToService() + * 1. call connectToServiceHelper() * 2. wait for execution of SocketConnectThread::run() * 3. if threaded connect succeeds call socketConnectSuccess() via signals * -> done * 4. if threaded connect fails call defaultSocketConnectFailed() via signals * 5. call fallBackConnect() if Android version 22 or below - * -> Android 23+ complete failure of entire connectToService() + * -> Android 23+ complete failure of entire connectToServiceHelper() * 6. call fallBackReversedConnect() if Android version 23 or above - * -> if failure entire connectToService() fails + * -> if failure entire connectToServiceHelper() fails * 7. if threaded connect on one of above fallbacks succeeds call socketConnectSuccess() * via signals * -> done * 8. if threaded connect on fallback channel fails call fallbackSocketConnectFailed() - * -> complete failure of entire connectToService() + * -> complete failure of entire connectToServiceHelper() * */ -void QBluetoothSocketPrivateAndroid::connectToService(const QBluetoothAddress &address, +void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddress &address, const QBluetoothUuid &uuid, QIODevice::OpenMode openMode) { Q_Q(QBluetoothSocket); Q_UNUSED(openMode); - qCDebug(QT_BT_ANDROID) << "connectToService()" << address.toString() << uuid.toString(); + qCDebug(QT_BT_ANDROID) << "connectToServiceHelper()" << address.toString() << uuid.toString(); q->setSocketState(QBluetoothSocket::ConnectingState); -- cgit v1.2.1 From e84d9f24cbb7c686535cbe7e13f28a1c0baaa48d Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 23 Jul 2018 13:13:49 +0200 Subject: Move QBluetoothSocket::connectToService() to private implementations This permits each platform to customize the implementations without the need for ifdefs. Upcoming changes such as the BLuez DBuS addition will increase the platform differences. Task-number: QTBUG-68550 Change-Id: I8fc9a74d3ce704466f0bf2c16287e32f222c4376 Reviewed-by: Lubomir I. Ivanov Reviewed-by: Oliver Wolff --- src/bluetooth/qbluetoothsocket_android.cpp | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'src/bluetooth/qbluetoothsocket_android.cpp') diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index 109d3141..9047bb31 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -41,6 +41,8 @@ #include "qbluetoothsocket.h" #include "qbluetoothsocket_android_p.h" #include "qbluetoothaddress.h" +#include "qbluetoothdeviceinfo.h" +#include "qbluetoothserviceinfo.h" #include #include #include @@ -503,6 +505,70 @@ void QBluetoothSocketPrivateAndroid::connectToServiceHelper(const QBluetoothAddr emit connectJavaSocket(); } +void QBluetoothSocketPrivateAndroid::connectToService( + const QBluetoothServiceInfo &service, QIODevice::OpenMode openMode) +{ + Q_Q(QBluetoothSocket); + + if (q->state() != QBluetoothSocket::UnconnectedState + && q->state() != QBluetoothSocket::ServiceLookupState) { + qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService called on busy socket"; + errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress"); + q->setSocketError(QBluetoothSocket::OperationError); + return; + } + + if (!ensureNativeSocket(service.socketProtocol())) { + errorString = QBluetoothSocket::tr("Socket type not supported"); + q->setSocketError(QBluetoothSocket::UnsupportedProtocolError); + return; + } + connectToServiceHelper(service.device().address(), service.serviceUuid(), openMode); +} + +void QBluetoothSocketPrivateAndroid::connectToService( + const QBluetoothAddress &address, const QBluetoothUuid &uuid, + QIODevice::OpenMode openMode) +{ + Q_Q(QBluetoothSocket); + + if (q->state() != QBluetoothSocket::UnconnectedState) { + qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService called on busy socket"; + errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress"); + q->setSocketError(QBluetoothSocket::OperationError); + return; + } + + if (q->socketType() == QBluetoothServiceInfo::UnknownProtocol) { + qCWarning(QT_BT_ANDROID) << "QBluetoothSocketPrivateAndroid::connectToService cannot " + "connect with 'UnknownProtocol' (type provided by given service)"; + errorString = QBluetoothSocket::tr("Socket type not supported"); + q->setSocketError(QBluetoothSocket::UnsupportedProtocolError); + return; + } + + if (!ensureNativeSocket(q->socketType())) { + errorString = QBluetoothSocket::tr("Socket type not supported"); + q->setSocketError(QBluetoothSocket::UnsupportedProtocolError); + return; + } + connectToServiceHelper(address, uuid, openMode); +} + +void QBluetoothSocketPrivateAndroid::connectToService( + const QBluetoothAddress &address, quint16 port, QIODevice::OpenMode openMode) +{ + Q_UNUSED(port); + Q_UNUSED(openMode); + Q_UNUSED(address); + + Q_Q(QBluetoothSocket); + + errorString = tr("Connecting to port is not supported"); + q->setSocketError(QBluetoothSocket::ServiceNotFoundError); + qCWarning(QT_BT_ANDROID) << "Connecting to port is not supported"; +} + void QBluetoothSocketPrivateAndroid::socketConnectSuccess(const QAndroidJniObject &socket) { Q_Q(QBluetoothSocket); -- cgit v1.2.1