cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

On Android the app stays above the lock screen

Open ErkoKnoll opened this issue 8 years ago • 15 comments

When using this plugin and when the app is active and when powering off the screen (locking the phone) then the the app stays above the lock screen. For security reasons this is unwanted behavior.

Currently the only workaround is to listen for Cordova's pause event which is triggered when the power button is pressed and inside that event moveToBackground() has to be called. However such behavior isn't user friendly and not so reliable either. For example I have noticed that pause events are sometimes triggered on the app startup.

ErkoKnoll avatar Oct 24 '17 08:10 ErkoKnoll

I can confirm this. Another unwanted behavior us that if you have excluded the app from the recents list and you use it, after 15 seconds (or whatever your screen lock timer is), the phone will lock behind the app, as if the screen is off. Hitting the home button then will ask you to unlock.

dimitriscsd avatar Oct 24 '17 08:10 dimitriscsd

I'm having this issue as well but it's not this plugin. I believe it has something to do with the android platform itself. I upgraded from 6.2.3 to 6.4.0 and started to see this happen. Has anyone figured anything out yet?

BuddyLReno avatar Jan 12 '18 16:01 BuddyLReno

I belive it has to do with these flags being added to the window: BackgroundExt.java Line 294

See also this stackoverflow post.

This is a very dangerous default behaviour which should be fixed imho, because a security sensitive application may use this plugin without the developer knowing about this behaviour!

I am not an android developer myself or otherwise i would fix it

derrohrbach avatar Mar 08 '18 09:03 derrohrbach

Yup removing the flags fixes this bug. The problem is that most likely another feature (which i am not using) is going to break because of the change so i am not creating a merge request for now.

My fork: https://github.com/derrohrbach/cordova-plugin-background-mode

derrohrbach avatar Mar 19 '18 12:03 derrohrbach

I guess these flags are necessary for supporting wakeUp() and unlock().

I would propose, to require developers who want to use these functions/features, that they need to configure this before invoking the functions, e.g.

cordova.plugins.backgroundMode.enableWakeUp(true);

cordova.plugins.backgroundMode.enableUnlock(true);

and then set/update the window-flags accordingly.

So if not explicitly enabled, these flags should not be applied to the window.

russaa avatar Mar 21 '18 14:03 russaa

Any new about this?

lkonzen-garupa avatar Jun 11 '18 12:06 lkonzen-garupa

You can use my fork if you do not need the unlock/above lockscreen/turn screen on functionality

derrohrbach avatar Jun 11 '18 13:06 derrohrbach

Unfortunately that's my case. I am trying another solution and, if a found something I'll post it here. If anyone have other suggestion it'll be appreciated.

lkonzen-garupa avatar Jun 17 '18 18:06 lkonzen-garupa

if you only need the wake-up feature (i.e. not unlock), you could try my branch: https://github.com/mmig/cordova-plugin-background-mode/tree/issue325_configure-wakeup-unlock

you'd need to enable the the feature you want to use first,e.g.

cordova.plugins.backgroundMode.enableWakeUp();
   //...
cordova.plugins.backgroundMode.wakeUp();

This only sets the flag FLAG_TURN_SCREEN_ON, and not the others that are required for the unlock feature.

The drawback is that right now, the feature cannot be disabled once enabled

(if you want to use unlock: this feature requires all the window-flags set, so once it is enabled, it will behave same as the original plugin)

russaa avatar Jun 17 '18 19:06 russaa

@lkonzen-garupa did you find any solution?

Manja14 avatar Jun 30 '18 11:06 Manja14

@Manja14 if you want to use the unlock() feature, then you have to life with this:
putting the app "above the lock-screen" is how this plugin accomplishes the unlock (without the user needing to enter her/his password etc).

If you do not need the unlock() feature, you can use @derrohrbach's or my solution/branch

russaa avatar Jun 30 '18 19:06 russaa

I hope its fixed now by using the master branch.

katzer avatar Feb 03 '19 15:02 katzer

I hope its fixed now by using the master branch.

It seem not resolved in version 0.7.2, for my application this is a very unwanted and annoying behaviour, it should be conditionally enabled and disabled in some way.

Maybe the official cordova plugin didnt yet received the fix? how to install a fixed version in cordova?

LucaColombi avatar Mar 22 '19 17:03 LucaColombi

@LucaColombi cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git

lkonzen-garupa avatar Mar 22 '19 17:03 lkonzen-garupa

Hello guys, That's weird ... but i want that to happen. I want my app staying above the lockscreen ... how can i perform it? Actually i'm just calling cordova.plugins.backgroundMode.enable(); What i need to call next in order to make the app staying above the lockscreen? Thanks in advance

matrixreal avatar Dec 17 '20 09:12 matrixreal