Inherits from AdbHandset. Refer to separate document for a list of inherited functions.
Although handset objects can be created explicitly, you should always allocate handsets through the broker instead (possibly with more attributes set in the allocation profile):
from ave.broker import Broker
broker = Broker()
handset = broker.get({'type':'handset', 'platform':'android'})
The returned handset implements the API that is documented here.
Warning
Many functions require super user privileges and will not work before a root() call has been made.
Parameters: | profile – A HandsetProfile instance that must contain at least the following members: {
'type' : 'handset',
'platform': 'android',
'serial' : 'xxx' # the serial number of the handset
}
|
---|
Android handsets can be in any of the following power states:
'offline', # the handset is turned off or not connected
'service', # the handset is in service mode
'enumeration', # the handset's USB is set up and ready
'adb', # the handset is available via adb
'package_manager', # the Android package manager is ready
'boot_completed' # the sys.boot_completed property is set to "1"
Returns: | A string denoting the current power state. |
---|---|
Raises Exception: | |
If an error occured. |
Wait for the handset to reach a desired power state. The function returns when the first matching power state has been reached.
Parameters: |
|
---|---|
Returns: | The reached power state. |
Raises Exception: | |
If a state is invalid, an error or time out occurs. |
On a normal boot of a handset it will go through the power states in the following order:
offline > enumeration > adb > package_manager > boot_completed
Reboot the handset. The function returns when the handset enters the offline power state. Use e.g. wait_power_state('boot_completed') to wait for the handset to return to a fully booted state.
Parameters: |
|
---|---|
Raises: |
|
Get the phone number from SIM card.
Returns: | The phone number, formatted as a string. |
---|
Returns: | The name of the GSM operator, if any. Note that handsets in flight mode have no GSM operator even if they have a valid SIM card inserted. |
---|
Press key with the given keycode. These are the same codes as appear in Android SDK documentation. E.g. 3 is the go-to-home-screen key.
Parameters: | keycode – The keycode of the key to press, an integer. |
---|---|
Raises Exception: | |
If the keypress failed. |
Open the status bar.
Returns: | True if successfully opened status bar, otherwise False. |
---|
Check whether a view with the given identity is visible. View ID’s can be found by inspecting a running application with hierarchyviewer, which is included in the Android SDK.
Parameters: | identity – A string. The identity of the view. |
---|---|
Returns: | True if visible, else False. |
Check whether a checkbox with an ID that matches the given pattern is visible.
Parameters: | pattern – A string holding the ID to look for. |
---|---|
Returns: | True if visible, else False. |
Search for a visible view with text that is an exact match of the given pattern.
Parameters: | pattern – The exact match of the text in the view. |
---|---|
Returns: | True if visible, else False. |
Search for a visible view with text that is a match of the given regexp pattern.
Parameters: | pattern – The regexp pattern to search for. Note that this must be a plain regular expression, not a PCRE styled one. |
---|---|
Returns: | True if visible, else False. |
Click on an item with an ID that matches the given pattern.
Parameters: | identity – A string holding the ID to look for. |
---|---|
Returns: | True if succeeded, else False. |
Click on the item with text that is an exact match of the given pattern.
Parameters: | pattern – The exact pattern of the text in the item. |
---|---|
Returns: | True if succeeded, else False. |
Click on the item with text that is a match of the given regexp pattern.
Parameters: | pattern – The regexp pattern of the text in the view. |
---|---|
Returns: | True if succeeded, else False. |
Wait until a view with the given identity is visible.
Parameters: |
|
---|
Wait until a view with text that is an exact match of the given pattern is visible.
Parameters: |
|
---|
Wait until a view with text that is a match of the given regexp pattern is visible.
Parameters: |
|
---|---|
Raises Timeout: | If such occured. |
Get handset display bound for current display orientation.
Raises Exception: | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||
Returns: | Bound dictionary representing device display bound. |
||||||||||||||||||
Example : | >>> # Get handset display size
>>> bound = handset.get_display_bound()
>>> width = bound['width']
>>> height = bound['height']
>>> # Get center point of display
>>> bound = handset.get_display_bound()
>>> x = bound['center_x']
>>> y = bound.['center_y']
Following keys can be used on returned bound dictionary to fetch information
|
Get handset application content area bound. Application content area bound represents viewing area on the handset display except status bar and navigation bar.
Raises Exception: | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||
Returns: | Bound dictionary representing application content area bound. |
||||||||||||||||||
Example : | >>> # Get application content area rectangle
>>> bound = handset.get_application_content_area_bound()
>>> top_left_x = bound['x1']
>>> top_left_y = bound['y1']
>>> width = bound['width']
>>> height = bound['height']
Following keys can be used on returned bound dictionary to fetch information
|
Get handset status bar bound. Status bar bound represents area in display except application content area and navigation bar area.
Raises Exception: | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||
Returns: | Bound dictionary representing status bar area bound. |
||||||||||||||||||
Example : | >>> # Get status bar area rectangle
>>> bound = handset.get_status_bar_bound()
>>> top_left_x = bound['x1']
>>> top_left_y = bound['y1']
>>> width = bound['width']
>>> height = bound['height']
Following keys can be used on returned bound dictionary to fetch information
|
Get handset navigation bar bound. Navigation bar represents area in display except application content area and status bar area.
Raises Exception: | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||
Returns: | Bound dictionary representing navigation bar area bound. |
||||||||||||||||||
Example : | >>> # Get navigation bar area rectangle
>>> bound = handset.get_navigation_bar_bound()
>>> top_left_x = bound['x1']
>>> top_left_y = bound['y1']
>>> width = bound['width']
>>> height = bound['height']
Following keys can be used on returned bound dictionary to fetch information
|
Get handset display orientation.
Raises Exception: | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||
Returns: | String representing handset display orientation. Possible return values are:
|
||||||||||
Example : | >>> # Check if display is in 180 degree rotation
>>> rotation = handset.get_display_orientation()
>>> is_180_degree = rotation == '2'
|
Check if handset display orientation is in portrait mode. Display is in portrait mode if display orientation is either 0 degree or 180 degree.
Raises Exception: | |
---|---|
|
|
Returns: | Boolean value True if display orientation is in portrait mode else False. |
Example : | >>> # Check if handset display is in portrait mode
>>> if handset.is_orientation_portrait():
>>> print "Display is in Portrait mode"
|
Check if handset display orientation is in landscape mode. Display is in landscape mode if display orientation is either 90 degree or 270 degree.
Raises Exception: | |
---|---|
|
|
Returns: | Boolean value True if display orientation is in landscape mode else False. |
Example : | >>> # Check if handset display is in landscape mode
>>> if handset.is_orientation_landscape():
>>> print "Display is in Landscape mode"
|
Get bound for a view present in the device display.
Raises Exception: | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||
Parameters: |
|
||||||||||||||||||
Returns: | Bound dictionary for the matched view. |
||||||||||||||||||
Example : | >>> # Get rectangle for a view with id "Album-Image" and second occurrence in screen.
>>> bound = handset.get_view_bound("id", "album-image", index=1)
>>> top_left_x = bound['x1']
>>> top_left_y = bound['y1']
>>> width = bound['width']
>>> height = bound['height']
>>> # Get center coordinate of the first view with type "android.widget.ImageView"
>>> bound = handset.get_view_bound("type", "imageview")
>>> x = bound['center_x']
>>> y = bound['center_y']
>>> # Get bottom right coordinate for first view with exact text "Hello World"
>>> bound = handset.get_view_bound("text", "Hello World", matching=False)
>>> x = bound['x2']
>>> y = bound['y2']
>>> # Get width and height of 5'th view with description "item_image"
>>> bound = handset.get_view_bound("desc", "item_image", index=4)
>>> width = bound['width']
>>> height = bound['height']
Following keys can be used on returned bound dictionary to fetch information
|
Removes a dialog that asks the user to choose the usb mode. Caller must have called .root() beforehand.
Enables a dialog that asks the user to choose the usb mode. Caller must have called .root() beforehand.
Disables the following security check that was introduced in Jelly Bean: A dialog appears when the user installs an APK from an unknown source (e.g. one installed with ADB). The user must accept or reject the installation to remove the dialog.
Enables the following security check that was introduced in Jelly Bean: A dialog appears when the user installs an APK from an unknown source (e.g. one installed with ADB). The user must accept or reject the installation to remove the dialog.
List all installed packages on the handset.
Returns: | A list with all installed packages. |
---|---|
Raises Exception: | |
If it was not possible to list packages. |
Check if the given package is installed on the handset.
Parameters: | package – The package to check. |
---|---|
Returns: | True if the package is installed, False otherwise. |
Install an APK on the handset.
Parameters: |
|
---|
Uninstall an APK from the handset.
Parameters: | package – The name of the package to uninstall. |
---|
Reinstall an APK on the handset.
Parameters: | apk_path – The path to the APK to reinstall. |
---|
Get the version code of the package.
Parameters: | package – The package to check. |
---|---|
Returns: | Version code of the package. |
Raises Exception: | |
If it was not possible to get the version code. |
Prints all known permissions. Defalut options are ‘-d -g’.
Parameters: | args – -g: organize by group. -f: print all information. -s: short summary. -d: only list dangerous permissions. -u: list only the permissions users will see. |
---|---|
Returns: | permissions list string |
Grant permissions to apps. The permissions must be declared as used in the app’s manifest, be runtime permissions (protection level dangerous), and the app targeting SDK greater than Lollipop MR1.
Parameters: |
|
---|---|
Returns: | True |
Raises Exception: | |
If an error occurs |
Revoke permissions to apps. The permissions must be declared as used in the app’s manifest, be runtime permissions (protection level dangerous), and the app targeting SDK greater than Lollipop MR1.
Parameters: |
|
---|---|
Returns: | True |
Raises Exception: | |
If an error occurs |
Set a property.
Note
Local properties are not supported if handset’s SDK version > 15.
Note
If local=False and the key doesn’t start with “persist.” the property will be reset when handset is rebooted.
Note
If local=True, changes will only take effect upon reboot.
Note
If local=True, properties will be persistent through rebooting until /data/local.prop is cleared and the handset is rebooted again.
Parameters: |
|
---|---|
Raises Exception: | |
If the property was not set successfully. |
Clear all local properties by removing /data/local.prop. The change does not take effect until the handset is rebooted.
Note
Local properties are not supported if handset’s SDK version > 15.
Erase logcat logs from the handset.
Parameters: | args – Arguments to logcat; e.g. "-b main -b system". |
---|
Start Logcat logging.
Parameters: |
|
---|---|
Returns: | A unique ID that can be used with get_log(). |
Stop Logcat logging for the specified UID.
Every call to start_logcat spawns a new Logcat logger thread which will remain active until the handset is deallocated. To preserve system resources, the caller should always call stop_logcat to free up system resources when the logcat associated with the specified UID is no longer needed.
Parameters: | uid – The unique id returned by start_logcat(). |
---|
Get the logcat log by UID.
Parameters: |
|
---|---|
Returns: | The logcat log as a string. |
Get the JUnit instrumentation runners of a package on the handset.
Parameters: | package – The target package. |
---|---|
Returns: | A list of all instrumentation runners included in the package. |
Run JUnit tests on the handset.
It’s possible to run full test scope of the junit instrumentation test or just a subset of it, depending on what parameters are given. Exactly one of apk, runner and raw must be given, i.e. they may not be combined. The possible parameter combinations can be found in the table below and more details can be found under Args.
PARAMETERS | WHAT TO EXECUTE |
---|---|
test_package | All tests in the package (all runners) |
runner | All tests in the given runner |
runner, test_options | All tests that matches the parameters |
raw | All tests that matches the raw parameters |
Parameters: |
|
---|---|
Raises: |
|
Returns: | The instrumentation test output as a string. |
Try to kill the process of a JUit test running from a specific package.
Returns a list of GTest tests.
Parameters: | target – The path on the handset to the GTest executable. |
---|---|
Returns: | A list of test names. |
Raises Exception: | |
If target is not an existing executable file on the handset. |
Execute a GTest runner on the handset. If result_path is given, the execution output file and GTest result XML file will be saved on the host in that directory (not on the handset).
Parameters: |
|
---|---|
Returns: | A 3-tuple containing the following items:
|
Raises: |
|
Advanced Options:
--gtest_filter=POSTIVE_PATTERNS[-NEGATIVE_PATTERNS]
--gtest_also_run_disabled_tests
--gtest_repeat=[COUNT]
--gtest_shuffle
--gtest_random_seed=[NUMBER]
--gtest_color=(yes|no|auto)
--gtest_print_time=0
--gtest_death_test_style=(fast|threadsafe)
--gtest_break_on_failure
--gtest_throw_on_failure
--gtest_catch_exceptions=0
Check if mount_point is mounted.
Args mount_point: | |
---|---|
Mount point. | |
Returns: | True if mount_point is mounted, else False. |
Returns: | True if internal SD Card is mounted, else False. |
---|
Returns: | True if the external SD Card is mounted, else False. |
---|
Convenience method to set/unset property libc.debug.malloc and execute ‘stop’ and ‘start’ on the handset (stop/start must be executed for the change to take effect). The property libc.debug.malloc must be set to be able to dump native heap with dump_heap(native=True).
Note
Application processes will be restarted and get new PIDs.
Note
The libc.debug.malloc property is reset on reboot.
Parameters: |
|
---|---|
Returns: | True if the property was set before execution of this method, else False. |
Raises: |
|
Dump heap for processes with name ‘package’ (using am dumpheap) and save the resulting hprof-files to the directory on the host (not on the handset).
Note
The property libc.debug.malloc must already be set if native=True. See set_libc_debug_malloc().
Parameters: |
|
---|---|
Returns: | A list with each generated hprof file’s full path on the host. |
Raises: |
|
set the App Standby mode
Parameters: |
|
---|
get the App Standby mode
Parameters: | package – the app package name |
---|---|
Returns: | the app mode |
set Battery Service state
Parameters: | operate – default is unplug, pretend device not to be charged |
---|
Transition to Doze (Idle) mode
Parameters: |
|
---|