diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt index 52e24aab3f..48eda45001 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.dependencies import android.content.Context +import android.os.Trace import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.ConversationVolatileConfig @@ -60,11 +61,20 @@ class ConfigFactory( listeners -= listener } + private inline fun synchronizedWithLog(lock: Any, body: ()->T): T { + Trace.beginSection("synchronizedWithLog") + val result = synchronized(lock) { + body() + } + Trace.endSection() + return result + } + override val user: UserProfile? - get() = synchronized(userLock) { + get() = synchronizedWithLog(userLock) { if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null if (_userConfig == null) { - val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val (secretKey, publicKey) = maybeGetUserInfo() ?: return null val userDump = configDatabase.retrieveConfigAndHashes( SharedConfigMessage.Kind.USER_PROFILE.name, publicKey @@ -81,10 +91,10 @@ class ConfigFactory( } override val contacts: Contacts? - get() = synchronized(contactsLock) { + get() = synchronizedWithLog(contactsLock) { if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null if (_contacts == null) { - val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val (secretKey, publicKey) = maybeGetUserInfo() ?: return null val contactsDump = configDatabase.retrieveConfigAndHashes( SharedConfigMessage.Kind.CONTACTS.name, publicKey @@ -101,10 +111,10 @@ class ConfigFactory( } override val convoVolatile: ConversationVolatileConfig? - get() = synchronized(convoVolatileLock) { + get() = synchronizedWithLog(convoVolatileLock) { if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null if (_convoVolatileConfig == null) { - val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val (secretKey, publicKey) = maybeGetUserInfo() ?: return null val convoDump = configDatabase.retrieveConfigAndHashes( SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey @@ -122,10 +132,10 @@ class ConfigFactory( } override val userGroups: UserGroupsConfig? - get() = synchronized(userGroupsLock) { + get() = synchronizedWithLog(userGroupsLock) { if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null if (_userGroups == null) { - val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val (secretKey, publicKey) = maybeGetUserInfo() ?: return null val userGroupsDump = configDatabase.retrieveConfigAndHashes( SharedConfigMessage.Kind.GROUPS.name, publicKey diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index d52e482794..2cc912657c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -175,15 +175,17 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), } binding.sessionToolbar.disableClipping() // Set up seed reminder view - val hasViewedSeed = textSecurePreferences.getHasViewedSeed() - if (!hasViewedSeed) { - binding.seedReminderView.isVisible = true - binding.seedReminderView.title = SpannableString("You're almost finished! 80%") // Intentionally not yet translated - binding.seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_1) - binding.seedReminderView.setProgress(80, false) - binding.seedReminderView.delegate = this@HomeActivity - } else { - binding.seedReminderView.isVisible = false + lifecycleScope.launchWhenStarted { + val hasViewedSeed = textSecurePreferences.getHasViewedSeed() + if (!hasViewedSeed) { + binding.seedReminderView.isVisible = true + binding.seedReminderView.title = SpannableString("You're almost finished! 80%") // Intentionally not yet translated + binding.seedReminderView.subtitle = resources.getString(R.string.view_seed_reminder_subtitle_1) + binding.seedReminderView.setProgress(80, false) + binding.seedReminderView.delegate = this@HomeActivity + } else { + binding.seedReminderView.isVisible = false + } } setupMessageRequestsBanner() // Set up recycler view