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.datatypes.Rect 20 import android.tools.common.withCache 21 import kotlin.js.JsExport 22 import kotlin.js.JsName 23 24 /** 25 * Represents the configuration of a WM window 26 * 27 * This is a generic object that is reused by both Flicker and Winscope and cannot access internal 28 * Java/Android functionality 29 */ 30 @JsExport 31 open class WindowConfiguration( 32 val appBounds: Rect = Rect.EMPTY, 33 val bounds: Rect = Rect.EMPTY, 34 val maxBounds: Rect = Rect.EMPTY, 35 val windowingMode: Int = 0, 36 val activityType: Int = 0 37 ) { 38 @JsName("isEmpty") 39 val isEmpty: Boolean 40 get() = 41 appBounds.isEmpty && 42 bounds.isEmpty && 43 maxBounds.isEmpty && 44 windowingMode == 0 && 45 activityType == 0 46 equalsnull47 override fun equals(other: Any?): Boolean { 48 if (this === other) return true 49 if (other !is WindowConfiguration) return false 50 51 if (windowingMode != other.windowingMode) return false 52 if (activityType != other.activityType) return false 53 if (appBounds != other.appBounds) return false 54 if (bounds != other.bounds) return false 55 if (maxBounds != other.maxBounds) return false 56 57 return true 58 } 59 hashCodenull60 override fun hashCode(): Int { 61 var result = windowingMode 62 result = 31 * result + activityType 63 result = 31 * result + appBounds.hashCode() 64 result = 31 * result + bounds.hashCode() 65 result = 31 * result + maxBounds.hashCode() 66 return result 67 } 68 69 companion object { 70 @JsName("EMPTY") 71 val EMPTY: WindowConfiguration <lambda>null72 get() = withCache { WindowConfiguration() } 73 @JsName("from") fromnull74 fun from( 75 appBounds: Rect?, 76 bounds: Rect?, 77 maxBounds: Rect?, 78 windowingMode: Int, 79 activityType: Int 80 ): WindowConfiguration = withCache { 81 WindowConfiguration( 82 appBounds ?: Rect.EMPTY, 83 bounds ?: Rect.EMPTY, 84 maxBounds ?: Rect.EMPTY, 85 windowingMode, 86 activityType 87 ) 88 } 89 } 90 } 91