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: consider NotificationShade and StatusBar as lock screen for newer android versions #564

Merged
merged 5 commits into from
Mar 18, 2021
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
9 changes: 8 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

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