From 2d96840873d6b57917364351345bf8ba3bd4c160 Mon Sep 17 00:00:00 2001 From: Valentin Schneider Date: Mon, 12 Jun 2017 18:59:44 +0100 Subject: [PATCH] utils/android: Fix error detection in adb_shell() If we execute a command such as: 'am start -a android.intent.action.VIEW -d nothing' on Hikey960 with AOSP master, we do get an error message: 'Error: Activity not started, unable to resolve Intent ...' but the error code is set to 0. Furthermore, that error message is outputted to STDERR and not STDOUT. The current error checking in adb_shell() is done by either reading the error code or finding an error string in the standard output. This commit adds a check of the error output, and also changes the regular expression that is used to find an error string as it wasn't generic enough. --- devlib/utils/android.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index bd49ea4..f683190 100644 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -34,7 +34,7 @@ from devlib.utils.misc import escape_single_quotes, escape_double_quotes logger = logging.getLogger('android') MAX_ATTEMPTS = 5 -AM_START_ERROR = re.compile(r"Error: Activity class {[\w|.|/]*} does not exist") +AM_START_ERROR = re.compile(r"Error: Activity.*") # See: # http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels @@ -366,19 +366,19 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, if check_exit_code: exit_code = exit_code.strip() + re_search = AM_START_ERROR.findall('{}\n{}'.format(output, error)) if exit_code.isdigit(): if int(exit_code): message = ('Got exit code {}\nfrom target command: {}\n' 'STDOUT: {}\nSTDERR: {}') raise TargetError(message.format(exit_code, command, output, error)) - elif AM_START_ERROR.findall(output): - message = 'Could not start activity; got the following:' - message += '\n{}'.format(AM_START_ERROR.findall(output)[0]) - raise TargetError(message) - else: # not all digits - if AM_START_ERROR.findall(output): + elif re_search: message = 'Could not start activity; got the following:\n{}' - raise TargetError(message.format(AM_START_ERROR.findall(output)[0])) + raise TargetError(message.format(re_search[0])) + else: # not all digits + if re_search: + message = 'Could not start activity; got the following:\n{}' + raise TargetError(message.format(re_search[0])) else: message = 'adb has returned early; did not get an exit code. '\ 'Was kill-server invoked?'