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

[quick_actions] Android support only calling initialize once #4204

Merged
merged 11 commits into from
Aug 17, 2021

Conversation

monmanuela
Copy link
Contributor

Fixes flutter/flutter#87259

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.

Copy link
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.

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

While this does change a test file, there's no actually testing of the new functionality. Per separate discussion, that will need a native integration test that actually drives a quick actions flow.

private static final String CHANNEL_ID = "plugins.flutter.io/quick_actions";
protected static boolean isInitialized = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this static? Wouldn't each instance of the plugin need to be initialized?

Copy link

Choose a reason for hiding this comment

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

sounds like the use case is to support a single initialization. If that is the case, it could still be an instance field.

That said, I don't there's such a case as registering/initializing the same plugin name more than once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as it's unnecessary. Thanks.

@@ -43,6 +47,10 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
handler.setActivity(binding.getActivity());
binding.addOnNewIntentListener(this);
if (isInitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this (and the new method) needed? I don't see any deferment logic, so couldn't it just send the call unconditionally?

Copy link
Contributor Author

@monmanuela monmanuela Jul 30, 2021

Choose a reason for hiding this comment

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

Ah my bad. Initially I thought it'll call onNewIntent when the Dart side isn't initialized yet, which means it'll make a redundant method call which would just vanish. But after checking again, the method call does go through to Dart.

Removed the if block, the static field, and the new method. Thanks for catching this.

@@ -24,6 +25,7 @@ class MethodChannelQuickActions extends QuickActionsPlatform {
assert(call.method == 'launch');
handler(call.arguments);
});
unawaited(channel.invokeMethod<String?>('initialize'));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're going to call a new method, you should make it a no-op on iOS to avoid getting useless error messages (although per other comments, it's not clear to me that this is necessary).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as it's not necessary.

@stuartmorgan-g stuartmorgan-g requested a review from blasten July 29, 2021 20:14
@stuartmorgan-g
Copy link
Contributor

Adding @blasten to review the Android intent flow aspect of this.

@@ -60,6 +69,15 @@ public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}

@Override
public boolean onNewIntent(Intent intent) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false;
Copy link

Choose a reason for hiding this comment

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

Suggested change
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

}
return false;
}

private void setupChannel(BinaryMessenger messenger, Context context, Activity activity) {
channel = new MethodChannel(messenger, CHANNEL_ID);
handler = new MethodCallHandlerImpl(context, activity);
Copy link

Choose a reason for hiding this comment

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

MethodCallHandlerImpl could take an object that implements an interface. Then, QuickActionsPlugin could implement the interface. Lastly, pass the reference when it constructs MethodCallHandlerImpl.

Copy link

Choose a reason for hiding this comment

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

The interface implementation sets isInitialized = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. But as per stuartmorgan@'s comment above, removed the field as it's not necessary.

@@ -43,6 +47,10 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
@Override
public void onAttachedToActivity(ActivityPluginBinding binding) {
handler.setActivity(binding.getActivity());
binding.addOnNewIntentListener(this);
if (isInitialized) {
Copy link

Choose a reason for hiding this comment

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

could we add comments to the code? That will help the next maintainer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@monmanuela
Copy link
Contributor Author

Thanks for the reviews! 😄 Responded to the comments.

Copy link

@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.

Implementation LGTM, but it may also need a test.

@bparrishMines is there a plan to backfill this plugin as well?

Copy link
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.

Implementation LGTM, but it may also need a test.

Yes, this will need a test per my initial comment.

@bparrishMines is there a plan to backfill this plugin as well?

The scaffolding is in place now so it should be possible to add an integration test to this PR.

@monmanuela
Copy link
Contributor Author

Per @bparrishMines 's suggestions in a separate discussion, added unit tests for the new functionality

Copy link
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.

It wasn't actually clear to me from the offline discussion why unit tests are better here than UI tests of the actual flow (which would ensure that whole user flow behaves as expected), but it looks like this has reasonable coverage of the change so LGTM.

@stuartmorgan-g stuartmorgan-g merged commit d58036f into flutter:master Aug 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[quick_actions] Android support only calling initialize once
3 participants