From c7538737693ba746d92e16a8cb9ab996d87e2970 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 18 Jul 2017 22:15:17 +0200 Subject: [PATCH] setting to disable local broadcasts in NSClient --- .../broadcasts/BroadcastAckAlarm.java | 2 ++ .../broadcasts/BroadcastAlarm.java | 4 ++++ .../broadcasts/BroadcastAnnouncement.java | 4 ++++ .../broadcasts/BroadcastCals.java | 4 ++++ .../broadcasts/BroadcastClearAlarm.java | 4 ++++ .../broadcasts/BroadcastDeviceStatus.java | 6 ++++++ .../broadcasts/BroadcastMbgs.java | 4 ++++ .../broadcasts/BroadcastProfile.java | 4 ++++ .../broadcasts/BroadcastQueueStatus.java | 4 ++++ .../broadcasts/BroadcastSgvs.java | 4 ++++ .../broadcasts/BroadcastStatus.java | 4 ++++ .../broadcasts/BroadcastTreatment.java | 19 +++++++++++++++++++ .../broadcasts/BroadcastUrgentAlarm.java | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ .../main/res/xml/pref_nsclientinternal.xml | 5 +++++ 15 files changed, 74 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java index 8b27da530a..3b01e038ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAckAlarm.java @@ -12,6 +12,7 @@ import java.util.List; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; +import info.nightscout.utils.SP; /** * Created by mike on 11.06.2017. @@ -21,6 +22,7 @@ public class BroadcastAckAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class); public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) { + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; Bundle bundle = new Bundle(); bundle.putInt("level", originalAlarm.getLevel()); bundle.putString("group", originalAlarm.getGroup()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java index 1653a55bc6..01857bd8c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -20,6 +21,9 @@ public class BroadcastAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class); public static void handleAlarm(JSONObject alarm, Context context) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("data", alarm.toString()); Intent intent = new Intent(Intents.ACTION_ALARM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java index a39a59558f..96279a039e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -21,6 +22,9 @@ public class BroadcastAnnouncement { private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class); public static void handleAnnouncement(JSONObject announcement, Context context) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("data", announcement.toString()); Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java index 6445f13f94..e8e1cd4758 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastCals.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -20,6 +21,9 @@ public class BroadcastCals { private static Logger log = LoggerFactory.getLogger(BroadcastCals.class); public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("cals", cals.toString()); bundle.putBoolean("delta", isDelta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java index c3c1e41994..768df01be2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -20,6 +21,9 @@ public class BroadcastClearAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class); public static void handleClearAlarm(JSONObject clearalarm, Context context) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("data", clearalarm.toString()); Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java index 1f338b0038..4d1321241a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastDeviceStatus.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; public class BroadcastDeviceStatus { @@ -35,6 +36,11 @@ public class BroadcastDeviceStatus { } } public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) { + + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + + List splitted = BroadcastTreatment.splitArray(statuses); for (JSONArray part: splitted) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java index 7d66352328..d11a542714 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastMbgs.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -20,6 +21,9 @@ public class BroadcastMbgs { private static Logger log = LoggerFactory.getLogger(BroadcastMbgs.class); public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("mbgs", mbgs.toString()); bundle.putBoolean("delta", isDelta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java index 0b64da8384..3fe6bf4c35 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastProfile.java @@ -12,6 +12,7 @@ import java.util.List; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.utils.SP; /** @@ -21,6 +22,9 @@ public class BroadcastProfile { private static Logger log = LoggerFactory.getLogger(BroadcastProfile.class); public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("profile", profile.getData().toString()); bundle.putBoolean("delta", isDelta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java index fbcc1ed7a3..eedeb4574d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastQueueStatus.java @@ -6,12 +6,16 @@ import android.os.Bundle; import android.os.PowerManager; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 28.02.2016. */ public class BroadcastQueueStatus { public static void handleNewStatus(int size, Context context) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sendQueue"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java index 308a1fe395..52e88295c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastSgvs.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 22.02.2016. @@ -21,6 +22,9 @@ public class BroadcastSgvs { private static Logger log = LoggerFactory.getLogger(BroadcastSgvs.class); public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("sgv", sgv.toString()); bundle.putBoolean("delta", isDelta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java index 8edd749a95..82870b960e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastStatus.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; +import info.nightscout.utils.SP; /** * Created by mike on 24.02.2016. @@ -23,6 +24,9 @@ public class BroadcastStatus { private static Logger log = LoggerFactory.getLogger(BroadcastStatus.class); public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); try { bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java index 8975b54181..dbd6414152 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastTreatment.java @@ -17,6 +17,7 @@ import java.util.List; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; +import info.nightscout.utils.SP; /** * Created by mike on 20.02.2016. @@ -25,6 +26,9 @@ public class BroadcastTreatment { private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class); public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.getData().toString()); bundle.putBoolean("delta", isDelta); @@ -42,6 +46,9 @@ public class BroadcastTreatment { } public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + List splitted = splitArray(treatments); for (JSONArray part: splitted) { Bundle bundle = new Bundle(); @@ -62,6 +69,9 @@ public class BroadcastTreatment { } public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.toString()); bundle.putBoolean("delta", isDelta); @@ -78,6 +88,9 @@ public class BroadcastTreatment { } public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + List splitted = splitArray(treatments); for (JSONArray part: splitted) { Bundle bundle = new Bundle(); @@ -98,6 +111,9 @@ public class BroadcastTreatment { } public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("treatment", treatment.toString()); bundle.putBoolean("delta", isDelta); @@ -116,6 +132,9 @@ public class BroadcastTreatment { } public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("treatments", treatments.toString()); bundle.putBoolean("delta", isDelta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java index 3093e610bf..335c500c98 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.utils.SP; /** * Created by mike on 26.06.2016. @@ -20,6 +21,9 @@ public class BroadcastUrgentAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class); public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { + + if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; + Bundle bundle = new Bundle(); bundle.putString("data", urgentalarm.toString()); Intent intent = new Intent(Intents.ACTION_URGENT_ALARM); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a44e5ef758..a8083e7bc6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -580,6 +580,7 @@ Superbolus Log app start to NS ns_logappstartedevent + nsclient_localbroadcasts Exiting application to apply settings. DanaRv2 Insulin @@ -685,4 +686,5 @@ Values not stored! Overview Notifications Pass the Overview Notifications through as wear confirmation messages. + Enable loacal broadcasts to other apps (like xDrip). diff --git a/app/src/main/res/xml/pref_nsclientinternal.xml b/app/src/main/res/xml/pref_nsclientinternal.xml index 8c12efd5de..4eb1553a1c 100644 --- a/app/src/main/res/xml/pref_nsclientinternal.xml +++ b/app/src/main/res/xml/pref_nsclientinternal.xml @@ -27,6 +27,11 @@ android:key="@string/key_ns_logappstartedevent" android:title="@string/ns_logappstartedevent" /> + +