Merge "Add java-to-native converters for input events."
diff --git a/native/android/input.cpp b/native/android/input.cpp
index fc52138..8eeb955 100644
--- a/native/android/input.cpp
+++ b/native/android/input.cpp
@@ -26,6 +26,8 @@
 
 #include <android_runtime/android_app_NativeActivity.h>
 #include <android_runtime/android_view_InputQueue.h>
+#include <android_view_MotionEvent.h>
+#include <android_view_KeyEvent.h>
 
 #include <poll.h>
 #include <errno.h>
@@ -50,6 +52,10 @@
     return static_cast<const InputEvent*>(event)->getSource();
 }
 
+void AInputEvent_release(const AInputEvent* event) {
+    delete event;
+}
+
 int32_t AKeyEvent_getAction(const AInputEvent* key_event) {
     return static_cast<const KeyEvent*>(key_event)->getAction();
 }
@@ -77,6 +83,14 @@
     return static_cast<const KeyEvent*>(key_event)->getDownTime();
 }
 
+const AInputEvent* AKeyEvent_fromJava(JNIEnv* env, jobject keyEvent) {
+    std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>();
+    android::status_t ret = android::android_view_KeyEvent_toNative(env, keyEvent, event.get());
+    if (ret == android::OK) {
+        return event.release();
+    }
+    return nullptr;
+}
 
 int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) {
     return static_cast<const KeyEvent*>(key_event)->getEventTime();
@@ -269,6 +283,15 @@
             axis, pointer_index, history_index);
 }
 
+const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) {
+    MotionEvent* eventSrc = android::android_view_MotionEvent_getNativePtr(env, motionEvent);
+    if (eventSrc == nullptr) {
+        return nullptr;
+    }
+    MotionEvent* event = new MotionEvent();
+    event->copyFrom(eventSrc, true);
+    return event;
+}
 
 void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
         int ident, ALooper_callbackFunc callback, void* data) {
diff --git a/native/android/libandroid.map.txt b/native/android/libandroid.map.txt
index d56aa86..0414930 100644
--- a/native/android/libandroid.map.txt
+++ b/native/android/libandroid.map.txt
@@ -76,6 +76,7 @@
     AInputEvent_getDeviceId;
     AInputEvent_getSource;
     AInputEvent_getType;
+    AInputEvent_release; # introduced=31
     AInputQueue_attachLooper;
     AInputQueue_detachLooper;
     AInputQueue_finishEvent;
@@ -90,6 +91,7 @@
     AKeyEvent_getMetaState;
     AKeyEvent_getRepeatCount;
     AKeyEvent_getScanCode;
+    AKeyEvent_fromJava; # introduced=31
     ALooper_acquire;
     ALooper_addFd;
     ALooper_forThread;
@@ -139,6 +141,7 @@
     AMotionEvent_getY;
     AMotionEvent_getYOffset;
     AMotionEvent_getYPrecision;
+    AMotionEvent_fromJava; # introduced=31
     ANativeActivity_finish;
     ANativeActivity_hideSoftInput;
     ANativeActivity_setWindowFlags;