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 kotlin.js.JsExport 20 import kotlin.js.JsName 21 22 /** 23 * Represents a task fragment 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 @JsExport 29 class TaskFragment( 30 override val activityType: Int, 31 @JsName("displayId") val displayId: Int, 32 @JsName("minWidth") val minWidth: Int, 33 @JsName("minHeight") val minHeight: Int, 34 private val windowContainer: IWindowContainer <lambda>null35) : IWindowContainer by windowContainer { 36 @JsName("tasks") 37 val tasks: Array<Task> 38 get() = this.children.reversed().filterIsInstance<Task>().toTypedArray() 39 @JsName("taskFragments") 40 val taskFragments: Array<TaskFragment> 41 get() = this.children.reversed().filterIsInstance<TaskFragment>().toTypedArray() 42 @JsName("activities") 43 val activities: Array<Activity> 44 get() = this.children.reversed().filterIsInstance<Activity>().toTypedArray() 45 46 @JsName("getActivity") 47 fun getActivity(predicate: (Activity) -> Boolean): Activity? { 48 var activity: Activity? = activities.firstOrNull { predicate(it) } 49 if (activity != null) { 50 return activity 51 } 52 for (task in tasks) { 53 activity = task.getActivity(predicate) 54 if (activity != null) { 55 return activity 56 } 57 } 58 for (taskFragment in taskFragments) { 59 activity = taskFragment.getActivity(predicate) 60 if (activity != null) { 61 return activity 62 } 63 } 64 return null 65 } 66 67 override fun toString(): String { 68 return "${this::class.simpleName}: {$token $title} bounds=$bounds" 69 } 70 71 override fun equals(other: Any?): Boolean { 72 if (this === other) return true 73 if (other !is TaskFragment) return false 74 75 if (activityType != other.activityType) return false 76 if (displayId != other.displayId) return false 77 if (minWidth != other.minWidth) return false 78 if (minHeight != other.minHeight) return false 79 if (windowContainer != other.windowContainer) return false 80 81 return true 82 } 83 84 override fun hashCode(): Int { 85 var result = activityType 86 result = 31 * result + displayId 87 result = 31 * result + minWidth 88 result = 31 * result + minHeight 89 result = 31 * result + windowContainer.hashCode() 90 return result 91 } 92 } 93