From eaecf637245136f593cd525acf3d3ee209b12694 Mon Sep 17 00:00:00 2001 From: Jens Date: Sat, 6 Jan 2024 23:57:52 +0100 Subject: [PATCH] Calendar trigger --- .../java/com/jens/automation2/Rule.java | 5 +++++ .../java/com/jens/automation2/Rule.java | 5 +++++ .../com/jens/automation2/AutomationService.java | 13 ++++++++++++- app/src/main/java/com/jens/automation2/Trigger.java | 11 ++++++----- .../automation2/location/WifiBroadcastReceiver.java | 2 +- .../automation2/receivers/CalendarReceiver.java | 11 ++--------- fastlane/metadata/android/en-US/changelogs/138.txt | 1 + 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java index 4591e5f..822d943 100644 --- a/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/fdroidFlavor/java/com/jens/automation2/Rule.java @@ -373,6 +373,11 @@ public class Rule implements Comparable Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4); return true; } + else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this)) + { + Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4); + return true; + } else Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4); } diff --git a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java index 16fd399..012b4b4 100644 --- a/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java +++ b/app/src/googlePlayFlavor/java/com/jens/automation2/Rule.java @@ -376,6 +376,11 @@ public class Rule implements Comparable Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies and has flipped since its last execution.", 4); return true; } + else if(hasTriggerOfType(Trigger.Trigger_Enum.calendarEvent) && CalendarReceiver.mayRuleStillBeActivatedForPendingCalendarEvents(this)) + { + Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " applies, has not flipped since its last execution, but may still be executed for other calendar events.", 4); + return true; + } else Miscellaneous.logEvent("i", "getsGreenLight()", "Rule " + getName() + " has not flipped since its last execution.", 4); } diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 910d0d2..cae6c32 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -128,7 +128,18 @@ public class AutomationService extends Service implements OnInitListener // Store a reference to myself. Other classes often need a context or something, this can provide that. centralInstance = this; - Miscellaneous.setDisplayLanguage(AutomationService.this); + /* + This has been reported to throw a NullPointerException under + rare circumstances. The root cause remains unknown. + */ + try + { + Miscellaneous.setDisplayLanguage(AutomationService.this); + } + catch(NullPointerException e) + { + Miscellaneous.logEvent("e", "setDisplayLanguage()", Log.getStackTraceString(e), 3); + } } public boolean checkStartupRequirements(Context context, boolean startAtBoot) diff --git a/app/src/main/java/com/jens/automation2/Trigger.java b/app/src/main/java/com/jens/automation2/Trigger.java index 71e616c..8ebb9c1 100644 --- a/app/src/main/java/com/jens/automation2/Trigger.java +++ b/app/src/main/java/com/jens/automation2/Trigger.java @@ -644,6 +644,12 @@ public class Trigger // No contradictions found Miscellaneous.logEvent("i", "CalendarCheck", "Event " + event + " matches.", 4); + + /* + At this point the rule will either get executed for this event or it already has been executed for it. + */ + CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(getParentRule(), event)); + return true; } @@ -756,11 +762,6 @@ public class Trigger // No contradictions found Miscellaneous.logEvent("i", "CalendarCheck", "Event " + event + " matches.", 4); - /* - At this point the rule will either get executed for this event or it already has been executed for it. - */ - CalendarReceiver.addUsedPair(new CalendarReceiver.RuleEventPair(getParentRule(), event)); - return true; } diff --git a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java index 1a81d04..1b7782b 100644 --- a/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java +++ b/app/src/main/java/com/jens/automation2/location/WifiBroadcastReceiver.java @@ -55,7 +55,7 @@ public class WifiBroadcastReceiver extends BroadcastReceiver if(newWifiSsid.length() > 0) { if(!newWifiSsid.equals(unknownSsidName)) - WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid; + WifiBroadcastReceiver.lastWifiSsidReal = lastWifiSsid; WifiBroadcastReceiver.lastWifiSsid = newWifiSsid; } diff --git a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java index ca7369c..0e501b1 100644 --- a/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/CalendarReceiver.java @@ -57,7 +57,8 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis this.event = event; } } - static List calendarEventsUsed = new ArrayList<>(); // To determine for which events which rules have been executed + // To determine for which events which rules have been executed + static List calendarEventsUsed = new ArrayList<>(); public static void addUsedPair(RuleEventPair pair) { // Add pair only if it's not in the list already. @@ -100,14 +101,6 @@ public class CalendarReceiver extends BroadcastReceiver implements AutomationLis static void checkForRules(Context context) { - /* - Kann die selbe Regel mehrfach pro Termin ausgeführt werden? Nein, eh nicht, ne? - Am nächsten Tag ist es wieder ein anderer Termin. - - Wenn zwei zeitgleiche Termine mit gleichen Inhalten in verschiedenen Kalendern sind, - würde die Regel so 2x ausgeführt werden. - */ - //TODO: Second appointment directly one after another or overlapping won't get executed ArrayList ruleCandidates = Rule.findRuleCandidates(Trigger.Trigger_Enum.calendarEvent); for (int i = 0; i < ruleCandidates.size(); i++) { diff --git a/fastlane/metadata/android/en-US/changelogs/138.txt b/fastlane/metadata/android/en-US/changelogs/138.txt index 83b0f6e..b9de917 100644 --- a/fastlane/metadata/android/en-US/changelogs/138.txt +++ b/fastlane/metadata/android/en-US/changelogs/138.txt @@ -3,6 +3,7 @@ * Fixed: Bug in Android 14 (not in Automation!!!) required a change when dialing MMI codes containing a # character. * Fixed: Storage permission might be displayed as not granted even if it was * Fixed: Applied a very old bugfix also to F-Droid and Google-Play editions that had by mistake been implemented only in the APK edition (timeFrame trigger with repetitions) +* Fixed: Rare crash while starting service * Added: new action -> take screenshot * Added: Location service (GPS) can be toggled between states if WRITE_SECURE_SETTINGS has been granted from a computer * Added: triggerUrl action can now be used with POST and parameters