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

Conversation

@xster
Copy link
Member

@xster xster commented Apr 2, 2021

Was reverted in #25393

Fixes flutter/flutter#74646
Fixes flutter/flutter#79663

@xster xster marked this pull request as ready for review April 10, 2021 06:47
@xster xster requested a review from gaaclarke April 10, 2021 06:47
*/
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
if (flutterFragment.isFlutterEngineInjected()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the key bit that is different from the previous PR. It seems like there was a long-standing bug where even if the engine says don't auto-register, the activity registers it anyway, which makes it hard to test in while avoiding annoying registration errors.

Comically, this change makes everything harder to test since only a non-injected engine has the auto-registering behavior but a non-injected engine is harder to prevent real JNI calls on. Add more plumbing to make a default constructed engine testable.

}

@NonNull
public FlutterJNI.Factory flutterJNIFactory() {
Copy link
Member

Choose a reason for hiding this comment

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

nit: isn't it idiomatic in java to name this getFlutterJNIFactory()?

Copy link
Member Author

Choose a reason for hiding this comment

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

you're right

// If the FlutterEngine was explicitly built and injected into this FlutterActivity, the
// builder should explicitly decide whether to automatically register plugins via the
// FlutterEngine's construction parameter or via the AndroidManifest metadata.
return;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, should we report this? Potentially with an exception or a return value?

Copy link
Member Author

Choose a reason for hiding this comment

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

both the engine registration and the activity registration paths are called 99% of the time. We should just ignore the second call.

* A factory for creating {@code FlutterJNI} instances. Useful for FlutterJNI injections during
* tests.
*/
public static class Factory {
Copy link
Member

Choose a reason for hiding this comment

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

nit: The pattern should have the Factory being an interface. It's not a huge deal here, but helps if anyone tries to add methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

it creates a bit more indirection to be able to instantiate one if it was an interface though

@xster xster added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Apr 14, 2021
@fluttergithubbot fluttergithubbot merged commit 971a851 into flutter:master Apr 14, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 14, 2021
@xster xster deleted the plugin-registration branch April 15, 2021 07:22
duanqz pushed a commit to duanqz/engine that referenced this pull request Apr 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-android waiting for tree to go green 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.

There's potential double registering of plugins Deduplicate FlutterEngine.registerPlugins and GeneratedPluginRegister

5 participants