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.pip
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.traces.component.ComponentNameMatcher
23 import android.tools.traces.component.FullComponentIdMatcher
24 import android.tools.traces.wm.TransitionType
25 
26 object Components {
27     val PIP_DISMISS_OVERLAY =
28         ComponentTemplate("PipDismissOverlay") { ComponentNameMatcher("", "pip-dismiss-overlay") }
29     val PIP_CONTENT_OVERLAY =
30         ComponentTemplate("PipContentOverlay") { ComponentNameMatcher.PIP_CONTENT_OVERLAY }
31     val PIP_APP =
32         ComponentTemplate("PIP") { scenarioInstance: ScenarioInstance ->
33             if (scenarioInstance.type == ScenarioId("LAUNCHER_APP_CLOSE_TO_PIP")) {
34                 val associatedTransition =
35                     scenarioInstance.associatedTransition ?: error("Missing associated transition")
36                 val change =
37                     associatedTransition.changes.firstOrNull {
38                         it.transitMode == TransitionType.TO_BACK
39                     }
40                         ?: error("Missing to back change")
41                 FullComponentIdMatcher(change.windowId, change.layerId)
42             } else {
43                 error("Unhandled case - can't get PiP app for this case")
44             }
45         }
46 }
47