Repository: flutter
Issue: Screen freezes when app is opened via intent from lock screen
Labels: platform-android,engine,c: performance,has reproducible steps,P2,found in release: 3.0,found in release: 3.1,team-android,triaged-android




In our app, we handle VOIP calls.  On android we have the Firebase Messaging plugin start our MainActivity via an intent when it detects a push notifications signifying an incoming call. Then we detect and present the call answer UI in flutter.\
If the screen is locked we use native code to allow the app to be drawn over the lockscreen.  This has worked well until we updated to flutter 3.0. \
Mechanically everything still works as before however if flutter was configured while the device was locked the app does not render frames when pushed above the lock screen.  We get one frame so that our Answer/Decline dialog is shown but once the call is answered the screen does not update except oddly it will update one frame for every rotation change.
Input seems to be active, just any state changes due to the input are never realized.  The one exception to this is that if the call was a video call once the phone gets rotated so that the video renders are drawn both the local and remote video renders show live video.  I assume this is because the video is actually being rendered into a texture which was drawn once and is being updated by some other mechanism than a pure flutter widget rebuild.  (The audio part of the call seems to be working fine.)

We use bloc for our state management, and I have determined that our bloc is updating state appropriately.  The bloc listener widget's buildWhen methods are getting called with those state updates, however the widget's builder function never gets called when the buildWhen returns true, other than the first time.

The app still works as expected if the app is in the foreground and then the device is locked, the app is pushed over the lock screen and everything renders correctly, it seems to be when the flutter app is (re)started such that the splash screen and (our flutter) app initialization executes that the rendering fails to happen.

We are using flutter_webrtc (via LiveKit) for our call infrastructure.

I have tried to get android connection service working but as far as I can tell the way it needs to do video is incompatible with flutter.  (Certainly with my level of expertise with native android programming).

One other fact I have been able to determine is that once the engine (or whatever) is in the state where things are not rendering correctly, even unlocking the device does not resolve it issue.  I have manually unlocked and programatically requested unlock and neither result in a functional UI.  It would seem that being started from scratch when the device is locked is what is causing the issue.

<details>
  <summary>Logs</summary>

I can attach logs if needed, but only the extremely verbose logcat trace has the logs from the failed case.

```
```

```
$ flutter analyze
Analyzing lochbox...                                                    
No issues found! (ran in 4.3s)

```

```
[✓] Flutter (Channel stable, 3.0.1, on Fedora Linux 35 (Thirty Five) 5.17.11-200.fc35.x86_64, locale en_US.UTF-8)
    • Flutter version 3.0.1 at /server/home/csh/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (3 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /home/csh/Android/Sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: /server/home/csh/lib/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 13.0.0 (Fedora 13.0.0-3.fc35)
    • cmake version 3.22.2
    • ninja version 1.8.2
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.2)
    • Android Studio at /server/home/csh/lib/android-studio
    • Flutter plugin version 67.1.2
    • Dart plugin version 212.5744
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.67.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.42.0

[✓] Connected device (6 available)
    • G5 (mobile)                           • 7080018019007106 • android-arm64  • Android 9 (API 28)
    • sdk gphone x86 (mobile)               • emulator-5554    • android-x86    • Android R (API 29) (emulator)
    • Android SDK built for x86 64 (mobile) • emulator-5556    • android-x64    • Android 10 (API 29) (emulator)
    • sdk gphone64 x86 64 (mobile)          • emulator-5558    • android-x64    • Android 12 (API 31) (emulator)
    • Linux (desktop)                       • linux            • linux-x64      • Fedora Linux 35 (Thirty Five) 5.17.11-200.fc35.x86_64
    • Chrome (web)                          • chrome           • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

```

</details>