mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 05:48:09 +00:00
fix: clear passphrase cache when disabling
This commit is contained in:
parent
0d7d6eae79
commit
5082df2f93
@ -6,18 +6,25 @@
|
|||||||
package app.passwordstore.ui.settings
|
package app.passwordstore.ui.settings
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import app.passwordstore.R
|
import app.passwordstore.R
|
||||||
|
import app.passwordstore.data.crypto.PGPPassphraseCache
|
||||||
import app.passwordstore.ui.pgp.PGPKeyListActivity
|
import app.passwordstore.ui.pgp.PGPKeyListActivity
|
||||||
import app.passwordstore.util.auth.BiometricAuthenticator
|
import app.passwordstore.util.auth.BiometricAuthenticator
|
||||||
import app.passwordstore.util.extensions.launchActivity
|
import app.passwordstore.util.extensions.launchActivity
|
||||||
import app.passwordstore.util.features.Feature
|
import app.passwordstore.util.features.Feature
|
||||||
import app.passwordstore.util.settings.PreferenceKeys
|
import app.passwordstore.util.settings.PreferenceKeys
|
||||||
import de.Maxr1998.modernpreferences.PreferenceScreen
|
import de.Maxr1998.modernpreferences.PreferenceScreen
|
||||||
|
import de.Maxr1998.modernpreferences.helpers.onCheckedChange
|
||||||
import de.Maxr1998.modernpreferences.helpers.onClick
|
import de.Maxr1998.modernpreferences.helpers.onClick
|
||||||
import de.Maxr1998.modernpreferences.helpers.pref
|
import de.Maxr1998.modernpreferences.helpers.pref
|
||||||
import de.Maxr1998.modernpreferences.helpers.switch
|
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) {
|
override fun provideSettings(builder: PreferenceScreen.Builder) {
|
||||||
builder.apply {
|
builder.apply {
|
||||||
@ -38,6 +45,20 @@ class PGPSettings(private val activity: FragmentActivity) : SettingsProvider {
|
|||||||
titleRes = R.string.pref_passphrase_cache_title
|
titleRes = R.string.pref_passphrase_cache_title
|
||||||
summaryRes = R.string.pref_passphrase_cache_summary
|
summaryRes = R.string.pref_passphrase_cache_summary
|
||||||
defaultValue = false
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,22 +11,27 @@ import androidx.activity.addCallback
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.os.BundleCompat
|
import androidx.core.os.BundleCompat
|
||||||
import app.passwordstore.R
|
import app.passwordstore.R
|
||||||
|
import app.passwordstore.data.crypto.PGPPassphraseCache
|
||||||
import app.passwordstore.databinding.ActivityPreferenceRecyclerviewBinding
|
import app.passwordstore.databinding.ActivityPreferenceRecyclerviewBinding
|
||||||
import app.passwordstore.util.extensions.viewBinding
|
import app.passwordstore.util.extensions.viewBinding
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import de.Maxr1998.modernpreferences.Preference
|
import de.Maxr1998.modernpreferences.Preference
|
||||||
import de.Maxr1998.modernpreferences.PreferencesAdapter
|
import de.Maxr1998.modernpreferences.PreferencesAdapter
|
||||||
import de.Maxr1998.modernpreferences.helpers.screen
|
import de.Maxr1998.modernpreferences.helpers.screen
|
||||||
import de.Maxr1998.modernpreferences.helpers.subScreen
|
import de.Maxr1998.modernpreferences.helpers.subScreen
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@Inject lateinit var passphraseCache: PGPPassphraseCache
|
||||||
private val miscSettings = MiscSettings(this)
|
private val miscSettings = MiscSettings(this)
|
||||||
private val autofillSettings = AutofillSettings(this)
|
private val autofillSettings = AutofillSettings(this)
|
||||||
private val passwordSettings = PasswordSettings(this)
|
private val passwordSettings = PasswordSettings(this)
|
||||||
private val repositorySettings = RepositorySettings(this)
|
private val repositorySettings = RepositorySettings(this)
|
||||||
private val generalSettings = GeneralSettings(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 binding by viewBinding(ActivityPreferenceRecyclerviewBinding::inflate)
|
||||||
private val preferencesAdapter: PreferencesAdapter
|
private val preferencesAdapter: PreferencesAdapter
|
||||||
@ -36,6 +41,7 @@ class SettingsActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
Preference.Config.dialogBuilderFactory = { context -> MaterialAlertDialogBuilder(context) }
|
Preference.Config.dialogBuilderFactory = { context -> MaterialAlertDialogBuilder(context) }
|
||||||
|
pgpSettings = PGPSettings(this, passphraseCache)
|
||||||
val screen =
|
val screen =
|
||||||
screen(this) {
|
screen(this) {
|
||||||
subScreen {
|
subScreen {
|
||||||
|
@ -137,6 +137,7 @@
|
|||||||
<string name="pref_pgp_ascii_armor_title">Encrypt in ASCII armor mode</string>
|
<string name="pref_pgp_ascii_armor_title">Encrypt in ASCII armor mode</string>
|
||||||
<string name="pref_passphrase_cache_title">Enable passphrase caching</string>
|
<string name="pref_passphrase_cache_title">Enable passphrase caching</string>
|
||||||
<string name="pref_passphrase_cache_summary">WARNING: this feature is functional but very experimental. Requires an active screen lock.</string>
|
<string name="pref_passphrase_cache_summary">WARNING: this feature is functional but very experimental. Requires an active screen lock.</string>
|
||||||
|
<string name="pref_passphrase_cache_authenticate_clear">Authenticate to clear cache</string>
|
||||||
|
|
||||||
<!-- PasswordGenerator fragment -->
|
<!-- PasswordGenerator fragment -->
|
||||||
<string name="pwgen_title">Generate Password</string>
|
<string name="pwgen_title">Generate Password</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user