From f6c08cf8e5e4d09c0132325977105eaff7e42f06 Mon Sep 17 00:00:00 2001 From: bigdigital <4833779+bigdigital@users.noreply.github.com> Date: Thu, 28 Jul 2022 15:18:49 +0300 Subject: [PATCH 1/5] allow to send predicted data (IOB, BWP) --- .../broadcastservice/BroadcastService.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java index abe69b9b73..72566d9b51 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java @@ -12,6 +12,8 @@ import android.os.Parcelable; import android.os.PowerManager; import android.preference.PreferenceManager; +import android.support.v4.content.LocalBroadcastManager; +import android.util.Log; import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.Models.Accuracy; @@ -29,6 +31,7 @@ import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; import com.eveningoutpost.dexdrip.UtilityModels.Constants; +import com.eveningoutpost.dexdrip.UtilityModels.Intents; import com.eveningoutpost.dexdrip.UtilityModels.Pref; import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; import com.eveningoutpost.dexdrip.stats.StatsResult; @@ -76,6 +79,11 @@ public class BroadcastService extends Service { protected String TAG = this.getClass().getSimpleName(); protected Map broadcastEntities; + private BroadcastReceiver statusReceiver; + + private String predictedBWP; + private String predictedIOB; + /** * The receiver listening {@link ACTION_WATCH_COMMUNICATION_RECEIVER} action. * Every Receiver command requires {@link Const.INTENT_PACKAGE_KEY} @@ -209,7 +217,6 @@ public void onReceive(Context context, Intent intent) { } }; - @Override public IBinder onBind(Intent intent) { return null; @@ -227,6 +234,25 @@ public void onCreate() { registerReceiver(broadcastReceiver, new IntentFilter(ACTION_WATCH_COMMUNICATION_RECEIVER)); JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_START); + + statusReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + final String bwp = intent.getStringExtra("bwp"); + if (bwp != null) { + predictedBWP = bwp; + } else { + final String iob = intent.getStringExtra("iob"); + if (iob != null) { + predictedIOB = iob; + } + } + } + }; + + LocalBroadcastManager.getInstance(this).registerReceiver(statusReceiver, + new IntentFilter(Intents.HOME_STATUS_ACTION)); + super.onCreate(); } @@ -235,6 +261,12 @@ public void onDestroy() { UserError.Log.e(TAG, "killing service"); broadcastEntities.clear(); unregisterReceiver(broadcastReceiver); + + try { + LocalBroadcastManager.getInstance(this).unregisterReceiver(statusReceiver); + } catch (Exception e) { + Log.e(TAG, "Exception unregistering broadcast receiver: " + e); + } super.onDestroy(); } @@ -513,7 +545,7 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putDouble("lowMark", JoH.tolerantParseDouble(prefs.getString("lowValue", "70"), 70)); BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(xdrip.getAppContext(), start, end); - bgGraphBuilder.defaultLines(true); // simple mode + bgGraphBuilder.defaultLines(false); // not simple mode in order to receive simulated data bundle.putParcelable("graph.lowLine", new GraphLine(bgGraphBuilder.lowLine())); bundle.putParcelable("graph.highLine", new GraphLine(bgGraphBuilder.highLine())); @@ -530,7 +562,11 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ; } + + bundle.putString("predict.IOB", predictedIOB); + bundle.putString("predict.BWP", predictedBWP); } return bundle; } + } From deb66bb30e7cd1a98b11429fe3ca0adb259fdcf1 Mon Sep 17 00:00:00 2001 From: bigdigital <4833779+bigdigital@users.noreply.github.com> Date: Fri, 29 Jul 2022 12:14:52 +0300 Subject: [PATCH 2/5] reset predicted iob before data refresh --- .../dexdrip/Services/broadcastservice/BroadcastService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java index 72566d9b51..f61e4fd1ea 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java @@ -527,6 +527,9 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putLong("treatment.timeStamp", treatment.timestamp); } + predictedIOB = ""; + predictedBWP = ""; + if (settings.isDisplayGraph()) { long graphStartOffset = settings.getGraphStart(); long graphEndOffset = settings.getGraphEnd(); From 990fe51f3b72b83984ee3d466e0f7aebbab4e090 Mon Sep 17 00:00:00 2001 From: bigdigital <4833779+bigdigital@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:06:26 +0200 Subject: [PATCH 3/5] add cancel_alarm not notify remote devices in case alert were stopped by phone --- .../dexdrip/Services/broadcastservice/BroadcastEntry.java | 6 ++++++ .../dexdrip/Services/broadcastservice/BroadcastService.java | 6 ++++++ .../dexdrip/Services/broadcastservice/Const.java | 1 + .../eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java | 2 ++ 4 files changed, 15 insertions(+) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java index bfa888adb5..5e13e21701 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastEntry.java @@ -24,6 +24,12 @@ public static void sendLatestBG() { } } + public static void cancelAlert() { + if (isEnabled()) { + JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_CANCEL_ALERT); + } + } + public static void sendAlert(String type, String message) { if (isEnabled()) { Inevitable.task("broadcast-service-send-alert", 100, () -> JoH.startService(BroadcastService.class, diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java index f61e4fd1ea..36c9b95534 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java @@ -326,6 +326,9 @@ private void handleCommand(String function, Intent intent) { bundle.putString("message", intent.getStringExtra("message")); sendBroadcast(function, receiver, bundle); break; + case Const.CMD_CANCEL_ALERT: + sendBroadcast(function, receiver, bundle); + break; } } @@ -350,6 +353,9 @@ private void handleCommand(String function, Intent intent) { broadcastModel = broadcastEntities.get(receiver); bundle = prepareBgBundle(broadcastModel); break; + case Const.CMD_CANCEL_ALERT: + receiver = null; //broadcast + break; case Const.CMD_SNOOZE_ALERT: String alertName = ""; String replyMsg = ""; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java index acc3cf91b2..367999f2ca 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/Const.java @@ -19,6 +19,7 @@ public class Const { public static final String CMD_SET_SETTINGS = "set_settings"; public static final String CMD_UPDATE_BG_FORCE = "update_bg_force"; public static final String CMD_ALERT = "alarm"; + public static final String CMD_CANCEL_ALERT = "cancel_alarm"; public static final String CMD_SNOOZE_ALERT = "snooze_alarm"; public static final String CMD_ADD_STEPS = "add_steps"; public static final String CMD_ADD_HR = "add_hrs"; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java index 69c7e329b8..bb085a5156 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/AlertPlayer.java @@ -236,6 +236,8 @@ public synchronized void Snooze(Context ctx, int repeatTime) { && Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) { Amazfitservice.start("xDrip_AlarmCancel"); } + + BroadcastEntry.cancelAlert(); } public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) { From 457dd6517694f7cf829d097363ccabd55f4e4ca4 Mon Sep 17 00:00:00 2001 From: bigdigital <4833779+bigdigital@users.noreply.github.com> Date: Sat, 28 Jan 2023 21:18:55 +0200 Subject: [PATCH 4/5] add external status line in extra key as string + timeStamp --- .../Services/broadcastservice/BroadcastService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java index 36c9b95534..7f3bfac4b9 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/Services/broadcastservice/BroadcastService.java @@ -48,6 +48,10 @@ import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS; +// External status line from AAPS added +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLine; +import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLineTime; + /** * Broadcast API which provides common data like, bg values, graph info, statistic info. * Also it can handle different alarms, save HR data, steps and treatments. @@ -570,10 +574,16 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putParcelable("graph.predictedBg", new GraphLine(treatments[5])); // predictive bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ; + } bundle.putString("predict.IOB", predictedIOB); bundle.putString("predict.BWP", predictedBWP); + + // External status line from AAPS added + bundle.putString("external.statusLine", getLastStatusLine()); + bundle.putLong("external.timeStamp", getLastStatusLineTime()); + } return bundle; } From bb5261052fa9e166bc23bc22d566c79a23bc8756 Mon Sep 17 00:00:00 2001 From: bigdigital <4833779+bigdigital@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:54:57 +0200 Subject: [PATCH 5/5] use keystore to achieve predicted iob and bwp --- .../broadcastservice/BroadcastService.java | 49 +++++-------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java index f0641fa5f3..2ba4d6ead5 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/broadcastservice/BroadcastService.java @@ -12,8 +12,6 @@ import android.os.Parcelable; import android.os.PowerManager; import android.preference.PreferenceManager; -import android.support.v4.content.LocalBroadcastManager; -import android.util.Log; import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.Models.Accuracy; @@ -31,10 +29,11 @@ import com.eveningoutpost.dexdrip.UtilityModels.AlertPlayer; import com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder; import com.eveningoutpost.dexdrip.UtilityModels.Constants; -import com.eveningoutpost.dexdrip.UtilityModels.Intents; import com.eveningoutpost.dexdrip.UtilityModels.Pref; import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus; import com.eveningoutpost.dexdrip.stats.StatsResult; +import com.eveningoutpost.dexdrip.store.FastStore; +import com.eveningoutpost.dexdrip.store.KeyStore; import com.eveningoutpost.dexdrip.utils.PowerStateReceiver; import com.eveningoutpost.dexdrip.services.broadcastservice.models.BroadcastModel; import com.eveningoutpost.dexdrip.services.broadcastservice.models.GraphLine; @@ -83,10 +82,7 @@ public class BroadcastService extends Service { protected String TAG = this.getClass().getSimpleName(); protected Map broadcastEntities; - private BroadcastReceiver statusReceiver; - - private String predictedBWP; - private String predictedIOB; + protected KeyStore keyStore = FastStore.getInstance(); /** * The receiver listening {@link ACTION_WATCH_COMMUNICATION_RECEIVER} action. @@ -239,24 +235,6 @@ public void onCreate() { JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_START); - statusReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - final String bwp = intent.getStringExtra("bwp"); - if (bwp != null) { - predictedBWP = bwp; - } else { - final String iob = intent.getStringExtra("iob"); - if (iob != null) { - predictedIOB = iob; - } - } - } - }; - - LocalBroadcastManager.getInstance(this).registerReceiver(statusReceiver, - new IntentFilter(Intents.HOME_STATUS_ACTION)); - super.onCreate(); } @@ -265,12 +243,6 @@ public void onDestroy() { UserError.Log.e(TAG, "killing service"); broadcastEntities.clear(); unregisterReceiver(broadcastReceiver); - - try { - LocalBroadcastManager.getInstance(this).unregisterReceiver(statusReceiver); - } catch (Exception e) { - Log.e(TAG, "Exception unregistering broadcast receiver: " + e); - } super.onDestroy(); } @@ -537,9 +509,6 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putLong("treatment.timeStamp", treatment.timestamp); } - predictedIOB = ""; - predictedBWP = ""; - if (settings.isDisplayGraph()) { long graphStartOffset = settings.getGraphStart(); long graphEndOffset = settings.getGraphEnd(); @@ -574,11 +543,19 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) { bundle.putParcelable("graph.predictedBg", new GraphLine(treatments[5])); // predictive bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ; + } + String last_iob = keyStore.getS("last_iob"); + if ( last_iob != null){ + bundle.putString("predict.IOB", last_iob); + bundle.putLong("predict.IOB.timeStamp", keyStore.getL("last_iob_timestamp")); } - bundle.putString("predict.IOB", predictedIOB); - bundle.putString("predict.BWP", predictedBWP); + String last_bwp = keyStore.getS("last_bwp"); + if ( last_bwp != null){ + bundle.putString("predict.BWP", last_bwp); + bundle.putLong("predict.BWP.timeStamp", keyStore.getL("last_bwp_timestamp")); + } // External status line from AAPS added bundle.putString("external.statusLine", getLastStatusLine());