Deleting screen records for succeeded tests

Test: local runs
Bug: 187761685
Change-Id: I3b1a75b775d1d6677b331869a063fc6132217947
diff --git a/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java b/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
index 00b1cdd..7a5cf2c 100644
--- a/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
+++ b/tests/src/com/android/launcher3/util/rule/ScreenRecordRule.java
@@ -62,12 +62,17 @@
                 ParcelFileDescriptor output =
                         automation.executeShellCommand("screenrecord " + outputFile);
                 String screenRecordPid = device.executeShellCommand("pidof screenrecord");
+                boolean success = false;
                 try {
                     base.evaluate();
+                    success = true;
                 } finally {
                     device.executeShellCommand("kill -INT " + screenRecordPid);
                     Log.e(TAG, "Screenrecord captured at: " + outputFile);
                     output.close();
+                    if (success) {
+                        automation.executeShellCommand("rm " + outputFile);
+                    }
                 }
             }
         };
@@ -78,5 +83,6 @@
      */
     @Retention(RetentionPolicy.RUNTIME)
     @Target(ElementType.METHOD)
-    public @interface ScreenRecord { }
+    public @interface ScreenRecord {
+    }
 }