Workaround for flicker between handoff from app to task view

- Defer finishing the recents animation for a couple frames until the
  frame has likely been pushed to sf and drawn, otherwise the reparenting
  of the app surface may happen before the task view is visible in
  Launcher.

Bug: 111299394
Test: Swipe up repeatedly from an app
Change-Id: I627dc085a5e376436b2b8eb5841c45fd36deff42
diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
index 15ff19e..902eb95 100644
--- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -882,8 +882,21 @@
                 // new thumbnail
                 finishTransitionPosted = new WindowCallbacksCompat(taskView) {
 
+                    // The number of frames to defer until we actually finish the animation
+                    private int mDeferFrameCount = 2;
+
                     @Override
                     public void onPostDraw(Canvas canvas) {
+                        if (mDeferFrameCount > 0) {
+                            mDeferFrameCount--;
+                            // Workaround, detach and reattach to invalidate the root node for
+                            // another draw
+                            detach();
+                            attach();
+                            taskView.invalidate();
+                            return;
+                        }
+
                         setStateOnUiThread(STATE_SCREENSHOT_CAPTURED);
                         detach();
                     }