Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add screenState=SCREEN_STATE_OFF as the screen locked #791

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions lib/tools/lockmgmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -217,7 +217,8 @@ export async function isScreenLocked () {
return isShowingLockscreen(windowOutput)
|| isCurrentFocusOnKeyguard(windowOutput)
|| !isScreenOnFully(windowOutput)
|| isInDozingMode(powerOutput);
|| isInDozingMode(powerOutput)
|| isScreenStateOff(windowOutput);
}

/**
Expand Down
59 changes: 59 additions & 0 deletions test/unit/helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
Loading