diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java index 5b90d2a761..c0025e8927 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/KeyEventChannel.java @@ -4,8 +4,10 @@ package io.flutter.embedding.engine.systemchannels; +import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.view.InputDevice; import android.view.KeyEvent; import java.util.HashMap; @@ -55,12 +57,16 @@ public class KeyEventChannel { if (event.complexCharacter != null) { message.put("character", event.complexCharacter.toString()); } + message.put("source", event.source); + message.put("vendorId", event.vendorId); + message.put("productId", event.productId); } /** * Key event as defined by Flutter. */ public static class FlutterKeyEvent { + public final int deviceId; public final int flags; public final int plainCodePoint; public final int codePoint; @@ -69,6 +75,9 @@ public class KeyEventChannel { public final Character complexCharacter; public final int scanCode; public final int metaState; + public final int source; + public final int vendorId; + public final int productId; public FlutterKeyEvent( @NonNull KeyEvent androidKeyEvent @@ -81,25 +90,30 @@ public class KeyEventChannel { @Nullable Character complexCharacter ) { this( + androidKeyEvent.getDeviceId(), androidKeyEvent.getFlags(), androidKeyEvent.getUnicodeChar(0x0), androidKeyEvent.getUnicodeChar(), androidKeyEvent.getKeyCode(), complexCharacter, androidKeyEvent.getScanCode(), - androidKeyEvent.getMetaState() + androidKeyEvent.getMetaState(), + androidKeyEvent.getSource() ); } public FlutterKeyEvent( + int deviceId, int flags, int plainCodePoint, int codePoint, int keyCode, @Nullable Character complexCharacter, int scanCode, - int metaState + int metaState, + int source ) { + this.deviceId = deviceId; this.flags = flags; this.plainCodePoint = plainCodePoint; this.codePoint = codePoint; @@ -107,6 +121,20 @@ public class KeyEventChannel { this.complexCharacter = complexCharacter; this.scanCode = scanCode; this.metaState = metaState; + this.source = source; + InputDevice device = InputDevice.getDevice(deviceId); + if (device != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + this.vendorId = device.getVendorId(); + this.productId = device.getProductId(); + } else { + this.vendorId = 0; + this.productId = 0; + } + } else { + this.vendorId = 0; + this.productId = 0; + } } } }