Pull bugfix from https://github.com/Sitronik/cordova-plugin-powermanagement2
This commit is contained in:
commit
9bfaf229e2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.idea
|
@ -20,6 +20,11 @@ Install the plugin using the cordova command line utility:
|
||||
|
||||
`$ cordova plugin add https://github.com/boltex/cordova-plugin-powermanagement.git`
|
||||
|
||||
OR
|
||||
---
|
||||
|
||||
`npm i cordova-plugin-powermanagement2`
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@netsyms/cordova-plugin-powermanagement",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "Plugin for managing the power state (i.e. idle switching) for cordova",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
@ -9,7 +9,7 @@
|
||||
"type": "git",
|
||||
"url": "git+https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement.git"
|
||||
},
|
||||
"author": "Viras-",
|
||||
"contributors": ["Netsyms Technologies", "Viras-", "Sitronik"],
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://source.netsyms.com/Netsyms/cordova-plugin-powermanagement/issues"
|
||||
@ -18,9 +18,7 @@
|
||||
"keywords": [
|
||||
"ecosystem:cordova",
|
||||
"cordova-android",
|
||||
"cordova-ios",
|
||||
"cordova-wp7",
|
||||
"cordova-wp8"
|
||||
"cordova-ios"
|
||||
],
|
||||
"main": "index.js"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
|
||||
id="@netsyms/cordova-plugin-powermanagement"
|
||||
version="1.1.2">
|
||||
version="1.1.3">
|
||||
<name>PowerManagement</name>
|
||||
<description>PowerManagement plugin for Cordova</description>
|
||||
<license>Apache 2.0</license>
|
||||
|
@ -55,33 +55,33 @@ public class PowerManagement extends CordovaPlugin {
|
||||
private CordovaWebView webView;
|
||||
|
||||
private final Runnable heartbeat = new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
//Log.d("PowerManagementPlugin", "About to declare ourselves VISIBLE");
|
||||
webView.getEngine().getView().dispatchWindowVisibilityChanged(View.VISIBLE);
|
||||
public void run() {
|
||||
try {
|
||||
//Log.d("PowerManagementPlugin", "About to declare ourselves 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 (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) {
|
||||
//Log.d("PowerManagementPlugin", "Poking location service");
|
||||
try {
|
||||
wakeupIntent.send();
|
||||
} catch (SecurityException e) {
|
||||
Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed");
|
||||
} catch (PendingIntent.CanceledException e) {
|
||||
Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed");
|
||||
}
|
||||
}
|
||||
if (wakeLock != null && powerManager != null && powerManager.isDeviceIdleMode()) {
|
||||
//Log.d("PowerManagementPlugin", "Poking location service");
|
||||
try {
|
||||
wakeupIntent.send();
|
||||
} catch (SecurityException e) {
|
||||
Log.d("PowerManagementPlugin", "SecurityException : Heartbeat location manager keep-alive failed");
|
||||
} catch (PendingIntent.CanceledException e) {
|
||||
Log.d("PowerManagementPlugin", "PendingIntent.CanceledException : Heartbeat location manager keep-alive failed");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (handler != null) {
|
||||
handler.postDelayed(this, 10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (handler != null) {
|
||||
handler.postDelayed(this, 10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -99,14 +99,21 @@ public class PowerManagement extends CordovaPlugin {
|
||||
this.powerManager = (PowerManager) cordova.getActivity().getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
handler = new Handler();
|
||||
wakeupIntent = PendingIntent.getBroadcast( context , 0,
|
||||
new Intent("com.android.internal.location.ALARM_WAKEUP"), 0);
|
||||
wakeupIntent = PendingIntent.getBroadcast( context , 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
|
||||
public boolean execute(String action, JSONArray args,
|
||||
CallbackContext callbackContext) throws JSONException {
|
||||
CallbackContext callbackContext) throws JSONException {
|
||||
|
||||
PluginResult result = null;
|
||||
Log.d("PowerManagementPlugin", "Plugin execute called - " + this.toString() );
|
||||
@ -115,12 +122,9 @@ public class PowerManagement extends CordovaPlugin {
|
||||
try {
|
||||
if( action.equals("acquire") ) {
|
||||
if( args.length() > 0 && args.getBoolean(0) ) {
|
||||
Log.d("PowerManagementPlugin", "Partial wake lock" );
|
||||
result = this.acquire( PowerManager.PARTIAL_WAKE_LOCK );
|
||||
handler.postDelayed(heartbeat, 10000);
|
||||
}
|
||||
else {
|
||||
result = this.acquire( PowerManager.FULL_WAKE_LOCK );
|
||||
result = partialWakeLock();
|
||||
} else {
|
||||
result = partialWakeLock();
|
||||
}
|
||||
} else if( action.equals("release") ) {
|
||||
result = this.release();
|
||||
|
@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013 Wolfgang Koller
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -25,48 +25,29 @@
|
||||
@implementation PowerManagement
|
||||
- (void) acquire:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
CDVPluginResult* result = nil;
|
||||
NSString* jsString = nil;
|
||||
NSString* callbackId = command.callbackId;
|
||||
|
||||
// Acquire a reference to the local UIApplication singleton
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
|
||||
|
||||
CDVPluginResult *pluginResult = nil;
|
||||
if( ![app isIdleTimerDisabled] ) {
|
||||
[app setIdleTimerDisabled:true];
|
||||
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
jsString = [result toSuccessCallbackString:callbackId];
|
||||
}
|
||||
else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer already disabled"];
|
||||
jsString = [result toErrorCallbackString:callbackId];
|
||||
}
|
||||
|
||||
[self writeJavascript:jsString];
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
|
||||
- (void) release:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
CDVPluginResult* result = nil;
|
||||
NSString* jsString = nil;
|
||||
NSString* callbackId = command.callbackId;
|
||||
|
||||
{
|
||||
// Acquire a reference to the local UIApplication singleton
|
||||
UIApplication* app = [UIApplication sharedApplication];
|
||||
|
||||
|
||||
|
||||
CDVPluginResult *pluginResult = nil;
|
||||
if( [app isIdleTimerDisabled] ) {
|
||||
[app setIdleTimerDisabled:false];
|
||||
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
jsString = [result toSuccessCallbackString:callbackId];
|
||||
}
|
||||
else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ILLEGAL_ACCESS_EXCEPTION messageAsString:@"IdleTimer not disabled"];
|
||||
jsString = [result toErrorCallbackString:callbackId];
|
||||
}
|
||||
|
||||
[self writeJavascript:jsString];
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user