From b4037e1489992016c8a01d710c94fa35cb5088b4 Mon Sep 17 00:00:00 2001 From: John Wu Date: Tue, 31 May 2022 23:12:09 +0000 Subject: [PATCH] Exempt connected apps from intent filter enforcement to itself Directly use ActivityManager#checkComponentPermission() to check whether the components should be exempted from the intent filter enforcement added in T. Bug: 234103620 Test: atest CtsContentTestCases:PackageManagerTest Change-Id: I67d1b4bb7d3520370fa9095fb81189acb6c3ebc1 --- .../server/pm/PackageManagerServiceUtils.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java index 719c3b767b465..6afc5890a6a79 100644 --- a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +++ b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java @@ -36,6 +36,7 @@ import static com.android.server.pm.PackageManagerService.TAG; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; +import android.app.ActivityManager; import android.compat.annotation.ChangeId; import android.compat.annotation.EnabledSince; import android.content.Context; @@ -1089,12 +1090,6 @@ public class PackageManagerServiceUtils { PlatformCompat compat, ComponentResolverApi resolver, List resolveInfos, boolean isReceiver, Intent intent, String resolvedType, int filterCallingUid) { - // Do not enforce filter matching when the caller is system or root. - // see ActivityManager#checkComponentPermission(String, int, int, boolean) - if (filterCallingUid == Process.ROOT_UID || filterCallingUid == Process.SYSTEM_UID) { - return; - } - final Printer logPrinter = DEBUG_INTENT_MATCHING ? new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM) : null; @@ -1102,8 +1097,9 @@ public class PackageManagerServiceUtils { for (int i = resolveInfos.size() - 1; i >= 0; --i) { final ComponentInfo info = resolveInfos.get(i).getComponentInfo(); - // Do not enforce filter matching when the caller is the same app - if (info.applicationInfo.uid == filterCallingUid) { + // Do not enforce filter matching when the caller is system, root, or the same app + if (ActivityManager.checkComponentPermission(null, filterCallingUid, + info.applicationInfo.uid, false) == PackageManager.PERMISSION_GRANTED) { continue; }