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 all apps drawer 58 * @return 59 */ getAllAppsSelector()60 public BySelector getAllAppsSelector(); 61 62 /** 63 * Retrieves the all apps drawer forward scroll direction as implemented by the launcher 64 * @return 65 */ getAllAppsScrollDirection()66 public Direction getAllAppsScrollDirection(); 67 68 /** 69 * Opens the all widgets drawer of launcher 70 * @param reset if the all widgets drawer should be reset to the beginning 71 * @return {@link UiObject2} representation of the all widgets drawer 72 */ openAllWidgets(boolean reset)73 public UiObject2 openAllWidgets(boolean reset); 74 75 /** 76 * Returns a {@link BySelector} describing the all widgets drawer 77 * @return 78 */ getAllWidgetsSelector()79 public BySelector getAllWidgetsSelector(); 80 81 /** 82 * Retrieves the all widgets drawer forward scroll direction as implemented by the launcher 83 * @return 84 */ getAllWidgetsScrollDirection()85 public Direction getAllWidgetsScrollDirection(); 86 87 /** 88 * Returns a {@link BySelector} describing the home screen workspace 89 * @return 90 */ getWorkspaceSelector()91 public BySelector getWorkspaceSelector(); 92 93 /** 94 * Returns a {@link BySelector} describing the home screen hot seat (app icons at the bottom) 95 * @return 96 */ getHotSeatSelector()97 public BySelector getHotSeatSelector(); 98 99 /** 100 * Retrieves the home screen workspace forward scroll direction as implemented by the launcher 101 * @return 102 */ getWorkspaceScrollDirection()103 public Direction getWorkspaceScrollDirection(); 104 105 /** 106 * Launch the named application 107 * @param appName the name of the application to launch as shown in launcher 108 * @param packageName the expected package name to verify that the application has been launched 109 * into foreground. If <code>null</code> is provided, no verification is 110 * performed. 111 * @return <code>true</code> if application is verified to be in foreground after launch, or the 112 * verification is skipped; <code>false</code> otherwise. 113 */ launch(String appName, String packageName)114 public long launch(String appName, String packageName); 115 } 116