Loading packages/SystemUI/aconfig/systemui.aconfig +12 −2 Original line number Diff line number Diff line Loading @@ -430,6 +430,16 @@ flag { } } 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 { name: "update_user_switcher_background" namespace: "systemui" Loading packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt +21 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() { Loading @@ -29,15 +33,24 @@ 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) 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 Loading @@ -45,6 +58,7 @@ constructor( listener?.registerNewWalletCards(cards) } } } return binder } Loading packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt +8 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading
packages/SystemUI/aconfig/systemui.aconfig +12 −2 Original line number Diff line number Diff line Loading @@ -430,6 +430,16 @@ flag { } } 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 { name: "update_user_switcher_background" namespace: "systemui" Loading
packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt +21 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() { Loading @@ -29,15 +33,24 @@ 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) 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 Loading @@ -45,6 +58,7 @@ constructor( listener?.registerNewWalletCards(cards) } } } return binder } Loading
packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt +8 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading