Add scroll up and scroll down logging.

Bug: 247601175
Test: Manual. https://paste.googleplex.com/5757099224072192

Change-Id: Iec1697e1580c75572c9e77ec349942301ee87694
diff --git a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
index 21a7dfb..0efa7c4 100644
--- a/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsRecyclerView.java
@@ -17,7 +17,11 @@
 
 import static android.view.View.MeasureSpec.UNSPECIFIED;
 
-import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_SCROLLED;
+import static com.android.launcher3.logger.LauncherAtom.ContainerInfo;
+import static com.android.launcher3.logger.LauncherAtom.SearchResultContainer;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_SCROLLED_DOWN;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_SCROLLED_UNKNOWN_DIRECTION;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_SCROLLED_UP;
 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_VERTICAL_SWIPE_BEGIN;
 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_VERTICAL_SWIPE_END;
 import static com.android.launcher3.util.LogConfig.SEARCH_LOGGING;
@@ -31,6 +35,7 @@
 import androidx.recyclerview.widget.RecyclerView;
 
 import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.ExtendedEditText;
 import com.android.launcher3.FastScrollRecyclerView;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.R;
@@ -56,6 +61,7 @@
     private final SparseIntArray mViewHeights = new SparseIntArray();
     private final SparseIntArray mCachedScrollPositions = new SparseIntArray();
     private final AllAppsFastScrollHelper mFastScrollHelper;
+    private int mCumulativeVerticalScroll;
 
 
     private final AdapterDataObserver mObserver = new RecyclerView.AdapterDataObserver() {
@@ -157,7 +163,7 @@
         StatsLogManager mgr = ActivityContext.lookupContext(getContext()).getStatsLogManager();
         switch (state) {
             case SCROLL_STATE_DRAGGING:
-                mgr.logger().log(LAUNCHER_ALLAPPS_SCROLLED);
+                mCumulativeVerticalScroll = 0;
                 requestFocus();
                 mgr.logger().sendToInteractionJankMonitor(
                         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_BEGIN, this);
@@ -166,10 +172,17 @@
             case SCROLL_STATE_IDLE:
                 mgr.logger().sendToInteractionJankMonitor(
                         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_END, this);
+                logCumulativeVerticalScroll();
                 break;
         }
     }
 
+    @Override
+    public void onScrolled(int dx, int dy) {
+        super.onScrolled(dx, dy);
+        mCumulativeVerticalScroll += dy;
+    }
+
     /**
      * Maps the touch (from 0..1) to the adapter position that should be visible.
      */
@@ -349,4 +362,21 @@
     public boolean hasOverlappingRendering() {
         return false;
     }
+
+    private void logCumulativeVerticalScroll() {
+        ActivityContext context = ActivityContext.lookupContext(getContext());
+        StatsLogManager mgr = context.getStatsLogManager();
+        ExtendedEditText editText = context.getAppsView().getSearchUiManager().getEditText();
+        ContainerInfo containerInfo = ContainerInfo.newBuilder().setSearchResultContainer(
+                SearchResultContainer
+                        .newBuilder()
+                        .setQueryLength((editText == null) ? -1 : editText.length())).build();
+
+        // mCumulativeVerticalScroll == 0 when user comes back to original position, we don't
+        // know the direction of scrolling.
+        mgr.logger().withContainerInfo(containerInfo).log(
+                mCumulativeVerticalScroll == 0 ? LAUNCHER_ALLAPPS_SCROLLED_UNKNOWN_DIRECTION
+                        : (mCumulativeVerticalScroll > 0) ? LAUNCHER_ALLAPPS_SCROLLED_DOWN
+                                : LAUNCHER_ALLAPPS_SCROLLED_UP);
+    }
 }
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 22627b4..837e47a 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -555,6 +555,20 @@
                 + "result page etc.")
         LAUNCHER_ALLAPPS_SCROLLED(985),
 
+        @UiEvent(doc = "User scrolled up on one of the all apps surfaces such as A-Z list, search "
+                + "result page etc.")
+        LAUNCHER_ALLAPPS_SCROLLED_UP(1229),
+
+        @UiEvent(doc =
+                "User scrolled down on one of the all apps surfaces such as A-Z list, search "
+                        + "result page etc.")
+        LAUNCHER_ALLAPPS_SCROLLED_DOWN(1230),
+
+        @UiEvent(doc = "User scrolled on one of the all apps surfaces such as A-Z list, search "
+                + "result page etc and we don't know the direction since user came back to "
+                + "original position from which they scrolled.")
+        LAUNCHER_ALLAPPS_SCROLLED_UNKNOWN_DIRECTION(1231),
+
         @UiEvent(doc = "User tapped taskbar home button")
         LAUNCHER_TASKBAR_HOME_BUTTON_TAP(1003),