Merge "Add test name as the file prefix for different test cases. Test: forret run"
diff --git a/test_scripts/src/main/java/com/android/pixel/OWNERS b/test_scripts/src/main/java/com/android/pixel/OWNERS
index 05ffe9a..aa4bbf9 100644
--- a/test_scripts/src/main/java/com/android/pixel/OWNERS
+++ b/test_scripts/src/main/java/com/android/pixel/OWNERS
@@ -1,2 +1,2 @@
 murphykuo@google.com
-huilingchi@google.com
+elisahsu@google.com
diff --git a/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java b/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
index 6c44a88..aa79bb5 100644
--- a/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
+++ b/test_scripts/src/main/java/com/android/pixel/tests/PixelAppCompatTestBase.java
@@ -33,7 +33,6 @@
 /** Base class for Pixel app compatibility tests. */
 public abstract class PixelAppCompatTestBase {
     private static final String KEY_PACKAGE_NAME = "package";
-
     private DeviceUtils mDeviceUtils;
     private UiDevice mDevice;
     private KeyguardManager mKeyguardManager;
@@ -41,6 +40,7 @@
 
     @Before
     public void setUp() throws Exception {
+        getDeviceUtils().setTestName(this.getClass().getSimpleName());
         getDeviceUtils().createLogDataDir();
         getDeviceUtils().wakeAndUnlockScreen();
         // Start from the home screen
diff --git a/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java b/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
index 9d29dbc..1b665e3 100644
--- a/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
+++ b/test_scripts/src/main/java/com/android/pixel/utils/DeviceUtils.java
@@ -25,11 +25,14 @@
 import android.support.test.uiautomator.UiDevice;
 import android.util.Log;
 
+import com.google.common.base.Preconditions;
+
 import org.junit.Assert;
 
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Paths;
+import java.util.Optional;
 
 public class DeviceUtils {
     private static final String TAG = DeviceUtils.class.getSimpleName();
@@ -39,6 +42,8 @@
     private static final long VIDEO_TAIL_BUFFER = 500;
     private static final String DISMISS_KEYGUARD = "wm dismiss-keyguard";
 
+    private String mFolderDir = LOG_DATA_DIR;
+    private String mTestName = TAG;
     private RecordingThread mCurrentThread;
     private File mLogDataDir;
     private UiDevice mDevice;
@@ -47,9 +52,24 @@
         mDevice = device;
     }
 
+    /**
+     * Sets the test name and the folder path for the current test.
+     *
+     * @param testName The test name.
+     */
+    public void setTestName(String testName) {
+        Optional<String> optionalTestName = Optional.ofNullable(testName);
+        if (optionalTestName.isPresent()) {
+            mTestName = optionalTestName.get();
+            mFolderDir = String.join("/", LOG_DATA_DIR, optionalTestName.get());
+        } else {
+            Preconditions.checkNotNull(testName, "testName cannot be null");
+        }
+    }
+
     /** Create a directory to save test screenshots, screenrecord and text files. */
     public void createLogDataDir() {
-        mLogDataDir = new File(LOG_DATA_DIR);
+        mLogDataDir = new File(mFolderDir);
         if (mLogDataDir.exists()) {
             String[] children = mLogDataDir.list();
             for (String file : children) {
@@ -104,8 +124,9 @@
     public void takeScreenshot(String packageName, String description) {
         File screenshot =
                 new File(
-                        LOG_DATA_DIR,
-                        String.format("%s_screenshot_%s.png", packageName, description));
+                        mFolderDir,
+                        String.format(
+                                "%s_%s_screenshot_%s.png", mTestName, packageName, description));
         mDevice.takeScreenshot(screenshot);
     }
 
@@ -118,7 +139,8 @@
         Log.v(TAG, "Started Recording");
         mCurrentThread =
                 new RecordingThread(
-                        "test-screen-record", String.format("%s_screenrecord", packageName));
+                        "test-screen-record",
+                        String.format("%s_%s_screenrecord", mTestName, packageName));
         mCurrentThread.start();
     }