1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 10:11:17 +00:00

android device: added swipe-to-unlock option

This commit is contained in:
Sergei Trofimov 2015-10-01 09:53:21 +01:00
parent dc01dd79ee
commit fe4d49e334

View File

@ -33,6 +33,7 @@ from wlauto.utils.android import (adb_shell, adb_background_shell, adb_list_devi
SCREEN_STATE_REGEX = re.compile('(?:mPowerState|mScreenOn)=([0-9]+|true|false)', re.I) SCREEN_STATE_REGEX = re.compile('(?:mPowerState|mScreenOn)=([0-9]+|true|false)', re.I)
SCREEN_SIZE_REGEX = re.compile(r'mUnrestrictedScreen=\(\d+,\d+\)\s+(?P<width>\d+)x(?P<height>\d+)')
class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223 class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
@ -71,6 +72,11 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
Specified whether the device should make sure that the screen is on Specified whether the device should make sure that the screen is on
during initialization. during initialization.
"""), """),
Parameter('swipe_to_unlock', kind=boolean, default=False,
description="""
If set to ``True``, a horisonal swipe will be performed 2/3 down the screen.
This should unlock the screen.
"""),
] ]
default_timeout = 30 default_timeout = 30
@ -555,6 +561,23 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
else: else:
return adb_shell(self.adb_name, 'logcat -c', timeout=self.default_timeout) return adb_shell(self.adb_name, 'logcat -c', timeout=self.default_timeout)
def get_screen_size(self):
output = self.execute('dumpsys window')
match = SCREEN_SIZE_REGEX.search(output)
if match:
return (int(match.group('width')),
int(match.group('height')))
else:
return (0, 0)
def swipe_to_unlock(self):
width, height = self.get_screen_size()
swipe_heigh = height * 2 // 3
start = 100
stop = width - start
command = 'input swipe {} {} {} {}'
self.execute(command.format(start, swipe_heigh, stop, swipe_heigh))
def capture_screen(self, filepath): def capture_screen(self, filepath):
"""Caputers the current device screen into the specified file in a PNG format.""" """Caputers the current device screen into the specified file in a PNG format."""
on_device_file = self.path.join(self.working_directory, 'screen_capture.png') on_device_file = self.path.join(self.working_directory, 'screen_capture.png')