Support ANRs from windows that are not tracked by WM

Previously, ANRs for gesture monitors were reported using the pid of the
owner, and ANRs for all windows were reported using its input channel,
which was tracked by WM.

Now, there can be input windows that are not tracked by WM. We unify the
ANR reporting pipeline so that we first try to report an ANR using the
window's input channel. If the ANR reporting fails because the input
channel was not tracked by WM, we fall back on reporting ANR via the
pid of the window owner.

Bug: 210978621
Test: atest inputflinger_tests
Change-Id: I7f71186e042b0fc9df7d342a549ef609ff4862ae
Merged-In: I7f71186e042b0fc9df7d342a549ef609ff4862ae
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index e162c78..d3e171a 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -503,11 +503,11 @@
      */
     void processConnectionResponsiveLocked(const Connection& connection) REQUIRES(mLock);
 
-    void sendMonitorUnresponsiveCommandLocked(int32_t pid, std::string reason) REQUIRES(mLock);
-    void sendWindowUnresponsiveCommandLocked(const sp<IBinder>& connectionToken, std::string reason)
+    void sendWindowUnresponsiveCommandLocked(const sp<IBinder>& connectionToken,
+                                             std::optional<int32_t> pid, std::string reason)
             REQUIRES(mLock);
-    void sendMonitorResponsiveCommandLocked(int32_t pid) REQUIRES(mLock);
-    void sendWindowResponsiveCommandLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
+    void sendWindowResponsiveCommandLocked(const sp<IBinder>& connectionToken,
+                                           std::optional<int32_t> pid) REQUIRES(mLock);
 
     // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next.
     // AnrTracker must be kept in-sync with all responsive connection.waitQueues.