diff --git a/module/device/connection.py b/module/device/connection.py index 3db639ad9a..cbbc8b2b8f 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -719,6 +719,41 @@ def get_orientation(self): logger.attr('Device Orientation', f'{o} ({Connection._orientation_description.get(o, "Unknown")})') return o + @retry + def get_interactive(self): + """ + Makes sure device is interactive before starting tasks + """ + _INTERACTIVE_RE = re.compile( + r'mInteractive=(?P.+)' + ) + output = self.adb_shell(['dumpsys', 'input_method']) + + interactive = _INTERACTIVE_RE.search(output, 0) + + result = True + if interactive: + o = interactive.group('interactive') + if o == "true": + pass + elif o == "false": + result = False + else: + logger.warning(f'Invalid device interactivity: {o}, assume it is normal') + else: + logger.warning('Unable to get device interactivity, assume it is normal') + + logger.attr('Device interactive', {result}) + return result + + @retry + def wake(self): + """ + Attempts to wake device by pressing power button + """ + logger.info('Attempting to wake device') + self.adb_shell(['input', 'keyevent', 'KEYCODE_POWER']) + @retry def list_device(self): """ diff --git a/module/handler/login.py b/module/handler/login.py index 5b76643249..cb982a8273 100644 --- a/module/handler/login.py +++ b/module/handler/login.py @@ -34,6 +34,12 @@ def _handle_app_login(self): login_success = False while 1: + # Make sure device is interactive + if not self.device.get_interactive(): + self.device.wake() + self.device.sleep(1) + continue + # Watch device rotation if not login_success and orientation_timer.reached(): # Screen may rotate after starting an app diff --git a/module/ui/ui.py b/module/ui/ui.py index 8ae99bc86f..ed47d3f6c1 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -144,6 +144,10 @@ def rotation_check(): timeout = Timer(10, count=20).start() while 1: + if not self.device.get_interactive(): + self.device.wake() + self.device.sleep(1) + continue if skip_first_screenshot: skip_first_screenshot = False if not hasattr(self.device, "image") or self.device.image is None: