Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7ac580e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update the handleUpdateState() of Wallet Tile." into sc-dev

parents e714f620 ca83ce9c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1637,8 +1637,12 @@
    <string name="wallet_button_label_device_unlocked">Show all</string>
    <!-- Label of the button underneath the card carousel when device is locked. [CHAR LIMIT=NONE] -->
    <string name="wallet_button_label_device_locked">Unlock to pay</string>
    <!-- Secondary label of the quick access wallet tile. [CHAR LIMIT=32] -->
    <string name="wallet_secondary_label">Ready</string>
    <!-- Secondary label of the quick access wallet tile if active. [CHAR LIMIT=32] -->
    <string name="wallet_secondary_label_active">Ready</string>
    <!-- Secondary label of the quick access wallet tile if no card. [CHAR LIMIT=NONE] -->
    <string name="wallet_secondary_label_no_card">Set up payment</string>
    <!-- Secondary label of the quick access wallet tile if device locked. [CHAR LIMIT=NONE] -->
    <string name="wallet_secondary_label_device_locked">Unlock to use</string>
    <!-- Message shown when an unknown failure occurred when fetching cards. [CHAR LIMIT=NONE] -->
    <string name="wallet_error_generic">There was a problem getting your cards, please try again later</string>

+21 −5
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
    private final FeatureFlags mFeatureFlags;

    @VisibleForTesting Drawable mCardViewDrawable;
    private boolean mHasCard;

    @Inject
    public QuickAccessWalletTile(
@@ -128,16 +129,28 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
        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;
        }
        if (!isDeviceLocked) {
            state.sideViewDrawable = mCardViewDrawable;
        }
    }

    @Override
    public int getMetricsCategory() {
@@ -184,10 +197,12 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
            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<QSTile.State> {
        public void onWalletCardRetrievalError(@NonNull GetWalletCardsError error) {
            Log.w(TAG, "Error retrieve wallet cards");
            mCardViewDrawable = null;
            mHasCard = false;
            refreshState();
        }
    }
+62 −39
Original line number Diff line number Diff line
@@ -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_qawFeatureUnavailable_tileUnavailable() {
    public void testHandleUpdateState_noCard_tileInactive() {
        QSTile.State state = new QSTile.State();
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);
        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() {
        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);