From 7886dc7e14bb37a804f6c55cd4f10996f5e1313b Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Wed, 9 Aug 2023 19:44:15 +0200 Subject: [PATCH] combov2: Validate length of entered pairing PIN --- .../pump/combov2/activities/ComboV2PairingActivity.kt | 6 ++++++ pump/combov2/src/main/res/values/strings.xml | 1 + 2 files changed, 7 insertions(+) diff --git a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt index 8ecbda0c7a..48e7158d1e 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/activities/ComboV2PairingActivity.kt @@ -17,9 +17,11 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import info.nightscout.comboctl.base.BasicProgressStage +import info.nightscout.comboctl.base.PAIRING_PIN_SIZE import info.nightscout.comboctl.base.PairingPIN import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity import info.nightscout.core.ui.dialogs.OKDialog +import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.pump.combov2.ComboV2Plugin import info.nightscout.pump.combov2.R import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding @@ -334,6 +336,10 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() { // We need to skip whitespaces since the // TextWatcher above inserts some. val pinString = binding.combov2PinEntryEdit.text.replace(whitespaceRemovalRegex, "") + if (pinString.length != PAIRING_PIN_SIZE) { + ToastUtils.showToastInUiThread(this, rh.gs(R.string.combov2_pairing_invalid_pin_length, PAIRING_PIN_SIZE, pinString.length)) + return@setOnClickListener + } runBlocking { val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray()) combov2Plugin.providePairingPIN(PIN) diff --git a/pump/combov2/src/main/res/values/strings.xml b/pump/combov2/src/main/res/values/strings.xml index 3051413bcd..9c4933a7f1 100644 --- a/pump/combov2/src/main/res/values/strings.xml +++ b/pump/combov2/src/main/res/values/strings.xml @@ -53,6 +53,7 @@ buttons at the same time to cancel pairing)\n Combo scan timeout reached Pairing failed due to error: %1$s Pairing aborted for unknown reasons + "Invalid pairing PIN length: need %1$d digits, got %2$d" Scanning for pump Establishing Bluetooth connection (attempt no. %1$d) Performing handshake with pump