Merge "Add wrapper in scheduler, refactor the QuitRunnable"
diff --git a/src/com/android/tradefed/config/Configuration.java b/src/com/android/tradefed/config/Configuration.java
index fa0d183..93ec09d 100644
--- a/src/com/android/tradefed/config/Configuration.java
+++ b/src/com/android/tradefed/config/Configuration.java
@@ -1315,6 +1315,14 @@
     /** {@inheritDoc} */
     @Override
     public void dumpXml(PrintWriter output, List<String> excludeFilters) throws IOException {
+        dumpXml(output, excludeFilters, true);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void dumpXml(
+            PrintWriter output, List<String> excludeFilters, boolean printDeprecatedOptions)
+            throws IOException {
         KXmlSerializer serializer = new KXmlSerializer();
         serializer.setOutput(output);
         serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
@@ -1326,12 +1334,17 @@
                     serializer,
                     MULTI_PRE_TARGET_PREPARER_TYPE_NAME,
                     multiPreTargerPrep,
-                    excludeFilters);
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
 
         for (IMultiTargetPreparer multipreparer : getMultiTargetPreparers()) {
             ConfigurationUtil.dumpClassToXml(
-                    serializer, MULTI_PREPARER_TYPE_NAME, multipreparer, excludeFilters);
+                    serializer,
+                    MULTI_PREPARER_TYPE_NAME,
+                    multipreparer,
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
 
         if (getDeviceConfig().size() > 1) {
@@ -1346,80 +1359,132 @@
                         serializer,
                         BUILD_PROVIDER_TYPE_NAME,
                         deviceConfig.getBuildProvider(),
-                        excludeFilters);
+                        excludeFilters,
+                        printDeprecatedOptions);
                 for (ITargetPreparer preparer : deviceConfig.getTargetPreparers()) {
                     ConfigurationUtil.dumpClassToXml(
-                            serializer, TARGET_PREPARER_TYPE_NAME, preparer, excludeFilters);
+                            serializer,
+                            TARGET_PREPARER_TYPE_NAME,
+                            preparer,
+                            excludeFilters,
+                            printDeprecatedOptions);
                 }
                 ConfigurationUtil.dumpClassToXml(
                         serializer,
                         DEVICE_RECOVERY_TYPE_NAME,
                         deviceConfig.getDeviceRecovery(),
-                        excludeFilters);
+                        excludeFilters,
+                        printDeprecatedOptions);
                 ConfigurationUtil.dumpClassToXml(
                         serializer,
                         DEVICE_REQUIREMENTS_TYPE_NAME,
                         deviceConfig.getDeviceRequirements(),
-                        excludeFilters);
+                        excludeFilters,
+                        printDeprecatedOptions);
                 ConfigurationUtil.dumpClassToXml(
                         serializer,
                         DEVICE_OPTIONS_TYPE_NAME,
                         deviceConfig.getDeviceOptions(),
-                        excludeFilters);
+                        excludeFilters,
+                        printDeprecatedOptions);
                 serializer.endTag(null, Configuration.DEVICE_NAME);
             }
         } else {
             // Put single device tags
             ConfigurationUtil.dumpClassToXml(
-                    serializer, BUILD_PROVIDER_TYPE_NAME, getBuildProvider(), excludeFilters);
+                    serializer,
+                    BUILD_PROVIDER_TYPE_NAME,
+                    getBuildProvider(),
+                    excludeFilters,
+                    printDeprecatedOptions);
             for (ITargetPreparer preparer : getTargetPreparers()) {
                 ConfigurationUtil.dumpClassToXml(
-                        serializer, TARGET_PREPARER_TYPE_NAME, preparer, excludeFilters);
+                        serializer,
+                        TARGET_PREPARER_TYPE_NAME,
+                        preparer,
+                        excludeFilters,
+                        printDeprecatedOptions);
             }
             ConfigurationUtil.dumpClassToXml(
-                    serializer, DEVICE_RECOVERY_TYPE_NAME, getDeviceRecovery(), excludeFilters);
+                    serializer,
+                    DEVICE_RECOVERY_TYPE_NAME,
+                    getDeviceRecovery(),
+                    excludeFilters,
+                    printDeprecatedOptions);
             ConfigurationUtil.dumpClassToXml(
                     serializer,
                     DEVICE_REQUIREMENTS_TYPE_NAME,
                     getDeviceRequirements(),
-                    excludeFilters);
+                    excludeFilters,
+                    printDeprecatedOptions);
             ConfigurationUtil.dumpClassToXml(
-                    serializer, DEVICE_OPTIONS_TYPE_NAME, getDeviceOptions(), excludeFilters);
+                    serializer,
+                    DEVICE_OPTIONS_TYPE_NAME,
+                    getDeviceOptions(),
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
         for (IRemoteTest test : getTests()) {
-            ConfigurationUtil.dumpClassToXml(serializer, TEST_TYPE_NAME, test, excludeFilters);
+            ConfigurationUtil.dumpClassToXml(
+                    serializer, TEST_TYPE_NAME, test, excludeFilters, printDeprecatedOptions);
         }
         ConfigurationUtil.dumpClassToXml(
                 serializer,
                 CONFIGURATION_DESCRIPTION_TYPE_NAME,
                 getConfigurationDescription(),
-                excludeFilters);
+                excludeFilters,
+                printDeprecatedOptions);
         ConfigurationUtil.dumpClassToXml(
-                serializer, LOGGER_TYPE_NAME, getLogOutput(), excludeFilters);
+                serializer,
+                LOGGER_TYPE_NAME,
+                getLogOutput(),
+                excludeFilters,
+                printDeprecatedOptions);
         ConfigurationUtil.dumpClassToXml(
-                serializer, LOG_SAVER_TYPE_NAME, getLogSaver(), excludeFilters);
+                serializer,
+                LOG_SAVER_TYPE_NAME,
+                getLogSaver(),
+                excludeFilters,
+                printDeprecatedOptions);
         for (ITestInvocationListener listener : getTestInvocationListeners()) {
             ConfigurationUtil.dumpClassToXml(
-                    serializer, RESULT_REPORTER_TYPE_NAME, listener, excludeFilters);
+                    serializer,
+                    RESULT_REPORTER_TYPE_NAME,
+                    listener,
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
         ConfigurationUtil.dumpClassToXml(
-                serializer, CMD_OPTIONS_TYPE_NAME, getCommandOptions(), excludeFilters);
+                serializer,
+                CMD_OPTIONS_TYPE_NAME,
+                getCommandOptions(),
+                excludeFilters,
+                printDeprecatedOptions);
 
         for (IMetricCollector collector : getMetricCollectors()) {
             ConfigurationUtil.dumpClassToXml(
-                    serializer, DEVICE_METRICS_COLLECTOR_TYPE_NAME, collector, excludeFilters);
+                    serializer,
+                    DEVICE_METRICS_COLLECTOR_TYPE_NAME,
+                    collector,
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
 
         for (ISystemStatusChecker checker : getSystemStatusCheckers()) {
             ConfigurationUtil.dumpClassToXml(
-                    serializer, SYSTEM_STATUS_CHECKER_TYPE_NAME, checker, excludeFilters);
+                    serializer,
+                    SYSTEM_STATUS_CHECKER_TYPE_NAME,
+                    checker,
+                    excludeFilters,
+                    printDeprecatedOptions);
         }
 
         ConfigurationUtil.dumpClassToXml(
                 serializer,
                 SANBOX_OPTIONS_TYPE_NAME,
                 getConfigurationObject(SANBOX_OPTIONS_TYPE_NAME),
-                excludeFilters);
+                excludeFilters,
+                printDeprecatedOptions);
 
         serializer.endTag(null, ConfigurationUtil.CONFIGURATION_NAME);
         serializer.endDocument();
diff --git a/src/com/android/tradefed/config/ConfigurationUtil.java b/src/com/android/tradefed/config/ConfigurationUtil.java
index c6038f0..f162181 100644
--- a/src/com/android/tradefed/config/ConfigurationUtil.java
+++ b/src/com/android/tradefed/config/ConfigurationUtil.java
@@ -71,14 +71,17 @@
      * @param excludeClassFilter list of object configuration type or fully qualified class names to
      *     be excluded from the dump. for example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}.
      *     com.android.tradefed.testtype.StubTest
+     * @param printDeprecatedOptions whether or not to print deprecated options
      */
     static void dumpClassToXml(
             KXmlSerializer serializer,
             String classTypeName,
             Object obj,
-            List<String> excludeClassFilter)
+            List<String> excludeClassFilter,
+            boolean printDeprecatedOptions)
             throws IOException {
-        dumpClassToXml(serializer, classTypeName, obj, false, excludeClassFilter);
+        dumpClassToXml(
+                serializer, classTypeName, obj, false, excludeClassFilter, printDeprecatedOptions);
     }
 
     /**
@@ -91,13 +94,15 @@
      * @param excludeClassFilter list of object configuration type or fully qualified class names to
      *     be excluded from the dump. for example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}.
      *     com.android.tradefed.testtype.StubTest
+     * @param printDeprecatedOptions whether or not to print deprecated options
      */
     static void dumpClassToXml(
             KXmlSerializer serializer,
             String classTypeName,
             Object obj,
             boolean isGenericObject,
-            List<String> excludeClassFilter)
+            List<String> excludeClassFilter,
+            boolean printDeprecatedOptions)
             throws IOException {
         if (excludeClassFilter.contains(classTypeName)) {
             return;
@@ -109,12 +114,12 @@
             serializer.startTag(null, "object");
             serializer.attribute(null, "type", classTypeName);
             serializer.attribute(null, CLASS_NAME, obj.getClass().getName());
-            dumpOptionsToXml(serializer, obj);
+            dumpOptionsToXml(serializer, obj, printDeprecatedOptions);
             serializer.endTag(null, "object");
         } else {
             serializer.startTag(null, classTypeName);
             serializer.attribute(null, CLASS_NAME, obj.getClass().getName());
-            dumpOptionsToXml(serializer, obj);
+            dumpOptionsToXml(serializer, obj, printDeprecatedOptions);
             serializer.endTag(null, classTypeName);
         }
     }
@@ -124,11 +129,19 @@
      *
      * @param serializer a {@link KXmlSerializer} to create the XML dump
      * @param obj {@link Object} to be added to the XML dump
+     * @param printDeprecatedOptions whether or not to skip the deprecated options
      */
     @SuppressWarnings({"rawtypes", "unchecked"})
-    private static void dumpOptionsToXml(KXmlSerializer serializer, Object obj) throws IOException {
+    private static void dumpOptionsToXml(
+            KXmlSerializer serializer, Object obj, boolean printDeprecatedOptions)
+            throws IOException {
         for (Field field : OptionSetter.getOptionFieldsForClass(obj.getClass())) {
             Option option = field.getAnnotation(Option.class);
+            Deprecated deprecatedAnnotation = field.getAnnotation(Deprecated.class);
+            // If enabled, skip @Deprecated options
+            if (!printDeprecatedOptions && deprecatedAnnotation != null) {
+                continue;
+            }
             Object fieldVal = OptionSetter.getFieldValue(field, obj);
             if (fieldVal == null) {
                 continue;
diff --git a/src/com/android/tradefed/config/GlobalConfiguration.java b/src/com/android/tradefed/config/GlobalConfiguration.java
index aac2394..daf6ebc 100644
--- a/src/com/android/tradefed/config/GlobalConfiguration.java
+++ b/src/com/android/tradefed/config/GlobalConfiguration.java
@@ -802,7 +802,7 @@
                 isGenericObject = true;
             }
             ConfigurationUtil.dumpClassToXml(
-                    serializer, config, configObj, isGenericObject, new ArrayList<>());
+                    serializer, config, configObj, isGenericObject, new ArrayList<>(), true);
         }
         serializer.endTag(null, ConfigurationUtil.CONFIGURATION_NAME);
         serializer.endDocument();
diff --git a/src/com/android/tradefed/config/IConfiguration.java b/src/com/android/tradefed/config/IConfiguration.java
index d33127f..a22c7dd 100644
--- a/src/com/android/tradefed/config/IConfiguration.java
+++ b/src/com/android/tradefed/config/IConfiguration.java
@@ -581,4 +581,19 @@
      * @throws IOException
      */
     public void dumpXml(PrintWriter output, List<String> excludeFilters) throws IOException;
+
+    /**
+     * Gets the expanded XML file for the config with all options shown for this {@link
+     * IConfiguration} minus the objects filters by their key name.
+     *
+     * <p>Filter example: {@link Configuration#TARGET_PREPARER_TYPE_NAME}.
+     *
+     * @param output the writer to print the xml to.
+     * @param excludeFilters the list of object type that should not be dumped.
+     * @param printDeprecatedOptions Whether or not to print options marked as deprecated
+     * @throws IOException
+     */
+    public void dumpXml(
+            PrintWriter output, List<String> excludeFilters, boolean printDeprecatedOptions)
+            throws IOException;
 }
diff --git a/src/com/android/tradefed/device/cloud/GceManager.java b/src/com/android/tradefed/device/cloud/GceManager.java
index 1d62448..6f0212e 100644
--- a/src/com/android/tradefed/device/cloud/GceManager.java
+++ b/src/com/android/tradefed/device/cloud/GceManager.java
@@ -421,12 +421,40 @@
             IRunUtil runUtil,
             String remoteFilePath,
             LogDataType type) {
+        logNestedRemoteFile(logger, gceAvd, options, runUtil, remoteFilePath, type, null);
+    }
+
+    /**
+     * Fetch a remote file from a nested instance and log it.
+     *
+     * @param logger The {@link ITestLogger} where to log the file.
+     * @param gceAvd The {@link GceAvdInfo} that describe the device.
+     * @param options a {@link TestDeviceOptions} describing the device options to be used for the
+     *     GCE device.
+     * @param runUtil a {@link IRunUtil} to execute commands.
+     * @param remoteFilePath The remote path where to find the file.
+     * @param type the {@link LogDataType} of the logged file.
+     * @param baseName The base name to use to log the file. If null the actual file name will be
+     *     used.
+     */
+    public static void logNestedRemoteFile(
+            ITestLogger logger,
+            GceAvdInfo gceAvd,
+            TestDeviceOptions options,
+            IRunUtil runUtil,
+            String remoteFilePath,
+            LogDataType type,
+            String baseName) {
         File remoteFile =
                 RemoteFileUtil.fetchRemoteFile(
                         gceAvd, options, runUtil, REMOTE_FILE_OP_TIMEOUT, remoteFilePath);
         if (remoteFile != null) {
             try (InputStreamSource remoteFileStream = new FileInputStreamSource(remoteFile, true)) {
-                logger.testLog(remoteFile.getName(), type, remoteFileStream);
+                String name = baseName;
+                if (name == null) {
+                    name = remoteFile.getName();
+                }
+                logger.testLog(name, type, remoteFileStream);
             }
         }
     }
diff --git a/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java b/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
index e71751a..8c8d6f8 100644
--- a/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
+++ b/src/com/android/tradefed/device/cloud/RemoteAndroidVirtualDevice.java
@@ -199,17 +199,25 @@
                 // Capture extra cuttlefish specific logs
                 if (InstanceType.CUTTLEFISH.equals(getOptions().getInstanceType())
                         || InstanceType.REMOTE_NESTED_AVD.equals(getOptions().getInstanceType())) {
-                    LogRemoteFile(NESTED_REMOTE_LOG_DIR + "kernel.log", LogDataType.TEXT);
-                    LogRemoteFile(NESTED_REMOTE_LOG_DIR + "logcat", LogDataType.LOGCAT);
+                    LogRemoteFile(NESTED_REMOTE_LOG_DIR + "kernel.log", LogDataType.TEXT, null);
                     LogRemoteFile(
-                            NESTED_REMOTE_LOG_DIR + "cuttlefish_config.json", LogDataType.TEXT);
+                            NESTED_REMOTE_LOG_DIR + "logcat",
+                            LogDataType.LOGCAT,
+                            "full_gce_logcat");
+                    LogRemoteFile(
+                            NESTED_REMOTE_LOG_DIR + "cuttlefish_config.json",
+                            LogDataType.TEXT,
+                            null);
                 }
                 // Capture extra emulator specific logs
                 if (InstanceType.EMULATOR.equals(getOptions().getInstanceType())) {
-                    LogRemoteFile(EMULATOR_REMOTE_LOG_DIR + "logcat.log", LogDataType.LOGCAT);
-                    LogRemoteFile(EMULATOR_REMOTE_LOG_DIR + "adb.log", LogDataType.TEXT);
-                    LogRemoteFile(EMULATOR_REMOTE_LOG_DIR + "kernel.log", LogDataType.TEXT);
-                    LogRemoteFile("/var/log/daemon.log", LogDataType.TEXT);
+                    LogRemoteFile(
+                            EMULATOR_REMOTE_LOG_DIR + "logcat.log",
+                            LogDataType.LOGCAT,
+                            "full_gce_emulator_logcat");
+                    LogRemoteFile(EMULATOR_REMOTE_LOG_DIR + "adb.log", LogDataType.TEXT, null);
+                    LogRemoteFile(EMULATOR_REMOTE_LOG_DIR + "kernel.log", LogDataType.TEXT, null);
+                    LogRemoteFile("/var/log/daemon.log", LogDataType.TEXT, null);
                 }
 
                 // Cleanup GCE first to make sure ssh tunnel has nowhere to go.
@@ -234,10 +242,23 @@
         }
     }
 
-    /** Captures a log from the remote destination */
-    private void LogRemoteFile(String fileToRetrieve, LogDataType logType) {
+    /**
+     * Captures a log from the remote destination.
+     *
+     * @param fileToRetrieve The remote path to the file to pull.
+     * @param logType The expected type of the pulled log.
+     * @param baseName The base name that will be used to log the file, if null the actually file
+     *     name will be used.
+     */
+    private void LogRemoteFile(String fileToRetrieve, LogDataType logType, String baseName) {
         GceManager.logNestedRemoteFile(
-                mTestLogger, mGceAvd, getOptions(), getRunUtil(), fileToRetrieve, logType);
+                mTestLogger,
+                mGceAvd,
+                getOptions(),
+                getRunUtil(),
+                fileToRetrieve,
+                logType,
+                baseName);
     }
 
     /** Capture a remote bugreport by ssh-ing into the device directly. */
diff --git a/src/com/android/tradefed/device/metric/LogcatOnFailureCollector.java b/src/com/android/tradefed/device/metric/LogcatOnFailureCollector.java
index e8a3c50..0fe896c 100644
--- a/src/com/android/tradefed/device/metric/LogcatOnFailureCollector.java
+++ b/src/com/android/tradefed/device/metric/LogcatOnFailureCollector.java
@@ -35,6 +35,11 @@
 public class LogcatOnFailureCollector extends BaseDeviceMetricCollector {
 
     private static final int MAX_LOGAT_SIZE_BYTES = 4 * 1024 * 1024;
+    /** Always include a bit of prior data to capture what happened before */
+    private static final int OFFSET_CORRECTION = 20000;
+
+    private static final String NAME_FORMAT = "logcat-on-failure-%s-%s#%s";
+
     private Map<ITestDevice, ILogcatReceiver> mLogcatReceivers = new HashMap<>();
     private Map<ITestDevice, Integer> mOffset = new HashMap<>();
 
@@ -47,7 +52,7 @@
             mLogcatReceivers.put(device, receiver);
             receiver.start();
         }
-        getRunUtil().sleep(200);
+        getRunUtil().sleep(100);
         for (ITestDevice device : getDevices()) {
             mLogcatReceivers.get(device).clear();
         }
@@ -58,7 +63,11 @@
     public void onTestRunStart(DeviceMetricData runData) {
         for (ITestDevice device : getDevices()) {
             // Get the current offset of the buffer to be able to query later
-            mOffset.put(device, (int) mLogcatReceivers.get(device).getLogcatData().size());
+            int offset = (int) mLogcatReceivers.get(device).getLogcatData().size();
+            if (offset > OFFSET_CORRECTION) {
+                offset -= OFFSET_CORRECTION;
+            }
+            mOffset.put(device, offset);
         }
     }
 
@@ -76,12 +85,13 @@
                     mLogcatReceivers
                             .get(device)
                             .getLogcatData(MAX_LOGAT_SIZE_BYTES, mOffset.get(device))) {
-                super.testLog(
+                String name =
                         String.format(
-                                "logcat-on-failure-%s-%s#%s",
-                                device.getSerialNumber(), test.getClassName(), test.getTestName()),
-                        LogDataType.LOGCAT,
-                        logcatSource);
+                                NAME_FORMAT,
+                                device.getSerialNumber(),
+                                test.getClassName(),
+                                test.getTestName());
+                super.testLog(name, LogDataType.LOGCAT, logcatSource);
             }
         }
     }
diff --git a/src/com/android/tradefed/invoker/RemoteInvocationExecution.java b/src/com/android/tradefed/invoker/RemoteInvocationExecution.java
index 6d61427..a5ac579 100644
--- a/src/com/android/tradefed/invoker/RemoteInvocationExecution.java
+++ b/src/com/android/tradefed/invoker/RemoteInvocationExecution.java
@@ -63,11 +63,12 @@
 
     public static final long PUSH_TF_TIMEOUT = 120000L;
     public static final long PULL_RESULT_TIMEOUT = 180000L;
+    public static final long REMOTE_PROCESS_RUNNING_WAIT = 15000L;
 
     public static final String REMOTE_USER_DIR = "/home/{$USER}/";
     public static final String PROTO_RESULT_NAME = "output.pb";
-    public static final String STDOUT_FILE = "stdout.txt";
-    public static final String STDERR_FILE = "stderr.txt";
+    public static final String STDOUT_FILE = "remote-tradefed-stdout.txt";
+    public static final String STDERR_FILE = "remote-tradefed-stderr.txt";
 
     private String mRemoteTradefedDir = null;
     private String mRemoteFinalResult = null;
@@ -322,7 +323,7 @@
                 break;
             }
             if (stillRunning) {
-                RunUtil.getDefault().sleep(15000L);
+                RunUtil.getDefault().sleep(REMOTE_PROCESS_RUNNING_WAIT);
             }
         }
         File resultFile = null;
@@ -371,7 +372,8 @@
 
         if (resultFile != null) {
             // Report result to listener.
-            ProtoResultParser parser = new ProtoResultParser(currentInvocationListener, false);
+            ProtoResultParser parser =
+                    new ProtoResultParser(currentInvocationListener, false, "remote-");
             parser.processFinalizedProto(TestRecordProtoUtil.readFromFile(resultFile));
         }
     }
diff --git a/src/com/android/tradefed/result/proto/ProtoResultParser.java b/src/com/android/tradefed/result/proto/ProtoResultParser.java
index d9cc4ed..fac3e82 100644
--- a/src/com/android/tradefed/result/proto/ProtoResultParser.java
+++ b/src/com/android/tradefed/result/proto/ProtoResultParser.java
@@ -55,13 +55,22 @@
     private boolean mReportInvocation = false;
     /** The invocation context */
     private IInvocationContext mContext;
+    /** Prefix that will be added to the files logged through the parser. */
+    private String mFilePrefix;
 
     private boolean mQuietParsing = true;
 
     /** Ctor. */
     public ProtoResultParser(ITestInvocationListener listener, boolean reportInvocation) {
+        this(listener, reportInvocation, "subprocess-");
+    }
+
+    /** Ctor. */
+    public ProtoResultParser(
+            ITestInvocationListener listener, boolean reportInvocation, String prefixForFile) {
         mListener = listener;
         mReportInvocation = reportInvocation;
+        mFilePrefix = prefixForFile;
     }
 
     /** Sets whether or not to print when events are received. */
@@ -350,11 +359,11 @@
                             type = LogDataType.ZIP;
                         }
                         log("Logging %s from subprocess: %s ", entry.getKey(), file.getPath());
-                        logger.testLog("subprocess-" + entry.getKey(), type, source);
+                        logger.testLog(mFilePrefix + entry.getKey(), type, source);
                     }
                 } else {
                     log("Logging %s from subprocess: %s", entry.getKey(), file.getUrl());
-                    logger.logAssociation("subprocess-" + entry.getKey(), file);
+                    logger.logAssociation(mFilePrefix + entry.getKey(), file);
                 }
             } catch (InvalidProtocolBufferException e) {
                 CLog.e("Couldn't unpack %s as a LogFileInfo", entry.getKey());
diff --git a/src/com/android/tradefed/result/proto/StreamProtoReceiver.java b/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
index 1d2cc71..89870f4 100644
--- a/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
+++ b/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
@@ -63,8 +63,26 @@
     public StreamProtoReceiver(
             ITestInvocationListener listener, boolean reportInvocation, boolean quietParsing)
             throws IOException {
+        this(listener, reportInvocation, quietParsing, "subprocess-");
+    }
+
+    /**
+     * Ctor.
+     *
+     * @param listener the {@link ITestInvocationListener} where to report the results.
+     * @param reportInvocation Whether or not to report the invocation level events.
+     * @param quietParsing Whether or not to let the parser log debug information.
+     * @param logNamePrefix The prefix for file logged through the parser.
+     * @throws IOException
+     */
+    public StreamProtoReceiver(
+            ITestInvocationListener listener,
+            boolean reportInvocation,
+            boolean quietParsing,
+            String logNamePrefix)
+            throws IOException {
         mListener = listener;
-        mParser = new ProtoResultParser(mListener, reportInvocation);
+        mParser = new ProtoResultParser(mListener, reportInvocation, logNamePrefix);
         mParser.setQuiet(quietParsing);
         mEventReceiver = new EventReceiverThread();
         mEventReceiver.start();
diff --git a/src/com/android/tradefed/sandbox/TradefedSandbox.java b/src/com/android/tradefed/sandbox/TradefedSandbox.java
index 0f69ab9..339163b 100644
--- a/src/com/android/tradefed/sandbox/TradefedSandbox.java
+++ b/src/com/android/tradefed/sandbox/TradefedSandbox.java
@@ -268,7 +268,7 @@
             // TODO: switch reporting of parent and subprocess to proto
             String commandLine = config.getCommandLine();
             if (getSandboxOptions(config).shouldUseProtoReporter()) {
-                mProtoReceiver = new StreamProtoReceiver(listener, false, false);
+                mProtoReceiver = new StreamProtoReceiver(listener, false, false, "sandbox-");
                 // Force the child to the same mode as the parent.
                 commandLine = commandLine + " --" + SandboxOptions.USE_PROTO_REPORTER;
             } else {
@@ -398,7 +398,8 @@
             File tmpParentConfig =
                     FileUtil.createTempFile("parent-config", ".xml", mSandboxTmpFolder);
             PrintWriter pw = new PrintWriter(tmpParentConfig);
-            parentConfig.dumpXml(pw);
+            // Do not print deprecated options to avoid compatibility issues
+            parentConfig.dumpXml(pw, new ArrayList<>(), false);
             return tmpParentConfig;
         } catch (ConfigurationException | IOException e) {
             CLog.e("Parent doesn't understand the command either:");
diff --git a/src/com/android/tradefed/testtype/InstrumentationTest.java b/src/com/android/tradefed/testtype/InstrumentationTest.java
index 891ec38..d4dee84 100644
--- a/src/com/android/tradefed/testtype/InstrumentationTest.java
+++ b/src/com/android/tradefed/testtype/InstrumentationTest.java
@@ -847,6 +847,9 @@
                 if (collector.isDisabled()) {
                     CLog.d("%s has been disabled. Skipping.", collector);
                 } else {
+                    CLog.d(
+                            "Initializing %s for instrumentation.",
+                            collector.getClass().getCanonicalName());
                     listener = collector.init(mContext, listener);
                 }
             }
diff --git a/src/com/android/tradefed/testtype/suite/GranularRetriableTestWrapper.java b/src/com/android/tradefed/testtype/suite/GranularRetriableTestWrapper.java
index c687c0c..3a294d3 100644
--- a/src/com/android/tradefed/testtype/suite/GranularRetriableTestWrapper.java
+++ b/src/com/android/tradefed/testtype/suite/GranularRetriableTestWrapper.java
@@ -259,6 +259,7 @@
         try {
             CLog.d("Starting intra-module retry.");
             for (int attemptNumber = 1; attemptNumber < mMaxRunLimit; attemptNumber++) {
+                CLog.d("Retry attempt number %s", attemptNumber);
                 // Reset the filters to original.
                 if (mTest instanceof ITestFilterReceiver) {
                     ((ITestFilterReceiver) mTest).clearIncludeFilters();
diff --git a/tests/src/com/android/tradefed/config/ConfigurationUtilTest.java b/tests/src/com/android/tradefed/config/ConfigurationUtilTest.java
index e978ad3..75535e4 100644
--- a/tests/src/com/android/tradefed/config/ConfigurationUtilTest.java
+++ b/tests/src/com/android/tradefed/config/ConfigurationUtilTest.java
@@ -20,8 +20,14 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import com.android.tradefed.build.IBuildInfo;
 import com.android.tradefed.command.CommandScheduler;
 import com.android.tradefed.device.DeviceManager;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.targetprep.BuildError;
+import com.android.tradefed.targetprep.ITargetPreparer;
+import com.android.tradefed.targetprep.TargetSetupError;
 import com.android.tradefed.util.FileUtil;
 
 import org.junit.Test;
@@ -41,8 +47,8 @@
     private static final String DEVICE_MANAGER_TYPE_NAME = "device_manager";
 
     /**
-     * Test {@link ConfigurationUtil#dumpClassToXml(KXmlSerializer, String, Object, List)} to create
-     * a dump of a configuration.
+     * Test {@link ConfigurationUtil#dumpClassToXml(KXmlSerializer, String, Object, List, boolean)}
+     * to create a dump of a configuration.
      */
     @Test
     public void testDumpClassToXml() throws Throwable {
@@ -57,7 +63,11 @@
 
             DeviceManager deviceManager = new DeviceManager();
             ConfigurationUtil.dumpClassToXml(
-                    serializer, DEVICE_MANAGER_TYPE_NAME, deviceManager, new ArrayList<String>());
+                    serializer,
+                    DEVICE_MANAGER_TYPE_NAME,
+                    deviceManager,
+                    new ArrayList<String>(),
+                    true);
 
             serializer.endTag(null, ConfigurationUtil.CONFIGURATION_NAME);
             serializer.endDocument();
@@ -77,8 +87,8 @@
     }
 
     /**
-     * Test {@link ConfigurationUtil#dumpClassToXml(KXmlSerializer, String, Object, List)} to create
-     * a dump of a configuration with filters
+     * Test {@link ConfigurationUtil#dumpClassToXml(KXmlSerializer, String, Object, List, boolean)}
+     * to create a dump of a configuration with filters
      */
     @Test
     public void testDumpClassToXml_filtered() throws Throwable {
@@ -96,12 +106,14 @@
                     serializer,
                     GlobalConfiguration.DEVICE_MANAGER_TYPE_NAME,
                     deviceManager,
-                    Arrays.asList("com.android.tradefed.device.DeviceManager"));
+                    Arrays.asList("com.android.tradefed.device.DeviceManager"),
+                    true);
             ConfigurationUtil.dumpClassToXml(
                     serializer,
                     GlobalConfiguration.SCHEDULER_TYPE_NAME,
                     new CommandScheduler(),
-                    Arrays.asList("com.android.tradefed.device.DeviceManager"));
+                    Arrays.asList("com.android.tradefed.device.DeviceManager"),
+                    true);
 
             serializer.endTag(null, ConfigurationUtil.CONFIGURATION_NAME);
             serializer.endDocument();
@@ -236,4 +248,60 @@
             FileUtil.recursiveDelete(tmpDir);
         }
     }
+
+    private class TestTargetPreparer implements ITargetPreparer {
+
+        @Option(name = "real-option")
+        private boolean mReal;
+
+        @Deprecated
+        @Option(name = "deprecated-option")
+        private boolean mDeprecated;
+
+        @Override
+        public void setUp(ITestDevice device, IBuildInfo buildInfo)
+                throws TargetSetupError, BuildError, DeviceNotAvailableException {
+            // Should never be called
+            assertTrue(false);
+        }
+    }
+
+    /** Test that an option annotated with deprecated is properly filtered. */
+    @Test
+    public void testDumpClassToXml_filterDeprecated() throws Throwable {
+        File tmpXml = FileUtil.createTempFile("global_config", ".xml");
+        try {
+            PrintWriter output = new PrintWriter(tmpXml);
+            KXmlSerializer serializer = new KXmlSerializer();
+            serializer.setOutput(output);
+            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+            serializer.startDocument("UTF-8", null);
+            serializer.startTag(null, ConfigurationUtil.CONFIGURATION_NAME);
+
+            ITargetPreparer preparer = new TestTargetPreparer();
+            ConfigurationUtil.dumpClassToXml(
+                    serializer,
+                    Configuration.TARGET_PREPARER_TYPE_NAME,
+                    preparer,
+                    new ArrayList<String>(),
+                    false);
+
+            serializer.endTag(null, ConfigurationUtil.CONFIGURATION_NAME);
+            serializer.endDocument();
+
+            // Read the dump XML file, make sure configurations can be loaded.
+            String content = FileUtil.readStringFromFile(tmpXml);
+            assertTrue(content.length() > 100);
+            assertTrue(content.contains("<configuration>"));
+            assertTrue(content.contains("<option name=\"real-option\" value=\"false\" />"));
+            // Does not contain any trace of the deprecated option
+            assertFalse(content.contains("deprecated-option"));
+            assertTrue(
+                    content.contains(
+                            "<target_preparer class=\"com.android.tradefed.config."
+                                    + "ConfigurationUtilTest$TestTargetPreparer\">"));
+        } finally {
+            FileUtil.deleteFile(tmpXml);
+        }
+    }
 }
diff --git a/tests/src/com/android/tradefed/config/OptionSetterTest.java b/tests/src/com/android/tradefed/config/OptionSetterTest.java
index 78f73ee..255eb7a 100644
--- a/tests/src/com/android/tradefed/config/OptionSetterTest.java
+++ b/tests/src/com/android/tradefed/config/OptionSetterTest.java
@@ -266,14 +266,6 @@
         private final String mFinal= "foo";
     }
 
-    private static class RemoteFileOption {
-        @Option(name = "remote-file")
-        public File remoteFile = null;
-
-        @Option(name = "remote-file-list")
-        public Collection<File> remoteFileList = new ArrayList<>();
-    }
-
     /**
      * Test creating an {@link OptionSetter} for a source with invalid option type.
      */