diff --git a/api/current.txt b/api/current.txt index 59afab200fff4..3575b0dd22224 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11571,6 +11571,7 @@ package android.content.pm { method @NonNull public CharSequence getProfileSwitchingLabel(@NonNull android.os.UserHandle); method @NonNull public java.util.List getTargetUserProfiles(); method @RequiresPermission(anyOf={android.Manifest.permission.INTERACT_ACROSS_PROFILES, "android.permission.INTERACT_ACROSS_USERS"}) public void startActivity(@NonNull android.content.Intent, @NonNull android.os.UserHandle, @Nullable android.app.Activity); + method @RequiresPermission(anyOf={android.Manifest.permission.INTERACT_ACROSS_PROFILES, "android.permission.INTERACT_ACROSS_USERS"}) public void startActivity(@NonNull android.content.Intent, @NonNull android.os.UserHandle, @Nullable android.app.Activity, @Nullable android.os.Bundle); method public void startMainActivity(@NonNull android.content.ComponentName, @NonNull android.os.UserHandle); field public static final String ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED = "android.content.pm.action.CAN_INTERACT_ACROSS_PROFILES_CHANGED"; } diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java index 3261cb124e008..5e7e0c8a2d6a2 100644 --- a/core/java/android/content/pm/CrossProfileApps.java +++ b/core/java/android/content/pm/CrossProfileApps.java @@ -27,6 +27,7 @@ import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Bundle; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; @@ -128,6 +129,35 @@ public class CrossProfileApps { @NonNull Intent intent, @NonNull UserHandle targetUser, @Nullable Activity callingActivity) { + startActivity(intent, targetUser, callingActivity, /* options= */ null); + } + + /** + * Starts the specified activity of the caller package in the specified profile. + * + *

The caller must have the {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES}, + * {@code android.Manifest.permission#INTERACT_ACROSS_USERS}, or {@code + * android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission. Both the caller and + * target user profiles must be in the same profile group. The target user must be a valid user + * returned from {@link #getTargetUserProfiles()}. + * + * @param intent The intent to launch. A component in the caller package must be specified. + * @param targetUser The {@link UserHandle} of the profile; must be one of the users returned by + * {@link #getTargetUserProfiles()} if different to the calling user, otherwise a + * {@link SecurityException} will be thrown. + * @param callingActivity The activity to start the new activity from for the purposes of + * deciding which task the new activity should belong to. If {@code null}, the activity + * will always be started in a new task. + * @param options The activity options or {@code null}. See {@link android.app.ActivityOptions}. + */ + @RequiresPermission(anyOf = { + android.Manifest.permission.INTERACT_ACROSS_PROFILES, + android.Manifest.permission.INTERACT_ACROSS_USERS}) + public void startActivity( + @NonNull Intent intent, + @NonNull UserHandle targetUser, + @Nullable Activity callingActivity, + @Nullable Bundle options) { try { mService.startActivityAsUserByIntent( mContext.getIApplicationThread(), @@ -135,7 +165,8 @@ public class CrossProfileApps { mContext.getFeatureId(), intent, targetUser.getIdentifier(), - callingActivity != null ? callingActivity.getActivityToken() : null); + callingActivity != null ? callingActivity.getActivityToken() : null, + options); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } diff --git a/core/java/android/content/pm/ICrossProfileApps.aidl b/core/java/android/content/pm/ICrossProfileApps.aidl index 5a6e008608f31..4cecb30990e6c 100644 --- a/core/java/android/content/pm/ICrossProfileApps.aidl +++ b/core/java/android/content/pm/ICrossProfileApps.aidl @@ -31,7 +31,8 @@ interface ICrossProfileApps { in String callingFeatureId, in ComponentName component, int userId, boolean launchMainActivity); void startActivityAsUserByIntent(in IApplicationThread caller, in String callingPackage, - in String callingFeatureId, in Intent intent, int userId, in IBinder callingActivity); + in String callingFeatureId, in Intent intent, int userId, in IBinder callingActivity, + in Bundle options); List getTargetUserProfiles(in String callingPackage); boolean canInteractAcrossProfiles(in String callingPackage); boolean canRequestInteractAcrossProfiles(in String callingPackage); diff --git a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java index ec9b37db31376..83da38195053a 100644 --- a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java +++ b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java @@ -45,6 +45,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.ResolveInfo; import android.os.Binder; +import android.os.Bundle; import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; @@ -183,7 +184,8 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { String callingFeatureId, Intent intent, @UserIdInt int userId, - IBinder callingActivity) throws RemoteException { + IBinder callingActivity, + Bundle options) throws RemoteException { Objects.requireNonNull(callingPackage); Objects.requireNonNull(intent); Objects.requireNonNull(intent.getComponent(), "The intent must have a Component set"); @@ -226,7 +228,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { launchIntent, callingActivity, /* startFlags= */ 0, - /* options= */ null, + options, userId); logStartActivityByIntent(callingPackage); }