From 2b6cb264cffc97149030c6cd6e2b6873180434d3 Mon Sep 17 00:00:00 2001 From: Pierre-Clement Tosi Date: Tue, 18 Dec 2018 11:49:12 +0000 Subject: [PATCH] utils.android.ApkInfo: Add reading activity names Add an activities pseudo-attribute to the ApkInfo class that retrieves the names of the activities (_i.e._ entry points) of the APK. To keep backward compatibility, these are retrieved the first time the attribute is being accessed. --- devlib/utils/android.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index d617528..7b0ae58 100755 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -132,6 +132,7 @@ class ApkInfo(object): version_regex = re.compile(r"name='(?P[^']+)' versionCode='(?P[^']+)' versionName='(?P[^']+)'") name_regex = re.compile(r"name='(?P[^']+)'") permission_regex = re.compile(r"name='(?P[^']+)'") + activity_regex = re.compile(r'\s*A:\s*android:name\(0x\d+\)=".(?P\w+)"') def __init__(self, path=None): self.path = path @@ -180,6 +181,18 @@ class ApkInfo(object): else: pass # not interested + self._apk_path = apk_path + self._activities = None + + @property + def activities(self): + if self._activities is None: + cmd = [aapt, 'dump', 'xmltree', self._apk_path, + 'AndroidManifest.xml'] + matched_activities = self.activity_regex.finditer(self._run(cmd)) + self._activities = [m.group('name') for m in matched_activities] + return self._activities + def _run(self, command): logger.debug(' '.join(command)) try: