From f83aa56d36425964144ae97dde046fe5440bf3c6 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Mon, 14 Dec 2020 23:19:33 +0000 Subject: [PATCH] Pass monitor pid to InputDispatcher To help identify the owner of the monitor, pass its pid to InputDispatcher. This pid will later be used to report ANRs. Bug: 175593831 Test: atest inputflinger_tests Change-Id: Ic8e6e86cc2a8592b797fa19154e5a7fe246b7231 --- .../android/server/input/InputManagerService.java | 6 +++--- ...m_android_server_input_InputManagerService.cpp | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 46ccf1e18802b..3b88cebddf5c3 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -244,7 +244,7 @@ public class InputManagerService extends IInputManager.Stub int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists); private static native InputChannel nativeCreateInputChannel(long ptr, String name); private static native InputChannel nativeCreateInputMonitor(long ptr, int displayId, - boolean isGestureMonitor, String name); + boolean isGestureMonitor, String name, int pid); private static native void nativeRemoveInputChannel(long ptr, IBinder connectionToken); private static native void nativePilferPointers(long ptr, IBinder token); private static native void nativeSetInputFilterEnabled(long ptr, boolean enable); @@ -586,7 +586,7 @@ public class InputManagerService extends IInputManager.Stub } return nativeCreateInputMonitor(mPtr, displayId, false /* isGestureMonitor */, - inputChannelName); + inputChannelName, Binder.getCallingPid()); } /** @@ -614,7 +614,7 @@ public class InputManagerService extends IInputManager.Stub final long ident = Binder.clearCallingIdentity(); try { InputChannel inputChannel = nativeCreateInputMonitor( - mPtr, displayId, true /*isGestureMonitor*/, inputChannelName); + mPtr, displayId, true /*isGestureMonitor*/, inputChannelName, pid); InputMonitorHost host = new InputMonitorHost(inputChannel.getToken()); synchronized (mGestureMonitorPidsLock) { mGestureMonitorPidsByToken.put(inputChannel.getToken(), pid); diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 404b182d968f4..c3f4a25b85918 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -224,7 +224,8 @@ public: const std::string& name); base::Result> createInputMonitor(JNIEnv* env, int32_t displayId, bool isGestureMonitor, - const std::string& name); + const std::string& name, + int32_t pid); status_t removeInputChannel(JNIEnv* env, const sp& connectionToken); status_t pilferPointers(const sp& token); @@ -456,9 +457,11 @@ base::Result> NativeInputManager::createInputChann } base::Result> NativeInputManager::createInputMonitor( - JNIEnv* /* env */, int32_t displayId, bool isGestureMonitor, const std::string& name) { + JNIEnv* /* env */, int32_t displayId, bool isGestureMonitor, const std::string& name, + int32_t pid) { ATRACE_CALL(); - return mInputManager->getDispatcher()->createInputMonitor(displayId, isGestureMonitor, name); + return mInputManager->getDispatcher()->createInputMonitor(displayId, isGestureMonitor, name, + pid); } status_t NativeInputManager::removeInputChannel(JNIEnv* /* env */, @@ -1440,7 +1443,7 @@ static jobject nativeCreateInputChannel(JNIEnv* env, jclass /* clazz */, jlong p } static jobject nativeCreateInputMonitor(JNIEnv* env, jclass /* clazz */, jlong ptr, jint displayId, - jboolean isGestureMonitor, jstring nameObj) { + jboolean isGestureMonitor, jstring nameObj, jint pid) { NativeInputManager* im = reinterpret_cast(ptr); if (displayId == ADISPLAY_ID_NONE) { @@ -1453,7 +1456,7 @@ static jobject nativeCreateInputMonitor(JNIEnv* env, jclass /* clazz */, jlong p std::string name = nameChars.c_str(); base::Result> inputChannel = - im->createInputMonitor(env, displayId, isGestureMonitor, name); + im->createInputMonitor(env, displayId, isGestureMonitor, name, pid); if (!inputChannel) { std::string message = inputChannel.error().message(); @@ -1923,7 +1926,7 @@ static const JNINativeMethod gInputManagerMethods[] = { {"nativeHasKeys", "(JII[I[Z)Z", (void*)nativeHasKeys}, {"nativeCreateInputChannel", "(JLjava/lang/String;)Landroid/view/InputChannel;", (void*)nativeCreateInputChannel}, - {"nativeCreateInputMonitor", "(JIZLjava/lang/String;)Landroid/view/InputChannel;", + {"nativeCreateInputMonitor", "(JIZLjava/lang/String;I)Landroid/view/InputChannel;", (void*)nativeCreateInputMonitor}, {"nativeRemoveInputChannel", "(JLandroid/os/IBinder;)V", (void*)nativeRemoveInputChannel}, {"nativePilferPointers", "(JLandroid/os/IBinder;)V", (void*)nativePilferPointers},