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