Check window token when extending timeout

When the "no focused window" ANR is raised, the policy responds with a
timeout. The timeout indicates whether or not to extend the ANR, and by
how much.

When we process the response from the policy, it is done in the
'commands' portion of the dispatch cycle. At that time, we already have
lost the context about the ANR.

We used to rely on the optional 'mNoFocusedWindowTimeout' being set to
determine whether this is a 'no focused window' ANR. However, there's a
better way to do this, by simply checking the inputs that were first
provided to the policy.

This way, we are free to modify 'mNoFocusedWindowTimeout' in other
portions of the code.

Other changes in this CL:

* In 'onAnrLocked', we are assuming the connection is non-null, so let's
pass it by reference. This will get us closer to the goal of using
std::unique_ptr for the connection.

* In 'InputDispatcher_test', when we had a missing ANR, we would go on
to try to derefence a null (or empty) object. This caused crashes on
hwasan build. Fix this by returning default pair when the error
condition has been detected.

Bug: 164754075
Test: atest inputflinger_tests
Change-Id: I656315eda001f1fff31cd265eadce5397606b855
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 39e57e4..4fcdcc2 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -525,7 +525,7 @@
                               int32_t displayId, std::string_view reason) REQUIRES(mLock);
     void notifyFocusChangedLocked(const sp<IBinder>& oldFocus, const sp<IBinder>& newFocus)
             REQUIRES(mLock);
-    void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
+    void onAnrLocked(const Connection& connection) REQUIRES(mLock);
     void onAnrLocked(const std::shared_ptr<InputApplicationHandle>& application) REQUIRES(mLock);
     void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason)
             REQUIRES(mLock);