Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 982aa9d7 authored by Arpit Singh's avatar Arpit Singh
Browse files

Add NDK API to obtain Java InputEvent from Native AInputEvent

This CL adds an NDK API to obtain a copy of native AInputEvent as Java
InputEvent.

Test: atest MotionEventTest KeyEventTest
Bug: 298948992

Change-Id: Ia8ce8ab2bdfc54289eb2402a1beaee68dd1030b0
parent 9798b977
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -314,6 +314,23 @@ const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) {
    return event;
}

jobject AInputEvent_toJava(JNIEnv* env, const AInputEvent* aInputEvent) {
    LOG_ALWAYS_FATAL_IF(aInputEvent == nullptr, "Expected aInputEvent to be non-null");
    const int32_t eventType = AInputEvent_getType(aInputEvent);
    switch (eventType) {
        case AINPUT_EVENT_TYPE_MOTION:
            return android::android_view_MotionEvent_obtainAsCopy(env,
                                                                  static_cast<const MotionEvent&>(
                                                                          *aInputEvent));
        case AINPUT_EVENT_TYPE_KEY:
            return android::android_view_KeyEvent_fromNative(env,
                                                             static_cast<const KeyEvent&>(
                                                                     *aInputEvent));
        default:
            LOG_ALWAYS_FATAL("Unexpected event type %d in AInputEvent_toJava.", eventType);
    }
}

void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
        int ident, ALooper_callbackFunc callback, void* data) {
    InputQueue* iq = static_cast<InputQueue*>(queue);
+1 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ LIBANDROID {
    AInputEvent_getSource;
    AInputEvent_getType;
    AInputEvent_release; # introduced=31
    AInputEvent_toJava; # introduced=35
    AInputQueue_attachLooper;
    AInputQueue_detachLooper;
    AInputQueue_finishEvent;