1 /*
2  * 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.device.apphelpers
18 
19 import android.content.Intent
20 import android.tools.traces.ConditionsFactory
21 import android.tools.traces.component.IComponentMatcher
22 import android.tools.traces.component.IComponentNameMatcher
23 import android.tools.traces.parsers.WindowManagerStateHelper
24 
25 interface IStandardAppHelper : IComponentNameMatcher {
opennull26     fun open()
27 
28     fun exit()
29 
30     /** Exits the activity and wait for activity destroyed */
31     fun exit(wmHelper: WindowManagerStateHelper)
32 
33     /**
34      * Launches the app through an intent instead of interacting with the launcher.
35      *
36      * Uses UiAutomation to detect when the app is open
37      */
38     fun launchViaIntent(
39         expectedPackageName: String = "",
40         action: String? = null,
41         stringExtras: Map<String, String> = mapOf()
42     )
43 
44     /**
45      * Launches the app through an intent instead of interacting with the launcher and waits until
46      * the app window is visible
47      */
48     fun launchViaIntent(
49         wmHelper: WindowManagerStateHelper,
50         launchedAppComponentMatcherOverride: IComponentMatcher? = null,
51         action: String? = null,
52         stringExtras: Map<String, String> = mapOf(),
53         waitConditionsBuilder: WindowManagerStateHelper.StateSyncBuilder =
54             wmHelper
55                 .StateSyncBuilder()
56                 .add(ConditionsFactory.isWMStateComplete())
57                 .withAppTransitionIdle()
58     )
59 
60     /**
61      * Launches the app through an intent instead of interacting with the launcher and waits until
62      * the app window is visible
63      */
64     fun launchViaIntent(
65         wmHelper: WindowManagerStateHelper,
66         intent: Intent,
67         launchedAppComponentMatcherOverride: IComponentMatcher? = null,
68         waitConditionsBuilder: WindowManagerStateHelper.StateSyncBuilder =
69             wmHelper
70                 .StateSyncBuilder()
71                 .add(ConditionsFactory.isWMStateComplete())
72                 .withAppTransitionIdle()
73     )
74 
75     fun isAvailable(): Boolean
76 }
77