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

Conversation

bkonyi
Copy link
Contributor

@bkonyi bkonyi commented Jun 28, 2018

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.

blink::Settings settings,
fml::jni::JavaObjectWeakGlobalRef java_object)
fml::jni::JavaObjectWeakGlobalRef java_object,
bool is_background_view)
Copy link
Member

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?

Copy link
Contributor Author

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) {
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

@bkonyi bkonyi force-pushed the android_headless_plugins branch from 1d01869 to 1e36a0d Compare July 13, 2018 17:53
@flutter flutter deleted a comment from googlebot Jul 13, 2018
@flutter flutter deleted a comment from googlebot Jul 13, 2018
@s-bauer
Copy link

s-bauer commented Jul 16, 2018

Any update on this? It's quite important!

@bkonyi
Copy link
Contributor Author

bkonyi commented Jul 16, 2018

@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 dart:ui changes, but since those went in Friday I expect this change should go in soon after the review process is complete. Thanks for your patience!

fxl::RefPtr<fml::TaskRunner> gpu_runner;
fxl::RefPtr<fml::TaskRunner> ui_runner;
fxl::RefPtr<fml::TaskRunner> io_runner;
if (!is_background_view) {
Copy link
Member

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.

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.

version: "1.1.5"
sdks:
dart: ">=1.21.0 <2.0.0"
dart: ">=1.21.0 <=2.0.0-edge.7f1f54edc2cbe5280217ad3c858dd3df515aa3eb"
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@zanderso zanderso left a 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.

Copy link
Member

@chinmaygarde chinmaygarde left a 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(
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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?

@bkonyi bkonyi force-pushed the android_headless_plugins branch from 2449c41 to 3f88c42 Compare August 1, 2018 23:34
@googlebot

This comment has been minimized.

@googlebot googlebot added cla: no and removed cla: yes labels Aug 1, 2018
@googlebot

This comment has been minimized.

@bkonyi bkonyi force-pushed the android_headless_plugins branch from 0f465bc to 2449c41 Compare August 2, 2018 00:24
@googlebot

This comment has been minimized.

1 similar comment
@googlebot

This comment has been minimized.

@bkonyi bkonyi force-pushed the android_headless_plugins branch from df599bb to 8868cdf Compare August 2, 2018 00:37
@bkonyi bkonyi merged commit 2ba3d6b into headless_plugin Aug 3, 2018
@bkonyi bkonyi deleted the android_headless_plugins branch August 3, 2018 23:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants