Skip to content

Background Platform Channels #91635

@gaaclarke

Description

@gaaclarke

Implement a way for Platform Channels to execute their host platform handlers on a background thread instead of forcing them to use the platform thread.

Design doc: https://docs.google.com/document/d/1Y-fFKimMxt7xtZcnPmYp4bRgOlVfS5-xOpdcWYfXJug/edit?usp=sharing

Example usage:

public class PluginCodelabPlugin implements FlutterPlugin, MethodCallHandler {
  private MethodChannel methodChannel;
  private BasicMessageChannel<Object> basicChannel;

  private static void setup(PluginCodelabPlugin plugin,
                            BinaryMessenger binaryMessenger) {
    // This is a new call to create the TaskQueue.
    BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeTaskQueue();
    // The 3rd parameter is new.
    plugin.methodChannel = new MethodChannel(binaryMessenger, "method", taskQueue);
    plugin.methodChannel.setMethodCallHandler(plugin);
    // The 4th parameter is new.
    plugin.basicChannel =
      new BasicMessageChannel<>(binaryMessenger,
                                "basic",
                                StandardMessageCodec.INSTANCE,
                                taskQueue);
    plugin.basicChannel.setMessageHandler((message, reply) -> reply.reply(null));
  }

  @Override
  public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
    setup(this, flutterPluginBinding.getBinaryMessenger());
  }

  @Override
  public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
    result.notImplemented();
  }
}

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: new featureNothing broken; request for a new capabilityc: performanceRelates to speed or footprint issues (see "perf:" labels)c: proposalA detailed proposal for a change to Fluttercustomer: money (g3)engineflutter/engine related. See also e: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions