1 /*
2  * Copyright (C) 2015 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 package android.support.test.launcherhelper;
17 
18 import android.support.test.uiautomator.BySelector;
19 import android.support.test.uiautomator.Direction;
20 import android.support.test.uiautomator.UiDevice;
21 import android.support.test.uiautomator.UiObject2;
22 
23 /**
24  * Defines the common use cases a launcher UI automation helper should fulfill.
25  * <p>Class will be instantiated by {@link LauncherStrategyFactory} based on current launcher
26  * package, and a {@link UiDevice} instance will be provided via {@link #setUiDevice(UiDevice)}
27  * method.
28  */
29 public interface ILauncherStrategy {
30     long LAUNCH_FAILED_TIMESTAMP = -1;
31 
32     /**
33      * Returns the launcher application package that this {@link ILauncherStrategy} can automate
34      *
35      * @return
36      */
getSupportedLauncherPackage()37     String getSupportedLauncherPackage();
38 
39     /**
40      * Injects a {@link UiDevice} instance for UI interactions
41      *
42      * @param uiDevice
43      */
setUiDevice(UiDevice uiDevice)44     void setUiDevice(UiDevice uiDevice);
45 
46     /** Shows the home screen of launcher */
open()47     void open();
48 
49     /**
50      * Opens the all apps drawer of launcher
51      *
52      * @param reset if the all apps drawer should be reset to the beginning
53      * @return {@link UiObject2} representation of the all apps drawer
54      */
openAllApps(boolean reset)55     UiObject2 openAllApps(boolean reset);
56 
57     /** Opens the overview drawer of launcher */
openOverview()58     void openOverview();
59 
60     /**
61      * Clears the list of recently used apps from the overview drawer
62      *
63      * @return If the list of recent apps is empty
64      */
clearRecentAppsFromOverview()65     boolean clearRecentAppsFromOverview();
66 
67     /**
68      * Returns a {@link BySelector} describing the button to open the all apps drawer
69      *
70      * @return
71      */
getAllAppsButtonSelector()72     BySelector getAllAppsButtonSelector();
73 
74     /**
75      * Returns a {@link BySelector} describing the all apps drawer
76      *
77      * @return
78      */
getAllAppsSelector()79     BySelector getAllAppsSelector();
80 
81     /**
82      * Retrieves the all apps drawer forward scroll direction as implemented by the launcher
83      *
84      * @return
85      */
getAllAppsScrollDirection()86     Direction getAllAppsScrollDirection();
87 
88     /**
89      * Opens the all widgets drawer of launcher
90      *
91      * @param reset if the all widgets drawer should be reset to the beginning
92      * @return {@link UiObject2} representation of the all widgets drawer
93      */
openAllWidgets(boolean reset)94     UiObject2 openAllWidgets(boolean reset);
95 
96     /**
97      * Returns a {@link BySelector} describing the all widgets drawer
98      *
99      * @return
100      */
getAllWidgetsSelector()101     BySelector getAllWidgetsSelector();
102 
103     /**
104      * Retrieves the all widgets drawer forward scroll direction as implemented by the launcher
105      *
106      * @return
107      */
getAllWidgetsScrollDirection()108     Direction getAllWidgetsScrollDirection();
109 
110     /**
111      * Returns a {@link BySelector} describing the home screen workspace
112      *
113      * @return
114      */
getWorkspaceSelector()115     BySelector getWorkspaceSelector();
116 
117     /**
118      * Returns a {@link BySelector} describing the home screen hot seat (app icons at the bottom)
119      *
120      * @return
121      */
getHotSeatSelector()122     BySelector getHotSeatSelector();
123 
124     /**
125      * Returns a {@link BySelector} describing the overview screen (recent apps list)
126      *
127      * @return
128      */
getOverviewSelector()129     BySelector getOverviewSelector();
130 
131     /**
132      * Retrieves the home screen workspace forward scroll direction as implemented by the launcher
133      *
134      * @return
135      */
getWorkspaceScrollDirection()136     Direction getWorkspaceScrollDirection();
137 
138     /**
139      * Launch the named application
140      *
141      * @param appName the name of the application to launch as shown in launcher
142      * @param packageName the expected package name to verify that the application has been launched
143      *     into foreground. If <code>null</code> is provided, no verification is performed.
144      * @return <code>true</code> if application is verified to be in foreground after launch, or the
145      *     verification is skipped; <code>false</code> otherwise.
146      */
launch(String appName, String packageName)147     long launch(String appName, String packageName);
148 }
149