diff --git a/devlib/utils/android.py b/devlib/utils/android.py index bd221bd..d617528 100755 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -147,15 +147,7 @@ class ApkInfo(object): # pylint: disable=too-many-branches def parse(self, apk_path): _check_env() - command = [aapt, 'dump', 'badging', apk_path] - logger.debug(' '.join(command)) - try: - output = subprocess.check_output(command, stderr=subprocess.STDOUT) - if sys.version_info[0] == 3: - output = output.decode(sys.stdout.encoding or 'utf-8', 'replace') - except subprocess.CalledProcessError as e: - raise HostError('Error parsing APK file {}. `aapt` says:\n{}' - .format(apk_path, e.output)) + output = self._run([aapt, 'dump', 'badging', apk_path]) for line in output.split('\n'): if line.startswith('application-label:'): self.label = line.split(':')[1].strip().replace('\'', '') @@ -188,6 +180,17 @@ class ApkInfo(object): else: pass # not interested + def _run(self, command): + logger.debug(' '.join(command)) + try: + output = subprocess.check_output(command, stderr=subprocess.STDOUT) + if sys.version_info[0] == 3: + output = output.decode(sys.stdout.encoding or 'utf-8', 'replace') + except subprocess.CalledProcessError as e: + raise HostError('Error while running "{}":\n{}' + .format(command, e.output)) + return output + class AdbConnection(object):