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
This commit is contained in:
@@ -77,8 +77,11 @@ public class WalletScreenController implements
|
|||||||
private final FalsingManager mFalsingManager;
|
private final FalsingManager mFalsingManager;
|
||||||
private final UiEventLogger mUiEventLogger;
|
private final UiEventLogger mUiEventLogger;
|
||||||
|
|
||||||
@VisibleForTesting String mSelectedCardId;
|
|
||||||
@VisibleForTesting boolean mIsDismissed;
|
@VisibleForTesting
|
||||||
|
String mSelectedCardId;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mIsDismissed;
|
||||||
|
|
||||||
public WalletScreenController(
|
public WalletScreenController(
|
||||||
Context context,
|
Context context,
|
||||||
@@ -124,9 +127,20 @@ public class WalletScreenController implements
|
|||||||
}
|
}
|
||||||
Log.i(TAG, "Successfully retrieved wallet cards.");
|
Log.i(TAG, "Successfully retrieved wallet cards.");
|
||||||
List<WalletCard> walletCards = response.getWalletCards();
|
List<WalletCard> walletCards = response.getWalletCards();
|
||||||
List<WalletCardViewInfo> data = new ArrayList<>(walletCards.size());
|
|
||||||
|
boolean allUnknown = true;
|
||||||
for (WalletCard card : walletCards) {
|
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.
|
// Get on main thread for UI updates.
|
||||||
@@ -134,18 +148,18 @@ public class WalletScreenController implements
|
|||||||
if (mIsDismissed) {
|
if (mIsDismissed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.isEmpty()) {
|
if (paymentCardData.isEmpty()) {
|
||||||
showEmptyStateView();
|
showEmptyStateView();
|
||||||
} else {
|
} else {
|
||||||
int selectedIndex = response.getSelectedIndex();
|
int selectedIndex = response.getSelectedIndex();
|
||||||
if (selectedIndex >= data.size()) {
|
if (selectedIndex >= paymentCardData.size()) {
|
||||||
Log.w(TAG, "Invalid selected card index, showing empty state.");
|
Log.w(TAG, "Invalid selected card index, showing empty state.");
|
||||||
showEmptyStateView();
|
showEmptyStateView();
|
||||||
} else {
|
} else {
|
||||||
boolean isUdfpsEnabled = mKeyguardUpdateMonitor.isUdfpsEnrolled()
|
boolean isUdfpsEnabled = mKeyguardUpdateMonitor.isUdfpsEnrolled()
|
||||||
&& mKeyguardUpdateMonitor.isFingerprintDetectionRunning();
|
&& mKeyguardUpdateMonitor.isFingerprintDetectionRunning();
|
||||||
mWalletView.showCardCarousel(
|
mWalletView.showCardCarousel(
|
||||||
data,
|
paymentCardData,
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
!mKeyguardStateController.isUnlocked(),
|
!mKeyguardStateController.isUnlocked(),
|
||||||
isUdfpsEnabled);
|
isUdfpsEnabled);
|
||||||
@@ -213,7 +227,6 @@ public class WalletScreenController implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCardClicked(@NonNull WalletCardViewInfo cardInfo) {
|
public void onCardClicked(@NonNull WalletCardViewInfo cardInfo) {
|
||||||
if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
|
if (mFalsingManager.isFalseTap(FalsingManager.LOW_PENALTY)) {
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import static android.view.View.VISIBLE;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
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.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -63,6 +66,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
@TestableLooper.RunWithLooper
|
@TestableLooper.RunWithLooper
|
||||||
@@ -99,6 +103,8 @@ public class WalletScreenControllerTest extends SysuiTestCase {
|
|||||||
ArgumentCaptor<PendingIntent> mIntentCaptor;
|
ArgumentCaptor<PendingIntent> mIntentCaptor;
|
||||||
@Captor
|
@Captor
|
||||||
ArgumentCaptor<QuickAccessWalletClient.OnWalletCardsRetrievedCallback> mCallbackCaptor;
|
ArgumentCaptor<QuickAccessWalletClient.OnWalletCardsRetrievedCallback> mCallbackCaptor;
|
||||||
|
@Captor
|
||||||
|
ArgumentCaptor<List<WalletCardViewInfo>> mPaymentCardDataCaptor;
|
||||||
private WalletScreenController mController;
|
private WalletScreenController mController;
|
||||||
private TestableLooper mTestableLooper;
|
private TestableLooper mTestableLooper;
|
||||||
|
|
||||||
@@ -107,7 +113,7 @@ public class WalletScreenControllerTest extends SysuiTestCase {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mTestableLooper = TestableLooper.get(this);
|
mTestableLooper = TestableLooper.get(this);
|
||||||
when(mUserTracker.getUserContext()).thenReturn(mContext);
|
when(mUserTracker.getUserContext()).thenReturn(mContext);
|
||||||
mWalletView = new WalletView(mContext);
|
mWalletView = spy(new WalletView(mContext));
|
||||||
mWalletView.getCardCarousel().setExpectedViewWidth(CARD_CAROUSEL_WIDTH);
|
mWalletView.getCardCarousel().setExpectedViewWidth(CARD_CAROUSEL_WIDTH);
|
||||||
when(mWalletClient.getLogo()).thenReturn(mWalletLogo);
|
when(mWalletClient.getLogo()).thenReturn(mWalletLogo);
|
||||||
when(mWalletClient.getShortcutLongLabel()).thenReturn(SHORTCUT_LONG_LABEL);
|
when(mWalletClient.getShortcutLongLabel()).thenReturn(SHORTCUT_LONG_LABEL);
|
||||||
@@ -430,6 +436,41 @@ public class WalletScreenControllerTest extends SysuiTestCase {
|
|||||||
assertEquals(GONE, mWalletView.getVisibility());
|
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) {
|
private WalletCard createNonActiveWalletCard(Context context) {
|
||||||
PendingIntent pendingIntent =
|
PendingIntent pendingIntent =
|
||||||
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
||||||
@@ -457,6 +498,15 @@ public class WalletScreenControllerTest extends SysuiTestCase {
|
|||||||
.build();
|
.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) {
|
private WalletCard createCrazyWalletCard(Context context, boolean hasLabel) {
|
||||||
PendingIntent pendingIntent =
|
PendingIntent pendingIntent =
|
||||||
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user