diff --git a/lib/helpers.js b/lib/helpers.js index aa758ce9..31ef2117 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -210,11 +210,18 @@ async function getApkanalyzerForOs (sysHelpers) { * in comparison to `adb dumpsys window` output parsing. * But the trust command does not work for `Swipe` unlock pattern. * + * In some Android devices (Probably around Android 10+), `mShowingLockscreen` and `mDreamingLockscreen` + * do not work to detect lock status. Instead, keyguard preferences helps to detect the lock condition. + * Some devices such as Android TV do not have keyguard, so we should keep + * screen condition as this primary method. + * * @param {string} dumpsys - The output of dumpsys window command. * @return {boolean} True if lock screen is showing. */ function isShowingLockscreen (dumpsys) { - return /(mShowingLockscreen=true|mDreamingLockscreen=true)/gi.test(dumpsys); + return _.some(['mShowingLockscreen=true', 'mDreamingLockscreen=true'], (x) => dumpsys.includes(x)) + // `mIsShowing` and `mInputRestricted` are `true` in lock condition. `false` is unlock condition. + || _.every(['mIsShowing=false', 'mInputRestricted=false'], (x) => dumpsys.includes(x)); } /* diff --git a/test/unit/helper-specs.js b/test/unit/helper-specs.js index b8826dda..f01a853e 100644 --- a/test/unit/helper-specs.js +++ b/test/unit/helper-specs.js @@ -60,6 +60,19 @@ describe('helpers', withMocks({fs}, function (mocks) { let dumpsys = 'mShowingLockscreen=false mShowingDream=false mDreamingLockscreen=true mTopIsFullscreen=false'; (await isShowingLockscreen(dumpsys)).should.be.true; }); + it('should assume that screen is locked if keyguard is unlocked', async function () { + let dumpsys = ` + KeyguardServiceDelegate + .... + KeyguardStateMonitor + mIsShowing=false + mSimSecure=false + mInputRestricted=false + mCurrentUserId=0 + ... + `; + (await isShowingLockscreen(dumpsys)).should.be.true; + }); it('should return false if mShowingLockscreen and mDreamingLockscreen are false', async function () { let dumpsys = 'mShowingLockscreen=false mShowingDream=false mDreamingLockscreen=false mTopIsFullscreen=false'; (await isShowingLockscreen(dumpsys)).should.be.false; @@ -68,6 +81,32 @@ describe('helpers', withMocks({fs}, function (mocks) { let dumpsys = 'mShowingDream=false mTopIsFullscreen=false'; (await isShowingLockscreen(dumpsys)).should.be.false; }); + it('should assume that screen is unlocked if mInputRestricted and mIsShowing were true', async function () { + let dumpsys = ` + KeyguardServiceDelegate + .... + KeyguardStateMonitor + mIsShowing=true + mSimSecure=false + mInputRestricted=true + mCurrentUserId=0 + ... + `; + (await isShowingLockscreen(dumpsys)).should.be.false; + }); + it('should assume that screen is unlocked if mIsShowing was true', async function () { + let dumpsys = ` + KeyguardServiceDelegate + .... + KeyguardStateMonitor + mIsShowing=true + mSimSecure=false + mInputRestricted=false + mCurrentUserId=0 + ... + `; + (await isShowingLockscreen(dumpsys)).should.be.false; + }); }); describe('buildStartCmd', function () {