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

Commit eb5a9b8a authored by Silin Huang's avatar Silin Huang
Browse files

For the wallet card & icon, only allow the drawable be loaded from bitmap.

Test: manual
Bug: 366403307
Flag: EXEMPT bugfix
Change-Id: I0033f6ba7ce7f9b9d592e7ce44e63ba804ceb348
parent a3aae9ab
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
    private static final String CARD_DESCRIPTION = "•••• 1234";
    private static final Icon CARD_IMAGE =
            Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888));
    private static final Icon INVALID_CARD_IMAGE =
            Icon.createWithContentUri("content://media/external/images/media");
    private static final int PRIMARY_USER_ID = 0;
    private static final int SECONDARY_USER_ID = 10;

@@ -443,6 +445,14 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
        assertNull(mTile.getState().sideViewCustomDrawable);
    }

    @Test
    public void testQueryCards_invalidDrawable_noSideViewDrawable() {
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);
        setUpInvalidWalletCard(/* hasCard= */ true);

        assertNull(mTile.getState().sideViewCustomDrawable);
    }

    @Test
    public void testQueryCards_error_notUpdateSideViewDrawable() {
        String errorMessage = "getWalletCardsError";
@@ -503,9 +513,33 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
        mTestableLooper.processAllMessages();
    }

    private void setUpInvalidWalletCard(boolean hasCard) {
        GetWalletCardsResponse response =
                new GetWalletCardsResponse(
                        hasCard
                                ? Collections.singletonList(createInvalidWalletCard(mContext))
                                : Collections.EMPTY_LIST, 0);

        mTile.handleSetListening(true);

        verify(mController).queryWalletCards(mCallbackCaptor.capture());

        mCallbackCaptor.getValue().onWalletCardsRetrieved(response);
        mTestableLooper.processAllMessages();
    }

    private WalletCard createWalletCard(Context context) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
        return new WalletCard.Builder(CARD_ID, CARD_IMAGE, CARD_DESCRIPTION, pendingIntent).build();
    }

    private WalletCard createInvalidWalletCard(Context context) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
        return new WalletCard.Builder(
                CARD_ID, INVALID_CARD_IMAGE, CARD_DESCRIPTION, pendingIntent).build();
    }


}
+5 −5
Original line number Diff line number Diff line
@@ -243,15 +243,15 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
            }
            mSelectedCard = cards.get(selectedIndex);
            switch (mSelectedCard.getCardImage().getType()) {
                case TYPE_BITMAP:
                case TYPE_ADAPTIVE_BITMAP:
                    mCardViewDrawable = mSelectedCard.getCardImage().loadDrawable(mContext);
                    break;
                case TYPE_URI:
                case TYPE_URI_ADAPTIVE_BITMAP:
                    mCardViewDrawable = null;
                    break;
                case TYPE_RESOURCE:
                case TYPE_BITMAP:
                case TYPE_ADAPTIVE_BITMAP:
                case TYPE_DATA:
                    mCardViewDrawable = mSelectedCard.getCardImage().loadDrawable(mContext);
                    mCardViewDrawable = null;
                    break;
                default:
                    Log.e(TAG, "Unknown icon type: " + mSelectedCard.getCardImage().getType());
+10 −4
Original line number Diff line number Diff line
@@ -330,13 +330,19 @@ public class WalletScreenController implements
        QAWalletCardViewInfo(Context context, WalletCard walletCard) {
            mWalletCard = walletCard;
            Icon cardImageIcon = mWalletCard.getCardImage();
            if (cardImageIcon.getType() == Icon.TYPE_URI) {
                mCardDrawable = null;
            } else {
            if (cardImageIcon.getType() == Icon.TYPE_BITMAP
                    || cardImageIcon.getType() == Icon.TYPE_ADAPTIVE_BITMAP) {
                mCardDrawable = mWalletCard.getCardImage().loadDrawable(context);
            } else {
                mCardDrawable = null;
            }
            Icon icon = mWalletCard.getCardIcon();
            mIconDrawable = icon == null ? null : icon.loadDrawable(context);
            if (icon != null && (icon.getType() == Icon.TYPE_BITMAP
                    || icon.getType() == Icon.TYPE_ADAPTIVE_BITMAP)) {
                mIconDrawable = icon.loadDrawable(context);
            } else {
                mIconDrawable = null;
            }
        }

        @Override
+5 −0
Original line number Diff line number Diff line
@@ -283,6 +283,11 @@ public class WalletView extends FrameLayout implements WalletCardCarousel.OnCard
        return mCardLabel;
    }

    @VisibleForTesting
    ImageView getIcon() {
        return mIcon;
    }

    @Nullable
    private static Drawable getHeaderIcon(Context context, WalletCardViewInfo walletCard) {
        Drawable icon = walletCard.getIcon();
+39 −0
Original line number Diff line number Diff line
@@ -315,6 +315,31 @@ public class WalletScreenControllerTest extends SysuiTestCase {
        assertEquals(GONE, mWalletView.getErrorView().getVisibility());
    }

    @Test
    public void queryCards_hasCards_showCarousel_invalidIconSource_noIcon() {
        GetWalletCardsResponse response =
                new GetWalletCardsResponse(
                        Collections.singletonList(createWalletCardWithInvalidIcon(mContext)), 0);

        mController.queryWalletCards();
        mTestableLooper.processAllMessages();

        verify(mWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture());

        QuickAccessWalletClient.OnWalletCardsRetrievedCallback callback =
                mCallbackCaptor.getValue();

        assertEquals(mController, callback);

        callback.onWalletCardsRetrieved(response);
        mTestableLooper.processAllMessages();

        assertEquals(VISIBLE, mWalletView.getCardCarousel().getVisibility());
        assertEquals(GONE, mWalletView.getEmptyStateView().getVisibility());
        assertEquals(GONE, mWalletView.getErrorView().getVisibility());
        assertEquals(null, mWalletView.getIcon().getDrawable());
    }

    @Test
    public void queryCards_noCards_showEmptyState() {
        GetWalletCardsResponse response = new GetWalletCardsResponse(Collections.EMPTY_LIST, 0);
@@ -507,6 +532,16 @@ public class WalletScreenControllerTest extends SysuiTestCase {
                .build();
    }

    private WalletCard createWalletCardWithInvalidIcon(Context context) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
        return new WalletCard.Builder(
                CARD_ID_1, createIconWithInvalidSource(), "•••• 1234", pendingIntent)
                .setCardIcon(createIconWithInvalidSource())
                .setCardLabel("Hold to reader")
                .build();
    }

    private WalletCard createCrazyWalletCard(Context context, boolean hasLabel) {
        PendingIntent pendingIntent =
                PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
@@ -520,6 +555,10 @@ public class WalletScreenControllerTest extends SysuiTestCase {
        return Icon.createWithBitmap(Bitmap.createBitmap(70, 44, Bitmap.Config.ARGB_8888));
    }

    private static Icon createIconWithInvalidSource() {
        return Icon.createWithContentUri("content://media/external/images/media");
    }

    private WalletCardViewInfo createCardViewInfo(WalletCard walletCard) {
        return new WalletScreenController.QAWalletCardViewInfo(
                mContext, walletCard);