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

Commit 2fa1c954 authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Adds NON_BROWSER & DEFAULT match flags

This change adds two new flags for starting activities:
FLAG_ACTIVITY_REQUIRE_NON_BROWSER and FLAG_ACTIVITY_REQUIRE_DEFAULT.
The first will only start if the result is a non-browser result. The
second will only start if the result is not the resolver activity.

Bug: 148452357
Test: Builds
Change-Id: I1f25bd78b6231c08036c15436bd8c2e3dccf56d6
parent b55d7214
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -10827,6 +10827,8 @@ package android.content {
    field public static final int FLAG_ACTIVITY_NO_USER_ACTION = 262144; // 0x40000
    field public static final int FLAG_ACTIVITY_NO_USER_ACTION = 262144; // 0x40000
    field public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 16777216; // 0x1000000
    field public static final int FLAG_ACTIVITY_PREVIOUS_IS_TOP = 16777216; // 0x1000000
    field public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 131072; // 0x20000
    field public static final int FLAG_ACTIVITY_REORDER_TO_FRONT = 131072; // 0x20000
    field public static final int FLAG_ACTIVITY_REQUIRE_DEFAULT = 512; // 0x200
    field public static final int FLAG_ACTIVITY_REQUIRE_NON_BROWSER = 1024; // 0x400
    field public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 2097152; // 0x200000
    field public static final int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED = 2097152; // 0x200000
    field public static final int FLAG_ACTIVITY_RETAIN_IN_RECENTS = 8192; // 0x2000
    field public static final int FLAG_ACTIVITY_RETAIN_IN_RECENTS = 8192; // 0x2000
    field public static final int FLAG_ACTIVITY_SINGLE_TOP = 536870912; // 0x20000000
    field public static final int FLAG_ACTIVITY_SINGLE_TOP = 536870912; // 0x20000000
+15 −0
Original line number Original line Diff line number Diff line
@@ -6477,6 +6477,21 @@ public class Intent implements Parcelable, Cloneable {
     */
     */
    public static final int FLAG_ACTIVITY_MATCH_EXTERNAL = 0x00000800;
    public static final int FLAG_ACTIVITY_MATCH_EXTERNAL = 0x00000800;


    /**
     * If set in an intent passed to {@link Context#startActivity Context.startActivity()}, this
     * flag will only launch the intent if it resolves to a result that is not a browser. If no such
     * result exists, an {@link ActivityNotFoundException} will be thrown.
     */
    public static final int FLAG_ACTIVITY_REQUIRE_NON_BROWSER = 0x00000400;

    /**
     * If set in an intent passed to {@link Context#startActivity Context.startActivity()}, this
     * flag will only launch the intent if it resolves to a single result. If no such result exists
     * or if the system chooser would otherwise be displayed, an {@link ActivityNotFoundException}
     * will be thrown.
     */
    public static final int FLAG_ACTIVITY_REQUIRE_DEFAULT = 0x00000200;

    /**
    /**
     * If set, when sending a broadcast only registered receivers will be
     * If set, when sending a broadcast only registered receivers will be
     * called -- no BroadcastReceiver components will be launched.
     * called -- no BroadcastReceiver components will be launched.
+21 −1
Original line number Original line Diff line number Diff line
@@ -69,6 +69,25 @@ public abstract class PackageManagerInternal {
    public static final int PACKAGE_COMPANION = 14;
    public static final int PACKAGE_COMPANION = 14;
    public static final int PACKAGE_RETAIL_DEMO = 15;
    public static final int PACKAGE_RETAIL_DEMO = 15;


    @IntDef(flag = true, prefix = "RESOLVE_", value = {
            RESOLVE_NON_BROWSER_ONLY,
            RESOLVE_NON_RESOLVER_ONLY
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface PrivateResolveFlags {}

    /**
     * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag:
     * only match components that contain a generic web intent filter.
     */
    public static final int RESOLVE_NON_BROWSER_ONLY = 0x00000001;

    /**
     * Internal {@link #resolveIntent(Intent, String, int, int, int, boolean, int)} flag: do not
     * match to the resolver.
     */
    public static final int RESOLVE_NON_RESOLVER_ONLY = 0x00000002;

    @IntDef(value = {
    @IntDef(value = {
            INTEGRITY_VERIFICATION_ALLOW,
            INTEGRITY_VERIFICATION_ALLOW,
            INTEGRITY_VERIFICATION_REJECT,
            INTEGRITY_VERIFICATION_REJECT,
@@ -507,7 +526,8 @@ public abstract class PackageManagerInternal {
     * Resolves an activity intent, allowing instant apps to be resolved.
     * Resolves an activity intent, allowing instant apps to be resolved.
     */
     */
    public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
    public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
            int flags, int userId, boolean resolveForStart, int filterCallingUid);
            int flags, @PrivateResolveFlags int privateResolveFlags, int userId,
            boolean resolveForStart, int filterCallingUid);


    /**
    /**
    * Resolves a service intent, allowing instant apps to be resolved.
    * Resolves a service intent, allowing instant apps to be resolved.
+14 −4
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.pm.AuxiliaryResolveInfo;
import android.content.pm.InstantAppResolveInfo;
import android.content.pm.InstantAppResolveInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal.PrivateResolveFlags;
import android.content.pm.PackageUserState;
import android.content.pm.PackageUserState;
import android.content.pm.ProviderInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
@@ -229,9 +230,11 @@ public class ComponentResolver {
    }
    }


    @Nullable
    @Nullable
    List<ResolveInfo> queryActivities(Intent intent, String resolvedType, int flags, int userId) {
    List<ResolveInfo> queryActivities(Intent intent, String resolvedType, int flags,
            @PrivateResolveFlags int privateResolveFlags, int userId) {
        synchronized (mLock) {
        synchronized (mLock) {
            return mActivities.queryIntent(intent, resolvedType, flags, userId);
            return mActivities.queryIntent(
                    intent, resolvedType, flags, privateResolveFlags, userId);
        }
        }
    }
    }


@@ -368,7 +371,7 @@ public class ComponentResolver {
    @Nullable
    @Nullable
    List<ResolveInfo> queryReceivers(Intent intent, String resolvedType, int flags, int userId) {
    List<ResolveInfo> queryReceivers(Intent intent, String resolvedType, int flags, int userId) {
        synchronized (mLock) {
        synchronized (mLock) {
            return mReceivers.queryIntent(intent, resolvedType, flags, userId);
            return mReceivers.queryIntent(intent, resolvedType, flags, 0, userId);
        }
        }
    }
    }


@@ -1154,11 +1157,12 @@ public class ComponentResolver {
        }
        }


        List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
        List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
                int userId) {
                int privateResolveFlags, int userId) {
            if (!sUserManager.exists(userId)) {
            if (!sUserManager.exists(userId)) {
                return null;
                return null;
            }
            }
            mFlags = flags;
            mFlags = flags;
            mPrivateResolveFlags = privateResolveFlags;
            return super.queryIntent(intent, resolvedType,
            return super.queryIntent(intent, resolvedType,
                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0,
                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0,
                    userId);
                    userId);
@@ -1388,6 +1392,11 @@ public class ComponentResolver {
                }
                }
                return null;
                return null;
            }
            }
            final boolean matchNonBrowserOnly =
                    (mPrivateResolveFlags & PackageManagerInternal.RESOLVE_NON_BROWSER_ONLY) != 0;
            if (matchNonBrowserOnly && info.handleAllWebDataURI()) {
                return null;
            }
            final ResolveInfo res = new ResolveInfo();
            final ResolveInfo res = new ResolveInfo();
            res.activityInfo = ai;
            res.activityInfo = ai;
            if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
            if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
@@ -1465,6 +1474,7 @@ public class ComponentResolver {
        private final ArrayMap<ComponentName, ParsedActivity> mActivities =
        private final ArrayMap<ComponentName, ParsedActivity> mActivities =
                new ArrayMap<>();
                new ArrayMap<>();
        private int mFlags;
        private int mFlags;
        private int mPrivateResolveFlags;
    }
    }


    // Both receivers and activities share a class, but point to different get methods
    // Both receivers and activities share a class, but point to different get methods
+31 −20
Original line number Original line Diff line number Diff line
@@ -179,6 +179,7 @@ import android.content.pm.PackageManager.LegacyPackageDeleteObserver;
import android.content.pm.PackageManager.ModuleInfoFlags;
import android.content.pm.PackageManager.ModuleInfoFlags;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal.PackageListObserver;
import android.content.pm.PackageManagerInternal.PackageListObserver;
import android.content.pm.PackageManagerInternal.PrivateResolveFlags;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser.PackageLite;
import android.content.pm.PackageParser.PackageLite;
import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.PackageParser.PackageParserException;
@@ -6128,8 +6129,8 @@ public class PackageManagerService extends IPackageManager.Stub
    @Override
    @Override
    public ResolveInfo resolveIntent(Intent intent, String resolvedType,
    public ResolveInfo resolveIntent(Intent intent, String resolvedType,
            int flags, int userId) {
            int flags, int userId) {
        return resolveIntentInternal(intent, resolvedType, flags, userId, false,
        return resolveIntentInternal(intent, resolvedType, flags, 0 /*privateResolveFlags*/,
                Binder.getCallingUid());
                userId, false, Binder.getCallingUid());
    }
    }
    /**
    /**
@@ -6137,8 +6138,9 @@ public class PackageManagerService extends IPackageManager.Stub
     * However, if {@code resolveForStart} is {@code true}, all instant apps are visible
     * However, if {@code resolveForStart} is {@code true}, all instant apps are visible
     * since we need to allow the system to start any installed application.
     * since we need to allow the system to start any installed application.
     */
     */
    private ResolveInfo resolveIntentInternal(Intent intent, String resolvedType,
    private ResolveInfo resolveIntentInternal(Intent intent, String resolvedType, int flags,
            int flags, int userId, boolean resolveForStart, int filterCallingUid) {
            @PrivateResolveFlags int privateResolveFlags, int userId, boolean resolveForStart,
            int filterCallingUid) {
        try {
        try {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveIntent");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveIntent");
@@ -6150,11 +6152,13 @@ public class PackageManagerService extends IPackageManager.Stub
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "queryIntentActivities");
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "queryIntentActivities");
            final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType,
            final List<ResolveInfo> query = queryIntentActivitiesInternal(intent, resolvedType,
                    flags, filterCallingUid, userId, resolveForStart, true /*allowDynamicSplits*/);
                    flags, privateResolveFlags, filterCallingUid, userId, resolveForStart,
                    true /*allowDynamicSplits*/);
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            final ResolveInfo bestChoice =
            final ResolveInfo bestChoice =
                    chooseBestActivity(intent, resolvedType, flags, query, userId);
                    chooseBestActivity(
                            intent, resolvedType, flags, privateResolveFlags, query, userId);
            return bestChoice;
            return bestChoice;
        } finally {
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
@@ -6312,7 +6316,7 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    }
    private ResolveInfo chooseBestActivity(Intent intent, String resolvedType,
    private ResolveInfo chooseBestActivity(Intent intent, String resolvedType,
            int flags, List<ResolveInfo> query, int userId) {
            int flags, int privateResolveFlags, List<ResolveInfo> query, int userId) {
        if (query != null) {
        if (query != null) {
            final int N = query.size();
            final int N = query.size();
            if (N == 1) {
            if (N == 1) {
@@ -6354,6 +6358,10 @@ public class PackageManagerService extends IPackageManager.Stub
                        }
                        }
                    }
                    }
                }
                }
                if ((privateResolveFlags
                        & PackageManagerInternal.RESOLVE_NON_RESOLVER_ONLY) != 0) {
                    return null;
                }
                ri = new ResolveInfo(mResolveInfo);
                ri = new ResolveInfo(mResolveInfo);
                ri.activityInfo = new ActivityInfo(ri.activityInfo);
                ri.activityInfo = new ActivityInfo(ri.activityInfo);
                ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction());
                ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction());
@@ -6767,13 +6775,13 @@ public class PackageManagerService extends IPackageManager.Stub
    private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent,
    private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent,
            String resolvedType, int flags, int userId) {
            String resolvedType, int flags, int userId) {
        return queryIntentActivitiesInternal(
        return queryIntentActivitiesInternal(
                intent, resolvedType, flags, Binder.getCallingUid(), userId,
                intent, resolvedType, flags, 0 /*privateResolveFlags*/, Binder.getCallingUid(),
                false /*resolveForStart*/, true /*allowDynamicSplits*/);
                userId, false /*resolveForStart*/, true /*allowDynamicSplits*/);
    }
    }
    private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent,
    private @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent,
            String resolvedType, int flags, int filterCallingUid, int userId,
            String resolvedType, int flags, @PrivateResolveFlags int privateResolveFlags,
            boolean resolveForStart, boolean allowDynamicSplits) {
            int filterCallingUid, int userId, boolean resolveForStart, boolean allowDynamicSplits) {
        if (!mUserManager.exists(userId)) return Collections.emptyList();
        if (!mUserManager.exists(userId)) return Collections.emptyList();
        final String instantAppPkgName = getInstantAppPackageName(filterCallingUid);
        final String instantAppPkgName = getInstantAppPackageName(filterCallingUid);
        mPermissionManager.enforceCrossUserPermission(Binder.getCallingUid(), userId,
        mPermissionManager.enforceCrossUserPermission(Binder.getCallingUid(), userId,
@@ -6858,7 +6866,7 @@ public class PackageManagerService extends IPackageManager.Stub
                // Check for results in the current profile.
                // Check for results in the current profile.
                result = filterIfNotSystemUser(mComponentResolver.queryActivities(
                result = filterIfNotSystemUser(mComponentResolver.queryActivities(
                        intent, resolvedType, flags, userId), userId);
                        intent, resolvedType, flags, privateResolveFlags, userId), userId);
                addInstant = isInstantAppResolutionAllowed(intent, result, userId,
                addInstant = isInstantAppResolutionAllowed(intent, result, userId,
                        false /*skipPackageCheck*/);
                        false /*skipPackageCheck*/);
                // Check for cross profile results.
                // Check for cross profile results.
@@ -6957,7 +6965,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        | PackageManager.GET_RESOLVED_FILTER
                        | PackageManager.GET_RESOLVED_FILTER
                        | PackageManager.MATCH_INSTANT
                        | PackageManager.MATCH_INSTANT
                        | PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY,
                        | PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY,
                    userId);
                    0, userId);
            for (int i = instantApps.size() - 1; i >= 0; --i) {
            for (int i = instantApps.size() - 1; i >= 0; --i) {
                final ResolveInfo info = instantApps.get(i);
                final ResolveInfo info = instantApps.get(i);
                final String packageName = info.activityInfo.packageName;
                final String packageName = info.activityInfo.packageName;
@@ -7061,7 +7069,7 @@ public class PackageManagerService extends IPackageManager.Stub
            return null;
            return null;
        }
        }
        List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
        List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
                resolvedType, flags, parentUserId);
                resolvedType, flags, 0, parentUserId);
        if (resultTargetUser == null || resultTargetUser.isEmpty()) {
        if (resultTargetUser == null || resultTargetUser.isEmpty()) {
            return null;
            return null;
@@ -7246,8 +7254,9 @@ public class PackageManagerService extends IPackageManager.Stub
        failureActivityIntent.setPackage(packageName);
        failureActivityIntent.setPackage(packageName);
        // IMPORTANT: disallow dynamic splits to avoid an infinite loop
        // IMPORTANT: disallow dynamic splits to avoid an infinite loop
        final List<ResolveInfo> result = queryIntentActivitiesInternal(
        final List<ResolveInfo> result = queryIntentActivitiesInternal(
                failureActivityIntent, null /*resolvedType*/, 0 /*flags*/, filterCallingUid, userId,
                failureActivityIntent, null /*resolvedType*/, 0 /*flags*/,
                false /*resolveForStart*/, false /*allowDynamicSplits*/);
                0 /*privateResolveFlags*/, filterCallingUid, userId, false /*resolveForStart*/,
                false /*allowDynamicSplits*/);
        final int NR = result.size();
        final int NR = result.size();
        if (NR > 0) {
        if (NR > 0) {
            for (int i = 0; i < NR; i++) {
            for (int i = 0; i < NR; i++) {
@@ -7502,7 +7511,7 @@ public class PackageManagerService extends IPackageManager.Stub
            String resolvedType, int flags, int sourceUserId) {
            String resolvedType, int flags, int sourceUserId) {
        int targetUserId = filter.getTargetUserId();
        int targetUserId = filter.getTargetUserId();
        List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
        List<ResolveInfo> resultTargetUser = mComponentResolver.queryActivities(intent,
                resolvedType, flags, targetUserId);
                resolvedType, flags, 0, targetUserId);
        if (resultTargetUser != null && isUserEnabled(targetUserId)) {
        if (resultTargetUser != null && isUserEnabled(targetUserId)) {
            // If all the matches in the target profile are suspended, return null.
            // If all the matches in the target profile are suspended, return null.
            for (int i = resultTargetUser.size() - 1; i >= 0; i--) {
            for (int i = resultTargetUser.size() - 1; i >= 0; i--) {
@@ -23324,7 +23333,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public List<ResolveInfo> queryIntentActivities(
        public List<ResolveInfo> queryIntentActivities(
                Intent intent, String resolvedType, int flags, int filterCallingUid, int userId) {
                Intent intent, String resolvedType, int flags, int filterCallingUid, int userId) {
            return PackageManagerService.this
            return PackageManagerService.this
                    .queryIntentActivitiesInternal(intent, resolvedType, flags, filterCallingUid,
                    .queryIntentActivitiesInternal(intent, resolvedType, flags, 0, filterCallingUid,
                            userId, false /*resolveForStart*/, true /*allowDynamicSplits*/);
                            userId, false /*resolveForStart*/, true /*allowDynamicSplits*/);
        }
        }
@@ -23610,9 +23619,11 @@ public class PackageManagerService extends IPackageManager.Stub
        @Override
        @Override
        public ResolveInfo resolveIntent(Intent intent, String resolvedType,
        public ResolveInfo resolveIntent(Intent intent, String resolvedType,
                int flags, int userId, boolean resolveForStart, int filterCallingUid) {
                int flags, int privateResolveFlags, int userId, boolean resolveForStart,
                int filterCallingUid) {
            return resolveIntentInternal(
            return resolveIntentInternal(
                    intent, resolvedType, flags, userId, resolveForStart, filterCallingUid);
                    intent, resolvedType, flags, privateResolveFlags, userId, resolveForStart,
                    filterCallingUid);
        }
        }
        @Override
        @Override
Loading