4
4
*/
5
5
package app.passwordstore
6
6
7
+ import android.content.BroadcastReceiver
8
+ import android.content.Context
9
+ import android.content.Intent
10
+ import android.content.IntentFilter
7
11
import android.content.SharedPreferences
8
12
import android.os.Build
9
13
import android.os.StrictMode
10
14
import androidx.appcompat.app.AppCompatDelegate.*
15
+ import app.passwordstore.data.crypto.PGPPassphraseCache
11
16
import app.passwordstore.injection.context.FilesDirPath
12
17
import app.passwordstore.injection.prefs.SettingsPreferences
18
+ import app.passwordstore.util.coroutines.DispatcherProvider
13
19
import app.passwordstore.util.extensions.getString
14
20
import app.passwordstore.util.features.Feature
15
21
import app.passwordstore.util.features.Features
@@ -24,6 +30,10 @@ import io.sentry.Sentry
24
30
import io.sentry.protocol.User
25
31
import java.util.concurrent.Executors
26
32
import javax.inject.Inject
33
+ import kotlinx.coroutines.DelicateCoroutinesApi
34
+ import kotlinx.coroutines.GlobalScope
35
+ import kotlinx.coroutines.launch
36
+ import kotlinx.coroutines.withContext
27
37
import logcat.AndroidLogcatLogger
28
38
import logcat.LogPriority.DEBUG
29
39
import logcat.LogPriority.VERBOSE
@@ -36,8 +46,10 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
36
46
37
47
@Inject @SettingsPreferences lateinit var prefs: SharedPreferences
38
48
@Inject @FilesDirPath lateinit var filesDirPath: String
39
- @Inject lateinit var proxyUtils: ProxyUtils
49
+ @Inject lateinit var dispatcherProvider: DispatcherProvider
50
+ @Inject lateinit var passphraseCache: PGPPassphraseCache
40
51
@Inject lateinit var gitSettings: GitSettings
52
+ @Inject lateinit var proxyUtils: ProxyUtils
41
53
@Inject lateinit var features: Features
42
54
43
55
override fun onCreate () {
@@ -64,6 +76,27 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
64
76
}
65
77
scope.user = user
66
78
}
79
+ setupPassphraseCacheClearAction()
80
+ }
81
+
82
+ @OptIn(DelicateCoroutinesApi ::class )
83
+ private fun setupPassphraseCacheClearAction () {
84
+ if (prefs.getBoolean(PreferenceKeys .CLEAR_PASSPHRASE_CACHE , false )) {
85
+ val screenOffReceiver: BroadcastReceiver =
86
+ object : BroadcastReceiver () {
87
+ override fun onReceive (context : Context , intent : Intent ) {
88
+ if (intent.action == Intent .ACTION_SCREEN_OFF ) {
89
+ GlobalScope .launch {
90
+ withContext(dispatcherProvider.main()) {
91
+ passphraseCache.clearAllCachedPassphrases(context)
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ val filter = IntentFilter (Intent .ACTION_SCREEN_OFF )
98
+ registerReceiver(screenOffReceiver, filter)
99
+ }
67
100
}
68
101
69
102
override fun onTerminate () {
0 commit comments