mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
devlib/AndroidTarget: Update screen state methods to handle doze
Newer devices can have a "DOZE" or always on screen state. Enable the screen state to handle these cases and report these states as `ON`.
This commit is contained in:
parent
c25852b210
commit
ccde9de257
@ -58,7 +58,7 @@ from devlib.utils.types import integer, boolean, bitmask, identifier, caseless_s
|
||||
|
||||
|
||||
FSTAB_ENTRY_REGEX = re.compile(r'(\S+) on (.+) type (\S+) \((\S+)\)')
|
||||
ANDROID_SCREEN_STATE_REGEX = re.compile('(?:mPowerState|mScreenOn|Display Power: state)=([0-9]+|true|false|ON|OFF)',
|
||||
ANDROID_SCREEN_STATE_REGEX = re.compile('(?:mPowerState|mScreenOn|Display Power: state)=([0-9]+|true|false|ON|OFF|DOZE)',
|
||||
re.IGNORECASE)
|
||||
ANDROID_SCREEN_RESOLUTION_REGEX = re.compile(r'cur=(?P<width>\d+)x(?P<height>\d+)')
|
||||
ANDROID_SCREEN_ROTATION_REGEX = re.compile(r'orientation=(?P<rotation>[0-3])')
|
||||
@ -1564,17 +1564,28 @@ class AndroidTarget(Target):
|
||||
output = self.execute('dumpsys power')
|
||||
match = ANDROID_SCREEN_STATE_REGEX.search(output)
|
||||
if match:
|
||||
if 'DOZE' in match.group(1).upper():
|
||||
return True
|
||||
return boolean(match.group(1))
|
||||
else:
|
||||
raise TargetStableError('Could not establish screen state.')
|
||||
|
||||
def ensure_screen_is_on(self):
|
||||
def ensure_screen_is_on(self, verify=True):
|
||||
if not self.is_screen_on():
|
||||
self.execute('input keyevent 26')
|
||||
if verify and not self.is_screen_on():
|
||||
raise TargetStableError('Display cannot be turned on.')
|
||||
|
||||
def ensure_screen_is_off(self):
|
||||
def ensure_screen_is_off(self, verify=True):
|
||||
# Allow 2 attempts to help with cases of ambient display modes
|
||||
# where the first attempt will switch the display fully on.
|
||||
for _ in range(2):
|
||||
if self.is_screen_on():
|
||||
self.execute('input keyevent 26')
|
||||
time.sleep(0.5)
|
||||
if verify and self.is_screen_on():
|
||||
msg = 'Display cannot be turned off. Is always on display enabled?'
|
||||
raise TargetStableError(msg)
|
||||
|
||||
def set_auto_brightness(self, auto_brightness):
|
||||
cmd = 'settings put system screen_brightness_mode {}'
|
||||
|
@ -660,18 +660,24 @@ Android Target
|
||||
Returns ``True`` if the targets auto brightness is currently
|
||||
enabled and ``False`` otherwise.
|
||||
|
||||
.. method:: AndroidTarget.ensure_screen_is_off()
|
||||
.. method:: AndroidTarget.ensure_screen_is_off(verify=True)
|
||||
|
||||
Checks if the devices screen is on and if so turns it off.
|
||||
If ``verify`` is set to ``True`` then a ``TargetStableError``
|
||||
will be raise if the display cannot be turned off. E.g. if
|
||||
always on mode is enabled.
|
||||
|
||||
.. method:: AndroidTarget.ensure_screen_is_on()
|
||||
.. method:: AndroidTarget.ensure_screen_is_on(verify=True)
|
||||
|
||||
Checks if the devices screen is off and if so turns it on.
|
||||
If ``verify`` is set to ``True`` then a ``TargetStableError``
|
||||
will be raise if the display cannot be turned on.
|
||||
|
||||
.. method:: AndroidTarget.is_screen_on()
|
||||
|
||||
Returns ``True`` if the targets screen is currently on and ``False``
|
||||
otherwise.
|
||||
otherwise. If the display is in a "Doze" mode or similar always on state,
|
||||
this will return ``True``.
|
||||
|
||||
.. method:: AndroidTarget.wait_for_device(timeout=30)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user