androidmedia: Fix crashes when loading the plugin in a standalone application on Android >= 4.4
Check if libnativehelper is loaded in the process and if it has these awful wrappers for JNI_CreateJavaVM and JNI_GetCreatedJavaVMs that crash the app if you don't create a JniInvocation instance first. If it isn't we just fail here and don't initialize anything. See this code for reference: https://android.googlesource.com/platform/libnativehelper/+/master/JniInvocation.cpp
This commit is contained in:
parent
16fd917632
commit
0c93a82861
@ -353,6 +353,37 @@ gst_amc_get_jni_env (void)
|
|||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
check_nativehelper (void)
|
||||||
|
{
|
||||||
|
GModule *module;
|
||||||
|
void **jni_invocation = NULL;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
module = g_module_open (NULL, G_MODULE_BIND_LOCAL);
|
||||||
|
if (!module)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
/* Check if libnativehelper is loaded in the process and if
|
||||||
|
* it has these awful wrappers for JNI_CreateJavaVM and
|
||||||
|
* JNI_GetCreatedJavaVMs that crash the app if you don't
|
||||||
|
* create a JniInvocation instance first. If it isn't we
|
||||||
|
* just fail here and don't initialize anything.
|
||||||
|
* See this code for reference:
|
||||||
|
* https://android.googlesource.com/platform/libnativehelper/+/master/JniInvocation.cpp
|
||||||
|
*/
|
||||||
|
if (!g_module_symbol (module, "_ZN13JniInvocation15jni_invocation_E",
|
||||||
|
(gpointer *) & jni_invocation)) {
|
||||||
|
ret = TRUE;
|
||||||
|
} else {
|
||||||
|
ret = (jni_invocation != NULL && *jni_invocation != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_module_close (module);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
load_java_module (const gchar * name)
|
load_java_module (const gchar * name)
|
||||||
{
|
{
|
||||||
@ -391,6 +422,18 @@ initialize_java_vm (void)
|
|||||||
{
|
{
|
||||||
jsize n_vms;
|
jsize n_vms;
|
||||||
|
|
||||||
|
/* Returns TRUE if we can safely
|
||||||
|
* a) get the current VMs and
|
||||||
|
* b) start a VM if none is started yet
|
||||||
|
*
|
||||||
|
* FIXME: On Android >= 4.4 we won't be able to safely start a
|
||||||
|
* VM on our own without using private C++ API!
|
||||||
|
*/
|
||||||
|
if (!check_nativehelper ()) {
|
||||||
|
GST_ERROR ("Can't safely check for VMs or start a VM");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!load_java_module (NULL)) {
|
if (!load_java_module (NULL)) {
|
||||||
if (!load_java_module ("libdvm"))
|
if (!load_java_module ("libdvm"))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user