From bbdd8e4a3b4bd9bcf4574005b42bed83b4d4ed31 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 17 Feb 2017 13:13:42 -0800 Subject: [PATCH] Fix instant app resolution Resolving intents with a specified component goes down a different path than regular resolution. For Instant Apps, that meant that sometimes the Instant App was not able to resolve it's own activities. Added some new CTS tests to verify that this works. Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.EphemeralTest Change-Id: Ic8a8eaef7eb9e230fdc701c79c85227d0939d974 --- .../server/pm/PackageManagerService.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index e70dea4c5466b..0aa448499449f 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -6041,16 +6041,24 @@ public class PackageManagerService extends IPackageManager.Stub { // used when either 1) the calling package is normal and the activity is within // an ephemeral application or 2) the calling package is ephemeral and the // activity is not visible to ephemeral applications. - boolean matchEphemeral = + final boolean matchInstantApp = (flags & PackageManager.MATCH_INSTANT) != 0; - boolean ephemeralVisibleOnly = + final boolean matchVisibleToInstantAppOnly = (flags & PackageManager.MATCH_VISIBLE_TO_INSTANT_APP_ONLY) != 0; - boolean blockResolution = - (!matchEphemeral && instantAppPkgName == null - && (ai.applicationInfo.privateFlags - & ApplicationInfo.PRIVATE_FLAG_INSTANT) != 0) - || (ephemeralVisibleOnly && instantAppPkgName != null - && (ai.flags & ActivityInfo.FLAG_VISIBLE_TO_EPHEMERAL) == 0); + final boolean isCallerInstantApp = + instantAppPkgName != null; + final boolean isTargetSameInstantApp = + comp.getPackageName().equals(instantAppPkgName); + final boolean isTargetInstantApp = + (ai.applicationInfo.privateFlags + & ApplicationInfo.PRIVATE_FLAG_INSTANT) != 0; + final boolean isTargetHiddenFromInstantApp = + (ai.flags & ActivityInfo.FLAG_VISIBLE_TO_EPHEMERAL) == 0; + final boolean blockResolution = + !isTargetSameInstantApp + && ((!matchInstantApp && !isCallerInstantApp && isTargetInstantApp) + || (matchVisibleToInstantAppOnly && isCallerInstantApp + && isTargetHiddenFromInstantApp)); if (!blockResolution) { final ResolveInfo ri = new ResolveInfo(); ri.activityInfo = ai;