Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.embedding.engine.dart.DartExecutor Class Reference
Inheritance diagram for io.flutter.embedding.engine.dart.DartExecutor:
io.flutter.plugin.common.BinaryMessenger

Classes

class  DartCallback
 
class  DartEntrypoint
 
interface  IsolateServiceIdListener
 

Public Member Functions

 DartExecutor (@NonNull FlutterJNI flutterJNI, @NonNull AssetManager assetManager)
 
void onAttachedToJNI ()
 
void onDetachedFromJNI ()
 
boolean isExecutingDart ()
 
void executeDartEntrypoint (@NonNull DartEntrypoint dartEntrypoint)
 
void executeDartEntrypoint ( @NonNull DartEntrypoint dartEntrypoint, @Nullable List< String > dartEntrypointArgs)
 
void executeDartCallback (@NonNull DartCallback dartCallback)
 
BinaryMessenger getBinaryMessenger ()
 
TaskQueue makeBackgroundTaskQueue (TaskQueueOptions options)
 
void send (@NonNull String channel, @Nullable ByteBuffer message)
 
void send ( @NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryMessenger.BinaryReply callback)
 
void setMessageHandler ( @NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler)
 
void setMessageHandler ( @NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler, @Nullable TaskQueue taskQueue)
 
void enableBufferingIncomingMessages ()
 
void disableBufferingIncomingMessages ()
 
int getPendingChannelResponseCount ()
 
String getIsolateServiceId ()
 
void setIsolateServiceIdListener (@Nullable IsolateServiceIdListener listener)
 
void notifyLowMemoryWarning ()
 
- Public Member Functions inherited from io.flutter.plugin.common.BinaryMessenger
default TaskQueue makeBackgroundTaskQueue ()
 
default TaskQueue makeBackgroundTaskQueue (TaskQueueOptions options)
 
void send (@NonNull String channel, @Nullable ByteBuffer message)
 
void send (@NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryReply callback)
 
void setMessageHandler (@NonNull String channel, @Nullable BinaryMessageHandler handler)
 
default void setMessageHandler ( @NonNull String channel, @Nullable BinaryMessageHandler handler, @Nullable TaskQueue taskQueue)
 
default void enableBufferingIncomingMessages ()
 
default void disableBufferingIncomingMessages ()
 

Detailed Description

Configures, bootstraps, and starts executing Dart code.

To specify a top-level Dart function to execute, use a DartEntrypoint to tell DartExecutor where to find the Dart code to execute, and which Dart function to use as the entrypoint. To execute the entrypoint, pass the DartEntrypoint to executeDartEntrypoint(DartEntrypoint).

To specify a Dart callback to execute, use a DartCallback. A given Dart callback must be registered with the Dart VM to be invoked by a DartExecutor. To execute the callback, pass the DartCallback to executeDartCallback(DartCallback).

Once started, a DartExecutor cannot be stopped. The associated Dart code will execute until it completes, or until the io.flutter.embedding.engine.FlutterEngine that owns this DartExecutor is destroyed.

Definition at line 38 of file DartExecutor.java.

Constructor & Destructor Documentation

◆ DartExecutor()

io.flutter.embedding.engine.dart.DartExecutor.DartExecutor ( @NonNull FlutterJNI  flutterJNI,
@NonNull AssetManager  assetManager 
)
inline

Definition at line 60 of file DartExecutor.java.

60 {
61 this.flutterJNI = flutterJNI;
62 this.assetManager = assetManager;
63 this.dartMessenger = new DartMessenger(flutterJNI);
64 dartMessenger.setMessageHandler("flutter/isolate", isolateChannelMessageHandler);
65 this.binaryMessenger = new DefaultBinaryMessenger(dartMessenger);
66 // The JNI might already be attached if coming from a spawned engine. If so, correctly report
67 // that this DartExecutor is already running.
68 if (flutterJNI.isAttached()) {
69 isApplicationRunning = true;
70 }
71 }
void setMessageHandler( @NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler)

Member Function Documentation

◆ disableBufferingIncomingMessages()

void io.flutter.embedding.engine.dart.DartExecutor.disableBufferingIncomingMessages ( )
inline

◆ enableBufferingIncomingMessages()

void io.flutter.embedding.engine.dart.DartExecutor.enableBufferingIncomingMessages ( )
inline
Deprecated:
Use getBinaryMessenger() instead.

Implements io.flutter.plugin.common.BinaryMessenger.

Definition at line 243 of file DartExecutor.java.

243 {
244 dartMessenger.enableBufferingIncomingMessages();
245 }

◆ executeDartCallback()

void io.flutter.embedding.engine.dart.DartExecutor.executeDartCallback ( @NonNull DartCallback  dartCallback)
inline

Starts executing Dart code based on the given dartCallback.

See DartCallback for configuration options.

Parameters
dartCallbackspecifies which Dart callback to run, and where to find it

Definition at line 164 of file DartExecutor.java.

164 {
165 if (isApplicationRunning) {
166 Log.w(TAG, "Attempted to run a DartExecutor that is already running.");
167 return;
168 }
169
170 try (TraceSection e = TraceSection.scoped("DartExecutor#executeDartCallback")) {
171 Log.v(TAG, "Executing Dart callback: " + dartCallback);
173 dartCallback.pathToBundle,
174 dartCallback.callbackHandle.callbackName,
175 dartCallback.callbackHandle.callbackLibraryPath,
176 dartCallback.androidAssetManager,
177 null);
178
179 isApplicationRunning = true;
180 }
181 }
void runBundleAndSnapshotFromLibrary( @NonNull String bundlePath, @Nullable String entrypointFunctionName, @Nullable String pathToEntrypointFunction, @NonNull AssetManager assetManager, @Nullable List< String > entrypointArgs)
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137

◆ executeDartEntrypoint() [1/2]

void io.flutter.embedding.engine.dart.DartExecutor.executeDartEntrypoint ( @NonNull DartEntrypoint  dartEntrypoint,
@Nullable List< String >  dartEntrypointArgs 
)
inline

Starts executing Dart code based on the given dartEntrypoint and the
dartEntrypointArgs
.

See DartEntrypoint for configuration options.

Parameters
dartEntrypointspecifies which Dart function to run, and where to find it
dartEntrypointArgsArguments passed as a list of string to Dart's entrypoint function.

Definition at line 137 of file DartExecutor.java.

138 {
139 if (isApplicationRunning) {
140 Log.w(TAG, "Attempted to run a DartExecutor that is already running.");
141 return;
142 }
143
144 try (TraceSection e = TraceSection.scoped("DartExecutor#executeDartEntrypoint")) {
145 Log.v(TAG, "Executing Dart entrypoint: " + dartEntrypoint);
147 dartEntrypoint.pathToBundle,
148 dartEntrypoint.dartEntrypointFunctionName,
149 dartEntrypoint.dartEntrypointLibrary,
150 assetManager,
151 dartEntrypointArgs);
152
153 isApplicationRunning = true;
154 }
155 }

◆ executeDartEntrypoint() [2/2]

void io.flutter.embedding.engine.dart.DartExecutor.executeDartEntrypoint ( @NonNull DartEntrypoint  dartEntrypoint)
inline

Starts executing Dart code based on the given dartEntrypoint.

See DartEntrypoint for configuration options.

Parameters
dartEntrypointspecifies which Dart function to run, and where to find it

Definition at line 124 of file DartExecutor.java.

124 {
125 executeDartEntrypoint(dartEntrypoint, null);
126 }
void executeDartEntrypoint(@NonNull DartEntrypoint dartEntrypoint)

◆ getBinaryMessenger()

BinaryMessenger io.flutter.embedding.engine.dart.DartExecutor.getBinaryMessenger ( )
inline

Returns a BinaryMessenger that can be used to send messages to, and receive messages from, Dart code that this DartExecutor is executing.

Definition at line 188 of file DartExecutor.java.

188 {
189 return binaryMessenger;
190 }

◆ getIsolateServiceId()

String io.flutter.embedding.engine.dart.DartExecutor.getIsolateServiceId ( )
inline

Returns an identifier for this executor's primary isolate. This identifier can be used in queries to the Dart service protocol.

Definition at line 279 of file DartExecutor.java.

279 {
280 return isolateServiceId;
281 }

◆ getPendingChannelResponseCount()

int io.flutter.embedding.engine.dart.DartExecutor.getPendingChannelResponseCount ( )
inline

Returns the number of pending channel callback replies.

When sending messages to the Flutter application using ByteBuffer, io.flutter.plugin.common.BinaryMessenger.BinaryReply), developers can optionally specify a reply callback if they expect a reply from the Flutter application.

This method tracks all the pending callbacks that are waiting for response, and is supposed to be called from the main thread (as other methods). Calling from a different thread could possibly capture an indeterministic internal state, so don't do it.

Currently, it's mainly useful for a testing framework like Espresso to determine whether all the async channel callbacks are handled and the app is idle.

Definition at line 270 of file DartExecutor.java.

270 {
271 return dartMessenger.getPendingChannelResponseCount();
272 }

◆ isExecutingDart()

boolean io.flutter.embedding.engine.dart.DartExecutor.isExecutingDart ( )
inline

Is this DartExecutor currently executing Dart code?

Returns
true if Dart code is being executed, false otherwise

Definition at line 113 of file DartExecutor.java.

113 {
114 return isApplicationRunning;
115 }

◆ makeBackgroundTaskQueue()

TaskQueue io.flutter.embedding.engine.dart.DartExecutor.makeBackgroundTaskQueue ( TaskQueueOptions  options)
inline
Deprecated:
Use getBinaryMessenger() instead.

Implements io.flutter.plugin.common.BinaryMessenger.

Definition at line 197 of file DartExecutor.java.

197 {
198 return binaryMessenger.makeBackgroundTaskQueue(options);
199 }
const char * options

◆ notifyLowMemoryWarning()

void io.flutter.embedding.engine.dart.DartExecutor.notifyLowMemoryWarning ( )
inline

Notify the Dart VM of a low memory event, or that the application is in a state such that now is an appropriate time to free resources, such as going to the background.

This does not notify a Flutter application about memory pressure. For that, use the io.flutter.embedding.engine.systemchannels.SystemChannel#sendMemoryPressureWarning.

Calling this method may cause jank or latency in the application. Avoid calling it during critical periods like application startup or periods of animation.

Definition at line 309 of file DartExecutor.java.

309 {
310 if (flutterJNI.isAttached()) {
311 flutterJNI.notifyLowMemoryWarning();
312 }
313 }

◆ onAttachedToJNI()

void io.flutter.embedding.engine.dart.DartExecutor.onAttachedToJNI ( )
inline

Invoked when the io.flutter.embedding.engine.FlutterEngine that owns this DartExecutor attaches to JNI.

When attached to JNI, this DartExecutor begins handling 2-way communication to/from the Dart execution context. This communication is facilitate via 2 APIs:

Definition at line 85 of file DartExecutor.java.

85 {
86 Log.v(
87 TAG,
88 "Attached to JNI. Registering the platform message handler for this Dart execution"
89 + " context.");
90 flutterJNI.setPlatformMessageHandler(dartMessenger);
91 }
void setPlatformMessageHandler(@Nullable PlatformMessageHandler platformMessageHandler)

◆ onDetachedFromJNI()

void io.flutter.embedding.engine.dart.DartExecutor.onDetachedFromJNI ( )
inline

Invoked when the io.flutter.embedding.engine.FlutterEngine that owns this DartExecutor detaches from JNI.

When detached from JNI, this DartExecutor stops handling 2-way communication to/from the Dart execution context.

Definition at line 100 of file DartExecutor.java.

100 {
101 Log.v(
102 TAG,
103 "Detached from JNI. De-registering the platform message handler for this Dart execution"
104 + " context.");
105 flutterJNI.setPlatformMessageHandler(null);
106 }

◆ send() [1/2]

void io.flutter.embedding.engine.dart.DartExecutor.send ( @NonNull String  channel,
@Nullable ByteBuffer  message,
@Nullable BinaryMessenger.BinaryReply  callback 
)
inline
Deprecated:
Use getBinaryMessenger() instead.

Definition at line 213 of file DartExecutor.java.

216 {
217 binaryMessenger.send(channel, message, callback);
218 }
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void send(@NonNull String channel, @Nullable ByteBuffer message)
Win32Message message

◆ send() [2/2]

void io.flutter.embedding.engine.dart.DartExecutor.send ( @NonNull String  channel,
@Nullable ByteBuffer  message 
)
inline
Deprecated:
Use getBinaryMessenger() instead.

Implements io.flutter.plugin.common.BinaryMessenger.

Definition at line 205 of file DartExecutor.java.

205 {
206 binaryMessenger.send(channel, message);
207 }

◆ setIsolateServiceIdListener()

void io.flutter.embedding.engine.dart.DartExecutor.setIsolateServiceIdListener ( @Nullable IsolateServiceIdListener  listener)
inline

Set a listener that will be notified when an isolate identifier is available for this executor's primary isolate.

Definition at line 292 of file DartExecutor.java.

292 {
293 isolateServiceIdListener = listener;
294 if (isolateServiceIdListener != null && isolateServiceId != null) {
295 isolateServiceIdListener.onIsolateServiceIdAvailable(isolateServiceId);
296 }
297 }
void onIsolateServiceIdAvailable(@NonNull String isolateServiceId)

◆ setMessageHandler() [1/2]

void io.flutter.embedding.engine.dart.DartExecutor.setMessageHandler ( @NonNull String  channel,
@Nullable BinaryMessenger.BinaryMessageHandler  handler 
)
inline
Deprecated:
Use getBinaryMessenger() instead.

Definition at line 224 of file DartExecutor.java.

225 {
226 binaryMessenger.setMessageHandler(channel, handler);
227 }
void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler)

◆ setMessageHandler() [2/2]

void io.flutter.embedding.engine.dart.DartExecutor.setMessageHandler ( @NonNull String  channel,
@Nullable BinaryMessenger.BinaryMessageHandler  handler,
@Nullable TaskQueue  taskQueue 
)
inline
Deprecated:
Use getBinaryMessenger() instead.

Definition at line 233 of file DartExecutor.java.

236 {
237 binaryMessenger.setMessageHandler(channel, handler, taskQueue);
238 }

The documentation for this class was generated from the following file: