diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java index f7cdd855d7..ffbbec06d8 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java @@ -7,6 +7,7 @@ package io.flutter.embedding.engine.dart; import android.content.res.AssetManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.util.Log; import java.nio.ByteBuffer; @@ -145,6 +146,7 @@ public class DartExecutor implements BinaryMessenger { * @param message the message payload, a direct-allocated {@link ByteBuffer} with the message bytes */ @Override + @UiThread public void send(@NonNull String channel, @Nullable ByteBuffer message) { messenger.send(channel, message, null); } @@ -159,6 +161,7 @@ public class DartExecutor implements BinaryMessenger { * @param callback a callback invoked when the Dart application responds to the message */ @Override + @UiThread public void send(@NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryMessenger.BinaryReply callback) { messenger.send(channel, message, callback); } @@ -172,6 +175,7 @@ public class DartExecutor implements BinaryMessenger { * @param handler a {@link BinaryMessageHandler} to be invoked on incoming messages, or null. */ @Override + @UiThread public void setMessageHandler(@NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler) { messenger.setMessageHandler(channel, handler); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java index e9fe0a7cd8..eb24a6f5bc 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java @@ -6,6 +6,7 @@ package io.flutter.embedding.engine.dart; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.util.Log; import java.nio.ByteBuffer; @@ -53,6 +54,7 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler { } @Override + @UiThread public void send(@NonNull String channel, @NonNull ByteBuffer message) { send(channel, message, null); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java index ae21e89736..15cee8bb60 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java @@ -4,6 +4,7 @@ package io.flutter.plugin.common; +import android.support.annotation.UiThread; import android.util.Log; import java.nio.ByteBuffer; @@ -73,6 +74,7 @@ public final class BasicMessageChannel { * @param message the message, possibly null. * @param callback a {@link Reply} callback, possibly null. */ + @UiThread public void send(T message, final Reply callback) { messenger.send(name, codec.encodeMessage(message), callback == null ? null : new IncomingReplyHandler(callback)); @@ -89,6 +91,7 @@ public final class BasicMessageChannel { * * @param handler a {@link MessageHandler}, or null to deregister. */ + @UiThread public void setMessageHandler(final MessageHandler handler) { messenger.setMessageHandler(name, handler == null ? null : new IncomingMessageHandler(handler)); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java index 9f1e4eb4b6..8906d12864 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import android.support.annotation.UiThread; + import java.nio.ByteBuffer; /** @@ -29,6 +31,7 @@ public interface BinaryMessenger { * @param message the message payload, a direct-allocated {@link ByteBuffer} with the message bytes * between position zero and current position, or null. */ + @UiThread void send(String channel, ByteBuffer message); /** @@ -42,6 +45,7 @@ public interface BinaryMessenger { * @param callback a {@link BinaryReply} callback invoked when the Flutter application responds to the * message, possibly null. */ + @UiThread void send(String channel, ByteBuffer message, BinaryReply callback); /** @@ -57,6 +61,7 @@ public interface BinaryMessenger { * @param channel the name {@link String} of the channel. * @param handler a {@link BinaryMessageHandler} to be invoked on incoming messages, or null. */ + @UiThread void setMessageHandler(String channel, BinaryMessageHandler handler); /** @@ -76,6 +81,7 @@ public interface BinaryMessenger { * @param message the message {@link ByteBuffer} payload, possibly null. * @param reply A {@link BinaryReply} used for submitting a reply back to Flutter. */ + @UiThread void onMessage(ByteBuffer message, BinaryReply reply); } @@ -92,6 +98,7 @@ public interface BinaryMessenger { * outgoing replies must place the reply bytes between position zero and current position. * Reply receivers can read from the buffer directly. */ + @UiThread void reply(ByteBuffer reply); } } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/EventChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/EventChannel.java index 2866691275..15c50a9131 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/EventChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/EventChannel.java @@ -4,6 +4,7 @@ package io.flutter.plugin.common; +import android.support.annotation.UiThread; import android.util.Log; import io.flutter.BuildConfig; @@ -83,6 +84,7 @@ public final class EventChannel { * * @param handler a {@link StreamHandler}, or null to deregister. */ + @UiThread public void setStreamHandler(final StreamHandler handler) { messenger.setMessageHandler(name, handler == null ? null : new IncomingStreamRequestHandler(handler)); } @@ -216,6 +218,7 @@ public final class EventChannel { final AtomicBoolean hasEnded = new AtomicBoolean(false); @Override + @UiThread public void success(Object event) { if (hasEnded.get() || activeSink.get() != this) { return; @@ -224,6 +227,7 @@ public final class EventChannel { } @Override + @UiThread public void error(String errorCode, String errorMessage, Object errorDetails) { if (hasEnded.get() || activeSink.get() != this) { return; @@ -234,6 +238,7 @@ public final class EventChannel { } @Override + @UiThread public void endOfStream() { if (hasEnded.getAndSet(true) || activeSink.get() != this) { return; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java index 1c8c8636fa..e468b9b277 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java @@ -6,6 +6,7 @@ package io.flutter.plugin.common; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.util.Log; import io.flutter.BuildConfig; @@ -78,6 +79,7 @@ public final class MethodChannel { * @param method the name String of the method. * @param arguments the arguments for the invocation, possibly null. */ + @UiThread public void invokeMethod(@NonNull String method, @Nullable Object arguments) { invokeMethod(method, arguments, null); } @@ -91,6 +93,7 @@ public final class MethodChannel { * @param arguments the arguments for the invocation, possibly null. * @param callback a {@link Result} callback for the invocation result, or null. */ + @UiThread public void invokeMethod(String method, @Nullable Object arguments, Result callback) { messenger.send(name, codec.encodeMethodCall(new MethodCall(method, arguments)), callback == null ? null : new IncomingResultHandler(callback)); @@ -110,6 +113,7 @@ public final class MethodChannel { * * @param handler a {@link MethodCallHandler}, or null to deregister. */ + @UiThread public void setMethodCallHandler(final @Nullable MethodCallHandler handler) { messenger.setMessageHandler(name, handler == null ? null : new IncomingMethodCallHandler(handler)); @@ -137,6 +141,7 @@ public final class MethodChannel { * @param call A {@link MethodCall}. * @param result A {@link Result} used for submitting the result of the call. */ + @UiThread void onMethodCall(MethodCall call, Result result); } @@ -156,6 +161,7 @@ public final class MethodChannel { * * @param result The result, possibly null. */ + @UiThread void success(@Nullable Object result); /** @@ -165,11 +171,13 @@ public final class MethodChannel { * @param errorMessage A human-readable error message String, possibly null. * @param errorDetails Error details, possibly null */ + @UiThread void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails); /** * Handles a call to an unimplemented method. */ + @UiThread void notImplemented(); } @@ -181,6 +189,7 @@ public final class MethodChannel { } @Override + @UiThread public void reply(ByteBuffer reply) { try { if (reply == null) { @@ -206,6 +215,7 @@ public final class MethodChannel { } @Override + @UiThread public void onMessage(ByteBuffer message, final BinaryReply reply) { final MethodCall call = codec.decodeMethodCall(message); try { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 08c378d337..e1dc5b667c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -10,6 +10,7 @@ import static android.view.MotionEvent.PointerProperties; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; +import android.support.annotation.UiThread; import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; @@ -92,6 +93,7 @@ public class PlatformViewsController implements MethodChannel.MethodCallHandler, * After calling this the platform views controller will no longer listen to it's previous messenger, and will * not maintain references to the texture registry, context, and messenger passed to the previous attach call. */ + @UiThread public void detach() { mMessenger.setMessageHandler(CHANNEL_NAME, null); mMessenger = null; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java index 65622be1f4..8e227bbef7 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -7,6 +7,7 @@ package io.flutter.view; import android.app.Activity; import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import android.util.Log; import io.flutter.app.FlutterPluginRegistry; import io.flutter.embedding.engine.FlutterJNI; @@ -138,11 +139,13 @@ public class FlutterNativeView implements BinaryMessenger { } @Override + @UiThread public void send(String channel, ByteBuffer message) { dartExecutor.send(channel, message); } @Override + @UiThread public void send(String channel, ByteBuffer message, BinaryReply callback) { if (!isAttached()) { Log.d(TAG, "FlutterView.send called on a detached view, channel=" + channel); @@ -153,6 +156,7 @@ public class FlutterNativeView implements BinaryMessenger { } @Override + @UiThread public void setMessageHandler(String channel, BinaryMessageHandler handler) { dartExecutor.setMessageHandler(channel, handler); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 075a828f2e..5603695cb2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -17,6 +17,7 @@ import android.os.Build; import android.os.Handler; import android.os.LocaleList; import android.support.annotation.RequiresApi; +import android.support.annotation.UiThread; import android.text.format.DateFormat; import android.util.AttributeSet; import android.util.Log; @@ -725,11 +726,13 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture } @Override + @UiThread public void send(String channel, ByteBuffer message) { send(channel, message, null); } @Override + @UiThread public void send(String channel, ByteBuffer message, BinaryReply callback) { if (!isAttached()) { Log.d(TAG, "FlutterView.send called on a detached view, channel=" + channel); @@ -739,6 +742,7 @@ public class FlutterView extends SurfaceView implements BinaryMessenger, Texture } @Override + @UiThread public void setMessageHandler(String channel, BinaryMessageHandler handler) { mNativeView.setMessageHandler(channel, handler); }