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.traces.wm 18 19 import android.tools.traces.surfaceflinger.LayersTrace 20 21 class TransitionChange(val transitMode: TransitionType, val layerId: Int, val windowId: Int) { 22 toStringnull23 override fun toString(): String = Formatter(null, null).format(this) 24 25 override fun hashCode(): Int { 26 var result = transitMode.hashCode() 27 result = 31 * result + layerId 28 result = 31 * result + windowId 29 return result 30 } 31 equalsnull32 override fun equals(other: Any?): Boolean { 33 if (this === other) return true 34 if (other !is TransitionChange) return false 35 36 if (transitMode != other.transitMode) return false 37 if (layerId != other.layerId) return false 38 return windowId == other.windowId 39 } 40 41 class Formatter(val layersTrace: LayersTrace?, val wmTrace: WindowManagerTrace?) { formatnull42 fun format(change: TransitionChange): String { 43 val layerName = 44 layersTrace 45 ?.entries 46 ?.flatMap { it.flattenedLayers } 47 ?.firstOrNull { it.id == change.layerId } 48 ?.name 49 50 val windowName = 51 wmTrace 52 ?.entries 53 ?.flatMap { it.windowStates } 54 ?.firstOrNull { it.id == change.windowId } 55 ?.name 56 57 return buildString { 58 append("TransitionChange(") 59 append("transitMode=${change.transitMode}, ") 60 append("layerId=${change.layerId}, ") 61 if (layerName != null) { 62 append("layerName=$layerName, ") 63 } 64 append("windowId=${change.windowId}, ") 65 if (windowName != null) { 66 append("windowName=$windowName, ") 67 } 68 append(")") 69 } 70 } 71 } 72 } 73