xref: /aosp_15_r20/platform_testing/libraries/flicker/src/android/tools/flicker/config/desktopmode/Components.kt (revision dd0948b35e70be4c0246aabd6c72554a5eb8b22a)
1 /*
<lambda>null2  * 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.flicker.config.desktopmode
18 
19 import android.tools.flicker.ScenarioInstance
20 import android.tools.flicker.assertors.ComponentTemplate
21 import android.tools.flicker.config.ScenarioId
22 import android.tools.helpers.SYSTEMUI_PACKAGE
23 import android.tools.traces.component.ComponentNameMatcher
24 import android.tools.traces.component.FullComponentIdMatcher
25 import android.tools.traces.component.IComponentMatcher
26 import android.tools.traces.wm.Transition
27 import android.tools.traces.wm.TransitionType
28 
29 object Components {
30     val DESKTOP_MODE_CAPTION =
31         ComponentTemplate("APP_HEADER") { ComponentNameMatcher(SYSTEMUI_PACKAGE, "caption_handle") }
32 
33     val DESKTOP_MODE_APP =
34         ComponentTemplate("DESKTOP_MODE_APP") { scenarioInstance: ScenarioInstance ->
35             val associatedTransition =
36                 scenarioInstance.associatedTransition
37                     ?: error("Can only extract DESKTOP_MODE_APP from scenario with transition")
38 
39             getDesktopAppForScenario(scenarioInstance.type, associatedTransition)
40         }
41 
42     val SIMPLE_APP =
43         ComponentTemplate("SIMPLE_APP") {
44             ComponentNameMatcher(
45                 "com.android.server.wm.flicker.testapp",
46                 "com.android.server.wm.flicker.testapp.SimpleActivity",
47             )
48         }
49 
50     val NON_RESIZABLE_APP =
51         ComponentTemplate("NON_RESIZABLE_APP") {
52             ComponentNameMatcher(
53                 "com.android.server.wm.flicker.testapp",
54                 "com.android.server.wm.flicker.testapp.NonResizeableActivity",
55             )
56         }
57 
58     val DESKTOP_WALLPAPER =
59         ComponentTemplate("DesktopWallpaper") {
60             ComponentNameMatcher(
61                 SYSTEMUI_PACKAGE,
62                 "com.android.wm.shell.desktopmode.DesktopWallpaperActivity",
63             )
64         }
65 
66     private fun getDesktopAppForScenario(
67         type: ScenarioId,
68         associatedTransition: Transition,
69     ): IComponentMatcher {
70         return when (type) {
71             ScenarioId("END_DRAG_TO_DESKTOP") -> {
72                 val change =
73                     associatedTransition.changes.first { it.transitMode == TransitionType.CHANGE }
74                 FullComponentIdMatcher(change.windowId, change.layerId)
75             }
76             ScenarioId("CLOSE_APP"),
77             ScenarioId("CLOSE_LAST_APP") -> {
78                 val change =
79                     associatedTransition.changes.first { it.transitMode == TransitionType.CLOSE }
80                 FullComponentIdMatcher(change.windowId, change.layerId)
81             }
82             ScenarioId("OPEN_UNLIMITED_APPS"),
83             ScenarioId("CASCADE_APP") -> {
84                 val change =
85                     associatedTransition.changes.first { it.transitMode == TransitionType.OPEN }
86                 FullComponentIdMatcher(change.windowId, change.layerId)
87             }
88             ScenarioId("MINIMIZE_APP"),
89             ScenarioId("MINIMIZE_LAST_APP") -> {
90                 val change =
91                     associatedTransition.changes.first { it.transitMode == TransitionType.TO_BACK }
92                 FullComponentIdMatcher(change.windowId, change.layerId)
93             }
94             ScenarioId("CORNER_RESIZE"),
95             ScenarioId("CORNER_RESIZE_TO_MINIMUM_SIZE"),
96             ScenarioId("CORNER_RESIZE_TO_MAXIMUM_SIZE"),
97             ScenarioId("EDGE_RESIZE"),
98             ScenarioId("SNAP_RESIZE_LEFT_WITH_DRAG"),
99             ScenarioId("SNAP_RESIZE_RIGHT_WITH_DRAG"),
100             ScenarioId("SNAP_RESIZE_LEFT_WITH_BUTTON"),
101             ScenarioId("SNAP_RESIZE_RIGHT_WITH_BUTTON"),
102             ScenarioId("MAXIMIZE_APP"),
103             ScenarioId("MAXIMIZE_APP_NON_RESIZABLE"),
104             ScenarioId("MINIMIZE_AUTO_PIP_APP") -> {
105                 val change = associatedTransition.changes.first()
106                 FullComponentIdMatcher(change.windowId, change.layerId)
107             }
108             ScenarioId("BRING_APPS_TO_FRONT") -> {
109                 val change =
110                     associatedTransition.changes.first { it.transitMode == TransitionType.TO_FRONT }
111                 FullComponentIdMatcher(change.windowId, change.layerId)
112             }
113             else -> error("Unsupported transition type")
114         }
115     }
116 }
117