From 8895d9fed7df3d13369986427d46b4f9e175c5c3 Mon Sep 17 00:00:00 2001 From: Gareth Vaughan Date: Fri, 10 Dec 2021 12:49:35 -0500 Subject: [PATCH 1/2] Add new permission START_CROSS_PROFILE_ACTIVITIES This allows holders of START_CROSS_PROFILE_ACTIVITIES permission to start an activity of the caller package in the other profile. The "android.app.role.SYSTEM_WELLBEING" role will get this permission. Test: atest CrossProfileAppsHostSideTest (with new tests in change I661d4b7132291950c8bcb4690d90154a78751b1e) Ignore-AOSP-First: seeking internal review on WIP change prior to merging in AOSP Change-Id: I4f368ec1a5facc0a95efee06b56522db853ff6d8 Bug: 207117478 --- core/api/system-current.txt | 1 + core/res/AndroidManifest.xml | 4 ++++ packages/Shell/AndroidManifest.xml | 3 +++ 3 files changed, 8 insertions(+) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 1794c1314ccae..3527d57c660c9 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -298,6 +298,7 @@ package android { field public static final String SIGNAL_REBOOT_READINESS = "android.permission.SIGNAL_REBOOT_READINESS"; field public static final String SOUND_TRIGGER_RUN_IN_BATTERY_SAVER = "android.permission.SOUND_TRIGGER_RUN_IN_BATTERY_SAVER"; field public static final String START_ACTIVITIES_FROM_BACKGROUND = "android.permission.START_ACTIVITIES_FROM_BACKGROUND"; + field public static final String START_CROSS_PROFILE_ACTIVITIES = "android.permission.START_CROSS_PROFILE_ACTIVITIES"; field public static final String START_REVIEW_PERMISSION_DECISIONS = "android.permission.START_REVIEW_PERMISSION_DECISIONS"; field public static final String STATUS_BAR_SERVICE = "android.permission.STATUS_BAR_SERVICE"; field public static final String STOP_APP_SWITCHES = "android.permission.STOP_APP_SWITCHES"; diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index ae5414d4fa47f..2b0ce8e49ad8d 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2791,6 +2791,10 @@ + + + diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index 0c70821527dde..1303a62ff13da 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -350,6 +350,9 @@ + + + From 4851724447e793c9f012b9927fce7db04ff0878a Mon Sep 17 00:00:00 2001 From: Gareth Vaughan Date: Fri, 19 Nov 2021 10:37:26 -0500 Subject: [PATCH 2/2] Add START_CROSS_PROFILE_ACTIVITIES to startActivity This allows holders of START_CROSS_PROFILE_ACTIVITIES permission to start an activity of the caller package in the other profile. Test: atest CrossProfileAppsHostSideTest (with new tests in change I661d4b7132291950c8bcb4690d90154a78751b1e) Ignore-AOSP-First: seeking internal review on WIP change prior to merging in AOSP Bug: 207117478 Change-Id: I5afa2e458b2eda4f53cfceabe3af950c0df63ad7 --- core/api/system-current.txt | 2 +- .../android/content/pm/CrossProfileApps.java | 5 ++++- .../pm/CrossProfileAppsServiceImpl.java | 21 +++++++++---------- 3 files changed, 15 insertions(+), 13 deletions(-) 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);