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 import java.util.function.Predicate 23 24 class EdgeExtensionComponentMatcher : 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 { 40 if (it.name.contains("bbq-wrapper")) { 41 val parent = it.parent ?: return false 42 return layerMatchesAnyOf(parent) 43 } 44 45 return it.name.contains("Left Edge Extension") || 46 it.name.contains("Right Edge Extension") 47 } 48 } 49 50 /** {@inheritDoc} */ checknull51 override fun check( 52 layers: Collection<Layer>, 53 condition: Predicate<Collection<Layer>>, 54 ): Boolean = condition.test(layers.filter { layerMatchesAnyOf(it) }) 55 56 /** {@inheritDoc} */ toActivityIdentifiernull57 override fun toActivityIdentifier(): String { 58 throw NotImplementedError( 59 "toActivityIdentifier() is not implemented on EdgeExtensionComponentMatcher" 60 ) 61 } 62 63 /** {@inheritDoc} */ toWindowIdentifiernull64 override fun toWindowIdentifier(): String { 65 throw NotImplementedError( 66 "toWindowName() is not implemented on EdgeExtensionComponentMatcher" 67 ) 68 } 69 70 /** {@inheritDoc} */ toLayerIdentifiernull71 override fun toLayerIdentifier(): String { 72 return "EdgeExtensionLayer" 73 } 74 } 75