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

Commit c98ea903 authored by Jorge Gil's avatar Jorge Gil
Browse files

[2/N] Replace global userId with per-function argument

To allow reusing DesktopTasksController functions that build WCTs for
desktop operations for cases where the intended user is not current
(such as during user-switching), this change removes the
|taskRepository| member variable from inner functions and replaces it
with |DesktopUserRepositories.getProfile(userId)| using a userId
argument passed by callers. The source of |userId|s become the
TaskInfo.userId when available or ShellController.currentUserId when we
really do mean to use the current user. ShellController is the source of
truth for Shell, so we use that instead of manually tracking user
changes.

This is a refactor to prepare for a future change where a transition
request with user change info requires restoring the active desk of an
incoming user (which would not be "current" yet to SystemUI/Shell) and
deactivating the activate desk of the outgoing user.

Flag: EXEMPT refactor
Bug: 430988310
Bug: 406255019
Test: atest WMShellUnitTest
Change-Id: Iad29fa2f4dd51afdea62d31f96742d1879dc92b8
parent 557c7cc2
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1832,7 +1832,6 @@ public abstract class WMShellModule {
    @WMSingleton
    @Provides
    static Optional<DesktopImeHandler> provideDesktopImeHandler(
            Optional<DesktopTasksController> desktopTasksController,
            Optional<DesktopUserRepositories> desktopUserRepositories,
            FocusTransitionObserver focusTransitionObserver,
            DisplayImeController displayImeController,
@@ -1849,7 +1848,7 @@ public abstract class WMShellModule {
            return Optional.empty();
        }
        return Optional.of(
                new DesktopImeHandler(desktopTasksController.get(), desktopUserRepositories.get(),
                new DesktopImeHandler(desktopUserRepositories.get(),
                        focusTransitionObserver, shellTaskOrganizer,
                        displayImeController, desktopModeWindowDecorViewModel, displayController,
                        transitions, mainExecutor,
+1 −2
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import java.util.Optional

/** Handles the interactions between IME and desktop tasks */
class DesktopImeHandler(
    private val tasksController: DesktopTasksController,
    private val userRepositories: DesktopUserRepositories,
    private val focusTransitionObserver: FocusTransitionObserver,
    private val shellTaskOrganizer: ShellTaskOrganizer,
@@ -94,7 +93,7 @@ class DesktopImeHandler(
        isFloating: Boolean,
        t: Transaction?,
    ): Int {
        if (!tasksController.isAnyDeskActive(displayId) || isFloating) {
        if (!userRepositories.current.isAnyDeskActive(displayId) || isFloating) {
            return IME_ANIMATION_DEFAULT
        }

+13 −7
Original line number Diff line number Diff line
@@ -79,8 +79,9 @@ class DesktopModeKeyGestureHandler(
                        desktopTasksController
                            .get()
                            .moveToNextDesktopDisplay(
                                it.taskId,
                                EnterReason.KEYBOARD_SHORTCUT_ENTER,
                                taskId = it.taskId,
                                userId = desktopUserRepositories.current.userId,
                                enterReason = EnterReason.KEYBOARD_SHORTCUT_ENTER,
                            )
                    }
                }
@@ -91,8 +92,9 @@ class DesktopModeKeyGestureHandler(
                    desktopTasksController
                        .get()
                        .activatePreviousDesk(
                            focusTransitionObserver.globallyFocusedDisplayId,
                            EnterReason.KEYBOARD_SHORTCUT_ENTER,
                            displayId = focusTransitionObserver.globallyFocusedDisplayId,
                            userId = desktopUserRepositories.current.userId,
                            enterReason = EnterReason.KEYBOARD_SHORTCUT_ENTER,
                        )
                }
            }
@@ -102,8 +104,9 @@ class DesktopModeKeyGestureHandler(
                    desktopTasksController
                        .get()
                        .activateNextDesk(
                            focusTransitionObserver.globallyFocusedDisplayId,
                            EnterReason.KEYBOARD_SHORTCUT_ENTER,
                            displayId = focusTransitionObserver.globallyFocusedDisplayId,
                            userId = desktopUserRepositories.current.userId,
                            enterReason = EnterReason.KEYBOARD_SHORTCUT_ENTER,
                        )
                }
            }
@@ -221,7 +224,10 @@ class DesktopModeKeyGestureHandler(

        desktopTasksController
            .get()
            .getFocusedNonDesktopTasks(focusTransitionObserver.globallyFocusedDisplayId)
            .getFocusedNonDesktopTasks(
                displayId = focusTransitionObserver.globallyFocusedDisplayId,
                userId = desktopUserRepositories.current.userId,
            )
            .find { it.windowingMode == WINDOWING_MODE_FULLSCREEN }
            ?.let { fullscreenTask ->
                logV(
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ class DesktopModeShellCommandHandler(
                pw.println("Error: desk id should be an integer")
                return false
            }
        controller.activateDesk(deskId, enterReason = EnterReason.ADB_COMMAND)
        controller.activateDesk(deskId = deskId, enterReason = EnterReason.ADB_COMMAND)
        return true
    }

+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ class DesktopPipTransitionController(
                wct = wct,
                newTask = if (shouldAddParentToDesk) parentTask!! else runningTaskInfo,
                displayId = displayId,
                userId = desktopRepository.userId,
                enterReason = EnterReason.EXIT_PIP,
            )
        }
Loading