• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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 class OrComponentMatcher(private val componentMatchers: Array<out IComponentMatcher>) :
24     IComponentMatcher {
25 
26     /** {@inheritDoc} */
27     override fun windowMatchesAnyOf(window: IWindowContainer): Boolean {
28         return componentMatchers.any { it.windowMatchesAnyOf(window) }
29     }
30 
31     /** {@inheritDoc} */
32     override fun windowMatchesAnyOf(windows: Collection<IWindowContainer>): Boolean {
33         return componentMatchers.any { it.windowMatchesAnyOf(windows) }
34     }
35 
36     /** {@inheritDoc} */
37     override fun windowMatchesAnyOf(windows: Array<IWindowContainer>): Boolean {
38         return componentMatchers.any { it.windowMatchesAnyOf(windows) }
39     }
40 
41     /** {@inheritDoc} */
42     override fun activityMatchesAnyOf(activity: Activity): Boolean {
43         return componentMatchers.any { it.activityMatchesAnyOf(activity) }
44     }
45 
46     /** {@inheritDoc} */
47     override fun activityMatchesAnyOf(activities: Collection<Activity>): Boolean {
48         return componentMatchers.any { it.activityMatchesAnyOf(activities) }
49     }
50 
51     /** {@inheritDoc} */
52     override fun activityMatchesAnyOf(activities: Array<Activity>): Boolean {
53         return componentMatchers.any { it.activityMatchesAnyOf(activities) }
54     }
55 
56     /** {@inheritDoc} */
57     override fun layerMatchesAnyOf(layer: Layer): Boolean {
58         return componentMatchers.any { it.layerMatchesAnyOf(layer) }
59     }
60 
61     /** {@inheritDoc} */
62     override fun layerMatchesAnyOf(layers: Collection<Layer>): Boolean {
63         return componentMatchers.any { it.layerMatchesAnyOf(layers) }
64     }
65 
66     /** {@inheritDoc} */
67     override fun layerMatchesAnyOf(layers: Array<Layer>): Boolean {
68         return componentMatchers.any { it.layerMatchesAnyOf(layers) }
69     }
70 
71     /** {@inheritDoc} */
72     override fun check(
73         layers: Collection<Layer>,
74         condition: (Collection<Layer>) -> Boolean
75     ): Boolean {
76         return componentMatchers.any { oredComponent ->
77             oredComponent.check(layers) { condition(it) }
78         }
79     }
80 
81     /** {@inheritDoc} */
82     override fun toActivityIdentifier(): String =
83         componentMatchers.joinToString(" or ") { it.toActivityIdentifier() }
84 
85     /** {@inheritDoc} */
86     override fun toWindowIdentifier(): String =
87         componentMatchers.joinToString(" or ") { it.toWindowIdentifier() }
88 
89     /** {@inheritDoc} */
90     override fun toLayerIdentifier(): String =
91         componentMatchers.joinToString(" or ") { it.toLayerIdentifier() }
92 }
93