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