Allow start of explicit intents

This change relaxes startActivity* logic to allow for all explicit
intents to be started, even if the package name provided for such intent
is not visible to the caller.

Fixes: 161007330
Bug: 148657387
Test: atest AppEnumerationTests
Change-Id: Iceaee276e8d4c297ace1fe605100f52e4cc49b07
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index f533eb2..a2d0eae 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -7161,8 +7161,9 @@
                         && ((!matchInstantApp && !isCallerInstantApp && isTargetInstantApp)
                                 || (matchVisibleToInstantAppOnly && isCallerInstantApp
                                         && isTargetHiddenFromInstantApp));
-                final boolean blockNormalResolution = !isTargetInstantApp && !isCallerInstantApp
-                        && shouldFilterApplicationLocked(
+                final boolean blockNormalResolution =
+                        !resolveForStart && !isTargetInstantApp && !isCallerInstantApp
+                                && shouldFilterApplicationLocked(
                                 getPackageSettingInternal(ai.applicationInfo.packageName,
                                         Process.SYSTEM_UID), filterCallingUid, userId);
                 if (!blockInstantResolution && !blockNormalResolution) {
@@ -7255,8 +7256,8 @@
                 final PackageSetting setting =
                         getPackageSettingInternal(pkgName, Process.SYSTEM_UID);
                 result = null;
-                if (setting != null && setting.pkg != null
-                        && !shouldFilterApplicationLocked(setting, filterCallingUid, userId)) {
+                if (setting != null && setting.pkg != null && (resolveForStart
+                        || !shouldFilterApplicationLocked(setting, filterCallingUid, userId))) {
                     result = filterIfNotSystemUser(mComponentResolver.queryActivities(
                             intent, resolvedType, flags, setting.pkg.getActivities(), userId),
                             userId);