Disabling fling gesture for assistant over deferred region

Fixing missing trigger when using fling gesture

Bug: 130186141
Bug: 175839420
Test: Verified fling does not work over keyboard dismiss button
Change-Id: Id15320122cf9183c591416962634561a1ddc6fa0
diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
index 49feef0..7bf7712 100644
--- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
+++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
@@ -23,7 +23,6 @@
 import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY;
 import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
 import static com.android.systemui.shared.system.PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED;
-import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED;
 
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
@@ -119,10 +118,6 @@
         updateOverviewTargets();
     }
 
-    public boolean assistantGestureIsConstrained() {
-        return (mDeviceState.getSystemUiStateFlags() & SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED) != 0;
-    }
-
     /**
      * Update overview intent and {@link BaseActivityInterface} based off the current launcher home
      * component.
diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
index d8064a2..fb195f8 100644
--- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
+++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
@@ -24,6 +24,7 @@
 import static com.android.quickstep.SysUINavigationMode.Mode.TWO_BUTTONS;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BUBBLES_EXPANDED;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_GLOBAL_ACTIONS_SHOWING;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
@@ -374,7 +375,7 @@
      * @return the system ui state flags.
      */
     // TODO(141886704): See if we can remove this
-    public @SystemUiStateFlags int getSystemUiStateFlags() {
+    public int getSystemUiStateFlags() {
         return mSystemUiStateFlags;
     }
 
@@ -407,6 +408,13 @@
     }
 
     /**
+     * @return whether assistant gesture is constraint
+     */
+    public boolean isAssistantGestureIsConstrained() {
+        return (mSystemUiStateFlags & SYSUI_STATE_ASSIST_GESTURE_CONSTRAINED) != 0;
+    }
+
+    /**
      * @return whether the bubble stack is expanded
      */
     public boolean isBubblesExpanded() {
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 1e0a00a..e59035c 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -466,7 +466,8 @@
                             this,
                             mGestureState,
                             InputConsumer.NO_OP, mInputMonitorCompat,
-                            mOverviewComponentObserver.assistantGestureIsConstrained());
+                            mDeviceState,
+                            event);
                 } else if (mDeviceState.canTriggerOneHandedAction(event)
                     && !mDeviceState.isOneHandedModeActive()) {
                     // Consume gesture event for triggering one handed feature.
@@ -563,12 +564,8 @@
         }
         if (mDeviceState.isFullyGesturalNavMode()) {
             if (mDeviceState.canTriggerAssistantAction(event, newGestureState.getRunningTask())) {
-                base = new AssistantInputConsumer(
-                    this,
-                    newGestureState,
-                    base,
-                    mInputMonitorCompat,
-                    mOverviewComponentObserver.assistantGestureIsConstrained());
+                base = new AssistantInputConsumer(this, newGestureState, base, mInputMonitorCompat,
+                        mDeviceState, event);
             }
 
             if (FeatureFlags.ENABLE_QUICK_CAPTURE_GESTURE.get()) {
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/AssistantInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/AssistantInputConsumer.java
index 580e4ec..a3cd7df 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/AssistantInputConsumer.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/AssistantInputConsumer.java
@@ -44,9 +44,12 @@
 import com.android.quickstep.BaseActivityInterface;
 import com.android.quickstep.GestureState;
 import com.android.quickstep.InputConsumer;
+import com.android.quickstep.RecentsAnimationDeviceState;
 import com.android.quickstep.SystemUiProxy;
 import com.android.systemui.shared.system.InputMonitorCompat;
 
+import java.util.function.Consumer;
+
 /**
  * Touch consumer for handling events to launch assistant from launcher
  */
@@ -81,19 +84,18 @@
     private final int mAngleThreshold;
     private final float mSquaredSlop;
     private final Context mContext;
-    private final GestureDetector mGestureDetector;
-    private final boolean mIsAssistGestureConstrained;
+    private final Consumer<MotionEvent> mGestureDetector;
 
     public AssistantInputConsumer(
             Context context,
             GestureState gestureState,
             InputConsumer delegate,
             InputMonitorCompat inputMonitor,
-            boolean isAssistGestureConstrained) {
+            RecentsAnimationDeviceState deviceState,
+            MotionEvent startEvent) {
         super(delegate, inputMonitor);
         final Resources res = context.getResources();
         mContext = context;
-        mIsAssistGestureConstrained = isAssistGestureConstrained;
         mDragDistThreshold = res.getDimension(R.dimen.gestures_assistant_drag_threshold);
         mFlingDistThreshold = res.getDimension(R.dimen.gestures_assistant_fling_threshold);
         mTimeThreshold = res.getInteger(R.integer.assistant_gesture_min_time_threshold);
@@ -104,7 +106,11 @@
         mSquaredSlop = slop * slop;
         mActivityInterface = gestureState.getActivityInterface();
 
-        mGestureDetector = new GestureDetector(context, new AssistantGestureListener());
+        boolean flingDisabled = deviceState.isAssistantGestureIsConstrained()
+                || deviceState.isInDeferredGestureRegion(startEvent);
+        mGestureDetector = flingDisabled
+                ? ev -> { }
+                : new GestureDetector(context, new AssistantGestureListener())::onTouchEvent;
     }
 
     @Override
@@ -201,7 +207,7 @@
                 break;
         }
 
-        mGestureDetector.onTouchEvent(ev);
+        mGestureDetector.accept(ev);
 
         if (mState != STATE_ACTIVE) {
             mDelegate.onMotionEvent(ev);
@@ -214,12 +220,6 @@
             if (mDistance >= mDragDistThreshold && mTimeFraction >= 1) {
                 SystemUiProxy.INSTANCE.get(mContext).onAssistantGestureCompletion(0);
                 startAssistantInternal();
-
-                Bundle args = new Bundle();
-                args.putInt(OPA_BUNDLE_TRIGGER, OPA_BUNDLE_TRIGGER_DIAG_SWIPE_GESTURE);
-                args.putInt(INVOCATION_TYPE_KEY, INVOCATION_TYPE_GESTURE);
-                SystemUiProxy.INSTANCE.get(mContext).startAssistant(args);
-                mLaunchedAssistant = true;
             } else {
                 SystemUiProxy.INSTANCE.get(mContext).onAssistantProgress(mLastProgress);
             }
@@ -233,6 +233,12 @@
                 13, // HapticFeedbackConstants.GESTURE_END
                 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
         }
+
+        Bundle args = new Bundle();
+        args.putInt(OPA_BUNDLE_TRIGGER, OPA_BUNDLE_TRIGGER_DIAG_SWIPE_GESTURE);
+        args.putInt(INVOCATION_TYPE_KEY, INVOCATION_TYPE_GESTURE);
+        SystemUiProxy.INSTANCE.get(mContext).startAssistant(args);
+        mLaunchedAssistant = true;
     }
 
     /**
@@ -250,8 +256,7 @@
     private class AssistantGestureListener extends SimpleOnGestureListener {
         @Override
         public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
-            if (!mIsAssistGestureConstrained
-                && isValidAssistantGestureAngle(velocityX, -velocityY)
+            if (isValidAssistantGestureAngle(velocityX, -velocityY)
                     && mDistance >= mFlingDistThreshold
                     && !mLaunchedAssistant
                     && mState != STATE_DELEGATE_ACTIVE) {
@@ -259,11 +264,6 @@
                 SystemUiProxy.INSTANCE.get(mContext).onAssistantGestureCompletion(
                     (float) Math.sqrt(velocityX * velocityX + velocityY * velocityY));
                 startAssistantInternal();
-
-                Bundle args = new Bundle();
-                args.putInt(INVOCATION_TYPE_KEY, INVOCATION_TYPE_GESTURE);
-                SystemUiProxy.INSTANCE.get(mContext).startAssistant(args);
-                mLaunchedAssistant = true;
             }
             return true;
         }