Merge "More readable formatting for events mismatch message" into ub-launcher3-master
diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
index dde318e..bd2c539 100644
--- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
+++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
@@ -56,6 +56,7 @@
 import com.android.launcher3.tapl.TestHelpers;
 import com.android.launcher3.testcomponent.TestCommandReceiver;
 import com.android.launcher3.util.Wait;
+import com.android.launcher3.util.rule.FailureRewriterRule;
 import com.android.launcher3.util.rule.FailureWatcher;
 import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
 import com.android.quickstep.views.RecentsView;
@@ -100,7 +101,9 @@
             Utilities.enableRunningInTestHarnessForTests();
         }
 
-        mOrderSensitiveRules = RuleChain.outerRule(new NavigationModeSwitchRule(mLauncher))
+        mOrderSensitiveRules = RuleChain
+                .outerRule(new FailureRewriterRule())
+                .around(new NavigationModeSwitchRule(mLauncher))
                 .around(new FailureWatcher(mDevice));
 
         mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
index 891bf24..3d048a6 100644
--- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
+++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java
@@ -18,9 +18,6 @@
 
 import static com.android.launcher3.util.RaceConditionReproducer.enterEvt;
 import static com.android.launcher3.util.RaceConditionReproducer.exitEvt;
-import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_PRESUBMIT;
-import static com.android.launcher3.util.rule.TestStabilityRule.RUN_FLAFOR;
-import static com.android.launcher3.util.rule.TestStabilityRule.UNBUNDLED_PRESUBMIT;
 
 import android.content.Intent;
 
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index f4334b0..19997eb 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -62,6 +62,7 @@
 import com.android.launcher3.util.LooperExecutor;
 import com.android.launcher3.util.PackageManagerHelper;
 import com.android.launcher3.util.Wait;
+import com.android.launcher3.util.rule.FailureRewriterRule;
 import com.android.launcher3.util.rule.FailureWatcher;
 import com.android.launcher3.util.rule.LauncherActivityRule;
 import com.android.launcher3.util.rule.ShellCommandRule;
@@ -162,9 +163,10 @@
 
     @Rule
     public TestRule mOrderSensitiveRules = RuleChain.
-            outerRule(new TestStabilityRule()).
-            around(mActivityMonitor).
-            around(getRulesInsideActivityMonitor());
+            outerRule(new FailureRewriterRule())
+            .around(new TestStabilityRule())
+            .around(mActivityMonitor)
+            .around(getRulesInsideActivityMonitor());
 
     public UiDevice getDevice() {
         return mDevice;
diff --git a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java
index 56c885d..831685a 100644
--- a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java
+++ b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java
@@ -47,6 +47,20 @@
                     logSinceTestsStart)) {
                 return 147845913;
             }
+        } else if (matches("java.lang.AssertionError: Launcher build match not found", exception)) {
+            if (matches(
+                    "TestStabilityRule: Launcher package: com.google.android.setupwizard",
+                    logSinceTestsStart)) {
+                return 145935261;
+            }
+        } else if (matches("Launcher didn't initialize", exception)) {
+            if (matches(
+                    "ActivityManager: Reason: executing service com.google.android.apps"
+                            + ".nexuslauncher/com.android.launcher3.notification"
+                            + ".NotificationListener",
+                    logSinceTestsStart)) {
+                return 148238677;
+            }
         }
 
         return 0;
diff --git a/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java
new file mode 100644
index 0000000..4cb309a
--- /dev/null
+++ b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.util.rule;
+
+import android.util.Log;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class FailureRewriterRule implements TestRule {
+    private static final String TAG = "FailureRewriter";
+
+    private static final String testsStartTime =
+            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
+
+    @Override
+    public Statement apply(Statement base, Description description) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                try {
+                    base.evaluate();
+                } catch (Throwable e) {
+                    final int bug =
+                            FailureInvestigator.getBugForFailure(e.toString(), testsStartTime);
+                    if (bug == 0) throw e;
+
+                    Log.e(TAG, "Known bug found for the original failure "
+                            + android.util.Log.getStackTraceString(e));
+                    throw new AssertionError(
+                            "Detected a failure that matches a known bug b/" + bug);
+                }
+            }
+        };
+    }
+}
diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
index feb89b9..cdda0f0 100644
--- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
+++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
@@ -8,13 +8,10 @@
 
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 
 public class FailureWatcher extends TestWatcher {
     private static final String TAG = "FailureWatcher";
@@ -38,30 +35,6 @@
         }
     }
 
-    private static final String testsStartTime =
-            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
-
-    @Override
-    public Statement apply(Statement base, Description description) {
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                try {
-                    base.evaluate();
-                } catch (Throwable e) {
-                    final int bug =
-                            FailureInvestigator.getBugForFailure(e.toString(), testsStartTime);
-                    if (bug == 0) throw e;
-
-                    Log.e(TAG, "Known bug found for the original failure "
-                            + android.util.Log.getStackTraceString(e));
-                    throw new AssertionError(
-                            "Detected a failure that matches a known bug b/" + bug);
-                }
-            }
-        };
-    }
-
     @Override
     protected void failed(Throwable e, Description description) {
         onError(mDevice, description, e);
diff --git a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java
index b394bcb..1feb4e7 100644
--- a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java
+++ b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java
@@ -58,7 +58,7 @@
     public static final int PLATFORM_PRESUBMIT = 0x8;
     public static final int PLATFORM_POSTSUBMIT = 0x10;
 
-    public static final int RUN_FLAFOR = getRunFlavor();
+    private static int sRunFlavor;
 
     @Retention(RetentionPolicy.RUNTIME)
     @Target(ElementType.METHOD)
@@ -73,7 +73,8 @@
             return new Statement() {
                 @Override
                 public void evaluate() throws Throwable {
-                    if ((stability.flavors() & RUN_FLAFOR) != 0) {
+                    if (sRunFlavor == 0) sRunFlavor = getRunFlavor();
+                    if ((stability.flavors() & sRunFlavor) != 0) {
                         Log.d(TAG, "Running " + description.getDisplayName());
                         base.evaluate();
                     } else {