summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-05-26 01:54:15 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-05-26 02:08:09 +0530
commit173e802a369313952bcaa1ef65686a40c99659a3 (patch)
treeaa0f2ca50e6ad2468d0b79d4318f76f1d01dcc22 /app/src/main/java
parent3a6333481581fce2af153a5ffb56eddb9ee0f668 (diff)
feat: add option to auto clear passphrase cache
Fixes #3053
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/Application.kt35
-rw-r--r--app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt6
-rw-r--r--app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt1
3 files changed, 41 insertions, 1 deletions
diff --git a/app/src/main/java/app/passwordstore/Application.kt b/app/src/main/java/app/passwordstore/Application.kt
index b2bfa2cc..414ef54e 100644
--- a/app/src/main/java/app/passwordstore/Application.kt
+++ b/app/src/main/java/app/passwordstore/Application.kt
@@ -4,12 +4,18 @@
*/
package app.passwordstore
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
import android.content.SharedPreferences
import android.os.Build
import android.os.StrictMode
import androidx.appcompat.app.AppCompatDelegate.*
+import app.passwordstore.data.crypto.PGPPassphraseCache
import app.passwordstore.injection.context.FilesDirPath
import app.passwordstore.injection.prefs.SettingsPreferences
+import app.passwordstore.util.coroutines.DispatcherProvider
import app.passwordstore.util.extensions.getString
import app.passwordstore.util.features.Feature
import app.passwordstore.util.features.Features
@@ -24,6 +30,10 @@ import io.sentry.Sentry
import io.sentry.protocol.User
import java.util.concurrent.Executors
import javax.inject.Inject
+import kotlinx.coroutines.DelicateCoroutinesApi
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import logcat.AndroidLogcatLogger
import logcat.LogPriority.DEBUG
import logcat.LogPriority.VERBOSE
@@ -36,8 +46,10 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
@Inject @SettingsPreferences lateinit var prefs: SharedPreferences
@Inject @FilesDirPath lateinit var filesDirPath: String
- @Inject lateinit var proxyUtils: ProxyUtils
+ @Inject lateinit var dispatcherProvider: DispatcherProvider
+ @Inject lateinit var passphraseCache: PGPPassphraseCache
@Inject lateinit var gitSettings: GitSettings
+ @Inject lateinit var proxyUtils: ProxyUtils
@Inject lateinit var features: Features
override fun onCreate() {
@@ -64,6 +76,27 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
}
scope.user = user
}
+ setupPassphraseCacheClearAction()
+ }
+
+ @OptIn(DelicateCoroutinesApi::class)
+ private fun setupPassphraseCacheClearAction() {
+ if (prefs.getBoolean(PreferenceKeys.CLEAR_PASSPHRASE_CACHE, false)) {
+ val screenOffReceiver: BroadcastReceiver =
+ object : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ if (intent.action == Intent.ACTION_SCREEN_OFF) {
+ GlobalScope.launch {
+ withContext(dispatcherProvider.main()) {
+ passphraseCache.clearAllCachedPassphrases(context)
+ }
+ }
+ }
+ }
+ }
+ val filter = IntentFilter(Intent.ACTION_SCREEN_OFF)
+ registerReceiver(screenOffReceiver, filter)
+ }
}
override fun onTerminate() {
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 bb045799..09f81102 100644
--- a/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
+++ b/app/src/main/java/app/passwordstore/ui/settings/PGPSettings.kt
@@ -60,6 +60,12 @@ class PGPSettings(
true
}
}
+ switch(PreferenceKeys.CLEAR_PASSPHRASE_CACHE) {
+ dependency = Feature.EnablePGPPassphraseCache.configKey
+ titleRes = R.string.pref_passphrase_cache_auto_clear_title
+ summaryRes = R.string.pref_passphrase_cache_auto_clear_summary
+ defaultValue = false
+ }
}
}
}
diff --git a/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt b/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
index 5e55582c..d67a4bef 100644
--- a/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
+++ b/app/src/main/java/app/passwordstore/util/settings/PreferenceKeys.kt
@@ -91,4 +91,5 @@ object PreferenceKeys {
const val DICEWARE_LENGTH = "diceware_length"
const val DISABLE_SYNC_ACTION = "disable_sync_action"
const val ASCII_ARMOR = "pgpainless_ascii_armor"
+ const val CLEAR_PASSPHRASE_CACHE = "pgpainless_auto_clear_passphrase_cache_screen_off"
}