Launch split task with correct UserHandle

PendingIntent#getActivity gets the owner UserHandle from the app
context. That makes the activity launch fail since the app only exists
in the work profile environment(secondary user).

This CL gets the correct Userhandle from Launcher and use
PendingIntent#getActivityAsUser to launch split task.

Bug: 242039471
Test: Launch Google chat by shortcut to enter split (work-profile)
Change-Id: Ie1db8a858bf9cee700cb3ff3a9e607a5d1dbad30
This commit is contained in:
Jeff Chang
2022-08-18 20:51:33 +08:00
parent 2d675e8ab0
commit 9f27fa3687
3 changed files with 19 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.text.TextUtils;
import android.view.RemoteAnimationAdapter;
import android.view.SurfaceControl;
@@ -77,6 +78,8 @@ public class SplitSelectStateController {
private int mSecondTaskId = INVALID_TASK_ID;
private String mSecondTaskPackageName;
private boolean mRecentsAnimationRunning;
@Nullable
private UserHandle mUser;
/** If not null, this is the TaskView we want to launch from */
@Nullable
private GroupedTaskView mLaunchingTaskView;
@@ -97,12 +100,15 @@ public class SplitSelectStateController {
mInitialTaskId = taskId;
mStagePosition = stagePosition;
mInitialTaskIntent = null;
mUser = null;
}
public void setInitialTaskSelect(Intent intent, @StagePosition int stagePosition) {
public void setInitialTaskSelect(Intent intent, @StagePosition int stagePosition,
@Nullable UserHandle user) {
mInitialTaskIntent = intent;
mStagePosition = stagePosition;
mInitialTaskId = INVALID_TASK_ID;
mUser = user;
}
/**
@@ -120,9 +126,12 @@ public class SplitSelectStateController {
} else {
fillInIntent = null;
}
final PendingIntent pendingIntent =
mInitialTaskIntent == null ? null : PendingIntent.getActivity(mContext, 0,
mInitialTaskIntent, FLAG_MUTABLE);
final PendingIntent pendingIntent = mInitialTaskIntent == null ? null : (mUser != null
? PendingIntent.getActivityAsUser(mContext, 0, mInitialTaskIntent,
FLAG_MUTABLE, null /* options */, mUser)
: PendingIntent.getActivity(mContext, 0, mInitialTaskIntent, FLAG_MUTABLE));
launchTasks(mInitialTaskId, pendingIntent, fillInIntent, mSecondTaskId, mStagePosition,
callback, false /* freezeTaskList */, DEFAULT_SPLIT_RATIO);
}