summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-03-12 13:04:32 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-03-12 13:04:32 +0530
commit5082df2f934cf4728cf43ae5dd5a1749de0ba534 (patch)
tree6e57d76dfd7169e3184f5d130c59e03e0d071c78 /app/src/main/java
parent0d7d6eae79dc00500e0988d23094ddaa0d407e07 (diff)
fix: clear passphrase cache when disabling
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt23
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt8
2 files changed, 29 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
index e2b7e5a8..bb045799 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
@@ -6,18 +6,25 @@
package app.passwordstore.ui.settings
import androidx.fragment.app.FragmentActivity
+import androidx.lifecycle.lifecycleScope
import app.passwordstore.R
+import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.ui.pgp.PGPKeyListActivity
import app.passwordstore.util.auth.BiometricAuthenticator
import app.passwordstore.util.extensions.launchActivity
import app.passwordstore.util.features.Feature
import app.passwordstore.util.settings.PreferenceKeys
import de.Maxr1998.modernpreferences.PreferenceScreen
+import de.Maxr1998.modernpreferences.helpers.onCheckedChange
import de.Maxr1998.modernpreferences.helpers.onClick
import de.Maxr1998.modernpreferences.helpers.pref
import de.Maxr1998.modernpreferences.helpers.switch
+import kotlinx.coroutines.launch
-class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
+class PGPSettings(
+ private val activity: FragmentActivity,
+ private val passphraseCache: PGPPassphraseCache,
+) : SettingsProvider {
override fun provideSettings(builder: PreferenceScreen.Builder) {
builder.apply {
@@ -38,6 +45,20 @@ class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
titleRes = R.string.pref_passphrase_cache_title
summaryRes = R.string.pref_passphrase_cache_summary
defaultValue = false
+ onCheckedChange { checked ->
+ if (!checked && BiometricAuthenticator.canAuthenticate(activity)) {
+ BiometricAuthenticator.authenticate(
+ activity,
+ R.string.pref_passphrase_cache_authenticate_clear,
+ ) {
+ if (it is BiometricAuthenticator.Result.Success)
+ activity.lifecycleScope.launch {
+ passphraseCache.clearAllCachedPassphrases(activity)
+ }
+ }
+ }
+ true
+ }
}
}
}
diff --git a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
index a2b078e0..aea6acee 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt
@@ -11,22 +11,27 @@ import androidx.activity.addCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.BundleCompat
import app.passwordstore.R
+import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.databinding.ActivityPreferenceRecyclerviewBinding
import app.passwordstore.util.extensions.viewBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import dagger.hilt.android.AndroidEntryPoint
import de.Maxr1998.modernpreferences.Preference
import de.Maxr1998.modernpreferences.PreferencesAdapter
import de.Maxr1998.modernpreferences.helpers.screen
import de.Maxr1998.modernpreferences.helpers.subScreen
+import javax.inject.Inject
+@AndroidEntryPoint
class SettingsActivity : AppCompatActivity() {
+ @Inject lateinit var passphraseCache: PGPPassphraseCache
private val miscSettings = MiscSettings(this)
private val autofillSettings = AutofillSettings(this)
private val passwordSettings = PasswordSettings(this)
private val repositorySettings = RepositorySettings(this)
private val generalSettings = GeneralSettings(this)
- private val pgpSettings = PGPSettings(this)
+ private lateinit var pgpSettings: PGPSettings
private val binding by viewBinding(ActivityPreferenceRecyclerviewBinding::inflate)
private val preferencesAdapter: PreferencesAdapter
@@ -36,6 +41,7 @@ class SettingsActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(binding.root)
Preference.Config.dialogBuilderFactory = { context -> MaterialAlertDialogBuilder(context) }
+ pgpSettings = PGPSettings(this, passphraseCache)
val screen =
screen(this) {
subScreen {