Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
evil159 opened this issue Apr 9, 2024 · 42 comments · Fixed by flutter/engine#52370
Closed

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

evil159 opened this issue Apr 9, 2024 · 42 comments · Fixed by flutter/engine#52370
Assignees
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on P0 Critical issues such as a build break or regression platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team

Comments

@evil159
Copy link

evil159 commented Apr 9, 2024

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
  • Pixel 8 running AP31.240223.016.A3(Android 15 Preview)

Sample project: platform_view_test 3.zip

Expected results

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

Actual results

  • On Galaxy the platform view is not displayed, instead the place it used to occupy is rendered solid white.
  • On Pixel the platform view is displayed, but not interacting(doesn't respond to touch).

Code sample

Code sample

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<String, dynamic> creationParams = <String, dynamic>{};

    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:

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
Screen_recording_20240409_135855.mp4

Logs

Logs
---------------------------- 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=<unknown>): 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.<init>(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
[✓] 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 darshankawar added the in triage Presently being triaged by the triage team label Apr 10, 2024
@darshankawar
Copy link
Member

Thanks for the report @evil159
Most likely you are hitting #139630 that you can check and confirm since you are also seeing similar behavior you mentioned on Samsung device running Android 14.

#139630 (comment) for your reference.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 10, 2024
@evil159
Copy link
Author

evil159 commented Apr 10, 2024

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

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 10, 2024
@evil159
Copy link
Author

evil159 commented Apr 10, 2024

@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
Copy link
Member

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
screen-20240411-071658.mp4
screen-20240411-071434.mp4
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!

@danagbemava-nc danagbemava-nc added platform-android Android applications specifically engine flutter/engine repository. See also e: labels. a: platform-views Embedding Android/iOS views in Flutter apps has reproducible steps The issue has been confirmed reproducible and is ready to work on team-android Owned by Android platform team found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 and removed in triage Presently being triaged by the triage team labels Apr 11, 2024
@johnmccutchan johnmccutchan self-assigned this Apr 11, 2024
@johnmccutchan
Copy link
Contributor

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

@johnmccutchan
Copy link
Contributor

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
Copy link
Contributor

Another note:

The difference between stable and master is because flutter/engine#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
Copy link
Contributor

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

pipit-userdebug UpsideDownCake MASTER 93172441 dev-keys

@reidbaker
Copy link
Contributor

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

@reidbaker
Copy link
Contributor

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

@johnmccutchan
Copy link
Contributor

johnmccutchan commented Apr 18, 2024

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
Copy link
Contributor

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

@johnmccutchan johnmccutchan changed the title Platform views with FlutterEngineCache freeze/disappear on resume TLHC platform views on Android 14/15 stop updating on resume Apr 18, 2024
@johnmccutchan
Copy link
Contributor

Also, rotating the phone will fix the app.

@darshankawar darshankawar added the e: OS-version specific Affects only some versions of the relevant operating system label Apr 18, 2024
@reidbaker
Copy link
Contributor

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
Copy link
Contributor

@reidbaker
Copy link
Contributor

johnmccutchan added a commit to johnmccutchan/engine that referenced this issue Apr 29, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Unclear when the Android fix will be available in phones.
johnmccutchan added a commit to johnmccutchan/engine that referenced this issue Apr 30, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Unclear when the Android fix will be available in phones.
auto-submit bot pushed a commit to flutter/engine that referenced this issue Apr 30, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label Apr 30, 2024
@amrgetment
Copy link

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

reidbaker pushed a commit to reidbaker/engine that referenced this issue Apr 30, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
reidbaker pushed a commit to reidbaker/engine that referenced this issue Apr 30, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
reidbaker pushed a commit to reidbaker/engine that referenced this issue Apr 30, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
reidbaker pushed a commit to reidbaker/engine that referenced this issue May 1, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
reidbaker pushed a commit to reidbaker/engine that referenced this issue May 1, 2024
- Destroy ImageReaders on memory trim.
- Unset the VirtualDisplay's surface on memory trim.
- On resume, recreate ImageReaders.
- On resume, do a dumb little dance and then set the VirtualDisplay's surface

Fixes: flutter/flutter#146499
Fixes: flutter/flutter#144219

Internal bug: b/335646931
Android Fix: https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/27015418

Android 15 will include the fix. Unclear if Android 14 will be patched.
@OnClickListener2048
Copy link

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

@lukehutch
Copy link
Contributor

lukehutch commented May 6, 2024

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
Copy link

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
Copy link
Contributor

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 flutter/engine#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
Copy link
Author

evil159 commented May 16, 2024

Is this fixed in 3.22.0? Cannot find anything about flutter/engine#52370 in the release notes.

@yh-luo
Copy link

yh-luo commented May 16, 2024

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.

@mr-pant
Copy link

mr-pant commented May 17, 2024

I see that this issue is fixed with Flutter 3.22.0 for the mentioned steps, but I see this happening following different steps instead. Now if the platform view is your initial page and you press back button to move app to background, on launching again, you will see that the blank issue is reproducible. (Steps are similar to #148347)
So looks like issue is still not fully fixed.

Another interesting thing is that after this, if you follow the steps for old issue i.e - switch from another recent app to sample app from recent apps launcher, the platform view starts working again.

Edit:
Created a bug for this : #148662

@reidbaker
Copy link
Contributor

Promised update on the android fix.
The change to fix existing flutter apps (pre 3.22) on android 14 has been cherry picked into the July release of Pixel. I am still working on the escalation for other manufacturers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: platform-views Embedding Android/iOS views in Flutter apps e: OS-version specific Affects only some versions of the relevant operating system engine flutter/engine repository. See also e: labels. found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on P0 Critical issues such as a build break or regression platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.