1 /*
2  * Copyright (C) 2023 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 
17 package android.tools.io
18 
19 import android.tools.Tag
20 import android.tools.Timestamp
21 import android.tools.traces.events.CujTrace
22 import android.tools.traces.events.EventLog
23 import android.tools.traces.protolog.ProtoLogTrace
24 import android.tools.traces.surfaceflinger.LayersTrace
25 import android.tools.traces.surfaceflinger.TransactionsTrace
26 import android.tools.traces.wm.TransitionsTrace
27 import android.tools.traces.wm.WindowManagerTrace
28 
29 /** Helper class to read results from a flicker artifact */
30 interface Reader {
31     val artifact: Artifact
32     val artifactPath: String
33     val executionError: Throwable?
34     val runStatus: RunStatus
35     val isFailure: Boolean
36         get() = runStatus.isFailure
37 
38     /** @return a [WindowManagerTrace] from the dump associated to [tag] */
readWmStatenull39     fun readWmState(tag: String): WindowManagerTrace?
40 
41     /** @return a [WindowManagerTrace] for the part of the trace we want to run the assertions on */
42     fun readWmTrace(): WindowManagerTrace?
43 
44     /** @return a [LayersTrace] for the part of the trace we want to run the assertions on */
45     fun readLayersTrace(): LayersTrace?
46 
47     /** @return a [LayersTrace] from the dump associated to [tag] */
48     fun readLayersDump(tag: String): LayersTrace?
49 
50     /** @return a [TransactionsTrace] for the part of the trace we want to run the assertions on */
51     fun readTransactionsTrace(): TransactionsTrace?
52 
53     /** @return a [TransitionsTrace] for the part of the trace we want to run the assertions on */
54     fun readTransitionsTrace(): TransitionsTrace?
55 
56     /** @return an [EventLog] for the part of the trace we want to run the assertions on */
57     fun readEventLogTrace(): EventLog?
58 
59     /** @return a [CujTrace] for the part of the trace we want to run the assertions on */
60     fun readCujTrace(): CujTrace?
61 
62     /** @return a [ProtoLogTrace] for the part of the trace we want to run the assertions on */
63     fun readProtoLogTrace(): ProtoLogTrace?
64 
65     /** @return an [Reader] for the subsection of the trace we are reading in this reader */
66     fun slice(startTimestamp: Timestamp, endTimestamp: Timestamp): Reader
67 
68     /**
69      * @return [ByteArray] with the contents of a file from the artifact, or null if the file
70      *   doesn't exist
71      */
72     fun readBytes(traceType: TraceType, tag: String = Tag.ALL): ByteArray?
73 }
74