From 7c48ce83bc63c3283c07b62a5edc6ea9ffd3b49a Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Tue, 10 Nov 2020 17:26:05 -0800 Subject: [PATCH] SyncPointerCapture (4/n): Receive capture events in InputEventReceiver Since a capture event was added to the InputChannel, this CL lets InputEventReceiver receive the capture events sent by the publisher. Bug: 141749603 Test: build, crosshatch boots Change-Id: I608f3cf86d96e4d2b00b28f88fa2b7aa6e83b6dc --- core/java/android/view/InputEventReceiver.java | 14 ++++++++++++++ core/jni/android_view_InputEventReceiver.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java index 038dff654ba6f..7d1adc36964bb 100644 --- a/core/java/android/view/InputEventReceiver.java +++ b/core/java/android/view/InputEventReceiver.java @@ -143,6 +143,20 @@ public abstract class InputEventReceiver { public void onFocusEvent(boolean hasFocus, boolean inTouchMode) { } + /** + * Called when a Pointer Capture event is received. + * + * @param pointerCaptureEnabled if true, the window associated with this input channel has just + * received Pointer Capture + * if false, the window associated with this input channel has just + * lost Pointer Capture + * @see View#requestPointerCapture() + * @see View#releasePointerCapture() + */ + // Called from native code. + public void onPointerCaptureEvent(boolean pointerCaptureEnabled) { + } + /** * 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 1ea918a900ad6..1c78750f36102 100644 --- a/core/jni/android_view_InputEventReceiver.cpp +++ b/core/jni/android_view_InputEventReceiver.cpp @@ -50,6 +50,7 @@ static struct { jmethodID dispatchInputEvent; jmethodID onFocusEvent; + jmethodID onPointerCaptureEvent; jmethodID onBatchedInputEventPending; } gInputEventReceiverClassInfo; @@ -345,6 +346,19 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, 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())); + } + env->CallVoidMethod(receiverObj.get(), + gInputEventReceiverClassInfo.onPointerCaptureEvent, + jboolean(captureEvent->getPointerCaptureEnabled())); + finishInputEvent(seq, true /* handled */); + continue; + } default: assert(false); // InputConsumer should prevent this from ever happening @@ -489,6 +503,9 @@ int register_android_view_InputEventReceiver(JNIEnv* env) { "dispatchInputEvent", "(ILandroid/view/InputEvent;)V"); gInputEventReceiverClassInfo.onFocusEvent = GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onFocusEvent", "(ZZ)V"); + gInputEventReceiverClassInfo.onPointerCaptureEvent = + GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onPointerCaptureEvent", + "(Z)V"); gInputEventReceiverClassInfo.onBatchedInputEventPending = GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onBatchedInputEventPending", "(I)V");