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

I modified your plugin to enable android's PARTIAL_WAKELOCK #8

Open
boltex opened this issue Jun 8, 2015 · 13 comments
Open

I modified your plugin to enable android's PARTIAL_WAKELOCK #8

boltex opened this issue Jun 8, 2015 · 13 comments

Comments

@boltex
Copy link

boltex commented Jun 8, 2015

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?

@zeeshanjan82
Copy link

@boltex what is the benefit for using PARTIAL_WAKE_LOCK and when can I get your modifications.

@boltex
Copy link
Author

boltex commented Jul 13, 2015

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 :katzer/cordova-plugin-background-mode#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');
});

}

@zeeshanjan82
Copy link

Thanks @boltex I will surely try your solution today and revert back with my results.

@zeeshanjan82
Copy link

@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.

@Viras-
Copy link
Owner

Viras- commented Jul 14, 2015

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?

@boltex
Copy link
Author

boltex commented Jul 14, 2015

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!

@boltex
Copy link
Author

boltex commented Jul 14, 2015

@zeeshanjan82 I am not sure because I have never tried to "wake up" the screen myself.

@brcros
Copy link

brcros commented Aug 19, 2015

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

@Viras-
Copy link
Owner

Viras- commented Aug 20, 2015

I will modify the plugin accordingly and will let you know once I have a new version ready.

@boltex
Copy link
Author

boltex commented Aug 21, 2015

Thank you @Viras- !!!!

@pm-deepak-dhage
Copy link

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.

@boltex
Copy link
Author

boltex commented Oct 19, 2015

@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');
  });

@08Thug
Copy link

08Thug commented Dec 23, 2019

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.!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants