Taking screenshots for local tests for FallbackRecentsTest

Change-Id: I604e7e90f2146069827b520d44db1854edc7aa77
diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
index 0135911..e5f949b 100644
--- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
+++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java
@@ -43,10 +43,12 @@
 
 import com.android.launcher3.tapl.LauncherInstrumentation;
 import com.android.launcher3.testcomponent.TestCommandReceiver;
+import com.android.launcher3.util.rule.FailureWatcher;
 import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
 
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.RuleChain;
 import org.junit.rules.TestRule;
 import org.junit.runner.RunWith;
 import org.junit.runners.model.Statement;
@@ -62,10 +64,14 @@
     private final LauncherInstrumentation mLauncher;
     private final ActivityInfo mOtherLauncherActivity;
 
-    @Rule public final TestRule mDisableHeadsUpNotification = disableHeadsUpNotification();
-    @Rule public final TestRule mQuickstepOnOffExecutor;
+    @Rule
+    public final TestRule mDisableHeadsUpNotification = disableHeadsUpNotification();
 
-    @Rule public final TestRule mSetLauncherCommand;
+    @Rule
+    public final TestRule mSetLauncherCommand;
+
+    @Rule
+    public final TestRule mOrderSensitiveRules;
 
     public FallbackRecentsTest() throws RemoteException {
         Instrumentation instrumentation = getInstrumentation();
@@ -74,7 +80,10 @@
         mDevice.setOrientationNatural();
         mLauncher = new LauncherInstrumentation(instrumentation);
 
-        mQuickstepOnOffExecutor = new NavigationModeSwitchRule(mLauncher);
+        mOrderSensitiveRules = RuleChain.
+                outerRule(new NavigationModeSwitchRule(mLauncher)).
+                around(new FailureWatcher(mDevice));
+
         mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
                 getHomeIntentInPackage(context),
                 MATCH_DISABLED_COMPONENTS).get(0).activityInfo;
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index e663e70..4a0ca5c 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -125,7 +125,7 @@
     protected TestRule getRulesInsideActivityMonitor() {
         return RuleChain.
                 outerRule(new PortraitLandscapeRunner(this)).
-                around(new FailureWatcher(this));
+                around(new FailureWatcher(mDevice));
     }
 
     @Rule
diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
index 09cc98d..eef2f24 100644
--- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
+++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java
@@ -4,7 +4,7 @@
 
 import android.util.Log;
 
-import com.android.launcher3.ui.AbstractLauncherUiTest;
+import androidx.test.uiautomator.UiDevice;
 
 import org.junit.rules.TestWatcher;
 import org.junit.runner.Description;
@@ -16,16 +16,16 @@
 public class FailureWatcher extends TestWatcher {
     private static final String TAG = "FailureWatcher";
     private static int sScreenshotCount = 0;
-    private AbstractLauncherUiTest mAbstractLauncherUiTest;
+    final private UiDevice mDevice;
 
-    public FailureWatcher(AbstractLauncherUiTest abstractLauncherUiTest) {
-        mAbstractLauncherUiTest = abstractLauncherUiTest;
+    public FailureWatcher(UiDevice device) {
+        mDevice = device;
     }
 
     private void dumpViewHierarchy() {
         final ByteArrayOutputStream stream = new ByteArrayOutputStream();
         try {
-            mAbstractLauncherUiTest.getDevice().dumpWindowHierarchy(stream);
+            mDevice.dumpWindowHierarchy(stream);
             stream.flush();
             stream.close();
             for (String line : stream.toString().split("\\r?\\n")) {
@@ -38,7 +38,7 @@
 
     @Override
     protected void failed(Throwable e, Description description) {
-        if (mAbstractLauncherUiTest.getDevice() == null) return;
+        if (mDevice == null) return;
         final String pathname = getInstrumentation().getTargetContext().
                 getFilesDir().getPath() + "/TaplTestScreenshot" + sScreenshotCount++ + ".png";
         Log.e(TAG, "Failed test " + description.getMethodName() +
@@ -48,12 +48,12 @@
         dumpViewHierarchy();
 
         try {
-            final String dumpsysResult = mAbstractLauncherUiTest.getDevice().executeShellCommand(
+            final String dumpsysResult = mDevice.executeShellCommand(
                     "dumpsys activity service TouchInteractionService");
             Log.d(TAG, "TouchInteractionService: " + dumpsysResult);
         } catch (IOException ex) {
         }
 
-        mAbstractLauncherUiTest.getDevice().takeScreenshot(new File(pathname));
+        mDevice.takeScreenshot(new File(pathname));
     }
 }