Merge "Fixing onStateTransitionEnd is not called at the end of reset state" into ub-launcher3-qt-dev
diff --git a/Android.mk b/Android.mk
index 7956d28..9d113d9 100644
--- a/Android.mk
+++ b/Android.mk
@@ -298,7 +298,7 @@
 LOCAL_PACKAGE_NAME := Launcher3GoIconRecents
 LOCAL_PRIVILEGED_MODULE := true
 LOCAL_PRODUCT_MODULE := true
-LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3 Launcher3Go Launcher3QuickStep Launcher3QuickStepGo
+LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3 Launcher3Go Launcher3QuickStep
 LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.launcher3
 
 LOCAL_FULL_LIBS_MANIFEST_FILES := \
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
index 1c66968..d14de70 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java
@@ -83,4 +83,16 @@
     public int getVisibleElements(Launcher launcher) {
         return super.getVisibleElements(launcher) & ~RECENTS_CLEAR_ALL_BUTTON;
     }
+
+    @Override
+    public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) {
+        if ((getVisibleElements(launcher) & HOTSEAT_ICONS) != 0) {
+            // Translate hotseat offscreen if we show it in overview.
+            ScaleAndTranslation scaleAndTranslation = super.getHotseatScaleAndTranslation(launcher);
+            scaleAndTranslation.translationY = LayoutUtils.getShelfTrackingDistance(launcher,
+                    launcher.getDeviceProfile());
+            return scaleAndTranslation;
+        }
+        return super.getHotseatScaleAndTranslation(launcher);
+    }
 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewState.java
index 9a99c15..5c9b200 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewState.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/states/OverviewState.java
@@ -127,6 +127,10 @@
             // We have no all apps content, so we're still at the fully down progress.
             return super.getVerticalProgress(launcher);
         }
+        return getDefaultVerticalProgress(launcher);
+    }
+
+    public static float getDefaultVerticalProgress(Launcher launcher) {
         return 1 - (getDefaultSwipeHeight(launcher)
                 / launcher.getAllAppsController().getShiftRange());
     }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java
index 0d06c19..e7d085c 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityControllerHelper.java
@@ -16,7 +16,6 @@
 package com.android.quickstep;
 
 import static android.view.View.TRANSLATION_Y;
-
 import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
 import static com.android.launcher3.LauncherState.BACKGROUND_APP;
 import static com.android.launcher3.LauncherState.NORMAL;
@@ -62,6 +61,7 @@
 import com.android.launcher3.anim.AnimatorSetBuilder;
 import com.android.launcher3.anim.SpringObjectAnimator;
 import com.android.launcher3.testing.TestProtocol;
+import com.android.launcher3.uioverrides.states.OverviewState;
 import com.android.launcher3.userevent.nano.LauncherLogProto;
 import com.android.launcher3.views.FloatingIconView;
 import com.android.quickstep.SysUINavigationMode.Mode;
@@ -260,8 +260,11 @@
                 }
                 float shelfHiddenProgress = BACKGROUND_APP.getVerticalProgress(activity);
                 float shelfOverviewProgress = OVERVIEW.getVerticalProgress(activity);
+                // Peek based on default overview progress so we can see hotseat if we're showing
+                // that instead of predictions in overview.
+                float defaultOverviewProgress = OverviewState.getDefaultVerticalProgress(activity);
                 float shelfPeekingProgress = shelfHiddenProgress
-                        - (shelfHiddenProgress - shelfOverviewProgress) * 0.25f;
+                        - (shelfHiddenProgress - defaultOverviewProgress) * 0.25f;
                 float toProgress = mShelfState == ShelfAnimState.HIDE
                         ? shelfHiddenProgress
                         : mShelfState == ShelfAnimState.PEEK
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
index d0ea73a..6897c1e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TaskViewUtils.java
@@ -29,8 +29,6 @@
 import com.android.launcher3.BaseActivity;
 import com.android.launcher3.BaseDraggingActivity;
 import com.android.launcher3.ItemInfo;
-import com.android.launcher3.Launcher;
-import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.Utilities;
 import com.android.quickstep.util.ClipAnimationHelper;
 import com.android.quickstep.util.MultiValueUpdateListener;
@@ -123,6 +121,7 @@
                 new RemoteAnimationTargetSet(targets, MODE_OPENING);
         targetSet.addDependentTransactionApplier(applier);
 
+        final RecentsView recentsView = v.getRecentsView();
         final ValueAnimator appAnimator = ValueAnimator.ofFloat(0, 1);
         appAnimator.setInterpolator(TOUCH_RESPONSE_INTERPOLATOR);
         appAnimator.addUpdateListener(new MultiValueUpdateListener() {
@@ -153,7 +152,10 @@
                 // TODO: Take into account the current fullscreen progress for animating the insets
                 params.setProgress(1 - percent);
                 RectF taskBounds = inOutHelper.applyTransform(targetSet, params);
-                if (!skipViewChanges) {
+                int taskIndex = recentsView.indexOfChild(v);
+                int centerTaskIndex = recentsView.getCurrentPage();
+                boolean parallaxCenterAndAdjacentTask = taskIndex != centerTaskIndex;
+                if (!skipViewChanges && parallaxCenterAndAdjacentTask) {
                     float scale = taskBounds.width() / mThumbnailRect.width();
                     v.setScaleX(scale);
                     v.setScaleY(scale);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
index 5b2e27e..03441c8 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/LauncherRecentsView.java
@@ -33,9 +33,11 @@
 import android.graphics.Rect;
 import android.os.Build;
 import android.util.AttributeSet;
+import android.view.MotionEvent;
 import android.view.View;
 
 import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.Hotseat;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.LauncherStateManager.StateListener;
@@ -250,4 +252,16 @@
             setDisallowScrollToClearAll(!hasClearAllButton);
         }
     }
+
+    @Override
+    protected boolean shouldStealTouchFromSiblingsBelow(MotionEvent ev) {
+        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+            // Allow touches to go through to the hotseat.
+            Hotseat hotseat = mActivity.getHotseat();
+            boolean touchingHotseat = hotseat.isShown()
+                    && mActivity.getDragLayer().isEventOverView(hotseat, ev, this);
+            return !touchingHotseat;
+        }
+        return super.shouldStealTouchFromSiblingsBelow(ev);
+    }
 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 9058e7e..a8987a3 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -521,6 +521,10 @@
 
 
         // Do not let touch escape to siblings below this view.
+        return isHandlingTouch() || shouldStealTouchFromSiblingsBelow(ev);
+    }
+
+    protected boolean shouldStealTouchFromSiblingsBelow(MotionEvent ev) {
         return true;
     }
 
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java
index 6f10b42..d55a520 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskThumbnailView.java
@@ -367,8 +367,11 @@
         }
 
         mRotated = isRotated;
-        updateOverlay();
         invalidate();
+
+        // Update can be called from {@link #onSizeChanged} during layout, post handling of overlay
+        // as overlay could modify the views in the overlay as a side effect of its update.
+        post(this::updateOverlay);
     }
 
     @Override
diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
index b5da836..0a73b8b 100644
--- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
+++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java
@@ -115,7 +115,11 @@
             // as uninstalling the app or removing the "Launcher" feature in an update).
             // Listen for package updates of this app (and remove any previously attached
             // package listener).
-            if (!defaultHome.getPackageName().equals(mUpdateRegisteredPackage)) {
+            if (defaultHome == null) {
+                if (mUpdateRegisteredPackage != null) {
+                    mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
+                }
+            } else if (!defaultHome.getPackageName().equals(mUpdateRegisteredPackage)) {
                 if (mUpdateRegisteredPackage != null) {
                     mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
                 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepProcessInitializer.java b/quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java
similarity index 100%
rename from quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepProcessInitializer.java
rename to quickstep/src/com/android/quickstep/QuickstepProcessInitializer.java
diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
index f02859f..9e3bf2f 100644
--- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
+++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java
@@ -208,7 +208,7 @@
 
     @Test
     @NavigationModeSwitch
-    @PortraitLandscape
+//    @PortraitLandscape
     public void testBackground() throws Exception {
         startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
         final Background background = mLauncher.getBackground();
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index 80e17c9..dfa3e1b 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1204,6 +1204,7 @@
                     if (((initialScrollX >= mMaxScrollX) && (isVelocityXLeft || !isFling)) ||
                             ((initialScrollX <= mMinScrollX) && (!isVelocityXLeft || !isFling))) {
                         mScroller.springBack(getScrollX(), mMinScrollX, mMaxScrollX);
+                        mNextPage = getPageNearestToCenterOfScreen();
                     } else {
                         mScroller.setInterpolator(mDefaultInterpolator);
                         mScroller.fling(initialScrollX, -velocityX,
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index c62fc3d..a351b9a 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -2,6 +2,8 @@
 
 import static com.android.launcher3.LauncherState.ALL_APPS_CONTENT;
 import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
+import static com.android.launcher3.LauncherState.BACKGROUND_APP;
+import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
 import static com.android.launcher3.LauncherState.OVERVIEW;
 import static com.android.launcher3.LauncherState.VERTICAL_SWIPE_INDICATOR;
 import static com.android.launcher3.anim.AnimatorSetBuilder.ANIM_ALL_APPS_FADE;
@@ -28,15 +30,12 @@
 import com.android.launcher3.R;
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.AnimatorSetBuilder;
-import com.android.launcher3.anim.SpringObjectAnimator;
 import com.android.launcher3.anim.PropertySetter;
+import com.android.launcher3.anim.SpringObjectAnimator;
 import com.android.launcher3.testing.TestProtocol;
-import com.android.launcher3.util.MultiValueAlpha;
 import com.android.launcher3.util.Themes;
 import com.android.launcher3.views.ScrimView;
 
-import androidx.dynamicanimation.animation.FloatPropertyCompat;
-
 /**
  * Handles AllApps view transition.
  * 1) Slides all apps view using direct manipulation
@@ -139,6 +138,15 @@
         } else {
             mLauncher.getSystemUiController().updateUiState(UI_STATE_ALL_APPS, 0);
         }
+
+        if ((OVERVIEW.getVisibleElements(mLauncher) & HOTSEAT_ICONS) != 0) {
+            // Translate hotseat with the shelf until reaching overview.
+            float overviewProgress = OVERVIEW.getVerticalProgress(mLauncher);
+            if (progress >= overviewProgress || mLauncher.isInState(BACKGROUND_APP)) {
+                float hotseatShift = (progress - overviewProgress) * mShiftRange;
+                mLauncher.getHotseat().setTranslationY(hotseatShift);
+            }
+        }
     }
 
     @Override
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index ac152db..51c7022 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -116,11 +116,25 @@
         mMultiValueAlpha = new MultiValueAlpha(this, alphaChannelCount);
     }
 
+    /**
+     * Same as {@link #isEventOverView(View, MotionEvent, View)} where evView == this drag layer.
+     */
     public boolean isEventOverView(View view, MotionEvent ev) {
         getDescendantRectRelativeToSelf(view, mHitRect);
         return mHitRect.contains((int) ev.getX(), (int) ev.getY());
     }
 
+    /**
+     * Given a motion event in evView's coordinates, return whether the event is within another
+     * view's bounds.
+     */
+    public boolean isEventOverView(View view, MotionEvent ev, View evView) {
+        int[] xy = new int[] {(int) ev.getX(), (int) ev.getY()};
+        getDescendantCoordRelativeToSelf(evView, xy);
+        getDescendantRectRelativeToSelf(view, mHitRect);
+        return mHitRect.contains(xy[0], xy[1]);
+    }
+
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
         int action = ev.getAction();
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index abc93cd..e663e70 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -35,7 +35,6 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.util.Log;
-import android.view.Surface;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.uiautomator.By;
@@ -67,7 +66,6 @@
 import org.junit.Rule;
 import org.junit.rules.RuleChain;
 import org.junit.rules.TestRule;
-import org.junit.runners.model.Statement;
 
 import java.io.IOException;
 import java.lang.annotation.ElementType;
@@ -124,46 +122,10 @@
     protected @interface PortraitLandscape {
     }
 
-    @Rule
-    public TestRule mPortraitLandscapeExecutor =
-            (base, description) -> false && description.getAnnotation(PortraitLandscape.class)
-                    != null ? new Statement() {
-                @Override
-                public void evaluate() throws Throwable {
-                    try {
-                        // Create launcher activity if necessary and bring it to the front.
-                        mLauncher.pressHome();
-                        waitForLauncherCondition("Launcher activity wasn't created",
-                                launcher -> launcher != null);
-
-                        executeOnLauncher(launcher ->
-                                launcher.getRotationHelper().forceAllowRotationForTesting(true));
-
-                        evaluateInPortrait();
-                        evaluateInLandscape();
-                    } finally {
-                        mDevice.setOrientationNatural();
-                        executeOnLauncher(launcher ->
-                                launcher.getRotationHelper().forceAllowRotationForTesting(false));
-                        mLauncher.setExpectedRotation(Surface.ROTATION_0);
-                    }
-                }
-
-                private void evaluateInPortrait() throws Throwable {
-                    mDevice.setOrientationNatural();
-                    mLauncher.setExpectedRotation(Surface.ROTATION_0);
-                    base.evaluate();
-                }
-
-                private void evaluateInLandscape() throws Throwable {
-                    mDevice.setOrientationLeft();
-                    mLauncher.setExpectedRotation(Surface.ROTATION_90);
-                    base.evaluate();
-                }
-            } : base;
-
     protected TestRule getRulesInsideActivityMonitor() {
-        return new FailureWatcher(this);
+        return RuleChain.
+                outerRule(new PortraitLandscapeRunner(this)).
+                around(new FailureWatcher(this));
     }
 
     @Rule
diff --git a/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java b/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java
new file mode 100644
index 0000000..20cd1e7
--- /dev/null
+++ b/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java
@@ -0,0 +1,63 @@
+package com.android.launcher3.ui;
+
+import android.view.Surface;
+
+import com.android.launcher3.tapl.TestHelpers;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+class PortraitLandscapeRunner implements TestRule {
+    private AbstractLauncherUiTest mTest;
+
+    public PortraitLandscapeRunner(AbstractLauncherUiTest test) {
+        mTest = test;
+    }
+
+    @Override
+    public Statement apply(Statement base, Description description) {
+        if (!TestHelpers.isInLauncherProcess() ||
+                description.getAnnotation(AbstractLauncherUiTest.PortraitLandscape.class) == null) {
+            return base;
+        }
+
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                try {
+                    mTest.mDevice.pressHome();
+                    mTest.waitForLauncherCondition("Launcher activity wasn't created",
+                            launcher -> launcher != null);
+
+                    mTest.executeOnLauncher(launcher ->
+                            launcher.getRotationHelper().forceAllowRotationForTesting(
+                                    true));
+
+                    evaluateInPortrait();
+                    evaluateInLandscape();
+                } finally {
+                    mTest.mDevice.setOrientationNatural();
+                    mTest.executeOnLauncher(launcher ->
+                            launcher.getRotationHelper().forceAllowRotationForTesting(
+                                    false));
+                    mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
+                }
+            }
+
+            private void evaluateInPortrait() throws Throwable {
+                mTest.mDevice.setOrientationNatural();
+                mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
+                base.evaluate();
+                mTest.mLauncher.pressHome();
+            }
+
+            private void evaluateInLandscape() throws Throwable {
+                mTest.mDevice.setOrientationLeft();
+                mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
+                base.evaluate();
+                mTest.mLauncher.pressHome();
+            }
+        };
+    }
+}
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index d171004..06c56f2 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -59,11 +59,7 @@
 
     public static void initialize(AbstractLauncherUiTest test) throws Exception {
         test.clearLauncherData();
-        if (TestHelpers.isInLauncherProcess()) {
-            test.mActivityMonitor.returnToHome();
-        } else {
-            test.mDevice.pressHome();
-        }
+        test.mDevice.pressHome();
         test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
         test.waitForState("Launcher internal state didn't switch to Home", LauncherState.NORMAL);
         test.waitForResumed("Launcher internal state is still Background");
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index a57d7ba..be27a66 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -190,7 +190,7 @@
         }
 
         // Go back to home
-        mActivityMonitor.returnToHome();
+        mLauncher.pressHome();
         Wait.atMost(null, new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT);
     }
 
diff --git a/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java b/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
index 145c3c8..2aba7a5 100644
--- a/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
+++ b/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
@@ -72,11 +72,6 @@
         getInstrumentation().startActivitySync(getHomeIntentInPackage(getTargetContext()));
     }
 
-    public void returnToHome() {
-        getTargetContext().startActivity(getHomeIntentInPackage(getTargetContext()));
-        getInstrumentation().waitForIdleSync();
-    }
-
     private class MyStatement extends Statement implements ActivityLifecycleCallbacks {
 
         private final Statement mBase;
diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java
index 6c46192..c9eaf27 100644
--- a/tests/tapl/com/android/launcher3/tapl/Background.java
+++ b/tests/tapl/com/android/launcher3/tapl/Background.java
@@ -87,16 +87,24 @@
             }
 
             case TWO_BUTTON: {
-                final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
-                final int startY = getSwipeStartY();
-                final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()).
-                        getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
+                final int startX;
+                final int startY;
+                final int endX;
+                final int endY;
+                final int swipeLength = mLauncher.getTestInfo(getSwipeHeightRequestName()).
+                        getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD) + mLauncher.getTouchSlop();
 
-                mLauncher.swipeToState(
-                        centerX, startY, centerX,
-                        startY - swipeHeight - mLauncher.getTouchSlop(),
-                        10,
-                        expectedState);
+                if (mLauncher.getDevice().isNaturalOrientation()) {
+                    startX = endX = mLauncher.getDevice().getDisplayWidth() / 2;
+                    startY = getSwipeStartY();
+                    endY = startY - swipeLength;
+                } else {
+                    startX = getSwipeStartX();
+                    endX = startX - swipeLength;
+                    startY = endY = mLauncher.getDevice().getDisplayHeight() / 2;
+                }
+
+                mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState);
                 break;
             }
 
@@ -111,6 +119,10 @@
         return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT;
     }
 
+    protected int getSwipeStartX() {
+        return mLauncher.getRealDisplaySize().x - 1;
+    }
+
     protected int getSwipeStartY() {
         return mLauncher.getRealDisplaySize().y - 1;
     }
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 2db9d08..22b04fb 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -122,7 +122,7 @@
     private static final String APPS_RES_ID = "apps_view";
     private static final String OVERVIEW_RES_ID = "overview_panel";
     private static final String WIDGETS_RES_ID = "widgets_list_view";
-    public static final int WAIT_TIME_MS = 10000;
+    public static final int WAIT_TIME_MS = 60000;
     private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
 
     private static WeakReference<VisibleContainer> sActiveContainer = new WeakReference<>(null);
@@ -333,7 +333,11 @@
                 "but the current state is not " + containerType.name())) {
             switch (containerType) {
                 case WORKSPACE: {
-                    waitForLauncherObject(APPS_RES_ID);
+                    if (mDevice.isNaturalOrientation()) {
+                        waitForLauncherObject(APPS_RES_ID);
+                    } else {
+                        waitUntilGone(APPS_RES_ID);
+                    }
                     waitUntilGone(OVERVIEW_RES_ID);
                     waitUntilGone(WIDGETS_RES_ID);
                     return waitForLauncherObject(WORKSPACE_RES_ID);
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 33754c1..26c7b8f 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -213,6 +213,8 @@
 
     @Override
     protected int getSwipeStartY() {
-        return mLauncher.waitForLauncherObject("hotseat").getVisibleBounds().top;
+        return mLauncher.getDevice().isNaturalOrientation() ?
+                mLauncher.waitForLauncherObject("hotseat").getVisibleBounds().top
+                : mLauncher.getRealDisplaySize().y - 1;
     }
 }
\ No newline at end of file