From f7c6f601316b7f38fdfb2d451a101afe7fb7e695 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 7 Mar 2019 11:32:09 +0100 Subject: [PATCH] Low storage notification --- .../info/nightscout/androidaps/Constants.java | 3 +++ .../storage/StorageConstraintPlugin.java | 15 ++++++++++++--- .../overview/notifications/Notification.java | 1 + app/src/main/res/values/strings.xml | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 183975b984..2ecabfe965 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -68,4 +68,7 @@ public class Constants { //SMS Communicator public static final long SMS_CONFIRM_TIMEOUT = T.mins(5).msecs(); + //Storage [MB] + public static final long MINIMUM_FREE_SPACE = 200; + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java index 91f92f6c2d..197fd5c17a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import java.io.File; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; @@ -16,6 +17,9 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; /** * Created by Rumen on 06.03.2019. @@ -47,9 +51,14 @@ public class StorageConstraintPlugin extends PluginBase implements ConstraintsIn @Override public Constraint isClosedLoopAllowed(Constraint value) { long diskfree = getAvailableInternalMemorySize(); - log.debug("Internal storage free (Mb):"+diskfree); - if (diskfree < 200) { - value.set(false, MainApp.gs(R.string.diskfull), this); + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Internal storage free (Mb):" + diskfree); + if (diskfree < Constants.MINIMUM_FREE_SPACE) { + value.set(false, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this); + Notification notification = new Notification(Notification.DISKFULL, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL); + MainApp.bus().post(new EventNewNotification(notification)); + } else { + MainApp.bus().post(new EventDismissNotification(Notification.DISKFULL)); } return value; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java index 5477963240..3b6bcf615d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java @@ -73,6 +73,7 @@ public class Notification { public static final int INSIGHT_TIMEOUT_DURING_HANDSHAKE = 48; public static final int DST_LOOP_DISABLED = 49; public static final int DST_IN_24H = 50; + public static final int DISKFULL = 51; public int id; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 032052ad1c..be0e0e2c5d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1313,7 +1313,7 @@ Dayligh Saving time change in 24h or less Dayligh Saving time change in less than 3 hours - Closed loop diabled internal storage constraint - Free at least 200Mb from internal storage! Loop disabled! + Free at least %1$d MB from internal storage! Loop disabled! %1$d day %1$d days