diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-02-20 11:39:09 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-27 13:00:40 +0100 |
commit | 9d6057f3fa0b51ee2d36ad931072d2a3c816d0a6 (patch) | |
tree | abd3b315377daadd57f2c5356c5512b1020fe349 /src/bluetooth/android/jni_android.cpp | |
parent | ae1a2b8b0149b473190623910a98096c3f117328 (diff) |
Android: Fix crash in QBluetoothServer::close()
Java's BluetoothSocketServer.accept() is meant to be interrupted
via BluetoothSocketServer.close(). Unfortunately if the surrounding
thread is a QThread the returning accept call crashes the thread. This
does not happen if it is a Java Thread.
This commit changes the server's private backend to a Java thread.
Task-number: QTBUG-36754
Change-Id: I5aacc5444bbcd1275a11743b6aa04d2b11a5b22b
Reviewed-by: Nedim Hadzic <nedimhadzija@gmail.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/bluetooth/android/jni_android.cpp')
-rw-r--r-- | src/bluetooth/android/jni_android.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp index eb1fc2dd..ce0f19ca 100644 --- a/src/bluetooth/android/jni_android.cpp +++ b/src/bluetooth/android/jni_android.cpp @@ -46,6 +46,7 @@ #include <QtBluetooth/qbluetoothglobal.h> #include <QtAndroidExtras/QAndroidJniObject> #include "android/androidbroadcastreceiver_p.h" +#include "android/serveracceptancethread_p.h" Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID) @@ -55,9 +56,28 @@ void QtBroadcastReceiver_jniOnReceive(JNIEnv *env, jobject /*javaObject*/, reinterpret_cast<AndroidBroadcastReceiver*>(qtObject)->onReceive(env, context, intent); } +static void QtBluetoothSocketServer_errorOccurred(JNIEnv */*env*/, jobject /*javaObject*/, + jlong qtObject, jint errorCode) +{ + reinterpret_cast<ServerAcceptanceThread*>(qtObject)->javaThreadErrorOccurred(errorCode); +} + +static void QtBluetoothSocketServer_newSocket(JNIEnv */*env*/, jobject /*javaObject*/, + jlong qtObject, jobject socket) +{ + reinterpret_cast<ServerAcceptanceThread*>(qtObject)->javaNewSocket(socket); +} + static JNINativeMethod methods[] = { {"jniOnReceive", "(JLandroid/content/Context;Landroid/content/Intent;)V", - (void *) QtBroadcastReceiver_jniOnReceive}, + (void *) QtBroadcastReceiver_jniOnReceive}, +}; + +static JNINativeMethod methods_server[] = { + {"errorOccurred", "(JI)V", + (void *) QtBluetoothSocketServer_errorOccurred}, + {"newSocket", "(JLandroid/bluetooth/BluetoothSocket;)V", + (void *) QtBluetoothSocketServer_newSocket}, }; static const char logTag[] = "QtBluetooth"; @@ -75,8 +95,15 @@ static bool registerNatives(JNIEnv *env) jclass clazz; FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver"); + if (env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])) < 0) { - __android_log_print(ANDROID_LOG_FATAL, logTag, "RegisterNatives failed"); + __android_log_print(ANDROID_LOG_FATAL, logTag, "RegisterNatives for BraodcastReceiver failed"); + return false; + } + + FIND_AND_CHECK_CLASS("org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer"); + if (env->RegisterNatives(clazz, methods_server, sizeof(methods_server) / sizeof(methods_server[0])) < 0) { + __android_log_print(ANDROID_LOG_FATAL, logTag, "RegisterNatives for SocketServer failed"); return false; } |