From a9646cbf28dd1458f78fb895d39a0bc80d1543d8 Mon Sep 17 00:00:00 2001 From: Jens Date: Mon, 16 Jan 2023 23:44:28 +0100 Subject: [PATCH] Autostart error fixed --- .../main/java/com/jens/automation2/Miscellaneous.java | 9 +++++++-- .../main/java/com/jens/automation2/PointOfInterest.java | 2 +- .../automation2/receivers/StartupIntentReceiver.java | 3 ++- fastlane/metadata/android/en-US/changelogs/125.txt | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index dbfcc32e..7006c41c 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -111,6 +111,8 @@ import androidx.documentfile.provider.DocumentFile; public class Miscellaneous extends Service { protected static String writeableFolderStringCache = null; + public static Context startupContext; + public static final String lineSeparator = System.getProperty("line.separator"); public static String downloadURL(String url, String username, String password) @@ -273,7 +275,7 @@ public class Miscellaneous extends Service { writeToLogFile(type, header, description); - if(!logCleanerRunning && Math.random() < 0.1) // tidy up with 10% probability + if (!logCleanerRunning && Math.random() < 0.1) // tidy up with 10% probability { rotateLogFile(getLogFile()); } @@ -557,7 +559,10 @@ public class Miscellaneous extends Service returnContext = ActivityPermissions.getInstance().getApplicationContext(); if(returnContext != null) return returnContext; - + + if(startupContext != null) + return startupContext; + return null; } diff --git a/app/src/main/java/com/jens/automation2/PointOfInterest.java b/app/src/main/java/com/jens/automation2/PointOfInterest.java index 9f02ece6..0f799a02 100644 --- a/app/src/main/java/com/jens/automation2/PointOfInterest.java +++ b/app/src/main/java/com/jens/automation2/PointOfInterest.java @@ -494,7 +494,7 @@ public class PointOfInterest implements Comparable Check for change of rule name END */ - if (plausibilityCheck()) + if(plausibilityCheck()) { Miscellaneous.logEvent("i", "Changing POI", "Old name: " + this.oldName + ", new data: " + this.toStringLong(), 3); diff --git a/app/src/main/java/com/jens/automation2/receivers/StartupIntentReceiver.java b/app/src/main/java/com/jens/automation2/receivers/StartupIntentReceiver.java index 27db2dee..86e0585c 100644 --- a/app/src/main/java/com/jens/automation2/receivers/StartupIntentReceiver.java +++ b/app/src/main/java/com/jens/automation2/receivers/StartupIntentReceiver.java @@ -11,12 +11,13 @@ import com.jens.automation2.Settings; public class StartupIntentReceiver extends BroadcastReceiver { - @Override public void onReceive(Context context, Intent intent) { Settings.readFromPersistentStorage(context); + Miscellaneous.startupContext = context; + // Miscellaneous.logEvent("i", "Boot event", "Received event: " + intent.getAction(), 5); if(Settings.startServiceAtSystemBoot) diff --git a/fastlane/metadata/android/en-US/changelogs/125.txt b/fastlane/metadata/android/en-US/changelogs/125.txt index bcfee849..563d256e 100644 --- a/fastlane/metadata/android/en-US/changelogs/125.txt +++ b/fastlane/metadata/android/en-US/changelogs/125.txt @@ -1,2 +1,3 @@ * Fixed: Now allowing negative integers as intent data -* Fixed: Multiple time frames with reoccurence configured would trigger to early executions \ No newline at end of file +* Fixed: Multiple time frames with reoccurence configured would trigger to early executions +* Fixed: Automatic app start at boot might fail in some cases \ No newline at end of file