Skip to content

Commit

Permalink
Merge pull request #152 from Niweera/master
Browse files Browse the repository at this point in the history
[Feature] Update Droidbot tool to support Android API Level 32
  • Loading branch information
yuanchun-li authored Jul 11, 2023
2 parents 0186a84 + af0e386 commit a9fedcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion droidbot/adapter/droidbot_ime.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def disconnect(self):
"""
self.connected = False
r_disable = self.device.adb.shell("ime disable %s" % IME_SERVICE)
if r_disable.endswith("now disabled"):
if "now disabled" in r_disable:
self.connected = False
print("[CONNECTION] %s is disconnected" % self.__class__.__name__)
return
Expand Down
20 changes: 15 additions & 5 deletions droidbot/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def __init__(self, device_serial=None, is_emulator=False, output_dir=None,
self.logger.info("disable minicap on emulator")
self.adapters[self.minicap] = False

# minicap is not supporting android 32 and above
if self.get_sdk_version() >= 32:
self.logger.info("disable minicap on sdk >= 32")
self.adapters[self.minicap] = False

def check_connectivity(self):
"""
check if the device is available
Expand Down Expand Up @@ -504,7 +509,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 +546,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
2 changes: 2 additions & 0 deletions droidbot/device_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __parse_views(self, raw_views):

def __assemble_view_tree(self, root_view, views):
if not len(self.view_tree): # bootstrap
if not len(views): # to fix if views is empty
return
self.view_tree = copy.deepcopy(views[0])
self.__assemble_view_tree(self.view_tree, views)
else:
Expand Down

0 comments on commit a9fedcf

Please sign in to comment.