@ -41,6 +41,7 @@ public class PowerManagement extends CordovaPlugin {
// As we only allow one wake-lock, we keep a reference to it here
private PowerManager . WakeLock wakeLock = null ;
private PowerManager powerManager = null ;
private boolean releaseOnPause = true ;
/ * *
* Fetch a reference to the power - service when the plugin is initialized
@ -69,9 +70,15 @@ public class PowerManagement extends CordovaPlugin {
else {
result = this . acquire ( PowerManager . FULL_WAKE_LOCK ) ;
}
}
else if ( action . equals ( "release" ) ) {
} else if ( action . equals ( "release" ) ) {
result = this . release ( ) ;
} else if ( action . equals ( "setReleaseOnPause" ) ) {
try {
this . releaseOnPause = args . getBoolean ( 0 ) ;
result = new PluginResult ( PluginResult . Status . OK ) ;
} catch ( Exception e ) {
result = new PluginResult ( PluginResult . Status . ERROR , "Could not set releaseOnPause" ) ;
}
}
}
catch ( JSONException e ) {
@ -116,11 +123,16 @@ public class PowerManagement extends CordovaPlugin {
PluginResult result = null ;
if ( this . wakeLock ! = null ) {
try {
this . wakeLock . release ( ) ;
this . wakeLock = null ;
result = new PluginResult ( PluginResult . Status . OK , "OK" ) ;
}
catch ( Exception e ) {
result = new PluginResult ( PluginResult . Status . ILLEGAL_ACCESS_EXCEPTION , "WakeLock already released" ) ;
}
this . wakeLock = null ;
}
else {
result = new PluginResult ( PluginResult . Status . ILLEGAL_ACCESS_EXCEPTION , "No WakeLock active - acquire first" ) ;
}
@ -133,7 +145,9 @@ public class PowerManagement extends CordovaPlugin {
* /
@Override
public void onPause ( boolean multitasking ) {
if ( this . wakeLock ! = null ) this . wakeLock . release ( ) ;
if ( this . releaseOnPause & & this . wakeLock ! = null ) {
this . wakeLock . release ( ) ;
}
super . onPause ( multitasking ) ;
}
@ -143,7 +157,9 @@ public class PowerManagement extends CordovaPlugin {
* /
@Override
public void onResume ( boolean multitasking ) {
if ( this . wakeLock ! = null ) this . wakeLock . acquire ( ) ;
if ( this . releaseOnPause & & this . wakeLock ! = null ) {
this . wakeLock . acquire ( ) ;
}
super . onResume ( multitasking ) ;
}