-
Notifications
You must be signed in to change notification settings - Fork 6k
Updated background execution implementation for Android #5640
Conversation
blink::Settings settings, | ||
fml::jni::JavaObjectWeakGlobalRef java_object) | ||
fml::jni::JavaObjectWeakGlobalRef java_object, | ||
bool is_background_view) |
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.
Why does a headless shell need to be designated as a background view?
Would it be sufficient to create a standard shell and just not attach a surface?
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.
This flag determines whether or not a surface is created for the platform view and what number of task runners are created (see here)
|
||
public void runFromSource(final String assetsDirectory, final String main, final String packages) { | ||
public void runFromBundle(String bundlePath, String snapshotOverride, String entrypoint, | ||
String libraryUrl, boolean reuseRuntimeController, FlutterIsolateStartedEvent event) { |
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.
We should create an object that holds the parameters needed to launch the Dart runtime instead of adding more arguments here. Some of the arguments of runFromBundle() added from past experiments are already obsolete (snapshotOverride, reuseRuntimeController). I'd like to make it easier to evolve this interface.
@chinmaygarde had a proposal for refactoring the host APIs along these lines
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.
I think that's a good idea. Would you happen to know if there's a doc for this proposal?
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.
I've gone ahead and added FlutterRunArguments
to hold all the parameters required for entering an isolate in a new shell. Added deprecation message for all other runFromBundle
definitions that don't use this new argument object.
private static native long nativeAttach(FlutterNativeView view); | ||
private void onStarted(boolean success) { | ||
if (startedEvent == null) return; | ||
startedEvent.onStarted(success); |
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.
What is this event used for? Can this be replaced by a message sent by the app on a platform channel at a time of the app's choosing?
This will be called after the engine invokes _startMainIsolate, and the app code may not be fully initialized when this callback happens.
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.
This event is used to notify that the either the new shell has started running or there was an error starting the shell. Other than having this event, I don't believe that the plugin can determine whether or not the new shell was started successfully.
Good point about this being called after _startMainIsolate is invoked when the app still may not be fully initialized, but we could totally use a platform channel to notify the plugin when the background callback determines that initialization is complete.
1d01869
to
1e36a0d
Compare
Any update on this? It's quite important! |
@s-bauer yes, this is being worked on. The iOS changes needed to land first since this PR depended on some of the engine and |
fxl::RefPtr<fml::TaskRunner> gpu_runner; | ||
fxl::RefPtr<fml::TaskRunner> ui_runner; | ||
fxl::RefPtr<fml::TaskRunner> io_runner; | ||
if (!is_background_view) { |
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.
Think positive! Change to if (is_background_view) and swap if and else.
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.
Done.
version: "1.1.5" | ||
sdks: | ||
dart: ">=1.21.0 <2.0.0" | ||
dart: ">=1.21.0 <=2.0.0-edge.7f1f54edc2cbe5280217ad3c858dd3df515aa3eb" |
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.
That upper bound looks a bit strange.
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.
Yeah, the license script likes to update that field to weird stuff. See here for what it is currently.
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.
lgtm, but also bug jason, chinamy, or chris for any more comments.
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.
A few nits but I like the direction of this patch. Thanks!
"rendering."; | ||
} | ||
|
||
PlatformViewAndroid::PlatformViewAndroid( |
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.
I would be more comfortable with this being a separate subclass of PlatformView. Though you have added a null checks to the surface on each call site, there are also other callbacks that make no sense in a background execution context. Stuff like the first frame callback and such.
We can iterate on this in a subsequent patch however. I don't think this is necessarily blocking.
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.
That sounds like a plan!
"started and run."; | ||
success = true; | ||
} | ||
view->InvokeOnStartedCallback(success); |
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.
Attach a closure to the root_isolate_create_callback
field of the settings object used to start this shell. This will fire the callback only if the isolate is correctly launched and also take care of re-firing the callback in case of cold-restart events (which the plugins also probably need to react to). You will lose the ability for the plugin to react to failed launches. But, then again, there isn't much it can do now either. So, we may have to devise a more robust error recovery/reporting mechanism. But till that time, lets use the existing hooks.
Be careful that the callback in the settings object is fire on the UI thread, you might have to post a task back to the platform thread to fire a message back to the platform.
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.
On second thought, I don't think this is particularly useful if we have no way of notifying the plugin that we failed to start. I've gone ahead and removed this.
|
||
void FlutterViewOnFirstFrame(JNIEnv* env, jobject obj); | ||
|
||
void FlutterViewOnStarted(JNIEnv* env, jobject obj, jboolean success); |
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.
"started" is a rather nebulous term. Can be make this more descriptive like OnRootIsolateDidStart
or something?
2449c41
to
3f88c42
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0f465bc
to
2449c41
Compare
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
352a2f2
to
df599bb
Compare
df599bb
to
8868cdf
Compare
This change depends on changes made in PR #5539. Also,
clang-format
had some fun formatting a lot more than I had changed, so I apologize for the numerous white space changes!Fixes the Android portion of #3671 and is required to fix #17566.