Make mailbox screen view repository thread safe

- Explicitly remove FeatureFlagsInitializer from manifest

MAILAND-3071
This commit is contained in:
Marino Meneghel 2023-04-04 16:02:46 +02:00 committed by Zorica Stojchevska
parent 54cf43d280
commit 57e398a110
5 changed files with 20 additions and 13 deletions

View File

@ -144,6 +144,11 @@
android:name="ch.protonmail.android.onboarding.base.presentation.StartOnboardingObserverInitializer"
android:value="androidx.startup"
tools:node="remove" />
<meta-data
android:name="ch.protonmail.android.featureflags.FeatureFlagsInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
<provider
android:name="androidx.core.content.FileProvider"

View File

@ -20,6 +20,7 @@
package ch.protonmail.android.feature.rating
import timber.log.Timber
import java.util.concurrent.atomic.AtomicInteger
import javax.inject.Inject
import javax.inject.Singleton
@ -27,12 +28,12 @@ import javax.inject.Singleton
class MailboxScreenViewInMemoryRepository @Inject constructor() {
public val screenViewCount: Int
get() = mailboxScreenViews
get() = mailboxScreenViews.get()
private var mailboxScreenViews: Int = 0
private var mailboxScreenViews = AtomicInteger(0)
fun recordScreenView() {
mailboxScreenViews++
mailboxScreenViews.incrementAndGet()
Timber.d("Recording mailbox screen view: count $mailboxScreenViews")
}

View File

@ -19,7 +19,6 @@
package ch.protonmail.android.featureflags
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import me.proton.core.accountmanager.domain.AccountManager
@ -38,12 +37,14 @@ class RefreshFeatureFlags @Inject constructor(
private val scope get() = scopeProvider.GlobalIOSupervisedScope
fun refresh(): Job = scope.launch {
val accounts = accountManager.getAccounts().firstOrNull() ?: return@launch
Timber.d("Refreshing feature flags for ${accounts.count()} accounts")
accounts.map { it.userId }.forEach { userId ->
refreshCachedShowRatingsFeatureFlag(userId)
Timber.d("Rating feature flag refreshed for user $userId")
fun refresh() {
scope.launch {
val accounts = accountManager.getAccounts().firstOrNull() ?: return@launch
Timber.d("Refreshing feature flags for ${accounts.count()} accounts")
accounts.map { it.userId }.forEach { userId ->
refreshCachedShowRatingsFeatureFlag(userId)
Timber.d("Rating feature flag refreshed for user $userId")
}
}
}

View File

@ -28,7 +28,7 @@ class MailboxScreenViewInMemoryRepositoryTest {
private val showReviewAppRepository = MailboxScreenViewInMemoryRepository()
@Test
fun increaseMailboxScreenViewsCounterWhenRecordMailboxScreenViewIsCalled() = runTest {
fun `increase mailbox screen views counter when record mailbox screen view is called`() = runTest {
// given
check(showReviewAppRepository.screenViewCount == 0)

View File

@ -50,7 +50,7 @@ class RefreshFeatureFlagsTest {
)
@Test
fun doesNothingWhenThereAreNoAccounts() = runTest {
fun `does nothing when there are no accounts`() = runTest {
// given
coEvery { accountManager.getAccounts() } returns flowOf()
@ -62,7 +62,7 @@ class RefreshFeatureFlagsTest {
}
@Test
fun refreshShowRatingFeatureFlagForEachExistingUser() = runTest {
fun `refresh show rating feature flag for each existing user`() = runTest {
// given
showRatingsFlagForUserMocked(UserTestData.userId, false)
showRatingsFlagForUserMocked(UserTestData.secondaryUserId, true)