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

Commit f11bca68 authored by Winson Chiu's avatar Winson Chiu Committed by Automerger Merge Worker
Browse files

Merge "Only run domain verification filtering for valid Intents" into sc-dev am: b23fc47d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13632988

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I44a86697e0b0a2cd06b7d645878c883db54a1950
parents 99f1f5d3 b23fc47d
Loading
Loading
Loading
Loading
+31 −14
Original line number Original line Diff line number Diff line
@@ -389,6 +389,7 @@ import com.android.server.pm.permission.PermissionManagerService;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
import com.android.server.pm.permission.PermissionManagerServiceInternal;
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
import com.android.server.pm.verify.domain.DomainVerificationService;
import com.android.server.pm.verify.domain.DomainVerificationService;
import com.android.server.pm.verify.domain.DomainVerificationUtils;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxy;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxy;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV1;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV1;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV2;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV2;
@@ -2587,6 +2588,7 @@ public class PackageManagerService extends IPackageManager.Stub
                CrossProfileDomainInfo xpDomainInfo, int userId, boolean debug) {
                CrossProfileDomainInfo xpDomainInfo, int userId, boolean debug) {
            final ArrayList<ResolveInfo> result = new ArrayList<>();
            final ArrayList<ResolveInfo> result = new ArrayList<>();
            final ArrayList<ResolveInfo> matchAllList = new ArrayList<>();
            final ArrayList<ResolveInfo> matchAllList = new ArrayList<>();
            final ArrayList<ResolveInfo> undefinedList = new ArrayList<>();
            final int count = candidates.size();
            final int count = candidates.size();
            // First, try to use approved apps.
            // First, try to use approved apps.
@@ -2595,20 +2597,33 @@ public class PackageManagerService extends IPackageManager.Stub
                // Add to the special match all list (Browser use case)
                // Add to the special match all list (Browser use case)
                if (info.handleAllWebDataURI) {
                if (info.handleAllWebDataURI) {
                    matchAllList.add(info);
                    matchAllList.add(info);
                } else {
                    undefinedList.add(info);
                }
                }
            }
            }
            // We'll want to include browser possibilities in a few cases
            boolean includeBrowser = false;
            if (!DomainVerificationUtils.isDomainVerificationIntent(intent)) {
                result.addAll(undefinedList);
                // Maybe add one for the other profile.
                if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel
                        > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE) {
                    result.add(xpDomainInfo.resolveInfo);
                }
                includeBrowser = true;
            } else {
                Pair<List<ResolveInfo>, Integer> infosAndLevel = mDomainVerificationManager
                Pair<List<ResolveInfo>, Integer> infosAndLevel = mDomainVerificationManager
                    .filterToApprovedApp(intent, candidates, userId, mSettings::getPackageLPr);
                        .filterToApprovedApp(intent, undefinedList, userId,
                                mSettings::getPackageLPr);
                List<ResolveInfo> approvedInfos = infosAndLevel.first;
                List<ResolveInfo> approvedInfos = infosAndLevel.first;
                Integer highestApproval = infosAndLevel.second;
                Integer highestApproval = infosAndLevel.second;
            // We'll want to include browser possibilities in a few cases
            boolean includeBrowser = false;
                // If no apps are approved for the domain, resolve only to browsers
                // If no apps are approved for the domain, resolve only to browsers
                if (approvedInfos.isEmpty()) {
                if (approvedInfos.isEmpty()) {
                // If the other profile has a result, include that and delegate to ResolveActivity
                    // If the other profile has a result, include that and delegate to
                    // ResolveActivity
                    if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel
                    if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel
                            > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE) {
                            > DomainVerificationManagerInternal.APPROVAL_LEVEL_NONE) {
                        result.add(xpDomainInfo.resolveInfo);
                        result.add(xpDomainInfo.resolveInfo);
@@ -2619,10 +2634,12 @@ public class PackageManagerService extends IPackageManager.Stub
                    result.addAll(approvedInfos);
                    result.addAll(approvedInfos);
                    // If the other profile has an app that's of equal or higher approval, add it
                    // If the other profile has an app that's of equal or higher approval, add it
                if (xpDomainInfo != null && xpDomainInfo.highestApprovalLevel >= highestApproval) {
                    if (xpDomainInfo != null
                            && xpDomainInfo.highestApprovalLevel >= highestApproval) {
                        result.add(xpDomainInfo.resolveInfo);
                        result.add(xpDomainInfo.resolveInfo);
                    }
                    }
                }
                }
            }
            if (includeBrowser) {
            if (includeBrowser) {
                // Also add browsers (all of them or only the default one)
                // Also add browsers (all of them or only the default one)
+2 −2
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ import com.android.server.compat.PlatformCompat;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackage;


final class DomainVerificationUtils {
public final class DomainVerificationUtils {


    /**
    /**
     * Consolidates package exception messages. A generic unavailable message is included since the
     * Consolidates package exception messages. A generic unavailable message is included since the
@@ -40,7 +40,7 @@ final class DomainVerificationUtils {
        throw new NameNotFoundException("Package " + packageName + " unavailable");
        throw new NameNotFoundException("Package " + packageName + " unavailable");
    }
    }


    static boolean isDomainVerificationIntent(Intent intent) {
    public static boolean isDomainVerificationIntent(Intent intent) {
        return intent.isWebIntent()
        return intent.isWebIntent()
                && intent.hasCategory(Intent.CATEGORY_BROWSABLE)
                && intent.hasCategory(Intent.CATEGORY_BROWSABLE)
                && intent.hasCategory(Intent.CATEGORY_DEFAULT);
                && intent.hasCategory(Intent.CATEGORY_DEFAULT);