Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[android] Fix unexpected behavior in |detachFromFlutterEngine|. - #30202

Merged
fluttergithubbot merged 6 commits into
flutter-team-archive:mainfrom
0xZOne:task/detachFromFlutterEngine
Dec 9, 2021
Merged

fluttergithubbot merged 6 commits into
flutter-team-archive:mainfrom
0xZOne:task/detachFromFlutterEngine

Conversation

@0xZOne

@0xZOne 0xZOne commented Dec 8, 2021 •

Copy link
Copy Markdown
Contributor

Fixes flutter/flutter#94802

Related issue: flutter/flutter#49950 (comment)

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 and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

if (delegate == null) {
Log.w(TAG, "FlutterActivity " + hashCode() + " " + event + " called after release.");
if (delegate == null || !delegate.isAttached()) {
Log.w(TAG, "FlutterActivity " + hashCode() + " " + event + " called after detach.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

delegate becomes null in release, so this is still true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

public void updateSystemUiOverlays() {
if (delegate != null) {
if (delegate != null && delegate.isAttached()) {
delegate.updateSystemUiOverlays();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

updateSystemUiOverlays could check this internally. This way there's no need to expose isAttached in the public API of the delegate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

+ getFlutterEngine()
+ " evicted by another attaching activity");
release();
delegate.onDestroyView();

@blasten blasten Dec 8, 2021 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please check for delegate != null before calling methods.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, since you are making this change, could release also perform that check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

private boolean stillAttachedForEvent(String event) {
if (delegate == null) {
Log.w(TAG, "FlutterActivity " + hashCode() + " " + event + " called after release.");
if (delegate == null || !delegate.isAttached()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't need to add delegate.isAttached() here. what issue is this addressing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is needed. Here is to solve app lifecycle event crosstalk.

private boolean stillAttachedForEvent(String event) {
if (delegate == null) {
Log.w(TAG, "FlutterFragment " + hashCode() + " " + event + " called after release.");
if (delegate == null || !delegate.isAttached()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

similar comments as above

@0xZOne
0xZOne requested a review from blasten December 9, 2021 02:04
Comment on lines +1144 to +1145
Log.w(
TAG, "FlutterActivity " + hashCode() + " " + event + " called after release or detach.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can this avoid (either/or)? If someone is looking at this log, it's always better to know exactly what is going on.
I'd suggest to break this log into two.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

@0xZOne
0xZOne requested a review from blasten December 9, 2021 02:58
+ " connection to the engine "
+ getFlutterEngine()
+ " evicted by another attaching activity");
release();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what about adding a test to ensure that detachFromFlutterEngine() doesn't release the engine?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

@0xZOne
0xZOne requested a review from blasten December 9, 2021 03:33
flutterActivity.onPause();
flutterActivity.detachFromFlutterEngine();
assertNotNull(mockDelegate);
assertFalse(mockDelegate.isAttached());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this works, but can we also add a test where mockDelegate is indeed null. This ensures that the test itself is working as one would expect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

@0xZOne
0xZOne requested a review from blasten December 9, 2021 08:26

@blasten blasten left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Development

Successfully merging this pull request may close these issues.

[shared engine][android] Unexpected behavior in detachFromFlutterEngine

3 participants