• 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.PlatformConsts
20 import android.tools.common.datatypes.Rect
21 import android.tools.common.datatypes.Region
22 import android.tools.common.datatypes.Size
23 import kotlin.js.JsExport
24 import kotlin.js.JsName
25 
26 /**
27  * Represents a window in the window manager hierarchy
28  *
29  * This is a generic object that is reused by both Flicker and Winscope and cannot access internal
30  * Java/Android functionality
31  */
32 @JsExport
33 class WindowState(
34     val attributes: WindowLayoutParams,
35     @JsName("displayId") val displayId: Int,
36     @JsName("stackId") val stackId: Int,
37     @JsName("layer") val layer: Int,
38     val isSurfaceShown: Boolean,
39     val windowType: Int,
40     val requestedSize: Size,
41     val surfacePosition: Rect?,
42     @JsName("frame") val frame: Rect,
43     val containingFrame: Rect,
44     val parentFrame: Rect,
45     val contentFrame: Rect,
46     val contentInsets: Rect,
47     val surfaceInsets: Rect,
48     val givenContentInsets: Rect,
49     @JsName("crop") val crop: Rect,
50     private val windowContainer: IWindowContainer,
51     val isAppWindow: Boolean
<lambda>null52 ) : IWindowContainer by windowContainer {
53     override val isVisible: Boolean = windowContainer.isVisible && attributes.alpha > 0
54 
55     override val isFullscreen: Boolean
56         get() = this.attributes.flags.and(PlatformConsts.FLAG_FULLSCREEN) > 0
57     val isStartingWindow: Boolean = windowType == PlatformConsts.WINDOW_TYPE_STARTING
58     val isExitingWindow: Boolean = windowType == PlatformConsts.WINDOW_TYPE_EXITING
59     val isDebuggerWindow: Boolean = windowType == PlatformConsts.WINDOW_TYPE_DEBUGGER
60     val isValidNavBarType: Boolean = attributes.isValidNavBarType
61 
62     @JsName("frameRegion") val frameRegion: Region = Region.from(frame)
63 
64     private fun getWindowTypeSuffix(windowType: Int): String =
65         when (windowType) {
66             PlatformConsts.WINDOW_TYPE_STARTING -> " STARTING"
67             PlatformConsts.WINDOW_TYPE_EXITING -> " EXITING"
68             PlatformConsts.WINDOW_TYPE_DEBUGGER -> " DEBUGGER"
69             else -> ""
70         }
71 
72     override fun toString(): String =
73         "${this::class.simpleName}: " +
74             "{$token $title${getWindowTypeSuffix(windowType)}} " +
75             "type=${attributes.type} cf=$containingFrame pf=$parentFrame"
76 
77     override fun equals(other: Any?): Boolean {
78         if (this === other) return true
79         if (other !is WindowState) return false
80 
81         if (attributes != other.attributes) return false
82         if (displayId != other.displayId) return false
83         if (stackId != other.stackId) return false
84         if (layer != other.layer) return false
85         if (isSurfaceShown != other.isSurfaceShown) return false
86         if (windowType != other.windowType) return false
87         if (requestedSize != other.requestedSize) return false
88         if (surfacePosition != other.surfacePosition) return false
89         if (frame != other.frame) return false
90         if (containingFrame != other.containingFrame) return false
91         if (parentFrame != other.parentFrame) return false
92         if (contentFrame != other.contentFrame) return false
93         if (contentInsets != other.contentInsets) return false
94         if (surfaceInsets != other.surfaceInsets) return false
95         if (givenContentInsets != other.givenContentInsets) return false
96         if (crop != other.crop) return false
97         if (windowContainer != other.windowContainer) return false
98         if (isAppWindow != other.isAppWindow) return false
99 
100         return true
101     }
102 
103     override fun hashCode(): Int {
104         var result = attributes.hashCode()
105         result = 31 * result + displayId
106         result = 31 * result + stackId
107         result = 31 * result + layer
108         result = 31 * result + isSurfaceShown.hashCode()
109         result = 31 * result + windowType
110         result = 31 * result + requestedSize.hashCode()
111         result = 31 * result + (surfacePosition?.hashCode() ?: 0)
112         result = 31 * result + frame.hashCode()
113         result = 31 * result + containingFrame.hashCode()
114         result = 31 * result + parentFrame.hashCode()
115         result = 31 * result + contentFrame.hashCode()
116         result = 31 * result + contentInsets.hashCode()
117         result = 31 * result + surfaceInsets.hashCode()
118         result = 31 * result + givenContentInsets.hashCode()
119         result = 31 * result + crop.hashCode()
120         result = 31 * result + windowContainer.hashCode()
121         result = 31 * result + isAppWindow.hashCode()
122         result = 31 * result + isVisible.hashCode()
123         result = 31 * result + isStartingWindow.hashCode()
124         result = 31 * result + isExitingWindow.hashCode()
125         result = 31 * result + isDebuggerWindow.hashCode()
126         result = 31 * result + isValidNavBarType.hashCode()
127         result = 31 * result + frameRegion.hashCode()
128         return result
129     }
130 }
131