Skip to content

Commit

Permalink
fix bug:兼容 安卓10,miui11 (is_screenon(),is_locked())
Browse files Browse the repository at this point in the history
Fix bug #711

【安卓10 ,miui 11】 ,检测不了屏幕是否锁定 "Couldn't determine screen ON “

设备:小米8 miui11 android 10
1.is_screenon()
2.is_locked()

以上2个api,检测屏幕是否锁定时报错:"Couldn't determine screen ON “
(cherry picked from commit 80575ab)

(cherry picked from commit 1300359)
  • Loading branch information
Pactortester authored and yimelia committed Jun 28, 2020
1 parent d0a2040 commit c6b0823
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions airtest/core/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,18 @@ def is_screenon(self):
True or False whether the screen is turned on or off
"""
screenOnRE = re.compile('mScreenOnFully=(true|false)')
m = screenOnRE.search(self.shell('dumpsys window policy'))
if m:
return (m.group(1) == 'true')
raise AirtestError("Couldn't determine screen ON state")
try:
screenOnRE = re.compile('mScreenOnFully=(true|false)')
m = screenOnRE.search(self.shell('dumpsys window policy'))
if m:
return (m.group(1) == 'true')
raise AirtestError("Couldn't determine screen ON state")
except Exception:
screenOnRE = re.compile('screenState=(SCREEN_STATE_ON|SCREEN_STATE_OFF)')
m = screenOnRE.search(self.shell('dumpsys window policy'))
if m:
return (m.group(1) == 'SCREEN_STATE_ON')
raise AirtestError("Couldn't determine screen ON state")

def is_locked(self):
"""
Expand All @@ -1076,7 +1083,7 @@ def is_locked(self):
True or False whether the screen is locked or not
"""
lockScreenRE = re.compile('(?:mShowingLockscreen|isStatusBarKeyguard)=(true|false)')
lockScreenRE = re.compile('(?:mShowingLockscreen|isStatusBarKeyguard|showing)=(true|false)')
m = lockScreenRE.search(self.shell('dumpsys window policy'))
if not m:
raise AirtestError("Couldn't determine screen lock state")
Expand Down

0 comments on commit c6b0823

Please sign in to comment.