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

Commit 2814d858 authored by Pragya Bajoria's avatar Pragya Bajoria Committed by Android (Google) Code Review
Browse files

Merge "[WM Shell] Consolidate `addOrMoveFreeformTaskToTop`, `addActiveTask`...

Merge "[WM Shell] Consolidate `addOrMoveFreeformTaskToTop`, `addActiveTask` and `updateTaskVisibility` into the `addTask` method to simplify the code structure and make it easier to understand." into main
parents 6f17e8dc b5c7e002
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -139,12 +139,9 @@ class DesktopRepository (
                        && visibleTasksCount < maxTasks
                    ) {
                        visibleTasksCount++
                        addOrMoveFreeformTaskToTop(desktop.displayId, task.taskId)
                        addActiveTask(desktop.displayId, task.taskId)
                        updateTaskVisibility(desktop.displayId, task.taskId, visible = false)
                        addTask(desktop.displayId, task.taskId, isVisible = false)
                    } else {
                        addActiveTask(desktop.displayId, task.taskId)
                        updateTaskVisibility(desktop.displayId, task.taskId, visible = false)
                        addTask(desktop.displayId, task.taskId, isVisible = false)
                        minimizeTask(desktop.displayId, task.taskId)
                    }
                }
@@ -204,8 +201,15 @@ class DesktopRepository (
        visibleTasksListeners.remove(visibleTasksListener)
    }

    /** Adds task with [taskId] to the list of freeform tasks on [displayId]. */
    fun addTask(displayId: Int, taskId: Int, isVisible: Boolean) {
        addOrMoveFreeformTaskToTop(displayId, taskId)
        addActiveTask(displayId, taskId)
        updateTask(displayId, taskId, isVisible)
    }

    /** Adds task with [taskId] to the list of active tasks on [displayId]. */
    fun addActiveTask(displayId: Int, taskId: Int) {
    private fun addActiveTask(displayId: Int, taskId: Int) {
        // Removes task if it is active on another display excluding [displayId].
        removeActiveTask(taskId, excludedDisplayId = displayId)

@@ -292,8 +296,8 @@ class DesktopRepository (
     * If task was visible on a different display with a different [displayId], removes from
     * the set of visible tasks on that display and notifies listeners.
     */
    fun updateTaskVisibility(displayId: Int, taskId: Int, visible: Boolean) {
        if (visible) {
    fun updateTask(displayId: Int, taskId: Int, isVisible: Boolean) {
        if (isVisible) {
            // If task is visible, remove it from any other display besides [displayId].
            removeVisibleTask(taskId, excludedDisplayId = displayId)
        } else if (displayId == INVALID_DISPLAY) {
@@ -302,7 +306,7 @@ class DesktopRepository (
            return
        }
        val prevCount = getVisibleTaskCount(displayId)
        if (visible) {
        if (isVisible) {
            desktopTaskDataByDisplayId.getOrCreate(displayId).visibleTasks.add(taskId)
            unminimizeTask(displayId, taskId)
        } else {
@@ -311,7 +315,7 @@ class DesktopRepository (
        val newCount = getVisibleTaskCount(displayId)
        if (prevCount != newCount) {
            logD("Update task visibility taskId=%d visible=%b displayId=%d",
                taskId, visible, displayId)
                taskId, isVisible, displayId)
            logD("VisibleTaskCount has changed from %d to %d", prevCount, newCount)
            notifyVisibleTaskListeners(displayId, newCount)
        }
@@ -355,7 +359,7 @@ class DesktopRepository (
     *
     * Unminimizes the task if it is minimized.
     */
    fun addOrMoveFreeformTaskToTop(displayId: Int, taskId: Int) {
    private fun addOrMoveFreeformTaskToTop(displayId: Int, taskId: Int) {
        logD("Add or move task to top: display=%d taskId=%d", taskId, displayId)
        desktopTaskDataByDisplayId[displayId]?.freeformTasksInZOrder?.remove(taskId)
        desktopTaskDataByDisplayId.getOrCreate(displayId).freeformTasksInZOrder.add(0, taskId)
@@ -378,7 +382,7 @@ class DesktopRepository (
            logD("Minimize Task: display=%d, task=%d", displayId, taskId)
            desktopTaskDataByDisplayId.getOrCreate(displayId).minimizedTasks.add(taskId)
        }

        updateTask(displayId, taskId, isVisible = false)
        if (Flags.enableDesktopWindowingPersistence()) {
            updatePersistentRepository(displayId)
        }
@@ -426,7 +430,7 @@ class DesktopRepository (
        // Remove task from unminimized task if it is minimized.
        unminimizeTask(displayId, taskId)
        removeActiveTask(taskId)
        updateTaskVisibility(displayId, taskId, visible = false)
        removeVisibleTask(taskId)
        if (Flags.enableDesktopWindowingPersistence()) {
            updatePersistentRepository(displayId)
        }
+4 −8
Original line number Diff line number Diff line
@@ -32,11 +32,7 @@ class DesktopTaskChangeListener(
      return
    }
    if (isFreeformTask(taskInfo)) {
      desktopRepository.addOrMoveFreeformTaskToTop(taskInfo.displayId, taskInfo.taskId)
      if (taskInfo.isVisible) {
        desktopRepository.addActiveTask(taskInfo.displayId, taskInfo.taskId)
        desktopRepository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, visible = true)
      }
      desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
    }
  }

@@ -46,9 +42,9 @@ class DesktopTaskChangeListener(
    // Case 1: Freeform task is changed in Desktop Mode.
    if (isFreeformTask(taskInfo)) {
      if (taskInfo.isVisible) {
        desktopRepository.addActiveTask(taskInfo.displayId, taskInfo.taskId)
        desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
      }
      desktopRepository.updateTaskVisibility(
      desktopRepository.updateTask(
          taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
    } else {
      // Case 2: Freeform task is changed outside Desktop Mode.
@@ -87,7 +83,7 @@ class DesktopTaskChangeListener(
      desktopRepository.removeClosingTask(taskInfo.taskId)
      desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
    } else {
      desktopRepository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, visible = false)
      desktopRepository.updateTask(taskInfo.displayId, taskInfo.taskId, isVisible = false)
      desktopRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
    }
  }
+13 −20
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.freeform;

import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;

import static com.android.wm.shell.ShellTaskOrganizer.TASK_LISTENER_TYPE_FREEFORM;

import android.app.ActivityManager.RunningTaskInfo;
@@ -33,7 +34,6 @@ import com.android.wm.shell.desktopmode.DesktopTasksController;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.WindowDecorViewModel;

import java.io.PrintWriter;
@@ -57,11 +57,6 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,

    private final SparseArray<State> mTasks = new SparseArray<>();

    private static class State {
        RunningTaskInfo mTaskInfo;
        SurfaceControl mLeash;
    }

    public FreeformTaskListener(
            Context context,
            ShellInit shellInit,
@@ -105,12 +100,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
        if (!DesktopModeFlags.ENABLE_WINDOWING_TRANSITION_HANDLERS_OBSERVERS.isTrue() &&
                DesktopModeStatus.canEnterDesktopMode(mContext)) {
            mDesktopRepository.ifPresent(repository -> {
                repository.addOrMoveFreeformTaskToTop(taskInfo.displayId, taskInfo.taskId);
                if (taskInfo.isVisible) {
                    repository.addActiveTask(taskInfo.displayId, taskInfo.taskId);
                    repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId,
                        /* visible= */ true);
                }
                repository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible);
            });
        }
        updateLaunchAdjacentController();
@@ -133,7 +123,8 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                    repository.removeClosingTask(taskInfo.taskId);
                    repository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId);
                } else {
                    repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId, false);
                    repository.updateTask(taskInfo.displayId, taskInfo.taskId, /* isVisible= */
                            false);
                    repository.minimizeTask(taskInfo.displayId, taskInfo.taskId);
                }
            });
@@ -159,10 +150,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                        listener.onNonTransitionTaskChanging(taskInfo));
            } else {
                mDesktopRepository.ifPresent(repository -> {
                    if (taskInfo.isVisible) {
                        repository.addActiveTask(taskInfo.displayId, taskInfo.taskId);
                    }
                    repository.updateTaskVisibility(taskInfo.displayId, taskInfo.taskId,
                    repository.updateTask(taskInfo.displayId, taskInfo.taskId,
                            taskInfo.isVisible);
                });
            }
@@ -190,7 +178,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                taskInfo.taskId, taskInfo.isFocused);
        if (DesktopModeStatus.canEnterDesktopMode(mContext) && taskInfo.isFocused) {
            mDesktopRepository.ifPresent(repository -> {
                repository.addOrMoveFreeformTaskToTop(taskInfo.displayId, taskInfo.taskId);
                repository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible);
            });
        }
    }
@@ -224,4 +212,9 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
    public String toString() {
        return TAG;
    }

    private static class State {
        RunningTaskInfo mTaskInfo;
        SurfaceControl mLeash;
    }
}
+3 −6
Original line number Diff line number Diff line
@@ -172,8 +172,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
        activityInfo.screenOrientation = SCREEN_ORIENTATION_PORTRAIT
        task.topActivityInfo = activityInfo
        whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
        taskRepository.addActiveTask(DEFAULT_DISPLAY, task.taskId)
        taskRepository.updateTaskVisibility(DEFAULT_DISPLAY, task.taskId, visible = true)
        taskRepository.addTask(DEFAULT_DISPLAY, task.taskId, isVisible = true)
        runningTasks.add(task)

        taskStackListener.onActivityRequestedOrientationChanged(task.taskId,
@@ -196,7 +195,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
    @Test
    fun handleActivityOrientationChange_notInDesktopMode_doNothing() {
        val task = setUpFreeformTask(isResizeable = false)
        taskRepository.updateTaskVisibility(task.displayId, task.taskId, visible = false)
        taskRepository.updateTask(task.displayId, task.taskId, isVisible = false)

        taskStackListener.onActivityRequestedOrientationChanged(task.taskId,
            SCREEN_ORIENTATION_LANDSCAPE)
@@ -261,9 +260,7 @@ class DesktopActivityOrientationChangeHandlerTest : ShellTestCase() {
        task.topActivityInfo = activityInfo
        task.isResizeable = isResizeable
        whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
        taskRepository.addActiveTask(displayId, task.taskId)
        taskRepository.updateTaskVisibility(displayId, task.taskId, visible = true)
        taskRepository.addOrMoveFreeformTaskToTop(displayId, task.taskId)
        taskRepository.addTask(displayId, task.taskId, isVisible = true)
        runningTasks.add(task)
        return task
    }
+119 −133

File changed.

Preview size limit exceeded, changes collapsed.

Loading