diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 3527d57c660c9..a86e4457facf3 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2832,7 +2832,7 @@ package android.content.pm { } public class CrossProfileApps { - method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_PROFILES) public void startActivity(@NonNull android.content.ComponentName, @NonNull android.os.UserHandle); + method @RequiresPermission(anyOf={android.Manifest.permission.INTERACT_ACROSS_PROFILES, android.Manifest.permission.START_CROSS_PROFILE_ACTIVITIES}) public void startActivity(@NonNull android.content.ComponentName, @NonNull android.os.UserHandle); } public class DataLoaderParams { diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java index 48b634e52846b..11b2ea1f6523c 100644 --- a/core/java/android/content/pm/CrossProfileApps.java +++ b/core/java/android/content/pm/CrossProfileApps.java @@ -180,6 +180,7 @@ public class CrossProfileApps { * {@link #startMainActivity}, this can start any activity of the caller package, not just * the main activity. * The caller must have the {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES} + * or {@link android.Manifest.permission#START_CROSS_PROFILE_ACTIVITIES} * permission and both the caller and target user profiles must be in the same profile group. * * @param component The ComponentName of the activity to launch. It must be exported. @@ -189,7 +190,9 @@ public class CrossProfileApps { * @hide */ @SystemApi - @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_PROFILES) + @RequiresPermission(anyOf = { + android.Manifest.permission.INTERACT_ACROSS_PROFILES, + android.Manifest.permission.START_CROSS_PROFILE_ACTIVITIES}) public void startActivity(@NonNull ComponentName component, @NonNull UserHandle targetUser) { try { mService.startActivityAsUser(mContext.getIApplicationThread(), diff --git a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java index 62db886b90e94..b30798485bf7c 100644 --- a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java +++ b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java @@ -19,6 +19,7 @@ import static android.Manifest.permission.INTERACT_ACROSS_PROFILES; import static android.Manifest.permission.INTERACT_ACROSS_USERS; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; import static android.Manifest.permission.MANAGE_APP_OPS_MODES; +import static android.Manifest.permission.START_CROSS_PROFILE_ACTIVITIES; import static android.app.AppOpsManager.OP_INTERACT_ACROSS_PROFILES; import static android.content.Intent.FLAG_RECEIVER_REGISTERED_ONLY; import static android.content.pm.CrossProfileApps.ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED; @@ -154,17 +155,15 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { // must have the required permission and the users must be in the same profile group // in order to launch any of its own activities. if (callerUserId != userId) { - final int permissionFlag = PermissionChecker.checkPermissionForPreflight( - mContext, - INTERACT_ACROSS_PROFILES, - callingPid, - callingUid, - callingPackage); - if (permissionFlag != PermissionChecker.PERMISSION_GRANTED - || !isSameProfileGroup(callerUserId, userId)) { - throw new SecurityException("Attempt to launch activity without required " - + INTERACT_ACROSS_PROFILES - + " permission or target user is not in the same profile group."); + if (!hasInteractAcrossProfilesPermission(callingPackage, callingUid, callingPid) + && !isPermissionGranted(START_CROSS_PROFILE_ACTIVITIES, callingUid)) { + throw new SecurityException("Attempt to launch activity without one of the" + + " required " + INTERACT_ACROSS_PROFILES + " or " + + START_CROSS_PROFILE_ACTIVITIES + " permissions."); + } + if (!isSameProfileGroup(callerUserId, userId)) { + throw new SecurityException("Attempt to launch activity when target user is" + + " not in the same profile group."); } } launchIntent.setComponent(component);