From e7191141662cc574560da117140b5fe861449554 Mon Sep 17 00:00:00 2001 From: jens Date: Sun, 27 Feb 2022 18:01:54 +0100 Subject: [PATCH] parallel rule execution --- .../apkFlavor/java/com/jens/automation2/Rule.java | 13 ++++++++----- .../java/com/jens/automation2/Rule.java | 15 +++++++++------ .../java/com/jens/automation2/Rule.java | 13 ++++++++----- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/src/apkFlavor/java/com/jens/automation2/Rule.java b/app/src/apkFlavor/java/com/jens/automation2/Rule.java index daffe93..ec437b6 100644 --- a/app/src/apkFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/apkFlavor/java/com/jens/automation2/Rule.java @@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split; import android.annotation.SuppressLint; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Looper; import android.util.Log; import android.widget.Toast; @@ -21,8 +22,7 @@ import java.util.List; public class Rule implements Comparable { private static ArrayList ruleCollection = new ArrayList(); - public static boolean isAnyRuleActive = false; - + private static List ruleRunHistory = new ArrayList(); public static List getRuleRunHistory() @@ -538,7 +538,10 @@ public class Rule implements Comparable public void activate(AutomationService automationService, boolean force) { ActivateRuleTask task = new ActivateRuleTask(); - task.execute(automationService, force); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force); + else + task.execute(automationService, force); } public static ArrayList findRuleCandidates(Trigger.Trigger_Enum triggerType) @@ -547,13 +550,13 @@ public class Rule implements Comparable for(Rule oneRule : ruleCollection) { - innerloop: + innerLoop: for(Trigger oneTrigger : oneRule.getTriggerSet()) { if(oneTrigger.getTriggerType().equals(triggerType)) { 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 } } } diff --git a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java index 2642dad..8074f94 100644 --- a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java @@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split; import android.annotation.SuppressLint; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Looper; import android.util.Log; import android.widget.Toast; @@ -18,8 +19,7 @@ import java.util.List; public class Rule implements Comparable { private static ArrayList ruleCollection = new ArrayList(); - public static boolean isAnyRuleActive = false; - + private static List ruleRunHistory = new ArrayList(); public static List getRuleRunHistory() @@ -409,7 +409,7 @@ public class Rule implements Comparable 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()) android.os.Debug.waitForDebugger(); @@ -511,7 +511,10 @@ public class Rule implements Comparable public void activate(AutomationService automationService, boolean force) { ActivateRuleTask task = new ActivateRuleTask(); - task.execute(automationService, force); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force); + else + task.execute(automationService, force); } public static ArrayList findRuleCandidates(Trigger.Trigger_Enum triggerType) @@ -520,13 +523,13 @@ public class Rule implements Comparable for(Rule oneRule : ruleCollection) { - innerloop: + innerLoop: for(Trigger oneTrigger : oneRule.getTriggerSet()) { if(oneTrigger.getTriggerType().equals(triggerType)) { 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 } } } diff --git a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java index 4810f01..63e1580 100644 --- a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java @@ -5,6 +5,7 @@ import static com.jens.automation2.Trigger.triggerParameter2Split; import android.annotation.SuppressLint; import android.content.Context; import android.os.AsyncTask; +import android.os.Build; import android.os.Looper; import android.util.Log; import android.widget.Toast; @@ -21,8 +22,7 @@ import java.util.List; public class Rule implements Comparable { private static ArrayList ruleCollection = new ArrayList(); - public static boolean isAnyRuleActive = false; - + private static List ruleRunHistory = new ArrayList(); public static List getRuleRunHistory() @@ -538,7 +538,10 @@ public class Rule implements Comparable public void activate(AutomationService automationService, boolean force) { ActivateRuleTask task = new ActivateRuleTask(); - task.execute(automationService, force); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) + task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, automationService, force); + else + task.execute(automationService, force); } public static ArrayList findRuleCandidates(Trigger.Trigger_Enum triggerType) @@ -547,13 +550,13 @@ public class Rule implements Comparable for(Rule oneRule : ruleCollection) { - innerloop: + innerLoop: for(Trigger oneTrigger : oneRule.getTriggerSet()) { if(oneTrigger.getTriggerType().equals(triggerType)) { 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 } } }