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