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

Commit 1ad90d5a authored by Winson's avatar Winson
Browse files

Fix domain verification CATEGORY_DEFAULT check

The category is actually not added to startActivity Intents
automatically, instead relying on the MATCH_DEFAULT_ONLY flag being set.
This updates the Intent validity check to match.

Bug: 179683649

Test: manual, launch without DEFAULT, with MATCH_DEFAULT_ONLY

Change-Id: I00b78d596ee05c5a4a228771bbf8082af2b0ab8a
parent 0f477048
Loading
Loading
Loading
Loading
+24 −21
Original line number Diff line number Diff line
@@ -1960,9 +1960,10 @@ public class PackageManagerService extends IPackageManager.Stub
        boolean isInstantAppInternal(String packageName, @UserIdInt int userId, int callingUid);
        boolean isInstantAppInternalBody(String packageName, @UserIdInt int userId, int callingUid);
        boolean isInstantAppResolutionAllowed(Intent intent, List<ResolveInfo> resolvedActivities,
                int userId, boolean skipPackageCheck);
                int userId, boolean skipPackageCheck, int flags);
        boolean isInstantAppResolutionAllowedBody(Intent intent,
                List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck);
                List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck,
                int flags);
        boolean isPersistentPreferredActivitySetByDpm(Intent intent, int userId,
                String resolvedType, int flags);
        boolean isRecentsAccessingChildProfiles(int callingUid, int targetUserId);
@@ -2321,7 +2322,7 @@ public class PackageManagerService extends IPackageManager.Stub
                result = filterIfNotSystemUser(mComponentResolver.queryActivities(
                        intent, resolvedType, flags, userId), userId);
                addInstant = isInstantAppResolutionAllowed(intent, result, userId,
                        false /*skipPackageCheck*/);
                        false /*skipPackageCheck*/, flags);
                // Check for cross profile results.
                boolean hasNonNegativePriorityResult = hasNonNegativePriority(result);
                xpResolveInfo = queryCrossProfileIntents(
@@ -2386,8 +2387,8 @@ public class PackageManagerService extends IPackageManager.Stub
                if (result == null || result.size() == 0) {
                    // the caller wants to resolve for a particular package; however, there
                    // were no installed results, so, try to find an ephemeral result
                    addInstant = isInstantAppResolutionAllowed(
                                    intent, null /*result*/, userId, true /*skipPackageCheck*/);
                    addInstant = isInstantAppResolutionAllowed(intent, null /*result*/, userId,
                            true /*skipPackageCheck*/, flags);
                    if (result == null) {
                        result = new ArrayList<>();
                    }
@@ -2617,7 +2618,7 @@ public class PackageManagerService extends IPackageManager.Stub
            // We'll want to include browser possibilities in a few cases
            boolean includeBrowser = false;
            if (!DomainVerificationUtils.isDomainVerificationIntent(intent)) {
            if (!DomainVerificationUtils.isDomainVerificationIntent(intent, matchFlags)) {
                result.addAll(undefinedList);
                // Maybe add one for the other profile.
                if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel
@@ -2801,7 +2802,7 @@ public class PackageManagerService extends IPackageManager.Stub
                }
                result.highestApprovalLevel = Math.max(mDomainVerificationManager
                        .approvalLevelForDomain(ps, intent, riTargetUser.targetUserId),
                        .approvalLevelForDomain(ps, intent, flags, riTargetUser.targetUserId),
                        result.highestApprovalLevel);
            }
            if (result != null && result.highestApprovalLevel
@@ -3048,7 +3049,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    final String packageName = info.activityInfo.packageName;
                    final PackageSetting ps = mSettings.getPackageLPr(packageName);
                    if (ps.getInstantApp(userId)) {
                        if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent,
                        if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent, flags,
                                userId)) {
                            if (DEBUG_INSTANT) {
                                Slog.v(TAG, "Instant app approved for intent; pkg: "
@@ -3927,7 +3928,7 @@ public class PackageManagerService extends IPackageManager.Stub
        public boolean isInstantAppResolutionAllowed(
                Intent intent, List<ResolveInfo> resolvedActivities, int userId,
                boolean skipPackageCheck) {
                boolean skipPackageCheck, int flags) {
            if (mInstantAppResolverConnection == null) {
                return false;
            }
@@ -3960,14 +3961,14 @@ public class PackageManagerService extends IPackageManager.Stub
            // Deny ephemeral apps if the user chose _ALWAYS or _ALWAYS_ASK for intent resolution.
            // Or if there's already an ephemeral app installed that handles the action
            return isInstantAppResolutionAllowedBody(intent, resolvedActivities, userId,
                                                       skipPackageCheck);
                                                       skipPackageCheck, flags);
        }
        // Deny ephemeral apps if the user chose _ALWAYS or _ALWAYS_ASK for intent resolution.
        // Or if there's already an ephemeral app installed that handles the action
        public boolean isInstantAppResolutionAllowedBody(
                Intent intent, List<ResolveInfo> resolvedActivities, int userId,
                boolean skipPackageCheck) {
                boolean skipPackageCheck, int flags) {
            final int count = (resolvedActivities == null ? 0 : resolvedActivities.size());
            for (int n = 0; n < count; n++) {
                final ResolveInfo info = resolvedActivities.get(n);
@@ -3976,7 +3977,7 @@ public class PackageManagerService extends IPackageManager.Stub
                if (ps != null) {
                    // only check domain verification status if the app is not a browser
                    if (!info.handleAllWebDataURI) {
                        if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent,
                        if (hasAnyDomainApproval(mDomainVerificationManager, ps, intent, flags,
                                userId)) {
                            if (DEBUG_INSTANT) {
                                Slog.v(TAG, "DENY instant app;" + " pkg: " + packageName
@@ -4675,10 +4676,11 @@ public class PackageManagerService extends IPackageManager.Stub
            }
        }
        public boolean isInstantAppResolutionAllowedBody(Intent intent,
                List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck) {
                List<ResolveInfo> resolvedActivities, int userId, boolean skipPackageCheck,
                int flags) {
            synchronized (mLock) {
                return super.isInstantAppResolutionAllowedBody(intent, resolvedActivities, userId,
                        skipPackageCheck);
                        skipPackageCheck, flags);
            }
        }
        public int getPackageUidInternal(String packageName, int flags, int userId,
@@ -9469,20 +9471,20 @@ public class PackageManagerService extends IPackageManager.Stub
    private boolean isInstantAppResolutionAllowed(
            Intent intent, List<ResolveInfo> resolvedActivities, int userId,
            boolean skipPackageCheck) {
            boolean skipPackageCheck, int flags) {
        return liveComputer().isInstantAppResolutionAllowed(
            intent, resolvedActivities, userId,
            skipPackageCheck);
            skipPackageCheck, flags);
    }
    // Deny ephemeral apps if the user chose _ALWAYS or _ALWAYS_ASK for intent resolution.
    // Or if there's already an ephemeral app installed that handles the action
    private boolean isInstantAppResolutionAllowedBody(
            Intent intent, List<ResolveInfo> resolvedActivities, int userId,
            boolean skipPackageCheck) {
            boolean skipPackageCheck, int flags) {
        return liveComputer().isInstantAppResolutionAllowedBody(
            intent, resolvedActivities, userId,
            skipPackageCheck);
            skipPackageCheck, flags);
    }
    private void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
@@ -9539,7 +9541,7 @@ public class PackageManagerService extends IPackageManager.Stub
                        final String packageName = ri.activityInfo.packageName;
                        final PackageSetting ps = mSettings.getPackageLPr(packageName);
                        if (ps != null && hasAnyDomainApproval(mDomainVerificationManager, ps,
                                intent, userId)) {
                                intent, flags, userId)) {
                            return ri;
                        }
                    }
@@ -9596,8 +9598,9 @@ public class PackageManagerService extends IPackageManager.Stub
     */
    private static boolean hasAnyDomainApproval(
            @NonNull DomainVerificationManagerInternal manager, @NonNull PackageSetting pkgSetting,
            @NonNull Intent intent, @UserIdInt int userId) {
        return manager.approvalLevelForDomain(pkgSetting, intent, userId)
            @NonNull Intent intent, @PackageManager.ResolveInfoFlags int resolveInfoFlags,
            @UserIdInt int userId) {
        return manager.approvalLevelForDomain(pkgSetting, intent, resolveInfoFlags, userId)
                > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE;
    }
+1 −1
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ public interface DomainVerificationManagerInternal extends DomainVerificationMan
     */
    @ApprovalLevel
    int approvalLevelForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
            @UserIdInt int userId);
            @PackageManager.ResolveInfoFlags int resolveInfoFlags, @UserIdInt int userId);

    /**
     * @return the domain verification set ID for the given package, or null if the ID is
+2 −2
Original line number Diff line number Diff line
@@ -1346,9 +1346,9 @@ public class DomainVerificationService extends SystemService

    @Override
    public int approvalLevelForDomain(@NonNull PackageSetting pkgSetting, @NonNull Intent intent,
            @UserIdInt int userId) {
            @PackageManager.ResolveInfoFlags int resolveInfoFlags, @UserIdInt int userId) {
        String packageName = pkgSetting.name;
        if (!DomainVerificationUtils.isDomainVerificationIntent(intent)) {
        if (!DomainVerificationUtils.isDomainVerificationIntent(intent, resolveInfoFlags)) {
            if (DEBUG_APPROVAL) {
                debugApproval(packageName, intent, userId, false, "not valid intent");
            }
+7 −4
Original line number Diff line number Diff line
@@ -40,10 +40,13 @@ public final class DomainVerificationUtils {
        throw new NameNotFoundException("Package " + packageName + " unavailable");
    }

    public static boolean isDomainVerificationIntent(Intent intent) {
        return intent.isWebIntent()
                && intent.hasCategory(Intent.CATEGORY_BROWSABLE)
                && intent.hasCategory(Intent.CATEGORY_DEFAULT);
    public static boolean isDomainVerificationIntent(Intent intent, int resolveInfoFlags) {
        if (!intent.isWebIntent() || !intent.hasCategory(Intent.CATEGORY_BROWSABLE)) {
            return false;
        }

        return ((resolveInfoFlags & PackageManager.MATCH_DEFAULT_ONLY) != 0)
                || intent.hasCategory(Intent.CATEGORY_DEFAULT);
    }

    static boolean isChangeEnabled(PlatformCompat platformCompat, AndroidPackage pkg,