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

Commit 6a52bfc2 authored by John Wu's avatar John Wu Committed by Android (Google) Code Review
Browse files

Merge "Update enforce intent filter match implementation" into main

parents 67a36f68 b342d8fe
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public abstract class IntentResolver<F, R extends Object> {
     * Returns whether an intent matches the IntentFilter with a pre-resolved type.
     */
    public static boolean intentMatchesFilter(
            IntentFilter filter, Intent intent, String resolvedType, boolean defaultOnly) {
            IntentFilter filter, Intent intent, String resolvedType) {
        final boolean debug = localLOGV
                || ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);

@@ -97,10 +97,6 @@ public abstract class IntentResolver<F, R extends Object> {
        int match = filter.match(intent.getAction(), resolvedType, intent.getScheme(),
                intent.getData(), intent.getCategories(), TAG);

        if (match >= 0 && defaultOnly && !filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
            match = IntentFilter.NO_MATCH_CATEGORY;
        }

        if (match >= 0) {
            if (debug) {
                Slog.v(TAG, "Filter matched!  match=0x" + Integer.toHexString(match));
+4 −4
Original line number Diff line number Diff line
@@ -586,7 +586,7 @@ public class ComputerEngine implements Computer {
                    list.add(ri);
                    PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                            mInjector.getCompatibility(), mComponentResolver,
                            list, false, intent, resolvedType, flags, filterCallingUid);
                            list, false, intent, resolvedType, filterCallingUid);
                }
            }
        } else {
@@ -616,7 +616,7 @@ public class ComputerEngine implements Computer {
            // We also have to ensure all components match the original intent
            PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                    mInjector.getCompatibility(), mComponentResolver,
                    list, false, originalIntent, resolvedType, flags, filterCallingUid);
                    list, false, originalIntent, resolvedType, filterCallingUid);
        }

        return skipPostResolution ? list : applyPostResolutionFilter(
@@ -700,7 +700,7 @@ public class ComputerEngine implements Computer {
                    list.add(ri);
                    PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                            mInjector.getCompatibility(), mComponentResolver,
                            list, false, intent, resolvedType, flags, callingUid);
                            list, false, intent, resolvedType, callingUid);
                }
            }
        } else {
@@ -712,7 +712,7 @@ public class ComputerEngine implements Computer {
            // We also have to ensure all components match the original intent
            PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                    mInjector.getCompatibility(), mComponentResolver,
                    list, false, originalIntent, resolvedType, flags, callingUid);
                    list, false, originalIntent, resolvedType, callingUid);
        }

        return list;
+7 −10
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.Overridable;
import android.content.Context;
import android.content.Intent;
@@ -198,7 +198,7 @@ public class PackageManagerServiceUtils {
     */
    @Overridable
    @ChangeId
    @Disabled  /* Enforcement reverted in T: b/274147456 */
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    private static final long ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS = 161252188;

    /**
@@ -1192,8 +1192,7 @@ public class PackageManagerServiceUtils {
    public static void applyEnforceIntentFilterMatching(
            PlatformCompat compat, ComponentResolverApi resolver,
            List<ResolveInfo> resolveInfos, boolean isReceiver,
            Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags,
            int filterCallingUid) {
            Intent intent, String resolvedType, int filterCallingUid) {
        if (DISABLE_ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS.get()) return;

        // Do not enforce filter matching when the caller is system or root
@@ -1203,9 +1202,8 @@ public class PackageManagerServiceUtils {
                ? new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM)
                : null;

        final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;

        final boolean enforce = compat.isChangeEnabledByUidInternal(
        final boolean enforce = android.security.Flags.enforceIntentFilterMatch()
                && compat.isChangeEnabledByUidInternal(
                        ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS, filterCallingUid);

        for (int i = resolveInfos.size() - 1; i >= 0; --i) {
@@ -1237,8 +1235,7 @@ public class PackageManagerServiceUtils {
            boolean match = false;
            for (int j = 0, size = comp.getIntents().size(); j < size; ++j) {
                IntentFilter intentFilter = comp.getIntents().get(j).getIntentFilter();
                if (IntentResolver.intentMatchesFilter(
                        intentFilter, intent, resolvedType, defaultOnly)) {
                if (IntentResolver.intentMatchesFilter(intentFilter, intent, resolvedType)) {
                    match = true;
                    break;
                }
+2 −2
Original line number Diff line number Diff line
@@ -459,7 +459,7 @@ final class ResolveIntentHelper {
                    list.add(ri);
                    PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                            mPlatformCompat, componentResolver, list, true, intent,
                            resolvedType, flags, filterCallingUid);
                            resolvedType, filterCallingUid);
                }
            }
        } else {
@@ -485,7 +485,7 @@ final class ResolveIntentHelper {
            // We also have to ensure all components match the original intent
            PackageManagerServiceUtils.applyEnforceIntentFilterMatching(
                    mPlatformCompat, componentResolver,
                    list, true, originalIntent, resolvedType, flags, filterCallingUid);
                    list, true, originalIntent, resolvedType, filterCallingUid);
        }

        return computer.applyPostResolutionFilter(list, instantAppPkgName, false, queryingUid,