From fa3e19be27276a45a4ecaf7d3c0316b03f17c061 Mon Sep 17 00:00:00 2001 From: Stas Parshin Date: Wed, 19 Aug 2020 23:34:04 +0800 Subject: [PATCH] Fix NPE in PlatformViewsController.checkInputConnectionProxy (flutter/engine#20622) --- .../flutter/plugin/platform/PlatformViewsController.java | 8 +++++++- .../plugin/platform/PlatformViewsControllerTest.java | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 2293c4971e..75d724605c 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 @@ -17,6 +17,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.UiThread; import androidx.annotation.VisibleForTesting; import io.flutter.embedding.android.AndroidTouchProcessor; @@ -531,7 +532,12 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega * if the view was created in a platform view's VD, delegates the decision to the platform view's * {@link View#checkInputConnectionProxy(View)} method. Else returns false. */ - public boolean checkInputConnectionProxy(View view) { + public boolean checkInputConnectionProxy(@Nullable View view) { + // View can be null on some devices + // See: https://github.com/flutter/flutter/issues/36517 + if (view == null) { + return false; + } if (!contextToPlatformView.containsKey(view.getContext())) { return false; } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index fec7591db7..0e585b3e50 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -519,6 +519,13 @@ public class PlatformViewsControllerTest { assertEquals(flutterView.getChildCount(), 1); } + @Test + public void checkInputConnectionProxy__falseIfViewIsNull() { + final PlatformViewsController platformViewsController = new PlatformViewsController(); + boolean shouldProxying = platformViewsController.checkInputConnectionProxy(null); + assertFalse(shouldProxying); + } + private static byte[] encodeMethodCall(MethodCall call) { final ByteBuffer buffer = StandardMethodCodec.INSTANCE.encodeMethodCall(call); buffer.rewind();