diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 71fcd1de3b8fc..50e50bc7356bb 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -2328,33 +2328,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. private void notifySensorEvent(int deviceId, int sensorType, int accuracy, long timestamp, float[] values) { diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index d0c20501c785c..13c67523a7d63 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 notifySensorEvent; jmethodID notifySensorAccuracy; @@ -288,9 +290,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 notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType, @@ -775,10 +781,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(); @@ -788,14 +794,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(); @@ -804,8 +810,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) { @@ -2202,12 +2237,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");