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

Commit 72158f68 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Use task user Context when starting Home task for Desktop entry

Use the Context of the current user (instead of the default
WindowManager Shell Context) to start the Home Activity during Desktop
entry.
In HSUM mode, if we use the default WM Shell Context to launch the Home
Activity the launch fails, and the Desktop enter transition looks bad or
crashes (depending on which flags are enabled).

Bug: 377749397
Test: manual
Flag: com.android.window.flags.enable_desktop_windowing_mode
Change-Id: I1f7eb0bcb2b0ba5ac4c34d96431fa0fa60c83abd
parent 3cf71b7e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -472,7 +472,7 @@ class DesktopTasksController(
            CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD,
        )
        dragToDesktopTransitionHandler.startDragToDesktopTransition(
            taskInfo.taskId,
            taskInfo,
            dragToDesktopValueAnimator,
        )
    }
+13 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.os.Bundle
import android.os.IBinder
import android.os.SystemClock
import android.os.SystemProperties
import android.os.UserHandle
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CLOSE
import android.window.TransitionInfo
@@ -108,7 +109,10 @@ sealed class DragToDesktopTransitionHandler(
     * Note that the transition handler for this transition doesn't call the finish callback until
     * after one of the "end" or "cancel" transitions is merged into this transition.
     */
    fun startDragToDesktopTransition(taskId: Int, dragToDesktopAnimator: MoveToDesktopAnimator) {
    fun startDragToDesktopTransition(
        taskInfo: RunningTaskInfo,
        dragToDesktopAnimator: MoveToDesktopAnimator,
    ) {
        if (inProgress) {
            ProtoLog.v(
                ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
@@ -124,13 +128,15 @@ sealed class DragToDesktopTransitionHandler(
                pendingIntentCreatorBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
            }
        val taskUser = UserHandle.of(taskInfo.userId)
        val pendingIntent =
            PendingIntent.getActivity(
                context,
            PendingIntent.getActivityAsUser(
                context.createContextAsUser(taskUser, /* flags= */ 0),
                0 /* requestCode */,
                launchHomeIntent,
                FLAG_MUTABLE or FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT or FILL_IN_COMPONENT,
                options.toBundle(),
                taskUser,
            )
        val wct = WindowContainerTransaction()
        wct.sendPendingIntent(pendingIntent, launchHomeIntent, Bundle())
@@ -138,19 +144,19 @@ sealed class DragToDesktopTransitionHandler(
            transitions.startTransition(TRANSIT_DESKTOP_MODE_START_DRAG_TO_DESKTOP, wct, this)

        transitionState =
            if (isSplitTask(taskId)) {
            if (isSplitTask(taskInfo.taskId)) {
                val otherTask =
                    getOtherSplitTask(taskId)
                    getOtherSplitTask(taskInfo.taskId)
                        ?: throw IllegalStateException("Expected split task to have a counterpart.")
                TransitionState.FromSplit(
                    draggedTaskId = taskId,
                    draggedTaskId = taskInfo.taskId,
                    dragAnimator = dragToDesktopAnimator,
                    startTransitionToken = startTransitionToken,
                    otherSplitTask = otherTask,
                )
            } else {
                TransitionState.FromFullscreen(
                    draggedTaskId = taskId,
                    draggedTaskId = taskInfo.taskId,
                    dragAnimator = dragToDesktopAnimator,
                    startTransitionToken = startTransitionToken,
                )
+2 −1
Original line number Diff line number Diff line
@@ -607,7 +607,7 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {
                )
            )
            .thenReturn(token)
        handler.startDragToDesktopTransition(task.taskId, dragAnimator)
        handler.startDragToDesktopTransition(task, dragAnimator)
        return token
    }

@@ -661,6 +661,7 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {
        return TestRunningTaskInfoBuilder()
            .setActivityType(if (isHome) ACTIVITY_TYPE_HOME else ACTIVITY_TYPE_STANDARD)
            .setWindowingMode(windowingMode)
            .setUserId(mContext.userId)
            .build()
            .also {
                whenever(splitScreenController.isTaskInSplitScreen(it.taskId))