Set custom task transition spec when taskbar is visible

This is to ensure that the task to task animations look good when the
taskbar is visible (the transition background is the same as the taskbar
color, the taskbar overlay rounded corners are hidden, and the task
animates above the taskbar so it's rounded corners are visible during
the animation and not hidden behind the taskbar).

Test: Open tasks from other tasks to trigger task to task animations and
see if they look good
Bug: 200675009
Bug: 196387647

Change-Id: I8e46718829c0e6541a5c1b1a3a156285aeecd30a
diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
index f206252..648a16e 100644
--- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
@@ -21,14 +21,20 @@
 import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_STASHED_LAUNCHER_STATE;
 import static com.android.launcher3.taskbar.TaskbarStashController.TASKBAR_STASH_DURATION;
 import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME;
+import static com.android.systemui.shared.system.WindowManagerWrapper.ITYPE_EXTRA_NAVIGATION_BAR;
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
+import android.annotation.ColorInt;
 import android.graphics.Rect;
+import android.os.RemoteException;
+import android.util.Log;
 import android.view.MotionEvent;
+import android.view.TaskTransitionSpec;
 import android.view.View;
+import android.view.WindowManagerGlobal;
 
 import androidx.annotation.NonNull;
 
@@ -36,6 +42,7 @@
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.QuickstepTransitionManager;
+import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.anim.AnimatorListeners;
 import com.android.launcher3.anim.PendingAnimation;
@@ -56,6 +63,7 @@
 import com.android.systemui.shared.recents.model.ThumbnailData;
 
 import java.util.Arrays;
+import java.util.Set;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
@@ -64,6 +72,8 @@
  */
 public class LauncherTaskbarUIController extends TaskbarUIController {
 
+    private static final String TAG = "TaskbarUIController";
+
     private final BaseQuickstepLauncher mLauncher;
 
     private final AnimatedFloat mIconAlignmentForResumedState =
@@ -193,6 +203,7 @@
         mLauncher.getHotseat().setIconsAlpha(1f);
         mLauncher.setTaskbarUIController(null);
         mLauncher.removeOnDeviceProfileChangeListener(mProfileChangeListener);
+        updateTaskTransitionSpec(true);
     }
 
     @Override
@@ -367,6 +378,32 @@
     private void onStashedInAppChanged(DeviceProfile deviceProfile) {
         boolean taskbarStashedInApps = mControllers.taskbarStashController.isStashedInApp();
         deviceProfile.isTaskbarPresentInApps = !taskbarStashedInApps;
+        updateTaskTransitionSpec(taskbarStashedInApps);
+    }
+
+    private void updateTaskTransitionSpec(boolean taskbarIsHidden) {
+        try {
+            if (taskbarIsHidden) {
+                // Clear custom task transition settings when the taskbar is stashed
+                WindowManagerGlobal.getWindowManagerService().clearTaskTransitionSpec();
+            } else {
+                // Adjust task transition spec to account for taskbar being visible
+                @ColorInt int taskAnimationBackgroundColor =
+                        mLauncher.getColor(R.color.taskbar_background);
+
+                TaskTransitionSpec customTaskAnimationSpec = new TaskTransitionSpec(
+                        taskAnimationBackgroundColor,
+                        Set.of(ITYPE_EXTRA_NAVIGATION_BAR)
+                );
+                WindowManagerGlobal.getWindowManagerService()
+                        .setTaskTransitionSpec(customTaskAnimationSpec);
+            }
+        } catch (RemoteException e) {
+            // This shouldn't happen but if it does task animations won't look good until the
+            // taskbar stashing state is changed.
+            Log.e(TAG, "Failed to update task transition spec to account for new taskbar state",
+                    e);
+        }
     }
 
     /**