master^2
Denis 3 years ago
parent dd5b6d7dcc
commit 71695ca851

1
.gitignore vendored

@ -0,0 +1 @@
.idea

@ -1,5 +1,5 @@
{ {
"name": "cordova-plugin-powermanagement-orig", "name": "cordova-plugin-powermanagement2",
"version": "1.1.0", "version": "1.1.0",
"description": "Plugin for managing the power state (i.e. idle switching) for cordova", "description": "Plugin for managing the power state (i.e. idle switching) for cordova",
"scripts": { "scripts": {
@ -7,14 +7,14 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/boltex/cordova-plugin-powermanagement.git" "url": "git+https://github.com/sitronik/cordova-plugin-powermanagement2.git"
}, },
"author": "Viras-", "author": "Sitronik",
"license": "Apache-2.0", "license": "Apache-2.0",
"bugs": { "bugs": {
"url": "https://github.com/boltex/cordova-plugin-powermanagement/issues" "url": "https://github.com/sitronik/cordova-plugin-powermanagement2/issues"
}, },
"homepage": "https://github.com/boltex/cordova-plugin-powermanagement#readme", "homepage": "https://github.com/sitronik/cordova-plugin-powermanagement2#readme",
"keywords": [ "keywords": [
"ecosystem:cordova", "ecosystem:cordova",
"cordova-android", "cordova-android",

@ -55,33 +55,33 @@ public class PowerManagement extends CordovaPlugin {
private CordovaWebView webView; private CordovaWebView webView;
private final Runnable heartbeat = new Runnable() { private final Runnable heartbeat = new Runnable() {
public void run() { public void run() {
try { try {
//Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE"); //Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE");
webView.getEngine().getView().dispatchWindowVisibilityChanged(View.VISIBLE); webView.getView().dispatchWindowVisibilityChanged(View.VISIBLE);
// if sdk is 23 (android 6) or greater // if sdk is 23 (android 6) or greater
if(android.os.Build.VERSION.SDK_INT > 22){ if(android.os.Build.VERSION.SDK_INT > 22){
if (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) { if (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) {
//Log.d("PowerManagementPlugin", "Poking location service"); //Log.d("PowerManagementPlugin", "Poking location service");
try { try {
wakeupIntent.send(); wakeupIntent.send();
} catch (SecurityException e) { } catch (SecurityException e) {
Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed"); Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed");
} catch (PendingIntent.CanceledException e) { } catch (PendingIntent.CanceledException e) {
Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed"); Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed");
} }
} }
} }
} finally { } finally {
if (handler != null) { if (handler != null) {
handler.postDelayed(this, 10000); handler.postDelayed(this, 10000);
} }
} }
} }
}; };
/** /**
@ -99,14 +99,21 @@ public class PowerManagement extends CordovaPlugin {
this.powerManager = (PowerManager) cordova.getActivity().getSystemService(Context.POWER_SERVICE); this.powerManager = (PowerManager) cordova.getActivity().getSystemService(Context.POWER_SERVICE);
handler = new Handler(); handler = new Handler();
wakeupIntent = PendingIntent.getBroadcast( context , 0, wakeupIntent = PendingIntent.getBroadcast( context , 0,
new Intent("com.android.internal.location.ALARM_WAKEUP"), 0); new Intent("com.android.internal.location.ALARM_WAKEUP"), 0);
} }
public PluginResult partialWakeLock() {
Log.d("PowerManagementPlugin", "Partial wake lock" );
PluginResult result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK );
handler.postDelayed(heartbeat, 10000);
return result;
}
@Override @Override
public boolean execute(String action, JSONArray args, public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException { CallbackContext callbackContext) throws JSONException {
PluginResult result = null; PluginResult result = null;
Log.d("PowerManagementPlugin", "Plugin execute called - " + this.toString() ); Log.d("PowerManagementPlugin", "Plugin execute called - " + this.toString() );
@ -115,12 +122,9 @@ public class PowerManagement extends CordovaPlugin {
try { try {
if( action.equals("acquire") ) { if( action.equals("acquire") ) {
if( args.length() > 0 && args.getBoolean(0) ) { if( args.length() > 0 && args.getBoolean(0) ) {
Log.d("PowerManagementPlugin", "Partial wake lock" ); result = partialWakeLock();
result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK ); } else {
handler.postDelayed(heartbeat, 10000); result = partialWakeLock();
}
else {
result = this.acquire( PowerManager.FULL_WAKE_LOCK );
} }
} else if( action.equals("release") ) { } else if( action.equals("release") ) {
result = this.release(); result = this.release();

Loading…
Cancel
Save