• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.common.traces.wm
18 
19 import android.tools.common.traces.surfaceflinger.LayersTrace
20 import kotlin.js.JsExport
21 import kotlin.js.JsName
22 
23 @JsExport
24 class TransitionChange(
25     @JsName("transitMode") val transitMode: TransitionType,
26     @JsName("layerId") val layerId: Int,
27     @JsName("windowId") val windowId: Int,
28 ) {
29 
toStringnull30     override fun toString(): String = Formatter(null, null).format(this)
31 
32     class Formatter(val layersTrace: LayersTrace?, val wmTrace: WindowManagerTrace?) {
33         fun format(change: TransitionChange): String {
34             val layerName =
35                 layersTrace
36                     ?.entries
37                     ?.flatMap { it.flattenedLayers.asList() }
38                     ?.firstOrNull { it.id == change.layerId }
39                     ?.name
40 
41             val windowName =
42                 wmTrace
43                     ?.entries
44                     ?.flatMap { it.windowStates.asList() }
45                     ?.firstOrNull { it.token == change.windowId.toString(16) }
46                     ?.name
47 
48             return buildString {
49                 append("TransitionChange(")
50                 append("transitMode=${change.transitMode}, ")
51                 append("layerId=${change.layerId}, ")
52                 if (layerName != null) {
53                     append("layerName=$layerName, ")
54                 }
55                 append("windowId=${change.windowId}, ")
56                 if (windowName != null) {
57                     append("windowName=$windowName, ")
58                 }
59                 append(")")
60             }
61         }
62     }
63 }
64