diff --git a/data/etc/core.protolog.pb b/data/etc/core.protolog.pb
index ddb706e93ffc8acd281ca1700c75e066e117acaf..a105ba756d51dc93a1f30f9f1c759a0a003d2a1e 100644
Binary files a/data/etc/core.protolog.pb and b/data/etc/core.protolog.pb differ
diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json
index 80f143c63333e6d2748a261d5fde1f1f5713c950..db68f952815120d73df3ddfe8c9b056e763315f3 100644
--- a/data/etc/services.core.protolog.json
+++ b/data/etc/services.core.protolog.json
@@ -2035,6 +2035,24 @@
       "group": "WM_DEBUG_WINDOW_TRANSITIONS",
       "at": "com\/android\/server\/wm\/PhysicalDisplaySwitchTransitionLauncher.java"
     },
+    "-1640401313436844534": {
+      "message": "Resetting frozen recents task list reason=app touch win=%s x=%d y=%d insetFrame=%s",
+      "level": "INFO",
+      "group": "WM_DEBUG_TASKS",
+      "at": "com\/android\/server\/wm\/RecentTasks.java"
+    },
+    "-8803811426486764449": {
+      "message": "Setting frozen recents task list",
+      "level": "INFO",
+      "group": "WM_DEBUG_TASKS",
+      "at": "com\/android\/server\/wm\/RecentTasks.java"
+    },
+    "4040735335719974079": {
+      "message": "Resetting frozen recents task list reason=timeout",
+      "level": "INFO",
+      "group": "WM_DEBUG_TASKS",
+      "at": "com\/android\/server\/wm\/RecentTasks.java"
+    },
     "3308140128142966415": {
       "message": "remove RecentTask %s when finishing user %d",
       "level": "INFO",
diff --git a/services/core/java/com/android/server/wm/RecentTasks.java b/services/core/java/com/android/server/wm/RecentTasks.java
index 72f592b577da38d513e956c970cfc9513ab3e860..e07b72a051237d3d0989808f16cba8d019b2d62f 100644
--- a/services/core/java/com/android/server/wm/RecentTasks.java
+++ b/services/core/java/com/android/server/wm/RecentTasks.java
@@ -33,6 +33,7 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
 import static android.os.Process.SYSTEM_UID;
 import static android.view.MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE;
+import static android.view.WindowInsets.Type.mandatorySystemGestures;
 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
 import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
 
@@ -60,6 +61,8 @@ import android.content.pm.ParceledListSlice;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Insets;
+import android.graphics.Rect;
 import android.os.Environment;
 import android.os.IBinder;
 import android.os.RemoteException;
@@ -71,7 +74,9 @@ import android.util.IntArray;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseBooleanArray;
+import android.view.InsetsState;
 import android.view.MotionEvent;
+import android.view.WindowInsets;
 import android.view.WindowManagerPolicyConstants.PointerEventListener;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -208,6 +213,7 @@ class RecentTasks {
     private final HashMap<ComponentName, ActivityInfo> mTmpAvailActCache = new HashMap<>();
     private final HashMap<String, ApplicationInfo> mTmpAvailAppCache = new HashMap<>();
     private final SparseBooleanArray mTmpQuietProfileUserIds = new SparseBooleanArray();
+    private final Rect mTmpRect = new Rect();
 
     // TODO(b/127498985): This is currently a rough heuristic for interaction inside an app
     private final PointerEventListener mListener = new PointerEventListener() {
@@ -229,12 +235,27 @@ class RecentTasks {
                     if (win == null) {
                         return;
                     }
+
+                    // Verify the touch is within the mandatory system gesture inset bounds of the
+                    // window, use the raw insets state to ignore window z-order
+                    final InsetsState insetsState = dc.getInsetsStateController()
+                            .getRawInsetsState();
+                    mTmpRect.set(win.getFrame());
+                    mTmpRect.inset(insetsState.calculateInsets(win.getFrame(),
+                            mandatorySystemGestures(), false /* ignoreVisibility */));
+                    if (!mTmpRect.contains(x, y)) {
+                        return;
+                    }
+
                     // Unfreeze the task list once we touch down in a task
                     final boolean isAppWindowTouch = FIRST_APPLICATION_WINDOW <= win.mAttrs.type
                             && win.mAttrs.type <= LAST_APPLICATION_WINDOW;
                     if (isAppWindowTouch) {
                         final Task stack = mService.getTopDisplayFocusedRootTask();
                         final Task topTask = stack != null ? stack.getTopMostTask() : null;
+                        ProtoLog.i(WM_DEBUG_TASKS, "Resetting frozen recents task list"
+                                + " reason=app touch win=%s x=%d y=%d insetFrame=%s", win, x, y,
+                                mTmpRect);
                         resetFreezeTaskListReordering(topTask);
                     }
                 }
@@ -301,6 +322,8 @@ class RecentTasks {
             mFreezeTaskListReordering = true;
         }
 
+        ProtoLog.i(WM_DEBUG_TASKS, "Setting frozen recents task list");
+
         // Always update the reordering time when this is called to ensure that the timeout
         // is reset
         mService.mH.removeCallbacks(mResetFreezeTaskListOnTimeoutRunnable);
@@ -344,6 +367,7 @@ class RecentTasks {
             final Task focusedStack = mService.getTopDisplayFocusedRootTask();
             final Task topTask = focusedStack != null ? focusedStack.getTopMostTask() : null;
             final Task reorderToEndTask = topTask != null && topTask.hasChild() ? topTask : null;
+            ProtoLog.i(WM_DEBUG_TASKS, "Resetting frozen recents task list reason=timeout");
             resetFreezeTaskListReordering(reorderToEndTask);
         }
     }