Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 3ddd066

Browse files
authored
Resolve lock contention from lazy delegates (#1135)
1 parent 8a43160 commit 3ddd066

File tree

15 files changed

+27
-29
lines changed

15 files changed

+27
-29
lines changed

app/src/main/java/com/zeapo/pwdstore/ClipboardService.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.app.PendingIntent
1010
import android.app.Service
1111
import android.content.ClipData
1212
import android.content.Intent
13-
import android.content.SharedPreferences
1413
import android.os.Build
1514
import android.os.IBinder
1615
import androidx.core.app.NotificationCompat
@@ -32,7 +31,6 @@ import kotlinx.coroutines.withContext
3231
class ClipboardService : Service() {
3332

3433
private val scope = CoroutineScope(Job() + Dispatchers.Main)
35-
private val settings: SharedPreferences by lazy { sharedPrefs }
3634

3735
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
3836
if (intent != null) {
@@ -45,7 +43,7 @@ class ClipboardService : Service() {
4543
}
4644

4745
ACTION_START -> {
48-
val time = settings.getString(PreferenceKeys.GENERAL_SHOW_TIME)?.toIntOrNull() ?: 45
46+
val time = sharedPrefs.getString(PreferenceKeys.GENERAL_SHOW_TIME)?.toIntOrNull() ?: 45
4947

5048
if (time == 0) {
5149
stopSelf()
@@ -80,7 +78,7 @@ class ClipboardService : Service() {
8078
}
8179

8280
private fun clearClipboard() {
83-
val deepClear = settings.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, false)
81+
val deepClear = sharedPrefs.getBoolean(PreferenceKeys.CLEAR_CLIPBOARD_20X, false)
8482
val clipboard = clipboard
8583

8684
if (clipboard != null) {

app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel
139139

140140
private val root
141141
get() = PasswordRepository.getRepositoryDirectory()
142-
private val settings by lazy { application.sharedPrefs }
142+
private val settings by lazy(LazyThreadSafetyMode.NONE) { application.sharedPrefs }
143143
private val showHiddenContents
144144
get() = settings.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)
145145
private val defaultSearchMode

app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSaveActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AutofillSaveActivity : AppCompatActivity() {
8282
}
8383
}
8484

85-
private val formOrigin: FormOrigin? by lazy {
85+
private val formOrigin by lazy(LazyThreadSafetyMode.NONE) {
8686
val shouldMatchApp: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_APP)
8787
val shouldMatchWeb: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_WEB)
8888
if (shouldMatchApp != null && shouldMatchWeb == null) {

app/src/main/java/com/zeapo/pwdstore/crypto/BasePgpActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
4545
/**
4646
* Full path to the repository
4747
*/
48-
val repoPath: String by lazy { intent.getStringExtra("REPO_PATH") }
48+
val repoPath: String by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra("REPO_PATH") }
4949

5050
/**
5151
* Full path to the password file being worked on
5252
*/
53-
val fullPath: String by lazy { intent.getStringExtra("FILE_PATH") }
53+
val fullPath: String by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra("FILE_PATH") }
5454

5555
/**
5656
* Name of the password file
5757
*
5858
* Converts personal/auth.foo.org/[email protected] to john_doe.example.org
5959
*/
60-
val name: String by lazy { File(fullPath).nameWithoutExtension }
60+
val name: String by lazy(LazyThreadSafetyMode.NONE) { File(fullPath).nameWithoutExtension }
6161

6262
/**
6363
* Get the timestamp for when this file was last modified.
6464
*/
65-
val lastChangedString: CharSequence by lazy {
65+
val lastChangedString: CharSequence by lazy(LazyThreadSafetyMode.NONE) {
6666
getLastChangedString(
6767
intent.getLongExtra(
6868
"LAST_CHANGED_TIMESTAMP",
@@ -74,7 +74,7 @@ open class BasePgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBou
7474
/**
7575
* [SharedPreferences] instance used by subclasses to persist settings
7676
*/
77-
val settings: SharedPreferences by lazy { sharedPrefs }
77+
val settings: SharedPreferences by lazy(LazyThreadSafetyMode.NONE) { sharedPrefs }
7878

7979
/**
8080
* Handle to the [OpenPgpApi] instance that is used by subclasses to interface with OpenKeychain.

app/src/main/java/com/zeapo/pwdstore/crypto/DecryptActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DecryptActivity : BasePgpActivity(), OpenPgpServiceConnection.OnBound {
3939

4040
private val binding by viewBinding(DecryptLayoutBinding::inflate)
4141

42-
private val relativeParentPath by lazy { getParentPath(fullPath, repoPath) }
42+
private val relativeParentPath by lazy(LazyThreadSafetyMode.NONE) { getParentPath(fullPath, repoPath) }
4343
private var passwordEntry: PasswordEntry? = null
4444

4545
private val userInteractionRequiredResult = registerForActivityResult(StartIntentSenderForResult()) { result ->

app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
5656

5757
private val binding by viewBinding(PasswordCreationActivityBinding::inflate)
5858

59-
private val suggestedName by lazy { intent.getStringExtra(EXTRA_FILE_NAME) }
60-
private val suggestedPass by lazy { intent.getStringExtra(EXTRA_PASSWORD) }
61-
private val suggestedExtra by lazy { intent.getStringExtra(EXTRA_EXTRA_CONTENT) }
62-
private val shouldGeneratePassword by lazy { intent.getBooleanExtra(EXTRA_GENERATE_PASSWORD, false) }
63-
private val editing by lazy { intent.getBooleanExtra(EXTRA_EDITING, false) }
64-
private val oldFileName by lazy { intent.getStringExtra(EXTRA_FILE_NAME) }
59+
private val suggestedName by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra(EXTRA_FILE_NAME) }
60+
private val suggestedPass by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra(EXTRA_PASSWORD) }
61+
private val suggestedExtra by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra(EXTRA_EXTRA_CONTENT) }
62+
private val shouldGeneratePassword by lazy(LazyThreadSafetyMode.NONE) { intent.getBooleanExtra(EXTRA_GENERATE_PASSWORD, false) }
63+
private val editing by lazy(LazyThreadSafetyMode.NONE) { intent.getBooleanExtra(EXTRA_EDITING, false) }
64+
private val oldFileName by lazy(LazyThreadSafetyMode.NONE) { intent.getStringExtra(EXTRA_FILE_NAME) }
6565
private var oldCategory: String? = null
6666
private var copy: Boolean = false
6767
private var encryptionIntent: Intent = Intent()

app/src/main/java/com/zeapo/pwdstore/git/config/GitSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ object GitSettings {
5252

5353
private const val DEFAULT_BRANCH = "master"
5454

55-
private val settings by lazy { Application.instance.sharedPrefs }
56-
private val encryptedSettings by lazy { Application.instance.getEncryptedGitPrefs() }
55+
private val settings by lazy(LazyThreadSafetyMode.PUBLICATION) { Application.instance.sharedPrefs }
56+
private val encryptedSettings by lazy(LazyThreadSafetyMode.PUBLICATION) { Application.instance.getEncryptedGitPrefs() }
5757

5858
var authMode
5959
get() = AuthMode.fromString(settings.getString(PreferenceKeys.GIT_REMOTE_AUTH))

app/src/main/java/com/zeapo/pwdstore/git/log/GitLogModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GitLogModel {
4141
// This is because the commit graph is walked from HEAD to the last commit to obtain.
4242
// Additionally, tests with 1000 commits in the log have not produced a significant delay in the
4343
// user experience.
44-
private val cache: MutableList<GitCommit> by lazy {
44+
private val cache: MutableList<GitCommit> by lazy(LazyThreadSafetyMode.NONE) {
4545
commits().map {
4646
GitCommit(it.hash, it.shortMessage, it.authorIdent.name, it.time)
4747
}.toMutableList()

app/src/main/java/com/zeapo/pwdstore/git/sshj/SshKey.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private const val PROVIDER_ANDROID_KEY_STORE = "AndroidKeyStore"
5050
private const val KEYSTORE_ALIAS = "sshkey"
5151
private const val ANDROIDX_SECURITY_KEYSET_PREF_NAME = "androidx_sshkey_keyset_prefs"
5252

53-
private val androidKeystore: KeyStore by lazy {
53+
private val androidKeystore: KeyStore by lazy(LazyThreadSafetyMode.NONE) {
5454
KeyStore.getInstance(PROVIDER_ANDROID_KEY_STORE).apply { load(null) }
5555
}
5656

@@ -119,7 +119,7 @@ object SshKey {
119119
putString(PreferenceKeys.GIT_REMOTE_KEY_TYPE, value?.value)
120120
}
121121

122-
private val isStrongBoxSupported by lazy {
122+
private val isStrongBoxSupported by lazy(LazyThreadSafetyMode.NONE) {
123123
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
124124
context.packageManager.hasSystemFeature(PackageManager.FEATURE_STRONGBOX_KEYSTORE)
125125
else

app/src/main/java/com/zeapo/pwdstore/model/PasswordEntry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PasswordEntry(content: String, private val totpFinder: TotpFinder = UriTot
5959
return Otp.calculateCode(totpSecret, Date().time / (1000 * totpPeriod), totpAlgorithm, digits).get()
6060
}
6161

62-
val extraContentWithoutAuthData by lazy {
62+
val extraContentWithoutAuthData by lazy(LazyThreadSafetyMode.NONE) {
6363
extraContent.splitToSequence("\n").filter { line ->
6464
return@filter when {
6565
USERNAME_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } -> {

0 commit comments

Comments
 (0)