From ca83ce9c0a3daf87efa100cf9055132805adf8d6 Mon Sep 17 00:00:00 2001 From: Silin Huang Date: Mon, 5 Apr 2021 22:58:59 -0700 Subject: [PATCH] Update the handleUpdateState() of Wallet Tile. New logic for handle update state: 1. if the wallet feature is unavailable - Unavailable 2. if it has cards: device locked - Inactive device unlocked - Active 3. if no cards - Inactive Also update the secondary label for each case. Test: manually test on device Test: atest Bug: b/182486878 Change-Id: Iccd6624ff9f85926dfc3b147b65bc1354c74650f --- packages/SystemUI/res/values/strings.xml | 8 +- .../qs/tiles/QuickAccessWalletTile.java | 26 ++++- .../qs/tiles/QuickAccessWalletTileTest.java | 101 +++++++++++------- 3 files changed, 89 insertions(+), 46 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 2299fd5e5cb6b..62f8af285c48b 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1637,8 +1637,12 @@ Show all Unlock to pay - - Ready + + Ready + + Set up payment + + Unlock to use There was a problem getting your cards, please try again later 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 032e47e657301..bf9655837b256 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java @@ -71,6 +71,7 @@ public class QuickAccessWalletTile extends QSTileImpl { private final FeatureFlags mFeatureFlags; @VisibleForTesting Drawable mCardViewDrawable; + private boolean mHasCard; @Inject public QuickAccessWalletTile( @@ -128,15 +129,27 @@ public class QuickAccessWalletTile extends QSTileImpl { state.icon = ResourceIcon.get(R.drawable.ic_qs_wallet); boolean isDeviceLocked = !mKeyguardStateController.isUnlocked(); if (mQuickAccessWalletClient.isWalletFeatureAvailable()) { - state.state = isDeviceLocked ? Tile.STATE_INACTIVE : Tile.STATE_ACTIVE; - state.secondaryLabel = isDeviceLocked - ? null - : mContext.getString(R.string.wallet_secondary_label); + if (mHasCard) { + if (isDeviceLocked) { + state.state = Tile.STATE_INACTIVE; + state.secondaryLabel = + mContext.getString(R.string.wallet_secondary_label_device_locked); + } else { + state.state = Tile.STATE_ACTIVE; + state.secondaryLabel = + mContext.getString(R.string.wallet_secondary_label_active); + } + } else { + state.state = Tile.STATE_INACTIVE; + state.secondaryLabel = mContext.getString(R.string.wallet_secondary_label_no_card); + } state.stateDescription = state.secondaryLabel; } else { state.state = Tile.STATE_UNAVAILABLE; } - state.sideViewDrawable = mCardViewDrawable; + if (!isDeviceLocked) { + state.sideViewDrawable = mCardViewDrawable; + } } @Override @@ -184,10 +197,12 @@ public class QuickAccessWalletTile extends QSTileImpl { if (cards.isEmpty()) { Log.d(TAG, "No wallet cards exist."); mCardViewDrawable = null; + mHasCard = false; refreshState(); return; } mCardViewDrawable = cards.get(0).getCardImage().loadDrawable(mContext); + mHasCard = true; refreshState(); } @@ -195,6 +210,7 @@ public class QuickAccessWalletTile extends QSTileImpl { public void onWalletCardRetrievalError(@NonNull GetWalletCardsError error) { Log.w(TAG, "Error retrieve wallet cards"); mCardViewDrawable = null; + mHasCard = false; refreshState(); } } 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 96d797903a23d..f57283ff950d6 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 @@ -133,6 +133,7 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { when(mHost.getContext()).thenReturn(mContext); when(mHost.getUiEventLogger()).thenReturn(mUiEventLogger); when(mFeatureFlags.isQuickAccessWalletEnabled()).thenReturn(true); + when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true); mTile = new QuickAccessWalletTile( mHost, @@ -189,11 +190,11 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { @Test public void testHandleUpdateState_updateLabelAndIcon() { - QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_wallet); QSTile.State state = new QSTile.State(); + QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_wallet); when(mQuickAccessWalletClient.getServiceLabel()).thenReturn("QuickAccessWallet"); - mTile.handleUpdateState(state, new Object()); + mTile.handleUpdateState(state, null); assertEquals("QuickAccessWallet", state.label.toString()); assertTrue(state.label.toString().contentEquals(state.contentDescription)); @@ -201,41 +202,63 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { } @Test - public void testHandleUpdateState_deviceLocked_tileInactive() { - QSTile.State state = new QSTile.State(); + public void testHandleUpdateState_hasCard_deviceLocked_tileInactive() { when(mKeyguardStateController.isUnlocked()).thenReturn(false); - when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true); + QSTile.State state = new QSTile.State(); + setUpWalletCard(/* hasCard= */ true); - mTile.handleUpdateState(state, new Object()); + mTile.handleUpdateState(state, null); assertEquals(Tile.STATE_INACTIVE, state.state); - assertNull(state.stateDescription); + assertEquals( + mContext.getString(R.string.wallet_secondary_label_device_locked), + state.secondaryLabel); + assertNotNull(state.stateDescription); + assertNull(state.sideViewDrawable); } @Test - public void testHandleUpdateState_deviceLocked_tileActive() { - QSTile.State state = new QSTile.State(); + public void testHandleUpdateState_hasCard_deviceUnlocked_tileActive() { when(mKeyguardStateController.isUnlocked()).thenReturn(true); - when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true); + QSTile.State state = new QSTile.State(); + setUpWalletCard(/* hasCard= */ true); - mTile.handleUpdateState(state, new Object()); + mTile.handleUpdateState(state, null); assertEquals(Tile.STATE_ACTIVE, state.state); - assertTrue(state.secondaryLabel.toString().contentEquals(state.stateDescription)); assertEquals( - getContext().getString(R.string.wallet_secondary_label), - state.secondaryLabel.toString()); + mContext.getString(R.string.wallet_secondary_label_active), + state.secondaryLabel); + assertNotNull(state.stateDescription); + assertNotNull(state.sideViewDrawable); + } + + + @Test + public void testHandleUpdateState_noCard_tileInactive() { + QSTile.State state = new QSTile.State(); + setUpWalletCard(/* hasCard= */ false); + + mTile.handleUpdateState(state, null); + + assertEquals(Tile.STATE_INACTIVE, state.state); + assertEquals( + mContext.getString(R.string.wallet_secondary_label_no_card), + state.secondaryLabel); + assertNotNull(state.stateDescription); + assertNull(state.sideViewDrawable); } @Test public void testHandleUpdateState_qawFeatureUnavailable_tileUnavailable() { - QSTile.State state = new QSTile.State(); - when(mKeyguardStateController.isUnlocked()).thenReturn(true); when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false); + QSTile.State state = new QSTile.State(); - mTile.handleUpdateState(state, new Object()); + mTile.handleUpdateState(state, null); assertEquals(Tile.STATE_UNAVAILABLE, state.state); + assertNull(state.stateDescription); + assertNull(state.sideViewDrawable); } @Test @@ -258,23 +281,16 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { } @Test - public void testHandleSetListening_queryCards_hasCards_updateSideViewDrawable() { - GetWalletCardsResponse response = - new GetWalletCardsResponse( - Collections.singletonList(createWalletCard(mContext)), 0); - - mTile.handleSetListening(true); - - verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture()); - - mCallbackCaptor.getValue().onWalletCardsRetrieved(response); - mTestableLooper.processAllMessages(); + public void testQueryCards_hasCards_updateSideViewDrawable() { + when(mKeyguardStateController.isUnlocked()).thenReturn(true); + setUpWalletCard(/* hasCard= */ true); assertNotNull(mTile.getState().sideViewDrawable); } @Test public void testState_queryCards_hasCards_then_noCards() { + when(mKeyguardStateController.isUnlocked()).thenReturn(true); GetWalletCardsResponse responseWithCards = new GetWalletCardsResponse( Collections.singletonList(createWalletCard(mContext)), 0); @@ -304,22 +320,14 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { } @Test - public void testHandleSetListening_queryCards_noCards_notUpdateSideViewDrawable() { - QSTile.State state = new QSTile.State(); - GetWalletCardsResponse response = new GetWalletCardsResponse(Collections.EMPTY_LIST, 0); - - mTile.handleSetListening(true); - - verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture()); - - mCallbackCaptor.getValue().onWalletCardsRetrieved(response); - mTestableLooper.processAllMessages(); + public void testQueryCards_noCards_notUpdateSideViewDrawable() { + setUpWalletCard(/* hasCard= */ false); assertNull(mTile.getState().sideViewDrawable); } @Test - public void testHandleSetListening_queryCards_error_notUpdateSideViewDrawable() { + public void testQueryCards_error_notUpdateSideViewDrawable() { String errorMessage = "getWalletCardsError"; GetWalletCardsError error = new GetWalletCardsError(CARD_IMAGE, errorMessage); @@ -340,6 +348,21 @@ public class QuickAccessWalletTileTest extends SysuiTestCase { verifyZeroInteractions(mQuickAccessWalletClient); } + private void setUpWalletCard(boolean hasCard) { + GetWalletCardsResponse response = + new GetWalletCardsResponse( + hasCard + ? Collections.singletonList(createWalletCard(mContext)) + : Collections.EMPTY_LIST, 0); + + mTile.handleSetListening(true); + + verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture()); + + mCallbackCaptor.getValue().onWalletCardsRetrieved(response); + mTestableLooper.processAllMessages(); + } + private WalletCard createWalletCard(Context context) { PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);