From befd6bb1ea29201972ce5b4c9f99759148077cf1 Mon Sep 17 00:00:00 2001 From: Toni Barzic Date: Fri, 18 Oct 2024 23:46:59 +0000 Subject: [PATCH] Prevent tap in swipe up zone from closing KQS Tap down action in swipe up start zone may or may not be start of a navigation gesture - for example, it may be start of a tab on an icon in the task bar. If the user taps on the taskbar overflow button, closing the KQS on tap down produces unintended behavior (KQS is closed on tap down, and reopened on tap up). Additionally, this produces inconsistent behavior in response to app icon taps depending on whether gesture navigation is enabled or not. Instead, close KQS as part of `hideOverlayWindow()`, which gets called when a swipe gesture actually starts (note that KQS is added to the overlay's drag layer). Additionally, make sure that KeyboardQuickSwitchController state is reset if KeyboardQuickSwitchView gets detached from UI due to the taskbar overlay getting hidden (e.g. in response to home button). Without this, in certain situations, KQS may get hidden with the controller thinking the UI is still shown - in case the user releases the Alt + Tab key combination in this state, the shortcut would end up getting handled, and switch to the next task. Bug: 368119679 Test: Press and hold Alt+Tab (while an app is open). After KQS is open, Swipe up to transition to overflow, or home screen - KQS gets hidden. Releasing Alt+Tab is no-op. Test: Press and hold Alt+Tab (while an app is open) with three button navigation enabled. Press home button. KQS gets hidden. Releasting Alt+Tab is no-op. Test: Press and hold Alt+Tab. After KQS is open, open an app from task bar (either transient or persistent), or all apps list. KQS gets closed, Releasing Alt+Tab is no-op. Flag: EXEMPT bugfix Change-Id: I8b561db3c6ec8a9c7de93e330faf8e3e4d3c8f4e --- .../taskbar/KeyboardQuickSwitchView.java | 13 +++++++++++++ .../KeyboardQuickSwitchViewController.java | 15 ++++++++++++++- .../launcher3/taskbar/TaskbarActivityContext.java | 5 +---- .../launcher3/taskbar/TaskbarUIController.java | 2 ++ .../quickstep/TouchInteractionService.java | 3 --- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java index 50a253c6a9..05d34b5cb7 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchView.java @@ -130,6 +130,15 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { super(context, attrs, defStyleAttr, defStyleRes); } + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + + if (mViewCallbacks != null) { + mViewCallbacks.onViewDetchedFromWindow(); + } + } + @Override protected void onFinishInflate() { super.onFinishInflate(); @@ -281,6 +290,10 @@ public class KeyboardQuickSwitchView extends ConstraintLayout { return mDesktopTaskIndex; } + void resetViewCallbacks() { + mViewCallbacks = null; + } + protected Animator getCloseAnimation() { AnimatorSet closeAnimation = new AnimatorSet(); diff --git a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java index a80c11cc17..4f5cd135fd 100644 --- a/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/KeyboardQuickSwitchViewController.java @@ -68,6 +68,8 @@ public class KeyboardQuickSwitchViewController { private boolean mOnDesktop; private boolean mWasDesktopTaskFilteredOut; + private boolean mDetachingFromWindow = false; + protected KeyboardQuickSwitchViewController( @NonNull TaskbarControllers controllers, @NonNull TaskbarOverlayContext overlayContext, @@ -229,7 +231,12 @@ public class KeyboardQuickSwitchViewController { private void onCloseComplete() { mCloseAnimation = null; - mOverlayContext.getDragLayer().removeView(mKeyboardQuickSwitchView); + // Reset the view callbacks to prevent `onDetachedFromWindow` getting called in response to + // the `removeView(mKeyboardQuickSwitchView)` call. + mKeyboardQuickSwitchView.resetViewCallbacks(); + if (!mDetachingFromWindow) { + mOverlayContext.getDragLayer().removeView(mKeyboardQuickSwitchView); + } mControllerCallbacks.onCloseComplete(); InteractionJankMonitorWrapper.end(Cuj.CUJ_LAUNCHER_KEYBOARD_QUICK_SWITCH_CLOSE); } @@ -319,5 +326,11 @@ public class KeyboardQuickSwitchViewController { boolean isAspectRatioSquare() { return mControllerCallbacks.isAspectRatioSquare(); } + + void onViewDetchedFromWindow() { + mDetachingFromWindow = true; + closeQuickSwitchView(false); + mDetachingFromWindow = false; + } } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index f3741b21db..146beed410 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -29,7 +29,6 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_ON_BOARD_POPUP; import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import static com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_OVERLAY_PROXY; import static com.android.launcher3.Flags.enableCursorHoverStates; -import static com.android.launcher3.Flags.taskbarOverflow; import static com.android.launcher3.Utilities.calculateTextHeight; import static com.android.launcher3.Utilities.isRunningInTestHarness; import static com.android.launcher3.config.FeatureFlags.ENABLE_TASKBAR_NAVBAR_UNIFICATION; @@ -1213,9 +1212,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { boolean shouldCloseAllOpenViews = true; Object tag = view.getTag(); - if (taskbarOverflow()) { - mControllers.keyboardQuickSwitchController.closeQuickSwitchView(false); - } + mControllers.keyboardQuickSwitchController.closeQuickSwitchView(false); if (tag instanceof GroupTask groupTask) { handleGroupTaskLaunch( diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java index 7030088287..375e7db6b7 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarUIController.java @@ -126,6 +126,8 @@ public class TaskbarUIController implements BubbleBarController.BubbleBarLocatio * Manually closes the overlay window. */ public void hideOverlayWindow() { + mControllers.keyboardQuickSwitchController.closeQuickSwitchView(); + if (!DisplayController.isTransientTaskbar(mControllers.taskbarActivityContext) || mControllers.taskbarAllAppsController.isOpen()) { mControllers.taskbarOverlayController.hideWindow(); diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index 1481ef2460..01508116f6 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -927,9 +927,6 @@ public class TouchInteractionService extends Service { BubbleControllers bubbleControllers = tac != null ? tac.getBubbleControllers() : null; boolean isOnBubbles = bubbleControllers != null && BubbleBarInputConsumer.isEventOnBubbles(tac, event); - if (isInSwipeUpTouchRegion && tac != null) { - tac.closeKeyboardQuickSwitchView(); - } if (mDeviceState.isButtonNavMode() && mDeviceState.supportsAssistantGestureInButtonNav()) { reasonString.append("in three button mode which supports Assistant gesture");