forked from jens/Automation
service is starting can be inverted
This commit is contained in:
parent
d17e8b70fe
commit
7fdbf74906
@ -170,6 +170,7 @@
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -168,6 +168,7 @@
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -155,6 +155,7 @@
|
||||
<activity android:name=".ActivityManageActionWifi" />
|
||||
<activity android:name=".ActivityManageTriggerTethering" />
|
||||
<activity android:name=".ActivityManageActionWakeLock" />
|
||||
<activity android:name=".ActivityManageTriggerSubSystemState" />
|
||||
<activity
|
||||
android:name=".ActivityMainTabLayout"
|
||||
android:launchMode="singleTask">
|
||||
|
@ -131,6 +131,8 @@ public class ActivityManageRule extends Activity
|
||||
final static int requestCodeTriggerTetheringEdit = 818;
|
||||
final static int requestCodeActionWakeLockAdd = 819;
|
||||
final static int requestCodeActionWakeLockEdit = 820;
|
||||
final static int requestCodeTriggerSubSystemStateAdd = 821;
|
||||
final static int requestCodeTriggerSubSystemStateEdit = 822;
|
||||
|
||||
public static ActivityManageRule getInstance()
|
||||
{
|
||||
@ -321,6 +323,12 @@ public class ActivityManageRule extends Activity
|
||||
tetheringEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
startActivityForResult(tetheringEditor, requestCodeTriggerTetheringEdit);
|
||||
break;
|
||||
case subSystemState:
|
||||
Intent subSystemStateEditor = new Intent(ActivityManageRule.this, ActivityManageTriggerSubSystemState.class);
|
||||
subSystemStateEditor.putExtra(intentNameTriggerParameter1, selectedTrigger.getTriggerParameter());
|
||||
subSystemStateEditor.putExtra(intentNameTriggerParameter2, selectedTrigger.getTriggerParameter2());
|
||||
startActivityForResult(subSystemStateEditor, requestCodeTriggerSubSystemStateEdit);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -585,6 +593,8 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.alarm));
|
||||
else if(types[i].toString().equals(Trigger_Enum.tethering.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.router));
|
||||
else if(types[i].toString().equals(Trigger_Enum.subSystemState.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.subsystemstate));
|
||||
else
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||
}
|
||||
@ -757,19 +767,22 @@ public class ActivityManageRule extends Activity
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.lockedCommentScreenMustBeOff), ActivityManageRule.this).show();
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.deviceStarts)
|
||||
/*else if(triggerType == Trigger_Enum.deviceStarts)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.deviceStarts);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
refreshTriggerList();
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.serviceStarts)
|
||||
}*/
|
||||
else if(triggerType == Trigger_Enum.deviceStarts || triggerType == Trigger_Enum.serviceStarts)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.serviceStarts);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
refreshTriggerList();
|
||||
return;
|
||||
// newTrigger.setTriggerType(Trigger_Enum.serviceStarts);
|
||||
// ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
|
||||
booleanChoices = new String[]{getResources().getString(R.string.yes), getResources().getString(R.string.no)};
|
||||
|
||||
// refreshTriggerList();
|
||||
// return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.headsetPlugged)
|
||||
booleanChoices = new String[]{getResources().getString(R.string.connected), getResources().getString(R.string.disconnected)};
|
||||
@ -793,6 +806,13 @@ public class ActivityManageRule extends Activity
|
||||
startActivityForResult(tetheringTriggerEditor, requestCodeTriggerTetheringAdd);
|
||||
return;
|
||||
}
|
||||
else if(triggerType == Trigger_Enum.subSystemState)
|
||||
{
|
||||
newTrigger.setTriggerType(Trigger_Enum.subSystemState);
|
||||
Intent subSystemStateTriggerEditor = new Intent(myContext, ActivityManageTriggerSubSystemState.class);
|
||||
startActivityForResult(subSystemStateTriggerEditor, requestCodeTriggerSubSystemStateAdd);
|
||||
return;
|
||||
}
|
||||
else
|
||||
getTriggerParameterDialog(context, booleanChoices).show();
|
||||
|
||||
@ -1853,6 +1873,17 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerSubSystemStateAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
newTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
newTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().add(newTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerTetheringEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1865,6 +1896,19 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeTriggerSubSystemStateEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
Trigger editedTrigger = new Trigger();
|
||||
editedTrigger.setTriggerType(Trigger_Enum.subSystemState);
|
||||
editedTrigger.setTriggerParameter(data.getBooleanExtra(intentNameTriggerParameter1, true));
|
||||
editedTrigger.setTriggerParameter2(data.getStringExtra(intentNameTriggerParameter2));
|
||||
editedTrigger.setParentRule(ruleToEdit);
|
||||
ruleToEdit.getTriggerSet().set(editIndex, editedTrigger);
|
||||
this.refreshTriggerList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected AlertDialog getActionTypeDialog()
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.jens.automation2.Trigger.subSystemStates;
|
||||
|
||||
public class ActivityManageTriggerSubSystemState extends Activity
|
||||
{
|
||||
RadioButton rbSubSystemStateWifi, rbSubSystemStateBluetooth;
|
||||
RadioButton rbSubSystemStateEnabled, rbSubSystemStateDisabled;
|
||||
Button bSubSystemStateSave;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_trigger_subsystemstate);
|
||||
|
||||
rbSubSystemStateWifi = (RadioButton)findViewById(R.id.rbSubSystemStateWifi);
|
||||
rbSubSystemStateBluetooth = (RadioButton)findViewById(R.id.rbSubSystemStateBluetooth);
|
||||
rbSubSystemStateEnabled = (RadioButton)findViewById(R.id.rbSubSystemStateEnabled);
|
||||
rbSubSystemStateDisabled = (RadioButton)findViewById(R.id.rbSubSystemStateDisabled);
|
||||
bSubSystemStateSave = (Button)findViewById(R.id.bSubSystemStateSave);
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter1) && getIntent().hasExtra(ActivityManageRule.intentNameTriggerParameter2))
|
||||
{
|
||||
subSystemStates desiredState = subSystemStates.valueOf(getIntent().getStringExtra(ActivityManageRule.intentNameTriggerParameter2));
|
||||
|
||||
switch(desiredState)
|
||||
{
|
||||
case wifi:
|
||||
rbSubSystemStateWifi.setChecked(true);
|
||||
break;
|
||||
case bluetooth:
|
||||
rbSubSystemStateBluetooth.setChecked(true);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
if(getIntent().getBooleanExtra(ActivityManageRule.intentNameTriggerParameter1, true))
|
||||
rbSubSystemStateEnabled.setChecked(true);
|
||||
else
|
||||
rbSubSystemStateDisabled.setChecked(true);
|
||||
}
|
||||
|
||||
bSubSystemStateSave.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
Intent data = new Intent();
|
||||
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter1, rbSubSystemStateEnabled.isChecked());
|
||||
|
||||
if(rbSubSystemStateWifi.isChecked())
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, subSystemStates.wifi.name());
|
||||
else if(rbSubSystemStateBluetooth.isChecked())
|
||||
data.putExtra(ActivityManageRule.intentNameTriggerParameter2, subSystemStates.bluetooth.name());
|
||||
|
||||
ActivityManageTriggerSubSystemState.this.setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -473,6 +473,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
PackageReplacedReceiver.setHasServiceBeenRunning(false, this);
|
||||
|
||||
centralInstance = null;
|
||||
Settings.serviceStartDone = false;
|
||||
}
|
||||
|
||||
protected static Builder createDefaultNotificationBuilderOld()
|
||||
|
@ -18,6 +18,7 @@ import com.jens.automation2.receivers.NoiseListener;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
import com.jens.automation2.receivers.ProcessListener;
|
||||
import com.jens.automation2.receivers.ScreenStateReceiver;
|
||||
import com.jens.automation2.receivers.SubSystemStateReceiver;
|
||||
import com.jens.automation2.receivers.TetheringReceiver;
|
||||
import com.jens.automation2.receivers.TimeZoneListener;
|
||||
|
||||
@ -182,6 +183,9 @@ public class ReceiverCoordinator
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.tethering))
|
||||
TetheringReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.subSystemState))
|
||||
SubSystemStateReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
try
|
||||
{
|
||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||
@ -223,6 +227,7 @@ public class ReceiverCoordinator
|
||||
MediaPlayerListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
DeviceOrientationListener.getInstance().stopListener(AutomationService.getInstance());
|
||||
TetheringReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
|
||||
try
|
||||
{
|
||||
@ -440,6 +445,24 @@ public class ReceiverCoordinator
|
||||
}
|
||||
}
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.subSystemState))
|
||||
{
|
||||
if(!SubSystemStateReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "SubSystemStateReceiver", "Starting SubSystemStateReceiver because used in a new/changed rule.", 4);
|
||||
// if(DevicePositionListener.getInstance().haveAllPermission())
|
||||
TetheringReceiver.getInstance().startListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(SubSystemStateReceiver.getInstance().isListenerRunning())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "SubSystemStateReceiver", "Shutting down SubSystemStateReceiver because not used in any rule.", 4);
|
||||
SubSystemStateReceiver.getInstance().stopListener(AutomationService.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
AutomationService.updateNotification();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
@ -61,6 +60,7 @@ public class Trigger
|
||||
serviceStarts,
|
||||
broadcastReceived,
|
||||
tethering,
|
||||
subSystemState,
|
||||
phoneCall; //phoneCall always needs to be at the very end because of Google's shitty so called privacy
|
||||
|
||||
public String getFullName(Context context)
|
||||
@ -117,12 +117,16 @@ public class Trigger
|
||||
return context.getResources().getString(R.string.broadcastReceivedTitle);
|
||||
case tethering:
|
||||
return context.getResources().getString(R.string.tetheringState);
|
||||
case subSystemState:
|
||||
return context.getResources().getString(R.string.subSystemState);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static enum subSystemStates { wifi, bluetooth };
|
||||
|
||||
Rule parentRule = null;
|
||||
Calendar lastTimeNotApplied = null;
|
||||
|
||||
@ -236,6 +240,10 @@ public class Trigger
|
||||
if(!checkTetheringActive())
|
||||
result = false;
|
||||
break;
|
||||
case subSystemState:
|
||||
if(!checkSubSystemState())
|
||||
result = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -408,7 +416,9 @@ public class Trigger
|
||||
|
||||
boolean checkServiceStarts()
|
||||
{
|
||||
return !Settings.serviceStartDone;
|
||||
boolean result = !Settings.serviceStartDone == getTriggerParameter();
|
||||
return !Settings.serviceStartDone == getTriggerParameter();
|
||||
// return !Settings.serviceStartDone;
|
||||
}
|
||||
|
||||
boolean checkProfileActive()
|
||||
@ -536,6 +546,31 @@ public class Trigger
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean checkSubSystemState()
|
||||
{
|
||||
try
|
||||
{
|
||||
subSystemStates state = subSystemStates.valueOf(triggerParameter2);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case wifi:
|
||||
return WifiBroadcastReceiver.isWifiEnabled(Miscellaneous.getAnyContext()) == triggerParameter;
|
||||
case bluetooth:
|
||||
return BluetoothReceiver.isBluetoothEnabled() == triggerParameter;
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "checkSubSystemState()", "Invalid subSystemState: " + state.name(), 3);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "checkSubSystemState()", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean checkBluetooth()
|
||||
{
|
||||
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), String.format("Checking for bluetooth...", this.getParentRule().getName()), 4);
|
||||
@ -812,7 +847,10 @@ public class Trigger
|
||||
}
|
||||
else
|
||||
{
|
||||
if(BatteryReceiver.getBatteryLevel() >= this.getBatteryLevel())
|
||||
if(BatteryReceiver.getBatteryLevel() < 100 && BatteryReceiver.getBatteryLevel() >= this.getBatteryLevel()
|
||||
||
|
||||
BatteryReceiver.getBatteryLevel() > this.getBatteryLevel()
|
||||
)
|
||||
{
|
||||
Miscellaneous.logEvent("i", Miscellaneous.getAnyContext().getResources().getString(R.string.ruleCheckOf), String.format(Miscellaneous.getAnyContext().getResources().getString(R.string.ruleDoesntApplyBatteryHigherThan) + " " + String.valueOf(this.getBatteryLevel()), this.getParentRule().getName()), 3);
|
||||
return false;
|
||||
@ -1642,11 +1680,11 @@ public class Trigger
|
||||
break;
|
||||
case deviceStarts:
|
||||
// This type doesn't have an activate/deactivate equivalent
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.deviceHasJustStarted));
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.deviceIsStarting) + ": " + String.valueOf(triggerParameter));
|
||||
break;
|
||||
case serviceStarts:
|
||||
// This type doesn't have an activate/deactivate equivalent
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.serviceHasJustStarted));
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.serviceIsStarting) + ": " + String.valueOf(triggerParameter));
|
||||
break;
|
||||
case broadcastReceived:
|
||||
if(triggerParameter)
|
||||
@ -1662,6 +1700,25 @@ public class Trigger
|
||||
else
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.tetheringNotActive));
|
||||
break;
|
||||
case subSystemState:
|
||||
Trigger.subSystemStates desiredState = subSystemStates.valueOf(triggerParameter2);
|
||||
switch(desiredState)
|
||||
{
|
||||
case wifi:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.wifi));
|
||||
break;
|
||||
case bluetooth:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.bluetooth));
|
||||
break;
|
||||
}
|
||||
|
||||
returnString.append(" " + Miscellaneous.getAnyContext().getResources().getString(R.string.is) + " ");
|
||||
|
||||
if(triggerParameter)
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.activated));
|
||||
else
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.deactivated));
|
||||
break;
|
||||
default:
|
||||
returnString.append("error");
|
||||
break;
|
||||
|
@ -300,4 +300,16 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
{
|
||||
return new Trigger_Enum[] { Trigger_Enum.bluetoothConnection };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for Bluetooth.
|
||||
*
|
||||
* @return true if Bluetooth is available.
|
||||
*/
|
||||
public static boolean isBluetoothEnabled()
|
||||
{
|
||||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
|
||||
return bluetoothAdapter != null && bluetoothAdapter.isEnabled() && bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON;
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package com.jens.automation2.receivers;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
import com.jens.automation2.Rule;
|
||||
import com.jens.automation2.Trigger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SubSystemStateReceiver extends BroadcastReceiver implements AutomationListenerInterface
|
||||
{
|
||||
public static AutomationService automationServiceRef = null;
|
||||
private static IntentFilter subSystemStateIntentFilter = null;
|
||||
private static BroadcastReceiver subSystemStateReceiverInstance = null;
|
||||
private static Intent subSystemStatusIntent = null;
|
||||
private static boolean subSystemStateReceiverActive = false;
|
||||
static SubSystemStateReceiver instance;
|
||||
|
||||
final static String stateBluetooth = "android.bluetooth.adapter.action.STATE_CHANGED";
|
||||
final static String stateWifi = "android.net.wifi.STATE_CHANGE";
|
||||
final static String connectivityBroadcast = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||
|
||||
static Map<String, Boolean> stateMap = null;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if (intent == null)
|
||||
return;
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
Miscellaneous.logEvent("e", "ScreenStateReceiver", "Received: " + intent.getAction(), 3);
|
||||
|
||||
if(stateMap == null)
|
||||
stateMap = new HashMap<>();
|
||||
|
||||
try
|
||||
{
|
||||
/*if (intent.getAction().equals(stateWifi) || intent.getAction().equals(connectivityBroadcast))
|
||||
{
|
||||
if(intent.hasExtra(WifiManager.EXTRA_WIFI_STATE))
|
||||
{
|
||||
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
|
||||
|
||||
if (wifiState == WifiManager.WIFI_STATE_ENABLED)
|
||||
stateMap.put("wifi", true);
|
||||
else if (wifiState == WifiManager.WIFI_STATE_DISABLED)
|
||||
stateMap.put("wifi", false);
|
||||
}
|
||||
}
|
||||
else if (intent.getAction().equals(stateBluetooth))
|
||||
{
|
||||
if(intent.hasExtra(BluetoothAdapter.EXTRA_STATE))
|
||||
{
|
||||
int bluetoothState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
||||
|
||||
if (bluetoothState == BluetoothAdapter.STATE_ON)
|
||||
stateMap.put("bluetooth", true);
|
||||
else if (bluetoothState == BluetoothAdapter.STATE_OFF)
|
||||
stateMap.put("bluetooth", false);
|
||||
}
|
||||
}*/
|
||||
if (intent.getAction().equals(stateWifi) || intent.getAction().equals(connectivityBroadcast) || intent.getAction().equals(stateBluetooth))
|
||||
{
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.subSystemState);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).getsGreenLight(context))
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SubSystemStateReceiver", "Unknown state received: " + intent.getAction(), 3);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "SubSystemStateReceiver", "Error receiving screen state: " + e.getMessage(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static SubSystemStateReceiver getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
instance = new SubSystemStateReceiver();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startListener(AutomationService automationService)
|
||||
{
|
||||
if (!subSystemStateReceiverActive)
|
||||
{
|
||||
automationServiceRef = automationService;
|
||||
|
||||
if (subSystemStateReceiverInstance == null)
|
||||
subSystemStateReceiverInstance = new SubSystemStateReceiver();
|
||||
|
||||
if (subSystemStateIntentFilter == null)
|
||||
{
|
||||
subSystemStateIntentFilter = new IntentFilter();
|
||||
subSystemStateIntentFilter.addAction(stateWifi);
|
||||
subSystemStateIntentFilter.addAction(connectivityBroadcast);
|
||||
subSystemStateIntentFilter.addAction(stateBluetooth);
|
||||
}
|
||||
|
||||
subSystemStatusIntent = automationServiceRef.registerReceiver(subSystemStateReceiverInstance, subSystemStateIntentFilter);
|
||||
|
||||
subSystemStateReceiverActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopListener(AutomationService automationService)
|
||||
{
|
||||
if (subSystemStateReceiverActive)
|
||||
{
|
||||
if (subSystemStateReceiverInstance != null)
|
||||
{
|
||||
automationServiceRef.unregisterReceiver(subSystemStateReceiverInstance);
|
||||
subSystemStateReceiverInstance = null;
|
||||
}
|
||||
|
||||
subSystemStateReceiverActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListenerRunning()
|
||||
{
|
||||
return subSystemStateReceiverActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger.Trigger_Enum[] getMonitoredTrigger()
|
||||
{
|
||||
return new Trigger.Trigger_Enum[]{Trigger.Trigger_Enum.subSystemState};
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable-hdpi/subsystemstate.png
Normal file
BIN
app/src/main/res/drawable-hdpi/subsystemstate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="@dimen/default_margin" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<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/subSystemState" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSubSystemStateWifi"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:text="@string/wifi" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSubSystemStateBluetooth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/bluetooth" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_span="2"
|
||||
android:layout_height="1dp"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#aa000000" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSubSystemStateEnabled"
|
||||
android:checked="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/activated" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSubSystemStateDisabled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/deactivated" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSubSystemStateSave"
|
||||
android:layout_marginTop="@dimen/default_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -706,8 +706,8 @@
|
||||
<string name="startActivityInsertManually">Diese Einschränkung betrifft nur die Auswahl einer App, nicht den eigentlichen Start. So können Sie den Namen einer Anwendung immer noch manuell eingeben, falls Sie ihn kennen.</string>
|
||||
<string name="serviceStarts">Dienst startet</string>
|
||||
<string name="deviceStarts">Gerät startet</string>
|
||||
<string name="deviceHasJustStarted">Gerät ist gerade gestartet</string>
|
||||
<string name="serviceHasJustStarted">Dienst ist gerade gestartet</string>
|
||||
<string name="deviceIsStarting">Gerät startet gerade</string>
|
||||
<string name="serviceIsStarting">Dienst startet gerade</string>
|
||||
<string name="broadcastReceived">Broadcast empfangen</string>
|
||||
<string name="broadcastNotReceived">Broadcast nicht empfangen</string>
|
||||
<string name="broadcastReceivedTitle">Broadcast empfangen</string>
|
||||
|
@ -705,8 +705,8 @@
|
||||
<string name="startActivityInsertManually">Esta limitación se refiere solo a la selección de una aplicación, no al inicio real. Por lo tanto, aún puede ingresar el nombre de una aplicación manualmente si lo conoce.</string>
|
||||
<string name="deviceStarts">Dispositivo esta enciendo</string>
|
||||
<string name="serviceStarts">Servicio esta enciendo</string>
|
||||
<string name="deviceHasJustStarted">el dispositivo justamente ha encendido</string>
|
||||
<string name="serviceHasJustStarted">el servicio justamente ha encendido</string>
|
||||
<string name="deviceIsStarting">el dispositivo justamente esta encendido</string>
|
||||
<string name="serviceIsStarting">el servicio justamente esta encendido</string>
|
||||
<string name="emailPretext">Si tiene un problema, sugerencia o pregunta, escriba algo en el correo electrónico. No solo envíeme los archivos con el cuerpo de correo predeterminado. Ignoraré todo eso a menos que ya estemos en una conversación.</string>
|
||||
<string name="lockedCommentScreenMustBeOff">Cualquier estado de bloqueo solo se detectará si la pantalla está apagada.</string>
|
||||
<string name="lockedWithSecurity">bloqueado (con PIN, etc.)</string>
|
||||
|
@ -706,8 +706,8 @@
|
||||
<string name="startActivityInsertManually">Questa limitazione riguarda solo la selezione di un\'app, non l\'avvio effettivo. Quindi puoi comunque inserire manualmente il nome di un\'applicazione se lo conosci.</string>
|
||||
<string name="deviceStarts">Device starts</string>
|
||||
<string name="serviceStarts">Avvio del servizio</string>
|
||||
<string name="deviceHasJustStarted">il dispositivo è appena stato avviato</string>
|
||||
<string name="serviceHasJustStarted">il servizio è appena stato avviato</string>
|
||||
<string name="deviceIsStarting">Il dispositivo si sta avviando</string>
|
||||
<string name="serviceIsStarting">il servizio è in fase di avvio</string>
|
||||
<string name="broadcastReceived">broadcast ricevuto</string>
|
||||
<string name="broadcastNotReceived">broadcast non ricevuto</string>
|
||||
<string name="broadcastReceivedTitle">Broadcast ricevuto</string>
|
||||
|
@ -702,8 +702,8 @@
|
||||
<string name="timeFrameDaysHint">Als u een tijdsbestek gebruikt dat zich uitstrekt over middernacht, moet u ook de volgende dag selecteren als u wilt dat de trigger na middernacht van toepassing is.</string>
|
||||
<string name="featureNotInGooglePlayVersion">Deze functie is niet meer beschikbaar in de Google Play-versie.\\n\\nAlles af en toe pest Google ontwikkelaars. Als u bepaalde functies wilt blijven gebruiken, moet u papierwerk indienen. Helaas is er een kans van 99% dat het papierwerk wordt afgewezen. Het is vrijwel net als in de Asterix-strip / film.\\n\\nIk heb in het verleden wekenlang met hen gediscussieerd over dergelijke gevallen, maar ik bleef afwijzingen krijgen - hetzij door bots of mensen die ongeveer net zo intelligent zijn als bots. In de ik kan kiezen tussen de app die volledig uit de Play Store wordt verwijderd of de functie verwijdert.\\n Overweeg de APK-versie van mijn website of die van F-Droid te gebruiken als je die functies nodig hebt.</string>
|
||||
<string name="startActivityInsertManually">Deze beperking heeft alleen betrekking op de selectie van een app, niet op de daadwerkelijke start. U kunt dus nog steeds handmatig de naam van een toepassing invoeren als u deze kent.</string>
|
||||
<string name="deviceHasJustStarted">apparaat is net gestart</string>
|
||||
<string name="serviceHasJustStarted">service is net begonnen</string>
|
||||
<string name="deviceIsStarting">apparaat start</string>
|
||||
<string name="serviceIsStarting">service wordt gestart</string>
|
||||
<string name="serviceStarts">Service start</string>
|
||||
<string name="deviceStarts">Apparaat start</string>
|
||||
<string name="emailPretext">Als je een probleem, suggesties of vraag hebt, schrijf dan iets in de e-mail. Stuur me niet alleen de bestanden met de standaard e-mailtekst. Ik zal alles negeren, tenzij we al in gesprek zijn.</string>
|
||||
|
@ -801,8 +801,8 @@
|
||||
<string name="startActivityInsertManually">Это ограничение касается только выбора приложения, но не его запуска. Вы можете указать имя приложения вручную, если знаете его.</string>
|
||||
<string name="deviceStarts">Включение устройства</string>
|
||||
<string name="serviceStarts">Запуск службы</string>
|
||||
<string name="deviceHasJustStarted">устроство было включено</string>
|
||||
<string name="serviceHasJustStarted">служба была запущена</string>
|
||||
<string name="deviceIsStarting">устройство запускается</string>
|
||||
<string name="serviceIsStarting">Служба запускается</string>
|
||||
<string name="broadcastReceived">получено сообщение broadcast</string>
|
||||
<string name="broadcastNotReceived">сообщение broadcast не получено</string>
|
||||
<string name="explanationBroadcastTrigger">Большинство событий на вашем телефоне будут \"опубликованы\" при помощи Broadcast сообщений, которые передаются через операционную систему Android.\nНапример, включение/выключение режима "В самолёте" отправит подобное сообщение. Эти сообщения не видны/слышны, но если какое-нибудь приложение (как Automation) могут \"слушать\" их и когда они появляются, реагировать каким-либо образом.\n\nЗдесь вы можете настроить broadcast сообщение, которое Automation будет слушать. Вы можете ввести его вручную, скопировать откуда-нибудь или выбрать из списка. Так как этот триггер является очень гибким, я не могу предоставить вам объяснения по каждому из пунктов списка.\n\nПолнота списка не гарантируется, пожалуйста, перейдите по ссылке ниже для ознакомления с документацией Android.\nДополнительно, любое приложение может отправлять свои собственные сообщения, формат которых в документации Android, конечно же отсутствует.\n\nМногие broadcast сообщения для работы требуют специальных разрешений. Я попытался реализовать запрос разрешений там, где я знаю, что они необходимы. Если вы обнаружите, что где-то не происходит запрос разрешения, где по вашему мнению это нобходимо, пожалуйста сообщите мне.\n\n"Не получено"- значит такое сообщение не было получено с момента старта службы Automation. Реакция на некоторые параметры находится в разработке.</string>
|
||||
|
@ -802,8 +802,8 @@
|
||||
<string name="startActivityInsertManually">This limitation concerns only the selection of an app, not the actual start. So you can still enter the name of an application manually if you know it.</string>
|
||||
<string name="deviceStarts">Device starts</string>
|
||||
<string name="serviceStarts">Service starts</string>
|
||||
<string name="deviceHasJustStarted">device has just started</string>
|
||||
<string name="serviceHasJustStarted">service has just started</string>
|
||||
<string name="deviceIsStarting">device is starting</string>
|
||||
<string name="serviceIsStarting">service is starting</string>
|
||||
<string name="broadcastReceived">broadcast received</string>
|
||||
<string name="broadcastNotReceived">broadcast not received</string>
|
||||
<string name="explanationBroadcastTrigger">Most events on your phone will be \"published\" by broadcasting them throughout the operating system.\nFor example turning on/off airplane mode will trigger such a broadcast. Those broadcasts are not automatically visible/audible, but if an application (like Automation) is interested it can hook up to them. When they occur it will get notified and can react.\n\nYou can define a broadcast event here for which the application will wait. You may enter it manually, copy & paste it from somewhere or pick one from the list of suggestions. As this trigger is meant to be and remain very flexible I cannot provide you with explanations for the items.\n\nThe list of suggestions does not claim to be complete. Please visit the below URL to have a look at the Android documentation.\nAlso any app can send custom events which will not appear in the Android documentation of course.\n\nMany broadcasts require specific permissions in order to work. I try to request permissions where I know they will be required. If you think a permission is required for the action you entered, please let me know.\n\nNot received means there has not been such a broadcast ever since the service has been started. Responding to certain parameters is in development.</string>
|
||||
@ -845,4 +845,6 @@
|
||||
<string name="simplyDismissNotification">Simply dismiss</string>
|
||||
<string name="clickNotificationButton">Click a button</string>
|
||||
<string name="withButton">with button %1$s</string>
|
||||
<string name="subSystemState">Subsystem state</string>
|
||||
<string name="bluetooth">Bluetooth</string>
|
||||
</resources>
|
@ -3,4 +3,5 @@
|
||||
* New: Notification closing can now also be achieved by clicking a button of the target notification.
|
||||
* Fixed: Changed input type for decimal numbers when adding intent data
|
||||
* Fixed: Battery level trigger not working when using direction falling-below
|
||||
* New: Wifi trigger can now use Regex for SSID
|
||||
* New: Wifi trigger can now use Regex for SSID
|
||||
* Fixed: Battery receiver would trigger at 100 if specified above 100
|
Loading…
Reference in New Issue
Block a user