From 1deeac84b56450d33fa4be9c7f4f4deb081c6aa8 Mon Sep 17 00:00:00 2001 From: flutteractionsbot <154381524+flutteractionsbot@users.noreply.github.com> Date: Thu, 18 Apr 2024 09:25:03 -0700 Subject: [PATCH] [CP-beta][Android] post image task to main handler. (#52166) This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? Test failures in Impeller migration PR: https://github.com/flutter/packages/pull/6461 ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/wiki/Hotfix-Documentation-Best-Practices) for examples Ensure that Android platform view updates are posted on correct thread when platform view is created on background handler. ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) Migration to Impeller plugin APIs is blocked. ### Workaround: Is there a workaround for this issue? Disable impeller ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? However the tests are in flutter/packages and not flutter/engine. ### Validation Steps: What are the steps to validate that this fix works? Run the unit tests on the linked PR in flutter/packages --- .../io/flutter/embedding/engine/renderer/FlutterRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java index 3f920cf126b34..673f58bb25d6b 100644 --- a/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java +++ b/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java @@ -17,6 +17,7 @@ import android.media.ImageReader; import android.os.Build; import android.os.Handler; +import android.os.Looper; import android.view.Surface; import androidx.annotation.Keep; import androidx.annotation.NonNull; @@ -479,7 +480,8 @@ private class PerImageReader { public PerImageReader(ImageReader reader) { this.reader = reader; - reader.setOnImageAvailableListener(onImageAvailableListener, new Handler()); + reader.setOnImageAvailableListener( + onImageAvailableListener, new Handler(Looper.getMainLooper())); } PerImage queueImage(Image image) {