From fb5287c0185d2327da5d8091285214d2b85d75ca Mon Sep 17 00:00:00 2001 From: Antonio Kantek Date: Tue, 27 Jul 2021 21:23:14 -0700 Subject: [PATCH] TouchEvent (2/n): Receiving touch mode events in InputEventReceiver This CL enhances InputEventReceiver to receive incoming TouchModeEvent from the transport layer. Bug: 191935212 Test: manual (build) Change-Id: I6dba5ab213f52e26c25d856a3cb8b27bfdb81d40 --- core/java/android/view/InputEventReceiver.java | 10 ++++++++++ core/jni/android_view_InputEventReceiver.cpp | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java index 25dda5b2e0bb6..2884d2279bfd2 100644 --- a/core/java/android/view/InputEventReceiver.java +++ b/core/java/android/view/InputEventReceiver.java @@ -170,6 +170,16 @@ public abstract class InputEventReceiver { public void onDragEvent(boolean isExiting, float x, float y) { } + /** + * Called when the display for the window associated with the input channel has entered or + * exited touch mode. + * + * @param isInTouchMode {@code true} if the display showing the window associated with the + * input channel entered touch mode. + */ + public void onTouchModeChanged(boolean isInTouchMode) { + } + /** * Called when a batched input event is pending. * diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp index a699f912806d0..7b79b3844a864 100644 --- a/core/jni/android_view_InputEventReceiver.cpp +++ b/core/jni/android_view_InputEventReceiver.cpp @@ -54,6 +54,7 @@ static struct { jmethodID onPointerCaptureEvent; jmethodID onDragEvent; jmethodID onBatchedInputEventPending; + jmethodID onTouchModeChanged; } gInputEventReceiverClassInfo; // Add prefix to the beginning of each line in 'str' @@ -424,6 +425,18 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, 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