1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.tradefed.result; 17 18 /** 19 * Allows for {@link ITestInvocationListener}s to listen for when log files are saved. 20 * <p> 21 * This allows for multiple {@link ITestInvocationListener}s to use the same saved log file when 22 * generating reports, and avoids having each listener save the file individually when 23 * {@link ITestInvocationListener#testLog(String, LogDataType, InputStreamSource)} is called. 24 * </p><p> 25 * Classes implementing this interface should be aware that 26 * {@link #testLogSaved(String, LogDataType, InputStreamSource, LogFile)} will be called whenever 27 * {@link ITestInvocationListener#testLog(String, LogDataType, InputStreamSource)} is called. 28 * </p><p> 29 * This class also passes the global {@link ILogSaver} instance so {@link ITestInvocationListener}s 30 * can save additional files in the same location. 31 */ 32 public interface ILogSaverListener extends ITestInvocationListener { 33 34 /** 35 * Called when the test log is saved. 36 * <p> 37 * Should be used in place of 38 * {@link ITestInvocationListener#testLog(String, LogDataType, InputStreamSource)}. 39 * </p> 40 * @param dataName a {@link String} descriptive name of the data. e.g. "device_logcat". Note 41 * dataName may not be unique per invocation. ie implementers must be able to handle multiple 42 * calls with same dataName 43 * @param dataType the {@link LogDataType} of the data 44 * @param dataStream the {@link InputStreamSource} of the data. Implementers should call 45 * createInputStream to start reading the data, and ensure to close the resulting InputStream 46 * when complete. 47 * @param logFile the {@link LogFile} containing the meta data of the saved file. 48 */ testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)49 public void testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, 50 LogFile logFile); 51 52 /** 53 * In some cases, log must be strongly associated with a test cases, but the opportunity to do 54 * so on the direct {@link #testLogSaved(String, LogDataType, InputStreamSource, LogFile)} 55 * callback is not possible. Thus, this callback allows to provide a strong association 56 * explicitly. 57 * 58 * @param dataName The name of the data 59 * @param logFile the {@link LogFile} that was logged before and should be associated with the 60 * test case. 61 */ logAssociation(String dataName, LogFile logFile)62 public default void logAssociation(String dataName, LogFile logFile) { 63 // Do nothing by default 64 } 65 66 /** 67 * Set the {@link ILogSaver} to allow the implementor to save files. 68 * 69 * @param logSaver the {@link ILogSaver} 70 */ setLogSaver(ILogSaver logSaver)71 public void setLogSaver(ILogSaver logSaver); 72 } 73