Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1d01869

Browse files
committed
Updated to use DartCallbackCache to lookup callbacks
1 parent b67534f commit 1d01869

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

shell/platform/android/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ java_library("flutter_shell_java") {
132132
"io/flutter/util/PathUtils.java",
133133
"io/flutter/util/Preconditions.java",
134134
"io/flutter/view/AccessibilityBridge.java",
135+
"io/flutter/view/FlutterCallbackInformation.java",
135136
"io/flutter/view/FlutterIsolateStartedEvent.java",
136137
"io/flutter/view/FlutterMain.java",
137138
"io/flutter/view/FlutterNativeView.java",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.view;
6+
7+
public final class FlutterCallbackInformation {
8+
final public String callbackName;
9+
final public String callbackClassName;
10+
final public String callbackLibraryPath;
11+
12+
public static FlutterCallbackInformation lookupCallbackInformation(long handle) {
13+
return nativeLookupCallbackInformation(handle);
14+
}
15+
16+
private FlutterCallbackInformation(String callbackName, String callbackClassName, String callbackLibraryPath) {
17+
this.callbackName = callbackName;
18+
this.callbackClassName = callbackClassName;
19+
this.callbackLibraryPath = callbackLibraryPath;
20+
}
21+
22+
private static native FlutterCallbackInformation nativeLookupCallbackInformation(long handle);
23+
}

shell/platform/android/platform_view_android_jni.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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;
4649
static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_view_class = nullptr;
4750
static fml::jni::ScopedJavaGlobalRef<jclass>* g_flutter_native_view_class =
4851
nullptr;
4952
static 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+
5369
static jmethodID g_handle_platform_message_method = nullptr;
5470
void 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+
281306
static 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");

travis/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ FILE: ../../../flutter/lib/ui/window/window.h
202202
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
203203
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc
204204
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/JSONUtil.java
205+
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterIsolateStartedEvent.java
205206
FILE: ../../../flutter/shell/platform/darwin/desktop/Info.plist
206207
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec
207208
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Info.plist
@@ -501,6 +502,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor
501502
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistry.java
502503
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewRegistryImpl.java
503504
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java
505+
FILE: ../../../flutter/shell/platform/android/io/flutter/view/FlutterCallbackInformation.java
504506
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterCallbackCache.h
505507
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h
506508
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterCallbackCache.mm

0 commit comments

Comments
 (0)