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

Commit 57d1333

Browse files
author
Emmanuel Garcia
authored
Use public accessor and move keep annotation (#19232)
Fixes an issue introduced in #19221 where accessing a private field is causing a crash in release mode. Logs: https://console.firebase.google.com/project/flutter-infra/testlab/histories/bh.60bf482010a9daf5/matrices/8495138397166466033
1 parent bbe7503 commit 57d1333

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

shell/platform/android/io/flutter/embedding/engine/FlutterOverlaySurface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import androidx.annotation.Keep;
99
import androidx.annotation.NonNull;
1010

11+
@Keep
1112
public class FlutterOverlaySurface {
1213
@NonNull private final Surface surface;
1314

1415
private final long id;
1516

16-
@Keep
1717
public FlutterOverlaySurface(long id, @NonNull Surface surface) {
1818
this.id = id;
1919
this.surface = surface;

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ static jmethodID g_on_display_platform_view_method = nullptr;
102102

103103
static jmethodID g_on_display_overlay_surface_method = nullptr;
104104

105-
static jfieldID g_overlay_surface_id_field = nullptr;
105+
static jmethodID g_overlay_surface_id_method = nullptr;
106106

107-
static jfieldID g_overlay_surface_surface_field = nullptr;
107+
static jmethodID g_overlay_surface_surface_method = nullptr;
108108

109109
// Called By Java
110110
static jlong AttachJNI(JNIEnv* env,
@@ -708,16 +708,17 @@ bool RegisterApi(JNIEnv* env) {
708708
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface class";
709709
return false;
710710
}
711-
g_overlay_surface_id_field =
712-
env->GetFieldID(overlay_surface_class.obj(), "id", "J");
713-
if (g_overlay_surface_id_field == nullptr) {
714-
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.id field";
711+
g_overlay_surface_id_method =
712+
env->GetMethodID(overlay_surface_class.obj(), "getId", "()J");
713+
if (g_overlay_surface_id_method == nullptr) {
714+
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface#getId() method";
715715
return false;
716716
}
717-
g_overlay_surface_surface_field = env->GetFieldID(
718-
overlay_surface_class.obj(), "surface", "Landroid/view/Surface;");
719-
if (g_overlay_surface_surface_field == nullptr) {
720-
FML_LOG(ERROR) << "Could not locate FlutterOverlaySurface.surface field";
717+
g_overlay_surface_surface_method = env->GetMethodID(
718+
overlay_surface_class.obj(), "getSurface", "()Landroid/view/Surface;");
719+
if (g_overlay_surface_surface_method == nullptr) {
720+
FML_LOG(ERROR)
721+
<< "Could not locate FlutterOverlaySurface#getSurface() method";
721722
return false;
722723
}
723724

@@ -1147,13 +1148,13 @@ PlatformViewAndroidJNIImpl::FlutterViewCreateOverlaySurface() {
11471148
}
11481149

11491150
jlong overlay_id =
1150-
env->GetLongField(overlay.obj(), g_overlay_surface_id_field);
1151+
env->CallLongMethod(overlay.obj(), g_overlay_surface_id_method);
11511152

1152-
fml::jni::ScopedJavaLocalRef<jobject> overlay_surface(
1153-
env, env->GetObjectField(overlay.obj(), g_overlay_surface_surface_field));
1153+
jobject overlay_surface =
1154+
env->CallObjectMethod(overlay.obj(), g_overlay_surface_surface_method);
11541155

11551156
auto overlay_window = fml::MakeRefCounted<AndroidNativeWindow>(
1156-
ANativeWindow_fromSurface(env, overlay_surface.obj()));
1157+
ANativeWindow_fromSurface(env, overlay_surface));
11571158

11581159
return std::make_unique<PlatformViewAndroidJNI::OverlayMetadata>(
11591160
overlay_id, std::move(overlay_window));

0 commit comments

Comments
 (0)