summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothsocket_p.h
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-03-19 15:21:33 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-03-30 09:26:12 +0000
commite49ef4af0b202ef0387d6a76abd451f75760d1b8 (patch)
tree01dbab2ff387c2ca81d5ea32d8e49507faef2417 /src/bluetooth/qbluetoothsocket_p.h
parent3770dcf6dbfadd88c16beaa4d510dc16b519d4b8 (diff)
Android: Fix crash when destructing socket during active connect
Calling BluetoothSocket.connect in Java blocks for a certain amount of time. Previously, QtConcurrent::run() was used to separate the Java connect() call out into a different thread. Since the function executed by QtConcurrent and the user facing class shared data fields, a crash occurred if the user deleted QBluetoothSocket while QtConcurrent hadn't executed its service connect call yet. The problem is solved by using QThread and Standard signal/slots which separates the shared data members. The only remaining shared data member is Java's BluetoothSocket instance which is shared via QAndroidJniObject references. This is no problem as deleting one reference retains the other reference. Calling close() on an Android BluetoothSocket while a connect() is ongoing seems to be buggy. Sometimes the close() returns, the pending connect() throws an exception but the physical connection still gets established. To avoid this the patch queues the close() call up until after the connect() statement has returned. It is accepted behavior that the connection might still get enabled for a very brief moment despite a close() being issues before the connect() actually finished. The SocketConnectThread cleans itself up once the thread finished(). Task-number: QTBUG-44930 Change-Id: I8324497a7395de390529ecd0b97b1a326cd78f63 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qbluetoothsocket_p.h')
-rw-r--r--src/bluetooth/qbluetoothsocket_p.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/bluetooth/qbluetoothsocket_p.h b/src/bluetooth/qbluetoothsocket_p.h
index e95af465..dc490f26 100644
--- a/src/bluetooth/qbluetoothsocket_p.h
+++ b/src/bluetooth/qbluetoothsocket_p.h
@@ -52,8 +52,10 @@
#endif
#ifdef QT_ANDROID_BLUETOOTH
#include <QtAndroidExtras/QAndroidJniObject>
+#include <QtCore/QPointer>
#include "android/inputstreamthread_p.h"
#include <jni.h>
+class WorkerThread;
#endif
#ifndef QPRIVATELINEARBUFFER_BUFFERSIZE
@@ -93,18 +95,14 @@ public:
~QBluetoothSocketPrivate();
//On QNX and Android we connect using the uuid not the port
-#if defined(QT_QNX_BLUETOOTH)
- void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, QIODevice::OpenMode openMode);
-#elif defined(QT_ANDROID_BLUETOOTH)
+#if defined(QT_QNX_BLUETOOTH) || defined(QT_ANDROID_BLUETOOTH)
void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid,
- QIODevice::OpenMode openMode, int fallbackServiceChannel = 1);
- bool fallBackConnect(QAndroidJniObject uuid, int channel);
+ QIODevice::OpenMode openMode);
#else
void connectToService(const QBluetoothAddress &address, quint16 port, QIODevice::OpenMode openMode);
#endif
#ifdef QT_ANDROID_BLUETOOTH
- void connectToServiceConc(const QBluetoothAddress &address, const QBluetoothUuid &uuid,
- QIODevice::OpenMode openMode, int fallbackServiceChannel = 1);
+ bool fallBackConnect(QAndroidJniObject uuid, int channel);
#endif
@@ -166,9 +164,18 @@ public:
QAndroidJniObject outputStream;
InputStreamThread *inputThread;
-private slots:
+public slots:
+ void socketConnectSuccess(const QAndroidJniObject &socket);
+ void defaultSocketConnectFailed(const QAndroidJniObject & socket,
+ const QAndroidJniObject &targetUuid);
+ void fallbackSocketConnectFailed(const QAndroidJniObject &socket,
+ const QAndroidJniObject &targetUuid);
void inputThreadError(int errorCode);
+signals:
+ void connectJavaSocket();
+ void closeJavaSocket();
+
#endif
#if defined(QT_QNX_BLUETOOTH) || defined(QT_BLUEZ_BLUETOOTH)