Home | History | Annotate | Download | only in helpers
      1 /*
      2  * Copyright (C) 2016 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.platform.helpers;
     18 
     19 import android.content.pm.PackageManager.NameNotFoundException;
     20 
     21 import java.io.IOException;
     22 
     23 public interface IAppHelper {
     24 
     25     /**
     26      * Setup expectation: On the launcher home screen.
     27      *
     28      * Launches the desired application.
     29      */
     30     abstract void open();
     31 
     32     /**
     33      * Setup expectation: None
     34      * <p>
     35      * Presses back until the launcher package is visible, i.e. the home screen. This can be
     36      * overriden for custom functionality, however consider and document the exit state if doing so.
     37      */
     38     abstract void exit();
     39 
     40     /**
     41      * Setup expectations: This application is on the initial launch screen.
     42      * <p>
     43      * Dismiss all visible relevant dialogs and block until this process is complete.
     44      */
     45     abstract void dismissInitialDialogs();
     46 
     47     /**
     48      * Setup expectations: None
     49      * <p>
     50      * Get the target application's component package.
     51      * @return the package name for this helper's application.
     52      */
     53     abstract String getPackage();
     54 
     55     /**
     56      * Setup expectations: None.
     57      * <p>
     58      * Get the target application's launcher name.
     59      * @return the name of this application's launcher.
     60      */
     61     abstract String getLauncherName();
     62 
     63     /**
     64      * Setup expectations: None
     65      * <p>
     66      * Get the target application's version String.
     67      * @return the version code
     68      * @throws NameNotFoundException if {@code getPackage} is not found
     69      */
     70     abstract String getVersion() throws NameNotFoundException;
     71 
     72     /**
     73      * Setup expectations: None
     74      * @return true, if this app's package is the root (depth 0), and false otherwise
     75      */
     76     abstract boolean isAppInForeground();
     77 
     78     /**
     79      * Setup expectations: None
     80      * <p>
     81      * Captures a screenshot and UI XML with the supplied name.
     82      * @param name the screenshot prefix
     83      * @throws IOException if there is a capture failure
     84      * @throws RuntimeException if creating the screenshot directory fails.
     85      */
     86     abstract boolean captureScreenshot(String name) throws IOException;
     87 
     88     /**
     89      * Sends text events to the device through key codes.
     90      * <p>
     91      * Note: use this only when text accessibility is not supported.
     92      * @param text the text to input as events
     93      * @param delay the delay between each event
     94      * @return true if successful, false otherwise
     95      */
     96     abstract boolean sendTextEvents(String text, long delay);
     97 }
     98