From f1770c093b70412425fcd6ee78e956373cfd9ebb Mon Sep 17 00:00:00 2001 From: Dominik Dzienia Date: Fri, 3 Apr 2020 00:45:37 +0200 Subject: [PATCH] Introduced Patient name, refactored SMS OTP and Prefs Export to use it --- .../plugins/general/maintenance/ImportExportPrefs.kt | 10 +++++----- .../general/smsCommunicator/otp/OneTimePassword.kt | 6 +++--- .../nightscout/androidaps/setupwizard/SWDefinition.kt | 11 +++++++++++ app/src/main/res/values/strings.xml | 10 +++++----- app/src/main/res/xml/pref_general.xml | 8 ++++++++ app/src/main/res/xml/pref_smscommunicator.xml | 8 -------- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index 356fc918e1..785f2acd1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -125,13 +125,13 @@ class ImportExportPrefs @Inject constructor( val n5 = Settings.Secure.getString(context.contentResolver, "lock_screen_owner_info") val n6 = Settings.Global.getString(context.contentResolver, "device_name") - // name we use for SMS OTP token in communicator - val otpName = otp.name().trim() - val defaultOtpName = resourceHelper.gs(R.string.smscommunicator_default_user_display_name) + // name provided (hopefully) by user + val patientName = sp.getString(R.string.key_patient_name, "") + val defaultPatientName = resourceHelper.gs(R.string.patient_name_default) // name we detect from OS - val systemName = n1 ?: n2 ?: n3 ?: n4 ?: n5 ?: n6 ?: defaultOtpName - val name = if (otpName.length > 0 && otpName != defaultOtpName) otpName else systemName + val systemName = n1 ?: n2 ?: n3 ?: n4 ?: n5 ?: n6 ?: defaultPatientName + val name = if (patientName.isNotEmpty() && patientName != defaultPatientName) patientName else systemName return name } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt index 2f49ae25ef..3610fb37b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt @@ -48,8 +48,8 @@ class OneTimePassword @Inject constructor( * Name of master device (target of OTP) */ fun name(): String { - val defaultUserName = resourceHelper.gs(R.string.smscommunicator_default_user_display_name) - var userName = sp.getString(R.string.key_smscommunicator_otp_name, defaultUserName).replace(":", "").trim() + val defaultUserName = resourceHelper.gs(R.string.patient_name_default) + var userName = sp.getString(R.string.key_patient_name, defaultUserName).replace(":", "").trim() if (userName.isEmpty()) userName = defaultUserName return userName @@ -119,6 +119,6 @@ class OneTimePassword @Inject constructor( * Return URI used to provision Authenticator apps */ fun provisioningURI(): String? = - key?.let { "otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS" } + key?.let { "otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8").replace("+", "%20") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS" } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 3912b48433..4af38741b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -198,6 +198,14 @@ class SWDefinition @Inject constructor( .add(SWBreak(injector)) .validator(SWValidator { nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth }) .visibility(SWValidator { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) }) + private val screenPatientName = SWScreen(injector, R.string.patient_name) + .skippable(true) + .add(SWInfotext(injector) + .label(R.string.patient_name_summary)) + .add(SWEditString(injector) + .validator(SWTextValidator { text: String -> text.length > 0 }) + .preferenceId(R.string.key_patient_name) + .updateDelay(5)) private val screenAge = SWScreen(injector, R.string.patientage) .skippable(false) .add(SWBreak(injector)) @@ -389,6 +397,7 @@ class SWDefinition @Inject constructor( .add(screenUnits) .add(displaySettings) .add(screenNsClient) + .add(screenPatientName) .add(screenAge) .add(screenInsulin) .add(screenBgSource) @@ -415,6 +424,7 @@ class SWDefinition @Inject constructor( .add(screenUnits) .add(displaySettings) .add(screenNsClient) + .add(screenPatientName) .add(screenAge) .add(screenInsulin) .add(screenBgSource) @@ -437,6 +447,7 @@ class SWDefinition @Inject constructor( .add(displaySettings) .add(screenNsClient) .add(screenBgSource) + .add(screenPatientName) .add(screenAge) .add(screenInsulin) .add(screenSensitivity) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f1ebc84bc5..041004a25a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -276,7 +276,7 @@ Created at AAPS Version Build Variant - Exporting device name + Exporting device patient name Exporting device model File encryption @@ -611,6 +611,10 @@ adult resistantadult Please select patient age to setup safety limits + Patient name + Please provide patient name or nickname to differentiate among multiple setups + User + patient_name I_understand Glimp %1$s needs battery optimalization whitelisting for proper performance @@ -1755,19 +1759,15 @@ smscommunicator_otp_enabled - smscommunicator_otp_name smscommunicator_otp_password smscommunicator_otp_secret - User from Authenticator app for: %1$s Enable Authenticator Authenticate commands using One Time Passwords generated by Google Authenticator or similar 2FA apps. Additional PIN at token end Additional digits that should be memorised and glued at end of each generated One Time Password - User name for Authenticator - User name displayed along with generated OTP on Authenticator App Authenticator setup diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index b5f7074c7e..3ee920cc01 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -20,6 +20,14 @@ android:key="@string/key_language" android:title="@string/language" /> + + + - - - \ No newline at end of file