• 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.component
18 
19 import android.tools.common.traces.surfaceflinger.Layer
20 import android.tools.common.traces.wm.Activity
21 import android.tools.common.traces.wm.IWindowContainer
22 
23 interface IComponentMatcher {
ornull24     fun or(other: IComponentMatcher): IComponentMatcher {
25         return OrComponentMatcher(arrayOf(this, other))
26     }
27 
28     /**
29      * @param window to search
30      * @return if any of the components matches [window]
31      */
windowMatchesAnyOfnull32     fun windowMatchesAnyOf(window: IWindowContainer): Boolean = windowMatchesAnyOf(arrayOf(window))
33 
34     /**
35      * @param windows to search
36      * @return if any of the components matches any of [windows]
37      */
38     fun windowMatchesAnyOf(windows: Collection<IWindowContainer>): Boolean =
39         windowMatchesAnyOf(windows.toTypedArray())
40 
41     /**
42      * @param windows to search
43      * @return if any of the [windows] fit the matching conditions of the matcher
44      */
45     fun windowMatchesAnyOf(windows: Array<IWindowContainer>): Boolean
46 
47     /**
48      * @param activity to search
49      * @return if any of the components matches [activity]
50      */
51     fun activityMatchesAnyOf(activity: Activity): Boolean = activityMatchesAnyOf(arrayOf(activity))
52 
53     /**
54      * @param activities to search
55      * @return if any of the components matches any of [activities]
56      */
57     fun activityMatchesAnyOf(activities: Collection<Activity>): Boolean =
58         activityMatchesAnyOf(activities.toTypedArray())
59 
60     /**
61      * @param activities to search
62      * @return if any of the components matches any of [activities]
63      */
64     fun activityMatchesAnyOf(activities: Array<Activity>): Boolean
65 
66     /**
67      * @param layer to search
68      * @return if any of the components matches [layer]
69      */
70     fun layerMatchesAnyOf(layer: Layer): Boolean = layerMatchesAnyOf(arrayOf(layer))
71 
72     /**
73      * @param layers to search
74      * @return if any of the components matches any of [layers]
75      */
76     fun layerMatchesAnyOf(layers: Collection<Layer>): Boolean =
77         layerMatchesAnyOf(layers.toTypedArray())
78 
79     fun layerMatchesAnyOf(layers: Array<Layer>): Boolean
80 
81     /**
82      * @return an identifier string that provides enough information to determine which activities
83      *
84      * ```
85      *         the matcher is looking to match. Mostly used for debugging purposes in error messages
86      * ```
87      */
88     fun toActivityIdentifier(): String
89 
90     /**
91      * @return an identifier string that provides enough information to determine which windows the
92      *
93      * ```
94      *         matcher is looking to match. Mostly used for debugging purposes in error messages.
95      * ```
96      */
97     fun toWindowIdentifier(): String
98 
99     /**
100      * @return an identifier string that provides enough information to determine which layers the
101      *
102      * ```
103      *         matcher is looking to match. Mostly used for debugging purposes in error messages.
104      * ```
105      */
106     fun toLayerIdentifier(): String
107 
108     /**
109      * @param layers Collection of layers check for matches
110      * @param condition A function taking the matched layers of a base level component and returning
111      *
112      * ```
113      *              true or false base on if the check succeeded.
114      * @return
115      * ```
116      *
117      * true iff all the check condition is satisfied according to the ComponentMatcher's
118      *
119      * ```
120      *         defined execution of it.
121      * ```
122      */
123     fun check(layers: Collection<Layer>, condition: (Collection<Layer>) -> Boolean): Boolean
124 
125     fun filterLayers(layers: Collection<Layer>): Collection<Layer> =
126         layers.filter { layerMatchesAnyOf(it) }
127 
filterWindowsnull128     fun filterWindows(windows: Collection<IWindowContainer>): Collection<IWindowContainer> =
129         windows.filter { windowMatchesAnyOf(it) }
130 }
131