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

Commit 394de119 authored by Arpit Singh's avatar Arpit Singh Committed by Android (Google) Code Review
Browse files

Merge "Add NDK API to obtain Java InputEvent from Native AInputEvent" into main

parents b47b88de 982aa9d7
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;