From cbcbf66f6ae4077078116019625de010982bdc22 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Thu, 10 May 2018 17:25:29 -0700 Subject: [PATCH] Filter instant app resolution based on logical UID Test: cts-tradefed run cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.EphemeralTest cts-tradefed run cts-dev -m CtsActivityManagerDeviceTestCases bug: 79487366 Change-Id: I51157410d944bc3252de29b4143bb2c7fe7fcefe --- .../android/server/am/ActivityStartController.java | 3 +- .../com/android/server/am/ActivityStarter.java | 43 +++++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStartController.java b/services/core/java/com/android/server/am/ActivityStartController.java index 5e29d10908ca..bbdc9248a256 100644 --- a/services/core/java/com/android/server/am/ActivityStartController.java +++ b/services/core/java/com/android/server/am/ActivityStartController.java @@ -339,7 +339,8 @@ public class ActivityStartController { // Collect information about the target of the Intent. ActivityInfo aInfo = mSupervisor.resolveActivity(intent, resolvedTypes[i], 0, - null, userId, realCallingUid); + null, userId, ActivityStarter.computeResolveFilterUid( + callingUid, realCallingUid)); // TODO: New, check if this is correct aInfo = mService.getActivityInfoForUser(aInfo, userId); diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 3b18d3258237..bbf6e6cffee2 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -791,7 +791,8 @@ class ActivityStarter { callingUid = realCallingUid; callingPid = realCallingPid; - rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, 0, realCallingUid); + rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, 0, + computeResolveFilterUid(callingUid, realCallingUid)); aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, null /*profilerInfo*/); @@ -955,6 +956,16 @@ class ActivityStarter { final int realCallingPid = Binder.getCallingPid(); final int realCallingUid = Binder.getCallingUid(); + int callingPid; + if (callingUid >= 0) { + callingPid = -1; + } else if (caller == null) { + callingPid = realCallingPid; + callingUid = realCallingUid; + } else { + callingPid = callingUid = -1; + } + // Save a copy in case ephemeral needs it final Intent ephemeralIntent = new Intent(intent); // Don't modify the client's object! @@ -973,7 +984,7 @@ class ActivityStarter { } ResolveInfo rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, - 0 /* matchFlags */, realCallingUid); + 0 /* matchFlags */, computeResolveFilterUid(callingUid, realCallingUid)); if (rInfo == null) { UserInfo userInfo = mSupervisor.getUserInfo(userId); if (userInfo != null && userInfo.isManagedProfile()) { @@ -995,7 +1006,7 @@ class ActivityStarter { rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId, PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, - realCallingUid); + computeResolveFilterUid(callingUid, realCallingUid)); } } } @@ -1003,16 +1014,6 @@ class ActivityStarter { ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo); synchronized (mService) { - int callingPid; - if (callingUid >= 0) { - callingPid = -1; - } else if (caller == null) { - callingPid = realCallingPid; - callingUid = realCallingUid; - } else { - callingPid = callingUid = -1; - } - final ActivityStack stack = mSupervisor.mFocusedStack; stack.mConfigWillChange = globalConfig != null && mService.getGlobalConfiguration().diff(globalConfig) != 0; @@ -1077,7 +1078,8 @@ class ActivityStarter { callingPid = Binder.getCallingPid(); componentSpecified = true; rInfo = mSupervisor.resolveIntent(intent, null /*resolvedType*/, userId, - 0 /* matchFlags */, realCallingUid); + 0 /* matchFlags */, computeResolveFilterUid(callingUid, + realCallingUid)); aInfo = rInfo != null ? rInfo.activityInfo : null; if (aInfo != null) { aInfo = mService.getActivityInfoForUser(aInfo, userId); @@ -1164,6 +1166,19 @@ class ActivityStarter { } } + /** + * Compute the logical UID based on which the package manager would filter + * app components i.e. based on which the instant app policy would be applied + * because it is the logical calling UID. + * + * @param customCallingUid The UID on whose behalf to make the call. + * @param actualCallingUid The UID actually making the call. + * @return The logical UID making the call. + */ + static int computeResolveFilterUid(int customCallingUid, int actualCallingUid) { + return customCallingUid >= 0 ? customCallingUid : actualCallingUid; + } + private int startActivity(final ActivityRecord r, ActivityRecord sourceRecord, IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, int startFlags, boolean doResume, ActivityOptions options, TaskRecord inTask, -- 2.11.0