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

Commit d35c124c authored by Orhan Uysal's avatar Orhan Uysal Committed by Android (Google) Code Review
Browse files

Merge changes from topic "backNavDesktop" into main

* changes:
  Launch the app if it's not running onMovedToFront
  Minimize closing apps that are not closed by X.
parents cf5814f6 82a6c7a9
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -350,8 +350,17 @@ class DesktopModeTaskRepository (

    /** Minimizes the task for [taskId] and [displayId] */
    fun minimizeTask(displayId: Int, taskId: Int) {
        if (displayId == INVALID_DISPLAY) {
            // When a task vanishes it doesn't have a displayId. Find the display of the task and
            // mark it as minimized.
            getDisplayIdForTask(taskId)?.let {
                minimizeTask(it, taskId)
            } ?: logW("Minimize task: No display id found for task: taskId=%d", taskId)
        } else {
            logD("Minimize Task: display=%d, task=%d", displayId, taskId)
            desktopTaskDataByDisplayId.getOrCreate(displayId).minimizedTasks.add(taskId)
        }

        if (Flags.enableDesktopWindowingPersistence()) {
            updatePersistentRepository(displayId)
        }
+34 −14
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import android.view.Display.DEFAULT_DISPLAY
import android.view.DragEvent
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_NONE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_FRONT
@@ -550,7 +549,29 @@ class DesktopTasksController(

    /** Move a task to the front */
    fun moveTaskToFront(taskId: Int) {
        shellTaskOrganizer.getRunningTaskInfo(taskId)?.let { task -> moveTaskToFront(task) }
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId)
        if (task == null) moveBackgroundTaskToFront(taskId) else moveTaskToFront(task)
    }

    /**
     * Launch a background task in desktop. Note that this should be used when we are already in
     * desktop. If outside of desktop and want to launch a background task in desktop, use
     * [moveBackgroundTaskToDesktop] instead.
     */
    private fun moveBackgroundTaskToFront(taskId: Int) {
        logV("moveBackgroundTaskToFront taskId=%s", taskId)
        val wct = WindowContainerTransaction()
        // TODO: b/342378842 - Instead of using default display, support multiple displays
        val taskToMinimize: RunningTaskInfo? =
            addAndGetMinimizeChangesIfNeeded(DEFAULT_DISPLAY, wct, taskId)
        wct.startTask(
            taskId,
            ActivityOptions.makeBasic().apply {
                launchWindowingMode = WINDOWING_MODE_FREEFORM
            }.toBundle(),
        )
        val transition = transitions.startTransition(TRANSIT_OPEN, wct, null /* handler */)
        addPendingMinimizeTransition(transition, taskToMinimize)
    }

    /** Move a task to the front */
@@ -558,7 +579,8 @@ class DesktopTasksController(
        logV("moveTaskToFront taskId=%s", taskInfo.taskId)
        val wct = WindowContainerTransaction()
        wct.reorder(taskInfo.token, true)
        val taskToMinimize = addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo)
        val taskToMinimize =
            addAndGetMinimizeChangesIfNeeded(taskInfo.displayId, wct, taskInfo.taskId)
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            val transition = transitions.startTransition(TRANSIT_TO_FRONT, wct, null /* handler */)
            addPendingMinimizeTransition(transition, taskToMinimize)
@@ -1254,7 +1276,7 @@ class DesktopTasksController(
        }
        // Desktop Mode is showing and we're launching a new Task - we might need to minimize
        // a Task.
        val taskToMinimize = addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task)
        val taskToMinimize = addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
        if (taskToMinimize != null) {
            addPendingMinimizeTransition(transition, taskToMinimize)
            return wct
@@ -1280,7 +1302,8 @@ class DesktopTasksController(

                // Desktop Mode is already showing and we're launching a new Task - we might need to
                // minimize another Task.
                val taskToMinimize = addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task)
                val taskToMinimize =
                    addAndGetMinimizeChangesIfNeeded(task.displayId, wct, task.taskId)
                addPendingMinimizeTransition(transition, taskToMinimize)
            }
        }
@@ -1313,14 +1336,11 @@ class DesktopTasksController(
            // Remove wallpaper activity when the last active task is removed
            removeWallpaperActivity(wct)
        }

        if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) {
            taskRepository.addClosingTask(task.displayId, task.taskId)
        // If a CLOSE is triggered on a desktop task, remove the task.
        if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue() &&
            taskRepository.isVisibleTask(task.taskId) &&
            transitionType == TRANSIT_CLOSE
        ) {
            wct.removeTask(task.token)
        }

        taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
            doesAnyTaskRequireTaskbarRounding(
                task.displayId,
@@ -1425,12 +1445,12 @@ class DesktopTasksController(
    private fun addAndGetMinimizeChangesIfNeeded(
        displayId: Int,
        wct: WindowContainerTransaction,
        newTaskInfo: RunningTaskInfo
        newTaskId: Int
    ): RunningTaskInfo? {
        if (!desktopTasksLimiter.isPresent) return null
        return desktopTasksLimiter
            .get()
            .addAndGetMinimizeTaskChangesIfNeeded(displayId, wct, newTaskInfo)
            .addAndGetMinimizeTaskChangesIfNeeded(displayId, wct, newTaskId)
    }

    private fun addPendingMinimizeTransition(
+3 −3
Original line number Diff line number Diff line
@@ -208,15 +208,15 @@ class DesktopTasksLimiter (
    fun addAndGetMinimizeTaskChangesIfNeeded(
            displayId: Int,
            wct: WindowContainerTransaction,
            newFrontTaskInfo: RunningTaskInfo,
            newFrontTaskId: Int,
    ): RunningTaskInfo? {
        ProtoLog.v(
                ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
                "DesktopTasksLimiter: addMinimizeBackTaskChangesIfNeeded, newFrontTask=%d",
                newFrontTaskInfo.taskId)
            newFrontTaskId)
        val newTaskListOrderedFrontToBack = createOrderedTaskListWithGivenTaskInFront(
                taskRepository.getActiveNonMinimizedOrderedTasks(displayId),
                newFrontTaskInfo.taskId)
            newFrontTaskId)
        val taskToMinimize = getTaskToMinimizeIfNeeded(newTaskListOrderedFrontToBack)
        if (taskToMinimize != null) {
            wct.reorder(taskToMinimize.token, false /* onTop */)
+11 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.util.SparseArray;
import android.view.SurfaceControl;
import android.window.flags.DesktopModeFlags;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.ShellTaskOrganizer;
@@ -121,7 +122,16 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,

        if (DesktopModeStatus.canEnterDesktopMode(mContext)) {
            mDesktopModeTaskRepository.ifPresent(repository -> {
                // TODO: b/370038902 - Handle Activity#finishAndRemoveTask.
                if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()
                        || repository.isClosingTask(taskInfo.taskId)) {
                    // A task that's vanishing should be removed:
                    // - If it's closed by the X button which means it's marked as a closing task.
                    repository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId);
                } else {
                    repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, false);
                    repository.minimizeTask(taskInfo.displayId, taskInfo.taskId);
                }
            });
        }
        mWindowDecorationViewModel.onTaskVanished(taskInfo);
+12 −0
Original line number Diff line number Diff line
@@ -819,6 +819,18 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
        assertThat(repo.isMinimizedTask(taskId = 2)).isFalse()
    }

    @Test
    fun minimizeTask_withInvalidDisplay_minimizesCorrectTask() {
        repo.addActiveTask(displayId = DEFAULT_DISPLAY, taskId = 0)
        repo.addOrMoveFreeformTaskToTop(displayId = DEFAULT_DISPLAY, taskId = 0)

        repo.minimizeTask(displayId = INVALID_DISPLAY, taskId = 0)

        assertThat(repo.isMinimizedTask(taskId = 0)).isTrue()
        assertThat(repo.isMinimizedTask(taskId = 1)).isFalse()
        assertThat(repo.isMinimizedTask(taskId = 2)).isFalse()
    }

    @Test
    fun unminimizeTask_unminimizesTask() {
        repo.minimizeTask(displayId = 0, taskId = 0)
Loading