combov2: Validate length of entered pairing PIN

This commit is contained in:
Carlos Rafael Giani 2023-08-09 19:44:15 +02:00
parent 84f4303895
commit 7886dc7e14
2 changed files with 7 additions and 0 deletions

View file

@ -17,9 +17,11 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import info.nightscout.comboctl.base.BasicProgressStage import info.nightscout.comboctl.base.BasicProgressStage
import info.nightscout.comboctl.base.PAIRING_PIN_SIZE
import info.nightscout.comboctl.base.PairingPIN import info.nightscout.comboctl.base.PairingPIN
import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity import info.nightscout.core.ui.activities.TranslatedDaggerAppCompatActivity
import info.nightscout.core.ui.dialogs.OKDialog 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.ComboV2Plugin
import info.nightscout.pump.combov2.R import info.nightscout.pump.combov2.R
import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding import info.nightscout.pump.combov2.databinding.Combov2PairingActivityBinding
@ -334,6 +336,10 @@ class ComboV2PairingActivity : TranslatedDaggerAppCompatActivity() {
// We need to skip whitespaces since the // We need to skip whitespaces since the
// TextWatcher above inserts some. // TextWatcher above inserts some.
val pinString = binding.combov2PinEntryEdit.text.replace(whitespaceRemovalRegex, "") 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 { runBlocking {
val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray()) val PIN = PairingPIN(pinString.map { it - '0' }.toIntArray())
combov2Plugin.providePairingPIN(PIN) combov2Plugin.providePairingPIN(PIN)

View file

@ -53,6 +53,7 @@ buttons at the same time to cancel pairing)\n
<string name="combov2_pairing_combo_scan_timeout_reached">Combo scan timeout reached</string> <string name="combov2_pairing_combo_scan_timeout_reached">Combo scan timeout reached</string>
<string name="combov2_pairing_failed_due_to_error">Pairing failed due to error: %1$s</string> <string name="combov2_pairing_failed_due_to_error">Pairing failed due to error: %1$s</string>
<string name="combov2_pairing_aborted_unknown_reasons">Pairing aborted for unknown reasons</string> <string name="combov2_pairing_aborted_unknown_reasons">Pairing aborted for unknown reasons</string>
<string name="combov2_pairing_invalid_pin_length">"Invalid pairing PIN length: need %1$d digits, got %2$d"</string>
<string name="combov2_scanning_for_pump">Scanning for pump</string> <string name="combov2_scanning_for_pump">Scanning for pump</string>
<string name="combov2_establishing_bt_connection">Establishing Bluetooth connection (attempt no. %1$d)</string> <string name="combov2_establishing_bt_connection">Establishing Bluetooth connection (attempt no. %1$d)</string>
<string name="combov2_pairing_performing_handshake">Performing handshake with pump</string> <string name="combov2_pairing_performing_handshake">Performing handshake with pump</string>