Skip Pip animation to fullscreen if orientation is going to change

Having this kind of animation look good is extremely difficult.
The best we can do is skip the animation and just go to fullscreen
if we know the device orientation is going to change because the
current screen configuration isn't compatible with the fixed
orientation requested by the app going fullscreen.

Change-Id: I97b14723a0d678c05efedc93fe692ad3b3212a72
Fixes: 37722472
Test: manual
diff --git a/services/core/java/com/android/server/am/PinnedActivityStack.java b/services/core/java/com/android/server/am/PinnedActivityStack.java
index 672f563..34cdb54 100644
--- a/services/core/java/com/android/server/am/PinnedActivityStack.java
+++ b/services/core/java/com/android/server/am/PinnedActivityStack.java
@@ -17,6 +17,7 @@
 package com.android.server.am;
 
 import android.app.RemoteAction;
+import android.content.res.Configuration;
 import android.graphics.Rect;
 
 import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
@@ -50,8 +51,21 @@
 
     void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
             boolean schedulePipModeChangedOnAnimationEnd) {
-        getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
-                animationDuration, schedulePipModeChangedOnAnimationEnd);
+        if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
+            mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
+        } else {
+            getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
+                    animationDuration, schedulePipModeChangedOnAnimationEnd);
+        }
+    }
+
+    private boolean skipResizeAnimation(boolean toFullscreen) {
+        if (!toFullscreen) {
+            return false;
+        }
+        final Configuration parentConfig = getParent().getConfiguration();
+        final ActivityRecord top = topRunningNonOverlayTaskActivity();
+        return top != null && !top.isConfigurationCompatible(parentConfig);
     }
 
     void setPictureInPictureAspectRatio(float aspectRatio) {