swipe-dismiss: isolate animation definition

- Isolate animation definitions from the WMShellBaseModule in order to
  allow build time override
- Consolidate animations under ShellBackAnimation class
- Move mAnimationDefinition into ShellBackAnimationRegistry to
  centralize operations on animation type
- Move animation initialization from ShellInit to injection time
- Other minor lint fixes

Test: build & flash on phone/watch
Test: atest com.android.wm.shell.back
Bug: 290801681
Bug: 290801423
Change-Id: I0a89a34e67f16ea861f2bc95ed49eb8e080450c2
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationBackground.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationBackground.java
index 9bf3b80..42dc19c 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationBackground.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationBackground.java
@@ -52,12 +52,13 @@
 
     /**
      * Ensures the back animation background color layer is present.
+     *
      * @param startRect The start bounds of the closing target.
      * @param color The background color.
      * @param transaction The animation transaction.
      */
-    void ensureBackground(Rect startRect, int color,
-            @NonNull SurfaceControl.Transaction transaction) {
+    public void ensureBackground(
+            Rect startRect, int color, @NonNull SurfaceControl.Transaction transaction) {
         if (mBackgroundSurface != null) {
             return;
         }
@@ -81,7 +82,12 @@
         mIsRequestingStatusBarAppearance = false;
     }
 
-    void removeBackground(@NonNull SurfaceControl.Transaction transaction) {
+    /**
+     * Remove the back animation background.
+     *
+     * @param transaction The animation transaction.
+     */
+    public void removeBackground(@NonNull SurfaceControl.Transaction transaction) {
         if (mBackgroundSurface == null) {
             return;
         }
@@ -93,11 +99,21 @@
         mIsRequestingStatusBarAppearance = false;
     }
 
+    /**
+     * Attach a {@link StatusBarCustomizer} instance to allow status bar animate with back progress.
+     *
+     * @param customizer The {@link StatusBarCustomizer} to be used.
+     */
     void setStatusBarCustomizer(StatusBarCustomizer customizer) {
         mCustomizer = customizer;
     }
 
-    void onBackProgressed(float progress) {
+    /**
+     * Update back animation background with for the progress.
+     *
+     * @param progress Progress value from {@link android.window.BackProgressAnimator}
+     */
+    public void onBackProgressed(float progress) {
         if (mCustomizer == null || mStartBounds.isEmpty()) {
             return;
         }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
index bb543f2..3790f04 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationController.java
@@ -25,6 +25,7 @@
 import android.animation.ValueAnimator;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.annotation.SuppressLint;
 import android.app.ActivityTaskManager;
 import android.app.IActivityTaskManager;
 import android.content.ContentResolver;
@@ -43,7 +44,6 @@
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.util.MathUtils;
-import android.util.SparseArray;
 import android.view.IRemoteAnimationRunner;
 import android.view.InputDevice;
 import android.view.KeyCharacterMap;
@@ -70,6 +70,7 @@
 import com.android.wm.shell.sysui.ShellController;
 import com.android.wm.shell.sysui.ShellInit;
 
+
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -113,7 +114,11 @@
     private boolean mShouldStartOnNextMoveEvent = false;
     /** @see #setTriggerBack(boolean) */
     private boolean mTriggerBack;
-    private FlingAnimationUtils mFlingAnimationUtils;
+
+    private final FlingAnimationUtils mFlingAnimationUtils;
+
+    /** Registry for the back animations */
+    private final ShellBackAnimationRegistry mShellBackAnimationRegistry;
 
     @Nullable
     private BackNavigationInfo mBackNavigationInfo;
@@ -135,13 +140,9 @@
 
     private final TouchTracker mTouchTracker = new TouchTracker();
 
-    private final SparseArray<BackAnimationRunner> mAnimationDefinition = new SparseArray<>();
     @Nullable
     private IOnBackInvokedCallback mActiveCallback;
 
-    private CrossActivityAnimation mDefaultActivityAnimation;
-    private CustomizeActivityAnimation mCustomizeActivityAnimation;
-
     @VisibleForTesting
     final RemoteCallback mNavigationObserver = new RemoteCallback(
             new RemoteCallback.OnResultListener() {
@@ -169,10 +170,18 @@
             @NonNull @ShellMainThread ShellExecutor shellExecutor,
             @NonNull @ShellBackgroundThread Handler backgroundHandler,
             Context context,
-            @NonNull BackAnimationBackground backAnimationBackground) {
-        this(shellInit, shellController, shellExecutor, backgroundHandler,
-                ActivityTaskManager.getService(), context, context.getContentResolver(),
-                backAnimationBackground);
+            @NonNull BackAnimationBackground backAnimationBackground,
+            ShellBackAnimationRegistry shellBackAnimationRegistry) {
+        this(
+                shellInit,
+                shellController,
+                shellExecutor,
+                backgroundHandler,
+                ActivityTaskManager.getService(),
+                context,
+                context.getContentResolver(),
+                backAnimationBackground,
+                shellBackAnimationRegistry);
     }
 
     @VisibleForTesting
@@ -182,8 +191,10 @@
             @NonNull @ShellMainThread ShellExecutor shellExecutor,
             @NonNull @ShellBackgroundThread Handler bgHandler,
             @NonNull IActivityTaskManager activityTaskManager,
-            Context context, ContentResolver contentResolver,
-            @NonNull BackAnimationBackground backAnimationBackground) {
+            Context context,
+            ContentResolver contentResolver,
+            @NonNull BackAnimationBackground backAnimationBackground,
+            ShellBackAnimationRegistry shellBackAnimationRegistry) {
         mShellController = shellController;
         mShellExecutor = shellExecutor;
         mActivityTaskManager = activityTaskManager;
@@ -197,11 +208,7 @@
                 .setMaxLengthSeconds(FLING_MAX_LENGTH_SECONDS)
                 .setSpeedUpFactor(FLING_SPEED_UP_FACTOR)
                 .build();
-    }
-
-    @VisibleForTesting
-    void setEnableUAnimation(boolean enable) {
-        IS_U_ANIMATION_ENABLED = enable;
+        mShellBackAnimationRegistry = shellBackAnimationRegistry;
     }
 
     private void onInit() {
@@ -209,26 +216,6 @@
         createAdapter();
         mShellController.addExternalInterface(KEY_EXTRA_SHELL_BACK_ANIMATION,
                 this::createExternalInterface, this);
-
-        initBackAnimationRunners();
-    }
-
-    private void initBackAnimationRunners() {
-        if (!IS_U_ANIMATION_ENABLED) {
-            return;
-        }
-
-        final CrossTaskBackAnimation crossTaskAnimation =
-                new CrossTaskBackAnimation(mContext, mAnimationBackground);
-        mAnimationDefinition.set(BackNavigationInfo.TYPE_CROSS_TASK,
-                crossTaskAnimation.mBackAnimationRunner);
-        mDefaultActivityAnimation =
-                new CrossActivityAnimation(mContext, mAnimationBackground);
-        mAnimationDefinition.set(BackNavigationInfo.TYPE_CROSS_ACTIVITY,
-                mDefaultActivityAnimation.mBackAnimationRunner);
-        mCustomizeActivityAnimation =
-                new CustomizeActivityAnimation(mContext, mAnimationBackground);
-        // TODO (236760237): register dialog close animation when it's completed.
     }
 
     private void setupAnimationDeveloperSettingsObserver(
@@ -359,11 +346,11 @@
 
     void registerAnimation(@BackNavigationInfo.BackTargetType int type,
             @NonNull BackAnimationRunner runner) {
-        mAnimationDefinition.set(type, runner);
+        mShellBackAnimationRegistry.registerAnimation(type, runner);
     }
 
     void unregisterAnimation(@BackNavigationInfo.BackTargetType int type) {
-        mAnimationDefinition.remove(type);
+        mShellBackAnimationRegistry.unregisterAnimation(type);
     }
 
     /**
@@ -434,9 +421,7 @@
         final int backType = backNavigationInfo.getType();
         final boolean shouldDispatchToAnimator = shouldDispatchToAnimator();
         if (shouldDispatchToAnimator) {
-            if (mAnimationDefinition.contains(backType)) {
-                mAnimationDefinition.get(backType).startGesture();
-            } else {
+            if (!mShellBackAnimationRegistry.startGesture(backType)) {
                 mActiveCallback = null;
             }
         } else {
@@ -459,6 +444,7 @@
         sendBackEvent(KeyEvent.ACTION_UP);
     }
 
+    @SuppressLint("MissingPermission")
     private void sendBackEvent(int action) {
         final long when = SystemClock.uptimeMillis();
         final KeyEvent ev = new KeyEvent(when, when, action, KeyEvent.KEYCODE_BACK, 0 /* repeat */,
@@ -671,21 +657,17 @@
         }
 
         final int backType = mBackNavigationInfo.getType();
-        final BackAnimationRunner runner = mAnimationDefinition.get(backType);
         // Simply trigger and finish back navigation when no animator defined.
-        if (!shouldDispatchToAnimator() || runner == null) {
+        if (!shouldDispatchToAnimator()
+                || mShellBackAnimationRegistry.isAnimationCancelledOrNull(backType)) {
             invokeOrCancelBack();
             return;
-        }
-        if (runner.isWaitingAnimation()) {
+        } else if (mShellBackAnimationRegistry.isWaitingAnimation(backType)) {
             ProtoLog.w(WM_SHELL_BACK_PREVIEW, "Gesture released, but animation didn't ready.");
             // Supposed it is in post commit animation state, and start the timeout to watch
             // if the animation is ready.
             mShellExecutor.executeDelayed(mAnimationTimeoutRunnable, MAX_ANIMATION_DURATION);
             return;
-        } else if (runner.isAnimationCancelled()) {
-            invokeOrCancelBack();
-            return;
         }
         startPostCommitAnimation();
     }
@@ -737,12 +719,7 @@
         mShouldStartOnNextMoveEvent = false;
         mTouchTracker.reset();
         mActiveCallback = null;
-        // reset to default
-        if (mDefaultActivityAnimation != null
-                && mAnimationDefinition.contains(BackNavigationInfo.TYPE_CROSS_ACTIVITY)) {
-            mAnimationDefinition.set(BackNavigationInfo.TYPE_CROSS_ACTIVITY,
-                    mDefaultActivityAnimation.mBackAnimationRunner);
-        }
+        mShellBackAnimationRegistry.resetDefaultCrossActivity();
         if (mBackNavigationInfo != null) {
             mBackNavigationInfo.onBackNavigationFinished(mTriggerBack);
             mBackNavigationInfo = null;
@@ -750,86 +727,88 @@
         mTriggerBack = false;
     }
 
-    private BackAnimationRunner getAnimationRunnerAndInit() {
-        int type = mBackNavigationInfo.getType();
-        // Initiate customized cross-activity animation, or fall back to cross activity animation
-        if (type == BackNavigationInfo.TYPE_CROSS_ACTIVITY && mAnimationDefinition.contains(type)) {
-            final BackNavigationInfo.CustomAnimationInfo animationInfo =
-                    mBackNavigationInfo.getCustomAnimationInfo();
-            if (animationInfo != null && mCustomizeActivityAnimation != null
-                    && mCustomizeActivityAnimation.prepareNextAnimation(animationInfo)) {
-                mAnimationDefinition.get(type).resetWaitingAnimation();
-                mAnimationDefinition.set(BackNavigationInfo.TYPE_CROSS_ACTIVITY,
-                        mCustomizeActivityAnimation.mBackAnimationRunner);
-            }
-        }
-        return mAnimationDefinition.get(type);
-    }
 
     private void createAdapter() {
-        IBackAnimationRunner runner = new IBackAnimationRunner.Stub() {
-            @Override
-            public void onAnimationStart(RemoteAnimationTarget[] apps,
-                    RemoteAnimationTarget[] wallpapers, RemoteAnimationTarget[] nonApps,
-                    IBackAnimationFinishedCallback finishedCallback) {
-                mShellExecutor.execute(() -> {
-                    if (mBackNavigationInfo == null) {
-                        Log.e(TAG, "Lack of navigation info to start animation.");
-                        return;
-                    }
-                    final int type = mBackNavigationInfo.getType();
-                    final BackAnimationRunner runner = getAnimationRunnerAndInit();
-                    if (runner == null) {
-                        Log.e(TAG, "Animation didn't be defined for type "
-                                + BackNavigationInfo.typeToString(type));
-                        if (finishedCallback != null) {
-                            try {
-                                finishedCallback.onAnimationFinished(false);
-                            } catch (RemoteException e) {
-                                Log.w(TAG, "Failed call IBackNaviAnimationController", e);
-                            }
-                        }
-                        return;
-                    }
-                    mActiveCallback = runner.getCallback();
-                    mBackAnimationFinishedCallback = finishedCallback;
+        IBackAnimationRunner runner =
+                new IBackAnimationRunner.Stub() {
+                    @Override
+                    public void onAnimationStart(
+                            RemoteAnimationTarget[] apps,
+                            RemoteAnimationTarget[] wallpapers,
+                            RemoteAnimationTarget[] nonApps,
+                            IBackAnimationFinishedCallback finishedCallback) {
+                        mShellExecutor.execute(
+                                () -> {
+                                    if (mBackNavigationInfo == null) {
+                                        Log.e(TAG, "Lack of navigation info to start animation.");
+                                        return;
+                                    }
+                                    final BackAnimationRunner runner =
+                                            mShellBackAnimationRegistry.getAnimationRunnerAndInit(
+                                                    mBackNavigationInfo);
+                                    if (runner == null) {
+                                        if (finishedCallback != null) {
+                                            try {
+                                                finishedCallback.onAnimationFinished(false);
+                                            } catch (RemoteException e) {
+                                                Log.w(
+                                                        TAG,
+                                                        "Failed call IBackNaviAnimationController",
+                                                        e);
+                                            }
+                                        }
+                                        return;
+                                    }
+                                    mActiveCallback = runner.getCallback();
+                                    mBackAnimationFinishedCallback = finishedCallback;
 
-                    ProtoLog.d(WM_SHELL_BACK_PREVIEW, "BackAnimationController: startAnimation()");
-                    runner.startAnimation(apps, wallpapers, nonApps, () -> mShellExecutor.execute(
-                            BackAnimationController.this::onBackAnimationFinished));
+                                    ProtoLog.d(
+                                            WM_SHELL_BACK_PREVIEW,
+                                            "BackAnimationController: startAnimation()");
+                                    runner.startAnimation(
+                                            apps,
+                                            wallpapers,
+                                            nonApps,
+                                            () ->
+                                                    mShellExecutor.execute(
+                                                            BackAnimationController.this
+                                                                    ::onBackAnimationFinished));
 
-                    if (apps.length >= 1) {
-                        dispatchOnBackStarted(
-                                mActiveCallback, mTouchTracker.createStartEvent(apps[0]));
+                                    if (apps.length >= 1) {
+                                        dispatchOnBackStarted(
+                                                mActiveCallback,
+                                                mTouchTracker.createStartEvent(apps[0]));
+                                    }
+
+                                    // Dispatch the first progress after animation start for
+                                    // smoothing the initial animation, instead of waiting for next
+                                    // onMove.
+                                    final BackMotionEvent backFinish =
+                                            mTouchTracker.createProgressEvent();
+                                    dispatchOnBackProgressed(mActiveCallback, backFinish);
+                                    if (!mBackGestureStarted) {
+                                        // if the down -> up gesture happened before animation
+                                        // start, we have to trigger the uninterruptible transition
+                                        // to finish the back animation.
+                                        startPostCommitAnimation();
+                                    }
+                                });
                     }
 
-                    // Dispatch the first progress after animation start for smoothing the initial
-                    // animation, instead of waiting for next onMove.
-                    final BackMotionEvent backFinish = mTouchTracker.createProgressEvent();
-                    dispatchOnBackProgressed(mActiveCallback, backFinish);
-                    if (!mBackGestureStarted) {
-                        // if the down -> up gesture happened before animation start, we have to
-                        // trigger the uninterruptible transition to finish the back animation.
-                        startPostCommitAnimation();
+                    @Override
+                    public void onAnimationCancelled() {
+                        mShellExecutor.execute(
+                                () -> {
+                                    if (!mShellBackAnimationRegistry.cancel(
+                                            mBackNavigationInfo.getType())) {
+                                        return;
+                                    }
+                                    if (!mBackGestureStarted) {
+                                        invokeOrCancelBack();
+                                    }
+                                });
                     }
-                });
-            }
-
-            @Override
-            public void onAnimationCancelled() {
-                mShellExecutor.execute(() -> {
-                    final BackAnimationRunner runner = mAnimationDefinition.get(
-                            mBackNavigationInfo.getType());
-                    if (runner == null) {
-                        return;
-                    }
-                    runner.cancelAnimation();
-                    if (!mBackGestureStarted) {
-                        invokeOrCancelBack();
-                    }
-                });
-            }
-        };
+                };
         mBackAnimationAdapter = new BackAnimationAdapter(runner);
     }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java
index 913239f7..431df21 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/BackAnimationRunner.java
@@ -32,7 +32,7 @@
  * before it received IBackAnimationRunner#onAnimationStart, so the controller could continue
  * trigger the real back behavior.
  */
-class BackAnimationRunner {
+public class BackAnimationRunner {
     private static final String TAG = "ShellBackPreview";
 
     private final IOnBackInvokedCallback mCallback;
@@ -44,8 +44,8 @@
     /** True when the back animation is cancelled */
     private boolean mAnimationCancelled;
 
-    BackAnimationRunner(@NonNull IOnBackInvokedCallback callback,
-            @NonNull IRemoteAnimationRunner runner) {
+    public BackAnimationRunner(
+            @NonNull IOnBackInvokedCallback callback, @NonNull IRemoteAnimationRunner runner) {
         mCallback = callback;
         mRunner = runner;
     }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java
index edefe9e..9181281 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityAnimation.java
@@ -51,9 +51,11 @@
 import com.android.internal.protolog.common.ProtoLog;
 import com.android.wm.shell.common.annotations.ShellMainThread;
 
+import javax.inject.Inject;
+
 /** Class that defines cross-activity animation. */
 @ShellMainThread
-class CrossActivityAnimation {
+public class CrossActivityAnimation extends ShellBackAnimation {
     /**
      * Minimum scale of the entering/closing window.
      */
@@ -106,6 +108,7 @@
     private final SpringAnimation mLeavingProgressSpring;
     // Max window x-shift in pixels.
     private final float mWindowXShift;
+    private final BackAnimationRunner mBackAnimationRunner;
 
     private float mEnteringProgress = 0f;
     private float mLeavingProgress = 0f;
@@ -126,11 +129,11 @@
     private IRemoteAnimationFinishedCallback mFinishCallback;
 
     private final BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
-    final BackAnimationRunner mBackAnimationRunner;
 
     private final BackAnimationBackground mBackground;
 
-    CrossActivityAnimation(Context context, BackAnimationBackground background) {
+    @Inject
+    public CrossActivityAnimation(Context context, BackAnimationBackground background) {
         mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context);
         mBackAnimationRunner = new BackAnimationRunner(new Callback(), new Runner());
         mBackground = background;
@@ -357,6 +360,11 @@
         mTransaction.apply();
     }
 
+    @Override
+    public BackAnimationRunner getRunner() {
+        return mBackAnimationRunner;
+    }
+
     private final class Callback extends IOnBackInvokedCallback.Default {
         @Override
         public void onBackStarted(BackMotionEvent backEvent) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java
index a7dd27a..209d853 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossTaskBackAnimation.java
@@ -47,21 +47,23 @@
 import com.android.internal.protolog.common.ProtoLog;
 import com.android.wm.shell.common.annotations.ShellMainThread;
 
+import javax.inject.Inject;
+
 /**
  * Controls the animation of swiping back and returning to another task.
  *
- * This is a two part animation. The first part is an animation that tracks gesture location to
- * scale and move the closing and entering app windows.
- * Once the gesture is committed, the second part remains the closing window in place.
- * The entering window plays the rest of app opening transition to enter full screen.
+ * <p>This is a two part animation. The first part is an animation that tracks gesture location to
+ * scale and move the closing and entering app windows. Once the gesture is committed, the second
+ * part remains the closing window in place. The entering window plays the rest of app opening
+ * transition to enter full screen.
  *
- * This animation is used only for apps that enable back dispatching via
- * {@link android.window.OnBackInvokedDispatcher}. The controller registers
- * an {@link IOnBackInvokedCallback} with WM Shell and receives back dispatches when a back
- * navigation to launcher starts.
+ * <p>This animation is used only for apps that enable back dispatching via {@link
+ * android.window.OnBackInvokedDispatcher}. The controller registers an {@link
+ * IOnBackInvokedCallback} with WM Shell and receives back dispatches when a back navigation to
+ * launcher starts.
  */
 @ShellMainThread
-class CrossTaskBackAnimation {
+public class CrossTaskBackAnimation extends ShellBackAnimation {
     private static final int BACKGROUNDCOLOR = 0x43433A;
 
     /**
@@ -104,28 +106,41 @@
 
     private final float[] mTmpFloat9 = new float[9];
     private final float[] mTmpTranslate = {0, 0, 0};
-
+    private final BackAnimationRunner mBackAnimationRunner;
+    private final BackAnimationBackground mBackground;
     private RemoteAnimationTarget mEnteringTarget;
     private RemoteAnimationTarget mClosingTarget;
     private SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
-
     private boolean mBackInProgress = false;
-
     private boolean mIsRightEdge;
     private float mProgress = 0;
     private PointF mTouchPos = new PointF();
     private IRemoteAnimationFinishedCallback mFinishCallback;
     private BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
-    final BackAnimationRunner mBackAnimationRunner;
 
-    private final BackAnimationBackground mBackground;
-
-    CrossTaskBackAnimation(Context context, BackAnimationBackground background) {
+    @Inject
+    public CrossTaskBackAnimation(Context context, BackAnimationBackground background) {
         mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context);
         mBackAnimationRunner = new BackAnimationRunner(new Callback(), new Runner());
         mBackground = background;
     }
 
+    private static void computeScaleTransformMatrix(float scale, float[] matrix) {
+        matrix[0] = scale;
+        matrix[1] = 0;
+        matrix[2] = 0;
+        matrix[3] = 0;
+        matrix[4] = scale;
+        matrix[5] = 0;
+        matrix[6] = 0;
+        matrix[7] = 0;
+        matrix[8] = scale;
+    }
+
+    private static float mapRange(float value, float min, float max) {
+        return min + (value * (max - min));
+    }
+
     private float getInterpolatedProgress(float backProgress) {
         return 1 - (1 - backProgress) * (1 - backProgress) * (1 - backProgress);
     }
@@ -233,18 +248,6 @@
         mTransaction.setColorTransform(leash, mTmpFloat9, mTmpTranslate);
     }
 
-    static void computeScaleTransformMatrix(float scale, float[] matrix) {
-        matrix[0] = scale;
-        matrix[1] = 0;
-        matrix[2] = 0;
-        matrix[3] = 0;
-        matrix[4] = scale;
-        matrix[5] = 0;
-        matrix[6] = 0;
-        matrix[7] = 0;
-        matrix[8] = scale;
-    }
-
     private void finishAnimation() {
         if (mEnteringTarget != null) {
             mEnteringTarget.leash.release();
@@ -314,11 +317,12 @@
         valueAnimator.start();
     }
 
-    private static float mapRange(float value, float min, float max) {
-        return min + (value * (max - min));
+    @Override
+    public BackAnimationRunner getRunner() {
+        return mBackAnimationRunner;
     }
 
-    private final class Callback extends IOnBackInvokedCallback.Default  {
+    private final class Callback extends IOnBackInvokedCallback.Default {
         @Override
         public void onBackStarted(BackMotionEvent backEvent) {
             mProgressAnimator.onBackStarted(backEvent,
@@ -340,7 +344,7 @@
             mProgressAnimator.reset();
             onGestureCommitted();
         }
-    };
+    }
 
     private final class Runner extends IRemoteAnimationRunner.Default {
         @Override
@@ -360,5 +364,5 @@
             startBackAnimation();
             mFinishCallback = finishedCallback;
         }
-    };
+    }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomizeActivityAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomizeActivityAnimation.java
index 2d6ec75..aca638c 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomizeActivityAnimation.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomizeActivityAnimation.java
@@ -55,13 +55,13 @@
 import com.android.internal.protolog.common.ProtoLog;
 import com.android.wm.shell.common.annotations.ShellMainThread;
 
-/**
- * Class that handle customized close activity transition animation.
- */
+import javax.inject.Inject;
+
+/** Class that handle customized close activity transition animation. */
 @ShellMainThread
-class CustomizeActivityAnimation {
+public class CustomizeActivityAnimation extends ShellBackAnimation {
     private final BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
-    final BackAnimationRunner mBackAnimationRunner;
+    private final BackAnimationRunner mBackAnimationRunner;
     private final float mCornerRadius;
     private final SurfaceControl.Transaction mTransaction;
     private final BackAnimationBackground mBackground;
@@ -88,7 +88,8 @@
 
     private final Choreographer mChoreographer;
 
-    CustomizeActivityAnimation(Context context, BackAnimationBackground background) {
+    @Inject
+    public CustomizeActivityAnimation(Context context, BackAnimationBackground background) {
         this(context, background, new SurfaceControl.Transaction(), null);
     }
 
@@ -258,10 +259,12 @@
         valueAnimator.start();
     }
 
-    /**
-     * Load customize animation before animation start.
-     */
-    boolean prepareNextAnimation(BackNavigationInfo.CustomAnimationInfo animationInfo) {
+    /** Load customize animation before animation start. */
+    @Override
+    public boolean prepareNextAnimation(BackNavigationInfo.CustomAnimationInfo animationInfo) {
+        if (animationInfo == null) {
+            return false;
+        }
         final AnimationLoadResult result = mCustomAnimationLoader.loadAll(animationInfo);
         if (result != null) {
             mCloseAnimation = result.mCloseAnimation;
@@ -272,6 +275,11 @@
         return false;
     }
 
+    @Override
+    public BackAnimationRunner getRunner() {
+        return mBackAnimationRunner;
+    }
+
     private final class Callback extends IOnBackInvokedCallback.Default {
         @Override
         public void onBackStarted(BackMotionEvent backEvent) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimation.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimation.java
new file mode 100644
index 0000000..312e88d
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimation.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.back;
+
+import android.window.BackNavigationInfo;
+
+import javax.inject.Qualifier;
+
+/** Base class for all back animations. */
+public abstract class ShellBackAnimation {
+    @Qualifier
+    public @interface CrossActivity {}
+
+    @Qualifier
+    public @interface CrossTask {}
+
+    @Qualifier
+    public @interface CustomizeActivity {}
+
+    @Qualifier
+    public @interface ReturnToHome {}
+
+    /** Retrieve the {@link BackAnimationRunner} associated with this animation. */
+    public abstract BackAnimationRunner getRunner();
+
+    /**
+     * Prepare the next animation with customized animation.
+     *
+     * @return true if this type of back animation should override the default.
+     */
+    public boolean prepareNextAnimation(BackNavigationInfo.CustomAnimationInfo animationInfo) {
+        return false;
+    }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimationRegistry.java b/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimationRegistry.java
new file mode 100644
index 0000000..62b18f3
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/ShellBackAnimationRegistry.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.back;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.util.Log;
+import android.util.SparseArray;
+import android.window.BackNavigationInfo;
+
+/** Registry for all types of default back animations */
+public class ShellBackAnimationRegistry {
+    private static final String TAG = "ShellBackPreview";
+
+    private final SparseArray<BackAnimationRunner> mAnimationDefinition = new SparseArray<>();
+    private final ShellBackAnimation mDefaultCrossActivityAnimation;
+    private final ShellBackAnimation mCustomizeActivityAnimation;
+
+    public ShellBackAnimationRegistry(
+            @ShellBackAnimation.CrossActivity @Nullable ShellBackAnimation crossActivityAnimation,
+            @ShellBackAnimation.CrossTask @Nullable ShellBackAnimation crossTaskAnimation,
+            @ShellBackAnimation.CustomizeActivity @Nullable
+                    ShellBackAnimation customizeActivityAnimation,
+            @ShellBackAnimation.ReturnToHome @Nullable
+                    ShellBackAnimation defaultBackToHomeAnimation) {
+        if (crossActivityAnimation != null) {
+            mAnimationDefinition.set(
+                    BackNavigationInfo.TYPE_CROSS_TASK, crossTaskAnimation.getRunner());
+        }
+        if (crossActivityAnimation != null) {
+            mAnimationDefinition.set(
+                    BackNavigationInfo.TYPE_CROSS_ACTIVITY, crossActivityAnimation.getRunner());
+        }
+        if (defaultBackToHomeAnimation != null) {
+            mAnimationDefinition.set(
+                    BackNavigationInfo.TYPE_RETURN_TO_HOME, defaultBackToHomeAnimation.getRunner());
+        }
+
+        mDefaultCrossActivityAnimation = crossActivityAnimation;
+        mCustomizeActivityAnimation = customizeActivityAnimation;
+
+        // TODO(b/236760237): register dialog close animation when it's completed.
+    }
+
+    void registerAnimation(
+            @BackNavigationInfo.BackTargetType int type, @NonNull BackAnimationRunner runner) {
+        mAnimationDefinition.set(type, runner);
+    }
+
+    void unregisterAnimation(@BackNavigationInfo.BackTargetType int type) {
+        mAnimationDefinition.remove(type);
+    }
+
+    /**
+     * Start the {@link BackAnimationRunner} associated with a back target type.
+     *
+     * @param type back target type
+     * @return true if the animation is started, false if animation is not found for that type.
+     */
+    boolean startGesture(@BackNavigationInfo.BackTargetType int type) {
+        BackAnimationRunner runner = mAnimationDefinition.get(type);
+        if (runner == null) {
+            return false;
+        }
+        runner.startGesture();
+        return true;
+    }
+
+    /**
+     * Cancel the {@link BackAnimationRunner} associated with a back target type.
+     *
+     * @param type back target type
+     * @return true if the animation is started, false if animation is not found for that type.
+     */
+    boolean cancel(@BackNavigationInfo.BackTargetType int type) {
+        BackAnimationRunner runner = mAnimationDefinition.get(type);
+        if (runner == null) {
+            return false;
+        }
+        runner.cancelAnimation();
+        return true;
+    }
+
+    boolean isAnimationCancelledOrNull(@BackNavigationInfo.BackTargetType int type) {
+        BackAnimationRunner runner = mAnimationDefinition.get(type);
+        if (runner == null) {
+            return true;
+        }
+        return runner.isAnimationCancelled();
+    }
+
+    boolean isWaitingAnimation(@BackNavigationInfo.BackTargetType int type) {
+        BackAnimationRunner runner = mAnimationDefinition.get(type);
+        if (runner == null) {
+            return false;
+        }
+        return runner.isWaitingAnimation();
+    }
+
+    void resetDefaultCrossActivity() {
+        if (mDefaultCrossActivityAnimation == null
+                || !mAnimationDefinition.contains(BackNavigationInfo.TYPE_CROSS_ACTIVITY)) {
+            return;
+        }
+        mAnimationDefinition.set(
+                BackNavigationInfo.TYPE_CROSS_ACTIVITY, mDefaultCrossActivityAnimation.getRunner());
+    }
+
+    BackAnimationRunner getAnimationRunnerAndInit(BackNavigationInfo backNavigationInfo) {
+        int type = backNavigationInfo.getType();
+        // Initiate customized cross-activity animation, or fall back to cross activity animation
+        if (type == BackNavigationInfo.TYPE_CROSS_ACTIVITY && mAnimationDefinition.contains(type)) {
+            if (mCustomizeActivityAnimation != null
+                    && mCustomizeActivityAnimation.prepareNextAnimation(
+                            backNavigationInfo.getCustomAnimationInfo())) {
+                mAnimationDefinition.get(type).resetWaitingAnimation();
+                mAnimationDefinition.set(
+                        BackNavigationInfo.TYPE_CROSS_ACTIVITY,
+                        mCustomizeActivityAnimation.getRunner());
+            }
+        }
+        BackAnimationRunner runner = mAnimationDefinition.get(type);
+        if (runner == null) {
+            Log.e(
+                    TAG,
+                    "Animation didn't be defined for type "
+                            + BackNavigationInfo.typeToString(type));
+        }
+        return runner;
+    }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java
index 9facbd5..b52a118 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/TvWMShellModule.java
@@ -49,11 +49,11 @@
 import java.util.Optional;
 
 /**
- * Provides dependencies from {@link com.android.wm.shell}, these dependencies are only
- * accessible from components within the WM subcomponent (can be explicitly exposed to the
- * SysUIComponent, see {@link WMComponent}).
+ * Provides dependencies from {@link com.android.wm.shell}, these dependencies are only accessible
+ * from components within the WM subcomponent (can be explicitly exposed to the SysUIComponent, see
+ * {@link com.android.systemui.dagger.WMComponent}).
  *
- * This module only defines Shell dependencies for the TV SystemUI implementation.  Common
+ * <p>This module only defines Shell dependencies for the TV SystemUI implementation. Common
  * dependencies should go into {@link WMShellBaseModule}.
  */
 @Module(includes = {TvPipModule.class})
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
index 422e3b0..430fa95 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java
@@ -36,6 +36,7 @@
 import com.android.wm.shell.back.BackAnimation;
 import com.android.wm.shell.back.BackAnimationBackground;
 import com.android.wm.shell.back.BackAnimationController;
+import com.android.wm.shell.back.ShellBackAnimationRegistry;
 import com.android.wm.shell.bubbles.BubbleController;
 import com.android.wm.shell.bubbles.Bubbles;
 import com.android.wm.shell.common.DevicePostureController;
@@ -107,9 +108,9 @@
 /**
  * Provides basic dependencies from {@link com.android.wm.shell}, these dependencies are only
  * accessible from components within the WM subcomponent (can be explicitly exposed to the
- * SysUIComponent, see {@link WMComponent}).
+ * SysUIComponent, see {@link com.android.systemui.dagger.WMComponent}).
  *
- * This module only defines *common* dependencies across various SystemUI implementations,
+ * <p>This module only defines *common* dependencies across various SystemUI implementations,
  * dependencies that are device/form factor SystemUI implementation specific should go into their
  * respective modules (ie. {@link WMShellModule} for handheld, {@link TvWMShellModule} for tv, etc.)
  */
@@ -303,16 +304,25 @@
             ShellController shellController,
             @ShellMainThread ShellExecutor shellExecutor,
             @ShellBackgroundThread Handler backgroundHandler,
-            BackAnimationBackground backAnimationBackground
-    ) {
+            BackAnimationBackground backAnimationBackground,
+            Optional<ShellBackAnimationRegistry> shellBackAnimationRegistry) {
         if (BackAnimationController.IS_ENABLED) {
-            return Optional.of(
-                    new BackAnimationController(shellInit, shellController, shellExecutor,
-                            backgroundHandler, context, backAnimationBackground));
+            return shellBackAnimationRegistry.map(
+                    (animations) ->
+                            new BackAnimationController(
+                                    shellInit,
+                                    shellController,
+                                    shellExecutor,
+                                    backgroundHandler,
+                                    context,
+                                    backAnimationBackground,
+                                    animations));
         }
         return Optional.empty();
     }
 
+    @BindsOptionalOf
+    abstract ShellBackAnimationRegistry optionalBackAnimationRegistry();
 
     //
     // Bubbles (optional feature)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index 881c8f5..422bad5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -52,6 +52,7 @@
 import com.android.wm.shell.common.annotations.ShellAnimationThread;
 import com.android.wm.shell.common.annotations.ShellBackgroundThread;
 import com.android.wm.shell.common.annotations.ShellMainThread;
+import com.android.wm.shell.dagger.back.ShellBackAnimationModule;
 import com.android.wm.shell.dagger.pip.PipModule;
 import com.android.wm.shell.desktopmode.DesktopModeController;
 import com.android.wm.shell.desktopmode.DesktopModeStatus;
@@ -100,17 +101,19 @@
 import java.util.Optional;
 
 /**
- * Provides dependencies from {@link com.android.wm.shell}, these dependencies are only
- * accessible from components within the WM subcomponent (can be explicitly exposed to the
- * SysUIComponent, see {@link WMComponent}).
+ * Provides dependencies from {@link com.android.wm.shell}, these dependencies are only accessible
+ * from components within the WM subcomponent (can be explicitly exposed to the SysUIComponent, see
+ * {@link WMComponent}).
  *
- * This module only defines Shell dependencies for handheld SystemUI implementation.  Common
+ * <p>This module only defines Shell dependencies for handheld SystemUI implementation. Common
  * dependencies should go into {@link WMShellBaseModule}.
  */
-@Module(includes = {
-        WMShellBaseModule.class,
-        PipModule.class
-})
+@Module(
+        includes = {
+            WMShellBaseModule.class,
+            PipModule.class,
+            ShellBackAnimationModule.class,
+        })
 public abstract class WMShellModule {
 
     //
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/back/ShellBackAnimationModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/back/ShellBackAnimationModule.java
new file mode 100644
index 0000000..b34c6b2
--- /dev/null
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/back/ShellBackAnimationModule.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.wm.shell.dagger.back;
+
+import com.android.wm.shell.back.CrossActivityAnimation;
+import com.android.wm.shell.back.CrossTaskBackAnimation;
+import com.android.wm.shell.back.CustomizeActivityAnimation;
+import com.android.wm.shell.back.ShellBackAnimation;
+import com.android.wm.shell.back.ShellBackAnimationRegistry;
+
+import dagger.Binds;
+import dagger.Module;
+import dagger.Provides;
+
+/** Default animation definitions for predictive back. */
+@Module
+public interface ShellBackAnimationModule {
+    /** Default animation registry */
+    @Provides
+    static ShellBackAnimationRegistry provideBackAnimationRegistry(
+            @ShellBackAnimation.CrossActivity ShellBackAnimation crossActivity,
+            @ShellBackAnimation.CrossTask ShellBackAnimation crossTask,
+            @ShellBackAnimation.CustomizeActivity ShellBackAnimation customizeActivity) {
+        return new ShellBackAnimationRegistry(
+                crossActivity,
+                crossTask,
+                customizeActivity,
+                /* defaultBackToHomeAnimation= */ null);
+    }
+
+    /** Default cross activity back animation */
+    @Binds
+    @ShellBackAnimation.CrossActivity
+    ShellBackAnimation bindCrossActivityShellBackAnimation(
+            CrossActivityAnimation crossActivityAnimation);
+
+    /** Default cross task back animation */
+    @Binds
+    @ShellBackAnimation.CrossTask
+    ShellBackAnimation provideCrossTaskShellBackAnimation(
+            CrossTaskBackAnimation crossTaskBackAnimation);
+
+    /** Default customized activity back animation */
+    @Binds
+    @ShellBackAnimation.CustomizeActivity
+    ShellBackAnimation provideCustomizeActivityShellBackAnimation(
+            CustomizeActivityAnimation customizeActivityAnimation);
+}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
index 3d8bd38..e7d0f60 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackAnimationControllerTest.java
@@ -67,6 +67,7 @@
 import com.android.wm.shell.sysui.ShellInit;
 import com.android.wm.shell.sysui.ShellSharedConstants;
 
+
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -85,12 +86,11 @@
 
     private static final String ANIMATION_ENABLED = "1";
     private final TestShellExecutor mShellExecutor = new TestShellExecutor();
-    private ShellInit mShellInit;
-
     @Rule
     public TestableContext mContext =
             new TestableContext(InstrumentationRegistry.getInstrumentation().getContext());
 
+    private ShellInit mShellInit;
     @Mock
     private IActivityTaskManager mActivityTaskManager;
 
@@ -116,6 +116,8 @@
     private TestableContentResolver mContentResolver;
     private TestableLooper mTestableLooper;
 
+    private ShellBackAnimationRegistry mShellBackAnimationRegistry;
+
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
@@ -126,11 +128,23 @@
                 ANIMATION_ENABLED);
         mTestableLooper = TestableLooper.get(this);
         mShellInit = spy(new ShellInit(mShellExecutor));
-        mController = new BackAnimationController(mShellInit, mShellController,
-                mShellExecutor, new Handler(mTestableLooper.getLooper()),
-                mActivityTaskManager, mContext,
-                mContentResolver, mAnimationBackground);
-        mController.setEnableUAnimation(true);
+        mShellBackAnimationRegistry =
+                new ShellBackAnimationRegistry(
+                        new CrossActivityAnimation(mContext, mAnimationBackground),
+                        new CrossTaskBackAnimation(mContext, mAnimationBackground),
+                        new CustomizeActivityAnimation(mContext, mAnimationBackground),
+                        null);
+        mController =
+                new BackAnimationController(
+                        mShellInit,
+                        mShellController,
+                        mShellExecutor,
+                        new Handler(mTestableLooper.getLooper()),
+                        mActivityTaskManager,
+                        mContext,
+                        mContentResolver,
+                        mAnimationBackground,
+                        mShellBackAnimationRegistry);
         mShellInit.init();
         mShellExecutor.flushAll();
     }
@@ -138,12 +152,13 @@
     private void createNavigationInfo(int backType,
             boolean enableAnimation,
             boolean isAnimationCallback) {
-        BackNavigationInfo.Builder builder = new BackNavigationInfo.Builder()
-                .setType(backType)
-                .setOnBackNavigationDone(new RemoteCallback((bundle) -> {}))
-                .setOnBackInvokedCallback(mAppCallback)
-                .setPrepareRemoteAnimation(enableAnimation)
-                .setAnimationCallback(isAnimationCallback);
+        BackNavigationInfo.Builder builder =
+                new BackNavigationInfo.Builder()
+                        .setType(backType)
+                        .setOnBackNavigationDone(new RemoteCallback((bundle) -> {}))
+                        .setOnBackInvokedCallback(mAppCallback)
+                        .setPrepareRemoteAnimation(enableAnimation)
+                        .setAnimationCallback(isAnimationCallback);
 
         createNavigationInfo(builder);
     }
@@ -188,18 +203,21 @@
 
     @Test
     public void verifyNavigationFinishes() throws RemoteException {
-        final int[] testTypes = new int[] {BackNavigationInfo.TYPE_RETURN_TO_HOME,
-                BackNavigationInfo.TYPE_CROSS_TASK,
-                BackNavigationInfo.TYPE_CROSS_ACTIVITY,
-                BackNavigationInfo.TYPE_DIALOG_CLOSE,
-                BackNavigationInfo.TYPE_CALLBACK };
+        final int[] testTypes =
+                new int[] {
+                    BackNavigationInfo.TYPE_RETURN_TO_HOME,
+                    BackNavigationInfo.TYPE_CROSS_TASK,
+                    BackNavigationInfo.TYPE_CROSS_ACTIVITY,
+                    BackNavigationInfo.TYPE_DIALOG_CLOSE,
+                    BackNavigationInfo.TYPE_CALLBACK
+                };
 
-        for (int type: testTypes) {
+        for (int type : testTypes) {
             registerAnimation(type);
         }
 
-        for (int type: testTypes) {
-            final ResultListener result  = new ResultListener();
+        for (int type : testTypes) {
+            final ResultListener result = new ResultListener();
             createNavigationInfo(new BackNavigationInfo.Builder()
                     .setType(type)
                     .setOnBackInvokedCallback(mAppCallback)
@@ -275,10 +293,17 @@
         // Toggle the setting off
         Settings.Global.putString(mContentResolver, Settings.Global.ENABLE_BACK_ANIMATION, "0");
         ShellInit shellInit = new ShellInit(mShellExecutor);
-        mController = new BackAnimationController(shellInit, mShellController,
-                mShellExecutor, new Handler(mTestableLooper.getLooper()),
-                mActivityTaskManager, mContext,
-                mContentResolver, mAnimationBackground);
+        mController =
+                new BackAnimationController(
+                        shellInit,
+                        mShellController,
+                        mShellExecutor,
+                        new Handler(mTestableLooper.getLooper()),
+                        mActivityTaskManager,
+                        mContext,
+                        mContentResolver,
+                        mAnimationBackground,
+                        mShellBackAnimationRegistry);
         shellInit.init();
         registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME);
 
@@ -398,17 +423,19 @@
 
     @Test
     public void animationNotDefined() throws RemoteException {
-        final int[] testTypes = new int[] {
-                BackNavigationInfo.TYPE_RETURN_TO_HOME,
-                BackNavigationInfo.TYPE_CROSS_TASK,
-                BackNavigationInfo.TYPE_CROSS_ACTIVITY,
-                BackNavigationInfo.TYPE_DIALOG_CLOSE};
+        final int[] testTypes =
+                new int[] {
+                    BackNavigationInfo.TYPE_RETURN_TO_HOME,
+                    BackNavigationInfo.TYPE_CROSS_TASK,
+                    BackNavigationInfo.TYPE_CROSS_ACTIVITY,
+                    BackNavigationInfo.TYPE_DIALOG_CLOSE
+                };
 
-        for (int type: testTypes) {
+        for (int type : testTypes) {
             unregisterAnimation(type);
         }
 
-        for (int type: testTypes) {
+        for (int type : testTypes) {
             final ResultListener result = new ResultListener();
             createNavigationInfo(new BackNavigationInfo.Builder()
                     .setType(type)
@@ -468,16 +495,14 @@
     public void testBackToActivity() throws RemoteException {
         final CrossActivityAnimation animation = new CrossActivityAnimation(mContext,
                 mAnimationBackground);
-        verifySystemBackBehavior(
-                BackNavigationInfo.TYPE_CROSS_ACTIVITY, animation.mBackAnimationRunner);
+        verifySystemBackBehavior(BackNavigationInfo.TYPE_CROSS_ACTIVITY, animation.getRunner());
     }
 
     @Test
     public void testBackToTask() throws RemoteException {
         final CrossTaskBackAnimation animation = new CrossTaskBackAnimation(mContext,
                 mAnimationBackground);
-        verifySystemBackBehavior(
-                BackNavigationInfo.TYPE_CROSS_TASK, animation.mBackAnimationRunner);
+        verifySystemBackBehavior(BackNavigationInfo.TYPE_CROSS_TASK, animation.getRunner());
     }
 
     private void verifySystemBackBehavior(int type, BackAnimationRunner animation)
@@ -554,10 +579,12 @@
     private static class ResultListener implements RemoteCallback.OnResultListener {
         boolean mBackNavigationDone = false;
         boolean mTriggerBack = false;
+
         @Override
         public void onResult(@Nullable Bundle result) {
             mBackNavigationDone = true;
             mTriggerBack = result.getBoolean(KEY_TRIGGER_BACK);
         }
-    };
+    }
+    ;
 }
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/CustomizeActivityAnimationTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/CustomizeActivityAnimationTest.java
index e7d4598..cebbbd8 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/CustomizeActivityAnimationTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/CustomizeActivityAnimationTest.java
@@ -102,15 +102,17 @@
         // start animation with remote animation targets
         final CountDownLatch finishCalled = new CountDownLatch(1);
         final Runnable finishCallback = finishCalled::countDown;
-        mCustomizeActivityAnimation.mBackAnimationRunner.startAnimation(
-                new RemoteAnimationTarget[]{close, open}, null, null, finishCallback);
+        mCustomizeActivityAnimation
+                .getRunner()
+                .startAnimation(
+                        new RemoteAnimationTarget[] {close, open}, null, null, finishCallback);
         verify(mMockCloseAnimation).initialize(eq(BOUND_SIZE), eq(BOUND_SIZE),
                 eq(BOUND_SIZE), eq(BOUND_SIZE));
         verify(mMockOpenAnimation).initialize(eq(BOUND_SIZE), eq(BOUND_SIZE),
                 eq(BOUND_SIZE), eq(BOUND_SIZE));
 
         try {
-            mCustomizeActivityAnimation.mBackAnimationRunner.getCallback().onBackInvoked();
+            mCustomizeActivityAnimation.getRunner().getCallback().onBackInvoked();
         } catch (RemoteException r) {
             fail("onBackInvoked throw remote exception");
         }
@@ -133,15 +135,17 @@
         // start animation with remote animation targets
         final CountDownLatch finishCalled = new CountDownLatch(1);
         final Runnable finishCallback = finishCalled::countDown;
-        mCustomizeActivityAnimation.mBackAnimationRunner.startAnimation(
-                new RemoteAnimationTarget[]{close, open}, null, null, finishCallback);
+        mCustomizeActivityAnimation
+                .getRunner()
+                .startAnimation(
+                        new RemoteAnimationTarget[] {close, open}, null, null, finishCallback);
         verify(mMockCloseAnimation).initialize(eq(BOUND_SIZE), eq(BOUND_SIZE),
                 eq(BOUND_SIZE), eq(BOUND_SIZE));
         verify(mMockOpenAnimation).initialize(eq(BOUND_SIZE), eq(BOUND_SIZE),
                 eq(BOUND_SIZE), eq(BOUND_SIZE));
 
         try {
-            mCustomizeActivityAnimation.mBackAnimationRunner.getCallback().onBackCancelled();
+            mCustomizeActivityAnimation.getRunner().getCallback().onBackCancelled();
         } catch (RemoteException r) {
             fail("onBackCancelled throw remote exception");
         }
@@ -155,11 +159,12 @@
         // start animation without any remote animation targets
         final CountDownLatch finishCalled = new CountDownLatch(1);
         final Runnable finishCallback = finishCalled::countDown;
-        mCustomizeActivityAnimation.mBackAnimationRunner.startAnimation(
-                new RemoteAnimationTarget[]{}, null, null, finishCallback);
+        mCustomizeActivityAnimation
+                .getRunner()
+                .startAnimation(new RemoteAnimationTarget[] {}, null, null, finishCallback);
 
         try {
-            mCustomizeActivityAnimation.mBackAnimationRunner.getCallback().onBackInvoked();
+            mCustomizeActivityAnimation.getRunner().getCallback().onBackInvoked();
         } catch (RemoteException r) {
             fail("onBackInvoked throw remote exception");
         }