1 /*
2  * Copyright (C) 2024 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 import java.util.function.Predicate
23 
24 class SurfaceViewBackgroundMatcher : IComponentMatcher {
25     /** {@inheritDoc} */
windowMatchesAnyOfnull26     override fun windowMatchesAnyOf(windows: Collection<WindowContainer>): Boolean {
27         // Doesn't have a window component only layers
28         return false
29     }
30 
31     /** {@inheritDoc} */
activityMatchesAnyOfnull32     override fun activityMatchesAnyOf(activities: Collection<Activity>): Boolean {
33         // Doesn't have a window component only layers
34         return false
35     }
36 
37     /** {@inheritDoc} */
layerMatchesAnyOfnull38     override fun layerMatchesAnyOf(layers: Collection<Layer>): Boolean {
39         return layers.any { it.name.matches(Regex("^Background for \\w+ SurfaceView.*$")) }
40     }
41 
42     /** {@inheritDoc} */
checknull43     override fun check(
44         layers: Collection<Layer>,
45         condition: Predicate<Collection<Layer>>,
46     ): Boolean = condition.test(layers.filter { layerMatchesAnyOf(it) })
47 
48     /** {@inheritDoc} */
toActivityIdentifiernull49     override fun toActivityIdentifier(): String {
50         throw NotImplementedError(
51             "toActivityIdentifier() is not implemented on SurfaceViewBackgroundMatcher"
52         )
53     }
54 
55     /** {@inheritDoc} */
toWindowIdentifiernull56     override fun toWindowIdentifier(): String {
57         throw NotImplementedError(
58             "toWindowName() is not implemented on SurfaceViewBackgroundMatcher"
59         )
60     }
61 
62     /** {@inheritDoc} */
toLayerIdentifiernull63     override fun toLayerIdentifier(): String {
64         return "SurfaceViewBackground"
65     }
66 }
67