|
|
|
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
|
|
|
* (c) 2009-2019 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
|
|
|
* |
|
|
|
|
* QGroundControl is licensed according to the terms in the file |
|
|
|
|
* COPYING.md in the root of the source code directory. |
|
|
|
@ -85,6 +85,84 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
@@ -85,6 +85,84 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
|
|
|
|
|
#include "qserialport.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static jobject _class_loader = nullptr; |
|
|
|
|
static jobject _context = nullptr; |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
extern "C" { |
|
|
|
|
void gst_amc_jni_set_java_vm(JavaVM *java_vm); |
|
|
|
|
|
|
|
|
|
jobject gst_android_get_application_class_loader(void) |
|
|
|
|
{ |
|
|
|
|
return _class_loader; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
static void |
|
|
|
|
gst_android_init(JNIEnv* env, jobject context) |
|
|
|
|
{ |
|
|
|
|
jobject class_loader = nullptr; |
|
|
|
|
|
|
|
|
|
jclass context_cls = env->GetObjectClass(context); |
|
|
|
|
if (!context_cls) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jmethodID get_class_loader_id = env->GetMethodID(context_cls, "getClassLoader", "()Ljava/lang/ClassLoader;"); |
|
|
|
|
if (env->ExceptionCheck()) { |
|
|
|
|
env->ExceptionDescribe(); |
|
|
|
|
env->ExceptionClear(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class_loader = env->CallObjectMethod(context, get_class_loader_id); |
|
|
|
|
if (env->ExceptionCheck()) { |
|
|
|
|
env->ExceptionDescribe(); |
|
|
|
|
env->ExceptionClear(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_context = env->NewGlobalRef(context); |
|
|
|
|
_class_loader = env->NewGlobalRef (class_loader); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
static const char kJniClassName[] {"org/mavlink/qgroundcontrol/QGCActivity"}; |
|
|
|
|
|
|
|
|
|
void setNativeMethods(void) |
|
|
|
|
{ |
|
|
|
|
JNINativeMethod javaMethods[] { |
|
|
|
|
{"nativeInit", "(Landroid/content/Context;)V", reinterpret_cast<void *>(gst_android_init)} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
QAndroidJniEnvironment jniEnv; |
|
|
|
|
if (jniEnv->ExceptionCheck()) { |
|
|
|
|
jniEnv->ExceptionDescribe(); |
|
|
|
|
jniEnv->ExceptionClear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jclass objectClass = jniEnv->FindClass(kJniClassName); |
|
|
|
|
if(!objectClass) { |
|
|
|
|
qWarning() << "Couldn't find class:" << kJniClassName; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jint val = jniEnv->RegisterNatives(objectClass, javaMethods, sizeof(javaMethods) / sizeof(javaMethods[0])); |
|
|
|
|
|
|
|
|
|
if (val < 0) { |
|
|
|
|
qWarning() << "Error registering methods: " << val; |
|
|
|
|
} else { |
|
|
|
|
qDebug() << "Main Native Functions Registered"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (jniEnv->ExceptionCheck()) { |
|
|
|
|
jniEnv->ExceptionDescribe(); |
|
|
|
|
jniEnv->ExceptionClear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
jint JNI_OnLoad(JavaVM* vm, void* reserved) |
|
|
|
|
{ |
|
|
|
|
Q_UNUSED(reserved); |
|
|
|
@ -93,6 +171,18 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
@@ -93,6 +171,18 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|
|
|
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
setNativeMethods(); |
|
|
|
|
|
|
|
|
|
QAndroidJniObject resultL = QAndroidJniObject::callStaticObjectMethod( |
|
|
|
|
kJniClassName, |
|
|
|
|
"jniOnLoad", |
|
|
|
|
"();"); |
|
|
|
|
|
|
|
|
|
#if defined(QGC_GST_STREAMING) |
|
|
|
|
// Tell the androidmedia plugin about the Java VM
|
|
|
|
|
gst_amc_jni_set_java_vm(vm); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if !defined(NO_SERIAL_LINK) |
|
|
|
|
QSerialPort::setNativeMethods(); |
|
|
|
|
#endif |
|
|
|
@ -102,6 +192,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
@@ -102,6 +192,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
#ifdef __android__ |
|
|
|
|
#include <QtAndroid> |
|
|
|
|
bool checkAndroidWritePermission() { |
|
|
|
@ -117,6 +208,7 @@ bool checkAndroidWritePermission() {
@@ -117,6 +208,7 @@ bool checkAndroidWritePermission() {
|
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
/**
|
|
|
|
|
* @brief Starts the application |
|
|
|
|
* |
|
|
|
|