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 1 commit
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
Next Next commit
feat: consider NotificationShade and StatusBar as lock screen for new…
…er android versions
  • Loading branch information
KazuCocoa committed Mar 17, 2021
commit fff28d82b7aaaf3bb63894a574758f44b6976956
6 changes: 5 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@ 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+) show `mCurrentFocus` as `NotificationShade` or `StatusBar`
* as the lock screen while they do not have mShowingLockscreen nor mDreamingLockscreen.
* Although, these `NotificationShade` and `StatusBar` could be also regular notification view.
*
* @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 /(mShowingLockscreen=true|mDreamingLockscreen=true|mCurrentFocus=.+NotificationShade|mCurrentFocus=.+StatusBar)/gi.test(dumpsys);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be more restrictive about .+NotificationShade and .+StatusBar regexps to avoid false positives?

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example .+\sNotificationShade\b

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, could be to tune the regex. Let me try.

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also would it be possible to split this long line? Maybe we could simply move the regexp itself into constants, which should also speed up the API call

}

/*
Expand Down
16 changes: 16 additions & 0 deletions test/unit/helper-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ 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 NotificationShade is active', async function () {
let dumpsys = 'mCurrentFocus=Window{4bdb8b5 u0 NotificationShade}';
(await isShowingLockscreen(dumpsys)).should.be.true;
});
it('should assume that screen is locked if StatusBar is active', async function () {
let dumpsys = 'mCurrentFocus=Window{4bdb8b5 u0 StatusBar}';
(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 +76,14 @@ 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 mCurrentFocus is another activity', async function () {
let dumpsys = 'mCurrentFocus=Window{8b4bb70 u0 com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity}';
(await isShowingLockscreen(dumpsys)).should.be.false;
});
it('should assume that screen is unlocked if mCurrentFocus is another activity', async function () {
let dumpsys = 'mCurrentFocus=Window{8b4bb70 u0 com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity}';
(await isShowingLockscreen(dumpsys)).should.be.false;
});
});

describe('buildStartCmd', function () {
Expand Down