diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 183aeecc56e35..5000803f207e8 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -2382,7 +2382,6 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/rend ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/renderer/SurfaceTextureWrapper.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/DeferredComponentChannel.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyboardChannel.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LifecycleChannel.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/MouseCursorChannel.java + ../../../flutter/LICENSE @@ -2416,7 +2415,6 @@ ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/Listen ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/TextEditingDelta.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/keyboard/KeyboardPlugin.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/localization/LocalizationPlugin.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/mouse/MouseCursorPlugin.java + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/AccessibilityEventsDelegate.java + ../../../flutter/LICENSE @@ -5065,7 +5063,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/render FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/DeferredComponentChannel.java FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java -FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyboardChannel.java FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LifecycleChannel.java FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java FILE: ../../../flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/MouseCursorChannel.java @@ -5102,7 +5099,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/Listenab FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/SpellCheckPlugin.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/TextEditingDelta.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java -FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/keyboard/KeyboardPlugin.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/localization/LocalizationPlugin.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/mouse/MouseCursorPlugin.java FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/AccessibilityEventsDelegate.java diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 3770f182e38dc..0f3ff3ebb5b9a 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -250,7 +250,6 @@ android_java_sources = [ "io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java", "io/flutter/embedding/engine/systemchannels/DeferredComponentChannel.java", "io/flutter/embedding/engine/systemchannels/KeyEventChannel.java", - "io/flutter/embedding/engine/systemchannels/KeyboardChannel.java", "io/flutter/embedding/engine/systemchannels/LifecycleChannel.java", "io/flutter/embedding/engine/systemchannels/LocalizationChannel.java", "io/flutter/embedding/engine/systemchannels/MouseCursorChannel.java", @@ -287,7 +286,6 @@ android_java_sources = [ "io/flutter/plugin/editing/SpellCheckPlugin.java", "io/flutter/plugin/editing/TextEditingDelta.java", "io/flutter/plugin/editing/TextInputPlugin.java", - "io/flutter/plugin/keyboard/KeyboardPlugin.java", "io/flutter/plugin/localization/LocalizationPlugin.java", "io/flutter/plugin/mouse/MouseCursorPlugin.java", "io/flutter/plugin/platform/AccessibilityEventsDelegate.java", diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 09f4586648d78..45fae9f96456c 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -62,7 +62,6 @@ import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.editing.SpellCheckPlugin; import io.flutter.plugin.editing.TextInputPlugin; -import io.flutter.plugin.keyboard.KeyboardPlugin; import io.flutter.plugin.localization.LocalizationPlugin; import io.flutter.plugin.mouse.MouseCursorPlugin; import io.flutter.plugin.platform.PlatformViewsController; @@ -131,7 +130,6 @@ public class FlutterView extends FrameLayout @Nullable private MouseCursorPlugin mouseCursorPlugin; @Nullable private TextInputPlugin textInputPlugin; @Nullable private SpellCheckPlugin spellCheckPlugin; - @Nullable private KeyboardPlugin keyboardPlugin; @Nullable private LocalizationPlugin localizationPlugin; @Nullable private KeyboardManager keyboardManager; @Nullable private AndroidTouchProcessor androidTouchProcessor; @@ -1179,8 +1177,6 @@ public void attachToFlutterEngine(@NonNull FlutterEngine flutterEngine) { localizationPlugin = this.flutterEngine.getLocalizationPlugin(); keyboardManager = new KeyboardManager(this); - keyboardPlugin = new KeyboardPlugin(keyboardManager, this.flutterEngine.getKeyboardChannel()); - androidTouchProcessor = new AndroidTouchProcessor(this.flutterEngine.getRenderer(), /*trackMotionEvents=*/ false); accessibilityBridge = @@ -1277,12 +1273,10 @@ public void detachFromFlutterEngine() { if (spellCheckPlugin != null) { spellCheckPlugin.destroy(); } + if (mouseCursorPlugin != null) { mouseCursorPlugin.destroy(); } - if (keyboardPlugin != null) { - keyboardPlugin.destroy(); - } // Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface. FlutterRenderer flutterRenderer = flutterEngine.getRenderer(); diff --git a/shell/platform/android/io/flutter/embedding/android/KeyEmbedderResponder.java b/shell/platform/android/io/flutter/embedding/android/KeyEmbedderResponder.java index aa1fdec32d514..2a5d5b1a87400 100644 --- a/shell/platform/android/io/flutter/embedding/android/KeyEmbedderResponder.java +++ b/shell/platform/android/io/flutter/embedding/android/KeyEmbedderResponder.java @@ -11,9 +11,7 @@ import io.flutter.embedding.android.KeyboardMap.TogglingGoal; import io.flutter.plugin.common.BinaryMessenger; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Map; /** * A {@link KeyboardManager.Responder} of {@link KeyboardManager} that handles events by sending @@ -407,14 +405,4 @@ public void handleEvent( onKeyEventHandledCallback.onKeyEventHandled(true); } } - - /** - * Returns an unmodifiable view of the pressed state. - * - * @return A map whose keys are physical keyboard key IDs and values are the corresponding logical - * keyboard key IDs. - */ - public Map getPressedState() { - return Collections.unmodifiableMap(pressingRecords); - } } diff --git a/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java b/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java index 84cee4549c439..76e344a4e5d26 100644 --- a/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java +++ b/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java @@ -13,7 +13,6 @@ import io.flutter.plugin.editing.InputConnectionAdaptor; import io.flutter.plugin.editing.TextInputPlugin; import java.util.HashSet; -import java.util.Map; /** * Processes keyboard events and cooperate with {@link TextInputPlugin}. @@ -253,15 +252,4 @@ private void onUnhandled(@NonNull KeyEvent keyEvent) { Log.w(TAG, "A redispatched key event was consumed before reaching KeyboardManager"); } } - - /** - * Returns an unmodifiable view of the pressed state. - * - * @return A map whose keys are physical keyboard key IDs and values are the corresponding logical - * keyboard key IDs. - */ - public Map getPressedState() { - KeyEmbedderResponder embedderResponder = (KeyEmbedderResponder) responders[0]; - return embedderResponder.getPressedState(); - } } diff --git a/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java b/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java index 95f34bfeab145..a3a463be04553 100644 --- a/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java +++ b/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java @@ -26,7 +26,6 @@ import io.flutter.embedding.engine.renderer.RenderSurface; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; import io.flutter.embedding.engine.systemchannels.DeferredComponentChannel; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; import io.flutter.embedding.engine.systemchannels.LifecycleChannel; import io.flutter.embedding.engine.systemchannels.LocalizationChannel; import io.flutter.embedding.engine.systemchannels.MouseCursorChannel; @@ -90,7 +89,6 @@ public class FlutterEngine implements ViewUtils.DisplayUpdater { // System channels. @NonNull private final AccessibilityChannel accessibilityChannel; @NonNull private final DeferredComponentChannel deferredComponentChannel; - @NonNull private final KeyboardChannel keyboardChannel; @NonNull private final LifecycleChannel lifecycleChannel; @NonNull private final LocalizationChannel localizationChannel; @NonNull private final MouseCursorChannel mouseCursorChannel; @@ -326,7 +324,6 @@ public FlutterEngine( accessibilityChannel = new AccessibilityChannel(dartExecutor, flutterJNI); deferredComponentChannel = new DeferredComponentChannel(dartExecutor); - keyboardChannel = new KeyboardChannel(dartExecutor); lifecycleChannel = new LifecycleChannel(dartExecutor); localizationChannel = new LocalizationChannel(dartExecutor); mouseCursorChannel = new MouseCursorChannel(dartExecutor); @@ -519,12 +516,6 @@ public AccessibilityChannel getAccessibilityChannel() { return accessibilityChannel; } - /** System channel that allows querying the keyboard pressed state. */ - @NonNull - public KeyboardChannel getKeyboardChannel() { - return keyboardChannel; - } - /** System channel that sends Android lifecycle events to Flutter. */ @NonNull public LifecycleChannel getLifecycleChannel() { diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyboardChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyboardChannel.java deleted file mode 100644 index 956f6e0baa203..0000000000000 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyboardChannel.java +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.embedding.engine.systemchannels; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import io.flutter.embedding.engine.dart.DartExecutor; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.StandardMethodCodec; -import java.util.HashMap; -import java.util.Map; - -/** - * Event message channel for keyboard events to/from the Flutter framework. - * - *

Receives asynchronous messages from the framework to query the engine known pressed state. - */ -public class KeyboardChannel { - private static final String TAG = "KeyboardChannel"; - - public final MethodChannel channel; - private KeyboardMethodHandler keyboardMethodHandler; - - @NonNull - public final MethodChannel.MethodCallHandler parsingMethodHandler = - new MethodChannel.MethodCallHandler() { - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { - if (keyboardMethodHandler == null) { - return; - } - switch (call.method) { - case "getKeyboardState": - Map pressedState = new HashMap<>(); - try { - pressedState = keyboardMethodHandler.getKeyboardState(); - } catch (IllegalStateException exception) { - result.error("error", exception.getMessage(), null); - } - result.success(pressedState); - break; - default: - result.notImplemented(); - break; - } - } - }; - - public KeyboardChannel(@NonNull DartExecutor dartExecutor) { - channel = new MethodChannel(dartExecutor, "flutter/keyboard", StandardMethodCodec.INSTANCE); - channel.setMethodCallHandler(parsingMethodHandler); - } - - /** - * Sets the {@link KeyboardMethodHandler} which receives all requests to query the keyboard state. - */ - public void setKeyboardMethodHandler(@Nullable KeyboardMethodHandler keyboardMethodHandler) { - this.keyboardMethodHandler = keyboardMethodHandler; - } - - public interface KeyboardMethodHandler { - /** - * Returns the keyboard pressed states. - * - * @return A map whose keys are physical keyboard key IDs and values are the corresponding - * logical keyboard key IDs. - */ - Map getKeyboardState(); - } -} diff --git a/shell/platform/android/io/flutter/plugin/keyboard/KeyboardPlugin.java b/shell/platform/android/io/flutter/plugin/keyboard/KeyboardPlugin.java deleted file mode 100644 index b2d8c25ec43c8..0000000000000 --- a/shell/platform/android/io/flutter/plugin/keyboard/KeyboardPlugin.java +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugin.keyboard; - -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.embedding.android.KeyboardManager; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; -import io.flutter.plugin.common.MethodChannel; -import java.util.Map; - -/** - * {@link KeyboardPlugin} is the implementation of all functionalities needed for querying keyboard - * pressed state. - * - *

The plugin handles requests for querying keyboard pressed states by the {@link - * io.flutter.embedding.engine.systemchannels.KeyboardChannel} via returning the {@link - * io.flutter.embedding.android.KeyEmbedderResponder} pressed keys. - */ -public class KeyboardPlugin implements KeyboardChannel.KeyboardMethodHandler { - - private final KeyboardChannel mKeyboardChannel; - private final KeyboardManager mKeyboardManager; - - @VisibleForTesting MethodChannel.Result pendingResult; - - public KeyboardPlugin( - @NonNull KeyboardManager keyboardManager, @NonNull KeyboardChannel keyboardChannel) { - mKeyboardManager = keyboardManager; - mKeyboardChannel = keyboardChannel; - - mKeyboardChannel.setKeyboardMethodHandler(this); - } - - /** - * Unregisters this {@code KeyboardPlugin} as the {@code KeyboardChannel.KeyboardMethodHandler}, - * for the {@link io.flutter.embedding.engine.systemchannels.KeyboardChannel}. - * - *

Do not invoke any methods on a {@code KeyboardPlugin} after invoking this method. - */ - public void destroy() { - mKeyboardChannel.setKeyboardMethodHandler(null); - } - - /** - * Returns the keyboard pressed state. - * - * @return A map whose keys are physical keyboard key IDs and values are the corresponding logical - * keyboard key IDs. - */ - @Override - public Map getKeyboardState() { - return mKeyboardManager.getPressedState(); - } -} diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 4f20e75250c64..eb498a2335e96 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -48,7 +48,6 @@ import io.flutter.embedding.engine.renderer.FlutterRenderer; import io.flutter.embedding.engine.renderer.SurfaceTextureWrapper; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; import io.flutter.embedding.engine.systemchannels.LifecycleChannel; import io.flutter.embedding.engine.systemchannels.LocalizationChannel; import io.flutter.embedding.engine.systemchannels.MouseCursorChannel; @@ -60,7 +59,6 @@ import io.flutter.plugin.common.ActivityLifecycleListener; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.editing.TextInputPlugin; -import io.flutter.plugin.keyboard.KeyboardPlugin; import io.flutter.plugin.localization.LocalizationPlugin; import io.flutter.plugin.mouse.MouseCursorPlugin; import io.flutter.plugin.platform.PlatformPlugin; @@ -126,14 +124,12 @@ static final class ViewportMetrics { private final FlutterRenderer flutterRenderer; private final NavigationChannel navigationChannel; private final LifecycleChannel lifecycleChannel; - private final KeyboardChannel keyboardChannel; private final LocalizationChannel localizationChannel; private final PlatformChannel platformChannel; private final SettingsChannel settingsChannel; private final SystemChannel systemChannel; private final InputMethodManager mImm; private final TextInputPlugin mTextInputPlugin; - private final KeyboardPlugin mKeyboardPlugin; private final LocalizationPlugin mLocalizationPlugin; private final MouseCursorPlugin mMouseCursorPlugin; private final KeyboardManager mKeyboardManager; @@ -217,7 +213,6 @@ public void surfaceDestroyed(SurfaceHolder holder) { // Create all platform channels navigationChannel = new NavigationChannel(dartExecutor); - keyboardChannel = new KeyboardChannel(dartExecutor); lifecycleChannel = new LifecycleChannel(dartExecutor); localizationChannel = new LocalizationChannel(dartExecutor); platformChannel = new PlatformChannel(dartExecutor); @@ -238,9 +233,7 @@ public void onPostResume() { mNativeView.getPluginRegistry().getPlatformViewsController(); mTextInputPlugin = new TextInputPlugin(this, new TextInputChannel(dartExecutor), platformViewsController); - mKeyboardManager = new KeyboardManager(this); - mKeyboardPlugin = new KeyboardPlugin(mKeyboardManager, keyboardChannel); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { mMouseCursorPlugin = new MouseCursorPlugin(this, new MouseCursorChannel(dartExecutor)); diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 91669d276f254..8930a92f3eaf8 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -39,7 +39,6 @@ import io.flutter.embedding.engine.renderer.FlutterRenderer; import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; import io.flutter.embedding.engine.systemchannels.LifecycleChannel; import io.flutter.embedding.engine.systemchannels.LocalizationChannel; import io.flutter.embedding.engine.systemchannels.MouseCursorChannel; @@ -1294,7 +1293,6 @@ private FlutterEngine mockFlutterEngine() { when(engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class)); when(engine.getActivityControlSurface()).thenReturn(mock(ActivityControlSurface.class)); when(engine.getDartExecutor()).thenReturn(mock(DartExecutor.class)); - when(engine.getKeyboardChannel()).thenReturn(mock(KeyboardChannel.class)); when(engine.getLifecycleChannel()).thenReturn(mock(LifecycleChannel.class)); when(engine.getLocalizationChannel()).thenReturn(mock(LocalizationChannel.class)); when(engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class)); diff --git a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java index 6fddf593202d6..799ae861b2352 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/KeyboardManagerTest.java @@ -25,7 +25,6 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -1565,22 +1564,4 @@ public void synchronizeCapsLock() { calls.get(0).keyData, Type.kUp, PHYSICAL_CAPS_LOCK, LOGICAL_CAPS_LOCK, null, false); calls.clear(); } - - @Test - public void getPressedState() { - final KeyboardTester tester = new KeyboardTester(); - - tester.respondToTextInputWith(true); // Suppress redispatching. - - // Initial pressed state is empty. - assertEquals(tester.keyboardManager.getPressedState(), Map.of()); - - tester.keyboardManager.handleEvent( - new FakeKeyEvent(ACTION_DOWN, SCAN_KEY_A, KEYCODE_A, 1, 'a', 0)); - assertEquals(tester.keyboardManager.getPressedState(), Map.of(PHYSICAL_KEY_A, LOGICAL_KEY_A)); - - tester.keyboardManager.handleEvent( - new FakeKeyEvent(ACTION_UP, SCAN_KEY_A, KEYCODE_A, 0, 'a', 0)); - assertEquals(tester.keyboardManager.getPressedState(), Map.of()); - } } diff --git a/shell/platform/android/test/io/flutter/plugin/keyboard/KeyboardPluginTest.java b/shell/platform/android/test/io/flutter/plugin/keyboard/KeyboardPluginTest.java deleted file mode 100644 index 0e3ecb1385d9d..0000000000000 --- a/shell/platform/android/test/io/flutter/plugin/keyboard/KeyboardPluginTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.flutter.plugin.keyboard; - -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import io.flutter.embedding.engine.dart.DartExecutor; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.StandardMethodCodec; -import java.nio.ByteBuffer; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; - -@RunWith(AndroidJUnit4.class) -public class KeyboardPluginTest { - - private static void sendToBinaryMessageHandler( - BinaryMessenger.BinaryMessageHandler binaryMessageHandler, String method, Object args) { - MethodCall methodCall = new MethodCall(method, args); - ByteBuffer encodedMethodCall = StandardMethodCodec.INSTANCE.encodeMethodCall(methodCall); - binaryMessageHandler.onMessage( - (ByteBuffer) encodedMethodCall.flip(), mock(BinaryMessenger.BinaryReply.class)); - } - - @Test - public void respondsToGetKeyboardStateChannelMessage() { - ArgumentCaptor binaryMessageHandlerCaptor = - ArgumentCaptor.forClass(BinaryMessenger.BinaryMessageHandler.class); - DartExecutor mockBinaryMessenger = mock(DartExecutor.class); - KeyboardChannel.KeyboardMethodHandler mockHandler = - mock(KeyboardChannel.KeyboardMethodHandler.class); - KeyboardChannel keyboardChannel = new KeyboardChannel(mockBinaryMessenger); - - keyboardChannel.setKeyboardMethodHandler(mockHandler); - - verify(mockBinaryMessenger, times(1)) - .setMessageHandler(any(String.class), binaryMessageHandlerCaptor.capture()); - - BinaryMessenger.BinaryMessageHandler binaryMessageHandler = - binaryMessageHandlerCaptor.getValue(); - - sendToBinaryMessageHandler(binaryMessageHandler, "getKeyboardState", null); - - verify(mockHandler, times(1)).getKeyboardState(); - } -} diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index 8f934dc1437e1..77cdbe1299585 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -36,7 +36,6 @@ import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack; import io.flutter.embedding.engine.renderer.FlutterRenderer; import io.flutter.embedding.engine.systemchannels.AccessibilityChannel; -import io.flutter.embedding.engine.systemchannels.KeyboardChannel; import io.flutter.embedding.engine.systemchannels.MouseCursorChannel; import io.flutter.embedding.engine.systemchannels.PlatformViewsChannel; import io.flutter.embedding.engine.systemchannels.SettingsChannel; @@ -1496,7 +1495,6 @@ public void release() {} final FlutterEngine engine = mock(FlutterEngine.class); when(engine.getRenderer()).thenReturn(new FlutterRenderer(jni)); - when(engine.getKeyboardChannel()).thenReturn(mock(KeyboardChannel.class)); when(engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class)); when(engine.getTextInputChannel()).thenReturn(mock(TextInputChannel.class)); when(engine.getSettingsChannel()).thenReturn(new SettingsChannel(executor));