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

Commit d3cfe620 authored by Sean Pont's avatar Sean Pont
Browse files

Use POWER_MENU_LOCKED_SHOW_CONTENT in wallet

Use POWER_MENU_LOCKED_SHOW_CONTENT to control lock screen behavior for
the Quick Access Wallet.
Do not provide Intents that will fail to start an Activity.
Update comments.

Bug:155232731
Bug:155186709
Test: manual
Test: atest CtsQuickAccessWalletTestCases

Change-Id: I78e5355a69d666aee6dd122389edabed170f07b2
parent a1f9485d
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -2020,8 +2020,7 @@ public final class Settings {
     * In some cases, a matching Activity may not exist, so ensure you
     * In some cases, a matching Activity may not exist, so ensure you
     * safeguard against this.
     * safeguard against this.
     * <p>
     * <p>
     * Input: The Intent's data URI specifies the application package name
     * Input: Nothing.
     * to be shown, with the "package" scheme.  That is "package:com.my.app".
     * <p>
     * <p>
     * Output: Nothing.
     * Output: Nothing.
     */
     */
+58 −14
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.service.quickaccesswallet;
package android.service.quickaccesswallet;


import static android.service.quickaccesswallet.QuickAccessWalletService.ACTION_VIEW_WALLET;
import static android.service.quickaccesswallet.QuickAccessWalletService.ACTION_VIEW_WALLET_SETTINGS;
import static android.service.quickaccesswallet.QuickAccessWalletService.SERVICE_INTERFACE;
import static android.service.quickaccesswallet.QuickAccessWalletService.SERVICE_INTERFACE;


import android.annotation.CallbackExecutor;
import android.annotation.CallbackExecutor;
@@ -26,6 +28,9 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Handler;
import android.os.IBinder;
import android.os.IBinder;
@@ -97,8 +102,7 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser


    @Override
    @Override
    public boolean isWalletFeatureAvailableWhenDeviceLocked() {
    public boolean isWalletFeatureAvailableWhenDeviceLocked() {
        return checkSecureSetting(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS)
        return checkSecureSetting(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT);
                && checkSecureSetting(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
    }
    }


    @Override
    @Override
@@ -234,27 +238,67 @@ public class QuickAccessWalletClientImpl implements QuickAccessWalletClient, Ser
    @Override
    @Override
    @Nullable
    @Nullable
    public Intent createWalletIntent() {
    public Intent createWalletIntent() {
        if (mServiceInfo == null || TextUtils.isEmpty(mServiceInfo.getWalletActivity())) {
        if (mServiceInfo == null) {
            return null;
            return null;
        }
        }
        return new Intent(QuickAccessWalletService.ACTION_VIEW_WALLET)
        String packageName = mServiceInfo.getComponentName().getPackageName();
                .setComponent(
        String walletActivity = mServiceInfo.getWalletActivity();
                        new ComponentName(
        return createIntent(walletActivity, packageName, ACTION_VIEW_WALLET);
                                mServiceInfo.getComponentName().getPackageName(),
                                mServiceInfo.getWalletActivity()));
    }
    }


    @Override
    @Override
    @Nullable
    @Nullable
    public Intent createWalletSettingsIntent() {
    public Intent createWalletSettingsIntent() {
        if (mServiceInfo == null || TextUtils.isEmpty(mServiceInfo.getSettingsActivity())) {
        if (mServiceInfo == null) {
            return null;
            return null;
        }
        }
        return new Intent(QuickAccessWalletService.ACTION_VIEW_WALLET_SETTINGS)
        String packageName = mServiceInfo.getComponentName().getPackageName();
                .setComponent(
        String settingsActivity = mServiceInfo.getSettingsActivity();
                        new ComponentName(
        return createIntent(settingsActivity, packageName, ACTION_VIEW_WALLET_SETTINGS);
                                mServiceInfo.getComponentName().getPackageName(),
    }
                                mServiceInfo.getSettingsActivity()));

    @Nullable
    private Intent createIntent(@Nullable String activityName, String packageName, String action) {
        PackageManager pm = mContext.getPackageManager();
        if (TextUtils.isEmpty(activityName)) {
            activityName = queryActivityForAction(pm, packageName, action);
        }
        if (TextUtils.isEmpty(activityName)) {
            return null;
        }
        ComponentName component = new ComponentName(packageName, activityName);
        if (!isActivityEnabled(pm, component)) {
            return null;
        }
        return new Intent(action).setComponent(component);
    }

    @Nullable
    private static String queryActivityForAction(PackageManager pm, String packageName,
            String action) {
        Intent intent = new Intent(action).setPackage(packageName);
        ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
        if (resolveInfo == null
                || resolveInfo.activityInfo == null
                || !resolveInfo.activityInfo.exported) {
            return null;
        }
        return resolveInfo.activityInfo.name;
    }

    private static boolean isActivityEnabled(PackageManager pm, ComponentName component) {
        int setting = pm.getComponentEnabledSetting(component);
        if (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
            return true;
        }
        if (setting != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
            return false;
        }
        try {
            return pm.getActivityInfo(component, 0).isEnabled();
        } catch (NameNotFoundException e) {
            return false;
        }
    }
    }


    @Override
    @Override