From b7ebf2cdcd527fb1ab95e5ad511d8602268616e8 Mon Sep 17 00:00:00 2001 From: Jens Date: Sun, 21 Mar 2021 22:27:34 +0100 Subject: [PATCH] Fixed app crashing when saving rules while service is running. --- app/build.gradle | 4 +- .../jens/automation2/ReceiverCoordinator.java | 42 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a03f06c8..a177cc71 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { compileSdkVersion 29 buildToolsVersion '29.0.2' useLibrary 'org.apache.http.legacy' - versionCode 100 - versionName "1.6.24" + versionCode 101 + versionName "1.6.25" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java index b833da8d..b53f37c4 100644 --- a/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java +++ b/app/src/main/java/com/jens/automation2/ReceiverCoordinator.java @@ -273,32 +273,40 @@ public class ReceiverCoordinator if(Rule.isAnyRuleUsing(Trigger.Trigger_Enum.activityDetection)) { - boolean isRunning = (Boolean)Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "isActivityDetectionReceiverRunning", null); - if(isRunning) + Object runResult = Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "isActivityDetectionReceiverRunning", null);; + if(runResult instanceof Boolean) { - Miscellaneous.logEvent("i", "LocationProvider", "Restarting ActivityDetectionReceiver because used in a new/changed rule.", 4); - boolean haveAllPerms = (Boolean)Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "haveAllPermission", null); - if(haveAllPerms) - Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "restartActivityDetectionReceiver", null); + boolean isRunning = (Boolean) runResult; + if (isRunning) + { + Miscellaneous.logEvent("i", "LocationProvider", "Restarting ActivityDetectionReceiver because used in a new/changed rule.", 4); + boolean haveAllPerms = (Boolean) Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "haveAllPermission", null); + if (haveAllPerms) + Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "restartActivityDetectionReceiver", null); // ActivityDetectionReceiver.restartActivityDetectionReceiver(); - } - else - { - Miscellaneous.logEvent("i", "LocationProvider", "Starting ActivityDetectionReceiver because used in a new/changed rule.", 4); - boolean haveAllPerms = (Boolean)Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "haveAllPermission", null); - if(haveAllPerms) - Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "startActivityDetectionReceiver", null); + } + else + { + Miscellaneous.logEvent("i", "LocationProvider", "Starting ActivityDetectionReceiver because used in a new/changed rule.", 4); + boolean haveAllPerms = (Boolean) Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "haveAllPermission", null); + if (haveAllPerms) + Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "startActivityDetectionReceiver", null); // ActivityDetectionReceiver.startActivityDetectionReceiver(); + } } } else { - boolean isRunning = (Boolean)Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "isActivityDetectionReceiverRunning", null); - if(isRunning) + Object runResult = Miscellaneous.runMethodReflective(activityDetectionClassPath, "isActivityDetectionReceiverRunning", null); + if(runResult instanceof Boolean) { - Miscellaneous.logEvent("i", "LocationProvider", "Shutting down ActivityDetectionReceiver because not used in any rule.", 4); - Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "stopActivityDetectionReceiver", null); + boolean isRunning = (Boolean) runResult; + if (isRunning) + { + Miscellaneous.logEvent("i", "LocationProvider", "Shutting down ActivityDetectionReceiver because not used in any rule.", 4); + Miscellaneous.runMethodReflective("ActivityDetectionReceiver", "stopActivityDetectionReceiver", null); // ActivityDetectionReceiver.stopActivityDetectionReceiver(); + } } }