Disable intent filter enforcement in startActivityFromRecents

Due to the fact that the resolved type of an intent is not available
during startActivityFromRecents, the intent might not match the intent
filter, making the activity un-launchable if the enforcement is enabled.

The solution in this commit is a nasty hack for T; a proper fix should
be implemented in master.

Bug: 240373119
Test: atest CtsContentTestCases:PackageManagerTest
Change-Id: Ic88c728373d86dfddd6198600a05c696112048da
This commit is contained in:
John Wu
2022-09-08 22:54:27 +00:00
parent e354477990
commit 5e6409d64f
2 changed files with 13 additions and 0 deletions

View File

@@ -138,6 +138,11 @@ public class PackageManagerServiceUtils {
public final static Predicate<PackageStateInternal> REMOVE_IF_NULL_PKG =
pkgSetting -> pkgSetting.getPkg() == null;
// This is a horrible hack to workaround b/240373119, specifically for fixing the T branch.
// A proper fix should be implemented in master instead.
public static final ThreadLocal<Boolean> DISABLE_ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS =
ThreadLocal.withInitial(() -> false);
/**
* Components of apps targeting Android T and above will stop receiving intents from
* external callers that do not match its declared intent filters.
@@ -1089,6 +1094,8 @@ public class PackageManagerServiceUtils {
PlatformCompat compat, ComponentResolverApi resolver,
List<ResolveInfo> resolveInfos, boolean isReceiver,
Intent intent, String resolvedType, int filterCallingUid) {
if (DISABLE_ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS.get()) return;
final Printer logPrinter = DEBUG_INTENT_MATCHING
? new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM)
: null;

View File

@@ -146,6 +146,7 @@ import com.android.server.LocalServices;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.HostingRecord;
import com.android.server.am.UserState;
import com.android.server.pm.PackageManagerServiceUtils;
import com.android.server.utils.Slogf;
import com.android.server.wm.ActivityMetricsLogger.LaunchingState;
@@ -2634,12 +2635,17 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
// ActivityStarter will acquire the lock where the places need, so execute the request
// outside of the lock.
try {
// We need to temporarily disable the explicit intent filter matching enforcement
// because Task does not store the resolved type of the intent data, causing filter
// mismatch in certain cases. (b/240373119)
PackageManagerServiceUtils.DISABLE_ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS.set(true);
return mService.getActivityStartController().startActivityInPackage(taskCallingUid,
callingPid, callingUid, callingPackage, callingFeatureId, intent, null, null,
null, 0, 0, options, userId, task, "startActivityFromRecents",
false /* validateIncomingUser */, null /* originatingPendingIntent */,
false /* allowBackgroundActivityStart */);
} finally {
PackageManagerServiceUtils.DISABLE_ENFORCE_INTENTS_TO_MATCH_INTENT_FILTERS.set(false);
synchronized (mService.mGlobalLock) {
mService.continueWindowLayout();
}