Fix NPE in PlatformViewsController.checkInputConnectionProxy (flutter/engine#20622)

This commit is contained in:
Stas Parshin
2020-08-19 23:34:04 +08:00
committed by GitHub
parent 72162b7a66
commit fa3e19be27
2 changed files with 14 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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();