cordova-plugin-powermanagement
cordova-plugin-powermanagement copied to clipboard
I modified your plugin to enable android's PARTIAL_WAKELOCK
PARTIAL_WAKE_LOCK Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off : If the user presses the power button, then the screen will be turned off but the CPU will be kept on until all partial wake locks have been released.
I was wondering if there was a reason you did not provide for this mode in the first place.... I tought this was a very useful in some instances... Is there an issue I might not be aware of? Something that made you not to include this choice with your powermanagement plugin?
@boltex what is the benefit for using PARTIAL_WAKE_LOCK and when can I get your modifications.
Well the benefits are that it lets the screen turn off so the behavior is that of a normal application: but the app still runs in the background when used in cunjunction with the background mode plugin.
See :https://github.com/katzer/cordova-plugin-background-mode/issues/93
Made my own solution, https://github.com/boltex/cordova-plugin-powermanagement
I modified the power management plugin : I changed SCREEN_DIM_WAKE_LOCK to PARTIAL_WAKE_LOCK
here's how i use it along with the background mode plugin so the app is never in background and always running as a service...(altough it does let the screen turn off and/or switch to other apps but your app will keep running and never miss a timer trigger):
if( ionic.Platform.isAndroid() ){ cordova.plugins.backgroundMode.enable();
window.powerManagement.dim(function() { console.log('Wakelock acquired'); }, function() { console.log('Failed to acquire wakelock'); }); window.powerManagement.setReleaseOnPause(false, function() { console.log('setReleaseOnPause successfully'); }, function() { console.log('Failed to set'); });
}
Thanks @boltex I will surely try your solution today and revert back with my results.
@boltex I have a question, if I use your plugin along with the cordova-plugin-background will it enable me to wake up the phone and show my application screen when there is an event in my application. Similar to what happens when we receive a skype call and our phone is locked or in sleep mode, we are able to respond to the call even when our phone is locked.
Hi, no I had no reason to not include this in the plugin.
Can you create a pull request so that I can review your code and add it to the official code?
Hi @Viras- , I really appreciate your work and his plugin in particular! :)
I did only change SCREEN_DIM_WAKE_LOCK to PARTIAL_WAKE_LOCK in your code for the window.powerManagement.dim function in your /src/android/PowerManagement.java source.
Because i am not fluent in java, nor in cordova plugin developpement, i did not try to offer it as a third choice. I only replaced the "dim wakelock" with "partial wakelock".
It would be better if you added a third choice for the android platform such as a "window.powerManagement.partial" function.
Thanks again!
@zeeshanjan82 I am not sure because I have never tried to "wake up" the screen myself.
I also use background mode and need a wake lock else background process gets to disappear. So, as for my app, battery consumption is (life) critical, best way is to let the screen go off asap as usual app, and this, can be obtained only using a PARTIAL_WAKE_LOCK ( i cheked).
So i went for the Boltex implementation ( it works, thank you !) , but it could be great to have only 1 power management plugin implementing all the useful device abilities. As the current function accept other parameters with the JSON array, it should be easy to add a js function (partial) to call java with another parameter in order to adresse all modes without breaking the existing usages.
https://github.com/boltex/cordova-plugin-powermanagement
Thank you all.
Bruno
I will modify the plugin accordingly and will let you know once I have a new version ready.
Thank you @Viras- !!!!
Appreciate the good work, Viras and boltex! I have a doubt here. why does below code don't keep my activity actively running on screen is off?
if(!cordova.plugins.backgroundMode.isActive()){
cordova.plugins.backgroundMode.enable();
}
window.powerManagement.acquire(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
}, function() {
console.log('Failed to set');
});
@boltex, is this what you were facing and so you changed SCREEN_DIM_WAKE_LOCK to PARTIAL_WAKE_LOCK? I am not trying yoour version of powermanagement plugin to see if it works for me.
@pm-deepak-dhage it will work if you use my version at https://github.com/boltex/cordova-plugin-powermanagement... and i modified the function dim. not aquire.
cordova.plugins.backgroundMode.enable();
window.powerManagement.dim(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
console.log('setReleaseOnPause successfully');
}, function() {
console.log('Failed to set');
});
ionViewWillEnter(){
powerManagement.acquire(function() {
console.log('Wakelock acquired');
}, function() {
console.log('Failed to acquire wakelock');
});
}
ionViewWillLeave()
{
powerManagement.release(function() {
console.log('Wakelock release acquired');
}, function(err) {
console.log('Failed release to acquire wakelock'+err);
});
powerManagement.dim(function() {
console.log('Wakelock dim acquired');
}, function(err) {
console.log('Failed dim to acquire wakelock'+err);
});
}
@boltex after acquiring wakelock the screen stays Active after implementing release function the screen is still in active state.it stays active until we terminate the app.Does the release function revokes the powermanagement.acquire()-if it does then it should come back to normal state then the screen should go inactive(OFF) as we mentioned in device settings for screen saver.!