Skip to content

Ensure content-sizing resize is run on UI thread#181686

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
mboetger:move-maybe
Jan 30, 2026
Merged

Ensure content-sizing resize is run on UI thread#181686
auto-submit[bot] merged 7 commits into
flutter:masterfrom
mboetger:move-maybe

Conversation

@mboetger

Copy link
Copy Markdown
Contributor

While testing with a different add-to-app flutter/samples#2787, an exception is sometimes thrown when the resize is attempted because the callback comes from a different thread. It is expected that the raster thread calls this but with previous testing never caused this exception.

This PR ensures the resize happens on the UI thread. It also a flag to ensure content sizing is disabled.

Fixes: #181573

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@mboetger mboetger requested a review from a team as a code owner January 29, 2026 22:28
@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Jan 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a threading issue by ensuring that the content-sizing resize operation is executed on the UI thread. This is achieved by posting the MaybeResizeSurfaceView call to the platform task runner. Additionally, it introduces a new metadata flag, io.flutter.embedding.android.EnableContentSizing, to make content sizing an opt-in feature, which is now disabled by default. The changes appear correct and effectively resolve the described issue. I have a couple of minor suggestions to improve code clarity and correctness.

@gmackall gmackall left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think this makes more sense than the previous approach

mboetger added a commit to mboetger/samples that referenced this pull request Jan 30, 2026
@mboetger mboetger added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 30, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jan 30, 2026
@mboetger mboetger added the cp: beta cherry pick this pull request to beta release candidate branch label Jan 30, 2026
Merged via the queue into flutter:master with commit d143c41 Jan 30, 2026
182 of 184 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 30, 2026
@mboetger mboetger added cp: beta cherry pick this pull request to beta release candidate branch and removed cp: beta cherry pick this pull request to beta release candidate branch labels Jan 30, 2026
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request Jan 30, 2026
While testing with a different add-to-app
flutter/samples#2787, an exception is sometimes
thrown when the resize is attempted because the callback comes from a
different thread. It is expected that the raster thread calls this but
with previous
[testing](https://github.com/mboetger/test-add-to-app/tree/content-sizing)
never caused this exception.

This PR ensures the resize happens on the UI thread. It also a flag to
ensure content sizing is disabled.

Fixes: flutter#181573

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [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].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 31, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 31, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 1, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 1, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 1, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 2, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Feb 2, 2026
flutter/flutter@1d9d6a9...9eafba4

2026-02-01 [email protected] Roll Skia from a8ceddc2bca0 to 4ee9eb659ae0 (1 revision) (flutter/flutter#181773)
2026-02-01 [email protected] Roll Skia from a5a535bc21a3 to a8ceddc2bca0 (1 revision) (flutter/flutter#181772)
2026-02-01 [email protected] Roll Dart SDK from cde322c518b9 to 84abc8d58ec8 (1 revision) (flutter/flutter#181767)
2026-02-01 [email protected] Roll Dart SDK from c72b3f527a07 to cde322c518b9 (1 revision) (flutter/flutter#181763)
2026-01-31 [email protected] Roll Dart SDK from 43de79f08887 to c72b3f527a07 (1 revision) (flutter/flutter#181762)
2026-01-31 [email protected] Roll Fuchsia Linux SDK from 27OsrsrKcrr2pOaqY... to nI52U4LJMrBv8G1M9... (flutter/flutter#181760)
2026-01-31 [email protected] Roll Dart SDK from a0aac59705e5 to 43de79f08887 (1 revision) (flutter/flutter#181758)
2026-01-31 [email protected] Roll Skia from b704afbcd8e7 to a5a535bc21a3 (1 revision) (flutter/flutter#181757)
2026-01-31 [email protected] Roll Dart SDK from d6f77f9098e1 to a0aac59705e5 (1 revision) (flutter/flutter#181756)
2026-01-31 [email protected] Roll Skia from 6f9511ce11ba to b704afbcd8e7 (4 revisions) (flutter/flutter#181753)
2026-01-31 [email protected] Roll Dart SDK from 0cf997832948 to d6f77f9098e1 (2 revisions) (flutter/flutter#181749)
2026-01-31 [email protected] Roll Skia from 33c00c0f3b8b to 6f9511ce11ba (1 revision) (flutter/flutter#181744)
2026-01-31 [email protected] Roll Dart SDK from be3ffc51d407 to 0cf997832948 (1 revision) (flutter/flutter#181740)
2026-01-30 [email protected] Roll Skia from b62d43b59dd6 to 33c00c0f3b8b (1 revision) (flutter/flutter#181735)
2026-01-30 [email protected] [Impeller] Fix type conversion warnings seen on Windows when Impeller GL API wrappers log arguments with function types (flutter/flutter#181734)
2026-01-30 [email protected] Update New Android API Docs (flutter/flutter#180604)
2026-01-30 [email protected] Roll Fuchsia Linux SDK from isy1ARvK-3bsvtfc-... to 27OsrsrKcrr2pOaqY... (flutter/flutter#181733)
2026-01-30 [email protected] Fix P3-to-sRGB color conversion to operate in linear light (flutter/flutter#181720)
2026-01-30 [email protected] chore: deflake Linux_mokey flutter_engine_group_performance (flutter/flutter#181624)
2026-01-30 [email protected] Roll Dart SDK from 2703fd9733ce to be3ffc51d407 (1 revision) (flutter/flutter#181729)
2026-01-30 [email protected] Ensure content-sizing resize is run on UI thread (flutter/flutter#181686)
2026-01-30 [email protected] [ Tool ] Cleanup `ResidentCompiler` initialization logic (flutter/flutter#181421)
2026-01-30 [email protected] [native assets] Split debug info into `.dsym` files (flutter/flutter#181533)
2026-01-30 [email protected] Roll Skia from 4745eb2fe837 to b62d43b59dd6 (1 revision) (flutter/flutter#181727)
2026-01-30 [email protected] add ccache support for custom toolchain (flutter/flutter#180737)
2026-01-30 [email protected] update GLFW to latest and use EGL context creation on linux (flutter/flutter#181259)
2026-01-30 [email protected] add stacktrace support when requested for host builds (flutter/flutter#181264)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit Bot pushed a commit that referenced this pull request Feb 3, 2026
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Cherry-pick of #181686

### Issue Link:
What is the link to the issue this cherry-pick is addressing?

#181573

### Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Crash

Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
App crashes

This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

Apps running this code will crash: https://buganizer.corp.google.com/issues/478788744

### Changelog Description:
Explain this cherry pick:
* Makes sure the JNI method is called on Android's UI thread.
* The JNI method would be called by the raster's thread and cause a crash.
* That includes which platforms are impacted.
See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples.
Android Apps

< Replace with changelog description here >
[flutter/181573] When resize JNI method is called on Android, apps will crash.

### Workaround:
Is there a workaround for this issue?

No.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

Run the sample app flutter/samples#2787 and check it does not crash.
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Feb 6, 2026
While testing with a different add-to-app
flutter/samples#2787, an exception is sometimes
thrown when the resize is attempted because the callback comes from a
different thread. It is expected that the raster thread calls this but
with previous
[testing](https://github.com/mboetger/test-add-to-app/tree/content-sizing)
never caused this exception.

This PR ensures the resize happens on the UI thread. It also a flag to
ensure content sizing is disabled.

Fixes: flutter#181573

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [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].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
While testing with a different add-to-app
flutter/samples#2787, an exception is sometimes
thrown when the resize is attempted because the callback comes from a
different thread. It is expected that the raster thread calls this but
with previous
[testing](https://github.com/mboetger/test-add-to-app/tree/content-sizing)
never caused this exception.

This PR ensures the resize happens on the UI thread. It also a flag to
ensure content sizing is disabled.

Fixes: flutter#181573

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [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].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.
rickhohler pushed a commit to rickhohler/flutter that referenced this pull request Feb 19, 2026
While testing with a different add-to-app
flutter/samples#2787, an exception is sometimes
thrown when the resize is attempted because the callback comes from a
different thread. It is expected that the raster thread calls this but
with previous
[testing](https://github.com/mboetger/test-add-to-app/tree/content-sizing)
never caused this exception.

This PR ensures the resize happens on the UI thread. It also a flag to
ensure content sizing is disabled.

Fixes: flutter#181573

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [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].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.
Xbectordash pushed a commit to Xbectordash/abhi_flutter_fork that referenced this pull request May 13, 2026
…1732)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Cherry-pick of flutter#181686

What is the link to the issue this cherry-pick is addressing?

flutter#181573

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Crash

Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
App crashes

This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

Apps running this code will crash: https://buganizer.corp.google.com/issues/478788744

Explain this cherry pick:
* Makes sure the JNI method is called on Android's UI thread.
* The JNI method would be called by the raster's thread and cause a crash.
* That includes which platforms are impacted.
See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples.
Android Apps

< Replace with changelog description here >
[flutter/181573] When resize JNI method is called on Android, apps will crash.

Is there a workaround for this issue?

No.

What is the risk level of this cherry-pick?

Are you confident that your fix is well-tested by automated tests?

What are the steps to validate that this fix works?

Run the sample app flutter/samples#2787 and check it does not crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cp: beta cherry pick this pull request to beta release candidate branch engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Content Sizing Resize called on raster thread

2 participants