Merge "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" into tm-qpr-dev am: 2a4e3c2aaa am: 4adc052ba2
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21412785
Change-Id: Ie1fc4bf4fd54304df47f91ea60f8fc7ffa03e91c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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 a062e7b..492f231 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 @@
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 @@
}
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) {
- data.add(new QAWalletCardViewInfo(mContext, card));
+ if (card.getCardType() != WalletCard.CARD_TYPE_UNKNOWN) {
+ allUnknown = false;
+ break;
+ }
+ }
+
+ List<WalletCardViewInfo> 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 @@
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 @@
}
-
@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 b1950ea..692af6a 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 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.MockitoAnnotations;
import java.util.Collections;
+import java.util.List;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -99,6 +103,8 @@
ArgumentCaptor<PendingIntent> mIntentCaptor;
@Captor
ArgumentCaptor<QuickAccessWalletClient.OnWalletCardsRetrievedCallback> mCallbackCaptor;
+ @Captor
+ ArgumentCaptor<List<WalletCardViewInfo>> mPaymentCardDataCaptor;
private WalletScreenController mController;
private TestableLooper mTestableLooper;
@@ -107,7 +113,7 @@
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 @@
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 @@
.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);