Made the taskbar touchable during animation to home.

Enabled taskbar touch processing while animating to home. Also excluded
quick search bar from touch region, so it is not interactable during the
animation & removed corresponding TODO from TaskbarView.

Fixes: 368419997
Test: Manual. Enable gesture navigation. Open any application. Swipe up
to go to the launcher home screen. Click any taskbar icon - the
corresponding application will open. If clicking on Quick search,
launcher search will be opened. Video:
http://recall/-/gx8ASgewUeUS3QYohfrd1J/g6UWhF9dQZq3QsFyH0EwtK
Perform the same test for buttons navigation mode. Video:
http://recall/-/gx8ASgewUeUS3QYohfrd1J/gvuoSRnQfXQlejewBG1Ex8
Flag: EXEMPT bug fix

Change-Id: I07280bce70dd25d5ab78210302f08c0614309130
diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
index 09dbeb6..61563b9 100644
--- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java
@@ -150,12 +150,6 @@
         }
     }
 
-    @Override
-    protected boolean isTaskbarTouchable() {
-        return !(mTaskbarLauncherStateController.isAnimatingToLauncher()
-                && mTaskbarLauncherStateController.isTaskbarAlignedWithHotseat());
-    }
-
     public void setShouldDelayLauncherStateAnim(boolean shouldDelayLauncherStateAnim) {
         mTaskbarLauncherStateController.setShouldDelayLauncherStateAnim(
                 shouldDelayLauncherStateAnim);
@@ -420,6 +414,16 @@
     }
 
     @Override
+    public boolean isHotseatVisibleForTaskBarAlignment() {
+        return mTaskbarLauncherStateController.isHotseatVisibleForTaskbarAlignment();
+    }
+
+    @Override
+    public boolean isAnimatingToLauncher() {
+        return mTaskbarLauncherStateController.isAnimatingToLauncher();
+    }
+
+    @Override
     protected boolean isInOverviewUi() {
         return mTaskbarLauncherStateController.isInOverviewUi();
     }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
index 685c109..1141a01 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarInsetsController.kt
@@ -47,6 +47,7 @@
 import com.android.internal.policy.GestureNavigationSettingsObserver
 import com.android.launcher3.DeviceProfile
 import com.android.launcher3.R
+import com.android.launcher3.Utilities
 import com.android.launcher3.anim.AlphaUpdateListener
 import com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_NAVBAR_UNIFICATION
 import com.android.launcher3.config.FeatureFlags.enableTaskbarNoRecreate
@@ -82,7 +83,7 @@
             context.mainThreadHandler,
             Executors.UI_HELPER_EXECUTOR.handler,
             context,
-            this::onTaskbarOrBubblebarWindowHeightOrInsetsChanged
+            this::onTaskbarOrBubblebarWindowHeightOrInsetsChanged,
         )
     private val debugTouchableRegion = DebugTouchableRegion()
 
@@ -120,7 +121,7 @@
             if (enableTaskbarNoRecreate() && controllers.sharedState != null) {
                 getProvidedInsets(
                     controllers.sharedState!!.insetsFrameProviders,
-                    insetsRoundedCornerFlag
+                    insetsRoundedCornerFlag,
                 )
             } else {
                 getProvidedInsets(insetsRoundedCornerFlag)
@@ -133,9 +134,6 @@
         }
 
         val bubbleControllers = controllers.bubbleControllers.getOrNull()
-        val taskbarTouchableHeight = taskbarStashController.touchableHeight
-        val bubblesTouchableHeight =
-            bubbleControllers?.bubbleStashController?.getTouchableHeight() ?: 0
         // reset touch bounds
         defaultTouchableRegion.setEmpty()
         if (bubbleControllers != null) {
@@ -147,16 +145,45 @@
                 defaultTouchableRegion.addBoundsToRegion(bubbleBarViewController.bubbleBarBounds)
             }
         }
+        val uiController = controllers.uiController
         if (
-            taskbarStashController.isInApp ||
-                taskbarStashController.isInOverview ||
+            !uiController.isHotseatVisibleForTaskBarAlignment ||
                 DisplayController.showLockedTaskbarOnHome(context)
         ) {
-            // only add the taskbar touch region if not on home
+            // adding the taskbar touch region
+            val touchableHeight: Int
+            var left = 0
+            var right = context.deviceProfile.widthPx
+            var bubbleBarAdjustment = 0
+            if (uiController.isAnimatingToLauncher) {
+                val dp = controllers.taskbarActivityContext.deviceProfile
+                touchableHeight = windowLayoutParams.height
+                if (dp.isQsbInline) {
+                    // if Qsb is inline need to exclude search icon from touch region
+                    val isRtl = Utilities.isRtl(context.resources)
+                    bubbleControllers?.bubbleBarViewController?.let {
+                        if (dp.shouldAdjustHotseatOnBubblesLocationUpdate(context)) {
+                            val isBubblesOnLeft = it.bubbleBarLocation.isOnLeft(isRtl)
+                            bubbleBarAdjustment =
+                                dp.getHotseatTranslationXForBubbleBar(isBubblesOnLeft, isRtl)
+                        }
+                    }
+                    val hotseatPadding: Rect = dp.getHotseatLayoutPadding(context)
+                    val borderSpacing: Int = dp.hotseatBorderSpace
+                    if (isRtl) {
+                        right =
+                            dp.widthPx - hotseatPadding.right + borderSpacing + bubbleBarAdjustment
+                    } else {
+                        left = hotseatPadding.left - borderSpacing + bubbleBarAdjustment
+                    }
+                }
+            } else {
+                // if not animating to launcher use the taskbar touchanle height
+                touchableHeight = taskbarStashController.touchableHeight
+            }
             val bottom = windowLayoutParams.height
-            val top = bottom - taskbarTouchableHeight
-            val right = context.deviceProfile.widthPx
-            defaultTouchableRegion.addBoundsToRegion(Rect(/* left= */ 0, top, right, bottom))
+            val top = bottom - touchableHeight
+            defaultTouchableRegion.addBoundsToRegion(Rect(left, top, right, bottom))
         }
 
         // Pre-calculate insets for different providers across different rotations for this gravity
@@ -181,7 +208,7 @@
      */
     private fun getProvidedInsets(
         providedInsets: Array<InsetsFrameProvider>,
-        insetsRoundedCornerFlag: Int
+        insetsRoundedCornerFlag: Int,
     ): Array<InsetsFrameProvider> {
         val navBarsFlag =
             (if (context.isGestureNav) FLAG_SUPPRESS_SCRIM else 0) or insetsRoundedCornerFlag
@@ -207,14 +234,14 @@
             InsetsFrameProvider(insetsOwner, 0, navigationBars())
                 .setFlags(
                     navBarsFlag,
-                    FLAG_SUPPRESS_SCRIM or FLAG_ANIMATE_RESIZING or FLAG_INSETS_ROUNDED_CORNER
+                    FLAG_SUPPRESS_SCRIM or FLAG_ANIMATE_RESIZING or FLAG_INSETS_ROUNDED_CORNER,
                 ),
             InsetsFrameProvider(insetsOwner, 0, tappableElement()),
             InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures()),
             InsetsFrameProvider(insetsOwner, INDEX_LEFT, systemGestures())
                 .setSource(SOURCE_DISPLAY),
             InsetsFrameProvider(insetsOwner, INDEX_RIGHT, systemGestures())
-                .setSource(SOURCE_DISPLAY)
+                .setSource(SOURCE_DISPLAY),
         )
     }
 
@@ -232,7 +259,7 @@
                 val gestureHeight =
                     ResourceUtils.getNavbarSize(
                         ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE,
-                        context.resources
+                        context.resources,
                     )
                 val isPinnedTaskbar =
                     context.deviceProfile.isTaskbarPresent &&
@@ -272,8 +299,8 @@
                     // override below (insetsSizeOverrides must have the same length and
                     // types after the window is added according to
                     // WindowManagerService#relayoutWindow)
-                    provider.insetsSize
-                )
+                    provider.insetsSize,
+                ),
             )
         // Use 0 tappableElement insets for the VoiceInteractionWindow when gesture nav is enabled.
         val visInsetsSizeForTappableElement =
@@ -284,7 +311,7 @@
                 InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                 InsetsFrameProvider.InsetsSizeOverride(
                     TYPE_VOICE_INTERACTION,
-                    visInsetsSizeForTappableElement
+                    visInsetsSizeForTappableElement,
                 ),
             )
         if (
@@ -368,10 +395,6 @@
             // Let touches pass through us.
             insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
             debugTouchableRegion.lastSetTouchableReason = "Stashed over IME"
-        } else if (!controllers.uiController.isTaskbarTouchable) {
-            // Let touches pass through us.
-            insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
-            debugTouchableRegion.lastSetTouchableReason = "Taskbar is not touchable"
         } else if (controllers.taskbarDragController.isSystemDragInProgress) {
             // Let touches pass through us.
             insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
@@ -427,7 +450,7 @@
         // Always have nav buttons be touchable
         controllers.navbarButtonsViewController.addVisibleButtonsRegion(
             context.dragLayer,
-            insetsInfo.touchableRegion
+            insetsInfo.touchableRegion,
         )
         debugTouchableRegion.lastSetTouchableBounds.set(insetsInfo.touchableRegion.bounds)
         context.excludeFromMagnificationRegion(insetsIsTouchableRegion)
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
index 707d4b3..39aef28 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java
@@ -192,6 +192,8 @@
 
     private boolean mIsQsbInline;
 
+    private boolean mIsHotseatVisibleForTaskbarAlignment;
+
     private final DeviceProfile.OnDeviceProfileChangeListener mOnDeviceProfileChangeListener =
             new DeviceProfile.OnDeviceProfileChangeListener() {
                 @Override
@@ -738,6 +740,7 @@
             boolean committed) {
         boolean isInStashedState = mLauncherState.isTaskbarStashed(mLauncher);
         TaskbarStashController stashController = mControllers.taskbarStashController;
+        TaskbarInsetsController insetsController = mControllers.taskbarInsetsController;
         stashController.updateStateForFlag(FLAG_IN_STASHED_LAUNCHER_STATE, isInStashedState);
         Animator stashAnimator = stashController.createApplyStateAnimator(duration);
         if (stashAnimator != null) {
@@ -746,7 +749,11 @@
                 public void onAnimationEnd(Animator animation) {
                     if (isInStashedState && committed) {
                         // Reset hotseat alpha to default
-                        mLauncher.getHotseat().setIconsAlpha(1, ALPHA_CHANNEL_TASKBAR_ALIGNMENT);
+                        updateIconAlphaForHome(
+                                /* taskbarAlpha = */ 0,
+                                ALPHA_CHANNEL_TASKBAR_ALIGNMENT,
+                                /* updateTaskbarAlpha = */ false
+                        );
                     }
                 }
 
@@ -871,6 +878,14 @@
         if (mIsQsbInline) {
             mLauncher.getHotseat().setQsbAlpha(targetAlpha, alphaChannel);
         }
+        if (alphaChannel == ALPHA_CHANNEL_TASKBAR_ALIGNMENT) {
+            boolean isHotseatVisibleForTaskbarAlignment = isHotseatVisibleForTaskbarAlignment();
+            if (mIsHotseatVisibleForTaskbarAlignment != isHotseatVisibleForTaskbarAlignment) {
+                mIsHotseatVisibleForTaskbarAlignment = isHotseatVisibleForTaskbarAlignment;
+                mControllers.taskbarInsetsController
+                        .onTaskbarOrBubblebarWindowHeightOrInsetsChanged();
+            }
+        }
     }
 
     /** Updates launcher home screen appearance accordingly to the bubble bar location. */
@@ -932,6 +947,13 @@
         translationXAnimation.start();
     }
 
+    /** Returns true if hotseat icons visible for the taskbar alignment */
+    public boolean isHotseatVisibleForTaskbarAlignment() {
+        return mLauncher.getHotseat()
+                .getIconsAlpha(ALPHA_CHANNEL_TASKBAR_ALIGNMENT).getValue() == 1;
+    }
+
+
     private final class TaskBarRecentsAnimationListener implements
             RecentsAnimationCallbacks.RecentsAnimationListener {
         private final RecentsAnimationCallbacks mCallbacks;
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java
index b80aaf8..5c51fda 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java
@@ -75,8 +75,14 @@
         mControllers = null;
     }
 
-    protected boolean isTaskbarTouchable() {
-        return true;
+    /** Returns true if transition animation to launcher home is being played. */
+    public boolean isAnimatingToLauncher() {
+        return false;
+    }
+
+    /** Returns true if hotseat icons visible for the taskbar alignment. */
+    public boolean isHotseatVisibleForTaskBarAlignment() {
+        return false;
     }
 
     /**
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java
index ec94160..435ee5b 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java
@@ -185,7 +185,6 @@
                     resources.getDrawable(R.drawable.taskbar_overflow_icon));
             mTaskbarOverflowView.setPadding(mItemPadding, mItemPadding, mItemPadding, mItemPadding);
         }
-        // TODO: Disable touch events on QSB otherwise it can crash.
         mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false);
 
         mMaxNumIcons = calculateMaxNumIcons();