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     public static final long LAUNCH_FAILED_TIMESTAMP = -1;
31 
32     /**
33      * Returns the launcher application package that this {@link ILauncherStrategy} can automate
34      * @return
35      */
getSupportedLauncherPackage()36     public String getSupportedLauncherPackage();
37 
38     /**
39      * Injects a {@link UiDevice} instance for UI interactions
40      * @param uiDevice
41      */
setUiDevice(UiDevice uiDevice)42     public void setUiDevice(UiDevice uiDevice);
43 
44     /**
45      * Shows the home screen of launcher
46      */
open()47     public void open();
48 
49     /**
50      * Opens the all apps drawer of launcher
51      * @param reset if the all apps drawer should be reset to the beginning
52      * @return {@link UiObject2} representation of the all apps drawer
53      */
openAllApps(boolean reset)54     public UiObject2 openAllApps(boolean reset);
55 
56     /**
57      * Returns a {@link BySelector} describing the button to open the all apps drawer
58      * @return
59      */
getAllAppsButtonSelector()60     public BySelector getAllAppsButtonSelector();
61 
62     /**
63      * Returns a {@link BySelector} describing the all apps drawer
64      * @return
65      */
getAllAppsSelector()66     public BySelector getAllAppsSelector();
67 
68     /**
69      * Retrieves the all apps drawer forward scroll direction as implemented by the launcher
70      * @return
71      */
getAllAppsScrollDirection()72     public Direction getAllAppsScrollDirection();
73 
74     /**
75      * Opens the all widgets drawer of launcher
76      * @param reset if the all widgets drawer should be reset to the beginning
77      * @return {@link UiObject2} representation of the all widgets drawer
78      */
openAllWidgets(boolean reset)79     public UiObject2 openAllWidgets(boolean reset);
80 
81     /**
82      * Returns a {@link BySelector} describing the all widgets drawer
83      * @return
84      */
getAllWidgetsSelector()85     public BySelector getAllWidgetsSelector();
86 
87     /**
88      * Retrieves the all widgets drawer forward scroll direction as implemented by the launcher
89      * @return
90      */
getAllWidgetsScrollDirection()91     public Direction getAllWidgetsScrollDirection();
92 
93     /**
94      * Returns a {@link BySelector} describing the home screen workspace
95      * @return
96      */
getWorkspaceSelector()97     public BySelector getWorkspaceSelector();
98 
99     /**
100      * Returns a {@link BySelector} describing the home screen hot seat (app icons at the bottom)
101      * @return
102      */
getHotSeatSelector()103     public BySelector getHotSeatSelector();
104 
105     /**
106      * Retrieves the home screen workspace forward scroll direction as implemented by the launcher
107      * @return
108      */
getWorkspaceScrollDirection()109     public Direction getWorkspaceScrollDirection();
110 
111     /**
112      * Launch the named application
113      * @param appName the name of the application to launch as shown in launcher
114      * @param packageName the expected package name to verify that the application has been launched
115      *                    into foreground. If <code>null</code> is provided, no verification is
116      *                    performed.
117      * @return <code>true</code> if application is verified to be in foreground after launch, or the
118      *   verification is skipped; <code>false</code> otherwise.
119      */
launch(String appName, String packageName)120     public long launch(String appName, String packageName);
121 }
122