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

Commit bac848b9 authored by Omer Ozer's avatar Omer Ozer
Browse files

Change quickaccess tile logic for when the wallet role

is available and support Wallet Role being None.

Bug: 331247530
Test: manual and atest SystemUITests
Flag: ACONFIG android.permission.flags.wallet_role_enabled TRUNKFOOD
Change-Id: I517f72612fcb5f0ba6082b0b8ea29d45ce2775c1
parent 5af800b9
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -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);
        } 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) {
+4 −2
Original line number Diff line number Diff line
@@ -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
                    )
                }
            }
+7 −0
Original line number Diff line number Diff line
@@ -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() {
+7 −2
Original line number Diff line number Diff line
@@ -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.
     */
+13 −2
Original line number Diff line number Diff line
@@ -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,
@@ -207,6 +208,16 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
        assertTrue(mTile.isAvailable());
    }

    @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);
Loading