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
diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp
index 98814bf..6fcff99 100644
--- a/core/jni/android_view_InputEventReceiver.cpp
+++ b/core/jni/android_view_InputEventReceiver.cpp
@@ -368,73 +368,77 @@
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<KeyEvent*>(inputEvent));
- break;
+ case InputEventType::KEY:
+ if (kDebugDispatchCycle) {
+ ALOGD("channel '%s' ~ Received key event.", getInputChannelName().c_str());
+ }
+ inputEventObj =
+ android_view_KeyEvent_fromNative(env,
+ static_cast<KeyEvent*>(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<const MotionEvent&>(*inputEvent);
+ if ((motionEvent.getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) {
+ *outConsumedBatch = true;
+ }
+ inputEventObj = android_view_MotionEvent_obtainAsCopy(env, motionEvent);
+ break;
}
- const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*inputEvent);
- if ((motionEvent.getAction() & AMOTION_EVENT_ACTION_MOVE) && outConsumedBatch) {
- *outConsumedBatch = true;
+ case InputEventType::FOCUS: {
+ FocusEvent* focusEvent = static_cast<FocusEvent*>(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<FocusEvent*>(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<CaptureEvent*>(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<CaptureEvent*>(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<DragEvent*>(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<DragEvent*>(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<TouchModeEvent*>(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<TouchModeEvent*>(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 2f9df1f..2c4966e 100644
--- a/core/jni/android_view_InputQueue.cpp
+++ b/core/jni/android_view_InputQueue.cpp
@@ -114,7 +114,7 @@
}
bool InputQueue::preDispatchEvent(InputEvent* e) {
- if (e->getType() == AINPUT_EVENT_TYPE_KEY) {
+ if (e->getType() == InputEventType::KEY) {
KeyEvent* keyEvent = static_cast<KeyEvent*>(e);
if (keyEvent->getFlags() & AKEY_EVENT_FLAG_PREDISPATCH) {
finishEvent(e, false);
diff --git a/native/android/input.cpp b/native/android/input.cpp
index 432e21c..1bff97d 100644
--- a/native/android/input.cpp
+++ b/native/android/input.cpp
@@ -33,6 +33,7 @@
#include <errno.h>
using android::InputEvent;
+using android::InputEventType;
using android::InputQueue;
using android::KeyEvent;
using android::Looper;
@@ -41,7 +42,8 @@
using android::Vector;
int32_t AInputEvent_getType(const AInputEvent* event) {
- return static_cast<const InputEvent*>(event)->getType();
+ const InputEventType eventType = static_cast<const InputEvent*>(event)->getType();
+ return static_cast<int32_t>(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 d64b5a1..b01d08c 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 @@
JNIEnv* env = jniEnv();
switch (inputEvent->getType()) {
- case AINPUT_EVENT_TYPE_KEY:
- inputEventObj = android_view_KeyEvent_fromNative(env,
- static_cast<const KeyEvent*>(inputEvent));
- break;
- case AINPUT_EVENT_TYPE_MOTION:
- inputEventObj =
- android_view_MotionEvent_obtainAsCopy(env,
- static_cast<const MotionEvent&>(*inputEvent));
- break;
- default:
- return true; // dispatch the event normally
+ case InputEventType::KEY:
+ inputEventObj =
+ android_view_KeyEvent_fromNative(env, static_cast<const KeyEvent*>(inputEvent));
+ break;
+ case InputEventType::MOTION:
+ inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
+ static_cast<const MotionEvent&>(
+ *inputEvent));
+ break;
+ default:
+ return true; // dispatch the event normally
}
if (!inputEventObj) {