flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.21k stars 26.65k forks source link

TLHC platform views on Android 14/15 stop updating on resume #146499

Closed evil159 closed 2 weeks ago

evil159 commented 1 month ago

Steps to reproduce

I've created a new project with flutter create and integrated a simple test view on Android side as per https://docs.flutter.dev/platform-integration/android/platform-views. Set up FlutterEngine cache as per Step 3 of this guide https://docs.flutter.dev/add-to-app/android/add-flutter-screen#step-3-optional-use-a-cached-flutterengine.

Steps to reproduce
  1. Launch the app
  2. Switch to Home Screen
  3. Open an app or two(camera, phone app etc.)
    • This step can be skipped if Developer option > Don't keep activities is enabled
  4. Go back to the sample app.
Environment

Sample project: platform_view_test 3.zip

Expected results

The platform view hosted by Flutter app is displayed and interactive.

Actual results

Code sample

Code sample Dart: ```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({super.key}); @override Widget build(BuildContext context) { final Map creationParams = {}; return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text("App"), ), body: AndroidView( viewType: "nativeView", layoutDirection: TextDirection.ltr, creationParams: creationParams, creationParamsCodec: const StandardMessageCodec(), ), ); } } ``` Platform side: ```kotlin class MyApplication : Application() { private lateinit var flutterEngine : FlutterEngine override fun onCreate() { super.onCreate() // Instantiate a FlutterEngine. flutterEngine = FlutterEngine(this) // Start executing Dart code to pre-warm the FlutterEngine. flutterEngine.dartExecutor.executeDartEntrypoint( DartExecutor.DartEntrypoint.createDefault() ) // Cache the FlutterEngine to be used by FlutterActivity. FlutterEngineCache .getInstance() .put("my_engine_id", flutterEngine) } } class RootActivity: Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) startActivity( FlutterActivity.CachedEngineIntentBuilder(MainActivity::class.java, "my_engine_id") .build(this) ) finish() } } class MainActivity: FlutterActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) flutterEngine .platformViewsController .registry .registerViewFactory("nativeView", NativeViewFactory()) } } ```

Screenshots or Video

Screenshots / Video demonstration https://github.com/flutter/flutter/assets/1478430/63054699-c025-43ca-a205-1ecc82eb2c99

Logs

Logs ```console ---------------------------- PROCESS STARTED (19824) for package com.example.platform_view_test ---------------------------- 2024-04-09 14:01:09.947 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 171979766; UID 10274; state: ENABLED 2024-04-09 14:01:09.947 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 242716250; UID 10274; state: DISABLED 2024-04-09 14:01:09.959 19824-19824 ApplicationLoaders com.example.platform_view_test D Returning zygote-cached class loader: /system_ext/framework/androidx.window.extensions.jar 2024-04-09 14:01:09.959 19824-19824 ApplicationLoaders com.example.platform_view_test D Returning zygote-cached class loader: /system_ext/framework/androidx.window.sidecar.jar 2024-04-09 14:01:09.962 19824-19824 ziparchive com.example.platform_view_test W Unable to open '/data/data/com.example.platform_view_test/code_cache/.overlay/base.apk/classes.dm': No such file or directory 2024-04-09 14:01:09.975 19824-19824 ziparchive com.example.platform_view_test W Unable to open '/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/base.dm': No such file or directory 2024-04-09 14:01:09.975 19824-19824 ziparchive com.example.platform_view_test W Unable to open '/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/base.dm': No such file or directory 2024-04-09 14:01:10.011 19824-19824 nativeloader com.example.platform_view_test D Configuring clns-6 for other apk /data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/base.apk. target_sdk_version=33, uses_libraries=, library_path=/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/lib/arm64:/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/base.apk!/lib/arm64-v8a, permitted_path=/data:/mnt/expand:/data/user/0/com.example.platform_view_test 2024-04-09 14:01:10.024 19824-19824 GraphicsEnvironment com.example.platform_view_test V Currently set values for: 2024-04-09 14:01:10.024 19824-19824 GraphicsEnvironment com.example.platform_view_test V angle_gl_driver_selection_pkgs=[com.android.angle, com.linecorp.b612.android, com.campmobile.snow, com.google.android.apps.tachyon] 2024-04-09 14:01:10.024 19824-19824 GraphicsEnvironment com.example.platform_view_test V angle_gl_driver_selection_values=[angle, native, native, native] 2024-04-09 14:01:10.024 19824-19824 GraphicsEnvironment com.example.platform_view_test V com.example.platform_view_test is not listed in per-application setting 2024-04-09 14:01:10.025 19824-19824 GraphicsEnvironment com.example.platform_view_test V Neither updatable production driver nor prerelease driver is supported. 2024-04-09 14:01:10.049 19824-19897 ResourceExtractor com.example.platform_view_test I Found extracted resources res_timestamp-1-1712655907628 2024-04-09 14:01:10.052 19824-19896 nativeloader com.example.platform_view_test D Load /data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/lib/arm64/libflutter.so using ns clns-6 from class loader (caller=): ok 2024-04-09 14:01:10.059 19824-19824 tform_view_test com.example.platform_view_test W type=1400 audit(0.0:18469): avc: denied { read } for name="max_map_count" dev="proc" ino=6767069 scontext=u:r:untrusted_app_32:s0:c18,c257,c512,c768 tcontext=u:object_r:proc_max_map_count:s0 tclass=file permissive=0 app=com.example.platform_view_test 2024-04-09 14:01:10.133 19824-20001 vulkan com.example.platform_view_test D searching for layers in '/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/lib/arm64' 2024-04-09 14:01:10.142 19824-19941 flutter com.example.platform_view_test I The Dart VM service is listening on http://127.0.0.1:40127/VYwrTLx62Uk=/ 2024-04-09 14:01:10.160 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 279646685; UID 10274; state: DISABLED 2024-04-09 14:01:10.191 19824-20001 vulkan com.example.platform_view_test D added global layer 'VK_LAYER_KHRONOS_validation' from library '/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/lib/arm64/libVkLayer_khronos_validation.so' 2024-04-09 14:01:10.216 19824-20001 vulkan com.example.platform_view_test D searching for layers in '/data/app/~~Jwigw4BUI7MoNTTzWd31uw==/com.example.platform_view_test-mcIrPFuHK3VSxqnVEsDqsg==/base.apk!/lib/arm64-v8a' 2024-04-09 14:01:10.228 19824-19824 tform_view_test com.example.platform_view_test W Accessing hidden method Landroid/view/accessibility/AccessibilityNodeInfo;->getSourceNodeId()J (unsupported,test-api, reflection, allowed) 2024-04-09 14:01:10.228 19824-19824 tform_view_test com.example.platform_view_test W Accessing hidden method Landroid/view/accessibility/AccessibilityRecord;->getSourceNodeId()J (unsupported, reflection, allowed) 2024-04-09 14:01:10.228 19824-19824 tform_view_test com.example.platform_view_test W Accessing hidden field Landroid/view/accessibility/AccessibilityNodeInfo;->mChildNodeIds:Landroid/util/LongArray; (unsupported, reflection, allowed) 2024-04-09 14:01:10.228 19824-19824 tform_view_test com.example.platform_view_test W Accessing hidden method Landroid/util/LongArray;->get(I)J (unsupported, reflection, allowed) 2024-04-09 14:01:10.247 19824-19824 ContentCaptureHelper com.example.platform_view_test I Setting logging level to OFF 2024-04-09 14:01:10.254 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 237531167; UID 10274; state: DISABLED 2024-04-09 14:01:10.301 19824-19824 WindowExtensionsImpl com.example.platform_view_test I Initializing Window Extensions. 2024-04-09 14:01:10.581 19824-19855 tform_view_test com.example.platform_view_test I Compiler allocated 4683KB to compile void android.view.ViewRootImpl.performTraversals() 2024-04-09 14:01:10.664 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 171228096; UID 10274; state: ENABLED 2024-04-09 14:01:10.666 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 210923482; UID 10274; state: ENABLED 2024-04-09 14:01:10.666 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 63938206; UID 10274; state: DISABLED 2024-04-09 14:01:10.703 19824-19855 tform_view_test com.example.platform_view_test I Compiler allocated 4213KB to compile void android.widget.TextView.(android.content.Context, android.util.AttributeSet, int, int) 2024-04-09 14:01:10.705 19824-19824 PlatformViewsController com.example.platform_view_test I Hosting view in view hierarchy for platform view: 0 2024-04-09 14:01:10.706 19824-19824 PlatformViewsController com.example.platform_view_test I PlatformView is using ImageReader backend 2024-04-09 14:01:10.706 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 236825255; UID 10274; state: DISABLED 2024-04-09 14:01:10.770 19824-19824 ImageTextu...istryEntry com.example.platform_view_test E Dropping PlatformView Frame 2024-04-09 14:01:10.777 19824-19824 ContentCaptureHelper com.example.platform_view_test I Setting logging level to OFF 2024-04-09 14:01:11.933 19824-19824 ImageTextu...istryEntry com.example.platform_view_test E Dropping PlatformView Frame 2024-04-09 14:01:14.605 19824-19824 VRI[MainActivity] com.example.platform_view_test D visibilityChanged oldVisibility=true newVisibility=false 2024-04-09 14:01:14.677 19824-19824 WindowOnBackDispatcher com.example.platform_view_test W sendCancelIfRunning: isInProgress=falsecallback=android.view.ViewRootImpl$$ExternalSyntheticLambda11@e05917c 2024-04-09 14:01:17.388 19824-19824 ContentCaptureHelper com.example.platform_view_test I Setting logging level to OFF 2024-04-09 14:01:18.676 19824-19824 Compatibil...geReporter com.example.platform_view_test D Compat change id reported: 289878283; UID 10274; state: DISABLED ---------------------------- PROCESS ENDED (19824) for package com.example.platform_view_test ---------------------------- ```

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-FI) • Flutter version 3.19.5 on channel stable at /Users/romanlaitarenko/Downloads/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (12 days ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/romanlaitarenko//Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/romanlaitarenko//Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (6 available) • Pixel 8 (mobile) • 37280DLJH000VR • android-arm64 • Android 14 (API 34) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • Roman’s iPhone (2) (mobile) • 00008110-00110D1614F9801E • ios • iOS 17.4.1 21E236 • iPhone 15 Pro (mobile) • AB1C69B3-AE98-458C-BD91-BEFAFF2357B0 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.59 [✓] Network resources • All expected network resources are available. • No issues found! ```
darshankawar commented 1 month ago

Thanks for the report @evil159 Most likely you are hitting https://github.com/flutter/flutter/issues/139630 that you can check and confirm since you are also seeing similar behavior you mentioned on Samsung device running Android 14.

https://github.com/flutter/flutter/issues/139630#issuecomment-2007673827 for your reference.

evil159 commented 1 month ago

@darshankawar Indeed the issue on Samsung can be explained by that, but there is a separate bug on Pixels then.

evil159 commented 1 month ago

@darshankawar I've updated this issue accordingly, could you take a look at this again?

I don't believe that the fix that Samsung is preparing for Galaxy will fix the issue on Pixel phones.

danagbemava-nc commented 1 month ago

I can reproduce the issue using the code sample and steps provided above. I turned on Don't keep activities to reproduce the issue.

On the stable channel, the screen becomes unresponsive but on the master channel, nothing is rendered on the screen after returning from the background.

The screen recordings were taking from the app running in release mode.

stable master
flutter doctor -v ``` [!] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB) • Flutter version 3.19.5 on channel stable at /Users/nexus/dev/sdks/flutter ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (2 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (5 available) • Pixel 7 (mobile) • 28291FDH2001SA • android-arm64 • Android 14 (API 34) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.107 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ``` ``` [✓] Flutter (Channel master, 3.22.0-8.0.pre.17, on macOS 14.4.1 23E224 darwin-arm64, locale en-GB) • Flutter version 3.22.0-8.0.pre.17 on channel master at /Users/nexus/dev/sdks/flutters • Upstream repository https://github.com/flutter/flutter.git • Framework revision 61cbe2f5b7 (2 hours ago), 2024-04-11 01:44:16 -0400 • Engine revision fef8499fb9 • Dart version 3.5.0 (build 3.5.0-47.0.dev) • DevTools version 2.34.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/nexus/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode-15.3.0.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 77.2.2 • Dart plugin version 232.10286 [✓] VS Code (version 1.87.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (6 available) • Pixel 7 (mobile) • 28291FDH2001SA • android-arm64 • Android 14 (API 34) • Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 17.4.1 21E236 • Dean’s iPad (mobile) • 00008103-000825C811E3401E • ios • iOS 17.4.1 21E236 • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.107 [✓] Network resources • All expected network resources are available. • No issues found! ```
johnmccutchan commented 1 month ago

I've been able to reproduce this issue on a Pixel 7 Pro.

johnmccutchan commented 1 month ago

I added a lot of traces to the engine and this is my current understanding of the bug:

After we resume the ImageReader.OnImageAvailableListener callback never fires again.

We continue to render frames and notify the engine that a frame is available but the image reader is never notified and when we ask the imagereader for its latest frame null is returned.

johnmccutchan commented 1 month ago

Another note:

The difference between stable and master is because https://github.com/flutter/engine/pull/50792 removed the cached first frame. That is,

When stable resumes we use the last frame rendered before we were backgrounded. When main resumes we have nothing to render and so you see the Flutter app's background color.

Both stable and master would be fixed if ImageReader.OnImageAvailableListener was firing as expected.

reidbaker commented 4 weeks ago

Was not able to reproduce with a pixel fold running an unreleased version of android 14.

pipit-userdebug UpsideDownCake MASTER 93172441 dev-keys

reidbaker commented 4 weeks ago

Was not able to reproduce with Nexus 6 running android 7.1.2 build number n2g47w

reidbaker commented 4 weeks ago

I was able to reproduce on a pixel 6 running android 14 build number AP1A.240405.002

johnmccutchan commented 4 weeks ago

Today's update:

We've tried versions of Flutter back to 2022 and none of them work correctly on Android 14 (to be more precise: there are some Android 14 builds that work and some that do not, early Android 15 builds are broken too).

We have not reproduced this issue on Android < 14.

Simplest reproduction steps:

  1. Open sample app
  2. Background sample app.
  3. Launch the camera.
  4. Background camera.
  5. Use task switcher to select sample app.

We are trying to bisect on the Android side to understand more.

johnmccutchan commented 4 weeks ago

Also, it does not appear related to having a cached engine.

johnmccutchan commented 4 weeks ago

Also, rotating the phone will fix the app.

reidbaker commented 4 weeks ago

A coworker bisected this issue using an emulator and was able to find that the problematic android change happened between between build 10480234 (from 7/11/2023) and build 10488473 (from 7/12/2023).

Links for googlers 10480234:

For the second build I can't find any records. https://groups.google.com/a/google.com/g/android-build-police/search?q=after%3A2023-07-11%20before%3A2023-07-13%20

reidbaker commented 4 weeks ago

Build names appear to be 10480234 -> ZP1A.230712.001 10488473 -> ZP1A.230713.001 https://android-build.corp.google.com/build_explorer/branch/git_trunk-release/?gridSize=20&selectionType=START_BUILD_WINDOW&startBuildId=10488473&numBuilds=20&buildType=default

I think this url will let us search for changes but there were 1000 that landed. https://android-build.corp.google.com/build_explorer/branch_dashboard/git_trunk-release/build_id/10488473/?gridSize=20&activeTarget=akita-user

reidbaker commented 4 weeks ago

From the android team a better way to search commits. https://android-build.corp.google.com/range_search/cls/from_id/10488473/to_id/10480234/?s=menu&includeTo=0&includeFrom=1

reidbaker commented 4 weeks ago

Current belief is that this is an android regression that appeared during android 14 and we have escalated to the android team. Internal bug b/335646931

reidbaker commented 4 weeks ago

https://googleplex-android.googlesource.com/platform%2Fframeworks%2Fbase/+/20a4d68338ca000e3ee0c5c71a01552eab1061e1 the commit we think is the source of the error.

evil159 commented 3 weeks ago

Is there any workaround for this issue? Any way to make that ImageReader.OnImageAvailableListener firing again?

reidbaker commented 3 weeks ago

We don't know of any work around that apps can trigger as of this moment. If we find one we will add it to this bug. The android team has informed us of a way flutter can avoid this error by using different classes and we are working on implementing that solution. That fix will require apps to adopt a new version of flutter.

reidbaker commented 3 weeks ago

The android team has confirmed that the commit we thought was the issue was indeed the problem and has a fix on their side. Unfortunately android source changes take a long time to ship and live in the wild for a longer time. We are working to avoid the classes that are bugged and will update this issue when there is something app developers can do.

yh-luo commented 3 weeks ago

WebView is not functioning properly due to this issue. For my app, multiple Samsung and Pixel users have reported that the app displays a white screen upon resume when the UI utilizes WebView, as noted in #139039.

Also, rotating the phone will fix the app.

I tested this on a Pixel 7 running Android 14, but unfortunately, it did not resolve the issue :cry:

phcd30 commented 2 weeks ago

This is crazy that flutter webview does not work on the latest version of Android. The response in the previous thread was incredibly poor as well, very dismissive.

"Locked as spam" on an issue this critical. I'm sure a lot of other people using or looking at Flutter will be steered away by this type of developer interaction.

We've just launched a new app on flutter and every user with a recent Samsung or Android it seems are getting a lot of white screens, their only option is to close and open the app again. I'd put this in the P-Minus-Zero category of priorities if Flutter is to be taken seriously.

image

From reading through the next thread above it looks like it will only be fixed in Android 15 which is available from August on Pixel and later on other manufacturers. None of us can rely on users updating their phones so it looks like Flutter webview is not an option on Androids for 4+ yrs from now. We'll have to move to something that isn't just broken, or indeed likely to have a blasé approach to critical issues.

Also, if your logging and alerting are on point you should be lighting up like a Christmas tree, not asking people to repro on different devices.

reidbaker commented 2 weeks ago

@phcd30 there is a pull request open linked on this pr with a fix for flutter. https://github.com/flutter/engine/pull/52370

phcd30 commented 2 weeks ago

Do you think it will be fixed with a flutter update without the need to wait for Android 15 or a patch to Android 14?

The other thread starts with this statement - "Android 15 will include the fix. Unclear if Android 14 will be patched."

Hixie commented 2 weeks ago

@phcd30 Flutter is an open source project, many of us volunteer to work on this project in our free time; others are employed by companies that donate their resources and time to the project. We all have our own list of what is most critical to us and what we need to work on next to address our needs.

If this is "P-Minus-Zero" for you, your best option is to contribute a fix or hire someone to work on a fix. We would certainly welcome you or someone you hire into the community and would love to help you become productive contributors in whatever way we can. You can find more in our contributing guide.

I encourage you to reread your comment and think how it might be received by someone whom you are not paying but who has nonetheless contributed their time to create a product that you now rely on.

Also, if your logging and alerting are on point you should be lighting up like a Christmas tree, not asking people to repro on different devices.

For privacy reasons, we do not log anything from applications shipped with Flutter, so we have to rely on folks who do log information from their users to report that information to us.

phcd30 commented 2 weeks ago

Happy to test this fix if possible?

My feedback is constructive, take it as it's intended. If Flutter is viewing it's as a hobby project, as opposed to the marketing on the flutter home page -

image

it would be irresponsible for anyone to consider it. Please update the marketing to reflect the views and responses on this repo.

Hixie commented 2 weeks ago

Please review our code of conduct, especially the part relating to respect people's work and being kind and welcoming. I have blocked your account for seven days.

neilgrattan commented 2 weeks ago

To be honest I am also watching this issue for a resolution as it is causing serious issues for a huge number of users, and I am starting to think Flutter was marketed to me as a professionally supported project, and this kind of thing doesn't instil much confidence in a fix. I am going to have to remove flutter from our app because of it.

Hixie commented 2 weeks ago

(Please move discussion about how Flutter is marketed to another issue or to a Discord thread; it is off topic for this issue. I'm happy to discuss that particular topic, but we should keep issues focused on the topic at hand, as per https://github.com/flutter/flutter/wiki/Issue-hygiene#issues-are-not-always-the-best-venue-for-discussions. If you do wish to have that discussion, please cc me! Thanks.)

neilgrattan commented 2 weeks ago

"Please consult us about how we deceived you and how we can improve this going forward" is not an appropriate response.

reidbaker commented 2 weeks ago

We know this issue is serious and have spent multiple engineering weeks tracking down the root cause. Current recap for those that are following.

On Android 14 platform views encounter an Android bug where we stop getting draw information from android when memory trim is called, usually the app is in the background. This causes platform views to render transparent BUT the actual underlying views are still there and are interactable. This set of trigger conditions is not unique to flutter. The apis we use would also fail for Android apps. Additionally there was a change between flutter 3.19 and flutter master (probably 3.20) where for platform views we no longer cache the last frame and draw it onResume until we get the surface information from android. Before that previous frame helped hide this issue since the underlying android views were still interactable.

To the best of my knowledge, this issue does not appear when using the app regularly. It does not appear when backgrounded unless under memory pressure. Rotating the phone clears the condition. Evicting the app and relaunching clears the condition.

In order to detect the bug with an automated test the test would have to 1) Launch an app with a platform view, 2) background the app, 3) trigger memory trim, 4) relaunch the app 5) Scroll or some other action to move items 6) Take a screenshot and pixel compare. If you do not do step 5 then the test would continue to work because the last frame would have been preserved and you could still click the button and check for the callback or any other touch interaction. If you did step 5 but did not pixel compare a screenshot then the test would also have passed again because the underlying buttons are there but not visible/updating. As a general rule combining screenshots with scrolling is extremely flakey so we have not included those types of tests.

Also extending this bug is that it was reported as a samsung specific issue and the contributors working on this issue did not have access to samsung code to see how it differed. Samsung confirmed reproducibility but cross company interactions are significantly slower and then we were told Samsung had a fix but the code was not something we could review. I will admit my own fault that I assumed that Pixel phones would always have the newest version of android so I did not consider that this could have been a pure Android issue.

When we eventually tried to prove or disprove that Android had the bug we bisected a years worth of google internal android builds and narrowed it down to 2 days worth of commits (6 thousand commits) then searched for commits that could have touched the code at issue. The android commit at issue is linked above.

If you are here you probably care most about the fix. Android has a fix committed to their upstream but their release process is slower than we know our customers want. We have confirmed that Android's fix will be in Android 15. We are escalating to see if we(flutter) can get them(Android) to backport the fix to future patch versions of Android 14, if that is approved and I am allowed to share android release information I expect to update this bug . @johnmccutchan has a pull request up now that has a work around to avoid the bug. Once that pr is merged, flutter plans to backport that pr into older flutter engine builds. This bug will be updated with which flutter versions have the fix when they land and the version numbers of those builds. Finally if you are running a custom engine or an engine older than we backport you can apply the patch yourself and build with a custom engine.

We are not aware of any app side changes you can make to avoid this issue when the trigger conditions are met. Also note that an unrelated change in 3.19 causes platform views to not work on api 21 and 22 https://github.com/flutter/flutter/issues/147210.

reidbaker commented 2 weeks ago

A way to force the background trim condition `adb shell am send-trim-memory BACKGROUND

amrgetment commented 2 weeks ago

That’s a great effort from your team, people should see how the team is squeezing their brains to solve the flutter issues and make it a better framework Thanks a lot

OnClickListener2048 commented 1 week ago

This is a great job and thanks all for making this progress so far.

lukehutch commented 1 week ago

This causes platform views to render transparent BUT the actual underlying views are still there and are interactable.

To the best of my knowledge, this issue does not appear when using the app regularly. It does not appear when backgrounded unless under memory pressure. Rotating the phone clears the condition. Evicting the app and relaunching clears the condition.

@reidbaker I see this problem on both Pixel 4 and Pixel 7 Pro. However, my symptoms are somewhat different than this description.

  1. I get a "black screen of death" when backgrounding the app for some period of time, e.g. 5 minutes (presumably under memory pressure, but not always in any obvious way), then switching back to the app.
  2. The app is not responsive in any way, but I don't get an ANR unless I attach the debugger and pause the running process for long enough.
  3. I cannot connect a debugger to the running Flutter instance, which confirms that the app is not responsive under the black screen.
  4. Rotating the screen does not clear the condition in my case.
  5. The Back button pops the whole app, rather than what would be the current view in the app, which is another indication that the app is unresponsive.

Update: the Pixel 4 is actually running Android 13, not Android 14. The Pixel 7 Pro is running Android 14. Both exhibit the issue. So either this issue is not limited to Android 14, or there is another similar but not identical issue lurking that affects Android <14 too.

alpha2048 commented 1 week ago

Thank you to Flutter team for their hard work. But when will the work around be available on the stable channel? Our users using Pixel are still having trouble.

reidbaker commented 1 week ago

3.22 has had the fix pr cherry picked into the engine. We are working on creating a new framework build that has the updated engine code. 3.22 is scheduled to land as stable sometime around the Google IO timeframe (next week).

Standard response below.

This issue has been fixed by https://github.com/flutter/engine/pull/52370 To determine what versions of Flutter contain the fix, please see where’s my commit. If the commit has no release tag, it is currently only available in the master channel.

evil159 commented 9 hours ago

Is this fixed in 3.22.0? Cannot find anything about https://github.com/flutter/engine/pull/52370 in the release notes.

yh-luo commented 6 hours ago

I think the fix is merged in 3793869.

I found that under flutter/engine/3.22.0. Also the fix was mentioned in What’s new in Flutter 3.22: Platform views improvements.