Don't block touches if same application token

Don't block touches from windows if they have the same application token
as the touch-consuming window.

That is only set for activities and could be shared by sharing the
activity's LayoutParams with another app. This is how AGSA/Launcher's
integration (-1 screen and search pill) is done (check
http://b/166617888#comment5).

This fixes the bug where touches were being blocked in the AGSA/Launcher
-1 screen animation. Note that we fixed the final state before
(b/166617888) via alpha = 0 exemption, now we are also fixing the
animated state where alpha != 0.

Also remove redundant ownerUid check since that was incorporated in
canBeObscuredBy() (ag/12714766).

Bug: 166617888
Bug: 158002302
Test: Trigger -1 screen <> launcher animation, tap the screen while
      animating and verify no touches blocked.
Test: atest WindowUntrustedTouchTest WindowInputTests inputflinger_tests
      inputflinger_benchmarks libinput_tests libgui_test
Test: CTS coming
Change-Id: I8e016917b1981d99a5550708f3ec27781e03f988
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index cdc74f3..b3558c6 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -314,6 +314,14 @@
     return first->getToken() == second->getToken();
 }
 
+static bool haveSameApplicationToken(const InputWindowInfo* first, const InputWindowInfo* second) {
+    if (first == nullptr || second == nullptr) {
+        return false;
+    }
+    return first->applicationInfo.token != nullptr &&
+            first->applicationInfo.token == second->applicationInfo.token;
+}
+
 static bool isStaleEvent(nsecs_t currentTime, const EventEntry& entry) {
     return currentTime - entry.eventTime >= STALE_EVENT_TIMEOUT;
 }
@@ -2422,8 +2430,8 @@
             break; // All future windows are below us. Exit early.
         }
         const InputWindowInfo* otherInfo = otherHandle->getInfo();
-        if (canBeObscuredBy(windowHandle, otherHandle) &&
-            windowInfo->ownerUid != otherInfo->ownerUid && otherInfo->frameContainsPoint(x, y)) {
+        if (canBeObscuredBy(windowHandle, otherHandle) && otherInfo->frameContainsPoint(x, y) &&
+            !haveSameApplicationToken(windowInfo, otherInfo)) {
             if (DEBUG_TOUCH_OCCLUSION) {
                 info.debugInfo.push_back(
                         dumpWindowForTouchOcclusion(otherInfo, /* isTouchedWindow */ false));