Ignore broken input channel when finishing input event.

There are occasional races during application shut down where the
input dispatcher will close an input channel before the application
has finished its last event.  So just ignore EPIPE.

Also tweak the logging for failed input event injection to make
it clearer which pid was trying to perform the injection.

Bug: 6013004
Change-Id: I7bbb01441d41762b03eafd4d39dcf0323e1cadf3
diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp
index ee41398..9df280d 100644
--- a/core/jni/android_view_InputEventReceiver.cpp
+++ b/core/jni/android_view_InputEventReceiver.cpp
@@ -264,7 +264,7 @@
     sp<NativeInputEventReceiver> receiver =
             reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
     status_t status = receiver->finishInputEvent(seq, handled);
-    if (status) {
+    if (status && status != DEAD_OBJECT) {
         String8 message;
         message.appendFormat("Failed to finish input event.  status=%d", status);
         jniThrowRuntimeException(env, message.string());
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 1c81bb1..80ef0e6 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -6377,7 +6377,7 @@
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
-        return reportInjectionResult(result);
+        return reportInjectionResult(result, pid);
     }
 
     /**
@@ -6407,7 +6407,7 @@
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
-        return reportInjectionResult(result);
+        return reportInjectionResult(result, pid);
     }
 
     /**
@@ -6437,7 +6437,7 @@
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
-        return reportInjectionResult(result);
+        return reportInjectionResult(result, pid);
     }
     
     /**
@@ -6458,24 +6458,23 @@
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
-        return reportInjectionResult(result);
+        return reportInjectionResult(result, pid);
     }
     
-    private boolean reportInjectionResult(int result) {
+    private boolean reportInjectionResult(int result, int pid) {
         switch (result) {
             case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
-                Slog.w(TAG, "Input event injection permission denied.");
+                Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
                 throw new SecurityException(
                         "Injecting to another application requires INJECT_EVENTS permission");
             case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
-                //Slog.v(TAG, "Input event injection succeeded.");
                 return true;
             case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
-                Slog.w(TAG, "Input event injection timed out.");
+                Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
                 return false;
             case InputManager.INPUT_EVENT_INJECTION_FAILED:
             default:
-                Slog.w(TAG, "Input event injection failed.");
+                Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
                 return false;
         }
     }