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

Commit 0e25689f authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Run ktmft on WindowManager/Shell/s/c/a/wm/shell/desktopmode

Command:
external/ktfmt/ktfmt.sh --kotlinlang-style
libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/

Run ktfmt of the last files in shell/desktopmode/.

Bug: 372593306
Test: NA
Flag: EXEMPT formatting
Change-Id: Ib2bf20c3d5d457d5c6bde7ac7a56ad5ff5ba3a28
parent a896f644
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -106,13 +106,13 @@ constructor(
                // Scale the end bounds of the window down with an anchor in the center
                inset(
                    (startBounds.width().toFloat() * (1 - CLOSE_ANIM_SCALE) / 2).toInt(),
                    (startBounds.height().toFloat() * (1 - CLOSE_ANIM_SCALE) / 2).toInt()
                    (startBounds.height().toFloat() * (1 - CLOSE_ANIM_SCALE) / 2).toInt(),
                )
                val offsetY =
                    TypedValue.applyDimension(
                            TypedValue.COMPLEX_UNIT_DIP,
                            CLOSE_ANIM_OFFSET_Y,
                            context.resources.displayMetrics
                            context.resources.displayMetrics,
                        )
                        .toInt()
                offset(/* dx= */ 0, offsetY)
+18 −14
Original line number Diff line number Diff line
@@ -49,15 +49,17 @@ class DesktopActivityOrientationChangeHandler(
    }

    private fun onInit() {
        taskStackListener.addListener(object : TaskStackListenerCallback {
        taskStackListener.addListener(
            object : TaskStackListenerCallback {
                override fun onActivityRequestedOrientationChanged(
                    taskId: Int,
                @ScreenOrientation requestedOrientation: Int
                    @ScreenOrientation requestedOrientation: Int,
                ) {
                    // Handle requested screen orientation changes at runtime.
                    handleActivityOrientationChange(taskId, requestedOrientation)
                }
        })
            }
        )
    }

    /**
@@ -77,7 +79,7 @@ class DesktopActivityOrientationChangeHandler(

    private fun handleActivityOrientationChange(
        taskId: Int,
        @ScreenOrientation requestedOrientation: Int
        @ScreenOrientation requestedOrientation: Int,
    ) {
        if (!Flags.respectOrientationChangeForUnresizeable()) return
        val task = shellTaskOrganizer.getRunningTaskInfo(taskId) ?: return
@@ -93,10 +95,12 @@ class DesktopActivityOrientationChangeHandler(
            if (taskWidth > taskHeight) ORIENTATION_LANDSCAPE else ORIENTATION_PORTRAIT

        // Non-resizeable activity requested opposite orientation.
        if (orientation == ORIENTATION_PORTRAIT
                && ActivityInfo.isFixedOrientationLandscape(requestedOrientation)
            || orientation == ORIENTATION_LANDSCAPE
                && ActivityInfo.isFixedOrientationPortrait(requestedOrientation)) {
        if (
            orientation == ORIENTATION_PORTRAIT &&
                ActivityInfo.isFixedOrientationLandscape(requestedOrientation) ||
                orientation == ORIENTATION_LANDSCAPE &&
                    ActivityInfo.isFixedOrientationPortrait(requestedOrientation)
        ) {

            val finalSize = Size(taskHeight, taskWidth)
            // Use the center x as the resizing anchor point.
+2 −3
Original line number Diff line number Diff line
@@ -71,8 +71,7 @@ class DesktopBackNavigationTransitionHandler(
        animations +=
            info.changes
                .filter {
                    it.mode == info.type &&
                            it.taskInfo?.windowingMode == WINDOWING_MODE_FREEFORM
                    it.mode == info.type && it.taskInfo?.windowingMode == WINDOWING_MODE_FREEFORM
                }
                .mapNotNull { createMinimizeAnimation(it, finishTransaction, onAnimFinish) }
        if (animations.isEmpty()) return false
@@ -83,7 +82,7 @@ class DesktopBackNavigationTransitionHandler(
    private fun createMinimizeAnimation(
        change: TransitionInfo.Change,
        finishTransaction: Transaction,
        onAnimFinish: (Animator) -> Unit
        onAnimFinish: (Animator) -> Unit,
    ): Animator? {
        val t = Transaction()
        val sc = change.leash
+12 −6
Original line number Diff line number Diff line
@@ -64,16 +64,22 @@ class DesktopDisplayEventHandler(

    private fun refreshDisplayWindowingMode() {
        // TODO: b/375319538 - Replace the check with a DisplayManager API once it's available.
        val isExtendedDisplayEnabled = 0 != Settings.Global.getInt(
            context.contentResolver, DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0
        val isExtendedDisplayEnabled =
            0 !=
                Settings.Global.getInt(
                    context.contentResolver,
                    DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
                    0,
                )
        if (!isExtendedDisplayEnabled) {
            // No action needed in mirror or projected mode.
            return
        }

        val hasNonDefaultDisplay = rootTaskDisplayAreaOrganizer.getDisplayIds()
            .any { displayId -> displayId != DEFAULT_DISPLAY }
        val hasNonDefaultDisplay =
            rootTaskDisplayAreaOrganizer.getDisplayIds().any { displayId ->
                displayId != DEFAULT_DISPLAY
            }
        val targetDisplayWindowingMode =
            if (hasNonDefaultDisplay) {
                WINDOWING_MODE_FREEFORM
+90 −102
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@ import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener
import java.io.PrintWriter

/**
 * A controller to move tasks in/out of desktop's full immersive state where the task
 * remains freeform while being able to take fullscreen bounds and have its App Header visibility
 * be transient below the status bar like in fullscreen immersive mode.
 * A controller to move tasks in/out of desktop's full immersive state where the task remains
 * freeform while being able to take fullscreen bounds and have its App Header visibility be
 * transient below the status bar like in fullscreen immersive mode.
 */
class DesktopImmersiveController(
    shellInit: ShellInit,
@@ -71,14 +71,12 @@ class DesktopImmersiveController(
        displayController,
        shellTaskOrganizer,
        shellCommandHandler,
        { SurfaceControl.Transaction() }
        { SurfaceControl.Transaction() },
    )

    @VisibleForTesting
    var state: TransitionState? = null
    @VisibleForTesting var state: TransitionState? = null

    @VisibleForTesting
    val pendingExternalExitTransitions = mutableListOf<ExternalPendingExit>()
    @VisibleForTesting val pendingExternalExitTransitions = mutableListOf<ExternalPendingExit>()

    /** Whether there is an immersive transition that hasn't completed yet. */
    private val inProgress: Boolean
@@ -103,20 +101,19 @@ class DesktopImmersiveController(
        if (inProgress) {
            logV(
                "Cannot start entry because transition(s) already in progress: %s",
                getRunningTransitions()
                getRunningTransitions(),
            )
            return
        }
        val wct = WindowContainerTransaction().apply {
            setBounds(taskInfo.token, Rect())
        }
        val wct = WindowContainerTransaction().apply { setBounds(taskInfo.token, Rect()) }
        logV("Moving task ${taskInfo.taskId} into immersive mode")
        val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
        state = TransitionState(
        state =
            TransitionState(
                transition = transition,
                displayId = taskInfo.displayId,
                taskId = taskInfo.taskId,
            direction = Direction.ENTER
                direction = Direction.ENTER,
            )
    }

@@ -126,21 +123,23 @@ class DesktopImmersiveController(
        if (inProgress) {
            logV(
                "Cannot start exit because transition(s) already in progress: %s",
                getRunningTransitions()
                getRunningTransitions(),
            )
            return
        }

        val wct = WindowContainerTransaction().apply {
        val wct =
            WindowContainerTransaction().apply {
                setBounds(taskInfo.token, getExitDestinationBounds(taskInfo))
            }
        logV("Moving task %d out of immersive mode, reason: %s", taskInfo.taskId, reason)
        val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ this)
        state = TransitionState(
        state =
            TransitionState(
                transition = transition,
                displayId = taskInfo.displayId,
                taskId = taskInfo.taskId,
            direction = Direction.EXIT
                direction = Direction.EXIT,
            )
    }

@@ -183,18 +182,20 @@ class DesktopImmersiveController(
        if (immersiveTask == excludeTaskId) {
            return ExitResult.NoExit
        }
        val taskInfo = shellTaskOrganizer.getRunningTaskInfo(immersiveTask)
            ?: return ExitResult.NoExit
        val taskInfo =
            shellTaskOrganizer.getRunningTaskInfo(immersiveTask) ?: return ExitResult.NoExit
        logV(
            "Appending immersive exit for task: %d in display: %d for reason: %s",
            immersiveTask, displayId, reason
            immersiveTask,
            displayId,
            reason,
        )
        wct.setBounds(taskInfo.token, getExitDestinationBounds(taskInfo))
        return ExitResult.Exit(
            exitingTask = immersiveTask,
            runOnTransitionStart = { transition ->
                addPendingImmersiveExit(immersiveTask, displayId, transition)
            }
            },
        )
    }

@@ -222,20 +223,16 @@ class DesktopImmersiveController(
                    addPendingImmersiveExit(
                        taskId = taskInfo.taskId,
                        displayId = taskInfo.displayId,
                        transition = transition
                        transition = transition,
                    )
                }
                },
            )
        }
        return ExitResult.NoExit
    }


    /** Whether the [change] in the [transition] is a known immersive change. */
    fun isImmersiveChange(
        transition: IBinder,
        change: TransitionInfo.Change,
    ): Boolean {
    fun isImmersiveChange(transition: IBinder, change: TransitionInfo.Change): Boolean {
        return pendingExternalExitTransitions.any {
            it.transition == transition && it.taskId == change.taskInfo?.taskId
        }
@@ -243,11 +240,7 @@ class DesktopImmersiveController(

    private fun addPendingImmersiveExit(taskId: Int, displayId: Int, transition: IBinder) {
        pendingExternalExitTransitions.add(
            ExternalPendingExit(
                taskId = taskId,
                displayId = displayId,
                transition = transition
            )
            ExternalPendingExit(taskId = taskId, displayId = displayId, transition = transition)
        )
    }

@@ -256,7 +249,7 @@ class DesktopImmersiveController(
        info: TransitionInfo,
        startTransaction: SurfaceControl.Transaction,
        finishTransaction: SurfaceControl.Transaction,
        finishCallback: Transitions.TransitionFinishCallback
        finishCallback: Transitions.TransitionFinishCallback,
    ): Boolean {
        val state = requireState()
        check(state.transition == transition) {
@@ -284,7 +277,8 @@ class DesktopImmersiveController(
        finishCallback: Transitions.TransitionFinishCallback,
    ) {
        logD("animateResize for task#%d", targetTaskId)
        val change = info.changes.firstOrNull { c ->
        val change =
            info.changes.firstOrNull { c ->
                val taskInfo = c.taskInfo
                return@firstOrNull taskInfo != null && taskInfo.taskId == targetTaskId
            }
@@ -318,8 +312,7 @@ class DesktopImmersiveController(
            .setPosition(leash, startBounds.left.toFloat(), startBounds.top.toFloat())
            .setWindowCrop(leash, startBounds.width(), startBounds.height())
            .show(leash)
        onTaskResizeAnimationListener
            ?.onAnimationStart(taskId, startTransaction, startBounds)
        onTaskResizeAnimationListener?.onAnimationStart(taskId, startTransaction, startBounds)
            ?: startTransaction.apply()
        val updateTransaction = transactionSupplier()
        ValueAnimator.ofObject(rectEvaluator, startBounds, endBounds).apply {
@@ -341,8 +334,7 @@ class DesktopImmersiveController(
                    .setPosition(leash, rect.left.toFloat(), rect.top.toFloat())
                    .setWindowCrop(leash, rect.width(), rect.height())
                    .apply()
                onTaskResizeAnimationListener
                    ?.onBoundsChange(taskId, updateTransaction, rect)
                onTaskResizeAnimationListener?.onBoundsChange(taskId, updateTransaction, rect)
                    ?: updateTransaction.apply()
            }
            start()
@@ -351,13 +343,13 @@ class DesktopImmersiveController(

    override fun handleRequest(
        transition: IBinder,
        request: TransitionRequestInfo
        request: TransitionRequestInfo,
    ): WindowContainerTransaction? = null

    override fun onTransitionConsumed(
        transition: IBinder,
        aborted: Boolean,
        finishTransaction: SurfaceControl.Transaction?
        finishTransaction: SurfaceControl.Transaction?,
    ) {
        val state = this.state ?: return
        if (transition == state.transition && aborted) {
@@ -380,8 +372,10 @@ class DesktopImmersiveController(
    ) {
        val desktopRepository: DesktopRepository = desktopUserRepositories.current
        // Check if this is a pending external exit transition.
        val pendingExit = pendingExternalExitTransitions
            .firstOrNull { pendingExit -> pendingExit.transition == transition }
        val pendingExit =
            pendingExternalExitTransitions.firstOrNull { pendingExit ->
                pendingExit.transition == transition
            }
        if (pendingExit != null) {
            if (info.hasTaskChange(taskId = pendingExit.taskId)) {
                if (desktopRepository.isTaskInFullImmersiveState(pendingExit.taskId)) {
@@ -389,7 +383,7 @@ class DesktopImmersiveController(
                    desktopRepository.setTaskInFullImmersiveState(
                        displayId = pendingExit.displayId,
                        taskId = pendingExit.taskId,
                        immersive = false
                        immersive = false,
                    )
                    if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                        desktopRepository.removeBoundsBeforeFullImmersive(pendingExit.taskId)
@@ -402,13 +396,13 @@ class DesktopImmersiveController(
        // Check if this is a direct immersive enter/exit transition.
        if (transition == state?.transition) {
            val state = requireState()
            val immersiveChange = info.changes.firstOrNull { c ->
                c.taskInfo?.taskId == state.taskId
            }
            val immersiveChange =
                info.changes.firstOrNull { c -> c.taskInfo?.taskId == state.taskId }
            if (immersiveChange == null) {
                logV(
                    "Direct move for task#%d in %s direction missing immersive change.",
                    state.taskId, state.direction
                    state.taskId,
                    state.direction,
                )
                return
            }
@@ -420,7 +414,7 @@ class DesktopImmersiveController(
                    desktopRepository.setTaskInFullImmersiveState(
                        displayId = state.displayId,
                        taskId = state.taskId,
                        immersive = true
                        immersive = true,
                    )
                    if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                        desktopRepository.saveBoundsBeforeFullImmersive(state.taskId, startBounds)
@@ -430,7 +424,7 @@ class DesktopImmersiveController(
                    desktopRepository.setTaskInFullImmersiveState(
                        displayId = state.displayId,
                        taskId = state.taskId,
                        immersive = false
                        immersive = false,
                    )
                    if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                        desktopRepository.removeBoundsBeforeFullImmersive(state.taskId)
@@ -450,31 +444,34 @@ class DesktopImmersiveController(
                desktopRepository.setTaskInFullImmersiveState(
                    displayId = c.taskInfo!!.displayId,
                    taskId = c.taskInfo!!.taskId,
                    immersive = false
                    immersive = false,
                )
            }
    }

    override fun onTransitionMerged(merged: IBinder, playing: IBinder) {
        val pendingExit = pendingExternalExitTransitions
            .firstOrNull { pendingExit -> pendingExit.transition == merged }
        val pendingExit =
            pendingExternalExitTransitions.firstOrNull { pendingExit ->
                pendingExit.transition == merged
            }
        if (pendingExit != null) {
            logV(
                "Pending exit transition %s for task#%s merged into %s",
                merged, pendingExit.taskId, playing
                merged,
                pendingExit.taskId,
                playing,
            )
            pendingExit.transition = playing
        }
    }

    override fun onTransitionFinished(transition: IBinder, aborted: Boolean) {
        val pendingExit = pendingExternalExitTransitions
            .firstOrNull { pendingExit -> pendingExit.transition == transition }
        val pendingExit =
            pendingExternalExitTransitions.firstOrNull { pendingExit ->
                pendingExit.transition == transition
            }
        if (pendingExit != null) {
            logV(
                "Pending exit transition %s for task#%s finished",
                transition, pendingExit
            )
            logV("Pending exit transition %s for task#%s finished", transition, pendingExit)
            pendingExternalExitTransitions.remove(pendingExit)
        }
    }
@@ -484,11 +481,11 @@ class DesktopImmersiveController(
    }

    private fun getExitDestinationBounds(taskInfo: RunningTaskInfo): Rect {
        val displayLayout = displayController.getDisplayLayout(taskInfo.displayId)
        val displayLayout =
            displayController.getDisplayLayout(taskInfo.displayId)
                ?: error("Expected non-null display layout for displayId: ${taskInfo.displayId}")
        return if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
            desktopUserRepositories.current
                    .removeBoundsBeforeFullImmersive(taskInfo.taskId)
            desktopUserRepositories.current.removeBoundsBeforeFullImmersive(taskInfo.taskId)
                ?: if (ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue()) {
                    calculateInitialBounds(displayLayout, taskInfo)
                } else {
@@ -504,12 +501,8 @@ class DesktopImmersiveController(

    private fun getRunningTransitions(): List<IBinder> {
        val running = mutableListOf<IBinder>()
        state?.let {
            running.add(it.transition)
        }
        pendingExternalExitTransitions.forEach {
            running.add(it.transition)
        }
        state?.let { running.add(it.transition) }
        pendingExternalExitTransitions.forEach { running.add(it.transition) }
        return running
    }

@@ -529,28 +522,23 @@ class DesktopImmersiveController(
        val transition: IBinder,
        val displayId: Int,
        val taskId: Int,
        val direction: Direction
        val direction: Direction,
    )

    /**
     * Tracks state of a transition involving an immersive exit that is external to this class' own
     * transitions. This usually means transitions that exit immersive mode as a side-effect and
     * not the primary action (for example, minimizing the immersive task or launching a new task
     * on top of the immersive task).
     * transitions. This usually means transitions that exit immersive mode as a side-effect and not
     * the primary action (for example, minimizing the immersive task or launching a new task on top
     * of the immersive task).
     */
    data class ExternalPendingExit(
        val taskId: Int,
        val displayId: Int,
        var transition: IBinder,
    )
    data class ExternalPendingExit(val taskId: Int, val displayId: Int, var transition: IBinder)

    /** The result of an external exit request. */
    sealed class ExitResult {
        /** An immersive task exit (meaning, resize) was appended to the request. */
        data class Exit(
            val exitingTask: Int,
            val runOnTransitionStart: ((IBinder) -> Unit)
        ) : ExitResult()
        data class Exit(val exitingTask: Int, val runOnTransitionStart: ((IBinder) -> Unit)) :
            ExitResult()

        /** There was no exit appended to the request. */
        data object NoExit : ExitResult()

@@ -560,7 +548,8 @@ class DesktopImmersiveController(

    @VisibleForTesting
    enum class Direction {
        ENTER, EXIT
        ENTER,
        EXIT,
    }

    /** The reason for moving the task out of desktop immersive mode. */
@@ -583,7 +572,6 @@ class DesktopImmersiveController(
    companion object {
        private const val TAG = "DesktopImmersive"

        @VisibleForTesting
        const val FULL_IMMERSIVE_ANIM_DURATION_MS = 336L
        @VisibleForTesting const val FULL_IMMERSIVE_ANIM_DURATION_MS = 336L
    }
}
Loading