From 5e6409d64fd0af1c8921b52a480d4b2c2b270b76 Mon Sep 17 00:00:00 2001 From: John Wu Date: Thu, 8 Sep 2022 22:54:27 +0000 Subject: [PATCH] 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 --- .../com/android/server/pm/PackageManagerServiceUtils.java | 7 +++++++ .../java/com/android/server/wm/ActivityTaskSupervisor.java | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java index 3443d455ee824..e3b2d103fe19b 100644 --- a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +++ b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java @@ -138,6 +138,11 @@ public class PackageManagerServiceUtils { public final static Predicate 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 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 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; diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index 6eaeb15e30b51..565b8f8d117c0 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -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(); }