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.layers 18 19 import com.android.server.wm.traces.common.ITrace 20 21 /** 22 * Contains a collection of parsed Layers trace entries and assertions to apply over a single entry. 23 * 24 * Each entry is parsed into a list of [LayerTraceEntry] objects. 25 * 26 * This is a generic object that is reused by both Flicker and Winscope and cannot 27 * access internal Java/Android functionality 28 * 29 */ 30 data class LayersTrace( 31 override val entries: Array<BaseLayerTraceEntry> 32 ) : ITrace<BaseLayerTraceEntry>, List<BaseLayerTraceEntry> by entries.toList() { 33 constructor(entry: BaseLayerTraceEntry): this(arrayOf(entry)) 34 toStringnull35 override fun toString(): String { 36 return "LayersTrace(Start: ${entries.firstOrNull()}, " + 37 "End: ${entries.lastOrNull()})" 38 } 39 equalsnull40 override fun equals(other: Any?): Boolean { 41 if (this === other) return true 42 if (other !is LayersTrace) return false 43 44 if (!entries.contentEquals(other.entries)) return false 45 46 return true 47 } 48 hashCodenull49 override fun hashCode(): Int { 50 var result = entries.contentHashCode() 51 return result 52 } 53 54 /** 55 * Split the trace by the start and end timestamp. 56 * 57 * @param from the start timestamp 58 * @param to the end timestamp 59 * @return the subtrace trace(from, to) 60 */ filternull61 fun filter(from: Long, to: Long): LayersTrace { 62 return LayersTrace( 63 this.entries 64 .dropWhile { it.timestamp < from } 65 .dropLastWhile { it.timestamp > to } 66 .toTypedArray() 67 ) 68 } 69 }