From 244fd92f8b59aeca608253e87bb7a7076ca4a960 Mon Sep 17 00:00:00 2001 From: Aditya Wasan Date: Wed, 7 Sep 2022 17:49:08 -0400 Subject: Use `GENERAL_SHOW_TIME` for decryption screen timeout (#2107) * feat(app): use `GENERAL_SHOW_TIME` for decryption screen as well Signed-off-by: Aditya Wasan * feat: update timeout to 60 seconds Signed-off-by: Aditya Wasan * refactor(app): use constant instead of using a magic number Signed-off-by: Aditya Wasan * Add changelog entry Signed-off-by: Aditya Wasan Co-authored-by: Harsh Shandilya --- .../java/app/passwordstore/ui/crypto/BasePgpActivity.kt | 5 ++++- .../java/app/passwordstore/ui/crypto/DecryptActivity.kt | 15 +++++++++++---- .../java/app/passwordstore/util/settings/Constants.kt | 5 +++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/app/passwordstore/util/settings/Constants.kt (limited to 'app/src/main/java') diff --git a/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt index c769e334..f2778e2d 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/BasePgpActivity.kt @@ -22,6 +22,7 @@ import app.passwordstore.util.extensions.getString import app.passwordstore.util.extensions.snackbar import app.passwordstore.util.extensions.unsafeLazy import app.passwordstore.util.services.ClipboardService +import app.passwordstore.util.settings.Constants import app.passwordstore.util.settings.PreferenceKeys import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.AndroidEntryPoint @@ -87,7 +88,9 @@ open class BasePgpActivity : AppCompatActivity() { fun copyPasswordToClipboard(password: String?) { copyTextToClipboard(password) - val clearAfter = settings.getString(PreferenceKeys.GENERAL_SHOW_TIME)?.toIntOrNull() ?: 45 + val clearAfter = + settings.getString(PreferenceKeys.GENERAL_SHOW_TIME)?.toIntOrNull() + ?: Constants.DEFAULT_DECRYPTION_TIMEOUT if (clearAfter != 0) { val service = diff --git a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt index fa37f501..dfe9f8bc 100644 --- a/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/crypto/DecryptActivity.kt @@ -16,9 +16,11 @@ import app.passwordstore.data.passfile.PasswordEntry import app.passwordstore.data.password.FieldItem import app.passwordstore.databinding.DecryptLayoutBinding import app.passwordstore.ui.adapters.FieldItemAdapter +import app.passwordstore.util.extensions.getString import app.passwordstore.util.extensions.isErr import app.passwordstore.util.extensions.unsafeLazy import app.passwordstore.util.extensions.viewBinding +import app.passwordstore.util.settings.Constants import app.passwordstore.util.settings.PreferenceKeys import com.github.michaelbull.result.runCatching import com.github.michaelbull.result.unwrapError @@ -91,13 +93,18 @@ class DecryptActivity : BasePgpActivity() { } /** - * Automatically finishes the activity 60 seconds after decryption succeeded to prevent - * information leaks from stale activities. + * Automatically finishes the activity after [PreferenceKeys.GENERAL_SHOW_TIME] seconds decryption + * succeeded to prevent information leaks from stale activities. */ private fun startAutoDismissTimer() { lifecycleScope.launch { - delay(60.seconds) - finish() + val timeout = + settings.getString(PreferenceKeys.GENERAL_SHOW_TIME)?.toIntOrNull() + ?: Constants.DEFAULT_DECRYPTION_TIMEOUT + if (timeout != 0) { + delay(timeout.seconds) + finish() + } } } diff --git a/app/src/main/java/app/passwordstore/util/settings/Constants.kt b/app/src/main/java/app/passwordstore/util/settings/Constants.kt new file mode 100644 index 00000000..d843500f --- /dev/null +++ b/app/src/main/java/app/passwordstore/util/settings/Constants.kt @@ -0,0 +1,5 @@ +package app.passwordstore.util.settings + +object Constants { + const val DEFAULT_DECRYPTION_TIMEOUT = 60 +} -- cgit v1.2.3