Repository navigation
Commit 8bcda46
[Android] Guard PlatformViewsController2.onEndFrame against a detached FlutterView (flutter#190612)
`PlatformViewsController2.onEndFrame()` dereferenced `flutterView` and
the result of
`flutterView.getRootSurfaceControl()` without checking either for null.
`AndroidExternalViewEmbedder2::SubmitFlutterView()` posts
`onEndFrame2()` from the raster thread to
the platform thread on every frame, including frames with no platform
layers. By the time the task
runs, the `FlutterView` may have been detached from the controller, in
which case
`detachFromView()` has set `flutterView` to null, or detached from its
window, in which case
`View.getRootSurfaceControl()` returns null.
The resulting `NullPointerException` is not merely logged. The JNI call
ends with
`FML_CHECK(fml::jni::CheckException(env))`, which converts the pending
Java exception into an
`abort()`. This terminates the process with no Dart-side recovery or
application-level workaround
other than disabling HCPP.
This change guards both nullable values and closes the merged
`SurfaceControl.Transaction` before
returning early so that it is not leaked. It also moves
`flutterView.invalidate()` below the guard,
because that call was itself unsafe when `flutterView` was null.
The issue reproduces on every warm teardown when an HCPP platform view
is visible and the
`FlutterEngine` outlives its activity. In a 10-launch loop, the
unpatched embedding produced five
aborts because every abort killed the process and made the following
launch a cold start.
Verified locally on an Android 16 emulator by compiling the patched
class into the prebuilt
embedding JAR: 0 aborts across 12 teardowns. Platform-view rendering
continued to work after
reattaching the engine. The reproduction app and full before-and-after
logs are included in the
linked issue.
Fixes flutter#190609
## Pre-launch Checklist
* [x] I read the [[Contributor
Guide](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview)]
and followed the process outlined there for submitting PRs.
* [x] I read the [[AI contribution
guidelines](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines)]
and understand my responsibilities, or I am not using AI tools.
* [x] I read the [[Tree
Hygiene](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md)]
wiki page, which explains my responsibilities.
* [x] I read and followed the [[Flutter Style
Guide](https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md)],
including [[Features we expect every widget to
implement](https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement)].
* [x] I signed the [[CLA](https://cla.developers.google.com/)].
* [x] I listed at least one issue that this PR fixes in the description
above.
* [x] I updated/added relevant documentation (doc comments with `///`).
* [x] I added new tests to check the change I am making, or this PR is
[[test-exempt](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests)].
* [x] I followed the [[breaking change
policy](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes)]
and added [[Data Driven
Fixes](https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md)]
where supported.
* [ ] All existing and new tests are passing.
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Co-authored-by: Gray Mackall <[email protected]>1 parent f0b937d commit 8bcda46
2 files changed
Lines changed: 53 additions & 1 deletion
File tree
- engine/src/flutter/shell/platform/android
- io/flutter/plugin/platform
- test/io/flutter/plugin/platform
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
672 | 673 | | |
673 | 674 | | |
674 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
675 | 689 | | |
676 | | - | |
| 690 | + | |
677 | 691 | | |
678 | 692 | | |
679 | 693 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
556 | 594 | | |
557 | 595 | | |
558 | 596 | | |
| |||
0 commit comments