parallel rule execution

This commit is contained in:
jens 2022-02-27 18:01:54 +01:00
parent 0bd64e4a53
commit e719114166
3 changed files with 25 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -21,7 +22,6 @@ import java.util.List;
public class Rule implements Comparable<Rule> public class Rule implements Comparable<Rule>
{ {
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>(); private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
public static boolean isAnyRuleActive = false;
private static List<Rule> ruleRunHistory = new ArrayList<Rule>(); private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
@ -538,6 +538,9 @@ public class Rule implements Comparable<Rule>
public void activate(AutomationService automationService, boolean force) public void activate(AutomationService automationService, boolean force)
{ {
ActivateRuleTask task = new ActivateRuleTask(); ActivateRuleTask task = new ActivateRuleTask();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
else
task.execute(automationService, force); task.execute(automationService, force);
} }
@ -547,13 +550,13 @@ public class Rule implements Comparable<Rule>
for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
{ {
innerloop: innerLoop:
for(Trigger oneTrigger : oneRule.getTriggerSet()) for(Trigger oneTrigger : oneRule.getTriggerSet())
{ {
if(oneTrigger.getTriggerType().equals(triggerType)) if(oneTrigger.getTriggerType().equals(triggerType))
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; // we don't need to check the other triggers in the same rule break innerLoop; // we don't need to check the other triggers in the same rule
} }
} }
} }

View File

@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -18,7 +19,6 @@ import java.util.List;
public class Rule implements Comparable<Rule> public class Rule implements Comparable<Rule>
{ {
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>(); private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
public static boolean isAnyRuleActive = false;
private static List<Rule> ruleRunHistory = new ArrayList<Rule>(); private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
@ -409,7 +409,7 @@ public class Rule implements Comparable<Rule>
Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler); Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.uncaughtExceptionHandler);
// without this line debugger will - for some reason - skip all breakpoints in this class // without this line the debugger will - for some reason - skip all breakpoints in this class
if(android.os.Debug.isDebuggerConnected()) if(android.os.Debug.isDebuggerConnected())
android.os.Debug.waitForDebugger(); android.os.Debug.waitForDebugger();
@ -511,6 +511,9 @@ public class Rule implements Comparable<Rule>
public void activate(AutomationService automationService, boolean force) public void activate(AutomationService automationService, boolean force)
{ {
ActivateRuleTask task = new ActivateRuleTask(); ActivateRuleTask task = new ActivateRuleTask();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
else
task.execute(automationService, force); task.execute(automationService, force);
} }
@ -520,13 +523,13 @@ public class Rule implements Comparable<Rule>
for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
{ {
innerloop: innerLoop:
for(Trigger oneTrigger : oneRule.getTriggerSet()) for(Trigger oneTrigger : oneRule.getTriggerSet())
{ {
if(oneTrigger.getTriggerType().equals(triggerType)) if(oneTrigger.getTriggerType().equals(triggerType))
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; // we don't need to check the other triggers in the same rule break innerLoop; // we don't need to check the other triggers in the same rule
} }
} }
} }

View File

@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -21,7 +22,6 @@ import java.util.List;
public class Rule implements Comparable<Rule> public class Rule implements Comparable<Rule>
{ {
private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>(); private static ArrayList<Rule> ruleCollection = new ArrayList<Rule>();
public static boolean isAnyRuleActive = false;
private static List<Rule> ruleRunHistory = new ArrayList<Rule>(); private static List<Rule> ruleRunHistory = new ArrayList<Rule>();
@ -538,6 +538,9 @@ public class Rule implements Comparable<Rule>
public void activate(AutomationService automationService, boolean force) public void activate(AutomationService automationService, boolean force)
{ {
ActivateRuleTask task = new ActivateRuleTask(); ActivateRuleTask task = new ActivateRuleTask();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force);
else
task.execute(automationService, force); task.execute(automationService, force);
} }
@ -547,13 +550,13 @@ public class Rule implements Comparable<Rule>
for(Rule oneRule : ruleCollection) for(Rule oneRule : ruleCollection)
{ {
innerloop: innerLoop:
for(Trigger oneTrigger : oneRule.getTriggerSet()) for(Trigger oneTrigger : oneRule.getTriggerSet())
{ {
if(oneTrigger.getTriggerType().equals(triggerType)) if(oneTrigger.getTriggerType().equals(triggerType))
{ {
ruleCandidates.add(oneRule); ruleCandidates.add(oneRule);
break innerloop; // we don't need to check the other triggers in the same rule break innerLoop; // we don't need to check the other triggers in the same rule
} }
} }
} }