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
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/CloseDesktopTaskTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/CloseDesktopTaskTransitionHandler.kt
index a16c15df..9b5a289 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/CloseDesktopTaskTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/CloseDesktopTaskTransitionHandler.kt
@@ -106,13 +106,13 @@
                 // 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)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
index c0bf40b..6104e79 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopActivityOrientationChangeHandler.kt
@@ -49,15 +49,17 @@
     }
 
     private fun onInit() {
-        taskStackListener.addListener(object : TaskStackListenerCallback {
-            override fun onActivityRequestedOrientationChanged(
-                taskId: Int,
-                @ScreenOrientation requestedOrientation: Int
-            ) {
-                // Handle requested screen orientation changes at runtime.
-                handleActivityOrientationChange(taskId, requestedOrientation)
+        taskStackListener.addListener(
+            object : TaskStackListenerCallback {
+                override fun onActivityRequestedOrientationChanged(
+                    taskId: Int,
+                    @ScreenOrientation requestedOrientation: Int,
+                ) {
+                    // Handle requested screen orientation changes at runtime.
+                    handleActivityOrientationChange(taskId, requestedOrientation)
+                }
             }
-        })
+        )
     }
 
     /**
@@ -77,7 +79,7 @@
 
     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 @@
             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.
@@ -108,4 +112,4 @@
             resizeHandler.startTransition(wct)
         }
     }
-}
\ No newline at end of file
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopBackNavigationTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopBackNavigationTransitionHandler.kt
index 83b0f84..56c50ff 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopBackNavigationTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopBackNavigationTransitionHandler.kt
@@ -71,8 +71,7 @@
         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 @@
     private fun createMinimizeAnimation(
         change: TransitionInfo.Change,
         finishTransaction: Transaction,
-        onAnimFinish: (Animator) -> Unit
+        onAnimFinish: (Animator) -> Unit,
     ): Animator? {
         val t = Transaction()
         val sc = change.leash
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
index ba383fa..43e8d2a 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopDisplayEventHandler.kt
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
-*/
+ */
 
 package com.android.wm.shell.desktopmode
 
@@ -64,16 +64,22 @@
 
     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
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopImmersiveController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopImmersiveController.kt
index 79be698..8e2a412 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopImmersiveController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopImmersiveController.kt
@@ -43,9 +43,9 @@
 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 @@
         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,21 +101,20 @@
         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(
-            transition = transition,
-            displayId = taskInfo.displayId,
-            taskId = taskInfo.taskId,
-            direction = Direction.ENTER
-        )
+        state =
+            TransitionState(
+                transition = transition,
+                displayId = taskInfo.displayId,
+                taskId = taskInfo.taskId,
+                direction = Direction.ENTER,
+            )
     }
 
     /** Starts a transition to move an immersive task out of immersive. */
@@ -126,22 +123,24 @@
         if (inProgress) {
             logV(
                 "Cannot start exit because transition(s) already in progress: %s",
-                getRunningTransitions()
+                getRunningTransitions(),
             )
             return
         }
 
-        val wct = WindowContainerTransaction().apply {
-            setBounds(taskInfo.token, getExitDestinationBounds(taskInfo))
-        }
+        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(
-            transition = transition,
-            displayId = taskInfo.displayId,
-            taskId = taskInfo.taskId,
-            direction = Direction.EXIT
-        )
+        state =
+            TransitionState(
+                transition = transition,
+                displayId = taskInfo.displayId,
+                taskId = taskInfo.taskId,
+                direction = Direction.EXIT,
+            )
     }
 
     /**
@@ -183,18 +182,20 @@
         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 @@
                     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 @@
 
     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 @@
         info: TransitionInfo,
         startTransaction: SurfaceControl.Transaction,
         finishTransaction: SurfaceControl.Transaction,
-        finishCallback: Transitions.TransitionFinishCallback
+        finishCallback: Transitions.TransitionFinishCallback,
     ): Boolean {
         val state = requireState()
         check(state.transition == transition) {
@@ -284,10 +277,11 @@
         finishCallback: Transitions.TransitionFinishCallback,
     ) {
         logD("animateResize for task#%d", targetTaskId)
-        val change = info.changes.firstOrNull { c ->
-            val taskInfo = c.taskInfo
-            return@firstOrNull taskInfo != null && taskInfo.taskId == targetTaskId
-        }
+        val change =
+            info.changes.firstOrNull { c ->
+                val taskInfo = c.taskInfo
+                return@firstOrNull taskInfo != null && taskInfo.taskId == targetTaskId
+            }
         if (change == null) {
             logD("Did not find change for task#%d to animate", targetTaskId)
             startTransaction.apply()
@@ -298,9 +292,9 @@
     }
 
     /**
-     *  Animate an immersive change.
+     * Animate an immersive change.
      *
-     *  As of now, both enter and exit transitions have the same animation, a veiled resize.
+     * As of now, both enter and exit transitions have the same animation, a veiled resize.
      */
     fun animateResizeChange(
         change: TransitionInfo.Change,
@@ -318,8 +312,7 @@
             .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 @@
                     .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 @@
 
     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 @@
     ) {
         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 @@
                     desktopRepository.setTaskInFullImmersiveState(
                         displayId = pendingExit.displayId,
                         taskId = pendingExit.taskId,
-                        immersive = false
+                        immersive = false,
                     )
                     if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                         desktopRepository.removeBoundsBeforeFullImmersive(pendingExit.taskId)
@@ -402,13 +396,13 @@
         // 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 @@
                     desktopRepository.setTaskInFullImmersiveState(
                         displayId = state.displayId,
                         taskId = state.taskId,
-                        immersive = true
+                        immersive = true,
                     )
                     if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                         desktopRepository.saveBoundsBeforeFullImmersive(state.taskId, startBounds)
@@ -430,7 +424,7 @@
                     desktopRepository.setTaskInFullImmersiveState(
                         displayId = state.displayId,
                         taskId = state.taskId,
-                        immersive = false
+                        immersive = false,
                     )
                     if (Flags.enableRestoreToPreviousSizeFromDesktopImmersive()) {
                         desktopRepository.removeBoundsBeforeFullImmersive(state.taskId)
@@ -450,31 +444,34 @@
                 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 @@
     }
 
     private fun getExitDestinationBounds(taskInfo: RunningTaskInfo): Rect {
-        val displayLayout = displayController.getDisplayLayout(taskInfo.displayId)
-            ?: error("Expected non-null display layout for displayId: ${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 @@
 
     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 @@
         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 @@
 
     @VisibleForTesting
     enum class Direction {
-        ENTER, EXIT
+        ENTER,
+        EXIT,
     }
 
     /** The reason for moving the task out of desktop immersive mode. */
@@ -583,7 +572,6 @@
     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
     }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt
index 96bbd58..33d94d5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopMixedTransitionHandler.kt
@@ -61,11 +61,10 @@
 ) : MixedTransitionHandler, FreeformTaskTransitionStarter {
 
     init {
-        shellInit.addInitCallback ({ transitions.addHandler(this) }, this)
+        shellInit.addInitCallback({ transitions.addHandler(this) }, this)
     }
 
-    @VisibleForTesting
-    val pendingMixedTransitions = mutableListOf<PendingMixedTransition>()
+    @VisibleForTesting val pendingMixedTransitions = mutableListOf<PendingMixedTransition>()
 
     /** Delegates starting transition to [FreeformTaskTransitionHandler]. */
     override fun startWindowingModeTransition(
@@ -83,7 +82,8 @@
             return freeformTaskTransitionHandler.startRemoveTransition(wct)
         }
         requireNotNull(wct)
-        return transitions.startTransition(WindowManager.TRANSIT_CLOSE, wct, /* handler= */ this)
+        return transitions
+            .startTransition(WindowManager.TRANSIT_CLOSE, wct, /* handler= */ this)
             .also { transition ->
                 pendingMixedTransitions.add(PendingMixedTransition.Close(transition))
             }
@@ -100,8 +100,10 @@
         minimizingTaskId: Int? = null,
         exitingImmersiveTask: Int? = null,
     ): IBinder {
-        if (!Flags.enableFullyImmersiveInDesktop() &&
-            !DesktopModeFlags.ENABLE_DESKTOP_APP_LAUNCH_TRANSITIONS.isTrue) {
+        if (
+            !Flags.enableFullyImmersiveInDesktop() &&
+                !DesktopModeFlags.ENABLE_DESKTOP_APP_LAUNCH_TRANSITIONS.isTrue
+        ) {
             return transitions.startTransition(transitionType, wct, /* handler= */ null)
         }
         if (exitingImmersiveTask == null) {
@@ -109,18 +111,21 @@
         } else {
             logV(
                 "Starting mixed launch transition for task#%d with immersive exit of task#%d",
-                taskId, exitingImmersiveTask
+                taskId,
+                exitingImmersiveTask,
             )
         }
-        return transitions.startTransition(transitionType, wct, /* handler= */ this)
-            .also { transition ->
-                pendingMixedTransitions.add(PendingMixedTransition.Launch(
+        return transitions.startTransition(transitionType, wct, /* handler= */ this).also {
+            transition ->
+            pendingMixedTransitions.add(
+                PendingMixedTransition.Launch(
                     transition = transition,
                     launchingTask = taskId,
                     minimizingTask = minimizingTaskId,
                     exitingImmersiveTask = exitingImmersiveTask,
-                ))
-            }
+                )
+            )
+        }
     }
 
     /** Notifies this handler that there is a pending transition for it to handle. */
@@ -141,36 +146,38 @@
         finishTransaction: SurfaceControl.Transaction,
         finishCallback: TransitionFinishCallback,
     ): Boolean {
-        val pending = pendingMixedTransitions.find { pending -> pending.transition == transition }
-            ?: return false.also {
-                logV("No pending desktop transition")
-            }
+        val pending =
+            pendingMixedTransitions.find { pending -> pending.transition == transition }
+                ?: return false.also { logV("No pending desktop transition") }
         pendingMixedTransitions.remove(pending)
         logV("Animating pending mixed transition: %s", pending)
         return when (pending) {
-            is PendingMixedTransition.Close -> animateCloseTransition(
-                transition,
-                info,
-                startTransaction,
-                finishTransaction,
-                finishCallback
-            )
-            is PendingMixedTransition.Launch -> animateLaunchTransition(
-                pending,
-                transition,
-                info,
-                startTransaction,
-                finishTransaction,
-                finishCallback
-            )
-            is PendingMixedTransition.Minimize -> animateMinimizeTransition(
-                pending,
-                transition,
-                info,
-                startTransaction,
-                finishTransaction,
-                finishCallback
-            )
+            is PendingMixedTransition.Close ->
+                animateCloseTransition(
+                    transition,
+                    info,
+                    startTransaction,
+                    finishTransaction,
+                    finishCallback,
+                )
+            is PendingMixedTransition.Launch ->
+                animateLaunchTransition(
+                    pending,
+                    transition,
+                    info,
+                    startTransaction,
+                    finishTransaction,
+                    finishCallback,
+                )
+            is PendingMixedTransition.Minimize ->
+                animateMinimizeTransition(
+                    pending,
+                    transition,
+                    info,
+                    startTransaction,
+                    finishTransaction,
+                    finishCallback,
+                )
         }
     }
 
@@ -216,12 +223,10 @@
         finishCallback: TransitionFinishCallback,
     ): Boolean {
         // Check if there's also an immersive change during this launch.
-        val immersiveExitChange = pending.exitingImmersiveTask?.let { exitingTask ->
-            findTaskChange(info, exitingTask)
-        }
-        val minimizeChange = pending.minimizingTask?.let { minimizingTask ->
-            findTaskChange(info, minimizingTask)
-        }
+        val immersiveExitChange =
+            pending.exitingImmersiveTask?.let { exitingTask -> findTaskChange(info, exitingTask) }
+        val minimizeChange =
+            pending.minimizingTask?.let { minimizingTask -> findTaskChange(info, minimizingTask) }
         val launchChange = findDesktopTaskLaunchChange(info, pending.launchingTask)
         if (launchChange == null) {
             check(minimizeChange == null)
@@ -241,8 +246,9 @@
 
         logV(
             "Animating mixed launch transition task#%d, minimizingTask#%s immersiveExitTask#%s",
-            launchChange.taskInfo!!.taskId, minimizeChange?.taskInfo?.taskId,
-            immersiveExitChange?.taskInfo?.taskId
+            launchChange.taskInfo!!.taskId,
+            minimizeChange?.taskInfo?.taskId,
+            immersiveExitChange?.taskInfo?.taskId,
         )
         if (DesktopModeFlags.ENABLE_DESKTOP_APP_LAUNCH_TRANSITIONS.isTrue) {
             // Only apply minimize change reparenting here if we implement the new app launch
@@ -259,7 +265,7 @@
                 immersiveExitChange,
                 startTransaction,
                 finishTransaction,
-                finishCb
+                finishCb,
             )
             // Let the leftover/default handler animate the remaining changes.
             return dispatchToLeftoverHandler(
@@ -267,7 +273,7 @@
                 info,
                 startTransaction,
                 finishTransaction,
-                finishCb
+                finishCb,
             )
         }
         // There's nothing to animate separately, so let the left over handler animate
@@ -278,7 +284,7 @@
             info,
             startTransaction,
             finishTransaction,
-            finishCb
+            finishCb,
         )
     }
 
@@ -304,7 +310,7 @@
                 info,
                 startTransaction,
                 finishTransaction,
-                finishCallback
+                finishCallback,
             )
         }
 
@@ -321,7 +327,7 @@
     override fun onTransitionConsumed(
         transition: IBinder,
         aborted: Boolean,
-        finishTransaction: SurfaceControl.Transaction?
+        finishTransaction: SurfaceControl.Transaction?,
     ) {
         pendingMixedTransitions.removeAll { pending -> pending.transition == transition }
         super.onTransitionConsumed(transition, aborted, finishTransaction)
@@ -356,7 +362,7 @@
             doOnFinishCallback = {
                 // Finish the jank trace when closing the last window in desktop mode.
                 interactionJankMonitor.end(CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE)
-            }
+            },
         )
     }
 
@@ -379,7 +385,10 @@
         require(taskInfo.isFreeform)
         logV("Reparenting minimizing task#%d", taskInfo.taskId)
         rootTaskDisplayAreaOrganizer.reparentToDisplayArea(
-            taskInfo.displayId, minimizeChange.leash, startTransaction)
+            taskInfo.displayId,
+            minimizeChange.leash,
+            startTransaction,
+        )
     }
 
     private fun dispatchToLeftoverHandler(
@@ -399,7 +408,7 @@
                 doOnFinishCallback?.invoke()
                 finishCallback.onTransitionFinished(wct)
             },
-            /* skip= */ this
+            /* skip= */ this,
         ) != null
     }
 
@@ -423,7 +432,7 @@
 
     private fun findDesktopTaskLaunchChange(
         info: TransitionInfo,
-        launchTaskId: Int?
+        launchTaskId: Int?,
     ): TransitionInfo.Change? {
         return if (launchTaskId != null) {
             // Launching a known task (probably from background or moving to front), so
@@ -432,8 +441,9 @@
         } else {
             // Launching a new task, so the first opening freeform task.
             info.changes.firstOrNull { change ->
-                change.mode == TRANSIT_OPEN
-                        && change.taskInfo != null && change.taskInfo!!.isFreeform
+                change.mode == TRANSIT_OPEN &&
+                    change.taskInfo != null &&
+                    change.taskInfo!!.isFreeform
             }
         }
     }
@@ -451,9 +461,7 @@
         abstract val transition: IBinder
 
         /** A task is closing. */
-        data class Close(
-            override val transition: IBinder,
-        ) : PendingMixedTransition()
+        data class Close(override val transition: IBinder) : PendingMixedTransition()
 
         /** A task is opening or moving to front. */
         data class Launch(
@@ -463,8 +471,10 @@
             val exitingImmersiveTask: Int?,
         ) : PendingMixedTransition()
 
-        /** A task is minimizing. This should be used for task going to back and some closing cases
-         * with back navigation. */
+        /**
+         * A task is minimizing. This should be used for task going to back and some closing cases
+         * with back navigation.
+         */
         data class Minimize(
             override val transition: IBinder,
             val minimizingTask: Int,
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeDragAndDropTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeDragAndDropTransitionHandler.kt
index a7a4a10..ca02c72 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeDragAndDropTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeDragAndDropTransitionHandler.kt
@@ -27,16 +27,14 @@
 import com.android.wm.shell.transition.Transitions
 import com.android.wm.shell.transition.Transitions.TransitionFinishCallback
 
-/**
- * Transition handler for drag-and-drop (i.e., tab tear) transitions that occur in desktop mode.
- */
+/** Transition handler for drag-and-drop (i.e., tab tear) transitions that occur in desktop mode. */
 class DesktopModeDragAndDropTransitionHandler(private val transitions: Transitions) :
     Transitions.TransitionHandler {
     private val pendingTransitionTokens: MutableList<IBinder> = mutableListOf()
 
     /**
-     * Begin a transition when a [android.app.PendingIntent] is dropped without a window to
-     * accept it.
+     * Begin a transition when a [android.app.PendingIntent] is dropped without a window to accept
+     * it.
      */
     fun handleDropEvent(wct: WindowContainerTransaction): IBinder {
         val token = transitions.startTransition(TRANSIT_OPEN, wct, this)
@@ -49,29 +47,32 @@
         info: TransitionInfo,
         startTransaction: SurfaceControl.Transaction,
         finishTransaction: SurfaceControl.Transaction,
-        finishCallback: TransitionFinishCallback
+        finishCallback: TransitionFinishCallback,
     ): Boolean {
         if (!pendingTransitionTokens.contains(transition)) return false
         val change = findRelevantChange(info)
         val leash = change.leash
         val endBounds = change.endAbsBounds
-        startTransaction.hide(leash)
+        startTransaction
+            .hide(leash)
             .setWindowCrop(leash, endBounds.width(), endBounds.height())
             .apply()
         val animator = ValueAnimator()
         animator.setFloatValues(0f, 1f)
         animator.setDuration(FADE_IN_ANIMATION_DURATION)
         val t = SurfaceControl.Transaction()
-        animator.addListener(object : AnimatorListenerAdapter() {
-            override fun onAnimationStart(animation: Animator) {
-                t.show(leash)
-                t.apply()
-            }
+        animator.addListener(
+            object : AnimatorListenerAdapter() {
+                override fun onAnimationStart(animation: Animator) {
+                    t.show(leash)
+                    t.apply()
+                }
 
-            override fun onAnimationEnd(animation: Animator) {
-                finishCallback.onTransitionFinished(null)
+                override fun onAnimationEnd(animation: Animator) {
+                    finishCallback.onTransitionFinished(null)
+                }
             }
-        })
+        )
         animator.addUpdateListener { animation: ValueAnimator ->
             t.setAlpha(leash, animation.animatedFraction)
             t.apply()
@@ -83,9 +84,7 @@
 
     private fun findRelevantChange(info: TransitionInfo): TransitionInfo.Change {
         val matchingChanges =
-            info.changes.filter { c ->
-                isValidTaskChange(c) && c.mode == TRANSIT_OPEN
-            }
+            info.changes.filter { c -> isValidTaskChange(c) && c.mode == TRANSIT_OPEN }
         if (matchingChanges.size != 1) {
             throw IllegalStateException(
                 "Expected 1 relevant change but found: ${matchingChanges.size}"
@@ -100,7 +99,7 @@
 
     override fun handleRequest(
         transition: IBinder,
-        request: TransitionRequestInfo
+        request: TransitionRequestInfo,
     ): WindowContainerTransaction? {
         return null
     }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeEventLogger.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeEventLogger.kt
index dc23128..ff6fb59 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeEventLogger.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeEventLogger.kt
@@ -35,29 +35,25 @@
 import java.util.Random
 import java.util.concurrent.atomic.AtomicInteger
 
-
 /** Event logger for logging desktop mode session events */
 class DesktopModeEventLogger {
     private val random: Random = SecureRandom()
 
     /** The session id for the current desktop mode session */
-    @VisibleForTesting
-    val currentSessionId: AtomicInteger = AtomicInteger(NO_SESSION_ID)
+    @VisibleForTesting val currentSessionId: AtomicInteger = AtomicInteger(NO_SESSION_ID)
 
     private fun generateSessionId() = 1 + random.nextInt(1 shl 20)
 
-    /**
-     * Logs enter into desktop mode with [enterReason]
-     */
+    /** Logs enter into desktop mode with [enterReason] */
     fun logSessionEnter(enterReason: EnterReason) {
         val sessionId = generateSessionId()
         val previousSessionId = currentSessionId.getAndSet(sessionId)
         if (previousSessionId != NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: Existing desktop mode session id: %s found on desktop "
-                    + "mode enter",
-                previousSessionId
+                "DesktopModeLogger: Existing desktop mode session id: %s found on desktop " +
+                    "mode enter",
+                previousSessionId,
             )
         }
 
@@ -65,27 +61,25 @@
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging session enter, session: %s reason: %s",
             sessionId,
-            enterReason.name
+            enterReason.name,
         )
         FrameworkStatsLog.write(
             DESKTOP_MODE_ATOM_ID,
             /* event */ FrameworkStatsLog.DESKTOP_MODE_UICHANGED__EVENT__ENTER,
             /* enterReason */ enterReason.reason,
             /* exitReason */ 0,
-            /* session_id */ sessionId
+            /* session_id */ sessionId,
         )
         EventLogTags.writeWmShellEnterDesktopMode(enterReason.reason, sessionId)
     }
 
-    /**
-     * Logs exit from desktop mode session with [exitReason]
-     */
+    /** Logs exit from desktop mode session with [exitReason] */
     fun logSessionExit(exitReason: ExitReason) {
         val sessionId = currentSessionId.getAndSet(NO_SESSION_ID)
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging exit from desktop mode"
+                "DesktopModeLogger: No session id found for logging exit from desktop mode",
             )
             return
         }
@@ -94,27 +88,25 @@
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging session exit, session: %s reason: %s",
             sessionId,
-            exitReason.name
+            exitReason.name,
         )
         FrameworkStatsLog.write(
             DESKTOP_MODE_ATOM_ID,
             /* event */ FrameworkStatsLog.DESKTOP_MODE_UICHANGED__EVENT__EXIT,
             /* enterReason */ 0,
             /* exitReason */ exitReason.reason,
-            /* session_id */ sessionId
+            /* session_id */ sessionId,
         )
         EventLogTags.writeWmShellExitDesktopMode(exitReason.reason, sessionId)
     }
 
-    /**
-     * Logs that a task with [taskUpdate] was added in a desktop mode session
-     */
+    /** Logs that a task with [taskUpdate] was added in a desktop mode session */
     fun logTaskAdded(taskUpdate: TaskUpdate) {
         val sessionId = currentSessionId.get()
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging task added"
+                "DesktopModeLogger: No session id found for logging task added",
             )
             return
         }
@@ -123,23 +115,22 @@
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging task added, session: %s taskId: %s",
             sessionId,
-            taskUpdate.instanceId
+            taskUpdate.instanceId,
         )
         logTaskUpdate(
             FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__TASK_EVENT__TASK_ADDED,
-            sessionId, taskUpdate
+            sessionId,
+            taskUpdate,
         )
     }
 
-    /**
-     * Logs that a task with [taskUpdate] was removed from a desktop mode session
-     */
+    /** Logs that a task with [taskUpdate] was removed from a desktop mode session */
     fun logTaskRemoved(taskUpdate: TaskUpdate) {
         val sessionId = currentSessionId.get()
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging task removed"
+                "DesktopModeLogger: No session id found for logging task removed",
             )
             return
         }
@@ -148,23 +139,22 @@
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging task remove, session: %s taskId: %s",
             sessionId,
-            taskUpdate.instanceId
+            taskUpdate.instanceId,
         )
         logTaskUpdate(
             FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__TASK_EVENT__TASK_REMOVED,
-            sessionId, taskUpdate
+            sessionId,
+            taskUpdate,
         )
     }
 
-    /**
-     * Logs that a task with [taskUpdate] had it's info changed in a desktop mode session
-     */
+    /** Logs that a task with [taskUpdate] had it's info changed in a desktop mode session */
     fun logTaskInfoChanged(taskUpdate: TaskUpdate) {
         val sessionId = currentSessionId.get()
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging task info changed"
+                "DesktopModeLogger: No session id found for logging task info changed",
             )
             return
         }
@@ -173,11 +163,12 @@
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging task info changed, session: %s taskId: %s",
             sessionId,
-            taskUpdate.instanceId
+            taskUpdate.instanceId,
         )
         logTaskUpdate(
             FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__TASK_EVENT__TASK_INFO_CHANGED,
-            sessionId, taskUpdate
+            sessionId,
+            taskUpdate,
         )
     }
 
@@ -200,30 +191,32 @@
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging start of task resizing"
+                "DesktopModeLogger: No session id found for logging start of task resizing",
             )
             return
         }
 
-        val taskSizeUpdate = createTaskSizeUpdate(
-            resizeTrigger,
-            inputMethod,
-            taskInfo,
-            taskWidth,
-            taskHeight,
-            displayController = displayController,
-            displayLayoutSize = displayLayoutSize,
-        )
+        val taskSizeUpdate =
+            createTaskSizeUpdate(
+                resizeTrigger,
+                inputMethod,
+                taskInfo,
+                taskWidth,
+                taskHeight,
+                displayController = displayController,
+                displayLayoutSize = displayLayoutSize,
+            )
 
         ProtoLog.v(
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging task resize is starting, session: %s, taskSizeUpdate: %s",
             sessionId,
-            taskSizeUpdate
+            taskSizeUpdate,
         )
         logTaskSizeUpdated(
             FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__RESIZING_STAGE__START_RESIZING_STAGE,
-            sessionId, taskSizeUpdate
+            sessionId,
+            taskSizeUpdate,
         )
     }
 
@@ -245,31 +238,33 @@
         if (sessionId == NO_SESSION_ID) {
             ProtoLog.w(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: No session id found for logging end of task resizing"
+                "DesktopModeLogger: No session id found for logging end of task resizing",
             )
             return
         }
 
-        val taskSizeUpdate = createTaskSizeUpdate(
-            resizeTrigger,
-            inputMethod,
-            taskInfo,
-            taskWidth,
-            taskHeight,
-            displayController,
-            displayLayoutSize,
-        )
+        val taskSizeUpdate =
+            createTaskSizeUpdate(
+                resizeTrigger,
+                inputMethod,
+                taskInfo,
+                taskWidth,
+                taskHeight,
+                displayController,
+                displayLayoutSize,
+            )
 
         ProtoLog.v(
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: Logging task resize is ending, session: %s, taskSizeUpdate: %s",
             sessionId,
-            taskSizeUpdate
+            taskSizeUpdate,
         )
 
         logTaskSizeUpdated(
             FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__RESIZING_STAGE__END_RESIZING_STAGE,
-            sessionId, taskSizeUpdate
+            sessionId,
+            taskSizeUpdate,
         )
     }
 
@@ -287,12 +282,15 @@
         val height = taskHeight ?: taskBounds.height()
         val width = taskWidth ?: taskBounds.width()
 
-        val displaySize = when {
-            displayLayoutSize != null -> displayLayoutSize.height * displayLayoutSize.width
-            displayController != null -> displayController.getDisplayLayout(taskInfo.displayId)
-                ?.let { it.height() * it.width() }
-            else -> null
-        }
+        val displaySize =
+            when {
+                displayLayoutSize != null -> displayLayoutSize.height * displayLayoutSize.width
+                displayController != null ->
+                    displayController.getDisplayLayout(taskInfo.displayId)?.let {
+                        it.height() * it.width()
+                    }
+                else -> null
+            }
 
         return TaskSizeUpdate(
             resizeTrigger,
@@ -316,8 +314,8 @@
                 taskHeight = 0,
                 taskWidth = 0,
                 taskX = 0,
-                taskY = 0
-            )
+                taskY = 0,
+            ),
         )
     }
 
@@ -343,7 +341,7 @@
             taskUpdate.minimizeReason?.reason ?: UNSET_MINIMIZE_REASON,
             taskUpdate.unminimizeReason?.reason ?: UNSET_UNMINIMIZE_REASON,
             /* visible_task_count */
-            taskUpdate.visibleTaskCount
+            taskUpdate.visibleTaskCount,
         )
         EventLogTags.writeWmShellDesktopModeTaskUpdate(
             /* task_event */
@@ -365,14 +363,14 @@
             taskUpdate.minimizeReason?.reason ?: UNSET_MINIMIZE_REASON,
             taskUpdate.unminimizeReason?.reason ?: UNSET_UNMINIMIZE_REASON,
             /* visible_task_count */
-            taskUpdate.visibleTaskCount
+            taskUpdate.visibleTaskCount,
         )
     }
 
     private fun logTaskSizeUpdated(
         resizingStage: Int,
         sessionId: Int,
-        taskSizeUpdate: TaskSizeUpdate
+        taskSizeUpdate: TaskSizeUpdate,
     ) {
         FrameworkStatsLog.write(
             DESKTOP_MODE_TASK_SIZE_UPDATED_ATOM_ID,
@@ -393,7 +391,7 @@
             /* task_width */
             taskSizeUpdate.taskWidth,
             /* display_area */
-            taskSizeUpdate.displayArea ?: -1
+            taskSizeUpdate.displayArea ?: -1,
         )
     }
 
@@ -410,7 +408,6 @@
          * @property taskY y-coordinate of the top-left corner
          * @property minimizeReason the reason the task was minimized
          * @property unminimizeEvent the reason the task was unminimized
-         *
          */
         data class TaskUpdate(
             val instanceId: Int,
@@ -425,8 +422,7 @@
         )
 
         /**
-         * Describes a task size update (resizing, snapping or maximizing to
-         * stable bounds).
+         * Describes a task size update (resizing, snapping or maximizing to stable bounds).
          *
          * @property resizeTrigger the trigger for task resize
          * @property inputMethod the input method for resizing this task
@@ -450,9 +446,7 @@
         fun getInputMethodFromMotionEvent(e: MotionEvent?): InputMethod {
             if (e == null) return InputMethod.UNKNOWN_INPUT_METHOD
 
-            val toolType = e.getToolType(
-                e.findPointerIndex(e.getPointerId(0))
-            )
+            val toolType = e.getToolType(e.findPointerIndex(e.getPointerId(0)))
             return when {
                 toolType == TOOL_TYPE_STYLUS -> InputMethod.STYLUS
                 toolType == TOOL_TYPE_MOUSE -> InputMethod.MOUSE
@@ -474,8 +468,7 @@
                     .DESKTOP_MODE_SESSION_TASK_UPDATE__MINIMIZE_REASON__MINIMIZE_TASK_LIMIT
             ),
             MINIMIZE_BUTTON( // TODO(b/356843241): use this enum value
-                FrameworkStatsLog
-                    .DESKTOP_MODE_SESSION_TASK_UPDATE__MINIMIZE_REASON__MINIMIZE_BUTTON
+                FrameworkStatsLog.DESKTOP_MODE_SESSION_TASK_UPDATE__MINIMIZE_REASON__MINIMIZE_BUTTON
             ),
         }
 
@@ -611,20 +604,16 @@
          */
         enum class InputMethod(val method: Int) {
             UNKNOWN_INPUT_METHOD(
-                FrameworkStatsLog
-                    .DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__UNKNOWN_INPUT_METHOD
+                FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__UNKNOWN_INPUT_METHOD
             ),
             TOUCH(
-                FrameworkStatsLog
-                    .DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__TOUCH_INPUT_METHOD
+                FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__TOUCH_INPUT_METHOD
             ),
             STYLUS(
-                FrameworkStatsLog
-                    .DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__STYLUS_INPUT_METHOD
+                FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__STYLUS_INPUT_METHOD
             ),
             MOUSE(
-                FrameworkStatsLog
-                    .DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__MOUSE_INPUT_METHOD
+                FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED__INPUT_METHOD__MOUSE_INPUT_METHOD
             ),
             TOUCHPAD(
                 FrameworkStatsLog
@@ -643,4 +632,4 @@
             FrameworkStatsLog.DESKTOP_MODE_TASK_SIZE_UPDATED
         @VisibleForTesting const val NO_SESSION_ID = 0
     }
-}
\ No newline at end of file
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
index 250e177..71318cf 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeKeyGestureHandler.kt
@@ -16,31 +16,28 @@
 
 package com.android.wm.shell.desktopmode
 
-import android.hardware.input.KeyGestureEvent
-
-import android.hardware.input.InputManager
-import android.hardware.input.InputManager.KeyGestureEventHandler
-import android.os.IBinder
-import com.android.window.flags.Flags.enableMoveToNextDisplayShortcut
-import com.android.wm.shell.ShellTaskOrganizer
 import android.app.ActivityManager.RunningTaskInfo
-import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel
-import com.android.internal.protolog.ProtoLog
 import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
 import android.content.Context
+import android.hardware.input.InputManager
+import android.hardware.input.InputManager.KeyGestureEventHandler
+import android.hardware.input.KeyGestureEvent
+import android.os.IBinder
 import com.android.hardware.input.Flags.manageKeyGestures
+import com.android.internal.protolog.ProtoLog
+import com.android.window.flags.Flags.enableMoveToNextDisplayShortcut
 import com.android.window.flags.Flags.enableTaskResizingKeyboardShortcuts
-import com.android.wm.shell.common.ShellExecutor
+import com.android.wm.shell.ShellTaskOrganizer
 import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.ShellExecutor
 import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
-import com.android.wm.shell.transition.FocusTransitionObserver
 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
 import com.android.wm.shell.shared.annotations.ShellMainThread
+import com.android.wm.shell.transition.FocusTransitionObserver
+import com.android.wm.shell.windowdecor.DesktopModeWindowDecorViewModel
 import java.util.Optional
 
-/**
- * Handles key gesture events (keyboard shortcuts) in Desktop Mode.
- */
+/** Handles key gesture events (keyboard shortcuts) in Desktop Mode. */
 class DesktopModeKeyGestureHandler(
     private val context: Context,
     private val desktopModeWindowDecorViewModel: Optional<DesktopModeWindowDecorViewModel>,
@@ -57,17 +54,18 @@
     }
 
     override fun handleKeyGestureEvent(event: KeyGestureEvent, focusedToken: IBinder?): Boolean {
-        if (!isKeyGestureSupported(event.keyGestureType) || !desktopTasksController.isPresent
-            || !desktopModeWindowDecorViewModel.isPresent) {
+        if (
+            !isKeyGestureSupported(event.keyGestureType) ||
+                !desktopTasksController.isPresent ||
+                !desktopModeWindowDecorViewModel.isPresent
+        ) {
             return false
         }
         when (event.keyGestureType) {
             KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY -> {
                 logV("Key gesture MOVE_TO_NEXT_DISPLAY is handled")
                 getGloballyFocusedFreeformTask()?.let {
-                    desktopTasksController.get().moveToNextDisplay(
-                        it.taskId
-                    )
+                    desktopTasksController.get().moveToNextDisplay(it.taskId)
                 }
                 return true
             }
@@ -75,12 +73,14 @@
                 logV("Key gesture SNAP_LEFT_FREEFORM_WINDOW is handled")
                 getGloballyFocusedFreeformTask()?.let {
                     mainExecutor.execute {
-                        desktopModeWindowDecorViewModel.get().onSnapResize(
-                            it.taskId,
-                            true,
-                            DesktopModeEventLogger.Companion.InputMethod.KEYBOARD,
-                            /* fromMenu= */ false
-                        )
+                        desktopModeWindowDecorViewModel
+                            .get()
+                            .onSnapResize(
+                                it.taskId,
+                                true,
+                                DesktopModeEventLogger.Companion.InputMethod.KEYBOARD,
+                                /* fromMenu= */ false,
+                            )
                     }
                 }
                 return true
@@ -89,12 +89,14 @@
                 logV("Key gesture SNAP_RIGHT_FREEFORM_WINDOW is handled")
                 getGloballyFocusedFreeformTask()?.let {
                     mainExecutor.execute {
-                        desktopModeWindowDecorViewModel.get().onSnapResize(
-                            it.taskId,
-                            false,
-                            DesktopModeEventLogger.Companion.InputMethod.KEYBOARD,
-                            /* fromMenu= */ false
-                        )
+                        desktopModeWindowDecorViewModel
+                            .get()
+                            .onSnapResize(
+                                it.taskId,
+                                false,
+                                DesktopModeEventLogger.Companion.InputMethod.KEYBOARD,
+                                /* fromMenu= */ false,
+                            )
                     }
                 }
                 return true
@@ -103,14 +105,17 @@
                 logV("Key gesture TOGGLE_MAXIMIZE_FREEFORM_WINDOW is handled")
                 getGloballyFocusedFreeformTask()?.let { taskInfo ->
                     mainExecutor.execute {
-                        desktopTasksController.get().toggleDesktopTaskSize(
-                            taskInfo,
-                            ToggleTaskSizeInteraction(
-                                isMaximized = isTaskMaximized(taskInfo, displayController),
-                                source = ToggleTaskSizeInteraction.Source.KEYBOARD_SHORTCUT,
-                                inputMethod = DesktopModeEventLogger.Companion.InputMethod.KEYBOARD
+                        desktopTasksController
+                            .get()
+                            .toggleDesktopTaskSize(
+                                taskInfo,
+                                ToggleTaskSizeInteraction(
+                                    isMaximized = isTaskMaximized(taskInfo, displayController),
+                                    source = ToggleTaskSizeInteraction.Source.KEYBOARD_SHORTCUT,
+                                    inputMethod =
+                                        DesktopModeEventLogger.Companion.InputMethod.KEYBOARD,
+                                ),
                             )
-                        )
                     }
                 }
                 return true
@@ -118,11 +123,7 @@
             KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW -> {
                 logV("Key gesture MINIMIZE_FREEFORM_WINDOW is handled")
                 getGloballyFocusedFreeformTask()?.let {
-                    mainExecutor.execute {
-                        desktopTasksController.get().minimizeTask(
-                            it,
-                        )
-                    }
+                    mainExecutor.execute { desktopTasksController.get().minimizeTask(it) }
                 }
                 return true
             }
@@ -130,16 +131,17 @@
         }
     }
 
-    override fun isKeyGestureSupported(gestureType: Int): Boolean = when (gestureType) {
-        KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY
-            -> enableMoveToNextDisplayShortcut()
-        KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW,
-        KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW,
-        KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW,
-        KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW
-            -> enableTaskResizingKeyboardShortcuts() && manageKeyGestures()
-        else -> false
-    }
+    override fun isKeyGestureSupported(gestureType: Int): Boolean =
+        when (gestureType) {
+            KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY ->
+                enableMoveToNextDisplayShortcut()
+            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW,
+            KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW,
+            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW,
+            KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW ->
+                enableTaskResizingKeyboardShortcuts() && manageKeyGestures()
+            else -> false
+        }
 
     //  TODO: b/364154795 - wait for the completion of moveToNextDisplay transition, otherwise it
     //  will pick a wrong task when a user quickly perform other actions with keyboard shortcuts
@@ -147,7 +149,7 @@
     private fun getGloballyFocusedFreeformTask(): RunningTaskInfo? =
         shellTaskOrganizer.getRunningTasks().find { taskInfo ->
             taskInfo.windowingMode == WINDOWING_MODE_FREEFORM &&
-                    focusTransitionObserver.hasGlobalFocus(taskInfo)
+                focusTransitionObserver.hasGlobalFocus(taskInfo)
         }
 
     private fun logV(msg: String, vararg arguments: Any?) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeLoggerTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeLoggerTransitionObserver.kt
index 41febdf..dfa2d9b 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeLoggerTransitionObserver.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeLoggerTransitionObserver.kt
@@ -60,7 +60,7 @@
     context: Context,
     shellInit: ShellInit,
     private val transitions: Transitions,
-    private val desktopModeEventLogger: DesktopModeEventLogger
+    private val desktopModeEventLogger: DesktopModeEventLogger,
 ) : Transitions.TransitionObserver {
 
     init {
@@ -89,7 +89,8 @@
         transitions.registerObserver(this)
         SystemProperties.set(
             VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
-            VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY_DEFAULT_VALUE)
+            VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY_DEFAULT_VALUE,
+        )
         desktopModeEventLogger.logTaskInfoStateInit()
     }
 
@@ -97,13 +98,13 @@
         transition: IBinder,
         info: TransitionInfo,
         startTransaction: SurfaceControl.Transaction,
-        finishTransaction: SurfaceControl.Transaction
+        finishTransaction: SurfaceControl.Transaction,
     ) {
         // this was a new recents animation
         if (info.isExitToRecentsTransition() && tasksSavedForRecents.isEmpty()) {
             ProtoLog.v(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: Recents animation running, saving tasks for later"
+                "DesktopModeLogger: Recents animation running, saving tasks for later",
             )
             // TODO (b/326391303) - avoid logging session exit if we can identify a cancelled
             // recents animation
@@ -129,7 +130,7 @@
         ) {
             ProtoLog.v(
                 WM_SHELL_DESKTOP_MODE,
-                "DesktopModeLogger: Canceled recents animation, restoring tasks"
+                "DesktopModeLogger: Canceled recents animation, restoring tasks",
             )
             // restore saved tasks in the updated set and clear for next use
             postTransitionVisibleFreeformTasks += tasksSavedForRecents
@@ -140,7 +141,7 @@
         identifyLogEventAndUpdateState(
             transitionInfo = info,
             preTransitionVisibleFreeformTasks = visibleFreeformTaskInfos,
-            postTransitionVisibleFreeformTasks = postTransitionVisibleFreeformTasks
+            postTransitionVisibleFreeformTasks = postTransitionVisibleFreeformTasks,
         )
         wasPreviousTransitionExitToOverview = info.isExitToRecentsTransition()
     }
@@ -200,7 +201,7 @@
         ProtoLog.v(
             WM_SHELL_DESKTOP_MODE,
             "DesktopModeLogger: taskInfo map after processing changes %s",
-            postTransitionFreeformTasks.size()
+            postTransitionFreeformTasks.size(),
         )
 
         return postTransitionFreeformTasks
@@ -226,7 +227,7 @@
     private fun identifyLogEventAndUpdateState(
         transitionInfo: TransitionInfo,
         preTransitionVisibleFreeformTasks: SparseArray<TaskInfo>,
-        postTransitionVisibleFreeformTasks: SparseArray<TaskInfo>
+        postTransitionVisibleFreeformTasks: SparseArray<TaskInfo>,
     ) {
         if (
             postTransitionVisibleFreeformTasks.isEmpty() &&
@@ -236,12 +237,10 @@
             // Sessions is finishing, log task updates followed by an exit event
             identifyAndLogTaskUpdates(
                 preTransitionVisibleFreeformTasks,
-                postTransitionVisibleFreeformTasks
+                postTransitionVisibleFreeformTasks,
             )
 
-            desktopModeEventLogger.logSessionExit(
-                getExitReason(transitionInfo)
-            )
+            desktopModeEventLogger.logSessionExit(getExitReason(transitionInfo))
             isSessionActive = false
         } else if (
             postTransitionVisibleFreeformTasks.isNotEmpty() &&
@@ -250,19 +249,17 @@
         ) {
             // Session is starting, log enter event followed by task updates
             isSessionActive = true
-            desktopModeEventLogger.logSessionEnter(
-                getEnterReason(transitionInfo)
-            )
+            desktopModeEventLogger.logSessionEnter(getEnterReason(transitionInfo))
 
             identifyAndLogTaskUpdates(
                 preTransitionVisibleFreeformTasks,
-                postTransitionVisibleFreeformTasks
+                postTransitionVisibleFreeformTasks,
             )
         } else if (isSessionActive) {
             // Session is neither starting, nor finishing, log task updates if there are any
             identifyAndLogTaskUpdates(
                 preTransitionVisibleFreeformTasks,
-                postTransitionVisibleFreeformTasks
+                postTransitionVisibleFreeformTasks,
             )
         }
 
@@ -274,11 +271,11 @@
     /** Compare the old and new state of taskInfos and identify and log the changes */
     private fun identifyAndLogTaskUpdates(
         preTransitionVisibleFreeformTasks: SparseArray<TaskInfo>,
-        postTransitionVisibleFreeformTasks: SparseArray<TaskInfo>
+        postTransitionVisibleFreeformTasks: SparseArray<TaskInfo>,
     ) {
         postTransitionVisibleFreeformTasks.forEach { taskId, taskInfo ->
-            val currentTaskUpdate = buildTaskUpdateForTask(taskInfo,
-                postTransitionVisibleFreeformTasks.size())
+            val currentTaskUpdate =
+                buildTaskUpdateForTask(taskInfo, postTransitionVisibleFreeformTasks.size())
             val previousTaskInfo = preTransitionVisibleFreeformTasks[taskId]
             when {
                 // new tasks added
@@ -287,16 +284,20 @@
                     Trace.setCounter(
                         Trace.TRACE_TAG_WINDOW_MANAGER,
                         VISIBLE_TASKS_COUNTER_NAME,
-                        postTransitionVisibleFreeformTasks.size().toLong()
+                        postTransitionVisibleFreeformTasks.size().toLong(),
                     )
-                    SystemProperties.set(VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
-                        postTransitionVisibleFreeformTasks.size().toString())
+                    SystemProperties.set(
+                        VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
+                        postTransitionVisibleFreeformTasks.size().toString(),
+                    )
                 }
                 // old tasks that were resized or repositioned
                 // TODO(b/347935387): Log changes only once they are stable.
-                buildTaskUpdateForTask(previousTaskInfo, postTransitionVisibleFreeformTasks.size())
-                        != currentTaskUpdate ->
-                            desktopModeEventLogger.logTaskInfoChanged(currentTaskUpdate)
+                buildTaskUpdateForTask(
+                    previousTaskInfo,
+                    postTransitionVisibleFreeformTasks.size(),
+                ) != currentTaskUpdate ->
+                    desktopModeEventLogger.logTaskInfoChanged(currentTaskUpdate)
             }
         }
 
@@ -304,14 +305,17 @@
         preTransitionVisibleFreeformTasks.forEach { taskId, taskInfo ->
             if (!postTransitionVisibleFreeformTasks.containsKey(taskId)) {
                 desktopModeEventLogger.logTaskRemoved(
-                    buildTaskUpdateForTask(taskInfo, postTransitionVisibleFreeformTasks.size()))
+                    buildTaskUpdateForTask(taskInfo, postTransitionVisibleFreeformTasks.size())
+                )
                 Trace.setCounter(
                     Trace.TRACE_TAG_WINDOW_MANAGER,
                     VISIBLE_TASKS_COUNTER_NAME,
-                    postTransitionVisibleFreeformTasks.size().toLong()
+                    postTransitionVisibleFreeformTasks.size().toLong(),
                 )
-                SystemProperties.set(VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
-                    postTransitionVisibleFreeformTasks.size().toString())
+                SystemProperties.set(
+                    VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY,
+                    postTransitionVisibleFreeformTasks.size().toString(),
+                )
             }
         }
     }
@@ -332,45 +336,50 @@
 
     /** Get [EnterReason] for this session enter */
     private fun getEnterReason(transitionInfo: TransitionInfo): EnterReason {
-       val enterReason = when {
-            transitionInfo.type == WindowManager.TRANSIT_WAKE
-                   // If there is a screen lock, desktop window entry is after dismissing keyguard
-                   || (transitionInfo.type == WindowManager.TRANSIT_TO_BACK
-                   && wasPreviousTransitionExitByScreenOff) -> EnterReason.SCREEN_ON
-            transitionInfo.type == Transitions.TRANSIT_DESKTOP_MODE_END_DRAG_TO_DESKTOP ->
-                EnterReason.APP_HANDLE_DRAG
-            transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON ->
-                EnterReason.APP_HANDLE_MENU_BUTTON
-            transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW ->
-                EnterReason.APP_FROM_OVERVIEW
-            transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT ->
-                EnterReason.KEYBOARD_SHORTCUT_ENTER
-            // NOTE: the below condition also applies for EnterReason quickswitch
-            transitionInfo.type == WindowManager.TRANSIT_TO_FRONT -> EnterReason.OVERVIEW
-            // Enter desktop mode from cancelled recents has no transition. Enter is detected on the
-            // next transition involving freeform windows.
-            // TODO(b/346564416): Modify logging for cancelled recents once it transition is
-            //  changed. Also see how to account to time difference between actual enter time and
-            //  time of this log. Also account for the missed session when exit happens just after
-            //  a cancelled recents.
-            wasPreviousTransitionExitToOverview -> EnterReason.OVERVIEW
-            transitionInfo.type == WindowManager.TRANSIT_OPEN -> EnterReason.APP_FREEFORM_INTENT
-            else -> {
-                ProtoLog.w(
-                    WM_SHELL_DESKTOP_MODE,
-                    "Unknown enter reason for transition type: %s",
-                    transitionInfo.type
-                )
-                EnterReason.UNKNOWN_ENTER
+        val enterReason =
+            when {
+                transitionInfo.type == WindowManager.TRANSIT_WAKE
+                // If there is a screen lock, desktop window entry is after dismissing keyguard
+                ||
+                    (transitionInfo.type == WindowManager.TRANSIT_TO_BACK &&
+                        wasPreviousTransitionExitByScreenOff) -> EnterReason.SCREEN_ON
+                transitionInfo.type == Transitions.TRANSIT_DESKTOP_MODE_END_DRAG_TO_DESKTOP ->
+                    EnterReason.APP_HANDLE_DRAG
+                transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON ->
+                    EnterReason.APP_HANDLE_MENU_BUTTON
+                transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW ->
+                    EnterReason.APP_FROM_OVERVIEW
+                transitionInfo.type == TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT ->
+                    EnterReason.KEYBOARD_SHORTCUT_ENTER
+                // NOTE: the below condition also applies for EnterReason quickswitch
+                transitionInfo.type == WindowManager.TRANSIT_TO_FRONT -> EnterReason.OVERVIEW
+                // Enter desktop mode from cancelled recents has no transition. Enter is detected on
+                // the
+                // next transition involving freeform windows.
+                // TODO(b/346564416): Modify logging for cancelled recents once it transition is
+                //  changed. Also see how to account to time difference between actual enter time
+                // and
+                //  time of this log. Also account for the missed session when exit happens just
+                // after
+                //  a cancelled recents.
+                wasPreviousTransitionExitToOverview -> EnterReason.OVERVIEW
+                transitionInfo.type == WindowManager.TRANSIT_OPEN -> EnterReason.APP_FREEFORM_INTENT
+                else -> {
+                    ProtoLog.w(
+                        WM_SHELL_DESKTOP_MODE,
+                        "Unknown enter reason for transition type: %s",
+                        transitionInfo.type,
+                    )
+                    EnterReason.UNKNOWN_ENTER
+                }
             }
-        }
         wasPreviousTransitionExitByScreenOff = false
         return enterReason
     }
 
     /** Get [ExitReason] for this session exit */
     private fun getExitReason(transitionInfo: TransitionInfo): ExitReason =
-         when {
+        when {
             transitionInfo.type == WindowManager.TRANSIT_SLEEP -> {
                 wasPreviousTransitionExitByScreenOff = true
                 ExitReason.SCREEN_OFF
@@ -387,7 +396,7 @@
                 ProtoLog.w(
                     WM_SHELL_DESKTOP_MODE,
                     "Unknown exit reason for transition type: %s",
-                    transitionInfo.type
+                    transitionInfo.type,
                 )
                 ExitReason.UNKNOWN_EXIT
             }
@@ -413,8 +422,7 @@
     }
 
     companion object {
-        @VisibleForTesting
-        const val VISIBLE_TASKS_COUNTER_NAME = "desktop_mode_visible_tasks"
+        @VisibleForTesting const val VISIBLE_TASKS_COUNTER_NAME = "desktop_mode_visible_tasks"
         @VisibleForTesting
         const val VISIBLE_TASKS_COUNTER_SYSTEM_PROPERTY =
             "debug.tracing." + VISIBLE_TASKS_COUNTER_NAME
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTransitionTypes.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTransitionTypes.kt
index d6fccd1..9b3caca 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTransitionTypes.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTransitionTypes.kt
@@ -43,7 +43,7 @@
                 TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON,
                 TRANSIT_ENTER_DESKTOP_FROM_APP_FROM_OVERVIEW,
                 TRANSIT_ENTER_DESKTOP_FROM_KEYBOARD_SHORTCUT,
-                TRANSIT_ENTER_DESKTOP_FROM_UNKNOWN
+                TRANSIT_ENTER_DESKTOP_FROM_UNKNOWN,
             )
     }
 
@@ -73,7 +73,7 @@
                 TRANSIT_EXIT_DESKTOP_MODE_TASK_DRAG,
                 TRANSIT_EXIT_DESKTOP_MODE_HANDLE_MENU_BUTTON,
                 TRANSIT_EXIT_DESKTOP_MODE_KEYBOARD_SHORTCUT,
-                TRANSIT_EXIT_DESKTOP_MODE_UNKNOWN
+                TRANSIT_EXIT_DESKTOP_MODE_UNKNOWN,
             )
     }
 
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUiEventLogger.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUiEventLogger.kt
index 3821998..301ba9e 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUiEventLogger.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUiEventLogger.kt
@@ -75,7 +75,7 @@
         instanceId: InstanceId,
         uid: Int,
         packageName: String,
-        event: DesktopUiEventEnum
+        event: DesktopUiEventEnum,
     ) {
         if (packageName.isEmpty() || uid < 0) {
             logD("Skip logging since package name is empty or bad uid")
@@ -84,11 +84,12 @@
         uiEventLogger.logWithInstanceId(event, uid, packageName, instanceId)
     }
 
-    private fun getUid(packageName: String, userId: Int): Int = try {
-        packageManager.getApplicationInfoAsUser(packageName, /* flags= */ 0, userId).uid
-    } catch (e: PackageManager.NameNotFoundException) {
-        INVALID_PACKAGE_UID
-    }
+    private fun getUid(packageName: String, userId: Int): Int =
+        try {
+            packageManager.getApplicationInfoAsUser(packageName, /* flags= */ 0, userId).uid
+        } catch (e: PackageManager.NameNotFoundException) {
+            INVALID_PACKAGE_UID
+        }
 
     private fun logD(msg: String, vararg arguments: Any?) {
         ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
index 42c3b1c..14623cf 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeUtils.kt
@@ -37,21 +37,14 @@
 val DESKTOP_MODE_LANDSCAPE_APP_PADDING: Int =
     SystemProperties.getInt("persist.wm.debug.desktop_mode_landscape_app_padding", 25)
 
-/**
- * Calculates the initial bounds to enter desktop, centered on the display.
- */
+/** Calculates the initial bounds to enter desktop, centered on the display. */
 fun calculateDefaultDesktopTaskBounds(displayLayout: DisplayLayout): Rect {
     // TODO(b/319819547): Account for app constraints so apps do not become letterboxed
     val desiredWidth = (displayLayout.width() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE).toInt()
     val desiredHeight = (displayLayout.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE).toInt()
     val heightOffset = (displayLayout.height() - desiredHeight) / 2
     val widthOffset = (displayLayout.width() - desiredWidth) / 2
-    return Rect(
-        widthOffset,
-        heightOffset,
-        desiredWidth + widthOffset,
-        desiredHeight + heightOffset
-    )
+    return Rect(widthOffset, heightOffset, desiredWidth + widthOffset, desiredHeight + heightOffset)
 }
 
 /**
@@ -63,7 +56,7 @@
 fun calculateInitialBounds(
     displayLayout: DisplayLayout,
     taskInfo: RunningTaskInfo,
-    scale: Float = DESKTOP_MODE_INITIAL_BOUNDS_SCALE
+    scale: Float = DESKTOP_MODE_INITIAL_BOUNDS_SCALE,
 ): Rect {
     val screenBounds = Rect(0, 0, displayLayout.width(), displayLayout.height())
     val appAspectRatio = calculateAspectRatio(taskInfo)
@@ -88,8 +81,10 @@
                     if (isFixedOrientationPortrait(topActivityInfo.screenOrientation)) {
                         // For portrait resizeable activities, respect apps fullscreen width but
                         // apply ideal size height.
-                        Size(taskInfo.appCompatTaskInfo.topActivityLetterboxAppWidth,
-                            idealSize.height)
+                        Size(
+                            taskInfo.appCompatTaskInfo.topActivityLetterboxAppWidth,
+                            idealSize.height,
+                        )
                     } else {
                         // For landscape resizeable activities, simply apply ideal size.
                         idealSize
@@ -109,7 +104,7 @@
                         // apply custom app width.
                         Size(
                             customPortraitWidthForLandscapeApp,
-                            taskInfo.appCompatTaskInfo.topActivityLetterboxAppHeight
+                            taskInfo.appCompatTaskInfo.topActivityLetterboxAppHeight,
                         )
                     } else {
                         // For portrait resizeable activities, simply apply ideal size.
@@ -123,7 +118,7 @@
                         maximizeSizeGivenAspectRatio(
                             taskInfo,
                             Size(customPortraitWidthForLandscapeApp, idealSize.height),
-                            appAspectRatio
+                            appAspectRatio,
                         )
                     } else {
                         // For portrait unresizeable activities, calculate maximum size (within the
@@ -141,13 +136,10 @@
 }
 
 /**
- * Calculates the maximized bounds of a task given in the given [DisplayLayout], taking
- * resizability into consideration.
+ * Calculates the maximized bounds of a task given in the given [DisplayLayout], taking resizability
+ * into consideration.
  */
-fun calculateMaximizeBounds(
-    displayLayout: DisplayLayout,
-    taskInfo: RunningTaskInfo,
-): Rect {
+fun calculateMaximizeBounds(displayLayout: DisplayLayout, taskInfo: RunningTaskInfo): Rect {
     val stableBounds = Rect()
     displayLayout.getStableBounds(stableBounds)
     if (taskInfo.isResizeable) {
@@ -156,10 +148,13 @@
     } else {
         // if non-resizable then calculate max bounds according to aspect ratio
         val activityAspectRatio = calculateAspectRatio(taskInfo)
-        val newSize = maximizeSizeGivenAspectRatio(taskInfo,
-            Size(stableBounds.width(), stableBounds.height()), activityAspectRatio)
-        return centerInArea(
-            newSize, stableBounds, stableBounds.left, stableBounds.top)
+        val newSize =
+            maximizeSizeGivenAspectRatio(
+                taskInfo,
+                Size(stableBounds.width(), stableBounds.height()),
+                activityAspectRatio,
+            )
+        return centerInArea(newSize, stableBounds, stableBounds.left, stableBounds.top)
     }
 }
 
@@ -170,7 +165,7 @@
 fun maximizeSizeGivenAspectRatio(
     taskInfo: RunningTaskInfo,
     targetArea: Size,
-    aspectRatio: Float
+    aspectRatio: Float,
 ): Size {
     val targetHeight = targetArea.height
     val targetWidth = targetArea.width
@@ -213,22 +208,17 @@
 }
 
 /** Returns whether the task is maximized. */
-fun isTaskMaximized(
-    taskInfo: RunningTaskInfo,
-    displayController: DisplayController
-): Boolean {
-    val displayLayout = displayController.getDisplayLayout(taskInfo.displayId)
-        ?: error("Could not get display layout for display=${taskInfo.displayId}")
+fun isTaskMaximized(taskInfo: RunningTaskInfo, displayController: DisplayController): Boolean {
+    val displayLayout =
+        displayController.getDisplayLayout(taskInfo.displayId)
+            ?: error("Could not get display layout for display=${taskInfo.displayId}")
     val stableBounds = Rect()
     displayLayout.getStableBounds(stableBounds)
     return isTaskMaximized(taskInfo, stableBounds)
 }
 
 /** Returns whether the task is maximized. */
-fun isTaskMaximized(
-    taskInfo: RunningTaskInfo,
-    stableBounds: Rect
-): Boolean {
+fun isTaskMaximized(taskInfo: RunningTaskInfo, stableBounds: Rect): Boolean {
     val currentTaskBounds = taskInfo.configuration.windowConfiguration.bounds
     return if (taskInfo.isResizeable) {
         isTaskBoundsEqual(currentTaskBounds, stableBounds)
@@ -240,13 +230,13 @@
 /** Returns true if task's width or height is maximized else returns false. */
 fun isTaskWidthOrHeightEqual(taskBounds: Rect, stableBounds: Rect): Boolean {
     return taskBounds.width() == stableBounds.width() ||
-            taskBounds.height() == stableBounds.height()
+        taskBounds.height() == stableBounds.height()
 }
 
 /** Returns true if task bound is equal to stable bounds else returns false. */
 fun isTaskBoundsEqual(taskBounds: Rect, stableBounds: Rect): Boolean {
     return taskBounds.width() == stableBounds.width() &&
-            taskBounds.height() == stableBounds.height()
+        taskBounds.height() == stableBounds.height()
 }
 
 /**
@@ -274,8 +264,8 @@
     get() = isResizeable && !appCompatTaskInfo.hasMinAspectRatioOverride()
 
 /**
- * Adjusts bounds to be positioned in the middle of the area provided, not necessarily the
- * entire screen, as area can be offset by left and top start.
+ * Adjusts bounds to be positioned in the middle of the area provided, not necessarily the entire
+ * screen, as area can be offset by left and top start.
  */
 fun centerInArea(desiredSize: Size, areaBounds: Rect, leftStart: Int, topStart: Int): Rect {
     val heightOffset = (areaBounds.height() - desiredSize.height) / 2
@@ -312,6 +302,6 @@
 }
 
 private fun hasFullscreenOverride(taskInfo: RunningTaskInfo): Boolean {
-    return taskInfo.appCompatTaskInfo.isUserFullscreenOverrideEnabled
-            || taskInfo.appCompatTaskInfo.isSystemFullscreenOverrideEnabled
+    return taskInfo.appCompatTaskInfo.isUserFullscreenOverrideEnabled ||
+        taskInfo.appCompatTaskInfo.isSystemFullscreenOverrideEnabled
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
index ca3dc2d..e187d2c 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopRepository.kt
@@ -16,7 +16,6 @@
 
 package com.android.wm.shell.desktopmode
 
-import android.content.pm.UserInfo
 import android.graphics.Rect
 import android.graphics.Region
 import android.util.ArrayMap
@@ -39,23 +38,23 @@
 import kotlinx.coroutines.launch
 
 /** Tracks desktop data for Android Desktop Windowing. */
-class DesktopRepository (
+class DesktopRepository(
     private val persistentRepository: DesktopPersistentRepository,
     @ShellMainThread private val mainCoroutineScope: CoroutineScope,
     val userId: Int,
-){
+) {
     /**
      * Task data tracked per desktop.
      *
      * @property activeTasks task ids of active tasks currently or previously visible in Desktop
-     * mode session. Tasks become inactive when task closes or when desktop mode session ends.
+     *   mode session. Tasks become inactive when task closes or when desktop mode session ends.
      * @property visibleTasks task ids for active freeform tasks that are currently visible. There
-     * might be other active tasks in desktop mode that are not visible.
+     *   might be other active tasks in desktop mode that are not visible.
      * @property minimizedTasks task ids for active freeform tasks that are currently minimized.
      * @property closingTasks task ids for tasks that are going to close, but are currently visible.
      * @property freeformTasksInZOrder list of current freeform task ids ordered from top to bottom
      * @property fullImmersiveTaskId the task id of the desktop task that is in full-immersive mode.
-     * (top is at index 0).
+     *   (top is at index 0).
      */
     private data class DesktopTaskData(
         val activeTasks: ArraySet<Int> = ArraySet(),
@@ -66,14 +65,16 @@
         val freeformTasksInZOrder: ArrayList<Int> = ArrayList(),
         var fullImmersiveTaskId: Int? = null,
     ) {
-        fun deepCopy(): DesktopTaskData = DesktopTaskData(
-            activeTasks = ArraySet(activeTasks),
-            visibleTasks = ArraySet(visibleTasks),
-            minimizedTasks = ArraySet(minimizedTasks),
-            closingTasks = ArraySet(closingTasks),
-            freeformTasksInZOrder = ArrayList(freeformTasksInZOrder),
-            fullImmersiveTaskId = fullImmersiveTaskId
-        )
+        fun deepCopy(): DesktopTaskData =
+            DesktopTaskData(
+                activeTasks = ArraySet(activeTasks),
+                visibleTasks = ArraySet(visibleTasks),
+                minimizedTasks = ArraySet(minimizedTasks),
+                closingTasks = ArraySet(closingTasks),
+                freeformTasksInZOrder = ArrayList(freeformTasksInZOrder),
+                fullImmersiveTaskId = fullImmersiveTaskId,
+            )
+
         fun clear() {
             activeTasks.clear()
             visibleTasks.clear()
@@ -105,11 +106,12 @@
     private var desktopGestureExclusionListener: Consumer<Region>? = null
     private var desktopGestureExclusionExecutor: Executor? = null
 
-    private val desktopTaskDataByDisplayId = object : SparseArray<DesktopTaskData>() {
-        /** Gets [DesktopTaskData] for existing [displayId] or creates a new one. */
-        fun getOrCreate(displayId: Int): DesktopTaskData =
-            this[displayId] ?: DesktopTaskData().also { this[displayId] = it }
-    }
+    private val desktopTaskDataByDisplayId =
+        object : SparseArray<DesktopTaskData>() {
+            /** Gets [DesktopTaskData] for existing [displayId] or creates a new one. */
+            fun getOrCreate(displayId: Int): DesktopTaskData =
+                this[displayId] ?: DesktopTaskData().also { this[displayId] = it }
+        }
 
     /** Adds [activeTasksListener] to be notified of updates to active tasks. */
     fun addActiveTaskListener(activeTasksListener: ActiveTasksListener) {
@@ -121,9 +123,7 @@
         visibleTasksListeners[visibleTasksListener] = executor
         desktopTaskDataByDisplayId.keyIterator().forEach {
             val visibleTaskCount = getVisibleTaskCount(it)
-            executor.execute {
-                visibleTasksListener.onTasksVisibilityChanged(it, visibleTaskCount)
-            }
+            executor.execute { visibleTasksListener.onTasksVisibilityChanged(it, visibleTaskCount) }
         }
     }
 
@@ -185,8 +185,7 @@
     /** Removes task from active task list of displays excluding the [excludedDisplayId]. */
     fun removeActiveTask(taskId: Int, excludedDisplayId: Int? = null) {
         desktopTaskDataByDisplayId.forEach { displayId, desktopTaskData ->
-            if ((displayId != excludedDisplayId)
-                && desktopTaskData.activeTasks.remove(taskId)) {
+            if ((displayId != excludedDisplayId) && desktopTaskData.activeTasks.remove(taskId)) {
                 logD("Removed active task=%d displayId=%d", taskId, displayId)
                 updateActiveTasksListeners(displayId)
             }
@@ -213,16 +212,18 @@
     }
 
     fun isActiveTask(taskId: Int) = desktopTaskDataSequence().any { taskId in it.activeTasks }
+
     fun isClosingTask(taskId: Int) = desktopTaskDataSequence().any { taskId in it.closingTasks }
+
     fun isVisibleTask(taskId: Int) = desktopTaskDataSequence().any { taskId in it.visibleTasks }
+
     fun isMinimizedTask(taskId: Int) = desktopTaskDataSequence().any { taskId in it.minimizedTasks }
 
     /** Checks if a task is the only visible, non-closing, non-minimized task on its display. */
     fun isOnlyVisibleNonClosingTask(taskId: Int): Boolean =
-        desktopTaskDataSequence().any { it.visibleTasks
-            .subtract(it.closingTasks)
-            .subtract(it.minimizedTasks)
-            .singleOrNull() == taskId
+        desktopTaskDataSequence().any {
+            it.visibleTasks.subtract(it.closingTasks).subtract(it.minimizedTasks).singleOrNull() ==
+                taskId
         }
 
     fun getActiveTasks(displayId: Int): ArraySet<Int> =
@@ -256,8 +257,8 @@
     /**
      * Updates visibility of a freeform task with [taskId] on [displayId] and notifies listeners.
      *
-     * 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.
+     * 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 updateTask(displayId: Int, taskId: Int, isVisible: Boolean) {
         logD("updateTask taskId=%d, displayId=%d, isVisible=%b", taskId, displayId, isVisible)
@@ -279,8 +280,12 @@
         }
         val newCount = getVisibleTaskCount(displayId)
         if (prevCount != newCount) {
-            logD("Update task visibility taskId=%d visible=%b displayId=%d",
-                taskId, isVisible, displayId)
+            logD(
+                "Update task visibility taskId=%d visible=%b displayId=%d",
+                taskId,
+                isVisible,
+                displayId,
+            )
             logD("VisibleTaskCount has changed from %d to %d", prevCount, newCount)
             notifyVisibleTaskListeners(displayId, newCount)
             if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue()) {
@@ -318,9 +323,8 @@
 
     /** Gets number of visible tasks on given [displayId] */
     fun getVisibleTaskCount(displayId: Int): Int =
-        desktopTaskDataByDisplayId[displayId]?.visibleTasks?.size ?: 0.also {
-            logD("getVisibleTaskCount=$it")
-        }
+        desktopTaskDataByDisplayId[displayId]?.visibleTasks?.size
+            ?: 0.also { logD("getVisibleTaskCount=$it") }
 
     /**
      * Adds task (or moves if it already exists) to the top of the ordered list.
@@ -343,9 +347,8 @@
         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)
+            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)
@@ -359,8 +362,8 @@
     /** Unminimizes the task for [taskId] and [displayId] */
     fun unminimizeTask(displayId: Int, taskId: Int) {
         logD("Unminimize Task: display=%d, task=%d", displayId, taskId)
-        desktopTaskDataByDisplayId[displayId]?.minimizedTasks?.remove(taskId) ?:
-            logW("Unminimize Task: display=%d, task=%d, no task data", displayId, taskId)
+        desktopTaskDataByDisplayId[displayId]?.minimizedTasks?.remove(taskId)
+            ?: logW("Unminimize Task: display=%d, task=%d, no task data", displayId, taskId)
     }
 
     private fun getDisplayIdForTask(taskId: Int): Int? {
@@ -393,16 +396,14 @@
         desktopTaskDataByDisplayId[displayId]?.freeformTasksInZOrder?.remove(taskId)
         boundsBeforeMaximizeByTaskId.remove(taskId)
         boundsBeforeFullImmersiveByTaskId.remove(taskId)
-        logD("Remaining freeform tasks: %s",
-            desktopTaskDataByDisplayId[displayId]?.freeformTasksInZOrder?.toDumpString())
+        logD(
+            "Remaining freeform tasks: %s",
+            desktopTaskDataByDisplayId[displayId]?.freeformTasksInZOrder?.toDumpString(),
+        )
         // Remove task from unminimized task if it is minimized.
         unminimizeTask(displayId, taskId)
         // Mark task as not in immersive if it was immersive.
-        setTaskInFullImmersiveState(
-            displayId = displayId,
-            taskId = taskId,
-            immersive = false
-        )
+        setTaskInFullImmersiveState(displayId = displayId, taskId = taskId, immersive = false)
         removeActiveTask(taskId)
         removeVisibleTask(taskId)
         if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PERSISTENCE.isTrue()) {
@@ -485,12 +486,12 @@
                         desktopId = displayId,
                         visibleTasks = desktopTaskDataByDisplayIdCopy.visibleTasks,
                         minimizedTasks = desktopTaskDataByDisplayIdCopy.minimizedTasks,
-                        freeformTasksInZOrder = desktopTaskDataByDisplayIdCopy.freeformTasksInZOrder
+                        freeformTasksInZOrder = desktopTaskDataByDisplayIdCopy.freeformTasksInZOrder,
                     )
                 } catch (exception: Exception) {
                     logE(
                         "An exception occurred while updating the persistent repository \n%s",
-                        exception.stackTrace
+                        exception.stackTrace,
                     )
                 }
             }
@@ -516,7 +517,7 @@
             )
             pw.println("${innerPrefix}minimizedTasks=${data.minimizedTasks.toDumpString()}")
             pw.println("${innerPrefix}fullImmersiveTaskId=${data.fullImmersiveTaskId}")
-            pw.println("${innerPrefix}wallpaperActivityToken=${wallpaperActivityToken}")
+            pw.println("${innerPrefix}wallpaperActivityToken=$wallpaperActivityToken")
         }
     }
 
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt
index 80d8bfb..947a8dd 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskChangeListener.kt
@@ -22,80 +22,81 @@
 import com.android.wm.shell.freeform.TaskChangeListener
 
 /** Manages tasks handling specific to Android Desktop Mode. */
-class DesktopTaskChangeListener(
-  private val desktopUserRepositories: DesktopUserRepositories,
-) : TaskChangeListener {
+class DesktopTaskChangeListener(private val desktopUserRepositories: DesktopUserRepositories) :
+    TaskChangeListener {
 
-  override fun onTaskOpening(taskInfo: RunningTaskInfo) {
-    val desktopRepository: DesktopRepository =
-      desktopUserRepositories.getProfile(taskInfo.userId)
-    if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
-      desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
-      return
+    override fun onTaskOpening(taskInfo: RunningTaskInfo) {
+        val desktopRepository: DesktopRepository =
+            desktopUserRepositories.getProfile(taskInfo.userId)
+        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
+            desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+            return
+        }
+        if (isFreeformTask(taskInfo)) {
+            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
+        }
     }
-    if (isFreeformTask(taskInfo)) {
-      desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
+
+    override fun onTaskChanging(taskInfo: RunningTaskInfo) {
+        val desktopRepository: DesktopRepository =
+            desktopUserRepositories.getProfile(taskInfo.userId)
+        if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
+
+        // Case 1: Freeform task is changed in Desktop Mode.
+        if (isFreeformTask(taskInfo)) {
+            if (taskInfo.isVisible) {
+                desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
+            }
+            desktopRepository.updateTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
+        } else {
+            // Case 2: Freeform task is changed outside Desktop Mode.
+            desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+        }
     }
-  }
 
-  override fun onTaskChanging(taskInfo: RunningTaskInfo) {
-    val desktopRepository: DesktopRepository =
-      desktopUserRepositories.getProfile(taskInfo.userId)
-    if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
-
-    // Case 1: Freeform task is changed in Desktop Mode.
-    if (isFreeformTask(taskInfo)) {
-      if (taskInfo.isVisible) {
-        desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
-      }
-      desktopRepository.updateTask(
-          taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
-    } else {
-      // Case 2: Freeform task is changed outside Desktop Mode.
-      desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+    // This method should only be used for scenarios where the task info changes are not propagated
+    // to
+    // [DesktopTaskChangeListener#onTaskChanging] via [TransitionsObserver].
+    // Any changes to [DesktopRepository] from this method should be made carefully to minimize risk
+    // of race conditions and possible duplications with [onTaskChanging].
+    override fun onNonTransitionTaskChanging(taskInfo: RunningTaskInfo) {
+        // TODO: b/367268953 - Propapagate usages from FreeformTaskListener to this method.
     }
-  }
 
-  // This method should only be used for scenarios where the task info changes are not propagated to
-  // [DesktopTaskChangeListener#onTaskChanging] via [TransitionsObserver].
-  // Any changes to [DesktopRepository] from this method should be made carefully to minimize risk
-  // of race conditions and possible duplications with [onTaskChanging].
-  override fun onNonTransitionTaskChanging(taskInfo: RunningTaskInfo) {
-    // TODO: b/367268953 - Propapagate usages from FreeformTaskListener to this method.
-  }
-
-  override fun onTaskMovingToFront(taskInfo: RunningTaskInfo) {
-    val desktopRepository: DesktopRepository =
-      desktopUserRepositories.getProfile(taskInfo.userId)
-    if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
-    if (!isFreeformTask(taskInfo)) {
-      desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+    override fun onTaskMovingToFront(taskInfo: RunningTaskInfo) {
+        val desktopRepository: DesktopRepository =
+            desktopUserRepositories.getProfile(taskInfo.userId)
+        if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
+        if (!isFreeformTask(taskInfo)) {
+            desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+        }
+        // TODO: b/367268953 - Connect this with DesktopRepository for handling
+        // task moving to front for tasks in windowing mode.
     }
-    // TODO: b/367268953 - Connect this with DesktopRepository for handling
-    // task moving to front for tasks in windowing mode.
-  }
 
-  override fun onTaskMovingToBack(taskInfo: RunningTaskInfo) {
-    // TODO: b/367268953 - Connect this with DesktopRepository.
-  }
-
-  override fun onTaskClosing(taskInfo: RunningTaskInfo) {
-    val desktopRepository: DesktopRepository =
-      desktopUserRepositories.getProfile(taskInfo.userId)
-    if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
-    // TODO: b/370038902 - Handle Activity#finishAndRemoveTask.
-    if (!DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue() ||
-        desktopRepository.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.
-      desktopRepository.removeClosingTask(taskInfo.taskId)
-      desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
-    } else {
-      desktopRepository.updateTask(taskInfo.displayId, taskInfo.taskId, isVisible = false)
-      desktopRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
+    override fun onTaskMovingToBack(taskInfo: RunningTaskInfo) {
+        // TODO: b/367268953 - Connect this with DesktopRepository.
     }
-  }
 
-  private fun isFreeformTask(taskInfo: RunningTaskInfo): Boolean =
-      taskInfo.windowingMode == WINDOWING_MODE_FREEFORM
+    override fun onTaskClosing(taskInfo: RunningTaskInfo) {
+        val desktopRepository: DesktopRepository =
+            desktopUserRepositories.getProfile(taskInfo.userId)
+        if (!desktopRepository.isActiveTask(taskInfo.taskId)) return
+        // TODO: b/370038902 - Handle Activity#finishAndRemoveTask.
+        if (
+            !DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue() ||
+                desktopRepository.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.
+            desktopRepository.removeClosingTask(taskInfo.taskId)
+            desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
+        } else {
+            desktopRepository.updateTask(taskInfo.displayId, taskInfo.taskId, isVisible = false)
+            desktopRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
+        }
+    }
+
+    private fun isFreeformTask(taskInfo: RunningTaskInfo): Boolean =
+        taskInfo.windowingMode == WINDOWING_MODE_FREEFORM
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskPosition.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskPosition.kt
index 65f12cf..848d80f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskPosition.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTaskPosition.kt
@@ -22,16 +22,14 @@
 import android.graphics.Rect
 import android.view.Gravity
 import com.android.internal.annotations.VisibleForTesting
+import com.android.wm.shell.R
 import com.android.wm.shell.desktopmode.DesktopTaskPosition.BottomLeft
 import com.android.wm.shell.desktopmode.DesktopTaskPosition.BottomRight
 import com.android.wm.shell.desktopmode.DesktopTaskPosition.Center
 import com.android.wm.shell.desktopmode.DesktopTaskPosition.TopLeft
 import com.android.wm.shell.desktopmode.DesktopTaskPosition.TopRight
-import com.android.wm.shell.R
 
-/**
- * The position of a task window in desktop mode.
- */
+/** The position of a task window in desktop mode. */
 sealed class DesktopTaskPosition {
     data object Center : DesktopTaskPosition() {
         private const val WINDOW_HEIGHT_PROPORTION = 0.375
@@ -89,8 +87,8 @@
     }
 
     /**
-     * Returns the top left coordinates for the window to be placed in the given
-     * DesktopTaskPosition in the frame.
+     * Returns the top left coordinates for the window to be placed in the given DesktopTaskPosition
+     * in the frame.
      */
     abstract fun getTopLeftCoordinates(frame: Rect, window: Rect): Point
 
@@ -98,8 +96,8 @@
 }
 
 /**
- * If the app has specified horizontal or vertical gravity layout, don't change the
- * task position for cascading effect.
+ * If the app has specified horizontal or vertical gravity layout, don't change the task position
+ * for cascading effect.
  */
 fun canChangeTaskPosition(taskInfo: TaskInfo): Boolean {
     taskInfo.topActivityInfo?.windowLayout?.let {
@@ -110,9 +108,7 @@
     return true
 }
 
-/**
- * Returns the current DesktopTaskPosition for a given window in the frame.
- */
+/** Returns the current DesktopTaskPosition for a given window in the frame. */
 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
 fun Rect.getDesktopTaskPosition(bounds: Rect): DesktopTaskPosition {
     return when {
@@ -140,8 +136,8 @@
 
 internal fun prevBoundsMovedAboveThreshold(res: Resources, prev: Rect, newBounds: Rect): Boolean {
     // This is the required minimum dp for a task to be touchable.
-    val moveThresholdPx = res.getDimensionPixelSize(
-        R.dimen.freeform_required_visible_empty_space_in_header)
+    val moveThresholdPx =
+        res.getDimensionPixelSize(R.dimen.freeform_required_visible_empty_space_in_header)
     val leftFar = newBounds.left - prev.left > moveThresholdPx
     val topFar = newBounds.top - prev.top > moveThresholdPx
     val rightFar = prev.right - newBounds.right > moveThresholdPx
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
index 5cb94f8..cf8a9ae 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt
@@ -84,11 +84,17 @@
 import com.android.wm.shell.common.SingleInstanceRemoteListener
 import com.android.wm.shell.common.SyncTransactionQueue
 import com.android.wm.shell.compatui.isTopActivityExemptFromDesktopWindowing
-import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
+import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.InputMethod
+import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
+import com.android.wm.shell.desktopmode.DesktopModeUiEventLogger.DesktopUiEventEnum
 import com.android.wm.shell.desktopmode.DesktopModeVisualIndicator.DragStartState
 import com.android.wm.shell.desktopmode.DesktopModeVisualIndicator.IndicatorType
 import com.android.wm.shell.desktopmode.DesktopRepository.VisibleTasksListener
+import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.Companion.DRAG_TO_DESKTOP_FINISH_ANIM_DURATION_MS
 import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.DragToDesktopStateListener
+import com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FREEFORM_ANIMATION_DURATION
+import com.android.wm.shell.desktopmode.ExitDesktopTaskTransitionHandler.FULLSCREEN_ANIMATION_DURATION
+import com.android.wm.shell.desktopmode.common.ToggleTaskSizeInteraction
 import com.android.wm.shell.desktopmode.minimize.DesktopWindowLimitRemoteHandler
 import com.android.wm.shell.draganddrop.DragAndDropController
 import com.android.wm.shell.freeform.FreeformTaskTransitionStarter
@@ -96,6 +102,8 @@
 import com.android.wm.shell.recents.RecentTasksController
 import com.android.wm.shell.recents.RecentsTransitionHandler
 import com.android.wm.shell.recents.RecentsTransitionStateListener
+import com.android.wm.shell.recents.RecentsTransitionStateListener.RecentsTransitionState
+import com.android.wm.shell.recents.RecentsTransitionStateListener.TRANSITION_STATE_NOT_RUNNING
 import com.android.wm.shell.shared.ShellSharedConstants
 import com.android.wm.shell.shared.TransitionUtil
 import com.android.wm.shell.shared.annotations.ExternalThread
@@ -129,14 +137,6 @@
 import java.util.Optional
 import java.util.concurrent.Executor
 import java.util.function.Consumer
-import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.InputMethod
-import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
-import com.android.wm.shell.desktopmode.DesktopModeUiEventLogger.DesktopUiEventEnum
-import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler.Companion.DRAG_TO_DESKTOP_FINISH_ANIM_DURATION_MS
-import com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FREEFORM_ANIMATION_DURATION
-import com.android.wm.shell.desktopmode.ExitDesktopTaskTransitionHandler.FULLSCREEN_ANIMATION_DURATION
-import com.android.wm.shell.recents.RecentsTransitionStateListener.RecentsTransitionState
-import com.android.wm.shell.recents.RecentsTransitionStateListener.TRANSITION_STATE_NOT_RUNNING
 
 /** Handles moving tasks in and out of desktop */
 class DesktopTasksController(
@@ -205,8 +205,7 @@
             }
         }
 
-    @VisibleForTesting
-    var taskbarDesktopTaskListener: TaskbarDesktopTaskListener? = null
+    @VisibleForTesting var taskbarDesktopTaskListener: TaskbarDesktopTaskListener? = null
 
     @VisibleForTesting
     var desktopModeEnterExitTransitionListener: DesktopModeEntryExitTransitionListener? = null
@@ -215,8 +214,7 @@
     val draggingTaskId
         get() = dragToDesktopTransitionHandler.draggingTaskId
 
-    @RecentsTransitionState
-    private var recentsTransitionState = TRANSITION_STATE_NOT_RUNNING
+    @RecentsTransitionState private var recentsTransitionState = TRANSITION_STATE_NOT_RUNNING
 
     private lateinit var splitScreenController: SplitScreenController
     lateinit var freeformTaskTransitionStarter: FreeformTaskTransitionStarter
@@ -240,7 +238,7 @@
         shellController.addExternalInterface(
             ShellSharedConstants.KEY_EXTRA_SHELL_DESKTOP_MODE,
             { createExternalInterface() },
-            this
+            this,
         )
         shellController.addUserChangeListener(this)
         transitions.addHandler(this)
@@ -250,7 +248,7 @@
                 override fun onTransitionStateChanged(@RecentsTransitionState state: Int) {
                     logV(
                         "Recents transition state changed: %s",
-                        RecentsTransitionStateListener.stateToString(state)
+                        RecentsTransitionStateListener.stateToString(state),
                     )
                     recentsTransitionState = state
                     desktopTilingDecorViewModel.onOverviewAnimationStateChange(
@@ -300,17 +298,17 @@
         bringDesktopAppsToFront(displayId, wct)
 
         val transitionType = transitionType(remoteTransition)
-        val handler = remoteTransition?.let {
-            OneShotRemoteHandler(transitions.mainExecutor, remoteTransition)
-        }
+        val handler =
+            remoteTransition?.let {
+                OneShotRemoteHandler(transitions.mainExecutor, remoteTransition)
+            }
         transitions.startTransition(transitionType, wct, handler).also { t ->
             handler?.setTransition(t)
         }
     }
 
     /** Gets number of visible tasks in [displayId]. */
-    fun visibleTaskCount(displayId: Int): Int =
-        taskRepository.getVisibleTaskCount(displayId)
+    fun visibleTaskCount(displayId: Int): Int = taskRepository.getVisibleTaskCount(displayId)
 
     /** Returns true if any tasks are visible in Desktop Mode. */
     fun isDesktopModeShowing(displayId: Int): Boolean = visibleTaskCount(displayId) > 0
@@ -321,29 +319,37 @@
         when (allFocusedTasks.size) {
             0 -> return
             // Full screen case
-            1 -> moveRunningTaskToDesktop(
-                allFocusedTasks.single(), transitionSource = transitionSource)
+            1 ->
+                moveRunningTaskToDesktop(
+                    allFocusedTasks.single(),
+                    transitionSource = transitionSource,
+                )
             // Split-screen case where there are two focused tasks, then we find the child
             // task to move to desktop.
-            2 -> moveRunningTaskToDesktop(
-                getSplitFocusedTask(allFocusedTasks[0], allFocusedTasks[1]),
-                    transitionSource = transitionSource)
-            else -> logW(
-                "DesktopTasksController: Cannot enter desktop, expected less " +
-                "than 3 focused tasks but found %d", allFocusedTasks.size)
+            2 ->
+                moveRunningTaskToDesktop(
+                    getSplitFocusedTask(allFocusedTasks[0], allFocusedTasks[1]),
+                    transitionSource = transitionSource,
+                )
+            else ->
+                logW(
+                    "DesktopTasksController: Cannot enter desktop, expected less " +
+                        "than 3 focused tasks but found %d",
+                    allFocusedTasks.size,
+                )
         }
     }
 
     /**
-     * Returns all focused tasks in full screen or split screen mode in [displayId] when
-     * it is not the home activity.
+     * Returns all focused tasks in full screen or split screen mode in [displayId] when it is not
+     * the home activity.
      */
     private fun getAllFocusedTasks(displayId: Int): List<RunningTaskInfo> =
         shellTaskOrganizer.getRunningTasks(displayId).filter {
             it.isFocused &&
-            (it.windowingMode == WINDOWING_MODE_FULLSCREEN ||
-                it.windowingMode == WINDOWING_MODE_MULTI_WINDOW) &&
-            it.activityType != ACTIVITY_TYPE_HOME
+                (it.windowingMode == WINDOWING_MODE_FULLSCREEN ||
+                    it.windowingMode == WINDOWING_MODE_MULTI_WINDOW) &&
+                it.activityType != ACTIVITY_TYPE_HOME
         }
 
     /** Returns child task from two focused tasks in split screen mode. */
@@ -379,9 +385,9 @@
     }
 
     private fun moveBackgroundTaskToDesktop(
-            taskId: Int,
-            wct: WindowContainerTransaction,
-            transitionSource: DesktopModeTransitionSource,
+        taskId: Int,
+        wct: WindowContainerTransaction,
+        transitionSource: DesktopModeTransitionSource,
     ): Boolean {
         if (recentTasksController?.findTaskInBackground(taskId) == null) {
             logW("moveBackgroundTaskToDesktop taskId=%d not found", taskId)
@@ -389,54 +395,62 @@
         }
         logV("moveBackgroundTaskToDesktop with taskId=%d", taskId)
         // TODO(342378842): Instead of using default display, support multiple displays
-        val taskIdToMinimize = bringDesktopAppsToFrontBeforeShowingNewTask(
-            DEFAULT_DISPLAY, wct, taskId)
-        val exitResult = desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            displayId = DEFAULT_DISPLAY,
-            excludeTaskId = taskId,
-            reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
-        )
+        val taskIdToMinimize =
+            bringDesktopAppsToFrontBeforeShowingNewTask(DEFAULT_DISPLAY, wct, taskId)
+        val exitResult =
+            desktopImmersiveController.exitImmersiveIfApplicable(
+                wct = wct,
+                displayId = DEFAULT_DISPLAY,
+                excludeTaskId = taskId,
+                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
+            )
         wct.startTask(
             taskId,
-            ActivityOptions.makeBasic().apply {
-                launchWindowingMode = WINDOWING_MODE_FREEFORM
-            }.toBundle(),
+            ActivityOptions.makeBasic()
+                .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
+                .toBundle(),
         )
         // TODO(343149901): Add DPI changes for task launch
         val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
-        desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(FREEFORM_ANIMATION_DURATION)
+        desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
+            FREEFORM_ANIMATION_DURATION
+        )
         taskIdToMinimize?.let { addPendingMinimizeTransition(transition, it) }
         exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
         return true
     }
 
-   /** Moves a running task to desktop. */
+    /** Moves a running task to desktop. */
     fun moveRunningTaskToDesktop(
         task: RunningTaskInfo,
         wct: WindowContainerTransaction = WindowContainerTransaction(),
         transitionSource: DesktopModeTransitionSource,
     ) {
-        if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue()
-            && isTopActivityExemptFromDesktopWindowing(context, task)) {
+        if (
+            DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue() &&
+                isTopActivityExemptFromDesktopWindowing(context, task)
+        ) {
             logW("Cannot enter desktop for taskId %d, ineligible top activity found", task.taskId)
             return
         }
         logV("moveRunningTaskToDesktop taskId=%d", task.taskId)
         exitSplitIfApplicable(wct, task)
-        val exitResult = desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            displayId = task.displayId,
-            excludeTaskId = task.taskId,
-            reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
-        )
+        val exitResult =
+            desktopImmersiveController.exitImmersiveIfApplicable(
+                wct = wct,
+                displayId = task.displayId,
+                excludeTaskId = task.taskId,
+                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
+            )
         // Bring other apps to front first
         val taskIdToMinimize =
             bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
         addMoveToDesktopChanges(wct, task)
 
         val transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
-        desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(FREEFORM_ANIMATION_DURATION)
+        desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
+            FREEFORM_ANIMATION_DURATION
+        )
         taskIdToMinimize?.let { addPendingMinimizeTransition(transition, it) }
         exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
     }
@@ -451,11 +465,15 @@
         taskSurface: SurfaceControl,
     ) {
         logV("startDragToDesktop taskId=%d", taskInfo.taskId)
-        interactionJankMonitor.begin(taskSurface, context, handler,
-            CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD)
+        interactionJankMonitor.begin(
+            taskSurface,
+            context,
+            handler,
+            CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD,
+        )
         dragToDesktopTransitionHandler.startDragToDesktopTransition(
             taskInfo.taskId,
-            dragToDesktopValueAnimator
+            dragToDesktopValueAnimator,
         )
     }
 
@@ -467,7 +485,7 @@
         ProtoLog.v(
             WM_SHELL_DESKTOP_MODE,
             "DesktopTasksController: finalizeDragToDesktop taskId=%d",
-            taskInfo.taskId
+            taskInfo.taskId,
         )
         val wct = WindowContainerTransaction()
         exitSplitIfApplicable(wct, taskInfo)
@@ -475,12 +493,13 @@
         val taskIdToMinimize =
             bringDesktopAppsToFrontBeforeShowingNewTask(taskInfo.displayId, wct, taskInfo.taskId)
         addMoveToDesktopChanges(wct, taskInfo)
-        val exitResult = desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            displayId = taskInfo.displayId,
-            excludeTaskId = null,
-            reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH
-        )
+        val exitResult =
+            desktopImmersiveController.exitImmersiveIfApplicable(
+                wct = wct,
+                displayId = taskInfo.displayId,
+                excludeTaskId = null,
+                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
+            )
         val transition = dragToDesktopTransitionHandler.finishDragToDesktopTransition(wct)
         desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
             DRAG_TO_DESKTOP_FINISH_ANIM_DURATION_MS.toInt()
@@ -523,16 +542,16 @@
         performDesktopExitCleanupIfNeeded(taskId, wct)
         taskRepository.addClosingTask(displayId, taskId)
         taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
-            doesAnyTaskRequireTaskbarRounding(
-                displayId,
-                taskId
-            )
+            doesAnyTaskRequireTaskbarRounding(displayId, taskId)
         )
-        return desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            taskInfo = taskInfo,
-            reason = DesktopImmersiveController.ExitReason.CLOSED
-        ).asExit()?.runOnTransitionStart
+        return desktopImmersiveController
+            .exitImmersiveIfApplicable(
+                wct = wct,
+                taskInfo = taskInfo,
+                reason = DesktopImmersiveController.ExitReason.CLOSED,
+            )
+            .asExit()
+            ?.runOnTransitionStart
     }
 
     fun minimizeTask(taskInfo: RunningTaskInfo) {
@@ -541,11 +560,12 @@
         val wct = WindowContainerTransaction()
         performDesktopExitCleanupIfNeeded(taskId, wct)
         // Notify immersive handler as it might need to exit immersive state.
-        val exitResult = desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            taskInfo = taskInfo,
-            reason = DesktopImmersiveController.ExitReason.MINIMIZED
-        )
+        val exitResult =
+            desktopImmersiveController.exitImmersiveIfApplicable(
+                wct = wct,
+                taskInfo = taskInfo,
+                reason = DesktopImmersiveController.ExitReason.MINIMIZED,
+            )
 
         wct.reorder(taskInfo.token, false)
         val transition = freeformTaskTransitionStarter.startMinimizedModeTransition(wct)
@@ -553,7 +573,7 @@
             it.addPendingMinimizeChange(
                 transition = transition,
                 displayId = displayId,
-                taskId = taskId
+                taskId = taskId,
             )
         }
         exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
@@ -580,7 +600,7 @@
             splitScreenController.prepareExitSplitScreen(
                 wct,
                 splitScreenController.getStageOfTask(taskInfo.taskId),
-                EXIT_REASON_DESKTOP_MODE
+                EXIT_REASON_DESKTOP_MODE,
             )
             splitScreenController.transitionHandler?.onSplitToDesktop()
         }
@@ -600,22 +620,24 @@
     private fun moveToFullscreenWithAnimation(
         task: RunningTaskInfo,
         position: Point,
-        transitionSource: DesktopModeTransitionSource
+        transitionSource: DesktopModeTransitionSource,
     ) {
         logV("moveToFullscreenWithAnimation taskId=%d", task.taskId)
         val wct = WindowContainerTransaction()
         addMoveToFullscreenChanges(wct, task)
 
         exitDesktopTaskTransitionHandler.startTransition(
-                transitionSource,
-                wct,
-                position,
-                mOnAnimationFinishedCallback
-            )
+            transitionSource,
+            wct,
+            position,
+            mOnAnimationFinishedCallback,
+        )
 
         // handles case where we are moving to full screen without closing all DW tasks.
         if (!taskRepository.isOnlyVisibleNonClosingTask(task.taskId)) {
-            desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
+            desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
+                FULLSCREEN_ANIMATION_DURATION
+            )
         }
     }
 
@@ -645,16 +667,11 @@
         val wct = WindowContainerTransaction()
         wct.startTask(
             taskId,
-            ActivityOptions.makeBasic().apply {
-                launchWindowingMode = WINDOWING_MODE_FREEFORM
-            }.toBundle(),
+            ActivityOptions.makeBasic()
+                .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
+                .toBundle(),
         )
-        startLaunchTransition(
-            TRANSIT_OPEN,
-            wct,
-            taskId,
-            remoteTransition = remoteTransition
-        )
+        startLaunchTransition(TRANSIT_OPEN, wct, taskId, remoteTransition = remoteTransition)
     }
 
     /**
@@ -689,29 +706,32 @@
         remoteTransition: RemoteTransition? = null,
         displayId: Int = DEFAULT_DISPLAY,
     ): IBinder {
-        val taskIdToMinimize = if (launchingTaskId != null) {
-            addAndGetMinimizeChanges(displayId, wct, newTaskId = launchingTaskId)
-        } else {
-            logW("Starting desktop task launch without checking the task-limit")
-            // TODO(b/378920066): This currently does not respect the desktop window limit.
-            //  It's possible that |launchingTaskId| is null when launching using an intent, and
-            //  the task-limit should be respected then too.
-            null
-        }
-        val exitImmersiveResult = desktopImmersiveController.exitImmersiveIfApplicable(
-            wct = wct,
-            displayId = displayId,
-            excludeTaskId = launchingTaskId,
-            reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
-        )
-        if (remoteTransition == null) {
-            val t = desktopMixedTransitionHandler.startLaunchTransition(
-                transitionType = transitionType,
+        val taskIdToMinimize =
+            if (launchingTaskId != null) {
+                addAndGetMinimizeChanges(displayId, wct, newTaskId = launchingTaskId)
+            } else {
+                logW("Starting desktop task launch without checking the task-limit")
+                // TODO(b/378920066): This currently does not respect the desktop window limit.
+                //  It's possible that |launchingTaskId| is null when launching using an intent, and
+                //  the task-limit should be respected then too.
+                null
+            }
+        val exitImmersiveResult =
+            desktopImmersiveController.exitImmersiveIfApplicable(
                 wct = wct,
-                taskId = launchingTaskId,
-                minimizingTaskId = taskIdToMinimize,
-                exitingImmersiveTask = exitImmersiveResult.asExit()?.exitingTask,
+                displayId = displayId,
+                excludeTaskId = launchingTaskId,
+                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
             )
+        if (remoteTransition == null) {
+            val t =
+                desktopMixedTransitionHandler.startLaunchTransition(
+                    transitionType = transitionType,
+                    wct = wct,
+                    taskId = launchingTaskId,
+                    minimizingTaskId = taskIdToMinimize,
+                    exitingImmersiveTask = exitImmersiveResult.asExit()?.exitingTask,
+                )
             taskIdToMinimize?.let { addPendingMinimizeTransition(t, it) }
             exitImmersiveResult.asExit()?.runOnTransitionStart?.invoke(t)
             return t
@@ -725,7 +745,11 @@
         }
         val remoteTransitionHandler =
             DesktopWindowLimitRemoteHandler(
-                mainExecutor, rootTaskDisplayAreaOrganizer, remoteTransition, taskIdToMinimize)
+                mainExecutor,
+                rootTaskDisplayAreaOrganizer,
+                remoteTransition,
+                taskIdToMinimize,
+            )
         val t = transitions.startTransition(transitionType, wct, remoteTransitionHandler)
         remoteTransitionHandler.setTransition(t)
         taskIdToMinimize.let { addPendingMinimizeTransition(t, it) }
@@ -796,10 +820,7 @@
      * bounds) and a free floating state (either the last saved bounds if available or the default
      * bounds otherwise).
      */
-    fun toggleDesktopTaskSize(
-        taskInfo: RunningTaskInfo,
-        interaction: ToggleTaskSizeInteraction
-    ) {
+    fun toggleDesktopTaskSize(taskInfo: RunningTaskInfo, interaction: ToggleTaskSizeInteraction) {
         val currentTaskBounds = taskInfo.configuration.windowConfiguration.bounds
         desktopModeEventLogger.logTaskResizingStarted(
             interaction.resizeTrigger,
@@ -807,7 +828,7 @@
             taskInfo,
             currentTaskBounds.width(),
             currentTaskBounds.height(),
-            displayController
+            displayController,
         )
         val displayLayout = displayController.getDisplayLayout(taskInfo.displayId) ?: return
         val destinationBounds = Rect()
@@ -839,21 +860,20 @@
             destinationBounds.set(calculateMaximizeBounds(displayLayout, taskInfo))
         }
 
-
         val shouldRestoreToSnap =
             isMaximized && isTaskSnappedToHalfScreen(taskInfo, destinationBounds)
 
         logD("willMaximize = %s", willMaximize)
         logD("shouldRestoreToSnap = %s", shouldRestoreToSnap)
 
-        val doesAnyTaskRequireTaskbarRounding = willMaximize || shouldRestoreToSnap ||
+        val doesAnyTaskRequireTaskbarRounding =
+            willMaximize ||
+                shouldRestoreToSnap ||
                 doesAnyTaskRequireTaskbarRounding(taskInfo.displayId, taskInfo.taskId)
 
         taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(doesAnyTaskRequireTaskbarRounding)
         val wct = WindowContainerTransaction().setBounds(taskInfo.token, destinationBounds)
-        interaction.uiEvent?.let { uiEvent ->
-            desktopModeUiEventLogger.log(taskInfo, uiEvent)
-        }
+        interaction.uiEvent?.let { uiEvent -> desktopModeUiEventLogger.log(taskInfo, uiEvent) }
         desktopModeEventLogger.logTaskResizingEnded(
             interaction.resizeTrigger,
             interaction.inputMethod,
@@ -869,7 +889,7 @@
         taskInfo: RunningTaskInfo,
         taskSurface: SurfaceControl,
         currentDragBounds: Rect,
-        motionEvent: MotionEvent
+        motionEvent: MotionEvent,
     ) {
         if (isTaskMaximized(taskInfo, displayController)) {
             // Handle the case where we attempt to drag-to-maximize when already maximized: the task
@@ -893,7 +913,7 @@
                 direction = ToggleTaskSizeInteraction.Direction.MAXIMIZE,
                 source = ToggleTaskSizeInteraction.Source.HEADER_DRAG_TO_TOP,
                 inputMethod = DesktopModeEventLogger.getInputMethodFromMotionEvent(motionEvent),
-            )
+            ),
         )
     }
 
@@ -904,16 +924,19 @@
         } else {
             // if non-resizable then calculate max bounds according to aspect ratio
             val activityAspectRatio = calculateAspectRatio(taskInfo)
-            val newSize = maximizeSizeGivenAspectRatio(taskInfo,
-                Size(stableBounds.width(), stableBounds.height()), activityAspectRatio)
-            return centerInArea(
-                newSize, stableBounds, stableBounds.left, stableBounds.top)
+            val newSize =
+                maximizeSizeGivenAspectRatio(
+                    taskInfo,
+                    Size(stableBounds.width(), stableBounds.height()),
+                    activityAspectRatio,
+                )
+            return centerInArea(newSize, stableBounds, stableBounds.left, stableBounds.top)
         }
     }
 
     private fun isMaximizedToStableBoundsEdges(
         taskInfo: RunningTaskInfo,
-        stableBounds: Rect
+        stableBounds: Rect,
     ): Boolean {
         val currentTaskBounds = taskInfo.configuration.windowConfiguration.bounds
         return isTaskBoundsEqual(currentTaskBounds, stableBounds)
@@ -922,18 +945,16 @@
     /** Returns if current task bound is snapped to half screen */
     private fun isTaskSnappedToHalfScreen(
         taskInfo: RunningTaskInfo,
-        taskBounds: Rect = taskInfo.configuration.windowConfiguration.bounds
+        taskBounds: Rect = taskInfo.configuration.windowConfiguration.bounds,
     ): Boolean =
         getSnapBounds(taskInfo, SnapPosition.LEFT) == taskBounds ||
-                getSnapBounds(taskInfo, SnapPosition.RIGHT) == taskBounds
+            getSnapBounds(taskInfo, SnapPosition.RIGHT) == taskBounds
 
     @VisibleForTesting
-    fun doesAnyTaskRequireTaskbarRounding(
-        displayId: Int,
-        excludeTaskId: Int? = null,
-    ): Boolean {
+    fun doesAnyTaskRequireTaskbarRounding(displayId: Int, excludeTaskId: Int? = null): Boolean {
         val doesAnyTaskRequireTaskbarRounding =
-            taskRepository.getExpandedTasksOrdered(displayId)
+            taskRepository
+                .getExpandedTasksOrdered(displayId)
                 // exclude current task since maximize/restore transition has not taken place yet.
                 .filterNot { taskId -> taskId == excludeTaskId }
                 .any { taskId ->
@@ -943,14 +964,14 @@
                     logD("taskInfo = %s", taskInfo)
                     logD(
                         "isTaskSnappedToHalfScreen(taskInfo) = %s",
-                        isTaskSnappedToHalfScreen(taskInfo)
+                        isTaskSnappedToHalfScreen(taskInfo),
                     )
                     logD(
                         "isMaximizedToStableBoundsEdges(taskInfo, stableBounds) = %s",
-                        isMaximizedToStableBoundsEdges(taskInfo, stableBounds)
+                        isMaximizedToStableBoundsEdges(taskInfo, stableBounds),
                     )
-                    isTaskSnappedToHalfScreen(taskInfo)
-                            || isMaximizedToStableBoundsEdges(taskInfo, stableBounds)
+                    isTaskSnappedToHalfScreen(taskInfo) ||
+                        isMaximizedToStableBoundsEdges(taskInfo, stableBounds)
                 }
 
         logD("doesAnyTaskRequireTaskbarRounding = %s", doesAnyTaskRequireTaskbarRounding)
@@ -963,7 +984,7 @@
      * @param taskInfo current task that is being snap-resized via dragging or maximize menu button
      * @param taskSurface the leash of the task being dragged
      * @param currentDragBounds current position of the task leash being dragged (or current task
-     *                          bounds if being snapped resize via maximize menu button)
+     *   bounds if being snapped resize via maximize menu button)
      * @param position the portion of the screen (RIGHT or LEFT) we want to snap the task to.
      */
     fun snapToHalfScreen(
@@ -981,7 +1002,7 @@
             taskInfo,
             currentDragBounds.width(),
             currentDragBounds.height(),
-            displayController
+            displayController,
         )
 
         val destinationBounds = getSnapBounds(taskInfo, position)
@@ -995,12 +1016,13 @@
         )
 
         if (DesktopModeFlags.ENABLE_TILE_RESIZING.isTrue()) {
-            val isTiled = desktopTilingDecorViewModel.snapToHalfScreen(
-                taskInfo,
-                desktopWindowDecoration,
-                position,
-                currentDragBounds,
-            )
+            val isTiled =
+                desktopTilingDecorViewModel.snapToHalfScreen(
+                    taskInfo,
+                    desktopWindowDecoration,
+                    position,
+                    currentDragBounds,
+                )
             if (isTiled) {
                 taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(true)
             }
@@ -1041,10 +1063,11 @@
     ) {
         if (!isSnapResizingAllowed(taskInfo)) {
             Toast.makeText(
-                getContext(),
-                R.string.desktop_mode_non_resizable_snap_text,
-                Toast.LENGTH_SHORT
-            ).show()
+                    getContext(),
+                    R.string.desktop_mode_non_resizable_snap_text,
+                    Toast.LENGTH_SHORT,
+                )
+                .show()
             return
         }
 
@@ -1055,11 +1078,10 @@
             position,
             resizeTrigger,
             inputMethod,
-            desktopModeWindowDecoration
+            desktopModeWindowDecoration,
         )
     }
 
-
     @VisibleForTesting
     fun handleSnapResizingTaskOnDrag(
         taskInfo: RunningTaskInfo,
@@ -1073,7 +1095,11 @@
         releaseVisualIndicator()
         if (!isSnapResizingAllowed(taskInfo)) {
             interactionJankMonitor.begin(
-                taskSurface, context, handler, CUJ_DESKTOP_MODE_SNAP_RESIZE, "drag_non_resizable"
+                taskSurface,
+                context,
+                handler,
+                CUJ_DESKTOP_MODE_SNAP_RESIZE,
+                "drag_non_resizable",
             )
 
             // reposition non-resizable app back to its original position before being dragged
@@ -1084,20 +1110,26 @@
                 endBounds = dragStartBounds,
                 doOnEnd = {
                     Toast.makeText(
-                        context,
-                        com.android.wm.shell.R.string.desktop_mode_non_resizable_snap_text,
-                        Toast.LENGTH_SHORT
-                    ).show()
+                            context,
+                            com.android.wm.shell.R.string.desktop_mode_non_resizable_snap_text,
+                            Toast.LENGTH_SHORT,
+                        )
+                        .show()
                 },
             )
         } else {
-            val resizeTrigger = if (position == SnapPosition.LEFT) {
-                ResizeTrigger.DRAG_LEFT
-            } else {
-                ResizeTrigger.DRAG_RIGHT
-            }
+            val resizeTrigger =
+                if (position == SnapPosition.LEFT) {
+                    ResizeTrigger.DRAG_LEFT
+                } else {
+                    ResizeTrigger.DRAG_RIGHT
+                }
             interactionJankMonitor.begin(
-                taskSurface, context, handler, CUJ_DESKTOP_MODE_SNAP_RESIZE, "drag_resizable"
+                taskSurface,
+                context,
+                handler,
+                CUJ_DESKTOP_MODE_SNAP_RESIZE,
+                "drag_resizable",
             )
             snapToHalfScreen(
                 taskInfo,
@@ -1127,7 +1159,7 @@
                     stableBounds.left,
                     stableBounds.top,
                     stableBounds.left + destinationWidth,
-                    stableBounds.bottom
+                    stableBounds.bottom,
                 )
             }
             SnapPosition.RIGHT -> {
@@ -1135,7 +1167,7 @@
                     stableBounds.right - destinationWidth,
                     stableBounds.top,
                     stableBounds.right,
-                    stableBounds.bottom
+                    stableBounds.bottom,
                 )
             }
         }
@@ -1155,36 +1187,32 @@
     private fun bringDesktopAppsToFrontBeforeShowingNewTask(
         displayId: Int,
         wct: WindowContainerTransaction,
-        newTaskIdInFront: Int
+        newTaskIdInFront: Int,
     ): Int? = bringDesktopAppsToFront(displayId, wct, newTaskIdInFront)
 
     private fun bringDesktopAppsToFront(
         displayId: Int,
         wct: WindowContainerTransaction,
-        newTaskIdInFront: Int? = null
+        newTaskIdInFront: Int? = null,
     ): Int? {
         logV("bringDesktopAppsToFront, newTaskId=%d", newTaskIdInFront)
         // Move home to front, ensures that we go back home when all desktop windows are closed
         moveHomeTask(wct, toTop = true)
 
         // Currently, we only handle the desktop on the default display really.
-        if (displayId == DEFAULT_DISPLAY
-            && ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY.isTrue()) {
+        if (displayId == DEFAULT_DISPLAY && ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY.isTrue()) {
             // Add translucent wallpaper activity to show the wallpaper underneath
             addWallpaperActivity(wct)
         }
 
-        val expandedTasksOrderedFrontToBack =
-            taskRepository.getExpandedTasksOrdered(displayId)
+        val expandedTasksOrderedFrontToBack = taskRepository.getExpandedTasksOrdered(displayId)
         // If we're adding a new Task we might need to minimize an old one
         // TODO(b/365725441): Handle non running task minimization
         val taskIdToMinimize: Int? =
             if (newTaskIdInFront != null && desktopTasksLimiter.isPresent) {
-                desktopTasksLimiter.get()
-                    .getTaskIdToMinimize(
-                        expandedTasksOrderedFrontToBack,
-                        newTaskIdInFront
-                    )
+                desktopTasksLimiter
+                    .get()
+                    .getTaskIdToMinimize(expandedTasksOrderedFrontToBack, newTaskIdInFront)
             } else {
                 null
             }
@@ -1202,15 +1230,16 @@
                     // Task is not running, start it
                     wct.startTask(
                         taskId,
-                        ActivityOptions.makeBasic().apply {
-                            launchWindowingMode = WINDOWING_MODE_FREEFORM
-                        }.toBundle(),
+                        ActivityOptions.makeBasic()
+                            .apply { launchWindowingMode = WINDOWING_MODE_FREEFORM }
+                            .toBundle(),
                     )
                 }
             }
 
-        taskbarDesktopTaskListener?.
-            onTaskbarCornerRoundingUpdate(doesAnyTaskRequireTaskbarRounding(displayId))
+        taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
+            doesAnyTaskRequireTaskbarRounding(displayId)
+        )
 
         return taskIdToMinimize
     }
@@ -1225,8 +1254,7 @@
     private fun addWallpaperActivity(wct: WindowContainerTransaction) {
         logV("addWallpaperActivity")
         val userHandle = UserHandle.of(userId)
-        val userContext =
-            context.createContextAsUser(userHandle, /* flags= */ 0)
+        val userContext = context.createContextAsUser(userHandle, /* flags= */ 0)
         val intent = Intent(userContext, DesktopWallpaperActivity::class.java)
         intent.putExtra(Intent.EXTRA_USER_HANDLE, userId)
         val options =
@@ -1242,7 +1270,7 @@
                 intent,
                 PendingIntent.FLAG_IMMUTABLE,
                 /* options= */ null,
-                userHandle
+                userHandle,
             )
         wct.sendPendingIntent(pendingIntent, intent, options.toBundle())
     }
@@ -1262,13 +1290,14 @@
         if (!taskRepository.isOnlyVisibleNonClosingTask(taskId)) {
             return
         }
-        desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(FULLSCREEN_ANIMATION_DURATION)
+        desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
+            FULLSCREEN_ANIMATION_DURATION
+        )
         if (taskRepository.wallpaperActivityToken != null) {
             removeWallpaperActivity(wct)
         }
     }
 
-
     fun releaseVisualIndicator() {
         val t = SurfaceControl.Transaction()
         visualIndicator?.releaseVisualIndicator(t)
@@ -1292,7 +1321,7 @@
         info: TransitionInfo,
         startTransaction: SurfaceControl.Transaction,
         finishTransaction: SurfaceControl.Transaction,
-        finishCallback: Transitions.TransitionFinishCallback
+        finishCallback: Transitions.TransitionFinishCallback,
     ): Boolean {
         // This handler should never be the sole handler, so should not animate anything.
         return false
@@ -1300,7 +1329,7 @@
 
     override fun handleRequest(
         transition: IBinder,
-        request: TransitionRequestInfo
+        request: TransitionRequestInfo,
     ): WindowContainerTransaction? {
         logV("handleRequest request=%s", request)
         // Check if we should skip handling this transition
@@ -1363,11 +1392,8 @@
                     // Check if freeform task launch during recents should be handled
                     shouldHandleMidRecentsFreeformLaunch -> handleMidRecentsFreeformTaskLaunch(task)
                     // Check if the closing task needs to be handled
-                    TransitionUtil.isClosingType(request.type) -> handleTaskClosing(
-                        task,
-                        transition,
-                        request.type
-                    )
+                    TransitionUtil.isClosingType(request.type) ->
+                        handleTaskClosing(task, transition, request.type)
                     // Check if the top task shouldn't be allowed to enter desktop mode
                     isIncompatibleTask(task) -> handleIncompatibleTaskLaunch(task)
                     // Check if fullscreen task should be updated
@@ -1384,19 +1410,16 @@
     }
 
     /** Whether the given [change] in the [transition] is a known desktop change. */
-    fun isDesktopChange(
-        transition: IBinder,
-        change: TransitionInfo.Change,
-    ): Boolean {
+    fun isDesktopChange(transition: IBinder, change: TransitionInfo.Change): Boolean {
         // Only the immersive controller is currently involved in mixed transitions.
-        return Flags.enableFullyImmersiveInDesktop()
-                && desktopImmersiveController.isImmersiveChange(transition, change)
+        return Flags.enableFullyImmersiveInDesktop() &&
+            desktopImmersiveController.isImmersiveChange(transition, change)
     }
 
     /**
-     * Whether the given transition [info] will potentially include a desktop change, in which
-     * case the transition should be treated as mixed so that the change is in part animated by
-     * one of the desktop transition handlers.
+     * Whether the given transition [info] will potentially include a desktop change, in which case
+     * the transition should be treated as mixed so that the change is in part animated by one of
+     * the desktop transition handlers.
      */
     fun shouldPlayDesktopAnimation(info: TransitionRequestInfo): Boolean {
         // Only immersive mixed transition are currently supported.
@@ -1440,7 +1463,7 @@
             change,
             startTransaction,
             finishTransaction,
-            finishCallback
+            finishCallback,
         )
     }
 
@@ -1465,13 +1488,14 @@
 
     /** Returns whether an existing desktop task is being relaunched in freeform or not. */
     private fun isFreeformRelaunch(triggerTask: RunningTaskInfo?, request: TransitionRequestInfo) =
-        (triggerTask != null && triggerTask.windowingMode == WINDOWING_MODE_FREEFORM
-                && TransitionUtil.isOpeningType(request.type)
-                && taskRepository.isActiveTask(triggerTask.taskId))
+        (triggerTask != null &&
+            triggerTask.windowingMode == WINDOWING_MODE_FREEFORM &&
+            TransitionUtil.isOpeningType(request.type) &&
+            taskRepository.isActiveTask(triggerTask.taskId))
 
     private fun isIncompatibleTask(task: TaskInfo) =
-        DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue()
-                && isTopActivityExemptFromDesktopWindowing(context, task)
+        DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue() &&
+            isTopActivityExemptFromDesktopWindowing(context, task)
 
     private fun shouldHandleTaskClosing(request: TransitionRequestInfo): Boolean {
         return ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY.isTrue() &&
@@ -1480,18 +1504,19 @@
     }
 
     /** Open an existing instance of an app. */
-    fun openInstance(
-        callingTask: RunningTaskInfo,
-        requestedTaskId: Int
-    ) {
+    fun openInstance(callingTask: RunningTaskInfo, requestedTaskId: Int) {
         val wct = WindowContainerTransaction()
         val options = createNewWindowOptions(callingTask)
         if (options.launchWindowingMode == WINDOWING_MODE_FREEFORM) {
             wct.startTask(requestedTaskId, options.toBundle())
-            val taskIdToMinimize = bringDesktopAppsToFrontBeforeShowingNewTask(
-                callingTask.displayId, wct, requestedTaskId)
-            val exitResult = desktopImmersiveController
-                .exitImmersiveIfApplicable(
+            val taskIdToMinimize =
+                bringDesktopAppsToFrontBeforeShowingNewTask(
+                    callingTask.displayId,
+                    wct,
+                    requestedTaskId,
+                )
+            val exitResult =
+                desktopImmersiveController.exitImmersiveIfApplicable(
                     wct = wct,
                     displayId = callingTask.displayId,
                     excludeTaskId = requestedTaskId,
@@ -1503,44 +1528,51 @@
             exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
         } else {
             val splitPosition = splitScreenController.determineNewInstancePosition(callingTask)
-            splitScreenController.startTask(requestedTaskId, splitPosition,
-                options.toBundle(), null /* hideTaskToken */)
+            splitScreenController.startTask(
+                requestedTaskId,
+                splitPosition,
+                options.toBundle(),
+                null, /* hideTaskToken */
+            )
         }
     }
 
     /** Create an Intent to open a new window of a task. */
-    fun openNewWindow(
-        callingTaskInfo: RunningTaskInfo
-    ) {
+    fun openNewWindow(callingTaskInfo: RunningTaskInfo) {
         // TODO(b/337915660): Add a transition handler for these; animations
         //  need updates in some cases.
         val baseActivity = callingTaskInfo.baseActivity ?: return
-        val fillIn: Intent = context.packageManager
-            .getLaunchIntentForPackage(
-                baseActivity.packageName
-            ) ?: return
-        fillIn
-            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
-        val launchIntent = PendingIntent.getActivity(
-            context,
-            /* requestCode= */ 0,
-            fillIn,
-            PendingIntent.FLAG_IMMUTABLE
-        )
+        val fillIn: Intent =
+            context.packageManager.getLaunchIntentForPackage(baseActivity.packageName) ?: return
+        fillIn.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
+        val launchIntent =
+            PendingIntent.getActivity(
+                context,
+                /* requestCode= */ 0,
+                fillIn,
+                PendingIntent.FLAG_IMMUTABLE,
+            )
         val options = createNewWindowOptions(callingTaskInfo)
         when (options.launchWindowingMode) {
             WINDOWING_MODE_MULTI_WINDOW -> {
-                val splitPosition = splitScreenController
-                    .determineNewInstancePosition(callingTaskInfo)
+                val splitPosition =
+                    splitScreenController.determineNewInstancePosition(callingTaskInfo)
                 // TODO(b/349828130) currently pass in index_undefined until we can revisit these
                 //  specific cases in the future.
-                val splitIndex = if (enableFlexibleSplit())
-                    splitScreenController.determineNewInstanceIndex(callingTaskInfo) else
-                    SPLIT_INDEX_UNDEFINED
+                val splitIndex =
+                    if (enableFlexibleSplit())
+                        splitScreenController.determineNewInstanceIndex(callingTaskInfo)
+                    else SPLIT_INDEX_UNDEFINED
                 splitScreenController.startIntent(
-                    launchIntent, context.userId, fillIn, splitPosition,
-                    options.toBundle(), null /* hideTaskToken */,
-                    true /* forceLaunchNewTask */, splitIndex)
+                    launchIntent,
+                    context.userId,
+                    fillIn,
+                    splitPosition,
+                    options.toBundle(),
+                    null /* hideTaskToken */,
+                    true /* forceLaunchNewTask */,
+                    splitIndex,
+                )
             }
             WINDOWING_MODE_FREEFORM -> {
                 val wct = WindowContainerTransaction()
@@ -1549,36 +1581,39 @@
                     transitionType = TRANSIT_OPEN,
                     wct = wct,
                     launchingTaskId = null,
-                    displayId = callingTaskInfo.displayId
+                    displayId = callingTaskInfo.displayId,
                 )
             }
         }
     }
 
     private fun createNewWindowOptions(callingTask: RunningTaskInfo): ActivityOptions {
-        val newTaskWindowingMode = when {
-            callingTask.isFreeform -> {
-                WINDOWING_MODE_FREEFORM
+        val newTaskWindowingMode =
+            when {
+                callingTask.isFreeform -> {
+                    WINDOWING_MODE_FREEFORM
+                }
+                callingTask.isFullscreen || callingTask.isMultiWindow -> {
+                    WINDOWING_MODE_MULTI_WINDOW
+                }
+                else -> {
+                    error("Invalid windowing mode: ${callingTask.windowingMode}")
+                }
             }
-            callingTask.isFullscreen || callingTask.isMultiWindow -> {
-                WINDOWING_MODE_MULTI_WINDOW
+        val bounds =
+            when (newTaskWindowingMode) {
+                WINDOWING_MODE_FREEFORM -> {
+                    displayController.getDisplayLayout(callingTask.displayId)?.let {
+                        getInitialBounds(it, callingTask, callingTask.displayId)
+                    }
+                }
+                WINDOWING_MODE_MULTI_WINDOW -> {
+                    Rect()
+                }
+                else -> {
+                    error("Invalid windowing mode: $newTaskWindowingMode")
+                }
             }
-            else -> {
-                error("Invalid windowing mode: ${callingTask.windowingMode}")
-            }
-        }
-        val bounds = when (newTaskWindowingMode) {
-            WINDOWING_MODE_FREEFORM -> {
-                displayController.getDisplayLayout(callingTask.displayId)
-                    ?.let { getInitialBounds(it, callingTask, callingTask.displayId) }
-            }
-            WINDOWING_MODE_MULTI_WINDOW -> {
-                Rect()
-            }
-            else -> {
-                error("Invalid windowing mode: $newTaskWindowingMode")
-            }
-        }
         return ActivityOptions.makeBasic().apply {
             launchWindowingMode = newTaskWindowingMode
             pendingIntentBackgroundActivityStartMode =
@@ -1604,7 +1639,7 @@
 
     private fun handleFreeformTaskLaunch(
         task: RunningTaskInfo,
-        transition: IBinder
+        transition: IBinder,
     ): WindowContainerTransaction? {
         logV("handleFreeformTaskLaunch")
         if (keyguardManager.isKeyguardLocked) {
@@ -1631,8 +1666,10 @@
         // TODO(b/365723620): Handle non running tasks that were launched after reboot.
         // If task is already visible, it must have been handled already and added to desktop mode.
         // Cascade task only if it's not visible yet.
-        if (DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue()
-                && !taskRepository.isVisibleTask(task.taskId)) {
+        if (
+            DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue() &&
+                !taskRepository.isVisibleTask(task.taskId)
+        ) {
             val displayLayout = displayController.getDisplayLayout(task.displayId)
             if (displayLayout != null) {
                 val initialBounds = Rect(task.configuration.windowConfiguration.bounds)
@@ -1667,7 +1704,7 @@
 
     private fun handleFullscreenTaskLaunch(
         task: RunningTaskInfo,
-        transition: IBinder
+        transition: IBinder,
     ): WindowContainerTransaction? {
         logV("handleFullscreenTaskLaunch")
         if (shouldFullscreenTaskLaunchSwitchToDesktop(task)) {
@@ -1678,8 +1715,10 @@
                 // that's not the case for launches in desktop. Also, if this launch is the first
                 // one to trigger the desktop mode (e.g., when [forceEnterDesktop()]), activate the
                 // desktop mode here.
-                if (task.baseIntent.flags.and(Intent.FLAG_ACTIVITY_TASK_ON_HOME) != 0
-                    || !isDesktopModeShowing(task.displayId)) {
+                if (
+                    task.baseIntent.flags.and(Intent.FLAG_ACTIVITY_TASK_ON_HOME) != 0 ||
+                        !isDesktopModeShowing(task.displayId)
+                ) {
                     bringDesktopAppsToFrontBeforeShowingNewTask(task.displayId, wct, task.taskId)
                     wct.reorder(task.token, true)
                 }
@@ -1693,7 +1732,7 @@
                     transition,
                     wct,
                     task.displayId,
-                    reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH
+                    reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
                 )
             }
         } else if (taskRepository.isActiveTask(task.taskId)) {
@@ -1724,7 +1763,11 @@
     }
 
     /** Handle task closing by removing wallpaper activity if it's the last active task */
-    private fun handleTaskClosing(task: RunningTaskInfo, transition: IBinder, requestType: Int): WindowContainerTransaction? {
+    private fun handleTaskClosing(
+        task: RunningTaskInfo,
+        transition: IBinder,
+        requestType: Int,
+    ): WindowContainerTransaction? {
         logV("handleTaskClosing")
         if (!isDesktopModeShowing(task.displayId)) return null
 
@@ -1739,24 +1782,23 @@
             // [DesktopTasksTransitionObserver].
             desktopMixedTransitionHandler.addPendingMixedTransition(
                 DesktopMixedTransitionHandler.PendingMixedTransition.Minimize(
-                    transition, task.taskId, taskRepository.getVisibleTaskCount(task.displayId) == 1
+                    transition,
+                    task.taskId,
+                    taskRepository.getVisibleTaskCount(task.displayId) == 1,
                 )
             )
         }
 
         taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
-            doesAnyTaskRequireTaskbarRounding(
-                task.displayId,
-                task.taskId
-            )
+            doesAnyTaskRequireTaskbarRounding(task.displayId, task.taskId)
         )
         return if (wct.isEmpty) null else wct
     }
 
     /**
      * Apply all changes required when task is first added to desktop. Uses the task's current
-     * display by default to apply initial bounds and placement relative to the display.
-     * Use a different [displayId] if the task should be moved to a different display.
+     * display by default to apply initial bounds and placement relative to the display. Use a
+     * different [displayId] if the task should be moved to a different display.
      */
     @VisibleForTesting
     fun addMoveToDesktopChanges(
@@ -1791,11 +1833,12 @@
         taskInfo: RunningTaskInfo,
         displayId: Int,
     ): Rect {
-        val bounds = if (ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue) {
-            calculateInitialBounds(displayLayout, taskInfo)
-        } else {
-            calculateDefaultDesktopTaskBounds(displayLayout)
-        }
+        val bounds =
+            if (ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue) {
+                calculateInitialBounds(displayLayout, taskInfo)
+            } else {
+                calculateDefaultDesktopTaskBounds(displayLayout)
+            }
 
         if (DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue) {
             cascadeWindow(bounds, displayLayout, displayId)
@@ -1805,7 +1848,7 @@
 
     private fun addMoveToFullscreenChanges(
         wct: WindowContainerTransaction,
-        taskInfo: RunningTaskInfo
+        taskInfo: RunningTaskInfo,
     ) {
         val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(taskInfo.displayId)!!
         val tdaWindowingMode = tdaInfo.configuration.windowConfiguration.windowingMode
@@ -1832,8 +1875,12 @@
         val activeTasks = taskRepository.getExpandedTasksOrdered(displayId)
         activeTasks.firstOrNull()?.let { activeTask ->
             shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
-                cascadeWindow(context.resources, stableBounds,
-                    it.configuration.windowConfiguration.bounds, bounds)
+                cascadeWindow(
+                    context.resources,
+                    stableBounds,
+                    it.configuration.windowConfiguration.bounds,
+                    bounds,
+                )
             }
         }
     }
@@ -1859,24 +1906,19 @@
     private fun addAndGetMinimizeChanges(
         displayId: Int,
         wct: WindowContainerTransaction,
-        newTaskId: Int
+        newTaskId: Int,
     ): Int? {
         if (!desktopTasksLimiter.isPresent) return null
-        return desktopTasksLimiter
-            .get()
-            .addAndGetMinimizeTaskChanges(displayId, wct, newTaskId)
+        return desktopTasksLimiter.get().addAndGetMinimizeTaskChanges(displayId, wct, newTaskId)
     }
 
-    private fun addPendingMinimizeTransition(
-        transition: IBinder,
-        taskIdToMinimize: Int,
-    ) {
+    private fun addPendingMinimizeTransition(transition: IBinder, taskIdToMinimize: Int) {
         val taskToMinimize = shellTaskOrganizer.getRunningTaskInfo(taskIdToMinimize)
         desktopTasksLimiter.ifPresent {
             it.addPendingMinimizeChange(
                 transition = transition,
                 displayId = taskToMinimize?.displayId ?: DEFAULT_DISPLAY,
-                taskId = taskIdToMinimize
+                taskId = taskIdToMinimize,
             )
         }
     }
@@ -1892,7 +1934,12 @@
         // TODO b/359523924: pass immersive task here?
         desktopMixedTransitionHandler.addPendingMixedTransition(
             DesktopMixedTransitionHandler.PendingMixedTransition.Launch(
-                transition, launchTaskId, minimizeTaskId, /* exitingImmersiveTask= */ null))
+                transition,
+                launchTaskId,
+                minimizeTaskId,
+                /* exitingImmersiveTask= */ null,
+            )
+        )
     }
 
     fun removeDesktop(displayId: Int) {
@@ -1927,10 +1974,7 @@
      * changes if this transition is enabled.
      */
     @JvmOverloads
-    fun requestSplit(
-        taskInfo: RunningTaskInfo,
-        leftOrTop: Boolean = false
-    ) {
+    fun requestSplit(taskInfo: RunningTaskInfo, leftOrTop: Boolean = false) {
         // If a drag to desktop is in progress, we want to enter split select
         // even if the requesting task is already in split.
         val isDragging = dragToDesktopTransitionHandler.inProgress
@@ -1938,11 +1982,12 @@
         if (shouldRequestSplit) {
             if (isDragging) {
                 releaseVisualIndicator()
-                val cancelState = if (leftOrTop) {
-                    DragToDesktopTransitionHandler.CancelState.CANCEL_SPLIT_LEFT
-                } else {
-                    DragToDesktopTransitionHandler.CancelState.CANCEL_SPLIT_RIGHT
-                }
+                val cancelState =
+                    if (leftOrTop) {
+                        DragToDesktopTransitionHandler.CancelState.CANCEL_SPLIT_LEFT
+                    } else {
+                        DragToDesktopTransitionHandler.CancelState.CANCEL_SPLIT_RIGHT
+                    }
                 dragToDesktopTransitionHandler.cancelDragToDesktopTransition(cancelState)
             } else {
                 val wct = WindowContainerTransaction()
@@ -1951,7 +1996,7 @@
                     taskInfo,
                     wct,
                     if (leftOrTop) SPLIT_POSITION_TOP_OR_LEFT else SPLIT_POSITION_BOTTOM_OR_RIGHT,
-                    taskInfo.configuration.windowConfiguration.bounds
+                    taskInfo.configuration.windowConfiguration.bounds,
                 )
             }
         }
@@ -1986,12 +2031,17 @@
         taskInfo: RunningTaskInfo,
         taskSurface: SurfaceControl,
         inputX: Float,
-        taskBounds: Rect
+        taskBounds: Rect,
     ) {
         if (taskInfo.windowingMode != WINDOWING_MODE_FREEFORM) return
         desktopTilingDecorViewModel.removeTaskIfTiled(taskInfo.displayId, taskInfo.taskId)
-        updateVisualIndicator(taskInfo, taskSurface, inputX, taskBounds.top.toFloat(),
-            DragStartState.FROM_FREEFORM)
+        updateVisualIndicator(
+            taskInfo,
+            taskSurface,
+            inputX,
+            taskBounds.top.toFloat(),
+            DragStartState.FROM_FREEFORM,
+        )
     }
 
     fun updateVisualIndicator(
@@ -1999,7 +2049,7 @@
         taskSurface: SurfaceControl?,
         inputX: Float,
         taskTop: Float,
-        dragStartState: DragStartState
+        dragStartState: DragStartState,
     ): DesktopModeVisualIndicator.IndicatorType {
         // If the visual indicator does not exist, create it.
         val indicator =
@@ -2011,7 +2061,7 @@
                     context,
                     taskSurface,
                     rootTaskDisplayAreaOrganizer,
-                    dragStartState
+                    dragStartState,
                 )
         if (visualIndicator == null) visualIndicator = indicator
         return indicator.updateIndicatorType(PointF(inputX, taskTop))
@@ -2026,7 +2076,7 @@
      * @param position position of surface when drag ends.
      * @param inputCoordinate the coordinates of the motion event
      * @param currentDragBounds the current bounds of where the visible task is (might be actual
-     *                          task bounds or just task leash)
+     *   task bounds or just task leash)
      * @param validDragArea the bounds of where the task can be dragged within the display.
      * @param dragStartBounds the bounds of the task before starting dragging.
      */
@@ -2048,7 +2098,7 @@
         val indicator = getVisualIndicator() ?: return
         val indicatorType =
             indicator.updateIndicatorType(
-                PointF(inputCoordinate.x, currentDragBounds.top.toFloat()),
+                PointF(inputCoordinate.x, currentDragBounds.top.toFloat())
             )
         when (indicatorType) {
             IndicatorType.TO_FULLSCREEN_INDICATOR -> {
@@ -2057,19 +2107,19 @@
                 } else {
                     desktopModeUiEventLogger.log(
                         taskInfo,
-                        DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_FULL_SCREEN
+                        DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_FULL_SCREEN,
                     )
                     moveToFullscreenWithAnimation(
                         taskInfo,
                         position,
-                        DesktopModeTransitionSource.TASK_DRAG
+                        DesktopModeTransitionSource.TASK_DRAG,
                     )
                 }
             }
             IndicatorType.TO_SPLIT_LEFT_INDICATOR -> {
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_LEFT
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_LEFT,
                 )
                 handleSnapResizingTaskOnDrag(
                     taskInfo,
@@ -2084,7 +2134,7 @@
             IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_RIGHT
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_RIGHT,
                 )
                 handleSnapResizingTaskOnDrag(
                     taskInfo,
@@ -2103,7 +2153,7 @@
                 // If task bounds are outside valid drag area, snap them inward
                 DragPositioningCallbackUtility.snapTaskBoundsIfNecessary(
                     destinationBounds,
-                    validDragArea
+                    validDragArea,
                 )
 
                 if (destinationBounds == dragStartBounds) {
@@ -2135,8 +2185,9 @@
         }
         // A freeform drag-move ended, remove the indicator immediately.
         releaseVisualIndicator()
-        taskbarDesktopTaskListener
-            ?.onTaskbarCornerRoundingUpdate(doesAnyTaskRequireTaskbarRounding(taskInfo.displayId))
+        taskbarDesktopTaskListener?.onTaskbarCornerRoundingUpdate(
+            doesAnyTaskRequireTaskbarRounding(taskInfo.displayId)
+        )
     }
 
     /**
@@ -2144,9 +2195,7 @@
      *
      * @param taskInfo the task being dragged.
      */
-    fun onDragPositioningCancelThroughStatusBar(
-        taskInfo: RunningTaskInfo,
-    ) {
+    fun onDragPositioningCancelThroughStatusBar(taskInfo: RunningTaskInfo) {
         interactionJankMonitor.cancel(CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD)
         cancelDragToDesktop(taskInfo)
     }
@@ -2170,11 +2219,16 @@
         when (indicatorType) {
             IndicatorType.TO_DESKTOP_INDICATOR -> {
                 // Start a new jank interaction for the drag release to desktop window animation.
-                interactionJankMonitor.begin(taskSurface, context, handler,
-                    CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_RELEASE, "to_desktop")
+                interactionJankMonitor.begin(
+                    taskSurface,
+                    context,
+                    handler,
+                    CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_RELEASE,
+                    "to_desktop",
+                )
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_DESKTOP_MODE
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_DESKTOP_MODE,
                 )
                 finalizeDragToDesktop(taskInfo)
             }
@@ -2182,21 +2236,21 @@
             IndicatorType.TO_FULLSCREEN_INDICATOR -> {
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_FULL_SCREEN
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_FULL_SCREEN,
                 )
                 cancelDragToDesktop(taskInfo)
             }
             IndicatorType.TO_SPLIT_LEFT_INDICATOR -> {
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_SPLIT_SCREEN
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_SPLIT_SCREEN,
                 )
                 requestSplit(taskInfo, leftOrTop = true)
             }
             IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
                 desktopModeUiEventLogger.log(
                     taskInfo,
-                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_SPLIT_SCREEN
+                    DesktopUiEventEnum.DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_SPLIT_SCREEN,
                 )
                 requestSplit(taskInfo, leftOrTop = false)
             }
@@ -2238,7 +2292,7 @@
     override fun onUnhandledDrag(
         launchIntent: PendingIntent,
         dragEvent: DragEvent,
-        onFinishCallback: Consumer<Boolean>
+        onFinishCallback: Consumer<Boolean>,
     ): Boolean {
         // TODO(b/320797628): Pass through which display we are dropping onto
         if (!isDesktopModeShowing(DEFAULT_DISPLAY)) {
@@ -2257,22 +2311,27 @@
         //  window will accept a drag event. This way, we can hide the indicator when we won't
         //  be handling the transition here, allowing us to display the indicator accurately.
         //  For now, we create the indicator only on drag end and immediately dispose it.
-        val indicatorType = updateVisualIndicator(taskInfo, dragEvent.dragSurface,
-            dragEvent.x, dragEvent.y,
-            DragStartState.DRAGGED_INTENT)
+        val indicatorType =
+            updateVisualIndicator(
+                taskInfo,
+                dragEvent.dragSurface,
+                dragEvent.x,
+                dragEvent.y,
+                DragStartState.DRAGGED_INTENT,
+            )
         releaseVisualIndicator()
-        val windowingMode = when (indicatorType) {
-            IndicatorType.TO_FULLSCREEN_INDICATOR -> {
-                WINDOWING_MODE_FULLSCREEN
+        val windowingMode =
+            when (indicatorType) {
+                IndicatorType.TO_FULLSCREEN_INDICATOR -> {
+                    WINDOWING_MODE_FULLSCREEN
+                }
+                IndicatorType.TO_SPLIT_LEFT_INDICATOR,
+                IndicatorType.TO_SPLIT_RIGHT_INDICATOR,
+                IndicatorType.TO_DESKTOP_INDICATOR -> {
+                    WINDOWING_MODE_FREEFORM
+                }
+                else -> error("Invalid indicator type: $indicatorType")
             }
-            IndicatorType.TO_SPLIT_LEFT_INDICATOR,
-            IndicatorType.TO_SPLIT_RIGHT_INDICATOR,
-            IndicatorType.TO_DESKTOP_INDICATOR
-            -> {
-                WINDOWING_MODE_FREEFORM
-            }
-            else -> error("Invalid indicator type: $indicatorType")
-        }
         val displayLayout = displayController.getDisplayLayout(DEFAULT_DISPLAY) ?: return false
         val newWindowBounds = Rect()
         when (indicatorType) {
@@ -2281,7 +2340,7 @@
                 newWindowBounds.set(calculateDefaultDesktopTaskBounds(displayLayout))
                 newWindowBounds.offsetTo(
                     dragEvent.x.toInt() - (newWindowBounds.width() / 2),
-                    dragEvent.y.toInt()
+                    dragEvent.y.toInt(),
                 )
             }
             IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
@@ -2340,12 +2399,15 @@
         if (!Flags.enableFullyImmersiveInDesktop()) return
         val inImmersive = taskRepository.isTaskInFullImmersiveState(taskInfo.taskId)
         val requestingImmersive = taskInfo.requestingImmersive
-        if (inImmersive && !requestingImmersive
-            && !RecentsTransitionStateListener.isRunning(recentsTransitionState)) {
+        if (
+            inImmersive &&
+                !requestingImmersive &&
+                !RecentsTransitionStateListener.isRunning(recentsTransitionState)
+        ) {
             // Exit immersive if the app is no longer requesting it.
             desktopImmersiveController.moveTaskToNonImmersive(
                 taskInfo,
-                DesktopImmersiveController.ExitReason.APP_NOT_IMMERSIVE
+                DesktopImmersiveController.ExitReason.APP_NOT_IMMERSIVE,
             )
         }
     }
@@ -2363,7 +2425,7 @@
     private inner class DesktopModeImpl : DesktopMode {
         override fun addVisibleTasksListener(
             listener: VisibleTasksListener,
-            callbackExecutor: Executor
+            callbackExecutor: Executor,
         ) {
             mainExecutor.execute {
                 this@DesktopTasksController.addVisibleTasksListener(listener, callbackExecutor)
@@ -2372,7 +2434,7 @@
 
         override fun addDesktopGestureExclusionRegionListener(
             listener: Consumer<Region>,
-            callbackExecutor: Executor
+            callbackExecutor: Executor,
         ) {
             mainExecutor.execute {
                 this@DesktopTasksController.setTaskRegionListener(listener, callbackExecutor)
@@ -2381,7 +2443,7 @@
 
         override fun moveFocusedTaskToDesktop(
             displayId: Int,
-            transitionSource: DesktopModeTransitionSource
+            transitionSource: DesktopModeTransitionSource,
         ) {
             logV("moveFocusedTaskToDesktop")
             mainExecutor.execute {
@@ -2391,7 +2453,7 @@
 
         override fun moveFocusedTaskToFullscreen(
             displayId: Int,
-            transitionSource: DesktopModeTransitionSource
+            transitionSource: DesktopModeTransitionSource,
         ) {
             logV("moveFocusedTaskToFullscreen")
             mainExecutor.execute {
@@ -2420,7 +2482,7 @@
                         WM_SHELL_DESKTOP_MODE,
                         "IDesktopModeImpl: onVisibilityChanged display=%d visible=%d",
                         displayId,
-                        visibleTasksCount
+                        visibleTasksCount,
                     )
                     remoteListener.call { l ->
                         l.onTasksVisibilityChanged(displayId, visibleTasksCount)
@@ -2429,21 +2491,22 @@
             }
 
         private val taskbarDesktopTaskListener: TaskbarDesktopTaskListener =
-                object : TaskbarDesktopTaskListener {
-                    override fun onTaskbarCornerRoundingUpdate(
-                        hasTasksRequiringTaskbarRounding: Boolean) {
-                        ProtoLog.v(
-                                WM_SHELL_DESKTOP_MODE,
-                                "IDesktopModeImpl: onTaskbarCornerRoundingUpdate " +
-                                        "doesAnyTaskRequireTaskbarRounding=%s",
-                                hasTasksRequiringTaskbarRounding
-                        )
+            object : TaskbarDesktopTaskListener {
+                override fun onTaskbarCornerRoundingUpdate(
+                    hasTasksRequiringTaskbarRounding: Boolean
+                ) {
+                    ProtoLog.v(
+                        WM_SHELL_DESKTOP_MODE,
+                        "IDesktopModeImpl: onTaskbarCornerRoundingUpdate " +
+                            "doesAnyTaskRequireTaskbarRounding=%s",
+                        hasTasksRequiringTaskbarRounding,
+                    )
 
-                        remoteListener.call { l ->
-                            l.onTaskbarCornerRoundingUpdate(hasTasksRequiringTaskbarRounding)
-                        }
+                    remoteListener.call { l ->
+                        l.onTaskbarCornerRoundingUpdate(hasTasksRequiringTaskbarRounding)
                     }
                 }
+            }
 
         private val desktopModeEntryExitTransitionListener: DesktopModeEntryExitTransitionListener =
             object : DesktopModeEntryExitTransitionListener {
@@ -2451,18 +2514,22 @@
                     ProtoLog.v(
                         WM_SHELL_DESKTOP_MODE,
                         "IDesktopModeImpl: onEnterDesktopModeTransitionStarted transitionTime=%s",
-                        transitionDuration
+                        transitionDuration,
                     )
-                    remoteListener.call { l -> l.onEnterDesktopModeTransitionStarted(transitionDuration) }
+                    remoteListener.call { l ->
+                        l.onEnterDesktopModeTransitionStarted(transitionDuration)
+                    }
                 }
 
                 override fun onExitDesktopModeTransitionStarted(transitionDuration: Int) {
                     ProtoLog.v(
                         WM_SHELL_DESKTOP_MODE,
                         "IDesktopModeImpl: onExitDesktopModeTransitionStarted transitionTime=%s",
-                        transitionDuration
+                        transitionDuration,
                     )
-                    remoteListener.call { l -> l.onExitDesktopModeTransitionStarted(transitionDuration) }
+                    remoteListener.call { l ->
+                        l.onExitDesktopModeTransitionStarted(transitionDuration)
+                    }
                 }
             }
 
@@ -2484,7 +2551,7 @@
                             c.taskbarDesktopTaskListener = null
                             c.desktopModeEnterExitTransitionListener = null
                         }
-                    }
+                    },
                 )
         }
 
@@ -2511,8 +2578,10 @@
         }
 
         override fun hideStashedDesktopApps(displayId: Int) {
-            ProtoLog.w(WM_SHELL_DESKTOP_MODE,
-                "IDesktopModeImpl: hideStashedDesktopApps is deprecated")
+            ProtoLog.w(
+                WM_SHELL_DESKTOP_MODE,
+                "IDesktopModeImpl: hideStashedDesktopApps is deprecated",
+            )
         }
 
         override fun getVisibleTaskCount(displayId: Int): Int {
@@ -2521,16 +2590,14 @@
                 controller,
                 "visibleTaskCount",
                 { controller -> result[0] = controller.visibleTaskCount(displayId) },
-                true /* blocking */
+                true, /* blocking */
             )
             return result[0]
         }
 
         override fun onDesktopSplitSelectAnimComplete(taskInfo: RunningTaskInfo) {
-            executeRemoteCallWithTaskPermission(
-                controller,
-                "onDesktopSplitSelectAnimComplete"
-            ) { c ->
+            executeRemoteCallWithTaskPermission(controller, "onDesktopSplitSelectAnimComplete") { c
+                ->
                 c.onDesktopSplitSelectAnimComplete(taskInfo)
             }
         }
@@ -2564,9 +2631,11 @@
     private fun logV(msg: String, vararg arguments: Any?) {
         ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
     }
+
     private fun logD(msg: String, vararg arguments: Any?) {
         ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
     }
+
     private fun logW(msg: String, vararg arguments: Any?) {
         ProtoLog.w(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
     }
@@ -2601,6 +2670,6 @@
     /** The positions on a screen that a task can snap to. */
     enum class SnapPosition {
         RIGHT,
-        LEFT
+        LEFT,
     }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksLimiter.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksLimiter.kt
index 62b200a..635078e 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksLimiter.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksLimiter.kt
@@ -22,9 +22,9 @@
 import android.os.IBinder
 import android.view.SurfaceControl
 import android.view.WindowManager.TRANSIT_TO_BACK
+import android.window.DesktopModeFlags
 import android.window.TransitionInfo
 import android.window.WindowContainerTransaction
-import android.window.DesktopModeFlags
 import androidx.annotation.VisibleForTesting
 import com.android.internal.jank.Cuj.CUJ_DESKTOP_MODE_MINIMIZE_WINDOW
 import com.android.internal.jank.InteractionJankMonitor
@@ -32,7 +32,7 @@
 import com.android.wm.shell.ShellTaskOrganizer
 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
 import com.android.wm.shell.shared.annotations.ShellMainThread
-import com.android.wm.shell.sysui.UserChangeListener;
+import com.android.wm.shell.sysui.UserChangeListener
 import com.android.wm.shell.transition.Transitions
 import com.android.wm.shell.transition.Transitions.TransitionObserver
 
@@ -40,21 +40,20 @@
  * Limits the number of tasks shown in Desktop Mode.
  *
  * This class should only be used if
- * [android.window.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_TASK_LIMIT]
- * is enabled and [maxTasksLimit] is strictly greater than 0.
+ * [android.window.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_TASK_LIMIT] is enabled and
+ * [maxTasksLimit] is strictly greater than 0.
  */
-class DesktopTasksLimiter (
-        transitions: Transitions,
-        private val desktopUserRepositories: DesktopUserRepositories,
-        private val shellTaskOrganizer: ShellTaskOrganizer,
-        private val maxTasksLimit: Int,
-        private val interactionJankMonitor: InteractionJankMonitor,
-        private val context: Context,
-        @ShellMainThread private val handler: Handler,
+class DesktopTasksLimiter(
+    transitions: Transitions,
+    private val desktopUserRepositories: DesktopUserRepositories,
+    private val shellTaskOrganizer: ShellTaskOrganizer,
+    private val maxTasksLimit: Int,
+    private val interactionJankMonitor: InteractionJankMonitor,
+    private val context: Context,
+    @ShellMainThread private val handler: Handler,
 ) {
     private val minimizeTransitionObserver = MinimizeTransitionObserver()
-    @VisibleForTesting
-    val leftoverMinimizedTasksRemover = LeftoverMinimizedTasksRemover()
+    @VisibleForTesting val leftoverMinimizedTasksRemover = LeftoverMinimizedTasksRemover()
 
     private var userId: Int
 
@@ -71,7 +70,7 @@
     private data class TaskDetails(
         val displayId: Int,
         val taskId: Int,
-        var transitionInfo: TransitionInfo?
+        var transitionInfo: TransitionInfo?,
     )
 
     // TODO(b/333018485): replace this observer when implementing the minimize-animation
@@ -87,7 +86,7 @@
             transition: IBinder,
             info: TransitionInfo,
             startTransaction: SurfaceControl.Transaction,
-            finishTransaction: SurfaceControl.Transaction
+            finishTransaction: SurfaceControl.Transaction,
         ) {
             val taskRepository = desktopUserRepositories.current
             val taskToMinimize = pendingTransitionTokensAndTasks.remove(transition) ?: return
@@ -100,12 +99,13 @@
             activeTransitionTokensAndTasks[transition] = taskToMinimize
 
             // Save current bounds before minimizing in case we need to restore to it later.
-            val boundsBeforeMinimize = info.changes.find { change ->
-                change.taskInfo?.taskId == taskToMinimize.taskId }?.startAbsBounds
+            val boundsBeforeMinimize =
+                info.changes
+                    .find { change -> change.taskInfo?.taskId == taskToMinimize.taskId }
+                    ?.startAbsBounds
             taskRepository.saveBoundsBeforeMinimize(taskToMinimize.taskId, boundsBeforeMinimize)
 
-            this@DesktopTasksLimiter.minimizeTask(
-                    taskToMinimize.displayId, taskToMinimize.taskId)
+            this@DesktopTasksLimiter.minimizeTask(taskToMinimize.displayId, taskToMinimize.taskId)
         }
 
         /**
@@ -116,10 +116,10 @@
          */
         private fun isTaskReadyForMinimize(
             info: TransitionInfo,
-            taskDetails: TaskDetails
+            taskDetails: TaskDetails,
         ): Boolean {
-            val taskChange = info.changes.find { change ->
-                change.taskInfo?.taskId == taskDetails.taskId }
+            val taskChange =
+                info.changes.find { change -> change.taskInfo?.taskId == taskDetails.taskId }
             val taskRepository = desktopUserRepositories.current
             if (taskChange == null) return !taskRepository.isVisibleTask(taskDetails.taskId)
             return taskChange.mode == TRANSIT_TO_BACK
@@ -130,8 +130,10 @@
             if (mActiveTaskDetails != null && mActiveTaskDetails.transitionInfo != null) {
                 // Begin minimize window CUJ instrumentation.
                 interactionJankMonitor.begin(
-                    mActiveTaskDetails.transitionInfo?.rootLeash, context, handler,
-                    CUJ_DESKTOP_MODE_MINIMIZE_WINDOW
+                    mActiveTaskDetails.transitionInfo?.rootLeash,
+                    context,
+                    handler,
+                    CUJ_DESKTOP_MODE_MINIMIZE_WINDOW,
                 )
             }
         }
@@ -158,8 +160,8 @@
     }
 
     @VisibleForTesting
-    inner class LeftoverMinimizedTasksRemover
-            : DesktopRepository.ActiveTasksListener, UserChangeListener {
+    inner class LeftoverMinimizedTasksRemover :
+        DesktopRepository.ActiveTasksListener, UserChangeListener {
         override fun onActiveTasksChanged(displayId: Int) {
             // If back navigation is enabled, we shouldn't remove the leftover tasks
             if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) return
@@ -185,19 +187,19 @@
 
         override fun onUserChanged(newUserId: Int, userContext: Context) {
             // Removes active task listener for the previous repository
-            desktopUserRepositories.getProfile(userId).removeActiveTasksListener(this);
+            desktopUserRepositories.getProfile(userId).removeActiveTasksListener(this)
 
             // Sets active listener for the current repository.
             userId = newUserId
-            desktopUserRepositories.getProfile(newUserId).addActiveTaskListener(this);
+            desktopUserRepositories.getProfile(newUserId).addActiveTaskListener(this)
         }
     }
 
     /**
      * Mark task with [taskId] on [displayId] as minimized.
      *
-     * This should be after the corresponding transition has finished so we don't
-     * minimize the task if the transition fails.
+     * This should be after the corresponding transition has finished so we don't minimize the task
+     * if the transition fails.
      */
     private fun minimizeTask(displayId: Int, taskId: Int) {
         logV("Minimize taskId=%d, displayId=%d", taskId, displayId)
@@ -206,25 +208,22 @@
     }
 
     /**
-     * Adds a minimize-transition to [wct] if adding [newFrontTaskInfo] crosses task
-     * limit, returning the task to minimize.
+     * Adds a minimize-transition to [wct] if adding [newFrontTaskInfo] crosses task limit,
+     * returning the task to minimize.
      */
     fun addAndGetMinimizeTaskChanges(
-            displayId: Int,
-            wct: WindowContainerTransaction,
-            newFrontTaskId: Int,
+        displayId: Int,
+        wct: WindowContainerTransaction,
+        newFrontTaskId: Int,
     ): Int? {
         logV("addAndGetMinimizeTaskChanges, newFrontTask=%d", newFrontTaskId)
         val taskRepository = desktopUserRepositories.current
         val taskIdToMinimize =
-            getTaskIdToMinimize(
-                taskRepository.getExpandedTasksOrdered(displayId),
-                newFrontTaskId
-            )
+            getTaskIdToMinimize(taskRepository.getExpandedTasksOrdered(displayId), newFrontTaskId)
         // If it's a running task, reorder it to back.
-        taskIdToMinimize?.let { shellTaskOrganizer.getRunningTaskInfo(it) }?.let {
-            wct.reorder(it.token, false /* onTop */)
-        }
+        taskIdToMinimize
+            ?.let { shellTaskOrganizer.getRunningTaskInfo(it) }
+            ?.let { wct.reorder(it.token, false /* onTop */) }
         return taskIdToMinimize
     }
 
@@ -234,20 +233,19 @@
      */
     fun addPendingMinimizeChange(transition: IBinder, displayId: Int, taskId: Int) {
         minimizeTransitionObserver.addPendingTransitionToken(
-                transition, TaskDetails(displayId, taskId, transitionInfo = null))
+            transition,
+            TaskDetails(displayId, taskId, transitionInfo = null),
+        )
     }
 
     /**
-     * Returns the minimized task from the list of visible tasks ordered from front to back with
-     * the new task placed in front of other tasks.
+     * Returns the minimized task from the list of visible tasks ordered from front to back with the
+     * new task placed in front of other tasks.
      */
-    fun getTaskIdToMinimize(
-            visibleOrderedTasks: List<Int>,
-            newTaskIdInFront: Int? = null
-    ): Int? {
+    fun getTaskIdToMinimize(visibleOrderedTasks: List<Int>, newTaskIdInFront: Int? = null): Int? {
         return getTaskIdToMinimize(
-            createOrderedTaskListWithGivenTaskInFront(
-                visibleOrderedTasks, newTaskIdInFront))
+            createOrderedTaskListWithGivenTaskInFront(visibleOrderedTasks, newTaskIdInFront)
+        )
     }
 
     /** Returns the Task to minimize given a list of visible tasks ordered from front to back. */
@@ -261,16 +259,16 @@
     }
 
     private fun createOrderedTaskListWithGivenTaskInFront(
-            existingTaskIdsOrderedFrontToBack: List<Int>,
-            newTaskId: Int?
+        existingTaskIdsOrderedFrontToBack: List<Int>,
+        newTaskId: Int?,
     ): List<Int> {
         return if (newTaskId == null) existingTaskIdsOrderedFrontToBack
-        else listOf(newTaskId) +
+        else
+            listOf(newTaskId) +
                 existingTaskIdsOrderedFrontToBack.filter { taskId -> taskId != newTaskId }
     }
 
-    @VisibleForTesting
-    fun getTransitionObserver(): TransitionObserver = minimizeTransitionObserver
+    @VisibleForTesting fun getTransitionObserver(): TransitionObserver = minimizeTransitionObserver
 
     private fun logV(msg: String, vararg arguments: Any?) {
         ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
index d6bb7f9..b1667c5 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt
@@ -24,10 +24,10 @@
 import android.view.WindowManager
 import android.view.WindowManager.TRANSIT_CLOSE
 import android.view.WindowManager.TRANSIT_TO_BACK
-import android.window.TransitionInfo
-import android.window.WindowContainerTransaction
 import android.window.DesktopModeFlags
 import android.window.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY
+import android.window.TransitionInfo
+import android.window.WindowContainerTransaction
 import com.android.internal.protolog.ProtoLog
 import com.android.wm.shell.ShellTaskOrganizer
 import com.android.wm.shell.desktopmode.DesktopModeTransitionTypes.isExitDesktopModeTransition
@@ -48,7 +48,7 @@
     private val transitions: Transitions,
     private val shellTaskOrganizer: ShellTaskOrganizer,
     private val desktopMixedTransitionHandler: DesktopMixedTransitionHandler,
-    shellInit: ShellInit
+    shellInit: ShellInit,
 ) : Transitions.TransitionObserver {
 
     private var transitionToCloseWallpaper: IBinder? = null
@@ -70,7 +70,7 @@
         transition: IBinder,
         info: TransitionInfo,
         startTransaction: SurfaceControl.Transaction,
-        finishTransaction: SurfaceControl.Transaction
+        finishTransaction: SurfaceControl.Transaction,
     ) {
         // TODO: b/332682201 Update repository state
         updateWallpaperToken(info)
@@ -93,8 +93,10 @@
             if (taskInfo == null || taskInfo.taskId == -1) continue
 
             val desktopRepository = desktopUserRepositories.getProfile(taskInfo.userId)
-            if (desktopRepository.isActiveTask(taskInfo.taskId) &&
-                taskInfo.windowingMode != WINDOWING_MODE_FREEFORM) {
+            if (
+                desktopRepository.isActiveTask(taskInfo.taskId) &&
+                    taskInfo.windowingMode != WINDOWING_MODE_FREEFORM
+            ) {
                 desktopRepository.removeFreeformTask(taskInfo.displayId, taskInfo.taskId)
             }
         }
@@ -111,13 +113,19 @@
                 }
                 val desktopRepository = desktopUserRepositories.getProfile(taskInfo.userId)
                 val visibleTaskCount = desktopRepository.getVisibleTaskCount(taskInfo.displayId)
-                if (visibleTaskCount > 0 &&
-                    change.mode == TRANSIT_TO_BACK &&
-                    taskInfo.windowingMode == WINDOWING_MODE_FREEFORM) {
+                if (
+                    visibleTaskCount > 0 &&
+                        change.mode == TRANSIT_TO_BACK &&
+                        taskInfo.windowingMode == WINDOWING_MODE_FREEFORM
+                ) {
                     desktopRepository.minimizeTask(taskInfo.displayId, taskInfo.taskId)
                     desktopMixedTransitionHandler.addPendingMixedTransition(
                         DesktopMixedTransitionHandler.PendingMixedTransition.Minimize(
-                            transition, taskInfo.taskId, visibleTaskCount == 1))
+                            transition,
+                            taskInfo.taskId,
+                            visibleTaskCount == 1,
+                        )
+                    )
                 }
             }
         }
@@ -125,7 +133,7 @@
 
     private fun removeWallpaperOnLastTaskClosingIfNeeded(
         transition: IBinder,
-        info: TransitionInfo
+        info: TransitionInfo,
     ) {
         for (change in info.changes) {
             val taskInfo = change.taskInfo
@@ -133,10 +141,12 @@
                 continue
             }
             val desktopRepository = desktopUserRepositories.getProfile(taskInfo.userId)
-            if (desktopRepository.getVisibleTaskCount(taskInfo.displayId) == 1 &&
-                change.mode == TRANSIT_CLOSE &&
-                taskInfo.windowingMode == WINDOWING_MODE_FREEFORM &&
-                desktopRepository.wallpaperActivityToken != null) {
+            if (
+                desktopRepository.getVisibleTaskCount(taskInfo.displayId) == 1 &&
+                    change.mode == TRANSIT_CLOSE &&
+                    taskInfo.windowingMode == WINDOWING_MODE_FREEFORM &&
+                    desktopRepository.wallpaperActivityToken != null
+            ) {
                 transitionToCloseWallpaper = transition
                 currentProfileId = taskInfo.userId
             }
@@ -160,7 +170,8 @@
                 transitions.startTransition(
                     TRANSIT_CLOSE,
                     WindowContainerTransaction().removeTask(wallpaperActivityToken),
-                    null)
+                    null,
+                )
             }
             transitionToCloseWallpaper = null
         }
@@ -182,10 +193,10 @@
                             // task.
                             shellTaskOrganizer.applyTransaction(
                                 WindowContainerTransaction()
-                                    .setTaskTrimmableFromRecents(taskInfo.token, false))
+                                    .setTaskTrimmableFromRecents(taskInfo.token, false)
+                            )
                         }
-                        TRANSIT_CLOSE ->
-                            desktopRepository.wallpaperActivityToken = null
+                        TRANSIT_CLOSE -> desktopRepository.wallpaperActivityToken = null
                         else -> {}
                     }
                 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopUserRepositories.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopUserRepositories.kt
index 1e5a1b2..e5f5283 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopUserRepositories.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopUserRepositories.kt
@@ -21,8 +21,8 @@
 import android.content.pm.UserInfo
 import android.os.UserManager
 import android.util.SparseArray
-import com.android.window.flags.Flags
 import com.android.internal.protolog.ProtoLog
+import com.android.window.flags.Flags
 import com.android.wm.shell.desktopmode.persistence.DesktopPersistentRepository
 import com.android.wm.shell.desktopmode.persistence.DesktopRepositoryInitializer
 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
@@ -53,11 +53,9 @@
             /** Gets [DesktopRepository] for existing [userId] or creates a new one. */
             fun getOrCreate(userId: Int): DesktopRepository =
                 this[userId]
-                    ?: DesktopRepository(
-                        persistentRepository,
-                        mainCoroutineScope,
-                        userId)
-                        .also { this[userId] = it }
+                    ?: DesktopRepository(persistentRepository, mainCoroutineScope, userId).also {
+                        this[userId] = it
+                    }
         }
 
     init {