Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public AndroidKeyProcessor(
this.keyEventChannel.setEventResponseHandler(eventResponder);
}

/**
* Detaches the key processor from the Flutter engine.
*
* <p>The AndroidKeyProcessor instance should not be used after calling this.
*/
public void destroy() {
keyEventChannel.setEventResponseHandler(null);
}

/**
* Called when a key up event is received by the {@link FlutterView}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ public void detachFromFlutterEngine() {
textInputPlugin.getInputMethodManager().restartInput(this);
textInputPlugin.destroy();

androidKeyProcessor.destroy();

if (mouseCursorPlugin != null) {
mouseCursorPlugin.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static junit.framework.TestCase.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.notNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -56,6 +58,22 @@ public void respondsTrueWhenHandlingNewEvents() {
verify(fakeView, times(0)).dispatchKeyEvent(any(KeyEvent.class));
}

@Test
public void destroyTest() {
FlutterEngine flutterEngine = mockFlutterEngine();
KeyEventChannel fakeKeyEventChannel = flutterEngine.getKeyEventChannel();
View fakeView = mock(View.class);

AndroidKeyProcessor processor =
new AndroidKeyProcessor(fakeView, fakeKeyEventChannel, mock(TextInputPlugin.class));

verify(fakeKeyEventChannel, times(1))
.setEventResponseHandler(notNull(KeyEventChannel.EventResponseHandler.class));
processor.destroy();
verify(fakeKeyEventChannel, times(1))
.setEventResponseHandler(isNull(KeyEventChannel.EventResponseHandler.class));
}

public void synthesizesEventsWhenKeyDownNotHandled() {
FlutterEngine flutterEngine = mockFlutterEngine();
KeyEventChannel fakeKeyEventChannel = flutterEngine.getKeyEventChannel();
Expand Down