Revert "Revert "Finish recents animation upon home rotation""

This reverts commit 0f8787db8038301608e39418a7b15610dbcac425.

Reason for revert: Revert and fix the broken tapl test

Fixes: 184054813
Change-Id: Ib647e11bfa0a2dc79a5a815be56452bb07e04ddf
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index e5ce950..1a0a1a4 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -2486,6 +2486,15 @@
     @Override
     protected void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
+        if (LIVE_TILE.get() && mRunningTaskId != -1) {
+            switchToScreenshot(
+                    () -> finishRecentsAnimation(true, this::onConfigurationChangedInternal));
+        } else {
+            onConfigurationChangedInternal();
+        }
+    }
+
+    private void onConfigurationChangedInternal() {
         final int rotation = mActivity.getDisplay().getRotation();
         if (mOrientationState.setRecentsRotation(rotation)) {
             updateOrientationHandler();
@@ -3438,7 +3447,7 @@
      * capturing the snapshot at the same time.
      */
     public void switchToScreenshot(Runnable onFinishRunnable) {
-        switchToScreenshot(mRunningTaskId == -1 ? null
+        switchToScreenshot(mRecentsAnimationController == null || mRunningTaskId == -1 ? null
                 : mRecentsAnimationController.screenshotTask(mRunningTaskId), onFinishRunnable);
     }