Merge "Removing legacy launcher winscope tracing for tests" into udc-dev
diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
index 977163b..3ec82ce 100644
--- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
+++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
@@ -1702,6 +1702,7 @@
                     QuickStepContract.getWindowCornerRadius(mLauncher),
                     false /* fromPredictiveBack */);
 
+            TaskViewUtils.createSplitAuxiliarySurfacesAnimator(nonAppTargets, false, null);
             mLauncher.clearForceInvisibleFlag(INVISIBLE_ALL);
             result.setAnimation(pair.second, mLauncher);
         }
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
index 0a83279..040b8f7 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java
@@ -153,6 +153,11 @@
             return false;
         }
         TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onTaskbarItemLongClick");
+        if (TestProtocol.sDebugTracing) {
+            Log.d(TestProtocol.TWO_TASKBAR_LONG_CLICKS,
+                    "TaskbarDragController.startDragOnLongClick",
+                    new Throwable());
+        }
         BubbleTextView btv = (BubbleTextView) view;
         mActivity.onDragStart();
         btv.post(() -> {
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
index 77c76d9..88cac97 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
@@ -428,6 +428,55 @@
     }
 
     @Test
+    @PortraitLandscape
+    public void testOverviewDeadzones() throws Exception {
+        startTestAppsWithCheck();
+
+        Overview overview = mLauncher.goHome().switchToOverview();
+        assertTrue("Launcher internal state should be Overview",
+                isInState(() -> LauncherState.OVERVIEW));
+        executeOnLauncher(
+                launcher -> assertTrue("Should have at least 3 tasks",
+                        getTaskCount(launcher) >= 3));
+
+        // It should not dismiss overview when tapping between tasks
+        overview.touchBetweenTasks();
+        overview = mLauncher.getOverview();
+        assertTrue("Launcher internal state should be Overview",
+                isInState(() -> LauncherState.OVERVIEW));
+
+        // Dismiss when tapping to the right of the focused task
+        overview.touchOutsideFirstTask();
+        assertTrue("Launcher internal state should be Home",
+                isInState(() -> LauncherState.NORMAL));
+    }
+
+    @Test
+    @PortraitLandscape
+    public void testTaskbarDeadzonesForTablet() throws Exception {
+        assumeTrue(mLauncher.isTablet());
+
+        startTestAppsWithCheck();
+
+        Overview overview = mLauncher.goHome().switchToOverview();
+        assertTrue("Launcher internal state should be Overview",
+                isInState(() -> LauncherState.OVERVIEW));
+        executeOnLauncher(
+                launcher -> assertTrue("Should have at least 3 tasks",
+                        getTaskCount(launcher) >= 3));
+
+        // On persistent taskbar, it should not dismiss when tapping the taskbar
+        overview.touchTaskbarBottomCorner(/* tapRight= */ false);
+        assertTrue("Launcher internal state should be Overview",
+                isInState(() -> LauncherState.OVERVIEW));
+
+        // On persistent taskbar, it should not dismiss when tapping the taskbar
+        overview.touchTaskbarBottomCorner(/* tapRight= */ true);
+        assertTrue("Launcher internal state should be Overview",
+                isInState(() -> LauncherState.OVERVIEW));
+    }
+
+    @Test
     @ScreenRecord // b/242163205
     public void testDisableRotationCheckForPhone() throws Exception {
         assumeFalse(mLauncher.isTablet());
diff --git a/res/layout/widgets_full_sheet.xml b/res/layout/widgets_full_sheet.xml
index 9ec346a..47bf9e7 100644
--- a/res/layout/widgets_full_sheet.xml
+++ b/res/layout/widgets_full_sheet.xml
@@ -58,6 +58,7 @@
         <com.android.launcher3.views.RecyclerViewFastScroller
             android:id="@+id/fast_scroller"
             android:layout_width="@dimen/fastscroll_width"
+            android:elevation="1dp"
             android:layout_height="match_parent"
             android:layout_alignParentEnd="true"
             android:layout_alignParentTop="true"
diff --git a/res/layout/widgets_full_sheet_paged_view.xml b/res/layout/widgets_full_sheet_paged_view.xml
index 94f707a..069d4bc 100644
--- a/res/layout/widgets_full_sheet_paged_view.xml
+++ b/res/layout/widgets_full_sheet_paged_view.xml
@@ -48,7 +48,6 @@
         android:layout_height="wrap_content"
         android:layout_below="@id/collapse_handle"
         android:paddingBottom="0dp"
-        android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
         android:clipToOutline="true"
         android:orientation="vertical">
 
@@ -67,6 +66,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:elevation="0.1dp"
+            android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
             android:background="?attr/widgetPickerPrimarySurfaceColor"
             android:paddingBottom="8dp"
             launcher:layout_sticky="true">
@@ -78,6 +78,7 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="8dp"
+            android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
             android:background="@drawable/widgets_surface_background"
             android:paddingVertical="@dimen/recommended_widgets_table_vertical_padding"
             android:visibility="gone" />
@@ -89,6 +90,7 @@
             android:gravity="center_horizontal"
             android:orientation="horizontal"
             android:paddingVertical="8dp"
+            android:paddingHorizontal="@dimen/widget_list_horizontal_margin"
             android:background="?attr/widgetPickerPrimarySurfaceColor"
             style="@style/TextHeadline"
             launcher:layout_sticky="true">
diff --git a/res/layout/widgets_two_pane_sheet_paged_view.xml b/res/layout/widgets_two_pane_sheet_paged_view.xml
index 2e05d48..442957a 100644
--- a/res/layout/widgets_two_pane_sheet_paged_view.xml
+++ b/res/layout/widgets_two_pane_sheet_paged_view.xml
@@ -13,14 +13,14 @@
      limitations under the License.
 -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:launcher="http://schemas.android.com/apk/res-auto"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:launcher="http://schemas.android.com/apk/res-auto">
 
     <FrameLayout
         android:id="@+id/widgets_two_pane_sheet_paged_view"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:gravity="start"
+        android:paddingHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
         android:layout_gravity="start"
         android:layout_alignParentStart="true">
         <com.android.launcher3.widget.picker.WidgetPagedView
@@ -29,7 +29,6 @@
             android:layout_height="match_parent"
             android:clipToPadding="false"
             android:descendantFocusability="afterDescendants"
-            android:paddingHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
             launcher:pageIndicator="@+id/tabs" >
 
             <com.android.launcher3.widget.picker.WidgetsRecyclerView
@@ -62,7 +61,6 @@
                 android:clipToPadding="false"
                 android:elevation="0.1dp"
                 android:paddingBottom="8dp"
-                android:paddingHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
                 launcher:layout_sticky="true">
 
                 <include layout="@layout/widgets_search_bar" />
@@ -73,7 +71,6 @@
                 android:layout_height="match_parent"
                 android:id="@+id/suggestions_header"
                 android:layout_marginTop="8dp"
-                android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
                 android:orientation="horizontal"
                 android:background="?attr/widgetPickerPrimarySurfaceColor"
                 launcher:layout_sticky="true">
@@ -86,7 +83,6 @@
                 android:gravity="center_horizontal"
                 android:orientation="horizontal"
                 android:paddingVertical="8dp"
-                android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin_two_pane"
                 android:background="?attr/widgetPickerPrimarySurfaceColor"
                 style="@style/TextHeadline"
                 launcher:layout_sticky="true">
diff --git a/res/layout/widgets_two_pane_sheet_recyclerview.xml b/res/layout/widgets_two_pane_sheet_recyclerview.xml
index f8d72e8..c9c855c 100644
--- a/res/layout/widgets_two_pane_sheet_recyclerview.xml
+++ b/res/layout/widgets_two_pane_sheet_recyclerview.xml
@@ -13,8 +13,7 @@
      limitations under the License.
 -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:launcher="http://schemas.android.com/apk/res-auto"
-    xmlns:app="http://schemas.android.com/apk/res-auto">
+    xmlns:launcher="http://schemas.android.com/apk/res-auto">
 
     <FrameLayout
         android:id="@+id/widgets_two_pane_sheet_recyclerview"
diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
index 2b67cdd..bcad5de 100644
--- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
+++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java
@@ -154,6 +154,7 @@
     public static final String PERMANENT_DIAG_TAG = "TaplTarget";
     public static final String VIEW_AND_ACTIVITY_LEAKS = "b/260260325";
     public static final String WORK_TAB_MISSING = "b/243688989";
+    public static final String TWO_TASKBAR_LONG_CLICKS = "b/262282528";
 
     public static final String REQUEST_EMULATE_DISPLAY = "emulate-display";
     public static final String REQUEST_STOP_EMULATE_DISPLAY = "stop-emulate-display";
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index afeb8d7..2c3c028 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -72,6 +72,44 @@
     }
 
     /**
+     * Flings backward (right) and waits the fling's end.
+     */
+    public void flingBackward() {
+        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
+            flingBackwardImpl();
+        }
+    }
+
+    private void flingBackwardImpl() {
+        try (LauncherInstrumentation.Closable c =
+                     mLauncher.addContextLayer("want to fling backward in overview")) {
+            LauncherInstrumentation.log("Overview.flingBackward before fling");
+            final UiObject2 overview = verifyActiveContainer();
+            final int rightMargin =
+                    mLauncher.getTargetInsets().right + mLauncher.getEdgeSensitivityWidth();
+            mLauncher.scroll(
+                    overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false);
+            try (LauncherInstrumentation.Closable c2 =
+                         mLauncher.addContextLayer("flung backwards")) {
+                verifyActiveContainer();
+                verifyActionsViewVisibility();
+            }
+        }
+    }
+
+    private OverviewTask flingToFirstTask() {
+        OverviewTask currentTask = getCurrentTask();
+
+        while (mLauncher.getRealDisplaySize().x - currentTask.getUiObject().getVisibleBounds().right
+                <= mLauncher.getOverviewPageSpacing()) {
+            flingBackwardImpl();
+            currentTask = getCurrentTask();
+        }
+
+        return currentTask;
+    }
+
+    /**
      * Dismissed all tasks by scrolling to Clear-all button and pressing it.
      */
     public void dismissAllTasks() {
@@ -94,23 +132,57 @@
     }
 
     /**
-     * Flings backward (right) and waits the fling's end.
+     * Touch to the right of current task. This should dismiss overview and go back to Workspace.
      */
-    public void flingBackward() {
+    public Workspace touchOutsideFirstTask() {
         try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
-             LauncherInstrumentation.Closable c =
-                     mLauncher.addContextLayer("want to fling backward in overview")) {
-            LauncherInstrumentation.log("Overview.flingBackward before fling");
-            final UiObject2 overview = verifyActiveContainer();
-            final int rightMargin =
-                    mLauncher.getTargetInsets().right + mLauncher.getEdgeSensitivityWidth();
-            mLauncher.scroll(
-                    overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false);
-            try (LauncherInstrumentation.Closable c2 =
-                         mLauncher.addContextLayer("flung backwards")) {
-                verifyActiveContainer();
-                verifyActionsViewVisibility();
+             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+                     "touching outside the focused task")) {
+
+            if (getTaskCount() < 2) {
+                throw new IllegalStateException(
+                        "Need to have at least 2 tasks");
             }
+
+            OverviewTask currentTask = flingToFirstTask();
+
+            mLauncher.touchOutsideContainer(currentTask.getUiObject(),
+                    /* tapRight= */ true,
+                    /* halfwayToEdge= */ false);
+
+            return new Workspace(mLauncher);
+        }
+    }
+
+    /**
+     * Touch between two tasks
+     */
+    public void touchBetweenTasks() {
+        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
+             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+                     "touching outside the focused task")) {
+            if (getTaskCount() < 2) {
+                throw new IllegalStateException(
+                        "Need to have at least 2 tasks");
+            }
+
+            OverviewTask currentTask = flingToFirstTask();
+
+            mLauncher.touchOutsideContainer(currentTask.getUiObject(),
+                    /* tapRight= */ false,
+                    /* halfwayToEdge= */ false);
+        }
+    }
+
+    /**
+     * Touch either on the right or the left corner of the screen, 1 pixel from the bottom and
+     * from the sides.
+     */
+    public void touchTaskbarBottomCorner(boolean tapRight) {
+        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
+            Taskbar taskbar = new Taskbar(mLauncher);
+            taskbar.touchBottomCorner(tapRight);
+            verifyActiveContainer();
         }
     }
 
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 80fded5..2adfc98 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -2014,21 +2014,41 @@
     }
 
     /**
-     * Taps outside container to dismiss.
+     * Taps outside container to dismiss, centered vertically and halfway to the edge of the screen.
      *
      * @param container container to be dismissed
      * @param tapRight  tap on the right of the container if true, or left otherwise
      */
     void touchOutsideContainer(UiObject2 container, boolean tapRight) {
+        touchOutsideContainer(container, tapRight, true);
+    }
+
+    /**
+     * Taps outside the container, to the right or left, and centered vertically.
+     *
+     * @param tapRight      if true touches to the right of the container, otherwise touches on left
+     * @param halfwayToEdge if true touches halfway to the screen edge, if false touches 1 px from
+     *                      container
+     */
+    void touchOutsideContainer(UiObject2 container, boolean tapRight, boolean halfwayToEdge) {
         try (LauncherInstrumentation.Closable c = addContextLayer(
                 "want to tap outside container on the " + (tapRight ? "right" : "left"))) {
             Rect containerBounds = getVisibleBounds(container);
+
+            int x;
+            if (halfwayToEdge) {
+                x = tapRight
+                        ? (containerBounds.right + getRealDisplaySize().x) / 2
+                        : containerBounds.left / 2;
+            } else {
+                x = tapRight
+                        ? containerBounds.right + 1
+                        : containerBounds.left - 1;
+            }
+            int y = containerBounds.top + containerBounds.height() / 2;
+
             final long downTime = SystemClock.uptimeMillis();
-            final Point tapTarget = new Point(
-                    tapRight
-                            ? (containerBounds.right + getRealDisplaySize().x) / 2
-                            : containerBounds.left / 2,
-                    containerBounds.top + 1);
+            final Point tapTarget = new Point(x, y);
             sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget,
                     LauncherInstrumentation.GestureScope.INSIDE);
             sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget,
diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
index 90f3d13..39b93b4 100644
--- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
+++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
@@ -71,6 +71,10 @@
         return mTask.getVisibleBounds().exactCenterX();
     }
 
+    UiObject2 getUiObject() {
+        return mTask;
+    }
+
     /**
      * Dismisses the task by swiping up.
      */
diff --git a/tests/tapl/com/android/launcher3/tapl/Taskbar.java b/tests/tapl/com/android/launcher3/tapl/Taskbar.java
index 6ca7f4b..051630e 100644
--- a/tests/tapl/com/android/launcher3/tapl/Taskbar.java
+++ b/tests/tapl/com/android/launcher3/tapl/Taskbar.java
@@ -20,6 +20,7 @@
 import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING;
 
 import android.graphics.Point;
+import android.graphics.Rect;
 import android.os.SystemClock;
 import android.text.TextUtils;
 import android.view.MotionEvent;
@@ -122,4 +123,33 @@
         // Look for an icon with no text
         return By.clazz(TextView.class).text("");
     }
+
+    private Rect getVisibleBounds() {
+        return mLauncher.waitForSystemLauncherObject(TASKBAR_RES_ID).getVisibleBounds();
+    }
+
+    /**
+     * Touch either on the right or the left corner of the screen, 1 pixel from the bottom and
+     * from the sides.
+     */
+    void touchBottomCorner(boolean tapRight) {
+        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
+                "want to tap bottom corner on the " + (tapRight ? "right" : "left"))) {
+            final long downTime = SystemClock.uptimeMillis();
+            final Point tapTarget = new Point(
+                    tapRight
+                            ?
+                            getVisibleBounds().right
+                                    - mLauncher.getTargetInsets().right
+                                    - 1
+                            : getVisibleBounds().left
+                                    + 1,
+                    mLauncher.getRealDisplaySize().y - 1);
+
+            mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget,
+                    LauncherInstrumentation.GestureScope.INSIDE);
+            mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget,
+                    LauncherInstrumentation.GestureScope.INSIDE);
+        }
+    }
 }