Skip to content

Commit

Permalink
Update get_task_activities to support Android API 32
Browse files Browse the repository at this point in the history
Updated regex pattern
  • Loading branch information
Niweera committed Jun 7, 2023
1 parent 0186a84 commit 4b08408
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions droidbot/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def get_top_activity_name(self):
Get current activity
"""
r = self.adb.shell("dumpsys activity activities")
activity_line_re = re.compile('\* Hist #\d+: ActivityRecord{[^ ]+ [^ ]+ ([^ ]+) t(\d+)}')
activity_line_re = re.compile(r'\*\s*Hist\s*#\d+:\s*ActivityRecord\{[^ ]+\s*[^ ]+\s*([^ ]+)\s*t(\d+)}')
m = activity_line_re.search(r)
if m:
return m.group(1)
Expand Down Expand Up @@ -541,14 +541,19 @@ def get_task_activities(self):
task_to_activities = {}

lines = self.adb.shell("dumpsys activity activities").splitlines()
activity_line_re = re.compile('\* Hist #\d+: ActivityRecord{[^ ]+ [^ ]+ ([^ ]+) t(\d+)}')
activity_line_re = re.compile(r'\*\s*Hist\s*#\d+:\s*ActivityRecord\{[^ ]+\s*[^ ]+\s*([^ ]+)\s*t(\d+)}')

for line in lines:
line = line.strip()
if line.startswith("Task id #"):
task_id = line[9:]
activity_line_task_re = re.compile(r'^\s*Task\s*id\s*#(\d+)|^\s*Task\{\w+\s*#(\d+)')
activity_line_task_m = activity_line_task_re.match(line)
if activity_line_task_m:
if activity_line_task_m.group(1):
task_id = activity_line_task_m.group(1)
else:
task_id = activity_line_task_m.group(2)
task_to_activities[task_id] = []
elif line.startswith("* Hist #"):
elif re.match(r'\*\s*Hist\s*#', line):
m = activity_line_re.match(line)
if m:
activity = m.group(1)
Expand Down

0 comments on commit 4b08408

Please sign in to comment.