• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 com.android.server.wm.traces.common.windowmanager
18 
19 import com.android.server.wm.traces.common.ITrace
20 
21 /**
22  * Contains a collection of parsed WindowManager trace entries and assertions to apply over a single
23  * entry.
24  *
25  * Each entry is parsed into a list of [WindowManagerState] objects.
26  *
27  * This is a generic object that is reused by both Flicker and Winscope and cannot
28  * access internal Java/Android functionality
29  *
30  */
31 data class WindowManagerTrace(
32     override val entries: Array<WindowManagerState>
33 ) : ITrace<WindowManagerState>,
<lambda>null34     List<WindowManagerState> by entries.toList() {
35     override fun toString(): String {
36         return "WindowManagerTrace(Start: ${entries.firstOrNull()}, " +
37             "End: ${entries.lastOrNull()})"
38     }
39 
40     override fun equals(other: Any?): Boolean {
41         if (this === other) return true
42         if (other !is WindowManagerTrace) return false
43 
44         if (!entries.contentEquals(other.entries)) return false
45 
46         return true
47     }
48 
49     override fun hashCode(): Int {
50         return entries.contentHashCode()
51     }
52 
53     /**
54      * Split the trace by the start and end timestamp.
55      *
56      * @param from the start timestamp
57      * @param to the end timestamp
58      * @return the subtrace trace(from, to)
59      */
60     fun filter(from: Long, to: Long): WindowManagerTrace {
61         return WindowManagerTrace(
62             this.entries
63                 .dropWhile { it.timestamp < from }
64                 .dropLastWhile { it.timestamp > to }
65                 .toTypedArray())
66     }
67 }