1515#include " flutter/fml/platform/android/jni_util.h"
1616#include " flutter/fml/platform/android/jni_weak_ref.h"
1717#include " flutter/fml/platform/android/scoped_java_ref.h"
18+ #include " flutter/lib/ui/plugins/callback_cache.h"
1819#include " flutter/runtime/dart_service_isolate.h"
1920#include " flutter/shell/common/run_configuration.h"
2021#include " flutter/shell/platform/android/android_external_texture_gl.h"
@@ -43,13 +44,28 @@ bool CheckException(JNIEnv* env) {
4344
4445} // anonymous namespace
4546
47+ static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_callback_info_class =
48+ nullptr ;
4649static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_view_class = nullptr ;
4750static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_native_view_class =
4851 nullptr ;
4952static fml::jni::ScopedJavaGlobalRef<jclass>* g_surface_texture_class = nullptr ;
5053
5154// Called By Native
5255
56+ static jmethodID g_flutter_callback_info_constructor = nullptr ;
57+ jobject CreateFlutterCallbackInformation (
58+ JNIEnv* env,
59+ const std::string& callbackName,
60+ const std::string& callbackClassName,
61+ const std::string& callbackLibraryPath) {
62+ return env->NewObject (g_flutter_callback_info_class->obj (),
63+ g_flutter_callback_info_constructor,
64+ env->NewStringUTF (callbackName.c_str ()),
65+ env->NewStringUTF (callbackClassName.c_str ()),
66+ env->NewStringUTF (callbackLibraryPath.c_str ()));
67+ }
68+
5369static jmethodID g_handle_platform_message_method = nullptr ;
5470void FlutterViewHandlePlatformMessage (JNIEnv* env,
5571 jobject obj,
@@ -278,6 +294,15 @@ static void RunBundleAndSnapshotFromLibrary(
278294 ANDROID_SHELL_HOLDER->Launch (std::move (config));
279295}
280296
297+ static jobject LookupCallbackInformation (JNIEnv* env, jlong handle) {
298+ auto cbInfo = blink::DartCallbackCache::GetCallbackInformation (handle);
299+ if (cbInfo == nullptr ) {
300+ return nullptr ;
301+ }
302+ return CreateFlutterCallbackInformation (env, cbInfo->name , cbInfo->class_name ,
303+ cbInfo->library_path );
304+ }
305+
281306static void SetViewportMetrics (JNIEnv* env,
282307 jobject jcaller,
283308 jlong shell_holder,
@@ -504,6 +529,19 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
504529 return false ;
505530 }
506531
532+ g_flutter_callback_info_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
533+ env, env->FindClass (" io/flutter/view/FlutterCallbackInformation" ));
534+ if (g_flutter_callback_info_class->is_null ()) {
535+ return false ;
536+ }
537+
538+ g_flutter_callback_info_constructor = env->GetMethodID (
539+ g_flutter_callback_info_class->obj (), " <init>" ,
540+ " (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V" );
541+ if (g_flutter_callback_info_constructor == nullptr ) {
542+ return false ;
543+ }
544+
507545 g_flutter_view_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
508546 env, env->FindClass (" io/flutter/view/FlutterView" ));
509547 if (g_flutter_view_class->is_null ()) {
@@ -639,6 +677,14 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
639677 },
640678 };
641679
680+ static const JNINativeMethod callback_info_methods[] = {
681+ {
682+ .name = " nativeLookupCallbackInformation" ,
683+ .signature = " (J)Lio/flutter/view/FlutterCallbackInformation;" ,
684+ .fnPtr = reinterpret_cast <void *>(&shell::LookupCallbackInformation),
685+ },
686+ };
687+
642688 if (env->RegisterNatives (g_flutter_native_view_class->obj (),
643689 native_view_methods,
644690 arraysize (native_view_methods)) != 0 ) {
@@ -650,6 +696,12 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
650696 return false ;
651697 }
652698
699+ if (env->RegisterNatives (g_flutter_callback_info_class->obj (),
700+ callback_info_methods,
701+ arraysize (callback_info_methods)) != 0 ) {
702+ return false ;
703+ }
704+
653705 g_handle_platform_message_method =
654706 env->GetMethodID (g_flutter_native_view_class->obj (),
655707 " handlePlatformMessage" , " (Ljava/lang/String;[BI)V" );
0 commit comments