Use visible window bounds to determine if a point is within a task

We need to use the visible frame on the window for any touch-related
tests. Can't use the task's bounds because the original task bounds
might be adjusted to fit the content frame. For example, the presence
of the IME adjusting the windows frames when the app window is the
IME target.

Bug: 24680002
Change-Id: Id73453788d56de879410027531ddefa46d929c67
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index f13f350..438658e 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -266,9 +266,16 @@
             final ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
             for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
                 final Task task = tasks.get(taskNdx);
-                task.getBounds(mTmpRect);
-                if (mTmpRect.contains(x, y)) {
-                    return task.mTaskId;
+                // We need to use the visible frame on the window for any touch-related tests.
+                // Can't use the task's bounds because the original task bounds might be adjusted
+                // to fit the content frame. For example, the presence of the IME adjusting the
+                // windows frames when the app window is the IME target.
+                final WindowState win = task.getTopAppMainWindow();
+                if (win != null) {
+                    win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
+                    if (mTmpRect.contains(x, y)) {
+                        return task.mTaskId;
+                    }
                 }
             }
         }
@@ -298,7 +305,7 @@
                 // might be adjusted to fit the content frame. (One example is when the
                 // task is put to top-left quadrant, the actual visible frame would not
                 // start at (0,0) after it's adjusted for the status bar.)
-                WindowState win = task.getTopAppMainWindow();
+                final WindowState win = task.getTopAppMainWindow();
                 if (win != null) {
                     win.getVisibleBounds(mTmpRect, !BOUNDS_FOR_TOUCH);
                     mTmpRect.inset(-delta, -delta);