Making killing setup wizard a permanent solution

It will be killed only in presubmit. In postsubmit, we want to be a true
e2e test exposed to all actual problems, including setup wizard that
doesn't go away.

Bug: 309471958
Test: presubmit
Flag: N/A
Change-Id: I2e877eade060e75e277eb3603d90b659207b5a47
diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
index 281516c..17fa253 100644
--- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
+++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
@@ -162,7 +162,6 @@
     @Before
     public void setUp() {
         mLauncher.onTestStart();
-        AbstractLauncherUiTest.waitForSetupWizardDismissal();
         AbstractLauncherUiTest.onTestStart();
     }
 
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index 8847b8b..6296a97 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -105,12 +105,20 @@
     private static boolean sDumpWasGenerated = false;
     private static boolean sActivityLeakReported = false;
     private static boolean sSeenKeyguard = false;
+    private static boolean sFirstTimeWaitingForWizard = true;
 
     private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
 
     protected LooperExecutor mMainThreadExecutor = MAIN_EXECUTOR;
     protected final UiDevice mDevice = getUiDevice();
-    protected final LauncherInstrumentation mLauncher = new LauncherInstrumentation();
+    protected final LauncherInstrumentation mLauncher = createLauncherInstrumentation();
+
+    @NonNull
+    private static LauncherInstrumentation createLauncherInstrumentation() {
+        waitForSetupWizardDismissal(); // precondition for creating LauncherInstrumentation
+        return new LauncherInstrumentation();
+    }
+
     protected Context mTargetContext;
     protected String mTargetPackage;
     private int mLauncherPid;
@@ -249,8 +257,6 @@
     public void setUp() throws Exception {
         mLauncher.onTestStart();
 
-        waitForSetupWizardDismissal();
-
         final String launcherPackageName = mDevice.getLauncherPackageName();
         try {
             final Context context = InstrumentationRegistry.getContext();
@@ -286,6 +292,8 @@
 
     /** Method that should be called when a test starts. */
     public static void onTestStart() {
+        waitForSetupWizardDismissal();
+
         if (TestStabilityRule.isPresubmit()) {
             aggressivelyUnlockSysUi();
         } else {
@@ -320,18 +328,8 @@
         Log.d(TAG, "Keyguard is not visible");
     }
 
-    // b/309008042
-    private static boolean sFirstTimeWaitingForWizard = true;
-
-    // b/309008042
-    static {
-        waitForSetupWizardDismissal();
-    }
-
-    // b/309008042
-    // TODO(309471958) Productize killing/dismissal of setup wizard.
     /** Waits for setup wizard to go away. */
-    public static void waitForSetupWizardDismissal() {
+    private static void waitForSetupWizardDismissal() {
         if (!TestStabilityRule.isPresubmit()) return;
 
         if (sFirstTimeWaitingForWizard) {
@@ -464,7 +462,6 @@
     // flakiness.
     protected void waitForLauncherCondition(
             String message, Function<Launcher, Boolean> condition, long timeout) {
-        waitForSetupWizardDismissal();
         verifyKeyguardInvisible();
         if (!TestHelpers.isInLauncherProcess()) return;
         Wait.atMost(message, () -> getFromLauncher(condition), timeout, mLauncher);