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

Commit afa88d0f authored by Charles Wang's avatar Charles Wang
Browse files

This change update the WalletScreenController to only show payment cards on lock screen

carousel, maintaining the current behavior.
Context: We have an API change landing in U to support more card types for WalletCard (types shown at cs/android-internal/frameworks/base/core/java/android/service/quickaccesswallet/WalletCard.java;l=89?q=walletcard.java). This change ensures default behavior stays the same regarding only payment cards being shown on carousel.
Bug: b/268521874
Test: atest WalletScreenControllerTest.java

Change-Id: Ibd09e3c7eea07f2605fea7e0c532815078731425
parent a01881b6
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -77,8 +77,11 @@ public class WalletScreenController implements
    private final FalsingManager mFalsingManager;
    private final UiEventLogger mUiEventLogger;

    @VisibleForTesting String mSelectedCardId;
    @VisibleForTesting boolean mIsDismissed;

    @VisibleForTesting
    String mSelectedCardId;
    @VisibleForTesting
    boolean mIsDismissed;

    public WalletScreenController(
            Context context,
@@ -124,9 +127,20 @@ public class WalletScreenController implements
        }
        Log.i(TAG, "Successfully retrieved wallet cards.");
        List<WalletCard> walletCards = response.getWalletCards();
        List<WalletCardViewInfo> data = new ArrayList<>(walletCards.size());

        boolean allUnknown = true;
        for (WalletCard card : walletCards) {
            if (card.getCardType() != WalletCard.CARD_TYPE_UNKNOWN) {
                allUnknown = false;
                break;
            }
        }

        List<WalletCardViewInfo> paymentCardData = new ArrayList<>();
        for (WalletCard card : walletCards) {
            data.add(new QAWalletCardViewInfo(mContext, card));
            if (allUnknown || card.getCardType() == WalletCard.CARD_TYPE_PAYMENT) {
                paymentCardData.add(new QAWalletCardViewInfo(mContext, card));
            }
        }

        // Get on main thread for UI updates.
@@ -134,18 +148,18 @@ public class WalletScreenController implements
            if (mIsDismissed) {
                return;
            }
            if (data.isEmpty()) {
            if (paymentCardData.isEmpty()) {
                showEmptyStateView();
            } else {
                int selectedIndex = response.getSelectedIndex();
                if (selectedIndex >= data.size()) {
                if (selectedIndex >= paymentCardData.size()) {
                    Log.w(TAG, "Invalid selected card index, showing empty state.");
                    showEmptyStateView();
                } else {
                    boolean isUdfpsEnabled = mKeyguardUpdateMonitor.isUdfpsEnrolled()
                            && mKeyguardUpdateMonitor.isFingerprintDetectionRunning();
                    mWalletView.showCardCarousel(
                            data,
                            paymentCardData,
                            selectedIndex,
                            !mKeyguardStateController.isUnlocked(),
                            isUdfpsEnabled);
@@ -213,7 +227,6 @@ public class WalletScreenController implements
    }



    @Override
    public void onCardClicked(@NonNull WalletCardViewInfo cardInfo) {
        if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
+51 −1
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import static android.view.View.VISIBLE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -63,6 +66,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Collections;
import java.util.List;

@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -99,6 +103,8 @@ public class WalletScreenControllerTest extends SysuiTestCase {
    ArgumentCaptor<PendingIntent> mIntentCaptor;
    @Captor
    ArgumentCaptor<QuickAccessWalletClient.OnWalletCardsRetrievedCallback> mCallbackCaptor;
    @Captor
    ArgumentCaptor<List<WalletCardViewInfo>> mPaymentCardDataCaptor;
    private WalletScreenController mController;
    private TestableLooper mTestableLooper;

@@ -107,7 +113,7 @@ public class WalletScreenControllerTest extends SysuiTestCase {
        MockitoAnnotations.initMocks(this);
        mTestableLooper = TestableLooper.get(this);
        when(mUserTracker.getUserContext()).thenReturn(mContext);
        mWalletView = new WalletView(mContext);
        mWalletView = spy(new WalletView(mContext));
        mWalletView.getCardCarousel().setExpectedViewWidth(CARD_CAROUSEL_WIDTH);
        when(mWalletClient.getLogo()).thenReturn(mWalletLogo);
        when(mWalletClient.getShortcutLongLabel()).thenReturn(SHORTCUT_LONG_LABEL);
@@ -430,6 +436,41 @@ public class WalletScreenControllerTest extends SysuiTestCase {
        assertEquals(GONE, mWalletView.getVisibility());
    }

    @Test
    public void onWalletCardsRetrieved_cardDataAllUnknown_showsAllCards() {
        List<WalletCard> walletCardList = List.of(
                createWalletCardWithType(mContext, WalletCard.CARD_TYPE_UNKNOWN),
                createWalletCardWithType(mContext, WalletCard.CARD_TYPE_UNKNOWN),
                createWalletCardWithType(mContext, WalletCard.CARD_TYPE_UNKNOWN));
        GetWalletCardsResponse response = new GetWalletCardsResponse(walletCardList, 0);
        mController.onWalletCardsRetrieved(response);
        mTestableLooper.processAllMessages();

        verify(mWalletView).showCardCarousel(mPaymentCardDataCaptor.capture(), anyInt(),
                anyBoolean(),
                anyBoolean());
        List<WalletCardViewInfo> paymentCardData = mPaymentCardDataCaptor.getValue();
        assertEquals(paymentCardData.size(), walletCardList.size());
    }

    @Test
    public void onWalletCardsRetrieved_cardDataDifferentTypes_onlyShowsPayment() {
        List<WalletCard> walletCardList = List.of(createWalletCardWithType(mContext,
                        WalletCard.CARD_TYPE_UNKNOWN),
                createWalletCardWithType(mContext, WalletCard.CARD_TYPE_PAYMENT),
                createWalletCardWithType(mContext, WalletCard.CARD_TYPE_NON_PAYMENT)
                );
        GetWalletCardsResponse response = new GetWalletCardsResponse(walletCardList, 0);
        mController.onWalletCardsRetrieved(response);
        mTestableLooper.processAllMessages();

        verify(mWalletView).showCardCarousel(mPaymentCardDataCaptor.capture(), anyInt(),
                anyBoolean(),
                anyBoolean());
        List<WalletCardViewInfo> paymentCardData = mPaymentCardDataCaptor.getValue();
        assertEquals(paymentCardData.size(), 1);
    }

    private WalletCard createNonActiveWalletCard(Context context) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
@@ -457,6 +498,15 @@ public class WalletScreenControllerTest extends SysuiTestCase {
                .build();
    }

    private WalletCard createWalletCardWithType(Context context, int cardType) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
        return new WalletCard.Builder(CARD_ID_1, cardType, createIcon(), "•••• 1234", pendingIntent)
                .setCardIcon(createIcon())
                .setCardLabel("Hold to reader")
                .build();
    }

    private WalletCard createCrazyWalletCard(Context context, boolean hasLabel) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);