summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java23
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt6
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/wallet/controller/QuickAccessWalletController.java9
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/QuickAccessWalletTileTest.java15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/wallet/controller/QuickAccessWalletControllerTest.java27
6 files changed, 73 insertions, 14 deletions
diff --git a/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java b/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java
index e6d8fd0e2f2b..8a3f6ceb852b 100644
--- a/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java
+++ b/core/java/android/service/quickaccesswallet/QuickAccessWalletServiceInfo.java
@@ -71,9 +71,11 @@ class QuickAccessWalletServiceInfo {
@Nullable
static QuickAccessWalletServiceInfo tryCreate(@NonNull Context context) {
- String defaultAppPackageName = getDefaultWalletApp(context);
+ String defaultAppPackageName = null;
- if (defaultAppPackageName == null) {
+ if (isWalletRoleAvailable(context)) {
+ defaultAppPackageName = getDefaultWalletApp(context);
+ } else {
ComponentName defaultPaymentApp = getDefaultPaymentApp(context);
if (defaultPaymentApp == null) {
return null;
@@ -103,14 +105,21 @@ class QuickAccessWalletServiceInfo {
final long token = Binder.clearCallingIdentity();
try {
RoleManager roleManager = context.getSystemService(RoleManager.class);
- if (roleManager.isRoleAvailable(RoleManager.ROLE_WALLET)) {
- List<String> roleHolders = roleManager.getRoleHolders(RoleManager.ROLE_WALLET);
- return roleHolders.isEmpty() ? null : roleHolders.get(0);
- }
+ List<String> roleHolders = roleManager.getRoleHolders(RoleManager.ROLE_WALLET);
+ return roleHolders.isEmpty() ? null : roleHolders.get(0);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ private static boolean isWalletRoleAvailable(Context context) {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ RoleManager roleManager = context.getSystemService(RoleManager.class);
+ return roleManager.isRoleAvailable(RoleManager.ROLE_WALLET);
} finally {
Binder.restoreCallingIdentity(token);
}
- return null;
}
private static ComponentName getDefaultPaymentApp(Context context) {
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt
index 88eadd7be066..b3d9a7670c8a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt
@@ -92,7 +92,8 @@ constructor(
walletController.setupWalletChangeObservers(
callback,
QuickAccessWalletController.WalletChangeEvent.WALLET_PREFERENCE_CHANGE,
- QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
+ QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE,
+ QuickAccessWalletController.WalletChangeEvent.DEFAULT_WALLET_APP_CHANGE
)
withContext(backgroundDispatcher) {
@@ -104,7 +105,8 @@ constructor(
awaitClose {
walletController.unregisterWalletChangeObservers(
QuickAccessWalletController.WalletChangeEvent.WALLET_PREFERENCE_CHANGE,
- QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
+ QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE,
+ QuickAccessWalletController.WalletChangeEvent.DEFAULT_WALLET_APP_CHANGE
)
}
}
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 1b7322592b41..e1b742e1e7f0 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/QuickAccessWalletTile.java
@@ -182,12 +182,19 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
@Override
public boolean isAvailable() {
+ if (isWalletRoleAvailable()) {
+ return !mPackageManager.hasSystemFeature(FEATURE_CHROME_OS);
+ }
return mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
&& !mPackageManager.hasSystemFeature(FEATURE_CHROME_OS)
&& mSecureSettings.getStringForUser(NFC_PAYMENT_DEFAULT_COMPONENT,
UserHandle.USER_CURRENT) != null;
}
+ private boolean isWalletRoleAvailable() {
+ return mHost.getUserId() == UserHandle.USER_SYSTEM && mController.isWalletRoleAvailable();
+ }
+
@Nullable
@Override
public Intent getLongClickIntent() {
diff --git a/packages/SystemUI/src/com/android/systemui/wallet/controller/QuickAccessWalletController.java b/packages/SystemUI/src/com/android/systemui/wallet/controller/QuickAccessWalletController.java
index 1d9b90ac67af..ff1841819dea 100644
--- a/packages/SystemUI/src/com/android/systemui/wallet/controller/QuickAccessWalletController.java
+++ b/packages/SystemUI/src/com/android/systemui/wallet/controller/QuickAccessWalletController.java
@@ -91,17 +91,22 @@ public class QuickAccessWalletController {
@Background Executor bgExecutor,
SecureSettings secureSettings,
QuickAccessWalletClient quickAccessWalletClient,
- SystemClock clock) {
+ SystemClock clock,
+ RoleManager roleManager) {
mContext = context;
mExecutor = executor;
mBgExecutor = bgExecutor;
mSecureSettings = secureSettings;
- mRoleManager = mContext.getSystemService(RoleManager.class);
+ mRoleManager = roleManager;
mQuickAccessWalletClient = quickAccessWalletClient;
mClock = clock;
mQawClientCreatedTimeMillis = mClock.elapsedRealtime();
}
+ public boolean isWalletRoleAvailable() {
+ return mRoleManager.isRoleAvailable(RoleManager.ROLE_WALLET);
+ }
+
/**
* Returns true if the Quick Access Wallet service & feature is available.
*/
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 2d18f9293ec8..122d9e414d13 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
@@ -58,7 +58,6 @@ import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
import com.android.internal.logging.MetricsLogger;
-import com.android.systemui.res.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.classifier.FalsingManagerFake;
import com.android.systemui.plugins.ActivityStarter;
@@ -68,6 +67,7 @@ import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.QsEventLogger;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
+import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.wallet.controller.QuickAccessWalletController;
@@ -198,7 +198,8 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
}
@Test
- public void testIsAvailable_qawFeatureAvailable() {
+ public void testIsAvailable_qawFeatureAvailableWalletUnavailable() {
+ when(mController.isWalletRoleAvailable()).thenReturn(false);
when(mPackageManager.hasSystemFeature(FEATURE_NFC_HOST_CARD_EMULATION)).thenReturn(true);
when(mPackageManager.hasSystemFeature("org.chromium.arc")).thenReturn(false);
when(mSecureSettings.getStringForUser(NFC_PAYMENT_DEFAULT_COMPONENT,
@@ -208,6 +209,16 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
}
@Test
+ public void testIsAvailable_nfcUnavailableWalletAvailable() {
+ when(mController.isWalletRoleAvailable()).thenReturn(true);
+ when(mHost.getUserId()).thenReturn(PRIMARY_USER_ID);
+ when(mPackageManager.hasSystemFeature(FEATURE_NFC_HOST_CARD_EMULATION)).thenReturn(false);
+ when(mPackageManager.hasSystemFeature("org.chromium.arc")).thenReturn(false);
+
+ assertTrue(mTile.isAvailable());
+ }
+
+ @Test
public void testHandleClick_startQuickAccessUiIntent_noCard() {
setUpWalletCard(/* hasCard= */ false);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/QuickAccessWalletControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/QuickAccessWalletControllerTest.java
index fccb936a3bc8..dc5597a1cce0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/QuickAccessWalletControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/wallet/controller/QuickAccessWalletControllerTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.PendingIntent;
+import android.app.role.RoleManager;
import android.content.Intent;
import android.service.quickaccesswallet.GetWalletCardsRequest;
import android.service.quickaccesswallet.QuickAccessWalletClient;
@@ -54,11 +55,14 @@ import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.List;
+
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@SmallTest
public class QuickAccessWalletControllerTest extends SysuiTestCase {
+ private static final String WALLET_ROLE_HOLDER = "wallet.role.holder";
@Mock
private QuickAccessWalletClient mQuickAccessWalletClient;
@Mock
@@ -69,6 +73,8 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
private ActivityStarter mActivityStarter;
@Mock
private ActivityTransitionAnimator.Controller mAnimationController;
+ @Mock
+ private RoleManager mRoleManager;
@Captor
private ArgumentCaptor<GetWalletCardsRequest> mRequestCaptor;
@Captor
@@ -102,7 +108,8 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
MoreExecutors.directExecutor(),
mSecureSettings,
mQuickAccessWalletClient,
- mClock);
+ mClock,
+ mRoleManager);
}
@Test
@@ -113,6 +120,24 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
}
@Test
+ public void walletRoleAvailable_isAvailable() {
+ when(mRoleManager.isRoleAvailable(eq(RoleManager.ROLE_WALLET))).thenReturn(true);
+ when(mRoleManager.getRoleHolders(eq(RoleManager.ROLE_WALLET)))
+ .thenReturn(List.of(WALLET_ROLE_HOLDER));
+
+ assertTrue(mController.isWalletRoleAvailable());
+ }
+
+ @Test
+ public void walletRoleAvailable_isNotAvailable() {
+ when(mRoleManager.isRoleAvailable(eq(RoleManager.ROLE_WALLET))).thenReturn(false);
+ when(mRoleManager.getRoleHolders(eq(RoleManager.ROLE_WALLET)))
+ .thenReturn(List.of(WALLET_ROLE_HOLDER));
+
+ assertFalse(mController.isWalletRoleAvailable());
+ }
+
+ @Test
public void walletServiceUnavailable_walletNotEnabled() {
when(mQuickAccessWalletClient.isWalletServiceAvailable()).thenReturn(false);