diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 3b88cebddf5c3..23e6f736e4001 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -2216,33 +2216,25 @@ public class InputManagerService extends IInputManager.Stub } // Native callback - private void notifyConnectionUnresponsive(IBinder token, String reason) { - Integer gestureMonitorPid; - synchronized (mGestureMonitorPidsLock) { - gestureMonitorPid = mGestureMonitorPidsByToken.get(token); - } - if (gestureMonitorPid != null) { - mWindowManagerCallbacks.notifyGestureMonitorUnresponsive(gestureMonitorPid, reason); - return; - } - // If we couldn't find a gesture monitor for this token, it's a window + private void notifyWindowUnresponsive(IBinder token, String reason) { mWindowManagerCallbacks.notifyWindowUnresponsive(token, reason); } // Native callback - private void notifyConnectionResponsive(IBinder token) { - Integer gestureMonitorPid; - synchronized (mGestureMonitorPidsLock) { - gestureMonitorPid = mGestureMonitorPidsByToken.get(token); - } - if (gestureMonitorPid != null) { - mWindowManagerCallbacks.notifyGestureMonitorResponsive(gestureMonitorPid); - return; - } - // If we couldn't find a gesture monitor for this token, it's a window + private void notifyMonitorUnresponsive(int pid, String reason) { + mWindowManagerCallbacks.notifyGestureMonitorUnresponsive(pid, reason); + } + + // Native callback + private void notifyWindowResponsive(IBinder token) { mWindowManagerCallbacks.notifyWindowResponsive(token); } + // Native callback + private void notifyMonitorResponsive(int pid) { + mWindowManagerCallbacks.notifyGestureMonitorResponsive(pid); + } + // Native callback. final boolean filterInputEvent(InputEvent event, int policyFlags) { synchronized (mInputFilterLock) { diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index c3f4a25b85918..2ba2e53d9cdfd 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -98,8 +98,10 @@ static struct { jmethodID notifySwitch; jmethodID notifyInputChannelBroken; jmethodID notifyNoFocusedWindowAnr; - jmethodID notifyConnectionUnresponsive; - jmethodID notifyConnectionResponsive; + jmethodID notifyWindowUnresponsive; + jmethodID notifyWindowResponsive; + jmethodID notifyMonitorUnresponsive; + jmethodID notifyMonitorResponsive; jmethodID notifyFocusChanged; jmethodID notifyUntrustedTouch; jmethodID filterInputEvent; @@ -263,9 +265,13 @@ public: void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) override; void notifyConfigurationChanged(nsecs_t when) override; + // ANR-related callbacks -- start void notifyNoFocusedWindowAnr(const std::shared_ptr& handle) override; - void notifyConnectionUnresponsive(const sp& token, const std::string& reason) override; - void notifyConnectionResponsive(const sp& token) override; + void notifyWindowUnresponsive(const sp& token, const std::string& reason) override; + void notifyWindowResponsive(const sp& token) override; + void notifyMonitorUnresponsive(int32_t pid, const std::string& reason) override; + void notifyMonitorResponsive(int32_t pid) override; + // ANR-related callbacks -- end void notifyInputChannelBroken(const sp& token) override; void notifyFocusChanged(const sp& oldToken, const sp& newToken) override; void notifyUntrustedTouch(const std::string& obscuringPackage) override; @@ -744,10 +750,10 @@ void NativeInputManager::notifyNoFocusedWindowAnr( checkAndClearExceptionFromCallback(env, "notifyNoFocusedWindowAnr"); } -void NativeInputManager::notifyConnectionUnresponsive(const sp& token, - const std::string& reason) { +void NativeInputManager::notifyWindowUnresponsive(const sp& token, + const std::string& reason) { #if DEBUG_INPUT_DISPATCHER_POLICY - ALOGD("notifyConnectionUnresponsive"); + ALOGD("notifyWindowUnresponsive"); #endif ATRACE_CALL(); @@ -757,14 +763,14 @@ void NativeInputManager::notifyConnectionUnresponsive(const sp& token, jobject tokenObj = javaObjectForIBinder(env, token); ScopedLocalRef reasonObj(env, env->NewStringUTF(reason.c_str())); - env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConnectionUnresponsive, tokenObj, + env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyWindowUnresponsive, tokenObj, reasonObj.get()); - checkAndClearExceptionFromCallback(env, "notifyConnectionUnresponsive"); + checkAndClearExceptionFromCallback(env, "notifyWindowUnresponsive"); } -void NativeInputManager::notifyConnectionResponsive(const sp& token) { +void NativeInputManager::notifyWindowResponsive(const sp& token) { #if DEBUG_INPUT_DISPATCHER_POLICY - ALOGD("notifyConnectionResponsive"); + ALOGD("notifyWindowResponsive"); #endif ATRACE_CALL(); @@ -773,8 +779,37 @@ void NativeInputManager::notifyConnectionResponsive(const sp& token) { jobject tokenObj = javaObjectForIBinder(env, token); - env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConnectionResponsive, tokenObj); - checkAndClearExceptionFromCallback(env, "notifyConnectionResponsive"); + env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyWindowResponsive, tokenObj); + checkAndClearExceptionFromCallback(env, "notifyWindowResponsive"); +} + +void NativeInputManager::notifyMonitorUnresponsive(int32_t pid, const std::string& reason) { +#if DEBUG_INPUT_DISPATCHER_POLICY + ALOGD("notifyMonitorUnresponsive"); +#endif + ATRACE_CALL(); + + JNIEnv* env = jniEnv(); + ScopedLocalFrame localFrame(env); + + ScopedLocalRef reasonObj(env, env->NewStringUTF(reason.c_str())); + + env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyMonitorUnresponsive, pid, + reasonObj.get()); + checkAndClearExceptionFromCallback(env, "notifyMonitorUnresponsive"); +} + +void NativeInputManager::notifyMonitorResponsive(int32_t pid) { +#if DEBUG_INPUT_DISPATCHER_POLICY + ALOGD("notifyMonitorResponsive"); +#endif + ATRACE_CALL(); + + JNIEnv* env = jniEnv(); + ScopedLocalFrame localFrame(env); + + env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyMonitorResponsive, pid); + checkAndClearExceptionFromCallback(env, "notifyMonitorResponsive"); } void NativeInputManager::notifyInputChannelBroken(const sp& token) { @@ -2024,12 +2059,18 @@ int register_android_server_InputManager(JNIEnv* env) { GET_METHOD_ID(gServiceClassInfo.notifyNoFocusedWindowAnr, clazz, "notifyNoFocusedWindowAnr", "(Landroid/view/InputApplicationHandle;)V"); - GET_METHOD_ID(gServiceClassInfo.notifyConnectionUnresponsive, clazz, - "notifyConnectionUnresponsive", "(Landroid/os/IBinder;Ljava/lang/String;)V"); + GET_METHOD_ID(gServiceClassInfo.notifyWindowUnresponsive, clazz, "notifyWindowUnresponsive", + "(Landroid/os/IBinder;Ljava/lang/String;)V"); - GET_METHOD_ID(gServiceClassInfo.notifyConnectionResponsive, clazz, "notifyConnectionResponsive", + GET_METHOD_ID(gServiceClassInfo.notifyMonitorUnresponsive, clazz, "notifyMonitorUnresponsive", + "(ILjava/lang/String;)V"); + + GET_METHOD_ID(gServiceClassInfo.notifyWindowResponsive, clazz, "notifyWindowResponsive", "(Landroid/os/IBinder;)V"); + GET_METHOD_ID(gServiceClassInfo.notifyMonitorResponsive, clazz, "notifyMonitorResponsive", + "(I)V"); + GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz, "filterInputEvent", "(Landroid/view/InputEvent;I)Z");