Skip to content

[CP-beta]Ensure content-sizing resize is run on UI thread#181732

Merged
auto-submit[bot] merged 1 commit intoflutter:flutter-3.41-candidate.0from
flutteractionsbot:cp-beta-d143c41e41e3d5ed5a18d06ab4ee12d85455f006
Feb 3, 2026
Merged

[CP-beta]Ensure content-sizing resize is run on UI thread#181732
auto-submit[bot] merged 1 commit intoflutter:flutter-3.41-candidate.0from
flutteractionsbot:cp-beta-d143c41e41e3d5ed5a18d06ab4ee12d85455f006

Conversation

@flutteractionsbot
Copy link

@flutteractionsbot flutteractionsbot commented Jan 30, 2026

This pull request is created by automatic cherry pick workflow
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 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?

  • Low
  • Medium
  • High

Test Coverage:

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

  • Yes
  • No

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.

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.
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Jan 30, 2026
@flutteractionsbot flutteractionsbot requested a review from a team as a code owner January 30, 2026 19:35
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Jan 30, 2026
@flutteractionsbot
Copy link
Author

@mboetger please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard
Copy link

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@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 30, 2026
Copy link
Contributor

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

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 a JNI call for resizing a surface view is executed on the UI thread. This is achieved by posting the call as a task to the platform task runner in C++. The changes also introduce a new feature flag, io.flutter.embedding.android.EnableContentSizing, to conditionally enable content sizing logic in various Android views. The unit tests have been updated to accommodate both the asynchronous nature of the fix and the new feature flag. The changes appear to be correct and consistently applied.

Comment on lines +34 to +36
} catch (NameNotFoundException ex) {
Log.e(TAG, "Could not get metadata");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better diagnostics, it's recommended to include the exception object in the log call. This will print the stack trace and provide more context when a NameNotFoundException occurs, making it easier to debug.

Suggested change
} catch (NameNotFoundException ex) {
Log.e(TAG, "Could not get metadata");
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not get metadata", e);
}
References
  1. As per the style guide (line 32), error messages should be useful. Including the exception in the log provides valuable context like the stack trace, which is crucial for debugging. (link)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good suggestion but should be made on master.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI @mboetger

@reidbaker
Copy link
Contributor

Approved as the android tl, Still needs approval from a release engineer (who is not me)

@mboetger can I get you to do a second pass on your changelog description. "[flutter/181573] When resize JNI method is called on Android, apps will crash." What condition causes the resize jni method to be called?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

CPLGTM 👍

@mboetger mboetger added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 3, 2026
@auto-submit auto-submit bot merged commit 55bea55 into flutter:flutter-3.41-candidate.0 Feb 3, 2026
162 checks passed
auto-submit bot pushed a commit that referenced this pull request Feb 6, 2026
There were 2 cherry picks include:

 * #181732
 * #181670 (containing latest engine change 0aafd14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App cp: review Cherry-picks in the review queue 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.

4 participants