diff --git a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java index a062e7b2db502..492f2318fec6d 100644 --- a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java +++ b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java @@ -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 walletCards = response.getWalletCards(); - List data = new ArrayList<>(walletCards.size()); + + boolean allUnknown = true; for (WalletCard card : walletCards) { - data.add(new QAWalletCardViewInfo(mContext, card)); + if (card.getCardType() != WalletCard.CARD_TYPE_UNKNOWN) { + allUnknown = false; + break; + } + } + + List paymentCardData = new ArrayList<>(); + for (WalletCard card : walletCards) { + 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)) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallet/ui/WalletScreenControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallet/ui/WalletScreenControllerTest.java index b1950eac9846c..692af6a9a37b6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallet/ui/WalletScreenControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wallet/ui/WalletScreenControllerTest.java @@ -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 mIntentCaptor; @Captor ArgumentCaptor mCallbackCaptor; + @Captor + ArgumentCaptor> 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 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 paymentCardData = mPaymentCardDataCaptor.getValue(); + assertEquals(paymentCardData.size(), walletCardList.size()); + } + + @Test + public void onWalletCardsRetrieved_cardDataDifferentTypes_onlyShowsPayment() { + List 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 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);