Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Remove incorrect line #54021

Merged
merged 3 commits into from
Jul 25, 2024
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 @@ -369,7 +369,6 @@ private boolean handleEventImpl(
output.physicalKey = physicalKey;
output.character = character;
output.synthesized = false;
output.deviceType = KeyData.DeviceType.kKeyboard;

sendKeyEvent(output, onKeyEventHandledCallback);
for (final Runnable postSyncEvent : postSynchronizeEvents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -88,7 +89,7 @@ enum Kind {
/**
* Construct an empty call record.
*
* <p>Use the static functions to constuct specific types instead.
* <p>Use the static functions to construct specific types instead.
*/
private CallRecord() {}

Expand Down Expand Up @@ -1921,4 +1922,88 @@ public void getKeyboardState() {
new FakeKeyEvent(ACTION_UP, SCAN_KEY_A, KEYCODE_A, 0, 'a', 0));
assertEquals(tester.keyboardManager.getKeyboardState(), Map.of());
}

@Test
public void deviceTypeFromInputDevice() {
final KeyboardTester tester = new KeyboardTester();
final ArrayList<CallRecord> calls = new ArrayList<>();

tester.recordEmbedderCallsTo(calls);
tester.respondToTextInputWith(true);

// Keyboard
final KeyEvent keyboardEvent =
new FakeKeyEvent(
ACTION_DOWN, SCAN_KEY_A, KEYCODE_A, 0, 'a', 0, InputDevice.SOURCE_KEYBOARD);
assertEquals(true, tester.keyboardManager.handleEvent(keyboardEvent));
verifyEmbedderEvents(
calls,
new KeyData[] {
buildKeyData(Type.kDown, PHYSICAL_KEY_A, LOGICAL_KEY_A, "a", false, DeviceType.kKeyboard),
});
calls.clear();

// Directional pad
final KeyEvent directionalPadEvent =
new FakeKeyEvent(
ACTION_DOWN, SCAN_ARROW_LEFT, KEYCODE_DPAD_LEFT, 0, '\0', 0, InputDevice.SOURCE_DPAD);
assertEquals(true, tester.keyboardManager.handleEvent(directionalPadEvent));
verifyEmbedderEvents(
calls,
new KeyData[] {
buildKeyData(
Type.kDown,
PHYSICAL_ARROW_LEFT,
LOGICAL_ARROW_LEFT,
null,
false,
DeviceType.kDirectionalPad),
});
calls.clear();

// Gamepad
final KeyEvent gamepadEvent =
new FakeKeyEvent(
ACTION_DOWN, SCAN_ARROW_LEFT, KEYCODE_BUTTON_A, 0, '\0', 0, InputDevice.SOURCE_GAMEPAD);
assertEquals(true, tester.keyboardManager.handleEvent(gamepadEvent));
verifyEmbedderEvents(
calls,
new KeyData[] {
buildKeyData(
Type.kUp, PHYSICAL_ARROW_LEFT, LOGICAL_ARROW_LEFT, null, true, DeviceType.kKeyboard),
buildKeyData(
Type.kDown,
PHYSICAL_ARROW_LEFT,
LOGICAL_GAME_BUTTON_A,
null,
false,
DeviceType.kGamepad),
});
calls.clear();

// HDMI
final KeyEvent hdmiEvent =
new FakeKeyEvent(
ACTION_DOWN, SCAN_ARROW_LEFT, KEYCODE_BUTTON_A, 0, '\0', 0, InputDevice.SOURCE_HDMI);
assertEquals(true, tester.keyboardManager.handleEvent(hdmiEvent));
verifyEmbedderEvents(
calls,
new KeyData[] {
buildKeyData(
Type.kUp,
PHYSICAL_ARROW_LEFT,
LOGICAL_GAME_BUTTON_A,
null,
true,
DeviceType.kKeyboard),
buildKeyData(
Type.kDown,
PHYSICAL_ARROW_LEFT,
LOGICAL_GAME_BUTTON_A,
null,
false,
DeviceType.kHdmi),
});
calls.clear();
}
}
6 changes: 6 additions & 0 deletions shell/platform/android/test/io/flutter/util/FakeKeyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public FakeKeyEvent(
this.character = character;
}

public FakeKeyEvent(
int action, int scancode, int code, int repeat, char character, int metaState, int source) {
super(0, 0, action, code, repeat, metaState, 0, scancode, 0, source);
this.character = character;
}

private char character = 0;

public final int getUnicodeChar() {
Expand Down