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

Commit 055fab6f authored by John Johnson's avatar John Johnson Committed by Automerger Merge Worker
Browse files

Merge "Fix WalletContextualSuggestionsController so it works for multiple...

Merge "Fix WalletContextualSuggestionsController so it works for multiple cards" into udc-qpr-dev am: abf7cea0 am: c308cd6f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24284490



Change-Id: I98536b6a93f32c11c09324420a78514a84dbed28
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents cbd4d10c c308cd6f
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -157,9 +157,10 @@ public class QuickAccessWalletController {
     * Query the wallet cards from {@link QuickAccessWalletClient}.
     *
     * @param cardsRetriever a callback to retrieve wallet cards.
     * @param maxCards the maximum number of cards requested from the QuickAccessWallet
     */
    public void queryWalletCards(
            QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever) {
            QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever, int maxCards) {
        if (mClock.elapsedRealtime() - mQawClientCreatedTimeMillis
                > RECREATION_TIME_WINDOW) {
            Log.i(TAG, "Re-creating the QAW client to avoid stale.");
@@ -175,10 +176,21 @@ public class QuickAccessWalletController {
                mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_height);
        int iconSizePx = mContext.getResources().getDimensionPixelSize(R.dimen.wallet_icon_size);
        GetWalletCardsRequest request =
                new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, /* maxCards= */ 1);
                new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, maxCards);
        mQuickAccessWalletClient.getWalletCards(mBgExecutor, request, cardsRetriever);
    }

    /**
     * Query the wallet cards from {@link QuickAccessWalletClient}.
     *
     * @param cardsRetriever a callback to retrieve wallet cards.
     */
    public void queryWalletCards(
            QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever) {
        queryWalletCards(cardsRetriever, /* maxCards= */ 1);
    }


    /**
     * Re-create the {@link QuickAccessWalletClient} of the controller.
     */
+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
@@ -88,7 +87,7 @@ constructor(
                            QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
                        )
                        walletController.updateWalletPreference()
                        walletController.queryWalletCards(callback)
                        walletController.queryWalletCards(callback, MAX_CARDS)

                        awaitClose {
                            walletController.unregisterWalletChangeObservers(
@@ -152,5 +151,6 @@ constructor(

    companion object {
        private const val TAG = "WalletSuggestions"
        private const val MAX_CARDS = 50
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -187,6 +187,25 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
                request.getCardHeightPx());
    }

    @Test
    public void queryWalletCards_walletEnabled_queryMultipleCards() {
        mController.queryWalletCards(mCardsRetriever, 5);

        verify(mQuickAccessWalletClient)
                .getWalletCards(
                        eq(MoreExecutors.directExecutor()), mRequestCaptor.capture(),
                        eq(mCardsRetriever));

        GetWalletCardsRequest request = mRequestCaptor.getValue();
        assertEquals(5, mRequestCaptor.getValue().getMaxCards());
        assertEquals(
                mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_width),
                request.getCardWidthPx());
        assertEquals(
                mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_height),
                request.getCardHeightPx());
    }

    @Test
    public void queryWalletCards_walletFeatureNotAvailable_noQuery() {
        when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ class WalletContextualSuggestionsControllerTest : SysuiTestCase() {
        cards: List<WalletCard> = emptyList(),
        shouldFail: Boolean = false
    ) {
        whenever(walletController.queryWalletCards(any())).thenAnswer { invocation ->
        whenever(walletController.queryWalletCards(any(), anyInt())).thenAnswer { invocation ->
            with(
                invocation.arguments[0] as QuickAccessWalletClient.OnWalletCardsRetrievedCallback
            ) {