Merge "TaskThumbnailView - post updates to overlays." into ub-launcher3-qt-dev
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/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