Support touch event on letterbox surface

This is part of "Compatible behavior for non-resizable activity".
It allows window to receive motion event when sliding from a letterbox
surface. That makes it easier for users to slide out the side menu of
a letterboxed activity.

Note this only works when the touchable region of the activity doesn't
cover letterbox surface (lower layer than activity).

Bug: 112288258
Test: manual - Start an activity with fixed aspect ratio and make sure
      it touchable region matches its content size, and then slide from
      letterbox region into the activity, it should receive touch event.
Change-Id: Ibff9103adbdad0ae5dd93c4a44b00f41d06c1007
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index bcf6aba..9a8943c 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -884,6 +884,10 @@
             dc.setFocusedApp(null);
             mWmService.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
         }
+        if (mLetterbox != null) {
+            mLetterbox.destroy();
+            mLetterbox = null;
+        }
 
         if (!delayed) {
             updateReportedVisibilityLocked();
@@ -1297,6 +1301,10 @@
                 }
             }
         }
+
+        if (prevDc != mDisplayContent && mLetterbox != null) {
+            mLetterbox.onMovedToDisplay(mDisplayContent.getDisplayId());
+        }
     }
 
     /**
@@ -1844,6 +1852,7 @@
         if (needsLetterbox) {
             if (mLetterbox == null) {
                 mLetterbox = new Letterbox(() -> makeChildSurface(null));
+                mLetterbox.attachInput(w);
             }
             getPosition(mTmpPoint);
             mLetterbox.layout(getParent().getBounds(), w.getFrameLw(), mTmpPoint);