Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright (C) 2011 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 package com.android.chimpchat.core;
     18 
     19 import com.android.chimpchat.ChimpManager;
     20 import com.android.chimpchat.hierarchyviewer.HierarchyViewer;
     21 
     22 import java.util.Collection;
     23 import java.util.List;
     24 import java.util.Map;
     25 
     26 import javax.annotation.Nullable;
     27 
     28 /**
     29  * ChimpDevice interface.
     30  */
     31 public interface IChimpDevice {
     32     /**
     33      * Create a ChimpManager for talking to this device.
     34      *
     35      * @return the ChimpManager
     36      */
     37     ChimpManager getManager();
     38 
     39     /**
     40      * Dispose of any native resources this device may have taken hold of.
     41      */
     42     void dispose();
     43 
     44     /**
     45      * @return hierarchy viewer implementation for querying state of the view
     46      * hierarchy.
     47      */
     48     HierarchyViewer getHierarchyViewer();
     49 
     50     /**
     51      * Take the current screen's snapshot.
     52      * @return the snapshot image
     53      */
     54     IChimpImage takeSnapshot();
     55 
     56     /**
     57      * Reboot the device.
     58      *
     59      * @param into which bootloader to boot into.  Null means default reboot.
     60      */
     61     void reboot(@Nullable String into);
     62 
     63     /**
     64      * List properties of the device that we can inspect
     65      *
     66      * @return the list of property keys
     67      */
     68     Collection<String> getPropertyList();
     69 
     70     /**
     71      * Get device's property.
     72      *
     73      * @param key the property name
     74      * @return the property value
     75      */
     76     String getProperty(String key);
     77 
     78     /**
     79      * Get system property.
     80      *
     81      * @param key the name of the system property
     82      * @return  the property value
     83      */
     84     String getSystemProperty(String key);
     85 
     86     /**
     87      * Perform a touch of the given type at (x,y).
     88      *
     89      * @param x the x coordinate
     90      * @param y the y coordinate
     91      * @param type the touch type
     92      */
     93     void touch(int x, int y, TouchPressType type);
     94 
     95     /**
     96      * Perform a press of a given type using a given key.
     97      *
     98      * @param keyName the name of the key to use
     99      * @param type the type of press to perform
    100      */
    101     void press(String keyName, TouchPressType type);
    102 
    103 
    104     /**
    105      * Perform a press of a given type using a given key.
    106      *
    107      * @param key the key to press
    108      * @param type the type of press to perform
    109      */
    110     void press(PhysicalButton key, TouchPressType type);
    111 
    112     /**
    113      * Perform a drag from one one location to another
    114      *
    115      * @param startx the x coordinate of the drag's starting point
    116      * @param starty the y coordinate of the drag's starting point
    117      * @param endx the x coordinate of the drag's end point
    118      * @param endy the y coordinate of the drag's end point
    119      * @param steps the number of steps to take when interpolating points
    120      * @param ms the duration of the drag
    121      */
    122     void drag(int startx, int starty, int endx, int endy, int steps, long ms);
    123 
    124     /**
    125      * Type a given string.
    126      *
    127      * @param string the string to type
    128      */
    129     void type(String string);
    130 
    131     /**
    132      * Execute a shell command.
    133      *
    134      * @param cmd the command to execute
    135      * @return the output of the command
    136      */
    137     String shell(String cmd);
    138 
    139     /**
    140      * Install a given package.
    141      *
    142      * @param path the path to the installation package
    143      * @return true if success
    144      */
    145     boolean installPackage(String path);
    146 
    147     /**
    148      * Uninstall a given package.
    149      *
    150      * @param packageName the name of the package
    151      * @return true if success
    152      */
    153     boolean removePackage(String packageName);
    154 
    155     /**
    156      * Start an activity.
    157      *
    158      * @param uri the URI for the Intent
    159      * @param action the action for the Intent
    160      * @param data the data URI for the Intent
    161      * @param mimeType the mime type for the Intent
    162      * @param categories the category names for the Intent
    163      * @param extras the extras to add to the Intent
    164      * @param component the component of the Intent
    165      * @param flags the flags for the Intent
    166      */
    167     void startActivity(@Nullable String uri, @Nullable String action,
    168             @Nullable String data, @Nullable String mimeType,
    169             Collection<String> categories, Map<String, Object> extras, @Nullable String component,
    170             int flags);
    171 
    172     /**
    173      * Send a broadcast intent to the device.
    174      *
    175      * @param uri the URI for the Intent
    176      * @param action the action for the Intent
    177      * @param data the data URI for the Intent
    178      * @param mimeType the mime type for the Intent
    179      * @param categories the category names for the Intent
    180      * @param extras the extras to add to the Intent
    181      * @param component the component of the Intent
    182      * @param flags the flags for the Intent
    183      */
    184     void broadcastIntent(@Nullable String uri, @Nullable String action,
    185             @Nullable String data, @Nullable String mimeType,
    186             Collection<String> categories, Map<String, Object> extras, @Nullable String component,
    187             int flags);
    188 
    189     /**
    190      * Run the specified package with instrumentation and return the output it
    191      * generates.
    192      *
    193      * Use this to run a test package using InstrumentationTestRunner.
    194      *
    195      * @param packageName The class to run with instrumentation. The format is
    196      * packageName/className. Use packageName to specify the Android package to
    197      * run, and className to specify the class to run within that package. For
    198      * test packages, this is usually testPackageName/InstrumentationTestRunner
    199      * @param args a map of strings to objects containing the arguments to pass
    200      * to this instrumentation.
    201      * @return A map of strings to objects for the output from the package.
    202      * For a test package, contains a single key-value pair: the key is 'stream'
    203      * and the value is a string containing the test output.
    204      */
    205     Map<String, Object> instrument(String packageName,
    206             Map<String, Object> args);
    207 
    208     /**
    209      * Wake up the screen on the device.
    210      */
    211     void wake();
    212 
    213     /**
    214      * List the possible view ID strings from the current applications resource file
    215      * @return the list of view id strings
    216      */
    217     Collection<String> getViewIdList();
    218 
    219     /**
    220      * Retrieve the view object for the view with the given id.
    221      * @return a view object for the view with the given id
    222      */
    223     IChimpView getView(ISelector selector);
    224 
    225     /**
    226      * Retrive the root view object.
    227      * @return the root view object.
    228      */
    229     IChimpView getRootView();
    230 
    231     /**
    232      * Retrieves the view objects that match the given selector
    233      * @return A list of views that match the given selector
    234      */
    235     Collection<IChimpView> getViews(IMultiSelector selector);
    236 }
    237