This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fold the calls for FlutterMain into the FlutterEngine constructor #12069
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4cf02f9
start
xster 4239d8d
Fold in the calls to FlutterMain into the FlutterEngine constructor
xster d20c695
added tests
xster e8bd656
make tests work
xster fa0cff5
review
xster 421691c
Make an injector and move the flutter main content to a flutter loader
xster c80e083
tests work
xster 520c18a
poke at the license script, see if that makes it happy
xster 2cef89f
move engine to new api
xster 916b010
manually patch the license golden
xster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter; | ||
|
|
||
| import android.support.annotation.NonNull; | ||
| import android.support.annotation.VisibleForTesting; | ||
|
|
||
| import io.flutter.embedding.engine.loader.FlutterLoader; | ||
|
|
||
| import java.lang.IllegalStateException; | ||
|
|
||
| /* | ||
| * This class is a simple dependency injector for the Android part of the Flutter engine. | ||
| * | ||
| * This simple solution is used facilitate testability without bringing in heavier app-development | ||
| * centric dependency injection frameworks such as Guice or Dagger2. | ||
| */ | ||
| public final class FlutterInjector { | ||
|
|
||
| private static FlutterInjector instance; | ||
| private static boolean accessed; | ||
|
|
||
| /* | ||
| * Use {@link FlutterInjector.Builder} to specify members to be injected via the static | ||
| * {@code FlutterInjector}. | ||
| * | ||
| * This can only be called at the beginning of the program before the {@link #instance()} is | ||
| * accessed. | ||
| */ | ||
| public static void setInstance(@NonNull FlutterInjector injector) { | ||
| if (accessed) { | ||
| throw new IllegalStateException("Cannot change the FlutterInjector instance once it's been " + | ||
| "read. If you're trying to dependency inject, be sure to do so at the beginning of " + | ||
| "the program"); | ||
| } | ||
| instance = injector; | ||
| } | ||
|
|
||
| /* | ||
| * Retrieve the static instance of the {@code FlutterInjector} to use in your program. | ||
| * | ||
| * Once you access it, you can no longer change the values injected. | ||
| * | ||
| * If no override is provided for the injector, reasonable defaults are provided. | ||
| */ | ||
| public static FlutterInjector instance() { | ||
| accessed = true; | ||
| if (instance == null) { | ||
| instance = new Builder().build(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| // This whole class is here to enable testing so to test the thing that lets you test, some degree | ||
| // of hack is needed. | ||
| @VisibleForTesting | ||
| /* Package default */ static void reset() { | ||
| accessed = false; | ||
| instance = null; | ||
| } | ||
|
|
||
| private FlutterInjector( | ||
| boolean isRunningInRobolectricTest, | ||
| @NonNull FlutterLoader flutterLoader | ||
| ) { | ||
| this.isRunningInRobolectricTest = isRunningInRobolectricTest; | ||
| this.flutterLoader = flutterLoader; | ||
| } | ||
|
|
||
| private boolean isRunningInRobolectricTest; | ||
| private FlutterLoader flutterLoader; | ||
|
|
||
| public boolean isRunningInRobolectricTest() { | ||
| return isRunningInRobolectricTest; | ||
| } | ||
|
|
||
| @NonNull | ||
| public FlutterLoader flutterLoader() { | ||
| return flutterLoader; | ||
| } | ||
|
|
||
| /* | ||
| * Builder used to supply a custom FlutterInjector instance to | ||
| * {@link FlutterInjector#setInstance(FlutterInjector)}. | ||
| * | ||
| * Non-overriden values have reasonable defaults. | ||
| */ | ||
| public static final class Builder { | ||
|
|
||
| private boolean isRunningInRobolectricTest = false; | ||
| public Builder setIsRunningInRobolectricTest(boolean isRunningInRobolectricTest) { | ||
| this.isRunningInRobolectricTest = isRunningInRobolectricTest; | ||
| return this; | ||
| } | ||
|
|
||
| private FlutterLoader flutterLoader; | ||
| public Builder setFlutterLoader(@NonNull FlutterLoader flutterLoader) { | ||
| this.flutterLoader = flutterLoader; | ||
| return this; | ||
| } | ||
|
|
||
| public FlutterInjector build() { | ||
| if (flutterLoader == null) { | ||
| flutterLoader = new FlutterLoader(); | ||
| } | ||
|
|
||
| return new FlutterInjector(isRunningInRobolectricTest, flutterLoader); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you describe the time and memory impact of this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's loop back to this after I write the website page for this this week-ish. I'd like to keep all these numbers in a centralized place that's easy to update if they change.