From e77f19e2ccbf04b04f7bfe2d55b33bb07e11816a Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Mon, 22 Jun 2020 22:51:21 -0700 Subject: [PATCH 1/2] Use public accessor and move keep annotation --- .../engine/FlutterOverlaySurface.java | 2 +- .../android/platform_view_android_jni_impl.cc | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java b/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java index 05a3bdafb0c8c..64711d66cf26f 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java @@ -8,12 +8,12 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; +@Keep public class FlutterOverlaySurface { @NonNull private final Surface surface; private final long id; - @Keep public FlutterOverlaySurface(long id, @NonNull Surface surface) { this.id = id; this.surface = surface; diff --git a/shell/platform/android/platform_view_android_jni_impl.cc b/shell/platform/android/platform_view_android_jni_impl.cc index 8f874ebdfe7fe..9156c4f9fe7be 100644 --- a/shell/platform/android/platform_view_android_jni_impl.cc +++ b/shell/platform/android/platform_view_android_jni_impl.cc @@ -102,9 +102,9 @@ static jmethodID g_on_display_platform_view_method = nullptr; static jmethodID g_on_display_overlay_surface_method = nullptr; -static jfieldID g_overlay_surface_id_field = nullptr; +static jmethodID g_overlay_surface_id_method = nullptr; -static jfieldID g_overlay_surface_surface_field = nullptr; +static jmethodID g_overlay_surface_surface_method = nullptr; // Called By Java static jlong AttachJNI(JNIEnv* env, @@ -708,16 +708,17 @@ bool RegisterApi(JNIEnv* env) { FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface class"; return false; } - g_overlay_surface_id_field = - env->GetFieldID(overlay_surface_class.obj(), "id", "J"); - if (g_overlay_surface_id_field == nullptr) { - FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.id field"; + g_overlay_surface_id_method = + env->GetMethodID(overlay_surface_class.obj(), "getId", "()J"); + if (g_overlay_surface_id_method == nullptr) { + FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface#getId() method"; return false; } - g_overlay_surface_surface_field = env->GetFieldID( - overlay_surface_class.obj(), "surface", "Landroid/view/Surface;"); - if (g_overlay_surface_surface_field == nullptr) { - FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.surface field"; + g_overlay_surface_surface_method = env->GetMethodID( + overlay_surface_class.obj(), "getSurface", "Landroid/view/Surface;"); + if (g_overlay_surface_surface_method == nullptr) { + FML_LOG(ERROR) + << "Could not locate FlutterOverlaySurface#getSurface() method"; return false; } @@ -1147,13 +1148,13 @@ PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() { } jlong overlay_id = - env->GetLongField(overlay.obj(), g_overlay_surface_id_field); + env->CallLongMethod(overlay.obj(), g_overlay_surface_id_method); - fml::jni::ScopedJavaLocalRef overlay_surface( - env, env->GetObjectField(overlay.obj(), g_overlay_surface_surface_field)); + jobject overlay_surface = + env->CallObjectMethod(overlay.obj(), g_overlay_surface_surface_method); auto overlay_window = fml::MakeRefCounted( - ANativeWindow_fromSurface(env, overlay_surface.obj())); + ANativeWindow_fromSurface(env, overlay_surface)); return std::make_unique( overlay_id, std::move(overlay_window)); From 5d9752aa786f9f875ee0c92050f4eb883b1b1d50 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Mon, 22 Jun 2020 23:09:13 -0700 Subject: [PATCH 2/2] Fix signature --- shell/platform/android/platform_view_android_jni_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/platform_view_android_jni_impl.cc b/shell/platform/android/platform_view_android_jni_impl.cc index 9156c4f9fe7be..cebb2ecb02e18 100644 --- a/shell/platform/android/platform_view_android_jni_impl.cc +++ b/shell/platform/android/platform_view_android_jni_impl.cc @@ -715,7 +715,7 @@ bool RegisterApi(JNIEnv* env) { return false; } g_overlay_surface_surface_method = env->GetMethodID( - overlay_surface_class.obj(), "getSurface", "Landroid/view/Surface;"); + overlay_surface_class.obj(), "getSurface", "()Landroid/view/Surface;"); if (g_overlay_surface_surface_method == nullptr) { FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface#getSurface() method";