From 6d29225bf3f0c8c8e5d66eca45f21d33f1130a6d Mon Sep 17 00:00:00 2001 From: Silin Huang Date: Thu, 15 Apr 2021 22:40:46 -0700 Subject: [PATCH] Bug fix for QuickAccessWallet. 1. Update the Wallet tile label. 2. Check the card width and height in the request, if they are not valid (is 0) do not query cards. Test: manual Test: atest Bug: 184905963 Change-Id: Ie1f02a27e2ac0c3077dd576a3ee2efcce0c6b8d4 --- .../systemui/qs/tiles/QuickAccessWalletTile.java | 3 +-- .../systemui/wallet/ui/WalletScreenController.java | 7 +++++-- .../qs/tiles/QuickAccessWalletTileTest.java | 5 +++++ .../wallet/ui/WalletScreenControllerTest.java | 13 +++++++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java index b728b4360db02..6f19276b8d00c 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java @@ -184,8 +184,7 @@ public class QuickAccessWalletTile extends QSTileImpl { @Override public CharSequence getTileLabel() { - CharSequence qawLabel = mQuickAccessWalletClient.getServiceLabel(); - return qawLabel == null ? mLabel : qawLabel; + return mLabel; } private void queryWalletCards() { 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 d19506212d91b..d1a2c8a49a955 100644 --- a/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java +++ b/packages/SystemUI/src/com/android/systemui/wallet/ui/WalletScreenController.java @@ -222,6 +222,11 @@ public class WalletScreenController implements if (mIsDismissed) { return; } + int cardWidthPx = mCardCarousel.getCardWidthPx(); + int cardHeightPx = mCardCarousel.getCardHeightPx(); + if (cardWidthPx == 0 || cardHeightPx == 0) { + return; + } if (!mHasRegisteredListener) { // Listener is registered even when device is locked. Should only be registered once. mWalletClient.addWalletServiceEventListener(this); @@ -231,8 +236,6 @@ public class WalletScreenController implements mWalletView.show(); mWalletView.hideErrorMessage(); int iconSizePx = mContext.getResources().getDimensionPixelSize(R.dimen.wallet_icon_size); - int cardWidthPx = mCardCarousel.getCardWidthPx(); - int cardHeightPx = mCardCarousel.getCardHeightPx(); GetWalletCardsRequest request = new GetWalletCardsRequest(cardWidthPx, cardHeightPx, iconSizePx, MAX_CARDS); mWalletClient.getWalletCards(mExecutor, request, this); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/QuickAccessWalletTileTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/QuickAccessWalletTileTest.java index d236023499d20..4bba0d0d23e4b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/QuickAccessWalletTileTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/QuickAccessWalletTileTest.java @@ -232,6 +232,11 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { assertEquals(icon, state.icon); } + @Test + public void testGetTileLabel() { + assertEquals(mContext.getString(R.string.wallet_title), mTile.getTileLabel().toString()); + } + @Test public void testHandleUpdateState_hasCard_deviceLocked_tileInactive() { when(mKeyguardStateController.isUnlocked()).thenReturn(false); 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 653946ea5cc8f..6f6ef72610205 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 @@ -71,15 +71,17 @@ import java.util.Collections; public class WalletScreenControllerTest extends SysuiTestCase { private static final int MAX_CARDS = 10; + private static final int CARD_CAROUSEL_WIDTH = 10; private static final String CARD_ID = "card_id"; private static final CharSequence SHORTCUT_SHORT_LABEL = "View all"; private static final CharSequence SHORTCUT_LONG_LABEL = "Add a payment method"; private static final CharSequence SERVICE_LABEL = "Wallet app"; - private final WalletView mWalletView = new WalletView(mContext); private final Drawable mWalletLogo = mContext.getDrawable(android.R.drawable.ic_lock_lock); private final Intent mWalletIntent = new Intent(QuickAccessWalletService.ACTION_VIEW_WALLET) .setComponent(new ComponentName(mContext.getPackageName(), "WalletActivity")); + private WalletView mWalletView; + @Mock QuickAccessWalletClient mWalletClient; @Mock @@ -104,6 +106,8 @@ public class WalletScreenControllerTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); mTestableLooper = TestableLooper.get(this); when(mUserTracker.getUserContext()).thenReturn(mContext); + mWalletView = new WalletView(mContext); + mWalletView.getCardCarousel().setExpectedViewWidth(CARD_CAROUSEL_WIDTH); when(mWalletClient.getLogo()).thenReturn(mWalletLogo); when(mWalletClient.getShortcutLongLabel()).thenReturn(SHORTCUT_LONG_LABEL); when(mWalletClient.getShortcutShortLabel()).thenReturn(SHORTCUT_SHORT_LABEL); @@ -132,7 +136,12 @@ public class WalletScreenControllerTest extends SysuiTestCase { verify(mWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture()); - mCallbackCaptor.getValue().onWalletCardsRetrieved(response); + QuickAccessWalletClient.OnWalletCardsRetrievedCallback callback = + mCallbackCaptor.getValue(); + + assertEquals(mController, callback); + + callback.onWalletCardsRetrieved(response); mTestableLooper.processAllMessages(); assertEquals(VISIBLE, mWalletView.getCardCarouselContainer().getVisibility());