Use NavHandleLongPressInputConsumer regardless of flags.

This way we can still log long press attempts even when the
feature flags or settings are disabled.

We always log LAUNCHER_LONG_PRESS_NAVBAR when a long press is
detected, even if nothing else happens.

Additionally, we log LAUNCHER_DEEP_PRESS_NAVBAR if the long
press was short-circuited by a deep press. In this case both
logs will appear.

If ENABLE_LPNH_DEEP_PRESS is false, it's possible that
LAUNCHER_DEEP_PRESS_NAVBAR will be logged without
LAUNCHER_LONG_PRESS_NAVBAR. This is because we log deep press
even if the feature is disabled, but it won't cause long press to
trigger immediately, so the user may release their finger before
the normal long press triggers.

Note: getLongPressRunnable will still return null if the flags or
other checks fail, so nothing will happen beyond logging.

Fix: 313477667
Fix: 310955078
Test: Manual with wwlogcat with flags in various states
Flag: NA
Change-Id: I40ceb5a22b364c2d5d6e4fdabb546b81c84354eb
diff --git a/quickstep/src/com/android/quickstep/TouchInteractionService.java b/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 3717d9c..b7576c3 100644
--- a/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -982,12 +982,11 @@
                     base = new TaskbarUnstashInputConsumer(this, base, mInputMonitorCompat, tac,
                             mOverviewCommandHelper);
                 }
-            } else if (canStartSystemGesture && FeatureFlags.ENABLE_LONG_PRESS_NAV_HANDLE.get()
-                    && !previousGestureState.isRecentsAnimationRunning()) {
+            } else if (canStartSystemGesture && !previousGestureState.isRecentsAnimationRunning()) {
                 reasonString.append(NEWLINE_PREFIX)
                         .append(reasonPrefix)
                         .append(SUBSTRING_PREFIX)
-                        .append("Long press nav handle enabled, ")
+                        .append("Not running recents animation, ")
                         .append("using NavHandleLongPressInputConsumer");
                 base = new NavHandleLongPressInputConsumer(this, base, mInputMonitorCompat,
                         mDeviceState);
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressHandler.java b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressHandler.java
index 14305cf..57c05e9 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressHandler.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressHandler.java
@@ -48,17 +48,13 @@
     }
 
     /**
-     * Called when nav handle gesture starts. Returns true if long press nav handle is enabled and
-     * supported.
+     * Called when nav handle gesture starts.
      */
-    public boolean canStartTouch() {
-        return false;
-    }
+    public void onTouchStarted() {}
 
     /**
      * Called when nav handle gesture is finished by the user lifting their finger or the system
      * cancelling the touch for some other reason.
      */
-    public void onTouchFinished() {
-    }
+    public void onTouchFinished() {}
 }
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
index 8051e68..0127cc9 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
@@ -16,6 +16,8 @@
 package com.android.quickstep.inputconsumers;
 
 import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_TIMEOUT_MS;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DEEP_PRESS_NAVBAR;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LONG_PRESS_NAVBAR;
 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
 
 import android.content.Context;
@@ -25,9 +27,11 @@
 import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.R;
 import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.logging.StatsLogManager;
 import com.android.launcher3.util.DisplayController;
 import com.android.quickstep.InputConsumer;
 import com.android.quickstep.RecentsAnimationDeviceState;
+import com.android.quickstep.TopTaskTracker;
 import com.android.systemui.shared.system.InputMonitorCompat;
 
 /**
@@ -43,8 +47,11 @@
     private final float mTouchSlopSquared;
     private final int mLongPressTimeout;
     private final boolean mDeepPressEnabled;
+    private final StatsLogManager mStatsLogManager;
+    private final TopTaskTracker mTopTaskTracker;
 
     private MotionEvent mCurrentDownEvent;
+    private boolean mDeepPressLogged;  // Whether deep press has been logged for the current touch.
 
     public NavHandleLongPressInputConsumer(Context context, InputConsumer delegate,
             InputMonitorCompat inputMonitor, RecentsAnimationDeviceState deviceState) {
@@ -60,6 +67,8 @@
         }
         mTouchSlopSquared = deviceState.getSquaredTouchSlop();
         mNavHandleLongPressHandler = NavHandleLongPressHandler.newInstance(context);
+        mStatsLogManager = StatsLogManager.newInstance(context);
+        mTopTaskTracker = TopTaskTracker.INSTANCE.get(context);
     }
 
     @Override
@@ -87,8 +96,9 @@
                     mCurrentDownEvent.recycle();
                 }
                 mCurrentDownEvent = MotionEvent.obtain(ev);
-                if (isInNavBarHorizontalArea(ev.getRawX())
-                        && mNavHandleLongPressHandler.canStartTouch()) {
+                mDeepPressLogged = false;
+                if (isInNavBarHorizontalArea(ev.getRawX())) {
+                    mNavHandleLongPressHandler.onTouchStarted();
                     MAIN_EXECUTOR.getHandler().postDelayed(mTriggerLongPress,
                             mLongPressTimeout);
                 }
@@ -110,25 +120,41 @@
         }
 
         // If the gesture is deep press then trigger long press asap
-        if (mDeepPressEnabled && MAIN_EXECUTOR.getHandler().hasCallbacks(mTriggerLongPress)
-                && ev.getClassification() == MotionEvent.CLASSIFICATION_DEEP_PRESS) {
-            MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
-            MAIN_EXECUTOR.getHandler().post(mTriggerLongPress);
+        if (MAIN_EXECUTOR.getHandler().hasCallbacks(mTriggerLongPress)
+                && ev.getClassification() == MotionEvent.CLASSIFICATION_DEEP_PRESS
+                && !mDeepPressLogged) {
+            // Log deep press even if feature is disabled.
+            String runningPackage = mTopTaskTracker.getCachedTopTask(
+                    /* filterOnlyVisibleRecents */ true).getPackageName();
+            mStatsLogManager.logger().withPackageName(runningPackage)
+                    .log(LAUNCHER_DEEP_PRESS_NAVBAR);
+            mDeepPressLogged = true;
+
+            // But only trigger if the feature is enabled.
+            if (mDeepPressEnabled) {
+                MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
+                MAIN_EXECUTOR.getHandler().post(mTriggerLongPress);
+            }
         }
     }
 
     private void triggerLongPress() {
+        String runningPackage = mTopTaskTracker.getCachedTopTask(
+                /* filterOnlyVisibleRecents */ true).getPackageName();
+        mStatsLogManager.logger().withPackageName(runningPackage).log(LAUNCHER_LONG_PRESS_NAVBAR);
+
         Runnable longPressRunnable = mNavHandleLongPressHandler.getLongPressRunnable();
-        if (longPressRunnable != null) {
-            OtherActivityInputConsumer oaic = getInputConsumerOfClass(
-                    OtherActivityInputConsumer.class);
-            if (oaic != null && oaic.hasStartedTouchTracking()) {
-                oaic.setForceFinishRecentsTransitionCallback(longPressRunnable);
-                setActive(mCurrentDownEvent);
-            } else {
-                setActive(mCurrentDownEvent);
-                MAIN_EXECUTOR.post(longPressRunnable);
-            }
+        if (longPressRunnable == null) {
+            return;
+        }
+
+        OtherActivityInputConsumer oaic = getInputConsumerOfClass(OtherActivityInputConsumer.class);
+        if (oaic != null && oaic.hasStartedTouchTracking()) {
+            oaic.setForceFinishRecentsTransitionCallback(longPressRunnable);
+            setActive(mCurrentDownEvent);
+        } else {
+            setActive(mCurrentDownEvent);
+            MAIN_EXECUTOR.post(longPressRunnable);
         }
     }
 
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 9980218..f90779c 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -275,6 +275,12 @@
         @UiEvent(doc = "User swipes or fling in DOWN direction on the bottom bazel area.")
         LAUNCHER_SWIPEDOWN_NAVBAR(573),
 
+        @UiEvent(doc = "User deep presses on the bottom bezel area.")
+        LAUNCHER_DEEP_PRESS_NAVBAR(1543),
+
+        @UiEvent(doc = "User long presses on the bottom bezel area.")
+        LAUNCHER_LONG_PRESS_NAVBAR(1544),
+
         @UiEvent(doc = "User swipes or fling in UP direction from bottom bazel area.")
         LAUNCHER_HOME_GESTURE(574),