Move PiP animation to SysUI package

The bounds animation is cleaned up within window manager and it's now
the SysUI component listening on callbacks from TaskOrganizer for
entering to and exiting from PiP mode.

Additionally, the expand and move of the PiP window is now part of SysUI
as well.

Known issues:
- Black background when in transition from PiP to fullscreen. The
wallpaper gets into hidden state too early
- App gets into PiP mode too early when entering PiP, need to defer the
configuration change sent to app in this case

Bug: 146594635
Bug: 148198539
Bug: 138144750
Bug: 149569903
Test: atest PinnedStackTests
Test: atest PipAnimationControllerTest
Test: atest RecentsAnimationTest
Test: atest RecentTasksTest
Test: atest com.android.server.wm.ActivityStarterTests
Merged-In: Id0c8ce03fa26952daf5e3687b18b2eb2375b7d20
Change-Id: Id0c8ce03fa26952daf5e3687b18b2eb2375b7d20
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 5392257..9458939 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -2645,64 +2645,6 @@
         }
     }
 
-    @Override
-    public void animateResizePinnedStack(int stackId, Rect destBounds, int animationDuration) {
-        enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "animateResizePinnedStack()");
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mGlobalLock) {
-                final ActivityStack stack = mRootWindowContainer.getStack(stackId);
-                if (stack == null) {
-                    Slog.w(TAG, "resizeStack: stackId " + stackId + " not found.");
-                    return;
-                }
-                if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) {
-                    throw new IllegalArgumentException("Stack: " + stackId
-                        + " doesn't support animated resize.");
-                }
-                stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */,
-                        animationDuration, false /* fromFullscreen */);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public void offsetPinnedStackBounds(int stackId, Rect compareBounds, int xOffset, int yOffset,
-            int animationDuration) {
-        enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "offsetPinnedStackBounds()");
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mGlobalLock) {
-                if (xOffset == 0 && yOffset == 0) {
-                    return;
-                }
-                final ActivityStack stack = mRootWindowContainer.getStack(stackId);
-                if (stack == null) {
-                    Slog.w(TAG, "offsetPinnedStackBounds: stackId " + stackId + " not found.");
-                    return;
-                }
-                if (stack.getWindowingMode() != WINDOWING_MODE_PINNED) {
-                    throw new IllegalArgumentException("Stack: " + stackId
-                            + " doesn't support animated resize.");
-                }
-                final Rect destBounds = new Rect();
-                stack.getAnimationOrCurrentBounds(destBounds);
-                if (destBounds.isEmpty() || !destBounds.equals(compareBounds)) {
-                    Slog.w(TAG, "The current stack bounds does not matched! It may be obsolete.");
-                    return;
-                }
-                destBounds.offset(xOffset, yOffset);
-                stack.animateResizePinnedStack(destBounds, null /* sourceHintBounds */,
-                        animationDuration, false /* fromFullscreen */);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
     /**
      * Moves the specified task to the primary-split-screen stack.
      *
@@ -4016,17 +3958,7 @@
                     throw new IllegalArgumentException("Stack: " + stack
                             + " doesn't support animated resize.");
                 }
-                /**
-                 * TODO(b/146594635): Remove all PIP animation code from WM
-                 * once SysUI handles animation. Don't even try to animate TaskOrganized tasks.
-                 */
-                if (animate && !stack.isControlledByTaskOrganizer()) {
-                    stack.animateResizePinnedStack(null /* destBounds */,
-                            null /* sourceHintBounds */, animationDuration,
-                            false /* fromFullscreen */);
-                } else {
-                    stack.dismissPip();
-                }
+                stack.dismissPip();
             }
         } finally {
             Binder.restoreCallingIdentity(ident);
@@ -4121,15 +4053,10 @@
     }
 
     private boolean isInPictureInPictureMode(ActivityRecord r) {
-        if (r == null || r.getRootTask() == null || !r.inPinnedWindowingMode()
-                || r.getRootTask().isInStackLocked(r) == null) {
-            return false;
-        }
-
-        // If we are animating to fullscreen then we have already dispatched the PIP mode
-        // changed, so we should reflect that check here as well.
-        final ActivityStack taskStack = r.getRootTask();
-        return !taskStack.isAnimatingBoundsToFullscreen();
+        return r != null
+                && r.getRootTask() != null
+                && r.inPinnedWindowingMode()
+                && r.getRootTask().isInStackLocked(r) != null;
     }
 
     @Override
@@ -4213,11 +4140,9 @@
                     // if it is not already expanding to fullscreen. Otherwise, the arguments will
                     // be used the next time the activity enters PiP
                     final ActivityStack stack = r.getRootTask();
-                    if (!stack.isAnimatingBoundsToFullscreen()) {
-                        stack.setPictureInPictureAspectRatio(
-                                r.pictureInPictureArgs.getAspectRatio());
-                        stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions());
-                    }
+                    stack.setPictureInPictureAspectRatio(
+                            r.pictureInPictureArgs.getAspectRatio());
+                    stack.setPictureInPictureActions(r.pictureInPictureArgs.getActions());
                 }
                 logPictureInPictureArgs(params);
             }
@@ -4421,31 +4346,6 @@
                 .supportsLocalVoiceInteraction();
     }
 
-    /** Notifies all listeners when the pinned stack animation starts. */
-    @Override
-    public void notifyPinnedStackAnimationStarted() {
-        mTaskChangeNotificationController.notifyPinnedStackAnimationStarted();
-    }
-
-    /** Notifies all listeners when the pinned stack animation ends. */
-    @Override
-    public void notifyPinnedStackAnimationEnded() {
-        mTaskChangeNotificationController.notifyPinnedStackAnimationEnded();
-    }
-
-    @Override
-    public void resizePinnedStack(Rect displayedBounds, Rect configBounds) {
-        enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "resizePinnedStack()");
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mGlobalLock) {
-                mStackSupervisor.resizePinnedStack(displayedBounds, configBounds);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
     @Override
     public boolean updateConfiguration(Configuration values) {
         mAmInternal.enforceCallingPermission(CHANGE_CONFIGURATION, "updateConfiguration()");