Taking screenshot and view list ASAP after test failure

This helps to get accurate diags when, for example the normal test run is interrupted by a notification popup that goes on and off.

Bug: 202567877
Test: presubmit
Change-Id: I2fb27e8fcdb0f0e2aabebf84ca11874f9e1220c2
diff --git a/libraries/health/rules/src/android/platform/test/rule/ArtifactSaver.java b/libraries/health/rules/src/android/platform/test/rule/ArtifactSaver.java
index a3bf1bb..3b456fc 100644
--- a/libraries/health/rules/src/android/platform/test/rule/ArtifactSaver.java
+++ b/libraries/health/rules/src/android/platform/test/rule/ArtifactSaver.java
@@ -60,6 +60,15 @@
         final File screenshot = artifactFile(description, "TestScreenshot", "png");
         final File hierarchy = artifactFile(description, "Hierarchy", "zip");
 
+        device.takeScreenshot(screenshot);
+
+        // Dump accessibility hierarchy
+        try {
+            device.dumpWindowHierarchy(artifactFile(description, "AccessibilityHierarchy", "uix"));
+        } catch (Exception ex) {
+            android.util.Log.e(TAG, "Failed to save accessibility hierarchy", ex);
+        }
+
         // Dump window hierarchy
         try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(hierarchy))) {
             out.putNextEntry(new ZipEntry("bugreport.txt"));
@@ -83,14 +92,6 @@
                         + hierarchy
                         + " (use go/web-hv to open the dump file)",
                 e);
-        device.takeScreenshot(screenshot);
-
-        // Dump accessibility hierarchy
-        try {
-            device.dumpWindowHierarchy(artifactFile(description, "AccessibilityHierarchy", "uix"));
-        } catch (Exception ex) {
-            android.util.Log.e(TAG, "Failed to save accessibility hierarchy", ex);
-        }
 
         // Dump bugreport
         if (sShouldTakeBugreport && FailureWatcher.getSystemAnomalyMessage(device) != null) {