Add ability to show wallpaper during animation

In the new task switch animations, we'd like to show the wallpaper
behind. For that, we add the ability to show the wallpaper for
any animation via Animation.showWallpaper as an XML attribute.

If the window of an app is animating, and the animation requests
the wallpaper, it can also be a wallpaper.

One remaning issue here is that we don't wait for the wallpaper
to be drawn when waiting for the transition. However, usually this
isn't an issue because the wallpaper is drawn in any case.

To fix this we'd need to load the animation already and then make
it a target before the animation starts, which is a bit involved
/quirky.

Test: Open/close task, observe wallpaper behind
Test: go/wm-smoke
Bug: 72396815
Change-Id: I676273a4e6627f8b5e0a1366fcd80a7c92018123
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index 474db12..64686dd 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -206,6 +206,8 @@
      */
     private boolean mDetachWallpaper = false;
 
+    private boolean mShowWallpaper;
+
     private boolean mMore = true;
     private boolean mOneMoreTime = true;
 
@@ -253,7 +255,10 @@
 
         setBackgroundColor(a.getInt(com.android.internal.R.styleable.Animation_background, 0));
 
-        setDetachWallpaper(a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
+        setDetachWallpaper(
+                a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
+        setShowWallpaper(
+                a.getBoolean(com.android.internal.R.styleable.Animation_showWallpaper, false));
 
         final int resID = a.getResourceId(com.android.internal.R.styleable.Animation_interpolator, 0);
 
@@ -661,6 +666,18 @@
     }
 
     /**
+     * If this animation is run as a window animation, this will make the wallpaper visible behind
+     * the animation.
+     *
+     * @param showWallpaper Whether the wallpaper should be shown during the animation.
+     * @attr ref android.R.styleable#Animation_detachWallpaper
+     * @hide
+     */
+    public void setShowWallpaper(boolean showWallpaper) {
+        mShowWallpaper = showWallpaper;
+    }
+
+    /**
      * Gets the acceleration curve type for this animation.
      *
      * @return the {@link Interpolator} associated to this animation
@@ -775,6 +792,16 @@
     }
 
     /**
+     * @return If run as a window animation, returns whether the wallpaper will be shown behind
+     *         during the animation.
+     * @attr ref android.R.styleable#Animation_showWallpaper
+     * @hide
+     */
+    public boolean getShowWallpaper() {
+        return mShowWallpaper;
+    }
+
+    /**
      * <p>Indicates whether or not this animation will affect the transformation
      * matrix. For instance, a fade animation will not affect the matrix whereas
      * a scale animation will.</p>
diff --git a/core/res/res/anim/task_close_enter.xml b/core/res/res/anim/task_close_enter.xml
index 81d1300..c298b80 100644
--- a/core/res/res/anim/task_close_enter.xml
+++ b/core/res/res/anim/task_close_enter.xml
@@ -17,7 +17,8 @@
 -->
 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false"
-    android:zAdjustment="top">
+    android:zAdjustment="top"
+    android:showWallpaper="true">
 
     <alpha
         android:fromAlpha="1"
diff --git a/core/res/res/anim/task_close_exit.xml b/core/res/res/anim/task_close_exit.xml
index ab8b89c..9394c57 100644
--- a/core/res/res/anim/task_close_exit.xml
+++ b/core/res/res/anim/task_close_exit.xml
@@ -17,7 +17,8 @@
 -->
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
-    android:shareInterpolator="false">
+    android:shareInterpolator="false"
+    android:showWallpaper="true">
 
     <alpha
         android:fromAlpha="1.0"
diff --git a/core/res/res/anim/task_open_enter.xml b/core/res/res/anim/task_open_enter.xml
index 0e66eda..e23201f 100644
--- a/core/res/res/anim/task_open_enter.xml
+++ b/core/res/res/anim/task_open_enter.xml
@@ -19,7 +19,8 @@
 <!-- This should in sync with cross_profile_apps_thumbnail_enter.xml -->
 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false"
-    android:zAdjustment="top">
+    android:zAdjustment="top"
+    android:showWallpaper="true">
 
     <alpha
         android:fromAlpha="1"
diff --git a/core/res/res/anim/task_open_enter_cross_profile_apps.xml b/core/res/res/anim/task_open_enter_cross_profile_apps.xml
index a92425e..defea08 100644
--- a/core/res/res/anim/task_open_enter_cross_profile_apps.xml
+++ b/core/res/res/anim/task_open_enter_cross_profile_apps.xml
@@ -19,7 +19,8 @@
 <!-- This should in sync with task_open_enter.xml -->
 <set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false"
-    android:zAdjustment="top">
+    android:zAdjustment="top"
+    android:showWallpaper="true">
 
     <alpha
         android:fromAlpha="1"
diff --git a/core/res/res/anim/task_open_exit.xml b/core/res/res/anim/task_open_exit.xml
index ecb98ce..c9ade22 100644
--- a/core/res/res/anim/task_open_exit.xml
+++ b/core/res/res/anim/task_open_exit.xml
@@ -17,7 +17,8 @@
 -->
 
 <set xmlns:android="http://schemas.android.com/apk/res/android"
-    android:shareInterpolator="false">
+    android:shareInterpolator="false"
+    android:showWallpaper="true">
 
     <alpha
         android:fromAlpha="1.0"
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index d26567e..9d7432e 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -6328,6 +6328,9 @@
         <!-- Special option for window animations: if this window is on top
              of a wallpaper, don't animate the wallpaper with it. -->
         <attr name="detachWallpaper" format="boolean" />
+        <!-- Special option for window animations: show the wallpaper behind when running this
+             animation. -->
+        <attr name="showWallpaper" format="boolean" />
     </declare-styleable>
 
     <declare-styleable name="AnimationSet">
diff --git a/services/core/java/com/android/server/wm/AnimationAdapter.java b/services/core/java/com/android/server/wm/AnimationAdapter.java
index ed4543e..64f77a2 100644
--- a/services/core/java/com/android/server/wm/AnimationAdapter.java
+++ b/services/core/java/com/android/server/wm/AnimationAdapter.java
@@ -39,6 +39,12 @@
     boolean getDetachWallpaper();
 
     /**
+     * @return Whether we should show the wallpaper during the animation.
+     * @see Animation#getShowWallpaper()
+     */
+    boolean getShowWallpaper();
+
+    /**
      * @return The background color behind the animation.
      */
     @ColorInt int getBackgroundColor();
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 8155656..20bcd2d 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -1668,6 +1668,9 @@
             }
             if (adapter != null) {
                 startAnimation(getPendingTransaction(), adapter, !isVisible());
+                if (adapter.getShowWallpaper()) {
+                    mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                }
             }
         } else {
             cancelAnimation();
diff --git a/services/core/java/com/android/server/wm/LocalAnimationAdapter.java b/services/core/java/com/android/server/wm/LocalAnimationAdapter.java
index 2173fa3..1b41cb8 100644
--- a/services/core/java/com/android/server/wm/LocalAnimationAdapter.java
+++ b/services/core/java/com/android/server/wm/LocalAnimationAdapter.java
@@ -43,6 +43,11 @@
     }
 
     @Override
+    public boolean getShowWallpaper() {
+        return mSpec.getShowWallpaper();
+    }
+
+    @Override
     public int getBackgroundColor() {
         return mSpec.getBackgroundColor();
     }
@@ -82,6 +87,13 @@
         }
 
         /**
+         * @see AnimationAdapter#getShowWallpaper
+         */
+        default boolean getShowWallpaper() {
+            return false;
+        }
+
+        /**
          * @see AnimationAdapter#getBackgroundColor
          */
         default int getBackgroundColor() {
diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java
index 78dd580..31b5c69 100644
--- a/services/core/java/com/android/server/wm/RecentsAnimationController.java
+++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java
@@ -368,6 +368,11 @@
         }
 
         @Override
+        public boolean getShowWallpaper() {
+            return false;
+        }
+
+        @Override
         public int getBackgroundColor() {
             return 0;
         }
diff --git a/services/core/java/com/android/server/wm/RemoteAnimationController.java b/services/core/java/com/android/server/wm/RemoteAnimationController.java
index 35fc99f..ed6e606 100644
--- a/services/core/java/com/android/server/wm/RemoteAnimationController.java
+++ b/services/core/java/com/android/server/wm/RemoteAnimationController.java
@@ -221,6 +221,11 @@
         }
 
         @Override
+        public boolean getShowWallpaper() {
+            return false;
+        }
+
+        @Override
         public int getBackgroundColor() {
             return 0;
         }
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index a4f20b01..6356a35 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -606,8 +606,11 @@
         // If we are ready to perform an app transition, check through all of the app tokens to be
         // shown and see if they are ready to go.
         if (mService.mAppTransition.isReady()) {
-            defaultDisplay.pendingLayoutChanges |=
-                    surfacePlacer.handleAppTransitionReadyLocked();
+            // This needs to be split into two expressions, as handleAppTransitionReadyLocked may
+            // modify dc.pendingLayoutChanges, which would get lost when writing
+            // defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked()
+            final int layoutChanges = surfacePlacer.handleAppTransitionReadyLocked();
+            defaultDisplay.pendingLayoutChanges |= layoutChanges;
             if (DEBUG_LAYOUT_REPEATS)
                 surfacePlacer.debugLayoutRepeats("after handleAppTransitionReadyLocked",
                         defaultDisplay.pendingLayoutChanges);
diff --git a/services/core/java/com/android/server/wm/WallpaperController.java b/services/core/java/com/android/server/wm/WallpaperController.java
index f2ad6fb..a7d51f1 100644
--- a/services/core/java/com/android/server/wm/WallpaperController.java
+++ b/services/core/java/com/android/server/wm/WallpaperController.java
@@ -151,7 +151,10 @@
 
         final RecentsAnimationController recentsAnimationController =
                 mService.getRecentsAnimationController();
-        final boolean hasWallpaper = (w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
+        final boolean animationWallpaper = w.mAppToken != null && w.mAppToken.getAnimation() != null
+                && w.mAppToken.getAnimation().getShowWallpaper();
+        final boolean hasWallpaper = (w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0
+                || animationWallpaper;
         final boolean isRecentsTransitionTarget = (recentsAnimationController != null
                 && recentsAnimationController.isWallpaperVisible(w));
         if (isRecentsTransitionTarget) {
diff --git a/services/core/java/com/android/server/wm/WindowAnimationSpec.java b/services/core/java/com/android/server/wm/WindowAnimationSpec.java
index 0863ee9..43fa3d5 100644
--- a/services/core/java/com/android/server/wm/WindowAnimationSpec.java
+++ b/services/core/java/com/android/server/wm/WindowAnimationSpec.java
@@ -69,6 +69,11 @@
     }
 
     @Override
+    public boolean getShowWallpaper() {
+        return mAnimation.getShowWallpaper();
+    }
+
+    @Override
     public int getBackgroundColor() {
         return mAnimation.getBackgroundColor();
     }