forked from jens/Automation
wakelock action
This commit is contained in:
parent
f3fac2f4e8
commit
99faa2f7ef
@ -169,6 +169,7 @@
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -167,6 +167,7 @@
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -154,6 +154,7 @@
|
||||
<activity android:name=".ActivityManageActionRunExecutable" />
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -53,6 +53,7 @@ public class Action
|
||||
closeNotification,
|
||||
sendBroadcast,
|
||||
runExecutable,
|
||||
wakelock,
|
||||
sendTextMessage;
|
||||
|
||||
public String getFullName(Context context)
|
||||
@ -127,6 +128,8 @@ public class Action
|
||||
return context.getResources().getString(R.string.sendBroadcast);
|
||||
case runExecutable:
|
||||
return context.getResources().getString(R.string.runExecutable);
|
||||
case wakelock:
|
||||
return context.getResources().getString(R.string.keepDeviceAwake);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
@ -273,6 +276,9 @@ public class Action
|
||||
case runExecutable:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.runExecutable));
|
||||
break;
|
||||
case wakelock:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.keepDeviceAwake) + " (" + String.valueOf(getParameter1()) + ")");
|
||||
break;
|
||||
default:
|
||||
returnString.append(action.toString());
|
||||
}
|
||||
|
@ -1142,25 +1142,7 @@ public class Actions
|
||||
{
|
||||
Miscellaneous.logEvent("i", "waitBeforeNextAction", "waitBeforeNextAction for " + String.valueOf(waitTime) + " milliseconds.", 4);
|
||||
|
||||
try
|
||||
{
|
||||
PowerManager powerManager = (PowerManager) Miscellaneous.getAnyContext().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");
|
||||
fullWakeLock.acquire(); // turn on
|
||||
try
|
||||
{
|
||||
Thread.sleep(60000); // turn on duration
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
fullWakeLock.release();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
wakeLockStart(60000);
|
||||
try
|
||||
{
|
||||
Thread.sleep(waitTime);
|
||||
@ -2112,4 +2094,56 @@ public class Actions
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final static int wakeLockTimeoutDisabled = -1;
|
||||
static boolean wakeLockStopRequested = false;
|
||||
public static void wakeLockStart(long duration)
|
||||
{
|
||||
long waited = 0;
|
||||
int step = 1000;
|
||||
|
||||
if(duration < 0)
|
||||
step = 99999;
|
||||
|
||||
try
|
||||
{
|
||||
PowerManager powerManager = (PowerManager) Miscellaneous.getAnyContext().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");
|
||||
fullWakeLock.acquire(); // turn on
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(step); // turn on duration
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
waited += step;
|
||||
|
||||
if(false) //stop requested
|
||||
{
|
||||
Miscellaneous.logEvent("i", "WakeLockStart", "Stop requested.", 4);
|
||||
wakeLockStopRequested = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(waited <= duration);
|
||||
|
||||
fullWakeLock.release();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void wakeLockStop()
|
||||
{
|
||||
Miscellaneous.logEvent("i", "WakeLockStart", "Requesting stop.", 4);
|
||||
wakeLockStopRequested = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionWakeLock extends Activity
|
||||
{
|
||||
RadioButton rbWakeLockActivate, rbWakeLockDeactivate;
|
||||
CheckBox chkWakeLockTimeout;
|
||||
EditText etWakeLockDuration;
|
||||
Button bSaveWakelock;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_action_wakelock);
|
||||
|
||||
rbWakeLockActivate = (RadioButton)findViewById(R.id.rbWakeLockActivate);
|
||||
rbWakeLockDeactivate = (RadioButton)findViewById(R.id.rbWakeLockDeactivate);
|
||||
chkWakeLockTimeout = (CheckBox)findViewById(R.id.chkWakeLockTimeout);
|
||||
etWakeLockDuration = (EditText)findViewById(R.id.etWakeLockDuration);
|
||||
bSaveWakelock = (Button)findViewById(R.id.bSaveWakelock);
|
||||
|
||||
etWakeLockDuration.setEnabled(chkWakeLockTimeout.isChecked());
|
||||
|
||||
chkWakeLockTimeout.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean wakeLockTimeoutSet)
|
||||
{
|
||||
etWakeLockDuration.setEnabled(wakeLockTimeoutSet);
|
||||
|
||||
if(wakeLockTimeoutSet)
|
||||
etWakeLockDuration.setText(String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter1))
|
||||
{
|
||||
rbWakeLockActivate.setChecked(getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, true));
|
||||
rbWakeLockDeactivate.setChecked(!getIntent().getBooleanExtra(ActivityManageRule.intentNameActionParameter1, false));
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
if(Miscellaneous.isNumeric(getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2)))
|
||||
{
|
||||
long timeout = Long.parseLong((getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2)));
|
||||
chkWakeLockTimeout.setChecked(timeout != Actions.wakeLockTimeoutDisabled);
|
||||
etWakeLockDuration.setText(String.valueOf(timeout));
|
||||
}
|
||||
else
|
||||
{
|
||||
chkWakeLockTimeout.setChecked(false);
|
||||
etWakeLockDuration.setText(String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bSaveWakelock.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(chkWakeLockTimeout.isChecked())
|
||||
{
|
||||
if((StringUtils.isEmpty(etWakeLockDuration.getText().toString()) || Integer.parseInt(etWakeLockDuration.getText().toString()) <= 0))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionWakeLock.this, getResources().getString(R.string.enterAPositiveValidNonDecimalNumber), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Intent response = new Intent();
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter1, rbWakeLockActivate.isChecked());
|
||||
if(chkWakeLockTimeout.isChecked())
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, etWakeLockDuration.getText().toString());
|
||||
else
|
||||
response.putExtra(ActivityManageRule.intentNameActionParameter2, String.valueOf(Actions.wakeLockTimeoutDisabled));
|
||||
setResult(RESULT_OK, response);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -129,6 +129,8 @@ public class ActivityManageRule extends Activity
|
||||
final static int requestCodeActionSetWifiEdit = 816;
|
||||
final static int requestCodeTriggerTetheringAdd = 817;
|
||||
final static int requestCodeTriggerTetheringEdit = 818;
|
||||
final static int requestCodeActionWakeLockAdd = 819;
|
||||
final static int requestCodeActionWakeLockEdit = 820;
|
||||
|
||||
public static ActivityManageRule getInstance()
|
||||
{
|
||||
@ -393,6 +395,12 @@ public class ActivityManageRule extends Activity
|
||||
activityEditSendBroadcastIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditSendBroadcastIntent, requestCodeActionSendBroadcastEdit);
|
||||
break;
|
||||
case wakelock:
|
||||
Intent activityEditWakeLockIntent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
||||
activityEditWakeLockIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
activityEditWakeLockIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditWakeLockIntent, requestCodeActionWakeLockEdit);
|
||||
break;
|
||||
case runExecutable:
|
||||
Intent activityEditRunExecutableIntent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
||||
activityEditRunExecutableIntent.putExtra(intentNameActionParameter1, a.getParameter1());
|
||||
@ -1551,6 +1559,17 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionWakeLockAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionControlMediaAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1620,6 +1639,21 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionWakeLockEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter1))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, true));
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionRunExecutableEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1884,6 +1918,8 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||
else if(types[i].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.megaphone));
|
||||
else if(types[i].toString().equals(Action_Enum.wakelock.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.coffee));
|
||||
else if(types[i].toString().equals(Action_Enum.runExecutable.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.script));
|
||||
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||
@ -2058,6 +2094,12 @@ public class ActivityManageRule extends Activity
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionRunExecutable.class);
|
||||
startActivityForResult(intent, requestCodeActionRunExecutableAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.wakelock.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.wakelock);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionWakeLock.class);
|
||||
startActivityForResult(intent, requestCodeActionWakeLockAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.controlMediaPlayback.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.controlMediaPlayback);
|
||||
|
BIN
app/src/main/res/drawable-hdpi/coffee.png
Normal file
BIN
app/src/main/res/drawable-hdpi/coffee.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 679 B After Width: | Height: | Size: 679 B |
89
app/src/main/res/layout/activity_manage_action_wakelock.xml
Normal file
89
app/src/main/res/layout/activity_manage_action_wakelock.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="@dimen/default_margin">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_span="2"
|
||||
android:textSize="25dp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="@dimen/default_margin"
|
||||
android:text="@string/keepDeviceAwake" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:shrinkColumns="1"
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/direction" />
|
||||
|
||||
<RadioGroup>
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbWakeLockActivate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/activate" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbWakeLockDeactivate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/deactivate" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:text="@string/wakeLockTimeout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/chkWakeLockTimeout"
|
||||
android:text=""
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/duration" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etWakeLockDuration"
|
||||
android:inputType="number"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSaveWakelock"
|
||||
android:layout_marginTop="@dimen/default_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save" />
|
||||
|
||||
</LinearLayout>
|
@ -836,4 +836,7 @@
|
||||
<string name="tetheringState">Tethering state</string>
|
||||
<string name="regularExpressionsIfEquals">If \"equals\" is selected, you may enter a regular expression.</string>
|
||||
<string name="enter_a_number">Enter a number.</string>
|
||||
<string name="duration">Duration [ms]</string>
|
||||
<string name="keepDeviceAwake">Keep device awake</string>
|
||||
<string name="wakeLockTimeout">Specify timeout</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user