From 1aaa212641edc9367f937c53b85a3a4b8d2ed153 Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Tue, 7 Apr 2020 19:38:15 -0700 Subject: Add java-to-native converters for input events. Add java-to-native converters for android.view.KeyEvent, android.view.MotionEvent. Bug: 116830907 Test: atest KeyEventTest, atest MotionEventTest Change-Id: I66a2f1dbd627c03b5dc923713be74ee9c2b73e1a --- include/android/input.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'include/android/input.h') diff --git a/include/android/input.h b/include/android/input.h index dbfd61eb05..7c392348b7 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -55,6 +55,7 @@ #include #include #include +#include #if !defined(__INTRODUCED_IN) #define __INTRODUCED_IN(__api_level) /* nothing */ @@ -931,6 +932,15 @@ int32_t AInputEvent_getDeviceId(const AInputEvent* event); /** Get the input event source. */ int32_t AInputEvent_getSource(const AInputEvent* event); +/** + * Releases interface objects created by {@link AKeyEvent_fromJava()} + * and {@link AMotionEvent_fromJava()}. + * After returning, the specified AInputEvent* object becomes invalid and should no longer be used. + * The underlying Java object remains valid and does not change its state. + */ + +void AInputEvent_release(const AInputEvent* event); + /*** Accessors for key events only. ***/ /** Get the key event action. */ @@ -977,6 +987,15 @@ int64_t AKeyEvent_getDownTime(const AInputEvent* key_event); */ int64_t AKeyEvent_getEventTime(const AInputEvent* key_event); +/** + * Creates a native AInputEvent* object associated with the specified Java android.view.KeyEvent. + * The result may be used with generic and KeyEvent-specific AInputEvent_* functions. + * The object returned by this function must be disposed using {@link AInputEvent_release()}. + * User must guarantee that lifetime for object referenced by keyEvent is prolongated + * up to release of returned AInputEvent*. + */ +const AInputEvent* AKeyEvent_fromJava(JNIEnv* env, jobject keyEvent); + /*** Accessors for motion events only. ***/ /** Get the combined motion event action code and pointer index. */ @@ -1292,6 +1311,14 @@ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, siz float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index, size_t history_index); +/** + * Creates a native AInputEvent* object associated with the specified Java android.view.MotionEvent. + * The result may be used with generic and MotionEvent-specific AInputEvent_* functions. + * The object returned by this function must be disposed using {@link AInputEvent_release()}. + * User must guarantee that object referenced by motionEvent won't be recycled and + * its lifetime is prolongated up to release of returned AInputEvent*. + */ +const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent); struct AInputQueue; /** -- cgit v1.2.3-59-g8ed1b