From 7614077043c317db397ad1ccbc073c953ba4ca2e Mon Sep 17 00:00:00 2001 From: Sarup Dalwani Date: Wed, 26 Oct 2022 14:05:13 +0000 Subject: [PATCH] Creating internal only getActivityInfo for Cross Profile Current getActivityInfo is exposed as public api which needs cross profile access permissions. Now that we are performing chained intent resolution (example, clone profile -> owner -> work profile) we need to getActivityInfo to bypass cross profile check for intent redirection. This would be only internal method and not exposed to system or public. Bug: 255745774 Test: atest CtsAppCloningHostTest:com.android.cts.appcloning.IntentRedirectionTest Test: Manually tested with clone,owner and work profile. Change-Id: I91c685f5c500b12229dc56534a2fc558f7f2b8a1 --- .../java/com/android/server/pm/Computer.java | 8 ++++++++ .../com/android/server/pm/ComputerEngine.java | 20 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/Computer.java b/services/core/java/com/android/server/pm/Computer.java index bf00a33d7d209..5b8ee2b085cca 100644 --- a/services/core/java/com/android/server/pm/Computer.java +++ b/services/core/java/com/android/server/pm/Computer.java @@ -124,6 +124,14 @@ public interface Computer extends PackageDataSnapshot { String instantAppPkgName); ActivityInfo getActivityInfo(ComponentName component, long flags, int userId); + /** + * Similar to {@link Computer#getActivityInfo(android.content.ComponentName, long, int)} but + * only visible as internal service. This method bypass INTERACT_ACROSS_USERS or + * INTERACT_ACROSS_USERS_FULL permission checks and only to be used for intent resolution across + * chained cross profiles + */ + ActivityInfo getActivityInfoCrossProfile(ComponentName component, long flags, int userId); + /** * Important: The provided filterCallingUid is used exclusively to filter out activities * that can be seen based on user state. It's typically the original caller uid prior diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index b2851369b56e8..a8534b0b497ca 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -834,6 +834,24 @@ public class ComputerEngine implements Computer { return getActivityInfoInternal(component, flags, Binder.getCallingUid(), userId); } + /** + * Similar to {@link Computer#getActivityInfo(android.content.ComponentName, long, int)} but + * only visible as internal service. This method bypass INTERACT_ACROSS_USERS or + * INTERACT_ACROSS_USERS_FULL permission checks and only to be used for intent resolution across + * chained cross profiles + * @param component application's component + * @param flags resolve info flags + * @param userId user id where activity resides + * @return ActivityInfo corresponding to requested component. + */ + public final ActivityInfo getActivityInfoCrossProfile(ComponentName component, + @PackageManager.ResolveInfoFlagsBits long flags, int userId) { + if (!mUserManager.exists(userId)) return null; + flags = updateFlagsForComponent(flags, userId); + + return getActivityInfoInternalBody(component, flags, Binder.getCallingUid(), userId); + } + /** * Important: The provided filterCallingUid is used exclusively to filter out activities * that can be seen based on user state. It's typically the original caller uid prior @@ -1711,7 +1729,7 @@ public class ComputerEngine implements Computer { ComponentName forwardingActivityComponentName = new ComponentName( androidApplication().packageName, className); ActivityInfo forwardingActivityInfo = - getActivityInfo(forwardingActivityComponentName, 0, + getActivityInfoCrossProfile(forwardingActivityComponentName, 0, sourceUserId); if (!targetIsProfile) { forwardingActivityInfo.showUserIcon = targetUserId;