• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2020 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 com.android.server.wm.traces.common.windowmanager.windows
18 
19 import com.android.server.wm.traces.common.Rect
20 
21 /**
22  * Represents a display content in the window manager hierarchy
23  *
24  * This is a generic object that is reused by both Flicker and Winscope and cannot
25  * access internal Java/Android functionality
26  *
27  */
28 open class DisplayContent(
29     val id: Int,
30     val focusedRootTaskId: Int,
31     val resumedActivity: String,
32     val singleTaskInstance: Boolean,
33     val defaultPinnedStackBounds: Rect,
34     val pinnedStackMovementBounds: Rect,
35     val displayRect: Rect,
36     val appRect: Rect,
37     val dpi: Int,
38     val flags: Int,
39     val stableBounds: Rect,
40     val surfaceSize: Int,
41     val focusedApp: String,
42     val lastTransition: String,
43     val appTransitionState: String,
44     val rotation: Int,
45     val lastOrientation: Int,
46     windowContainer: WindowContainer
47 ) : WindowContainer(windowContainer) {
48     override val name: String = id.toString()
49     override val isVisible: Boolean = false
50 
51     val rootTasks: Array<Task>
52         get() {
53             val tasks = this.collectDescendants<Task> { it.isRootTask }.toMutableList()
54             // TODO(b/149338177): figure out how CTS tests deal with organizer. For now,
55             //                    don't treat them as regular stacks
56             val rootOrganizedTasks = mutableListOf<Task>()
57             val reversedTaskList = tasks.reversed()
58             reversedTaskList.forEach { task ->
59                 // Skip tasks created by an organizer
60                 if (task.createdByOrganizer) {
61                     tasks.remove(task)
62                     rootOrganizedTasks.add(task)
63                 }
64             }
65             // Add root tasks controlled by an organizer
66             rootOrganizedTasks.reversed().forEach { task ->
67                 tasks.addAll(task.children.reversed().map { it as Task })
68             }
69 
70             return tasks.toTypedArray()
71         }
72 
73     fun containsActivity(activityName: String): Boolean =
74         rootTasks.any { it.containsActivity(activityName) }
75 
76     fun getTaskDisplayArea(activityName: String): DisplayArea? {
77         val taskDisplayAreas = this.collectDescendants<DisplayArea> { it.isTaskDisplayArea }
78             .filter { it.containsActivity(activityName) }
79 
80         if (taskDisplayAreas.size > 1) {
81             throw IllegalArgumentException(
82                 "There must be exactly one activity among all TaskDisplayAreas.")
83         }
84 
85         return taskDisplayAreas.firstOrNull()
86     }
87 
88     override fun toString(): String {
89         return "${this::class.simpleName} #$id: name=$title mDisplayRect=$displayRect " +
90             "mAppRect=$appRect mFlags=$flags"
91     }
92 
93     override fun equals(other: Any?): Boolean {
94         if (this === other) return true
95         if (other !is DisplayContent) return false
96         if (!super.equals(other)) return false
97 
98         if (id != other.id) return false
99         if (focusedRootTaskId != other.focusedRootTaskId) return false
100         if (resumedActivity != other.resumedActivity) return false
101         if (defaultPinnedStackBounds != other.defaultPinnedStackBounds) return false
102         if (pinnedStackMovementBounds != other.pinnedStackMovementBounds) return false
103         if (stableBounds != other.stableBounds) return false
104         if (displayRect != other.displayRect) return false
105         if (appRect != other.appRect) return false
106         if (dpi != other.dpi) return false
107         if (flags != other.flags) return false
108         if (focusedApp != other.focusedApp) return false
109         if (lastTransition != other.lastTransition) return false
110         if (appTransitionState != other.appTransitionState) return false
111         if (rotation != other.rotation) return false
112         if (lastOrientation != other.lastOrientation) return false
113         if (name != other.name) return false
114         if (singleTaskInstance != other.singleTaskInstance) return false
115         if (surfaceSize != other.surfaceSize) return false
116 
117         return true
118     }
119 
120     override fun hashCode(): Int {
121         var result = super.hashCode()
122         result = 31 * result + id
123         result = 31 * result + focusedRootTaskId
124         result = 31 * result + resumedActivity.hashCode()
125         result = 31 * result + singleTaskInstance.hashCode()
126         result = 31 * result + defaultPinnedStackBounds.hashCode()
127         result = 31 * result + pinnedStackMovementBounds.hashCode()
128         result = 31 * result + displayRect.hashCode()
129         result = 31 * result + appRect.hashCode()
130         result = 31 * result + dpi
131         result = 31 * result + flags
132         result = 31 * result + stableBounds.hashCode()
133         result = 31 * result + surfaceSize
134         result = 31 * result + focusedApp.hashCode()
135         result = 31 * result + lastTransition.hashCode()
136         result = 31 * result + appTransitionState.hashCode()
137         result = 31 * result + rotation
138         result = 31 * result + lastOrientation
139         result = 31 * result + name.hashCode()
140         result = 31 * result + isVisible.hashCode()
141         return result
142     }
143 }