From a7430a100f5df1986f96cfba2b3c0ccd0a24e57e Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Wed, 26 Apr 2023 12:46:11 +0000 Subject: [PATCH] Passing activity token for identify sourceTask System will launch activity into taskDisplayArea if can not identify the sourceTask. This CL passing the activity token from CrossProfileApps#mContext as the calling activity and add the new_task flag. That will make activity launches into split with different tasks when switching profile. Bug: 223405562 Test: split (A|B),switch the work/personal profile from split. atest CrossProfileAppsTest Change-Id: I3bc713aa72985b93b42c288e23bec7f12dd6a01d --- core/java/android/content/pm/CrossProfileApps.java | 5 +++-- .../com/android/server/pm/CrossProfileAppsServiceImpl.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java index 7ac8f37c645e4..c3df17d4b53e3 100644 --- a/core/java/android/content/pm/CrossProfileApps.java +++ b/core/java/android/content/pm/CrossProfileApps.java @@ -27,6 +27,7 @@ import android.annotation.SystemApi; import android.annotation.TestApi; import android.annotation.UserHandleAware; import android.app.Activity; +import android.app.ActivityOptions; import android.app.AppOpsManager.Mode; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; @@ -110,8 +111,8 @@ public class CrossProfileApps { component, targetUser.getIdentifier(), true, - null, - null); + mContext.getActivityToken(), + ActivityOptions.makeBasic().toBundle()); } catch (RemoteException ex) { throw ex.rethrowFromSystemServer(); } diff --git a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java index a610b5b7f88fd..affe67d1b79a7 100644 --- a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java +++ b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java @@ -147,7 +147,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { if (launchMainActivity) { launchIntent.setAction(Intent.ACTION_MAIN); launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); - if (targetTask == null) { + if (targetTask == null || options != null) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } else {