diff options
3 files changed, 41 insertions, 12 deletions
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig index c2072ac8770d..6f34f05447a9 100644 --- a/packages/SystemUI/aconfig/systemui.aconfig +++ b/packages/SystemUI/aconfig/systemui.aconfig @@ -426,8 +426,18 @@ flag { description: "Decide whether to fetch the connected bluetooth device name outside a synchronized block." bug: "323995015" metadata { - purpose: PURPOSE_BUGFIX - } + purpose: PURPOSE_BUGFIX + } +} + +flag { + name: "register_new_wallet_card_in_background" + namespace: "systemui" + description: "Decide whether the call to registerNewWalletCards method should be issued on background thread." + bug: "322506838" + metadata { + purpose: PURPOSE_BUGFIX + } } flag { diff --git a/packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt b/packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt index bb4a2c405b31..3c50c7b4a212 100644 --- a/packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt +++ b/packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt @@ -6,9 +6,12 @@ import android.util.Log import androidx.annotation.VisibleForTesting import androidx.lifecycle.LifecycleService import androidx.lifecycle.lifecycleScope +import com.android.systemui.Flags.registerNewWalletCardInBackground +import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import javax.inject.Inject +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -21,6 +24,7 @@ import kotlinx.coroutines.launch class WalletContextualLocationsService @Inject constructor( + @Background private val backgroundDispatcher: CoroutineDispatcher, private val controller: WalletContextualSuggestionsController, private val featureFlags: FeatureFlags, ) : LifecycleService() { @@ -29,20 +33,30 @@ constructor( @VisibleForTesting constructor( + dispatcher: CoroutineDispatcher, controller: WalletContextualSuggestionsController, featureFlags: FeatureFlags, scope: CoroutineScope, - ) : this(controller, featureFlags) { + ) : this(dispatcher, controller, featureFlags) { this.scope = scope } - override fun onBind(intent: Intent): IBinder { super.onBind(intent) - scope.launch { - controller.allWalletCards.collect { cards -> - val cardsSize = cards.size - Log.i(TAG, "Number of cards registered $cardsSize") - listener?.registerNewWalletCards(cards) + if (registerNewWalletCardInBackground()) { + scope.launch(backgroundDispatcher) { + controller.allWalletCards.collect { cards -> + val cardsSize = cards.size + Log.i(TAG, "Number of cards registered $cardsSize") + listener?.registerNewWalletCards(cards) + } + } + } else { + scope.launch { + controller.allWalletCards.collect { cards -> + val cardsSize = cards.size + Log.i(TAG, "Number of cards registered $cardsSize") + listener?.registerNewWalletCards(cards) + } } } return binder diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt index e6b4d069ac98..8c5df6efef33 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt @@ -14,6 +14,7 @@ import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update +import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest @@ -53,13 +54,17 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { doNothing().whenever(controller).setSuggestionCardIds(anySet()) if (Looper.myLooper() == null) Looper.prepare() - + val testDispatcher = StandardTestDispatcher() testScope = TestScope() featureFlags.set(Flags.ENABLE_WALLET_CONTEXTUAL_LOYALTY_CARDS, true) listenerRegisteredCount = 0 - underTest = - WalletContextualLocationsService(controller, featureFlags, testScope.backgroundScope) + WalletContextualLocationsService( + testDispatcher, + controller, + featureFlags, + testScope.backgroundScope + ) } @Test |