1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 10:10:46 +00:00

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.
This commit is contained in:
Pierre-Clement Tosi 2018-12-18 11:49:12 +00:00 committed by Marc Bonnici
parent 7e0e6e8706
commit 2b6cb264cf

View File

@ -132,6 +132,7 @@ class ApkInfo(object):
version_regex = re.compile(r"name='(?P<name>[^']+)' versionCode='(?P<vcode>[^']+)' versionName='(?P<vname>[^']+)'") version_regex = re.compile(r"name='(?P<name>[^']+)' versionCode='(?P<vcode>[^']+)' versionName='(?P<vname>[^']+)'")
name_regex = re.compile(r"name='(?P<name>[^']+)'") name_regex = re.compile(r"name='(?P<name>[^']+)'")
permission_regex = re.compile(r"name='(?P<permission>[^']+)'") permission_regex = re.compile(r"name='(?P<permission>[^']+)'")
activity_regex = re.compile(r'\s*A:\s*android:name\(0x\d+\)=".(?P<name>\w+)"')
def __init__(self, path=None): def __init__(self, path=None):
self.path = path self.path = path
@ -180,6 +181,18 @@ class ApkInfo(object):
else: else:
pass # not interested 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): def _run(self, command):
logger.debug(' '.join(command)) logger.debug(' '.join(command))
try: try: