• 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.flicker.config.applaunch
18 
19 import android.tools.flicker.ScenarioInstance
20 import android.tools.flicker.assertors.ComponentTemplate
21 import android.tools.flicker.isAppTransitionChange
22 import android.tools.traces.component.FullComponentIdMatcher
23 import android.tools.traces.component.IComponentMatcher
24 import android.tools.traces.surfaceflinger.LayersTrace
25 import android.tools.traces.wm.Transition
26 import android.tools.traces.wm.TransitionType
27 import android.tools.traces.wm.WindowManagerTrace
28 
29 object Components {
30     val OPENING_APPS =
31         ComponentTemplate("OPENING_APP(S)") { scenarioInstance: ScenarioInstance ->
32             openingAppFrom(
33                 scenarioInstance.associatedTransition ?: error("Missing associated transition"),
34                 scenarioInstance.reader.readLayersTrace(),
35                 scenarioInstance.reader.readWmTrace(),
36             )
37         }
38 
39     val OPENING_CHANGES =
40         ComponentTemplate("OPENING_CHANGE(S)") { scenarioInstance: ScenarioInstance ->
41             openingChanges(
42                 scenarioInstance.associatedTransition ?: error("Missing associated transition")
43             )
44         }
45 
46     private fun openingAppFrom(
47         transition: Transition,
48         layersTrace: LayersTrace?,
49         wmTrace: WindowManagerTrace?,
50     ): IComponentMatcher {
51         val targetChanges =
52             transition.changes.filter {
53                 (it.transitMode == TransitionType.OPEN ||
54                     it.transitMode == TransitionType.TO_FRONT) &&
55                     isAppTransitionChange(it, layersTrace, wmTrace)
56             }
57 
58         val openingAppMatchers =
59             targetChanges.map { FullComponentIdMatcher(it.windowId, it.layerId) }
60 
61         return openingAppMatchers.reduce<IComponentMatcher, IComponentMatcher> { acc, matcher ->
62             acc.or(matcher)
63         }
64     }
65 
66     private fun openingChanges(transition: Transition): IComponentMatcher {
67         val changes =
68             transition.changes.filter {
69                 it.transitMode == TransitionType.OPEN || it.transitMode == TransitionType.TO_FRONT
70             }
71 
72         val matcher = changes.map { FullComponentIdMatcher(it.windowId, it.layerId) }
73 
74         return matcher.reduce<IComponentMatcher, IComponentMatcher> { acc, matcher ->
75             acc.or(matcher)
76         }
77     }
78 }
79