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.traces.component.IComponentMatcher 20 import android.tools.traces.wm.Utils.collectDescendants 21 22 /** 23 * Represents a display area in the window manager hierarchy 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 class DisplayArea(val isTaskDisplayArea: Boolean, private val windowContainer: WindowContainer) : <lambda>null29 WindowContainer by windowContainer { 30 val activities: Collection<Activity> 31 get() = 32 if (isTaskDisplayArea) { 33 collectDescendants() 34 } else { 35 emptyList() 36 } 37 38 /** 39 * @param componentMatcher Components to search 40 * @return if [componentMatcher] matches any activity 41 */ 42 fun containsActivity(componentMatcher: IComponentMatcher): Boolean { 43 return if (!isTaskDisplayArea) { 44 false 45 } else { 46 componentMatcher.activityMatchesAnyOf(activities) 47 } 48 } 49 50 override fun toString(): String { 51 return "${this::class.simpleName} {$token $title} isTaskArea=$isTaskDisplayArea" 52 } 53 54 override fun equals(other: Any?): Boolean { 55 if (this === other) return true 56 if (other !is DisplayArea) return false 57 58 if (isTaskDisplayArea != other.isTaskDisplayArea) return false 59 if (isVisible != other.isVisible) return false 60 if (orientation != other.orientation) return false 61 if (title != other.title) return false 62 if (token != other.token) return false 63 if (windowContainer != other.windowContainer) return false 64 65 return true 66 } 67 68 override fun hashCode(): Int { 69 var result = super.hashCode() 70 result = 31 * result + isTaskDisplayArea.hashCode() 71 result = 31 * result + windowContainer.hashCode() 72 return result 73 } 74 } 75