diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 8562e4318b..f01c90423e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -1264,14 +1264,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, treatmentButton.setVisibility(View.GONE); } } - if (wizardButton != null) { + if (pump.isInitialized() && !pump.isSuspended() && wizardButton != null) { if (SP.getBoolean(R.string.key_show_wizard_button, true)) { wizardButton.setVisibility(View.VISIBLE); } else { wizardButton.setVisibility(View.GONE); } } - if (insulinButton != null) { + if (pump.isInitialized() && !pump.isSuspended() && insulinButton != null) { if (SP.getBoolean(R.string.key_show_insulin_button, true)) { insulinButton.setVisibility(View.VISIBLE); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 1b2d7c2dfe..14c21cf576 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -145,7 +145,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { @Override public boolean isInitialized() { DanaRPump pump = DanaRPump.getInstance(); - return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0; + return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0 && pump.isPasswordOK(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index b982dad78c..3a6b3b5786 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -249,4 +249,10 @@ public class DanaRPump { return record; } + public boolean isPasswordOK() { + if (password != -1 && password != SP.getInt(R.string.key_danar_password, -1)) { + return false; + } + return true; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java index 188e12ffa8..8fc7cf032c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java @@ -3,8 +3,13 @@ package info.nightscout.androidaps.plugins.PumpDanaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; /** @@ -36,6 +41,13 @@ public class MsgInitConnStatusOption extends MessageBase { log.debug("Pump password: " + DanaRPump.getInstance().password); } + if (!DanaRPump.getInstance().isPasswordOK()) { + Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } else { + MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); + } + // This is last message of initial sequence ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java index 88745f66b5..f45f222861 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java @@ -67,8 +67,6 @@ public abstract class AbstractDanaRExecutionService extends Service { protected final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); - protected long lastWrongPumpPassword = 0; - protected long lastApproachingDailyLimit = 0; @@ -239,6 +237,4 @@ public abstract class AbstractDanaRExecutionService extends Service { result.comment = "OK"; return result; } - - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index a2b15d8f2f..1e13250db3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -98,15 +98,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { } public void connect() { - if (mDanaRPump.password != -1 && mDanaRPump.password != SP.getInt(R.string.key_danar_password, -1)) { - if (System.currentTimeMillis() > lastWrongPumpPassword + 30 * 1000) { - Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); - notification.soundId = R.raw.error; - lastWrongPumpPassword = System.currentTimeMillis(); - } - return; - } - if (mConnectionInProgress) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 35578d577b..1ff5fb472c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -149,7 +149,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { @Override public boolean isInitialized() { DanaRPump pump = DanaRPump.getInstance(); - return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled; + return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled && pump.isPasswordOK(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java index 46222938d7..32253b0007 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusBasic_k.java @@ -46,5 +46,12 @@ public class MsgInitConnStatusBasic_k extends MessageBase { } else { MainApp.bus().post(new EventDismissNotification(Notification.EASYMODE_ENABLED)); } + + if (!DanaRPump.getInstance().isPasswordOK()) { + Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); + MainApp.bus().post(new EventNewNotification(notification)); + } else { + MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index 59eab2d384..8adc954aa4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -93,7 +93,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { MainApp.instance().getApplicationContext().unregisterReceiver(receiver); stopSelf(); - } + } @Subscribe public void onStatusEvent(final EventPreferenceChange pch) { @@ -102,15 +102,6 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { } public void connect() { - if (mDanaRPump.password != -1 && mDanaRPump.password != SP.getInt(R.string.key_danar_password, -1)) { - if (System.currentTimeMillis() > lastWrongPumpPassword + 30 * 1000) { - Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); - notification.soundId = R.raw.error; - lastWrongPumpPassword = System.currentTimeMillis(); - } - return; - } - if (mConnectionInProgress) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 3c9077e76d..179e85293f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -112,7 +112,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { @Override public boolean isInitialized() { - return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0; + return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0 && DanaRPump.getInstance().isPasswordOK(); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 609783bec5..59f0ba9330 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -112,7 +112,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { MainApp.instance().getApplicationContext().unregisterReceiver(receiver); stopSelf(); - } + } @Subscribe public void onStatusEvent(final EventPreferenceChange pch) { @@ -121,15 +121,6 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public void connect() { - if (mDanaRPump.password != -1 && mDanaRPump.password != SP.getInt(R.string.key_danar_password, -1)) { - if (System.currentTimeMillis() > lastWrongPumpPassword + 30 * 1000) { - Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); - notification.soundId = R.raw.error; - lastWrongPumpPassword = System.currentTimeMillis(); - } - return; - } - if (mConnectionInProgress) return;