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

Commit 01db1e3c authored by Silin Huang's avatar Silin Huang
Browse files

Launch WalletActivity on Wallet Tile clicked.

If it has cards, open the WalletActivity; otherwise open the wallet app
(e.g. Google Pay).
The WalletActivity can monitor the KeyguardState- if it's locked, prompt
the user to unlock to use the wallet, and once it's unlocked, reload the
"ready to use" UI.
Also a few UI tweaks on the Wallet card carousel screen.

Test: manually test on device, see demo video
https://drive.google.com/file/d/1BzHnEnb0rWGZ1r9_go4pYgzE9A9aStDr/view?usp=sharing&resourcekey=0-Zp1277CmmrlpRGS06d395w
Test: atest
Bug: b/184490333
Bug: b/184306042
Change-Id: Ifcfb8c35ffaff3d5fcda0448f9999965c0a9159c
parent 245ce41e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -18,5 +18,6 @@
    <size
        android:height="50dp"
        android:width="50dp" />
        <solid android:color="#1A73E8" />
    <solid android:color="@android:color/transparent" />
    <stroke android:width="2dp" android:color="#AECBFA" />
</shape>
+18 −5
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.wallet.ui.WalletActivity;

import java.util.List;
import java.util.concurrent.Executor;
@@ -117,9 +118,23 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {

    @Override
    protected void handleClick() {
        mUiHandler.post(() -> {
            mHost.collapsePanels();
            if (mHasCard) {
                Intent intent = new Intent(mContext, WalletActivity.class)
                        .setAction(Intent.ACTION_VIEW)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            } else {
                if (mQuickAccessWalletClient.createWalletIntent() == null) {
                    Log.w(TAG, "Could not get intent of the wallet app.");
                    return;
                }
                mActivityStarter.postStartActivityDismissingKeyguard(
                        mQuickAccessWalletClient.createWalletIntent(), /* delay= */ 0);
            }
        });
    }

    @Override
    protected void handleUpdateState(State state, Object arg) {
@@ -147,9 +162,7 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
        } else {
            state.state = Tile.STATE_UNAVAILABLE;
        }
        if (!isDeviceLocked) {
            state.sideViewDrawable = mCardViewDrawable;
        }
        state.sideViewDrawable = isDeviceLocked ? null : mCardViewDrawable;
    }

    @Override
+20 −4
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ import androidx.annotation.NonNull;

import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.LifecycleActivity;

@@ -44,6 +46,7 @@ public class WalletActivity extends LifecycleActivity {

    private final QuickAccessWalletClient mQuickAccessWalletClient;
    private final KeyguardStateController mKeyguardStateController;
    private final KeyguardDismissUtil mKeyguardDismissUtil;
    private final ActivityStarter mActivityStarter;
    private final Executor mExecutor;
    private final Handler mHandler;
@@ -54,12 +57,14 @@ public class WalletActivity extends LifecycleActivity {
    public WalletActivity(
            QuickAccessWalletClient quickAccessWalletClient,
            KeyguardStateController keyguardStateController,
            KeyguardDismissUtil keyguardDismissUtil,
            ActivityStarter activityStarter,
            @Background Executor executor,
            @Background Handler handler,
            @Main Handler handler,
            UserTracker userTracker) {
        mQuickAccessWalletClient = quickAccessWalletClient;
        mKeyguardStateController = keyguardStateController;
        mKeyguardDismissUtil = keyguardDismissUtil;
        mActivityStarter = activityStarter;
        mExecutor = executor;
        mHandler = handler;
@@ -88,20 +93,30 @@ public class WalletActivity extends LifecycleActivity {
                mExecutor,
                mHandler,
                mUserTracker,
                !mKeyguardStateController.isUnlocked());
                mKeyguardStateController);
        // Clicking the wallet button will open the wallet app if the device is unlocked; bring up
        // the security bouncer otherwise.
        walletView.getWalletButton().setOnClickListener(
                v -> mActivityStarter.startActivity(
                        mQuickAccessWalletClient.createWalletIntent(), true));
                v -> {
                    if (mKeyguardStateController.isUnlocked()) {
                        mActivityStarter.startActivity(
                                mQuickAccessWalletClient.createWalletIntent(), true);
                    } else {
                        mKeyguardDismissUtil.executeWhenUnlocked(() -> false, false);
                    }
                });
    }

    @Override
    protected void onStart() {
        super.onStart();
        mKeyguardStateController.addCallback(mWalletScreenController);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mWalletScreenController.queryWalletCards();
    }

    @Override
@@ -116,6 +131,7 @@ public class WalletActivity extends LifecycleActivity {

    @Override
    protected void onDestroy() {
        mKeyguardStateController.removeCallback(mWalletScreenController);
        mWalletScreenController.onDismissed();
        super.onDestroy();
    }
+21 −8
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.R;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.KeyguardStateController;

import java.util.ArrayList;
import java.util.List;
@@ -52,7 +53,8 @@ import java.util.concurrent.TimeUnit;
public class WalletScreenController implements
        WalletCardCarousel.OnSelectionListener,
        QuickAccessWalletClient.OnWalletCardsRetrievedCallback,
        QuickAccessWalletClient.WalletServiceEventListener {
        QuickAccessWalletClient.WalletServiceEventListener,
        KeyguardStateController.Callback {

    private static final String TAG = "WalletScreenCtrl";
    private static final String PREFS_HAS_CARDS = "has_cards";
@@ -65,6 +67,7 @@ public class WalletScreenController implements
    private final ActivityStarter mActivityStarter;
    private final Executor mExecutor;
    private final Handler mHandler;
    private final KeyguardStateController mKeyguardStateController;
    private final Runnable mSelectionRunnable = this::selectCard;
    private final SharedPreferences mPrefs;
    private final WalletView mWalletView;
@@ -72,7 +75,6 @@ public class WalletScreenController implements

    @VisibleForTesting String mSelectedCardId;
    @VisibleForTesting boolean mIsDismissed;
    private boolean mIsDeviceLocked;
    private boolean mHasRegisteredListener;

    public WalletScreenController(
@@ -83,12 +85,13 @@ public class WalletScreenController implements
            Executor executor,
            Handler handler,
            UserTracker userTracker,
            boolean isDeviceLocked) {
            KeyguardStateController keyguardStateController) {
        mContext = context;
        mWalletClient = walletClient;
        mActivityStarter = activityStarter;
        mExecutor = executor;
        mHandler = handler;
        mKeyguardStateController = keyguardStateController;
        mPrefs = userTracker.getUserContext().getSharedPreferences(TAG, Context.MODE_PRIVATE);
        mWalletView = walletView;
        mWalletView.setMinimumHeight(getExpectedMinHeight());
@@ -105,7 +108,6 @@ public class WalletScreenController implements
            // to decrease perceived latency.
            showEmptyStateView();
        }
        mIsDeviceLocked = isDeviceLocked;
    }

    /**
@@ -122,11 +124,17 @@ public class WalletScreenController implements
        for (WalletCard card : walletCards) {
            data.add(new QAWalletCardViewInfo(mContext, card));
        }

        // Get on main thread for UI updates.
        mHandler.post(() -> {
            if (mIsDismissed) {
                return;
            }
            if (data.isEmpty()) {
                showEmptyStateView();
            } else {
                mWalletView.showCardCarousel(data, response.getSelectedIndex(), mIsDeviceLocked);
                mWalletView.showCardCarousel(
                        data, response.getSelectedIndex(), !mKeyguardStateController.isUnlocked());
            }
            // The empty state view will not be shown preemptively next time if cards were returned
            mPrefs.edit().putBoolean(PREFS_HAS_CARDS, !data.isEmpty()).apply();
@@ -140,10 +148,10 @@ public class WalletScreenController implements
     */
    @Override
    public void onWalletCardRetrievalError(@NonNull GetWalletCardsError error) {
        mHandler.post(() -> {
            if (mIsDismissed) {
                return;
            }
        mHandler.post(() -> {
            mWalletView.showErrorMessage(error.getMessage());
        });
    }
@@ -169,6 +177,11 @@ public class WalletScreenController implements
        }
    }

    @Override
    public void onKeyguardFadingAwayChanged() {
        queryWalletCards();
    }

    @Override
    public void onCardSelected(@NonNull WalletCardViewInfo card) {
        if (mIsDismissed) {
+3 −2
Original line number Diff line number Diff line
@@ -103,7 +103,9 @@ public class WalletView extends FrameLayout implements WalletCardCarousel.OnCard
        CharSequence centerCardText = centerCard.getLabel();
        Drawable icon = centerCard.getIcon();
        if (icon != null) {
            mIcon.setImageDrawable(resizeDrawable(getResources(), icon));
            Drawable drawable = resizeDrawable(getResources(), icon);
            drawable.setTint(mContext.getColor(R.color.GM2_blue_600));
            mIcon.setImageDrawable(drawable);
            mIcon.setVisibility(VISIBLE);
        } else {
            mIcon.setVisibility(INVISIBLE);
@@ -126,7 +128,6 @@ public class WalletView extends FrameLayout implements WalletCardCarousel.OnCard
        mCardCarouselContainer.setVisibility(VISIBLE);
        mErrorView.setVisibility(GONE);
        if (isDeviceLocked) {
            // TODO(b/182964813): Add click action to prompt device unlock.
            mWalletButton.setText(R.string.wallet_button_label_device_locked);
        } else {
            mWalletButton.setText(R.string.wallet_button_label_device_unlocked);
Loading