Pass JNIEnv explicitly into AInputQueue_fromJava
Instead of assuming a JNIEnv*, the method should have the env passed
into it, which is the standard practice for native APIs.
Bug: 210727635
Test: atest InputQueueTest
Change-Id: Iae5fc5bd39c758c530185694751d6d79715ce31b
diff --git a/core/jni/android_view_InputQueue.cpp b/core/jni/android_view_InputQueue.cpp
index b910d16..74bbd7b 100644
--- a/core/jni/android_view_InputQueue.cpp
+++ b/core/jni/android_view_InputQueue.cpp
@@ -269,8 +269,7 @@
return RegisterMethodsOrDie(env, kInputQueuePathName, g_methods, NELEM(g_methods));
}
-AInputQueue* android_view_InputQueue_getNativePtr(jobject inputQueue) {
- JNIEnv* env = AndroidRuntime::getJNIEnv();
+AInputQueue* android_view_InputQueue_getNativePtr(JNIEnv* env, jobject inputQueue) {
jlong ptr = env->CallLongMethod(inputQueue, gInputQueueClassInfo.getNativePtr);
return reinterpret_cast<AInputQueue*>(ptr);
}
diff --git a/core/jni/include/android_runtime/android_view_InputQueue.h b/core/jni/include/android_runtime/android_view_InputQueue.h
index c1b611c..115e2f8 100644
--- a/core/jni/include/android_runtime/android_view_InputQueue.h
+++ b/core/jni/include/android_runtime/android_view_InputQueue.h
@@ -80,7 +80,7 @@
Vector<key_value_pair_t<InputEvent*, bool> > mFinishedEvents;
};
-extern AInputQueue* android_view_InputQueue_getNativePtr(jobject inputQueue);
+extern AInputQueue* android_view_InputQueue_getNativePtr(JNIEnv* env, jobject inputQueue);
} // namespace android
diff --git a/native/android/input.cpp b/native/android/input.cpp
index 4de2c23..c06c81e 100644
--- a/native/android/input.cpp
+++ b/native/android/input.cpp
@@ -330,6 +330,6 @@
iq->finishEvent(e, handled != 0);
}
-AInputQueue* AInputQueue_fromJava(jobject inputQueue) {
- return android::android_view_InputQueue_getNativePtr(inputQueue);
+AInputQueue* AInputQueue_fromJava(JNIEnv* env, jobject inputQueue) {
+ return android::android_view_InputQueue_getNativePtr(env, inputQueue);
}