Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48517244 authored by Gareth Vaughan's avatar Gareth Vaughan
Browse files

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
parent 8895d9fe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 {
+4 −1
Original line number Diff line number Diff line
@@ -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(),
+10 −11
Original line number Diff line number Diff line
@@ -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);