Browse Source

Merge pull request #7449 from MatejFranceskin/pr-fix-jni-crash

Set Android Joystick native methods from JNI_OnLoad
QGC4.4
Don Gagne 6 years ago committed by GitHub
parent
commit
a7c5f11a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Joystick/JoystickAndroid.cc
  2. 4
      src/Joystick/JoystickAndroid.h
  3. 9
      src/main.cc

8
src/Joystick/JoystickAndroid.cc

@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr; @@ -211,9 +211,7 @@ static JoystickManager *_manager = nullptr;
//helper method
bool JoystickAndroid::init(JoystickManager *manager) {
if (_manager == nullptr) {
setNativeMethods(manager);
}
_manager = manager;
//this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports
//instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change
@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA) @@ -267,12 +265,10 @@ static void jniUpdateAvailableJoysticks(JNIEnv *envA, jobject thizA)
}
}
void JoystickAndroid::setNativeMethods(JoystickManager *manager)
void JoystickAndroid::setNativeMethods()
{
qCDebug(JoystickLog) << "Registering Native Functions";
_manager = manager;
// REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod javaMethods[] {
{"nativeUpdateAvailableJoysticks", "()V", reinterpret_cast<void *>(jniUpdateAvailableJoysticks)}

4
src/Joystick/JoystickAndroid.h

@ -21,14 +21,14 @@ public: @@ -21,14 +21,14 @@ public:
static bool init(JoystickManager *manager);
static void setNativeMethods();
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
private:
bool handleKeyEvent(jobject event);
bool handleGenericMotionEvent(jobject event);
static void setNativeMethods(JoystickManager *manager);
virtual bool _open();
virtual void _close();
virtual bool _update();

9
src/main.cc

@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue) @@ -78,9 +78,12 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
#endif
#if defined(__android__) && !defined(NO_SERIAL_LINK)
#if defined(__android__)
#include <jni.h>
#include "JoystickAndroid.h"
#if !defined(NO_SERIAL_LINK)
#include "qserialport.h"
#endif
jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) @@ -90,8 +93,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return -1;
}
#if !defined(NO_SERIAL_LINK)
QSerialPort::setNativeMethods();
#endif
JoystickAndroid::setNativeMethods();
return JNI_VERSION_1_6;
}

Loading…
Cancel
Save