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.traces.component
18 
19 import android.tools.traces.surfaceflinger.Layer
20 import android.tools.traces.wm.Activity
21 import android.tools.traces.wm.WindowContainer
22 
23 class EdgeExtensionComponentMatcher : IComponentMatcher {
24     /** {@inheritDoc} */
windowMatchesAnyOfnull25     override fun windowMatchesAnyOf(windows: Collection<WindowContainer>): Boolean {
26         // Doesn't have a window component only layers
27         return false
28     }
29 
30     /** {@inheritDoc} */
activityMatchesAnyOfnull31     override fun activityMatchesAnyOf(activities: Collection<Activity>): Boolean {
32         // Doesn't have a window component only layers
33         return false
34     }
35 
36     /** {@inheritDoc} */
layerMatchesAnyOfnull37     override fun layerMatchesAnyOf(layers: Collection<Layer>): Boolean {
38         return layers.any {
39             if (it.name.contains("bbq-wrapper")) {
40                 val parent = it.parent ?: return false
41                 return layerMatchesAnyOf(parent)
42             }
43 
44             return it.name.contains("Left Edge Extension") ||
45                 it.name.contains("Right Edge Extension")
46         }
47     }
48 
49     /** {@inheritDoc} */
checknull50     override fun check(
51         layers: Collection<Layer>,
52         condition: (Collection<Layer>) -> Boolean
53     ): Boolean = condition(layers.filter { layerMatchesAnyOf(it) })
54 
55     /** {@inheritDoc} */
toActivityIdentifiernull56     override fun toActivityIdentifier(): String {
57         throw NotImplementedError(
58             "toActivityIdentifier() is not implemented on EdgeExtensionComponentMatcher"
59         )
60     }
61 
62     /** {@inheritDoc} */
toWindowIdentifiernull63     override fun toWindowIdentifier(): String {
64         throw NotImplementedError(
65             "toWindowName() is not implemented on EdgeExtensionComponentMatcher"
66         )
67     }
68 
69     /** {@inheritDoc} */
toLayerIdentifiernull70     override fun toLayerIdentifier(): String {
71         return "EdgeExtensionLayer"
72     }
73 }
74