From fe5ea33cfe784daced346703aeeb8c2c4efd2396 Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Mon, 20 Jun 2016 17:51:53 +0100 Subject: [PATCH] libs/utils/android: add more system utility functions Signed-off-by: Michele Di Giorgio --- libs/utils/android/system.py | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index 87258e49e..c4429f431 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -37,4 +37,48 @@ class System(object): '--ez state {}'\ .format(ap_state)) + @staticmethod + def start(target, apk_name, activity_name): + """ + Start an application. + + :param apk_name: name of the apk + :type apk_name: str + + :param activity_name: name of the activity to launch + :type activity_name: str + """ + target.execute('am start -n {}/{}'.format(apk_name, activity_name)) + + @staticmethod + def force_stop(target, apk_name, clear=False): + """ + Stop the application and clear its data if necessary. + + :param target: instance of devlib Android target + :type target: devlib.target.AndroidTarget + + :param apk_name: name of the apk + :type apk_name: str + + :param clear: clear application data + :type clear: bool + """ + target.execute('am force-stop {}'.format(apk_name)) + if clear: + target.execute('pm clear {}'.format(apk_name)) + + @staticmethod + def tap(target, x, y): + """ + Tap a given point on the screen. + + :param x: horizontal coordinate + :type x: int + + :param y: vertical coordinate + :type y: int + """ + target.execute('tap {} {}'.format(x, y)) + # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab