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

Commit 16406c38 authored by Alex Kershaw's avatar Alex Kershaw
Browse files

CrossProfileApps#startActivity by intent starts in same task by default

This is based on developer feedback from Google Calendar. Tweak the API
to take in the calling activity.

Javadoc in ActivityTaskManagerInternal's new method is copied from the
existing method.

Bug: 149677845
Bug: 136249261
Test: atest com.android.cts.devicepolicy.CrossProfileAppsHostSideTest#testStartActivityIntent_sameTaskByDefault
Change-Id: I2f2d4d8fd82febf4916ba70a08de5e71c678a1f4
parent 0ddd5ae3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11563,7 +11563,7 @@ package android.content.pm {
    method @NonNull public android.graphics.drawable.Drawable getProfileSwitchingIconDrawable(@NonNull android.os.UserHandle);
    method @NonNull public CharSequence getProfileSwitchingLabel(@NonNull android.os.UserHandle);
    method @NonNull public java.util.List<android.os.UserHandle> 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);
    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 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";
  }
+10 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.app.Activity;
import android.app.AppOpsManager.Mode;
import android.content.ComponentName;
import android.content.Context;
@@ -116,18 +117,25 @@ public class CrossProfileApps {
     * @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.
     */
    @RequiresPermission(anyOf = {
            android.Manifest.permission.INTERACT_ACROSS_PROFILES,
            android.Manifest.permission.INTERACT_ACROSS_USERS})
    public void startActivity(@NonNull Intent intent, @NonNull UserHandle targetUser) {
    public void startActivity(
            @NonNull Intent intent,
            @NonNull UserHandle targetUser,
            @Nullable Activity callingActivity) {
        try {
            mService.startActivityAsUserByIntent(
                    mContext.getIApplicationThread(),
                    mContext.getPackageName(),
                    mContext.getFeatureId(),
                    intent,
                    targetUser.getIdentifier());
                    targetUser.getIdentifier(),
                    callingActivity != null ? callingActivity.getActivityToken() : null);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ 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 String callingFeatureId, in Intent intent, int userId, in IBinder callingActivity);
    List<UserHandle> getTargetUserProfiles(in String callingPackage);
    boolean canInteractAcrossProfiles(in String callingPackage);
    boolean canRequestInteractAcrossProfiles(in String callingPackage);
+15 −3
Original line number Diff line number Diff line
@@ -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.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -167,6 +168,8 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
        launchIntent.setComponent(component);
        mInjector.getActivityTaskManagerInternal().startActivityAsUser(
                caller, callingPackage, callingFeatureId, launchIntent,
                /* resultTo= */ null,
                Intent.FLAG_ACTIVITY_NEW_TASK,
                launchMainActivity
                        ? ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle()
                        : null,
@@ -179,7 +182,8 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
            String callingPackage,
            String callingFeatureId,
            Intent intent,
            @UserIdInt int userId) throws RemoteException {
            @UserIdInt int userId,
            IBinder callingActivity) throws RemoteException {
        Objects.requireNonNull(callingPackage);
        Objects.requireNonNull(intent);
        Objects.requireNonNull(intent.getComponent(), "The intent must have a Component set");
@@ -214,8 +218,16 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {

        verifyActivityCanHandleIntent(launchIntent, callingUid, userId);

        mInjector.getActivityTaskManagerInternal().startActivityAsUser(caller, callingPackage,
                callingFeatureId, launchIntent, /* options= */ null, userId);
        mInjector.getActivityTaskManagerInternal()
                .startActivityAsUser(
                        caller,
                        callingPackage,
                        callingFeatureId,
                        launchIntent,
                        callingActivity,
                        /* startFlags= */ 0,
                        /* options= */ null,
                        userId);
        logStartActivityByIntent(callingPackage);
    }

+6 −3
Original line number Diff line number Diff line
@@ -896,7 +896,8 @@ public class LauncherAppsService extends SystemService {
            i.setSourceBounds(sourceBounds);

            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, i, opts, userId);
                    callingFeatureId, i, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK, opts,
                    userId);
        }

        @Override
@@ -955,7 +956,8 @@ public class LauncherAppsService extends SystemService {
                Binder.restoreCallingIdentity(ident);
            }
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, launchIntent, opts, user.getIdentifier());
                    callingFeatureId, launchIntent, /* resultTo= */ null,
                    Intent.FLAG_ACTIVITY_NEW_TASK, opts, user.getIdentifier());
        }

        @Override
@@ -978,7 +980,8 @@ public class LauncherAppsService extends SystemService {
                Binder.restoreCallingIdentity(ident);
            }
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, intent, opts, user.getIdentifier());
                    callingFeatureId, intent, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK,
                    opts, user.getIdentifier());
        }

        /** Checks if user is a profile of or same as listeningUser.
Loading