Rework
This commit is contained in:
@ -264,7 +264,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions())
|
||||
if(ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies for entering POI " + this.getName() + ".", 2);
|
||||
ruleCandidates.get(i).activate(parentService, false);
|
||||
@ -296,7 +296,7 @@ public class PointOfInterest implements Comparable<PointOfInterest>
|
||||
Miscellaneous.logEvent("i", "POI", "POI " + this.getName() + " found in " + ruleCandidates.size() + " rule(s).", 2);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(parentService))
|
||||
if(ruleCandidates.get(i).applies(parentService) && ruleCandidates.get(i).haveEnoughPermissions() && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
{
|
||||
Miscellaneous.logEvent("i", "POI", "Rule " + ruleCandidates.get(i).getName() + " applies for leaving POI " + this.getName() + ".", 2);
|
||||
ruleCandidates.get(i).activate(parentService, false);
|
||||
|
@ -47,6 +47,7 @@ public class ReceiverCoordinator
|
||||
BatteryReceiver.class,
|
||||
BluetoothReceiver.class,
|
||||
ConnectivityReceiver.class,
|
||||
DevicePositionListener.class,
|
||||
HeadphoneJackListener.class,
|
||||
//NfcReceiver.class,
|
||||
NoiseListener.class,
|
||||
@ -57,13 +58,12 @@ public class ReceiverCoordinator
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
// e.printStackTrace();
|
||||
|
||||
allImplementers = new Class[] {
|
||||
DateTimeListener.class,
|
||||
BatteryReceiver.class,
|
||||
BluetoothReceiver.class,
|
||||
ConnectivityReceiver.class,
|
||||
DevicePositionListener.class,
|
||||
HeadphoneJackListener.class,
|
||||
//NfcReceiver.class,
|
||||
NoiseListener.class,
|
||||
@ -167,6 +167,9 @@ public class ReceiverCoordinator
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.process_started_stopped))
|
||||
ProcessListener.startProcessListener(AutomationService.getInstance());
|
||||
|
||||
if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.devicePosition))
|
||||
DevicePositionListener.getInstance().startListener(AutomationService.getInstance());
|
||||
|
||||
try
|
||||
{
|
||||
Class testClass = Class.forName(ActivityManageRule.activityDetectionClassPath);
|
||||
|
@ -31,103 +31,99 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class Trigger
|
||||
{
|
||||
Rule parentRule = null;
|
||||
boolean hasFlipped = false;
|
||||
|
||||
public boolean getHasFlipped()
|
||||
{
|
||||
return hasFlipped;
|
||||
}
|
||||
|
||||
public void setHasFlipped(boolean hasFlipped)
|
||||
{
|
||||
this.hasFlipped = hasFlipped;
|
||||
}
|
||||
Calendar lastTimeNotApplied = null;
|
||||
|
||||
public boolean applies(Object triggeringObject, Context context)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
try
|
||||
{
|
||||
switch(this.getTriggerType())
|
||||
{
|
||||
case timeFrame:
|
||||
if(!checkDateTime(triggeringObject, false))
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case pointOfInterest:
|
||||
if(!checkLocation())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case charging:
|
||||
if(!checkCharging())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case usb_host_connection:
|
||||
if(!checkUsbHostConnection())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case batteryLevel:
|
||||
if(!checkBatteryLevel())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case speed:
|
||||
if(!checkSpeed())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case noiseLevel:
|
||||
if(!checkNoiseLevel())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case wifiConnection:
|
||||
if(!checkWifiConnection())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case process_started_stopped:
|
||||
if(!checkProcess())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case airplaneMode:
|
||||
if(!checkAirplaneMode())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case roaming:
|
||||
if(!checkRoaming())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case phoneCall:
|
||||
if(!checkPhoneCall())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case nfcTag:
|
||||
if(!checkNfc())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case bluetoothConnection:
|
||||
if(!checkBluetooth())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case headsetPlugged:
|
||||
if(!checkHeadsetPlugged())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case notification:
|
||||
if(!checkNotification())
|
||||
return false;
|
||||
result = false;
|
||||
break;
|
||||
case devicePosition:
|
||||
and others
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Trigger", "Error while checking if rule " + getParentRule().getName() + " applies. Error occured in trigger " + this.getParentRule().toString() + "." + Miscellaneous.lineSeparator + Log.getStackTraceString(e), 1);
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
|
||||
if(!result)
|
||||
lastTimeNotApplied = Calendar.getInstance();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean checkNotification()
|
||||
@ -623,31 +619,19 @@ public class Trigger
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasStateRecentlyNotApplied(Object triggeringObject)
|
||||
public boolean hasStateNotAppliedSinceLastRuleExecution()
|
||||
{
|
||||
// nur mit einem Trigger?
|
||||
|
||||
// door -> was state different in previous step
|
||||
|
||||
try
|
||||
{
|
||||
switch(getTriggerType())
|
||||
{
|
||||
case timeFrame:
|
||||
if(!checkDateTime(triggeringObject, true))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(getParentRule().getLastExecution() == null)
|
||||
return true;
|
||||
}
|
||||
catch(Exception e)
|
||||
else if(lastTimeNotApplied != null)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "Trigger", "Error while checking if rule " + getParentRule().getName() + " applies. Error occured in trigger " + this.getParentRule().toString() + "." + Miscellaneous.lineSeparator + Log.getStackTraceString(e), 1);
|
||||
return false;
|
||||
if(lastTimeNotApplied.getTimeInMillis() > getParentRule().getLastExecution().getTimeInMillis())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean checkCharging()
|
||||
|
@ -201,7 +201,7 @@ public class LocationProvider
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesBySpeed();
|
||||
for (Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if (oneRule.applies(this.getParentService()))
|
||||
if (oneRule.applies(this.getParentService()) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
oneRule.activate(getParentService(), false);
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByWifiConnection();
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(automationServiceInstance))
|
||||
if(oneRule.applies(automationServiceInstance) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
oneRule.activate(automationServiceInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(true);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context))
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByBatteryLevel();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context))
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -234,7 +234,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByCharging(false);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context))
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(true);
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(context))
|
||||
if(oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
oneRule.activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ public class BatteryReceiver extends BroadcastReceiver implements AutomationList
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByUsbHost(false);
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(context))
|
||||
if(oneRule.applies(context) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
oneRule.activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class BluetoothReceiver extends BroadcastReceiver implements AutomationLi
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByBluetoothConnection();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(AutomationService.getInstance()))
|
||||
if(ruleCandidates.get(i).applies(AutomationService.getInstance()) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class ConnectivityReceiver extends BroadcastReceiver implements Automatio
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByAirplaneMode(isAirplaneMode);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef))
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ public class ConnectivityReceiver extends BroadcastReceiver implements Automatio
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByRoaming(isRoaming);
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef))
|
||||
if(ruleCandidates.get(i).applies(automationServiceRef) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class DateTimeListener extends BroadcastReceiver implements AutomationLis
|
||||
ArrayList<Rule> allRulesWithNowInTimeFrame = Rule.findRuleCandidatesByTime(passTime);
|
||||
for(int i=0; i<allRulesWithNowInTimeFrame.size(); i++)
|
||||
{
|
||||
if(allRulesWithNowInTimeFrame.get(i).applies(context))
|
||||
if(allRulesWithNowInTimeFrame.get(i).applies(context) && allRulesWithNowInTimeFrame.get(i).hasNotAppliedSinceLastExecution())
|
||||
allRulesWithNowInTimeFrame.get(i).activate(automationServiceRef, false);
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,8 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
|
||||
public void stopSensorFromConfigActivity()
|
||||
{
|
||||
activityManageTriggerDevicePositionInstance = null;
|
||||
|
||||
if(isRunning)
|
||||
{
|
||||
if(!Rule.isAnyRuleUsing(Trigger.Trigger_Enum.devicePosition))
|
||||
@ -127,7 +129,7 @@ public class DevicePositionListener implements SensorEventListener, AutomationLi
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.devicePosition);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).applies(Miscellaneous.getAnyContext()))
|
||||
if (ruleCandidates.get(i).applies(Miscellaneous.getAnyContext()) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class HeadphoneJackListener extends BroadcastReceiver implements Automati
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByHeadphoneJack(isHeadsetConnected());
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(context))
|
||||
if(ruleCandidates.get(i).applies(context) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class NfcReceiver
|
||||
ArrayList<Rule> allRulesWithNfcTags = Rule.findRuleCandidatesByNfc();
|
||||
for(int i=0; i<allRulesWithNfcTags.size(); i++)
|
||||
{
|
||||
if(allRulesWithNfcTags.get(i).applies(asInstance))
|
||||
if(allRulesWithNfcTags.get(i).applies(asInstance) && allRulesWithNfcTags.get(i).hasNotAppliedSinceLastExecution())
|
||||
allRulesWithNfcTags.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class NoiseListener implements AutomationListenerInterface
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByNoiseLevel();
|
||||
for(Rule oneRule : ruleCandidates)
|
||||
{
|
||||
if(oneRule.applies(automationService))
|
||||
if(oneRule.applies(automationService) && oneRule.hasNotAppliedSinceLastExecution())
|
||||
oneRule.activate(automationService, false);
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class NotificationListener extends NotificationListenerService
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.notification);
|
||||
for (int i = 0; i < ruleCandidates.size(); i++)
|
||||
{
|
||||
if (ruleCandidates.get(i).applies(NotificationListener.this))
|
||||
if (ruleCandidates.get(i).applies(NotificationListener.this) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(AutomationService.getInstance(), false);
|
||||
}
|
||||
// }
|
||||
|
@ -114,7 +114,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).applies(asInstance))
|
||||
if(ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if (asInstance != null)
|
||||
if (ruleCandidates.get(i).applies(asInstance))
|
||||
if (ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ public class PhoneStatusListener implements AutomationListenerInterface
|
||||
{
|
||||
AutomationService asInstance = AutomationService.getInstance();
|
||||
if(asInstance != null)
|
||||
if(ruleCandidates.get(i).applies(asInstance))
|
||||
if(ruleCandidates.get(i).applies(asInstance) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(asInstance, false);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class ProcessListener implements AutomationListenerInterface
|
||||
ArrayList<Rule> ruleCandidates = Rule.findRuleCandidatesByProcess();
|
||||
for(int i=0; i<ruleCandidates.size(); i++)
|
||||
{
|
||||
if(ruleCandidates.get(i).applies(automationService))
|
||||
if(ruleCandidates.get(i).applies(automationService) && ruleCandidates.get(i).hasNotAppliedSinceLastExecution())
|
||||
ruleCandidates.get(i).activate(automationService, false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user