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

Commit c498ba5f authored by Patrick Baumann's avatar Patrick Baumann
Browse files

Add support for queries matching provider filters

This change adds support for matching queries-intent tags to provider
intent filters and refactors the code to cut down on repetition.

Test: atest AppEnumerationTests AppsFilterTest
Fixes: 154824622
Change-Id: Iaa8ae0982986e8cb918695b0dda3a26ed5221ef2
parent 648c4f96
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -27,12 +27,11 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageParser;
import android.content.pm.parsing.component.ParsedActivity;
import android.content.pm.parsing.component.ParsedComponent;
import android.content.pm.parsing.component.ParsedInstrumentation;
import android.content.pm.parsing.component.ParsedIntentInfo;
import android.content.pm.parsing.component.ParsedMainComponent;
import android.content.pm.parsing.component.ParsedProvider;
import android.content.pm.parsing.component.ParsedService;
import android.os.Binder;
import android.os.Process;
import android.os.Trace;
@@ -302,7 +301,7 @@ public class AppsFilter {
            AndroidPackage potentialTarget, Set<String> protectedBroadcasts) {
        if (!querying.getQueriesIntents().isEmpty()) {
            for (Intent intent : querying.getQueriesIntents()) {
                if (matchesIntentFilters(intent, potentialTarget, protectedBroadcasts)) {
                if (matchesPackage(intent, potentialTarget, protectedBroadcasts)) {
                    return true;
                }
            }
@@ -354,33 +353,35 @@ public class AppsFilter {
        return false;
    }

    private static boolean matchesIntentFilters(Intent intent, AndroidPackage potentialTarget,
    private static boolean matchesPackage(Intent intent, AndroidPackage potentialTarget,
            Set<String> protectedBroadcasts) {
        for (int s = ArrayUtils.size(potentialTarget.getServices()) - 1; s >= 0; s--) {
            ParsedService service = potentialTarget.getServices().get(s);
            if (!service.isExported()) {
                continue;
            }
            if (matchesAnyFilter(intent, service, null /*protectedBroadcasts*/)) {
        if (matchesAnyComponents(
                intent, potentialTarget.getServices(), null /*protectedBroadcasts*/)) {
            return true;
        }
        if (matchesAnyComponents(
                intent, potentialTarget.getActivities(), null /*protectedBroadcasts*/)) {
            return true;
        }
        for (int a = ArrayUtils.size(potentialTarget.getActivities()) - 1; a >= 0; a--) {
            ParsedActivity activity = potentialTarget.getActivities().get(a);
            if (!activity.isExported()) {
                continue;
        if (matchesAnyComponents(intent, potentialTarget.getReceivers(), protectedBroadcasts)) {
            return true;
        }

            if (matchesAnyFilter(intent, activity, null /*protectedBroadcasts*/)) {
        if (matchesAnyComponents(
                intent, potentialTarget.getProviders(), null /*protectedBroadcasts*/)) {
            return true;
        }
        return false;
    }
        for (int r = ArrayUtils.size(potentialTarget.getReceivers()) - 1; r >= 0; r--) {
            ParsedActivity receiver = potentialTarget.getReceivers().get(r);
            if (!receiver.isExported()) {

    private static boolean matchesAnyComponents(Intent intent,
            List<? extends ParsedMainComponent> components,
            Set<String> protectedBroadcasts) {
        for (int i = ArrayUtils.size(components) - 1; i >= 0; i--) {
            ParsedMainComponent component = components.get(i);
            if (!component.isExported()) {
                continue;
            }
            if (matchesAnyFilter(intent, receiver, protectedBroadcasts)) {
            if (matchesAnyFilter(intent, component, protectedBroadcasts)) {
                return true;
            }
        }