wakelock action
This commit is contained in:
parent
99faa2f7ef
commit
536a5e22f9
@ -576,6 +576,12 @@ public class Action
|
|||||||
else if(execParts.length == 2)
|
else if(execParts.length == 2)
|
||||||
Actions.runExecutable(context, this.getParameter1(), execParts[0], execParts[1]);
|
Actions.runExecutable(context, this.getParameter1(), execParts[0], execParts[1]);
|
||||||
break;
|
break;
|
||||||
|
case wakelock:
|
||||||
|
if(this.getParameter1())
|
||||||
|
Actions.wakeLockStart(context, Long.parseLong(this.getParameter2()));
|
||||||
|
else
|
||||||
|
Actions.wakeLockStop();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||||
break;
|
break;
|
||||||
|
@ -1142,7 +1142,6 @@ public class Actions
|
|||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "waitBeforeNextAction", "waitBeforeNextAction for " + String.valueOf(waitTime) + " milliseconds.", 4);
|
Miscellaneous.logEvent("i", "waitBeforeNextAction", "waitBeforeNextAction for " + String.valueOf(waitTime) + " milliseconds.", 4);
|
||||||
|
|
||||||
wakeLockStart(60000);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(waitTime);
|
Thread.sleep(waitTime);
|
||||||
@ -2097,48 +2096,53 @@ public class Actions
|
|||||||
|
|
||||||
public final static int wakeLockTimeoutDisabled = -1;
|
public final static int wakeLockTimeoutDisabled = -1;
|
||||||
static boolean wakeLockStopRequested = false;
|
static boolean wakeLockStopRequested = false;
|
||||||
public static void wakeLockStart(long duration)
|
public static void wakeLockStart(Context context, long duration)
|
||||||
{
|
{
|
||||||
long waited = 0;
|
Thread lockThread = new Thread(new Runnable()
|
||||||
int step = 1000;
|
|
||||||
|
|
||||||
if(duration < 0)
|
|
||||||
step = 99999;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
PowerManager powerManager = (PowerManager) Miscellaneous.getAnyContext().getSystemService(Context.POWER_SERVICE);
|
@Override
|
||||||
PowerManager.WakeLock fullWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Loneworker - FULL WAKE LOCK");
|
public void run()
|
||||||
fullWakeLock.acquire(); // turn on
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
|
wakeLockStopRequested = false;
|
||||||
|
|
||||||
|
long waited = 0;
|
||||||
|
int step = 2000;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(step); // turn on duration
|
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
}
|
PowerManager.WakeLock fullWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Loneworker - FULL WAKE LOCK");
|
||||||
catch (InterruptedException e)
|
fullWakeLock.acquire(); // turn on
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
waited += step;
|
do
|
||||||
|
{
|
||||||
|
|
||||||
if(false) //stop requested
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(step); // turn on duration
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(duration > 0)
|
||||||
|
waited += step;
|
||||||
|
|
||||||
|
if(wakeLockStopRequested) //stop requested
|
||||||
|
Miscellaneous.logEvent("i", "WakeLockStart", "Stop requested.", 4);
|
||||||
|
}
|
||||||
|
while(!wakeLockStopRequested && (duration < 0 || waited <= duration));
|
||||||
|
|
||||||
|
fullWakeLock.release();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Miscellaneous.logEvent("i", "WakeLockStart", "Stop requested.", 4);
|
|
||||||
wakeLockStopRequested = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(waited <= duration);
|
});
|
||||||
|
|
||||||
fullWakeLock.release();
|
lockThread.start();
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void wakeLockStop()
|
public static void wakeLockStop()
|
||||||
|
Loading…
Reference in New Issue
Block a user