diff --git a/lib/helpers.js b/lib/helpers.js index 4641f44f..2159c80b 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -271,6 +271,17 @@ export async function getApkanalyzerForOs (sysHelpers) { return await sysHelpers.getBinaryFromSdkRoot('apkanalyzer'); } +/** + * Checks screenState has SCREEN_STATE_OFF in dumpsys output to determine + * possible lock screen. + * + * @param {string} dumpsys - The output of dumpsys window command. + * @return {boolean} True if lock screen is showing. + */ +export function isScreenStateOff(dumpsys) { + return /\s+screenState=SCREEN_STATE_OFF/i.test(dumpsys); +} + /** * Checks mShowingLockscreen or mDreamingLockscreen in dumpsys output to determine * if lock screen is showing @@ -323,7 +334,8 @@ export function getSurfaceOrientation (dumpsys) { /* * Checks mScreenOnFully in dumpsys output to determine if screen is showing - * Default is true + * Default is true. + * Note: this key */ export function isScreenOnFully (dumpsys) { let m = /mScreenOnFully=\w+/gi.exec(dumpsys); diff --git a/lib/tools/lockmgmt.js b/lib/tools/lockmgmt.js index dcea9a5b..af944227 100644 --- a/lib/tools/lockmgmt.js +++ b/lib/tools/lockmgmt.js @@ -2,7 +2,7 @@ import { log } from '../logger.js'; import _ from 'lodash'; import { isShowingLockscreen, isCurrentFocusOnKeyguard, isScreenOnFully, - isInDozingMode, + isInDozingMode, isScreenStateOff, } from '../helpers.js'; import B from 'bluebird'; import { waitForCondition } from 'asyncbox'; @@ -217,7 +217,8 @@ export async function isScreenLocked () { return isShowingLockscreen(windowOutput) || isCurrentFocusOnKeyguard(windowOutput) || !isScreenOnFully(windowOutput) - || isInDozingMode(powerOutput); + || isInDozingMode(powerOutput) + || isScreenStateOff(windowOutput); } /** diff --git a/test/unit/helper-specs.js b/test/unit/helper-specs.js index eb300735..b8872fea 100644 --- a/test/unit/helper-specs.js +++ b/test/unit/helper-specs.js @@ -3,6 +3,7 @@ import { buildStartCmd, isShowingLockscreen, getBuildToolsDirs, parseAaptStrings, parseAapt2Strings, extractMatchingPermissions, parseLaunchableActivityNames, matchComponentName, + isScreenStateOff, } from '../../lib/helpers'; import { withMocks } from '@appium/test-support'; import { fs } from '@appium/support'; @@ -58,6 +59,64 @@ describe('helpers', withMocks({fs}, function (mocks) { }); }); + describe('isScreenStateOff', function () { + it('should return true if isScreenStateOff is off', async function () { + let dumpsys = ` + KeyguardServiceDelegate + showing=false + showingAndNotOccluded=true + inputRestricted=false + occluded=false + secure=false + dreaming=false + systemIsReady=true + deviceHasKeyguard=true + enabled=true + offReason=OFF_BECAUSE_OF_USER + currentUser=-10000 + bootCompleted=true + screenState=SCREEN_STATE_OFF + interactiveState=INTERACTIVE_STATE_SLEEP + KeyguardStateMonitor + mIsShowing=false + mSimSecure=false + mInputRestricted=false + mTrusted=false + mCurrentUserId=0 + ... + `; + isScreenStateOff(dumpsys).should.be.true; + }); + it('should return true if isScreenStateOff is on', async function () { + let dumpsys = ` + KeyguardServiceDelegate + showing=false + showingAndNotOccluded=true + inputRestricted=false + occluded=false + secure=false + dreaming=false + systemIsReady=true + deviceHasKeyguard=true + enabled=true + offReason=OFF_BECAUSE_OF_USER + currentUser=-10000 + bootCompleted=true + screenState=SCREEN_STATE_ON + interactiveState=INTERACTIVE_STATE_AWAKE + KeyguardStateMonitor + mIsShowing=false + mSimSecure=false + mInputRestricted=false + mTrusted=false + mCurrentUserId=0 + ... + `; + isScreenStateOff(dumpsys).should.be.false; + }); + }); + + describe('isShowingLockscreen', function () { it('should return true if mShowingLockscreen is true', async function () { let dumpsys = 'mShowingLockscreen=true mShowingDream=false mDreamingLockscreen=false mTopIsFullscreen=false';