From c802d6ce22168486e2ca8163acc027023253b8bc Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Thu, 21 Mar 2019 13:45:13 -0700 Subject: [PATCH] FlutterJNI no longer asserts it is attached when dispatching platform messages and instead fizzles with a warning if not attached. Not sure what root cause of issue is, but this is necessary to avoid crashes. (flutter/engine#8246) --- .../flutter/embedding/engine/FlutterJNI.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 925e2a8d72..66e98087c4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -461,8 +461,11 @@ public class FlutterJNI { @UiThread public void dispatchEmptyPlatformMessage(String channel, int responseId) { - ensureAttachedToNative(); - nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId); + if (isAttached()) { + nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId); + } else { + Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId); + } } // Send an empty platform message to Dart. @@ -474,14 +477,17 @@ public class FlutterJNI { @UiThread public void dispatchPlatformMessage(String channel, ByteBuffer message, int position, int responseId) { - ensureAttachedToNative(); - nativeDispatchPlatformMessage( - nativePlatformViewId, - channel, - message, - position, - responseId - ); + if (isAttached()) { + nativeDispatchPlatformMessage( + nativePlatformViewId, + channel, + message, + position, + responseId + ); + } else { + Log.w(TAG, "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: " + channel + ". Response ID: " + responseId); + } } // Send a data-carrying platform message to Dart.