• 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.withCache
20 import kotlin.js.JsExport
21 import kotlin.js.JsName
22 
23 /**
24  * Represents the attributes of a WindowState in the window manager hierarchy
25  *
26  * This is a generic object that is reused by both Flicker and Winscope and cannot access internal
27  * Java/Android functionality
28  */
29 @JsExport
30 class WindowLayoutParams
31 private constructor(
32     @JsName("type") val type: Int = 0,
33     @JsName("x") val x: Int = 0,
34     @JsName("y") val y: Int = 0,
35     @JsName("width") val width: Int = 0,
36     @JsName("height") val height: Int = 0,
37     @JsName("horizontalMargin") val horizontalMargin: Float = 0f,
38     @JsName("verticalMargin") val verticalMargin: Float = 0f,
39     @JsName("gravity") val gravity: Int = 0,
40     @JsName("softInputMode") val softInputMode: Int = 0,
41     @JsName("format") val format: Int = 0,
42     @JsName("windowAnimations") val windowAnimations: Int = 0,
43     @JsName("alpha") val alpha: Float = 0f,
44     @JsName("screenBrightness") val screenBrightness: Float = 0f,
45     @JsName("buttonBrightness") val buttonBrightness: Float = 0f,
46     @JsName("rotationAnimation") val rotationAnimation: Int = 0,
47     @JsName("preferredRefreshRate") val preferredRefreshRate: Float = 0f,
48     @JsName("preferredDisplayModeId") val preferredDisplayModeId: Int = 0,
49     @JsName("hasSystemUiListeners") val hasSystemUiListeners: Boolean = false,
50     @JsName("inputFeatureFlags") val inputFeatureFlags: Int = 0,
51     @JsName("userActivityTimeout") val userActivityTimeout: Long = 0L,
52     @JsName("colorMode") val colorMode: Int = 0,
53     @JsName("flags") val flags: Int = 0,
54     @JsName("privateFlags") val privateFlags: Int = 0,
55     @JsName("systemUiVisibilityFlags") val systemUiVisibilityFlags: Int = 0,
56     @JsName("subtreeSystemUiVisibilityFlags") val subtreeSystemUiVisibilityFlags: Int = 0,
57     @JsName("appearance") val appearance: Int = 0,
58     @JsName("behavior") val behavior: Int = 0,
59     @JsName("fitInsetsTypes") val fitInsetsTypes: Int = 0,
60     @JsName("fitInsetsSides") val fitInsetsSides: Int = 0,
61     @JsName("fitIgnoreVisibility") val fitIgnoreVisibility: Boolean = false
62 ) {
63     @JsName("isValidNavBarType") val isValidNavBarType: Boolean = this.type == TYPE_NAVIGATION_BAR
64 
equalsnull65     override fun equals(other: Any?): Boolean {
66         if (this === other) return true
67         if (other !is WindowLayoutParams) return false
68 
69         if (type != other.type) return false
70         if (x != other.x) return false
71         if (y != other.y) return false
72         if (width != other.width) return false
73         if (height != other.height) return false
74         if (horizontalMargin != other.horizontalMargin) return false
75         if (verticalMargin != other.verticalMargin) return false
76         if (gravity != other.gravity) return false
77         if (softInputMode != other.softInputMode) return false
78         if (format != other.format) return false
79         if (windowAnimations != other.windowAnimations) return false
80         if (alpha != other.alpha) return false
81         if (screenBrightness != other.screenBrightness) return false
82         if (buttonBrightness != other.buttonBrightness) return false
83         if (rotationAnimation != other.rotationAnimation) return false
84         if (preferredRefreshRate != other.preferredRefreshRate) return false
85         if (preferredDisplayModeId != other.preferredDisplayModeId) return false
86         if (hasSystemUiListeners != other.hasSystemUiListeners) return false
87         if (inputFeatureFlags != other.inputFeatureFlags) return false
88         if (userActivityTimeout != other.userActivityTimeout) return false
89         if (colorMode != other.colorMode) return false
90         if (flags != other.flags) return false
91         if (privateFlags != other.privateFlags) return false
92         if (systemUiVisibilityFlags != other.systemUiVisibilityFlags) return false
93         if (subtreeSystemUiVisibilityFlags != other.subtreeSystemUiVisibilityFlags) return false
94         if (appearance != other.appearance) return false
95         if (behavior != other.behavior) return false
96         if (fitInsetsTypes != other.fitInsetsTypes) return false
97         if (fitInsetsSides != other.fitInsetsSides) return false
98         if (fitIgnoreVisibility != other.fitIgnoreVisibility) return false
99         if (isValidNavBarType != other.isValidNavBarType) return false
100 
101         return true
102     }
103 
hashCodenull104     override fun hashCode(): Int {
105         var result = type
106         result = 31 * result + x
107         result = 31 * result + y
108         result = 31 * result + width
109         result = 31 * result + height
110         result = 31 * result + horizontalMargin.hashCode()
111         result = 31 * result + verticalMargin.hashCode()
112         result = 31 * result + gravity
113         result = 31 * result + softInputMode
114         result = 31 * result + format
115         result = 31 * result + windowAnimations
116         result = 31 * result + alpha.hashCode()
117         result = 31 * result + screenBrightness.hashCode()
118         result = 31 * result + buttonBrightness.hashCode()
119         result = 31 * result + rotationAnimation
120         result = 31 * result + preferredRefreshRate.hashCode()
121         result = 31 * result + preferredDisplayModeId
122         result = 31 * result + hasSystemUiListeners.hashCode()
123         result = 31 * result + inputFeatureFlags
124         result = 31 * result + userActivityTimeout.hashCode()
125         result = 31 * result + colorMode
126         result = 31 * result + flags
127         result = 31 * result + privateFlags
128         result = 31 * result + systemUiVisibilityFlags
129         result = 31 * result + subtreeSystemUiVisibilityFlags
130         result = 31 * result + appearance
131         result = 31 * result + behavior
132         result = 31 * result + fitInsetsTypes
133         result = 31 * result + fitInsetsSides
134         result = 31 * result + fitIgnoreVisibility.hashCode()
135         result = 31 * result + isValidNavBarType.hashCode()
136         return result
137     }
138 
toStringnull139     override fun toString(): String {
140         return "WindowLayoutParams(type=$type, x=$x, y=$y, width=$width, height=$height, " +
141             "horizontalMargin=$horizontalMargin, verticalMargin=$verticalMargin, " +
142             "gravity=$gravity, softInputMode=$softInputMode, format=$format, " +
143             "windowAnimations=$windowAnimations, alpha=$alpha, " +
144             "screenBrightness=$screenBrightness, buttonBrightness=$buttonBrightness, " +
145             "rotationAnimation=$rotationAnimation, preferredRefreshRate=$preferredRefreshRate, " +
146             "preferredDisplayModeId=$preferredDisplayModeId, " +
147             "hasSystemUiListeners=$hasSystemUiListeners, inputFeatureFlags=$inputFeatureFlags, " +
148             "userActivityTimeout=$userActivityTimeout, colorMode=$colorMode, flags=$flags, " +
149             "privateFlags=$privateFlags, systemUiVisibilityFlags=$systemUiVisibilityFlags, " +
150             "subtreeSystemUiVisibilityFlags=$subtreeSystemUiVisibilityFlags, " +
151             "appearance=$appearance, behavior=$behavior, fitInsetsTypes=$fitInsetsTypes, " +
152             "fitInsetsSides=$fitInsetsSides, fitIgnoreVisibility=$fitIgnoreVisibility, " +
153             "isValidNavBarType=$isValidNavBarType)"
154     }
155 
156     companion object {
157         val EMPTY: WindowLayoutParams
<lambda>null158             get() = withCache { WindowLayoutParams() }
159         /** @see WindowManager.LayoutParams */
160         private const val TYPE_NAVIGATION_BAR = 2019
161 
162         @JsName("from")
fromnull163         fun from(
164             type: Int,
165             x: Int,
166             y: Int,
167             width: Int,
168             height: Int,
169             horizontalMargin: Float,
170             verticalMargin: Float,
171             gravity: Int,
172             softInputMode: Int,
173             format: Int,
174             windowAnimations: Int,
175             alpha: Float,
176             screenBrightness: Float,
177             buttonBrightness: Float,
178             rotationAnimation: Int,
179             preferredRefreshRate: Float,
180             preferredDisplayModeId: Int,
181             hasSystemUiListeners: Boolean,
182             inputFeatureFlags: Int,
183             userActivityTimeout: Long,
184             colorMode: Int,
185             flags: Int,
186             privateFlags: Int,
187             systemUiVisibilityFlags: Int,
188             subtreeSystemUiVisibilityFlags: Int,
189             appearance: Int,
190             behavior: Int,
191             fitInsetsTypes: Int,
192             fitInsetsSides: Int,
193             fitIgnoreVisibility: Boolean
194         ): WindowLayoutParams = withCache {
195             WindowLayoutParams(
196                 type,
197                 x,
198                 y,
199                 width,
200                 height,
201                 horizontalMargin,
202                 verticalMargin,
203                 gravity,
204                 softInputMode,
205                 format,
206                 windowAnimations,
207                 alpha,
208                 screenBrightness,
209                 buttonBrightness,
210                 rotationAnimation,
211                 preferredRefreshRate,
212                 preferredDisplayModeId,
213                 hasSystemUiListeners,
214                 inputFeatureFlags,
215                 userActivityTimeout,
216                 colorMode,
217                 flags,
218                 privateFlags,
219                 systemUiVisibilityFlags,
220                 subtreeSystemUiVisibilityFlags,
221                 appearance,
222                 behavior,
223                 fitInsetsTypes,
224                 fitInsetsSides,
225                 fitIgnoreVisibility
226             )
227         }
228     }
229 }
230