[vlc-devel] [PATCH v2 4/7] android: util: load ClassLoader functions

Alexandre Janniaux ajanni at videolabs.io
Thu Feb 11 08:34:06 UTC 2021


Fill the jclass and findClass in the jfields table.
---
 modules/video_output/android/utils.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index e46b8e004d..96832ad2b3 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -109,12 +109,17 @@ struct vlc_android_jfields
         jclass clazz;
         jmethodID init_st;
     } Surface;
+    struct {
+        jobject instance;
+        jmethodID findClass;
+    } ClassLoader;
 };
 
 struct AWindowHandler
 {
     JavaVM *p_jvm;
     jobject jobj;
+    jobject classloader;
     vout_window_t *wnd;
 
     struct vlc_android_jfields jfields;
@@ -846,6 +851,25 @@ AWindowHandler_new(vlc_object_t *obj, vout_window_t *wnd, awh_events_t *p_events
     /* Zero the jfields structure before usage. */
     p_awh->jfields = (struct vlc_android_jfields) { .AWindow.clazz = NULL };
 
+    p_awh->jfields.ClassLoader.instance = var_InheritAddress(obj, "android-classloader");
+    if (p_awh->jfields.ClassLoader.instance)
+    {
+        jclass ClassLoader_clazz = (*p_env)->GetObjectClass(p_env,
+                p_awh->jfields.ClassLoader.instance);
+        p_awh->jfields.ClassLoader.findClass = (*p_env)->GetMethodID(p_env,
+                ClassLoader_clazz, "findClass",
+                "(Ljava/lang/String;)Ljava/lang/Class;");
+        (*p_env)->DeleteLocalRef(p_env, ClassLoader_clazz);
+        if ((*p_env)->ExceptionCheck(p_env))
+        {
+            msg_Err(obj, "ClassLoader didn't have a findClass method");
+            if (p_awh->jobj)
+                (*p_env)->DeleteGlobalRef(p_env, p_awh->jobj);
+            free(p_awh);
+            return NULL;
+        }
+    }
+
     p_awh->wnd = wnd;
     if (p_events)
         p_awh->event.cb = *p_events;
-- 
2.30.1



More information about the vlc-devel mailing list