Merge "WalletTile should display the default card of wallet." into sc-dev

This commit is contained in:
Silin Huang
2021-04-29 17:24:39 +00:00
committed by Android (Google) Code Review
2 changed files with 36 additions and 6 deletions

View File

@@ -129,8 +129,15 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
Intent intent = new Intent(mContext, WalletActivity.class) Intent intent = new Intent(mContext, WalletActivity.class)
.setAction(Intent.ACTION_VIEW) .setAction(Intent.ACTION_VIEW)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
mActivityStarter.startActivity(intent, true /* dismissShade */, if (mKeyguardStateController.isUnlocked()) {
animationController); mActivityStarter.startActivity(intent, true /* dismissShade */,
animationController);
} else {
mHost.collapsePanels();
// Do not use ActivityStarter here because the WalletActivity is required to be
// started without prompting keyguard when the device is locked.
mContext.startActivity(intent);
}
} else { } else {
if (mQuickAccessWalletClient.createWalletIntent() == null) { if (mQuickAccessWalletClient.createWalletIntent() == null) {
Log.w(TAG, "Could not get intent of the wallet app."); Log.w(TAG, "Could not get intent of the wallet app.");
@@ -147,7 +154,7 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
protected void handleUpdateState(State state, Object arg) { protected void handleUpdateState(State state, Object arg) {
state.label = mLabel; state.label = mLabel;
state.contentDescription = state.label; state.contentDescription = state.label;
state.icon = ResourceIcon.get(R.drawable.ic_qs_wallet); state.icon = ResourceIcon.get(R.drawable.ic_wallet_lockscreen);
boolean isDeviceLocked = !mKeyguardStateController.isUnlocked(); boolean isDeviceLocked = !mKeyguardStateController.isUnlocked();
if (mQuickAccessWalletClient.isWalletServiceAvailable()) { if (mQuickAccessWalletClient.isWalletServiceAvailable()) {
if (mHasCard) { if (mHasCard) {
@@ -219,7 +226,12 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
refreshState(); refreshState();
return; return;
} }
mCardViewDrawable = cards.get(0).getCardImage().loadDrawable(mContext); int selectedIndex = response.getSelectedIndex();
if (selectedIndex >= cards.size()) {
Log.d(TAG, "Selected card index out of bounds.");
return;
}
mCardViewDrawable = cards.get(selectedIndex).getCardImage().loadDrawable(mContext);
mHasCard = true; mHasCard = true;
refreshState(); refreshState();
} }

View File

@@ -207,7 +207,25 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
} }
@Test @Test
public void testHandleClick_hasCards_startWalletActivity() { public void testHandleClick_hasCards_deviceLocked_startWalletActivity() {
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
setUpWalletCard(/* hasCard= */ true);
mTile.handleClick(null /* view */);
mTestableLooper.processAllMessages();
verify(mSpiedContext).startActivity(mIntentCaptor.capture());
Intent nextStartedIntent = mIntentCaptor.getValue();
String walletClassName = "com.android.systemui.wallet.ui.WalletActivity";
assertNotNull(nextStartedIntent);
assertThat(nextStartedIntent.getComponent().getClassName()).isEqualTo(walletClassName);
}
@Test
public void testHandleClick_hasCards_deviceUnlocked_startWalletActivity() {
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
setUpWalletCard(/* hasCard= */ true); setUpWalletCard(/* hasCard= */ true);
mTile.handleClick(null /* view */); mTile.handleClick(null /* view */);
@@ -226,7 +244,7 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
@Test @Test
public void testHandleUpdateState_updateLabelAndIcon() { public void testHandleUpdateState_updateLabelAndIcon() {
QSTile.State state = new QSTile.State(); QSTile.State state = new QSTile.State();
QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_wallet); QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_wallet_lockscreen);
mTile.handleUpdateState(state, null); mTile.handleUpdateState(state, null);