diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/activities/SmsCommunicatorOtpActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/activities/SmsCommunicatorOtpActivity.kt
index 12e4679d38..e1cdce7d17 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/activities/SmsCommunicatorOtpActivity.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/activities/SmsCommunicatorOtpActivity.kt
@@ -1,5 +1,8 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator.activities
+import android.content.ClipData
+import android.content.ClipboardManager
+import android.content.Context
import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle
@@ -16,8 +19,8 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicato
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult
import info.nightscout.androidaps.utils.FabricPrivacy
-import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.ToastUtils
+import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper
import kotlinx.android.synthetic.main.activity_smscommunicator_otp.*
import net.glxn.qrgen.android.QRCode
@@ -66,9 +69,23 @@ class SmsCommunicatorOtpActivity : NoSplashAppCompatActivity() {
Runnable {
otp.ensureKey(true)
updateGui()
- ToastUtils.showToastInUiThread(this, R.string.smscommunicator_otp_reset_successful)
+ ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_reset_successful))
})
}
+
+ smscommunicator_otp_provisioning.setOnLongClickListener {
+ OKDialog.showConfirmation(this,
+ resourceHelper.gs(R.string.smscommunicator_otp_export_title),
+ resourceHelper.gs(R.string.smscommunicator_otp_export_prompt),
+ Runnable {
+ val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
+ val clip = ClipData.newPlainText("OTP Secret", otp.provisioningSecret())
+ clipboard.primaryClip = clip
+ ToastUtils.Long.infoToast(this, resourceHelper.gs(R.string.smscommunicator_otp_export_successful))
+ })
+
+ true
+ }
}
@Synchronized
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 3610fb37b4..75b913c302 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
@@ -121,4 +121,10 @@ class OneTimePassword @Inject constructor(
fun provisioningURI(): String? =
key?.let { "otpauth://totp/AndroidAPS:" + URLEncoder.encode(name(), "utf-8").replace("+", "%20") + "?secret=" + BaseEncoding.base32().encode(it.encoded).replace("=", "") + "&issuer=AndroidAPS" }
+ /**
+ * Return secret used to provision Authenticator apps, in Base32 format
+ */
+ fun provisioningSecret(): String? =
+ key?.let { BaseEncoding.base32().encode(it.encoded).replace("=", "") }
+
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 891c266dd0..e9dd459b02 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1376,6 +1376,10 @@
Are you sure to reset Authenticator key? It will render all currently configured Authenticators invalid, and you will need to set them up again.
New Authenticator Key was generated! Please use updated QRCode to provision authenticators.
+ Exporting OTP secret
+ Are you sure you want to copy OTP secret to clipboard?\n\nYou may only need that if your authenticator app have issues scanning QRCode, you want to enter it manually or you want to configure hardware OTP token using dedicated app.
+ OTP secret (in Base32 format) exported and copied into clipboard. Paste it into authenticator or hardware OTP burner!
+
1. Install Authenticator
2. Scan code to setup AndroidAPS OTP codes
3. Test One-Time-Password