Merge "Stop using magic constant 0.1 for switching from home to all apps" into ub-launcher3-master
diff --git a/quickstep/src/com/android/quickstep/TestInformationProvider.java b/quickstep/src/com/android/quickstep/TestInformationProvider.java
index 0c93dd6..e57d3ec 100644
--- a/quickstep/src/com/android/quickstep/TestInformationProvider.java
+++ b/quickstep/src/com/android/quickstep/TestInformationProvider.java
@@ -71,6 +71,9 @@
             final Context context = getContext();
             final DeviceProfile deviceProfile = InvariantDeviceProfile.INSTANCE.
                     get(context).getDeviceProfile(context);
+            final LauncherAppState launcherAppState = LauncherAppState.getInstanceNoCreate();
+            final Launcher launcher = launcherAppState != null ?
+                    (Launcher) launcherAppState.getModel().getCallback() : null;
 
             switch (method) {
                 case TestProtocol.REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT: {
@@ -79,18 +82,15 @@
                     response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight);
                     break;
                 }
+
                 case TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT: {
                     final float swipeHeight =
                             LayoutUtils.getShelfTrackingDistance(context, deviceProfile);
                     response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight);
                     break;
                 }
-                case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: {
-                    final LauncherAppState launcherAppState =
-                            LauncherAppState.getInstanceNoCreate();
-                    if (launcherAppState == null) return null;
 
-                    final Launcher launcher = (Launcher) launcherAppState.getModel().getCallback();
+                case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: {
                     if (launcher == null) return null;
 
                     final float progress = LauncherState.OVERVIEW.getVerticalProgress(launcher)
@@ -100,6 +100,17 @@
                     response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance);
                     break;
                 }
+
+                case TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT: {
+                    if (launcher == null) return null;
+
+                    final float progress = LauncherState.NORMAL.getVerticalProgress(launcher)
+                            - LauncherState.ALL_APPS.getVerticalProgress(launcher);
+                    final float distance =
+                            launcher.getAllAppsController().getShiftRange() * progress;
+                    response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) distance);
+                    break;
+                }
             }
             return response;
         }
diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/TestProtocol.java
index a4e4227..4eb3627 100644
--- a/src/com/android/launcher3/TestProtocol.java
+++ b/src/com/android/launcher3/TestProtocol.java
@@ -38,4 +38,6 @@
             "background-to-overview-swipe-height";
     public static final String REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT =
             "all-apps-to-overview-swipe-height";
+    public static final String REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT =
+            "home-to-all-apps-swipe-height";
 }
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 819e10d..e3ef74a 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -51,15 +51,16 @@
     @NonNull
     public AllApps switchToAllApps() {
         verifyActiveContainer();
-        // Swipe from the hotseat to near the top, e.g. 10% of the screen.
         final UiObject2 hotseat = mHotseat;
         final Point start = hotseat.getVisibleCenter();
-        final int endY = (int) (mLauncher.getDevice().getDisplayHeight() * 0.1f);
+        final int swipeHeight = mLauncher.getTestInfo(
+                TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT).
+                getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
         mLauncher.swipe(
                 start.x,
                 start.y,
                 start.x,
-                endY,
+                start.y - swipeHeight - mLauncher.getTouchSlop(),
                 ALL_APPS_STATE_ORDINAL
         );