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

[image_picker] Fixes activity leak#4439

Merged
fluttergithubbot merged 2 commits intoflutter:mainfrom
0xZOne:task/image_picker_leaks
Mar 10, 2022
Merged

[image_picker] Fixes activity leak#4439
fluttergithubbot merged 2 commits intoflutter:mainfrom
0xZOne:task/image_picker_leaks

Conversation

@0xZOne
Copy link
Copy Markdown
Member

@0xZOne 0xZOne commented Oct 20, 2021

Fixes flutter/flutter#92148

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 relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

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

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

Thanks for the submission! You removed most of the PR checklist; it's there for a reason, and many of the items you removed are not optional. I'm going to mark this as a draft for now; please restore the original checklist, address the missing elements, then remove the draft designation so that we can get it reviewed.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft October 20, 2021 20:25
@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from f565703 to 0b4c890 Compare October 21, 2021 01:08
@0xZOne
Copy link
Copy Markdown
Member Author

0xZOne commented Oct 21, 2021

Thanks for the submission! You removed most of the PR checklist; it's there for a reason, and many of the items you removed are not optional. I'm going to mark this as a draft for now; please restore the original checklist, address the missing elements, then remove the draft designation so that we can get it reviewed.

Sorry, I misunderstood. Those removed items are restored now.

@0xZOne 0xZOne marked this pull request as ready for review October 21, 2021 01:58
Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

This change needs these steps. Please see the first link there.

  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.

As discussed at length in the contributing docs, this step is required.

@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch 2 times, most recently from fc3b3a6 to b096c1c Compare October 22, 2021 04:23
@0xZOne
Copy link
Copy Markdown
Member Author

0xZOne commented Oct 22, 2021

This change needs these steps. Please see the first link there.

  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.

As discussed at length in the contributing docs, this step is required.

Just simply recycling resources in tearDown, I don't think there is a need for test cases.

It is hard to add tests here. Any guidance? Thanks. @stuartmorgan

@0xZOne 0xZOne requested a review from stuartmorgan-g October 22, 2021 04:29
@stuartmorgan-g
Copy link
Copy Markdown
Contributor

Just simply recycling resources in tearDown, I don't think there is a need for test cases.

You appear to believe that the bug needs to be fixed, since you filed an issue and submitted a PR. Why wouldn't you want to prevent it from regressing again in the future?

But regardless, PRs here follow Flutter policy (which you've indicated in the checklist that you have read), and personal opinions about the value of tests isn't one of the exemptions listed in that policy.

It is hard to add tests here. Any guidance?

There are lots of possible ways to test this. In order to make the code as future-proof as possible, I would probably move all of this activity-lifetime-bound state into a helper object, so that setup and tearDown would just become constructor and finalize calls of the helper object. Then you could put a package-level accessor on the plugin to see if that helper object is null after the activity is detached, which ensures that all state references have been cleared.

/cc @blasten in case he has alternate preferences.

@0xZOne
Copy link
Copy Markdown
Member Author

0xZOne commented Oct 23, 2021

@stuartmorgan Thank you for your rapid reply and patient.

@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from c9cfde7 to 68f0c30 Compare October 24, 2021 07:15
@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from c52d2de to c7108c1 Compare October 30, 2021 01:44
@0xZOne 0xZOne requested a review from stuartmorgan-g November 5, 2021 01:33
@0xZOne 0xZOne marked this pull request as draft December 6, 2021 01:16
@0xZOne 0xZOne marked this pull request as ready for review December 6, 2021 11:12
@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch 2 times, most recently from b966ec3 to 1067b74 Compare December 9, 2021 11:38
@godofredoc godofredoc changed the base branch from master to main January 6, 2022 22:46
Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

This change needs a version bump since it's changing code behavior, but otherwise looks good to me at a high level.

@blasten Please assign a primary reviewer from the Android side.

@stuartmorgan-g stuartmorgan-g requested review from blasten and removed request for cyanglaz January 21, 2022 17:24
Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with nits


* Updates Android compileSdkVersion to 31.
* Fix iOS RunnerUITests search paths.
* Fix Activity leak
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.

Please add the missing period at the end.

Also this should be "Fixes" per the repo's new CHANGELOG style guide. (It would be great if you could update the line above it the same way.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

channel = null;
application.unregisterActivityLifecycleCallbacks(observer);
application = null;
activityState.release();
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.

Doesn't this need a null check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from 2ec0b45 to 60559bb Compare January 25, 2022 01:47
@0xZOne 0xZOne changed the title [image_picker] Fix activity leak [image_picker] Fixes activity leak Jan 25, 2022
@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch 2 times, most recently from 1860782 to c113535 Compare January 26, 2022 06:22
@stuartmorgan-g
Copy link
Copy Markdown
Contributor

@blasten Ping for second review here?

Comment on lines +120 to +128
// V1 embedding setup for activity listeners.
application.registerActivityLifecycleCallbacks(observer);
registrar.addActivityResultListener(delegate);
registrar.addRequestPermissionsResultListener(delegate);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I will just throw here. We planned on removing the v1 embedding this quarter. cc @GaryQian

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is more appropriate to remove the v1 embedding in another PR.

}
}

ActivityState(final ImagePickerDelegate delegate, final Activity activity) {
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 needs javadocs. when is this constructor preferred over the other one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

// This is null when not using v2 embedding;
private Lifecycle lifecycle;

ActivityState(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

needs java doc

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the behavior of ActivityState#release() depends upon which constructor is used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

}

@Test
public void onDetachedFromActivity_ShouldReleaseActivityState() {
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 testing ActivityState#release() - Is that covered somehow?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ActivityState#release() is an internal helper function and does not need to add special test cases. Here we just need to make sure that ActivityState is released as expected after onDetachedFromActivity is called.

@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch 2 times, most recently from 670c612 to b191e9c Compare March 4, 2022 07:20
@0xZOne 0xZOne requested a review from blasten March 4, 2022 07:21
Copy link
Copy Markdown

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

No version change: The PR does not involve external interface changes.

That's not how our version change policy works. This needs a version change. (I've removed this from the description so that our CI checks will work correctly.)

Please read the explanation of versioning linked from the checklist item about versions.

* Updates Android compileSdkVersion to 31.
* Fix iOS RunnerUITests search paths.
* Fixes iOS RunnerUITests search paths.
* Fixes Activity leak.
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.

Version 0.8.4+5, which is now 5 versions old, did not include this fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done.

@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from b191e9c to 833d9ae Compare March 9, 2022 01:40
@0xZOne 0xZOne requested a review from stuartmorgan-g March 9, 2022 01:42
* Improves the documentation on handling MainActivity being killed by the Android OS.
* Updates Android compileSdkVersion to 31.
* Fix iOS RunnerUITests search paths.
* Fixes iOS RunnerUITests search paths.
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.

Please don't change old versions' notes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I learned!

@@ -1,3 +1,7 @@
## NEXT
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.

As I said before, and as it says in the document I referenced above, this PR needs a version change.

Copy link
Copy Markdown
Member 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 stuartmorgan-g March 9, 2022 05:44
@0xZOne 0xZOne force-pushed the task/image_picker_leaks branch from 72ff357 to 86a271e Compare March 10, 2022 01:44
Copy link
Copy Markdown
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Mar 10, 2022
@fluttergithubbot fluttergithubbot merged commit 6ff862f into flutter:main Mar 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 11, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes p: image_picker platform-android waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[image_picker] [android] The activity leaks in ImagePickerPlugin

4 participants