From b37b927fd09be29e17ad63f11235008409c5bbc7 Mon Sep 17 00:00:00 2001 From: fro0116 Date: Mon, 8 Apr 2024 21:48:28 -0700 Subject: [PATCH 1/3] Add interactivity check --- module/device/connection.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/module/device/connection.py b/module/device/connection.py index 3db639ad9a..4aeb30e505 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -719,6 +719,33 @@ 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 list_device(self): """ From 46c3cbbdfa3dbd301b5f0fa1484622ea04a57e43 Mon Sep 17 00:00:00 2001 From: fro0116 Date: Mon, 8 Apr 2024 21:50:23 -0700 Subject: [PATCH 2/3] Ensure interactivity --- module/ui/ui.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/module/ui/ui.py b/module/ui/ui.py index 8ae99bc86f..7685c29782 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -144,6 +144,11 @@ def rotation_check(): timeout = Timer(10, count=20).start() while 1: + if not self.device.get_interactive(): + logger.info('Device not interactive, attempting to wake device') + self.device.adb_shell(['input', 'keyevent', 'KEYCODE_POWER']) + 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: From 9615777eeb606fa2ebd72d4afe169bcbc7002712 Mon Sep 17 00:00:00 2001 From: fro0116 Date: Tue, 9 Apr 2024 16:21:21 -0700 Subject: [PATCH 3/3] Ensure interactivity on login too --- module/device/connection.py | 8 ++++++++ module/handler/login.py | 6 ++++++ module/ui/ui.py | 3 +-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/module/device/connection.py b/module/device/connection.py index 4aeb30e505..cbbc8b2b8f 100644 --- a/module/device/connection.py +++ b/module/device/connection.py @@ -746,6 +746,14 @@ def get_interactive(self): 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 7685c29782..ed47d3f6c1 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -145,8 +145,7 @@ def rotation_check(): timeout = Timer(10, count=20).start() while 1: if not self.device.get_interactive(): - logger.info('Device not interactive, attempting to wake device') - self.device.adb_shell(['input', 'keyevent', 'KEYCODE_POWER']) + self.device.wake() self.device.sleep(1) continue if skip_first_screenshot: