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.flicker.config.appclose 18 19 import android.tools.common.flicker.ScenarioInstance 20 import android.tools.common.flicker.assertors.ComponentTemplate 21 import android.tools.common.traces.component.FullComponentIdMatcher 22 import android.tools.common.traces.component.IComponentMatcher 23 import android.tools.common.traces.wm.Transition 24 import android.tools.common.traces.wm.TransitionType 25 26 object Components { 27 val CLOSING_APP = 28 ComponentTemplate("CLOSING_APP") { scenarioInstance: ScenarioInstance -> 29 closingAppFrom( 30 scenarioInstance.associatedTransition ?: error("Missing associated transition") 31 ) 32 } 33 34 private fun closingAppFrom(transition: Transition): IComponentMatcher { 35 val targetChanges = 36 transition.changes.filter { 37 it.transitMode == TransitionType.CLOSE || it.transitMode == TransitionType.TO_BACK 38 } 39 40 val closingLayerIds = targetChanges.map { it.layerId } 41 require(closingLayerIds.size == 1) { 42 "Expected 1 closing layer but got ${closingLayerIds.size}" 43 } 44 45 val closingWindowIds = targetChanges.map { it.windowId } 46 require(closingWindowIds.size == 1) { 47 "Expected 1 closing window but got ${closingWindowIds.size}" 48 } 49 50 val windowId = closingWindowIds.first() 51 val layerId = closingLayerIds.first() 52 return FullComponentIdMatcher(windowId, layerId) 53 } 54 } 55