Give access to the native InputQueue to all native applications.

Bug: 116830907
Test: atest android.view.cts.InputQueueTest#testNativeInputQueue
Change-Id: Ia7741ac4922afeeca334266caef3331b521f87e4
This commit is contained in:
Jim Blackler
2021-09-01 16:24:23 +01:00
parent e461cc6e67
commit 86df7e4214
4 changed files with 15 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ namespace android {
static struct {
jmethodID finishInputEvent;
jmethodID getNativePtr;
} gInputQueueClassInfo;
enum {
@@ -263,8 +264,15 @@ int register_android_view_InputQueue(JNIEnv* env)
jclass clazz = FindClassOrDie(env, kInputQueuePathName);
gInputQueueClassInfo.finishInputEvent = GetMethodIDOrDie(env, clazz, "finishInputEvent",
"(JZ)V");
gInputQueueClassInfo.getNativePtr = GetMethodIDOrDie(env, clazz, "getNativePtr", "()J");
return RegisterMethodsOrDie(env, kInputQueuePathName, g_methods, NELEM(g_methods));
}
AInputQueue* android_view_InputQueue_getNativePtr(jobject inputQueue) {
JNIEnv* env = AndroidRuntime::getJNIEnv();
jlong ptr = env->CallLongMethod(inputQueue, gInputQueueClassInfo.getNativePtr);
return reinterpret_cast<AInputQueue*>(ptr);
}
} // namespace android

View File

@@ -80,6 +80,8 @@ private:
Vector<key_value_pair_t<InputEvent*, bool> > mFinishedEvents;
};
extern AInputQueue* android_view_InputQueue_getNativePtr(jobject inputQueue);
} // namespace android
#endif

View File

@@ -329,3 +329,7 @@ void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled
InputEvent* e = static_cast<InputEvent*>(event);
iq->finishEvent(e, handled != 0);
}
AInputQueue* AInputQueue_fromJava(jobject inputQueue) {
return android::android_view_InputQueue_getNativePtr(inputQueue);
}

View File

@@ -91,6 +91,7 @@ LIBANDROID {
AInputQueue_attachLooper;
AInputQueue_detachLooper;
AInputQueue_finishEvent;
AInputQueue_fromJava; # introduced=Tiramisu
AInputQueue_getEvent;
AInputQueue_hasEvents;
AInputQueue_preDispatchEvent;