Bugfix: Prevent crash when responding to a platform message after FlutterJNI detaches from native (#28651). (flutter/engine#8170)

This commit is contained in:
Matt Carroll
2019-03-14 21:13:03 -07:00
committed by GitHub
parent aea91df5b4
commit 95c350dcd2

View File

@@ -10,6 +10,7 @@ import android.graphics.SurfaceTexture;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.util.Log;
import android.view.Surface;
import java.nio.ByteBuffer;
@@ -494,8 +495,11 @@ public class FlutterJNI {
@UiThread
public void invokePlatformMessageEmptyResponseCallback(int responseId) {
ensureAttachedToNative();
nativeInvokePlatformMessageEmptyResponseCallback(nativePlatformViewId, responseId);
if (isAttached()) {
nativeInvokePlatformMessageEmptyResponseCallback(nativePlatformViewId, responseId);
} else {
Log.w(TAG, "Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: " + responseId);
}
}
// Send an empty response to a platform message received from Dart.
@@ -506,13 +510,16 @@ public class FlutterJNI {
@UiThread
public void invokePlatformMessageResponseCallback(int responseId, ByteBuffer message, int position) {
ensureAttachedToNative();
nativeInvokePlatformMessageResponseCallback(
nativePlatformViewId,
responseId,
message,
position
);
if (isAttached()) {
nativeInvokePlatformMessageResponseCallback(
nativePlatformViewId,
responseId,
message,
position
);
} else {
Log.w(TAG, "Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: " + responseId);
}
}
// Send a data-carrying response to a platform message received from Dart.