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

Commit 40bf8007 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

[7/n] Add parentTaskId for persisted tasks after reboot

Set launchRootTask for task in background which will be relaunched in
desk after device reboot. This ensures taskInfo.parentTaskId will be set
to the correct deskId instead of -1.

Flag: EXEMPT bug fix
Test: atest DesktopTasksControllerTest
      atest RootTaskDesksOrganizerTest
Bug: 423560267
Change-Id: I86dad3b208ac49426f132f61e1897a6c756a998f
parent aba58742
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.Companion
import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.DragToDesktopStateListener
import com.android.wm.shell.desktopmode.ExitDesktopTaskTransitionHandler.FULLSCREEN_ANIMATION_DURATION
import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
import com.android.wm.shell.desktopmode.data.DesktopRepository.Companion.INVALID_DESK_ID
import com.android.wm.shell.desktopmode.data.DesktopRepository.DeskChangeListener
import com.android.wm.shell.desktopmode.data.DesktopRepository.VisibleTasksListener
import com.android.wm.shell.desktopmode.data.DesktopRepositoryInitializer
@@ -4612,7 +4613,7 @@ class DesktopTasksController(
                .forEach { taskId ->
                    val runningTaskInfo = shellTaskOrganizer.getRunningTaskInfo(taskId)
                    if (runningTaskInfo == null) {
                        wct.startTask(taskId, createActivityOptionsForStartTask().toBundle())
                        wct.startTask(taskId, createActivityOptionsForStartTask(deskId).toBundle())
                    } else {
                        desksOrganizer.reorderTaskToFront(wct, deskId, runningTaskInfo)
                    }
@@ -4809,7 +4810,7 @@ class DesktopTasksController(
                    // Task is not running, start it.
                    wct.startTask(
                        taskIdToReorderToFront,
                        createActivityOptionsForStartTask().toBundle(),
                        createActivityOptionsForStartTask(deskId).toBundle(),
                    )
                }
                else -> {
@@ -5629,11 +5630,16 @@ class DesktopTasksController(
        }
    }

    private fun createActivityOptionsForStartTask(): ActivityOptions {
        return ActivityOptions.makeBasic().apply {
    private fun createActivityOptionsForStartTask(deskId: Int = INVALID_DESK_ID): ActivityOptions {
        val activityOptions =
            ActivityOptions.makeBasic().apply {
                launchWindowingMode = WINDOWING_MODE_FREEFORM
                splashScreenStyle = SPLASH_SCREEN_STYLE_ICON
            }
        if (deskId != INVALID_DESK_ID) {
            desksOrganizer.addLaunchDeskToActivityOptions(activityOptions, deskId)
        }
        return activityOptions
    }

    private fun dump(pw: PrintWriter, prefix: String) {
+1 −1
Original line number Diff line number Diff line
@@ -1624,7 +1624,7 @@ class DesktopRepository(
    companion object {
        private const val TAG = "DesktopRepository"

        @VisibleForTesting const val INVALID_DESK_ID = -1
        const val INVALID_DESK_ID = -1
    }
}

+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.wm.shell.desktopmode.multidesks

import android.app.ActivityManager
import android.app.ActivityOptions
import android.window.TransitionInfo
import android.window.WindowContainerTransaction

@@ -104,6 +105,9 @@ interface DesksOrganizer {
        onTop: Boolean,
    )

    /** Adds launch root task token to activity options to reparent task to desk after reboot. */
    fun addLaunchDeskToActivityOptions(activityOptions: ActivityOptions, deskId: Int)

    /** A callback that is invoked when the desk container is created. */
    fun interface OnCreateCallback {
        /** Calls back when the [deskId] has been created. */
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.wm.shell.desktopmode.multidesks

import android.annotation.SuppressLint
import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityOptions
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD
import android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED
@@ -236,6 +237,11 @@ class RootTaskDesksOrganizer(
        updateTaskMoveAllowed(wct, deskId, allowed = false)
    }

    override fun addLaunchDeskToActivityOptions(activityOptions: ActivityOptions, deskId: Int) {
        val root = checkNotNull(deskRootsByDeskId[deskId]) { "Root not found for desk: $deskId" }
        activityOptions.launchRootTask = root.token
    }

    private fun updateLaunchRoot(wct: WindowContainerTransaction, deskId: Int, enabled: Boolean) {
        val root = checkNotNull(deskRootsByDeskId[deskId]) { "Root not found for desk: $deskId" }
        if (root.isLaunchRootRequested == enabled) {
+1 −0
Original line number Diff line number Diff line
@@ -7907,6 +7907,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

        val wct = getLatestWct(TRANSIT_TO_FRONT, OneShotRemoteHandler::class.java)
        assertNotNull(wct)
        verify(desksOrganizer).addLaunchDeskToActivityOptions(any(), eq(deskId))
        wct.assertLaunchTask(nonRunningTask.taskId, WINDOWING_MODE_FREEFORM)
    }

Loading