Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e48fc40a authored by Sindhu B's avatar Sindhu B Committed by Android (Google) Code Review
Browse files

Merge "Fix: WalletContextualLocationsService issuing binder calls on main thread" into main

parents 48b3faa0 561c2407
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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"
+21 −7
Original line number Diff line number Diff line
@@ -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,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
@@ -45,6 +58,7 @@ constructor(
                    listener?.registerNewWalletCards(cards)
                }
            }
        }
        return binder
    }

+8 −3
Original line number Diff line number Diff line
@@ -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