From 4b063a776615c4ed33da45f0edfb04e29475dbd5 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 1 Dec 2017 13:49:50 +0100 Subject: [PATCH 1/3] fix SP for long with string-ressource-id --- app/src/main/java/info/nightscout/utils/SP.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/SP.java b/app/src/main/java/info/nightscout/utils/SP.java index 36ab3b05e7..16015d8956 100644 --- a/app/src/main/java/info/nightscout/utils/SP.java +++ b/app/src/main/java/info/nightscout/utils/SP.java @@ -65,7 +65,11 @@ public class SP { } static public long getLong(int resourceID, Long defaultValue) { - return SafeParse.stringToLong(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); + try { + return sharedPreferences.getLong(MainApp.sResources.getString(resourceID), defaultValue); + } catch (Exception e) { + return SafeParse.stringToLong(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); + } } static public long getLong(String key, Long defaultValue) { From 09dac632f9d175ab4118f7a90dddaf0709d274a7 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 1 Dec 2017 13:57:53 +0100 Subject: [PATCH 2/3] bluetooth watchdog --- .../info/nightscout/androidaps/Constants.java | 1 + .../androidaps/queue/QueueThread.java | 25 +++++++++++++++++-- app/src/main/res/values/strings.xml | 5 ++++ app/src/main/res/xml/pref_advanced.xml | 10 ++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 46e8bc33a2..6765b15558 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -61,4 +61,5 @@ public class Constants { // Pump public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 60 - 1; + public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60; } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 36b43d2181..68811a1486 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -1,5 +1,6 @@ package info.nightscout.androidaps.queue; +import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.os.PowerManager; import android.os.SystemClock; @@ -16,6 +17,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.queue.events.EventQueueChanged; +import info.nightscout.utils.SP; /** * Created by mike on 09.11.2017. @@ -61,8 +63,27 @@ public class QueueThread extends Thread { MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult())); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout))); pump.stopConnecting(); - queue.clear(); - return; + + //BLUETOOTH-WATCHDOG + boolean watchdog = SP.getBoolean(R.string.key_btwatchdog, false); + long last_watchdog = SP.getLong(R.string.key_btwatchdog_lastbark, 0l); + watchdog = watchdog && System.currentTimeMillis() - last_watchdog > (Constants.MIN_WATCHDOG_INTERVAL_IN_SECONDS * 1000); + if(watchdog) { + log.debug("BT watchdog - toggeling the phonest bluetooth"); + //write time + SP.putLong(R.string.key_btwatchdog_lastbark, System.currentTimeMillis()); + //toggle BT + BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + mBluetoothAdapter.disable(); + SystemClock.sleep(1000); + mBluetoothAdapter.enable(); + SystemClock.sleep(1000); + //start over again once after watchdog barked + connectionStartTime = System.currentTimeMillis(); + } else { + queue.clear(); + return; + } } if (!pump.isConnected()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0e2833c970..33f8f466e2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -772,5 +772,10 @@ missed_bg_readings_threshold Urgent Alarm INFO + bt_watchdog + bt_watchdog_last + Bluetooth + BT Watchdog + Switches off the phone\'s bluetooth for one second if no connection to the pump is possible. This may help on some phones where the bluetooth stack freezes. diff --git a/app/src/main/res/xml/pref_advanced.xml b/app/src/main/res/xml/pref_advanced.xml index 5395a75f1e..25beb5fda7 100644 --- a/app/src/main/res/xml/pref_advanced.xml +++ b/app/src/main/res/xml/pref_advanced.xml @@ -124,6 +124,16 @@ android:title="@string/do_not_track_profile_switch" android:summary="@string/do_not_track_profile_switch_summary"/> + + + + + From 14bb0e6ac495e1046a3ca5f6da041ab92bd7ac8c Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 2 Dec 2017 10:21:42 +0100 Subject: [PATCH 3/3] Only do pump alarms in APS mode --- .../nightscout/androidaps/receivers/KeepAliveReceiver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index 828f2c5bed..38ca9ee2a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory; import java.util.Date; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -81,7 +82,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis(); boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis(); - if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true) + if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true) && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !ConfigBuilderPlugin.getActiveLoop().isDisconnected()) { Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT); n.soundId = R.raw.alarm; @@ -145,4 +146,4 @@ public class KeepAliveReceiver extends BroadcastReceiver { nextPumpDisconnectedAlarm = Math.min(System.currentTimeMillis() + pumpUnreachableThreshold(), nextPumpDisconnectedAlarm); SP.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm); } -} \ No newline at end of file +}