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 import com.android.tradefed.invoker.IInvocationContext;
19 
20 import java.io.IOException;
21 import java.io.InputStream;
22 
23 /**
24  * Classes which implement this interface provide methods for storing logs to a central location.
25  * <p>
26  * A {@link ILogSaver} is declared in the configuration and is responsible for storing logs to a
27  * central location. It also exposes methods so {@link ILogSaverListener}s may save additional files
28  * to the same location.
29  * </p>
30  */
31 public interface ILogSaver {
32 
33     /**
34      * Reports the start of the test invocation.
35      * <p>
36      * Will be automatically called by the TradeFederation framework before
37      * {@link ITestInvocationListener#invocationStarted(IInvocationContext)} is called.
38      * </p>
39      *
40      * @param context information about the invocation.
41      */
invocationStarted(IInvocationContext context)42     public void invocationStarted(IInvocationContext context);
43 
44     /**
45      * Reports that the invocation has terminated, whether successfully or due to some error
46      * condition.
47      * <p>
48      * Will be automatically called by the TradeFederation framework after
49      * {@link ITestInvocationListener#invocationEnded(long)} is called.
50      * </p>
51      *
52      * @param elapsedTime the elapsed time of the invocation in ms
53      */
invocationEnded(long elapsedTime)54     public void invocationEnded(long elapsedTime);
55 
56     /**
57      * Save the log data.
58      * <p>
59      * Will be automatically called by the TradeFederation framework whenever
60      * {@link ITestInvocationListener#testLog(String, LogDataType, InputStreamSource)} is called. It
61      * may also be used as a helper method to save additional log data.
62      * </p><p>
63      * Depending on the implementation and policy, the logs may be saved in a compressed form. Logs
64      * may also be stored in a location inaccessable to Tradefed.
65      * </p>
66      *
67      * @param dataName a {@link String} descriptive name of the data. e.g. "device_logcat"
68      * @param dataType the {@link LogDataType} of the file.
69      * @param dataStream the {@link InputStream} of the data.
70      * @return the {@link LogFile} containing the path and URL of the saved file.
71      * @throws IOException if log file could not be generated
72      */
saveLogData(String dataName, LogDataType dataType, InputStream dataStream)73     public LogFile saveLogData(String dataName, LogDataType dataType, InputStream dataStream)
74             throws IOException;
75 
76     /**
77      * A helper method to save the log data unmodified.
78      *
79      * <p>Logs may be stored in a location inaccessible to Tradefed.
80      *
81      * @param dataName a {@link String} descriptive name of the data. e.g. "device_logcat".
82      * @param type a {@link LogDataType} containing the type and the extension of the file
83      * @param dataStream the {@link InputStream} of the data.
84      * @return the {@link LogFile} containing the path and URL of the saved file.
85      * @throws IOException if log file could not be generated
86      */
saveLogDataRaw(String dataName, LogDataType type, InputStream dataStream)87     public LogFile saveLogDataRaw(String dataName, LogDataType type, InputStream dataStream)
88             throws IOException;
89 
90     /**
91      * Get the {@link LogFile} containing the path and/or URL of the directory where logs are saved.
92      *
93      * @return The {@link LogFile}.
94      */
getLogReportDir()95     public LogFile getLogReportDir();
96 }
97