From 10acd4aac7068bbbaf2074a918307adc951fcda4 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 12 Apr 2023 11:01:15 -0700 Subject: [PATCH] Update input event type to enum class The native definitions for event type were changed to enum class. Update the usages here. Bug: 274073185 Test: m checkinput Change-Id: If80dc6fc568da2d195606b5fbece7b7b5975e061 --- core/jni/android_view_InputEventReceiver.cpp | 126 +++++++++--------- core/jni/android_view_InputQueue.cpp | 2 +- native/android/input.cpp | 4 +- ...droid_server_input_InputManagerService.cpp | 22 +-- 4 files changed, 80 insertions(+), 74 deletions(-) diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp index 98814bf602fcc..6fcff990974aa 100644 --- a/core/jni/android_view_InputEventReceiver.cpp +++ b/core/jni/android_view_InputEventReceiver.cpp @@ -368,73 +368,77 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, jobject inputEventObj; switch (inputEvent->getType()) { - case AINPUT_EVENT_TYPE_KEY: - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received key event.", getInputChannelName().c_str()); - } - inputEventObj = android_view_KeyEvent_fromNative(env, - static_cast(inputEvent)); - break; + case InputEventType::KEY: + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received key event.", getInputChannelName().c_str()); + } + inputEventObj = + android_view_KeyEvent_fromNative(env, + static_cast(inputEvent)); + break; - case AINPUT_EVENT_TYPE_MOTION: { - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received motion event.", getInputChannelName().c_str()); + case InputEventType::MOTION: { + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received motion event.", + getInputChannelName().c_str()); + } + const MotionEvent& motionEvent = static_cast(*inputEvent); + if ((motionEvent.getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) { + *outConsumedBatch = true; + } + inputEventObj = android_view_MotionEvent_obtainAsCopy(env, motionEvent); + break; } - const MotionEvent& motionEvent = static_cast(*inputEvent); - if ((motionEvent.getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) { - *outConsumedBatch = true; + case InputEventType::FOCUS: { + FocusEvent* focusEvent = static_cast(inputEvent); + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received focus event: hasFocus=%s.", + getInputChannelName().c_str(), toString(focusEvent->getHasFocus())); + } + env->CallVoidMethod(receiverObj.get(), + gInputEventReceiverClassInfo.onFocusEvent, + jboolean(focusEvent->getHasFocus())); + finishInputEvent(seq, true /* handled */); + continue; } - inputEventObj = android_view_MotionEvent_obtainAsCopy(env, motionEvent); - break; - } - case AINPUT_EVENT_TYPE_FOCUS: { - FocusEvent* focusEvent = static_cast(inputEvent); - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received focus event: hasFocus=%s.", - getInputChannelName().c_str(), toString(focusEvent->getHasFocus())); + case InputEventType::CAPTURE: { + const CaptureEvent* captureEvent = static_cast(inputEvent); + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received capture event: pointerCaptureEnabled=%s", + getInputChannelName().c_str(), + toString(captureEvent->getPointerCaptureEnabled())); + } + env->CallVoidMethod(receiverObj.get(), + gInputEventReceiverClassInfo.onPointerCaptureEvent, + jboolean(captureEvent->getPointerCaptureEnabled())); + finishInputEvent(seq, true /* handled */); + continue; } - env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.onFocusEvent, - jboolean(focusEvent->getHasFocus())); - finishInputEvent(seq, true /* handled */); - continue; - } - case AINPUT_EVENT_TYPE_CAPTURE: { - const CaptureEvent* captureEvent = static_cast(inputEvent); - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received capture event: pointerCaptureEnabled=%s", - getInputChannelName().c_str(), - toString(captureEvent->getPointerCaptureEnabled())); + case InputEventType::DRAG: { + const DragEvent* dragEvent = static_cast(inputEvent); + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received drag event: isExiting=%s", + getInputChannelName().c_str(), toString(dragEvent->isExiting())); + } + env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.onDragEvent, + jboolean(dragEvent->isExiting()), dragEvent->getX(), + dragEvent->getY()); + finishInputEvent(seq, true /* handled */); + continue; } - env->CallVoidMethod(receiverObj.get(), - gInputEventReceiverClassInfo.onPointerCaptureEvent, - jboolean(captureEvent->getPointerCaptureEnabled())); - finishInputEvent(seq, true /* handled */); - continue; - } - case AINPUT_EVENT_TYPE_DRAG: { - const DragEvent* dragEvent = static_cast(inputEvent); - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received drag event: isExiting=%s", - getInputChannelName().c_str(), toString(dragEvent->isExiting())); + case InputEventType::TOUCH_MODE: { + const TouchModeEvent* touchModeEvent = static_cast(inputEvent); + if (kDebugDispatchCycle) { + ALOGD("channel '%s' ~ Received touch mode event: isInTouchMode=%s", + getInputChannelName().c_str(), + toString(touchModeEvent->isInTouchMode())); + } + env->CallVoidMethod(receiverObj.get(), + gInputEventReceiverClassInfo.onTouchModeChanged, + jboolean(touchModeEvent->isInTouchMode())); + finishInputEvent(seq, true /* handled */); + continue; } - env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.onDragEvent, - jboolean(dragEvent->isExiting()), dragEvent->getX(), - dragEvent->getY()); - finishInputEvent(seq, true /* handled */); - continue; - } - case AINPUT_EVENT_TYPE_TOUCH_MODE: { - const TouchModeEvent* touchModeEvent = static_cast(inputEvent); - if (kDebugDispatchCycle) { - ALOGD("channel '%s' ~ Received touch mode event: isInTouchMode=%s", - getInputChannelName().c_str(), toString(touchModeEvent->isInTouchMode())); - } - env->CallVoidMethod(receiverObj.get(), - gInputEventReceiverClassInfo.onTouchModeChanged, - jboolean(touchModeEvent->isInTouchMode())); - finishInputEvent(seq, true /* handled */); - continue; - } default: assert(false); // InputConsumer should prevent this from ever happening diff --git a/core/jni/android_view_InputQueue.cpp b/core/jni/android_view_InputQueue.cpp index 2f9df1fbe9d0e..2c4966eaf408a 100644 --- a/core/jni/android_view_InputQueue.cpp +++ b/core/jni/android_view_InputQueue.cpp @@ -114,7 +114,7 @@ status_t InputQueue::getEvent(InputEvent** outEvent) { } bool InputQueue::preDispatchEvent(InputEvent* e) { - if (e->getType() == AINPUT_EVENT_TYPE_KEY) { + if (e->getType() == InputEventType::KEY) { KeyEvent* keyEvent = static_cast(e); if (keyEvent->getFlags() & AKEY_EVENT_FLAG_PREDISPATCH) { finishEvent(e, false); diff --git a/native/android/input.cpp b/native/android/input.cpp index 432e21cb5c084..1bff97dfdadaa 100644 --- a/native/android/input.cpp +++ b/native/android/input.cpp @@ -33,6 +33,7 @@ #include using android::InputEvent; +using android::InputEventType; using android::InputQueue; using android::KeyEvent; using android::Looper; @@ -41,7 +42,8 @@ using android::sp; using android::Vector; int32_t AInputEvent_getType(const AInputEvent* event) { - return static_cast(event)->getType(); + const InputEventType eventType = static_cast(event)->getType(); + return static_cast(eventType); } int32_t AInputEvent_getDeviceId(const AInputEvent* event) { diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index d64b5a17b33d9..b01d08c385316 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -1311,17 +1311,17 @@ bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t JNIEnv* env = jniEnv(); switch (inputEvent->getType()) { - case AINPUT_EVENT_TYPE_KEY: - inputEventObj = android_view_KeyEvent_fromNative(env, - static_cast(inputEvent)); - break; - case AINPUT_EVENT_TYPE_MOTION: - inputEventObj = - android_view_MotionEvent_obtainAsCopy(env, - static_cast(*inputEvent)); - break; - default: - return true; // dispatch the event normally + case InputEventType::KEY: + inputEventObj = + android_view_KeyEvent_fromNative(env, static_cast(inputEvent)); + break; + case InputEventType::MOTION: + inputEventObj = android_view_MotionEvent_obtainAsCopy(env, + static_cast( + *inputEvent)); + break; + default: + return true; // dispatch the event normally } if (!inputEventObj) {