From d248ee750710c030af7e1f686bd674094789ef5a Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Mon, 23 Jan 2023 22:06:19 -0800 Subject: [PATCH] [Gesture Library Integration] Update the check for motion events on trackpad The gesture library is ported and enabled, thus we are updating our check for motion events on trackpad. Bug: 254783214 Test: Swipe up and hold to go to overview; swipe up to go home Change-Id: I4b74e88c7f8b6ef86c779391b0f8064ea828ed8f --- .../StatusBarTouchController.java | 7 +-- .../android/quickstep/AbsSwipeUpHandler.java | 4 +- .../android/quickstep/MotionEventsUtils.java | 48 +++++++++++++++++++ .../quickstep/RotationTouchHelper.java | 10 ++-- .../quickstep/TouchInteractionService.java | 18 +++++-- .../TaskbarStashInputConsumer.java | 2 +- src/com/android/launcher3/Utilities.java | 10 ---- 7 files changed, 72 insertions(+), 27 deletions(-) create mode 100644 quickstep/src/com/android/quickstep/MotionEventsUtils.java diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java index af63a071eb..7de6b189a9 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/StatusBarTouchController.java @@ -21,8 +21,8 @@ import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_UP; import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY; -import static com.android.launcher3.Utilities.isTrackpadMotionEvent; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN; +import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent; import android.graphics.PointF; import android.util.SparseArray; @@ -91,10 +91,11 @@ public class StatusBarTouchController implements TouchController { if (!mCanIntercept) { return false; } + mDownEvents.clear(); mDownEvents.put(pid, new PointF(ev.getX(), ev.getY())); } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { - // Check!! should only set it only when threshold is not entered. - mDownEvents.put(pid, new PointF(ev.getX(idx), ev.getY(idx))); + // Check!! should only set it only when threshold is not entered. + mDownEvents.put(pid, new PointF(ev.getX(idx), ev.getY(idx))); } if (!mCanIntercept) { return false; diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 752e748a45..933fb49371 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -369,7 +369,7 @@ public abstract class AbsSwipeUpHandler, mIsTaskbarAllAppsOpen = controller != null && controller.isTaskbarAllAppsOpen(); mTaskbarAppWindowThreshold = res.getDimensionPixelSize(R.dimen.taskbar_app_window_threshold); - boolean swipeWillNotShowTaskbar = mTaskbarAlreadyOpen; + boolean swipeWillNotShowTaskbar = mTaskbarAlreadyOpen || mGestureState.isTrackpadGesture(); mTaskbarHomeOverviewThreshold = swipeWillNotShowTaskbar ? 0 : res.getDimensionPixelSize(R.dimen.taskbar_home_overview_threshold); @@ -2317,7 +2317,7 @@ public abstract class AbsSwipeUpHandler, return displacement; } - if (mTaskbarAlreadyOpen || mIsTaskbarAllAppsOpen) { + if (mTaskbarAlreadyOpen || mIsTaskbarAllAppsOpen || mGestureState.isTrackpadGesture()) { return displacement; } diff --git a/quickstep/src/com/android/quickstep/MotionEventsUtils.java b/quickstep/src/com/android/quickstep/MotionEventsUtils.java new file mode 100644 index 0000000000..142febf829 --- /dev/null +++ b/quickstep/src/com/android/quickstep/MotionEventsUtils.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.quickstep; + +import static android.view.MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE; + +import static com.android.launcher3.config.FeatureFlags.ENABLE_TRACKPAD_GESTURE; + +import android.annotation.TargetApi; +import android.os.Build; +import android.view.MotionEvent; + +/** Handles motion events from trackpad. */ +public class MotionEventsUtils { + + /** {@link MotionEvent#CLASSIFICATION_MULTI_FINGER_SWIPE} is hidden. */ + public static final int CLASSIFICATION_MULTI_FINGER_SWIPE = 4; + + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + public static boolean isTrackpadScroll(MotionEvent event) { + return ENABLE_TRACKPAD_GESTURE.get() + && event.getClassification() == CLASSIFICATION_TWO_FINGER_SWIPE; + } + + @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + public static boolean isTrackpadMultiFingerSwipe(MotionEvent event) { + return ENABLE_TRACKPAD_GESTURE.get() + && event.getClassification() == CLASSIFICATION_MULTI_FINGER_SWIPE; + } + + public static boolean isTrackpadMotionEvent(MotionEvent event) { + return isTrackpadScroll(event) || isTrackpadMultiFingerSwipe(event); + } +} diff --git a/quickstep/src/com/android/quickstep/RotationTouchHelper.java b/quickstep/src/com/android/quickstep/RotationTouchHelper.java index b9390b854b..7500e79118 100644 --- a/quickstep/src/com/android/quickstep/RotationTouchHelper.java +++ b/quickstep/src/com/android/quickstep/RotationTouchHelper.java @@ -18,7 +18,6 @@ package com.android.quickstep; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Surface.ROTATION_0; -import static com.android.launcher3.Utilities.isTrackpadMotionEvent; import static com.android.launcher3.util.DisplayController.CHANGE_ACTIVE_SCREEN; import static com.android.launcher3.util.DisplayController.CHANGE_ALL; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; @@ -26,6 +25,8 @@ import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION; import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.launcher3.util.NavigationMode.THREE_BUTTONS; +import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent; +import static com.android.quickstep.MotionEventsUtils.isTrackpadMultiFingerSwipe; import android.content.Context; import android.content.res.Resources; @@ -233,10 +234,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { * @return whether the coordinates of the {@param event} is in the swipe up gesture region. */ public boolean isInSwipeUpTouchRegion(MotionEvent event, BaseActivityInterface activity) { - if (isTrackpadMotionEvent(event)) { - return !activity.isResumed(); - } - return mOrientationTouchTransformer.touchInValidSwipeRegions(event.getX(), event.getY()); + return isInSwipeUpTouchRegion(event, 0, activity); } /** @@ -246,7 +244,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener { public boolean isInSwipeUpTouchRegion(MotionEvent event, int pointerIndex, BaseActivityInterface activity) { if (isTrackpadMotionEvent(event)) { - return !activity.isResumed(); + return isTrackpadMultiFingerSwipe(event) && !activity.isResumed(); } return mOrientationTouchTransformer.touchInValidSwipeRegions(event.getX(pointerIndex), event.getY(pointerIndex)); diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java index d44a5b87ad..f4c95a1651 100644 --- a/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -18,12 +18,14 @@ package com.android.quickstep; import static android.accessibilityservice.AccessibilityService.GLOBAL_ACTION_ACCESSIBILITY_ALL_APPS; import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_DOWN; +import static android.view.MotionEvent.ACTION_POINTER_DOWN; +import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; -import static com.android.launcher3.Utilities.isTrackpadMotionEvent; import static com.android.launcher3.config.FeatureFlags.ASSISTANT_GIVES_LAUNCHER_FOCUS; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.quickstep.GestureState.DEFAULT_STATE; +import static com.android.quickstep.MotionEventsUtils.isTrackpadMultiFingerSwipe; import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.FLAG_USING_OTHER_ACTIVITY_INPUT_CONSUMER; import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_DOWN; import static com.android.quickstep.util.ActiveGestureErrorDetector.GestureEvent.MOTION_UP; @@ -622,7 +624,7 @@ public class TouchInteractionService extends Service Object traceToken = TraceHelper.INSTANCE.beginFlagsOverride( TraceHelper.FLAG_ALLOW_BINDER_TRACKING); - final int action = event.getAction(); + final int action = event.getActionMasked(); if (action == ACTION_DOWN) { mRotationTouchHelper.setOrientationTransformIfNeeded(event); @@ -633,7 +635,7 @@ public class TouchInteractionService extends Service // onConsumerInactive and wipe the previous gesture state GestureState prevGestureState = new GestureState(mGestureState); GestureState newGestureState = createGestureState(mGestureState, - isTrackpadMotionEvent(event)); + isTrackpadMultiFingerSwipe(event)); newGestureState.setSwipeUpStartTimeMs(SystemClock.uptimeMillis()); mConsumer.onConsumerAboutToBeSwitched(); mGestureState = newGestureState; @@ -641,7 +643,8 @@ public class TouchInteractionService extends Service mUncheckedConsumer = mConsumer; } else if (mDeviceState.isUserUnlocked() && mDeviceState.isFullyGesturalNavMode() && mDeviceState.canTriggerAssistantAction(event)) { - mGestureState = createGestureState(mGestureState, isTrackpadMotionEvent(event)); + mGestureState = createGestureState(mGestureState, + isTrackpadMultiFingerSwipe(event)); // Do not change mConsumer as if there is an ongoing QuickSwitch gesture, we // should not interrupt it. QuickSwitch assumes that interruption can only // happen if the next gesture is also quick switch. @@ -688,7 +691,12 @@ public class TouchInteractionService extends Service if (cancelGesture) { event.setAction(ACTION_CANCEL); } - mUncheckedConsumer.onMotionEvent(event); + + // Skip ACTION_POINTER_DOWN and ACTION_POINTER_UP events from trackpad. + if (!mGestureState.isTrackpadGesture() || (action != ACTION_POINTER_DOWN + && action != ACTION_POINTER_UP)) { + mUncheckedConsumer.onMotionEvent(event); + } if (cleanUpConsumer) { reset(); diff --git a/quickstep/src/com/android/quickstep/inputconsumers/TaskbarStashInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/TaskbarStashInputConsumer.java index 992618a147..8ccbf1e46a 100644 --- a/quickstep/src/com/android/quickstep/inputconsumers/TaskbarStashInputConsumer.java +++ b/quickstep/src/com/android/quickstep/inputconsumers/TaskbarStashInputConsumer.java @@ -17,9 +17,9 @@ package com.android.quickstep.inputconsumers; import static android.view.MotionEvent.INVALID_POINTER_ID; -import static com.android.launcher3.Utilities.isTrackpadMotionEvent; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_TOUCHING; +import static com.android.quickstep.MotionEventsUtils.isTrackpadMotionEvent; import android.content.Context; import android.content.res.Resources; diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 379d1e5432..13efa674f3 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -16,9 +16,6 @@ package com.android.launcher3; -import static android.view.InputDevice.SOURCE_TOUCHSCREEN; - -import static com.android.launcher3.config.FeatureFlags.ENABLE_TRACKPAD_GESTURE; import static com.android.launcher3.icons.BitmapInfo.FLAG_THEMED; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ICON_BADGED; import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT; @@ -725,13 +722,6 @@ public final class Utilities { )); } - public static boolean isTrackpadMotionEvent(MotionEvent event) { - // TODO: ideally should use event.getClassification(), but currently only the move - // events get assigned the correct classification. - return ENABLE_TRACKPAD_GESTURE.get() - && (event.getSource() & SOURCE_TOUCHSCREEN) != SOURCE_TOUCHSCREEN; - } - /** Logs the Scale and Translate properties of a matrix. Ignores skew and perspective. */ public static void logMatrix(String label, Matrix matrix) { float[] matrixValues = new float[9];