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

Commit 63d235c0 authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

Fix a crash where tiling animations are not canceled on resetting.

This CL fixes a crash where overview animations would trigger a tiling
animation wrongly, and then in the unlikely case of a task vanishing,
the divider view would cause a crash as tiling resources are destroyed
during an animation.

Flag: com.android.window.flags.enable_tile_resizing
Test: unit tests and on device testing
Bug: 409602968
Change-Id: I6a153b3386d505c6e38f4ffac96df4008f6fb5da
parent f31e4b71
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -335,7 +335,6 @@ class DesktopTasksController(
                        RecentsTransitionStateListener.stateToString(state),
                    )
                    recentsTransitionState = state
                    snapEventHandler.onOverviewAnimationStateChange(state)
                }
            }
        )
@@ -490,8 +489,11 @@ class DesktopTasksController(
            returnToApp,
            activeDeskIdOnRecentsStart,
        )

        if (returnToApp) {
            // Returning to the same desk, nothing to do.
            // Returning to the same desk, notify the snap event handler of recents animation
            // ending to the same desk.
            snapEventHandler.onRecentsAnimationEndedToSameDesk()
            return
        }
        if (
+2 −3
Original line number Diff line number Diff line
@@ -1005,9 +1005,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    }

    @Override
    public void onOverviewAnimationStateChange(
            @RecentsTransitionStateListener.RecentsTransitionState int state) {
        mDesktopTilingDecorViewModel.onOverviewAnimationStateChange(state);
    public void onRecentsAnimationEndedToSameDesk() {
        mDesktopTilingDecorViewModel.onOverviewAnimationEndedToSameDesk();
    }

    @Override
+2 −5
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.wm.shell.desktopmode.DesktopUserRepositories
import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.shared.annotations.ShellBackgroundThread
import com.android.wm.shell.shared.annotations.ShellMainThread
import com.android.wm.shell.shared.desktopmode.DesktopState
@@ -147,12 +146,10 @@ class DesktopTilingDecorViewModel(
            ?.moveTiledPairToFront(taskInfo.taskId, isFocusedOnDisplay = true) ?: false
    }

    fun onOverviewAnimationStateChange(
        @RecentsTransitionStateListener.RecentsTransitionState state: Int
    ) {
    fun onOverviewAnimationEndedToSameDesk() {
        val activeUserHandlers = tilingHandlerByUserAndDeskId[currentUserId] ?: return
        for (tilingHandler in activeUserHandlers.valueIterator()) {
            tilingHandler.onOverviewAnimationStateChange(state)
            tilingHandler.onRecentsAnimationEndedToSameDesk()
        }
    }

+16 −7
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class DesktopTilingDividerWindowManager(
        )
    private var setTouchRegion = true
    private val maxRoundedCornerRadius = getMaxRoundedCornerRadius()
    private var runningAnimator: ValueAnimator? = null

    /**
     * Gets bounds of divider window with screen based coordinate on the param Rect.
@@ -151,7 +152,7 @@ class DesktopTilingDividerWindowManager(
        getDividerBounds(tmpDividerBounds)
        dividerView.setup(this, tmpDividerBounds, handleRegionSize, isDarkMode)
        val dividerAnimatorT = transactionSupplier.get()
        val dividerAnimator =
        runningAnimator =
            ValueAnimator.ofFloat(0f, 1f).apply {
                duration = DIVIDER_FADE_IN_ALPHA_DURATION
                addUpdateListener {
@@ -174,12 +175,13 @@ class DesktopTilingDividerWindowManager(

                        override fun onAnimationEnd(animation: Animator) {
                            dividerAnimatorT.setAlpha(leash, 1f).apply()
                            dividerShown = true
                            runningAnimator = null
                        }
                    }
                )
            }
        dividerAnimator.start()
        runningAnimator?.start()
        dividerShown = true
        viewHost = surfaceControlViewHost
        tilingDividerView = dividerView
        updateTouchRegion()
@@ -201,15 +203,21 @@ class DesktopTilingDividerWindowManager(
        if (!dividerShown) {
            return
        }
        cancelAnimation()
        val t = transactionSupplier.get()
        t.hide(leash)
        t.apply()
        dividerShown = false
    }

    fun cancelAnimation() {
        runningAnimator?.removeAllUpdateListeners()
        runningAnimator?.cancel()
        runningAnimator = null
    }
    /** Shows the divider bar. */
    fun showDividerBar(isTilingVisibleAfterRecents: Boolean) {
        if (dividerShown) return
        if (dividerShown || runningAnimator != null) return
        val dividerAnimatorT = transactionSupplier.get()
        val dividerAnimDuration =
            if (isTilingVisibleAfterRecents) {
@@ -217,7 +225,7 @@ class DesktopTilingDividerWindowManager(
            } else {
                DIVIDER_FADE_IN_ALPHA_DURATION
            }
        val dividerAnimator =
        runningAnimator =
            ValueAnimator.ofFloat(0f, 1f).apply {
                duration = dividerAnimDuration
                addUpdateListener {
@@ -231,12 +239,12 @@ class DesktopTilingDividerWindowManager(

                        override fun onAnimationEnd(animation: Animator) {
                            dividerAnimatorT.setAlpha(leash, 1f).apply()
                            dividerShown = true
                            runningAnimator = null
                        }
                    }
                )
            }
        dividerAnimator.start()
        runningAnimator?.start()
        dividerShown = true
    }

@@ -302,6 +310,7 @@ class DesktopTilingDividerWindowManager(
     * hierarchy.y.
     */
    fun release() {
        cancelAnimation()
        tilingDividerView = null
        viewHost.release()
        transactionSupplier.get().hide(leash).remove(leash).apply()
+11 −15
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.wm.shell.desktopmode.DesktopTasksController.SnapPosition
import com.android.wm.shell.desktopmode.DesktopUserRepositories
import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler
import com.android.wm.shell.recents.RecentsTransitionStateListener
import com.android.wm.shell.shared.FocusTransitionListener
import com.android.wm.shell.shared.annotations.ShellBackgroundThread
import com.android.wm.shell.shared.annotations.ShellMainThread
@@ -60,6 +59,7 @@ import com.android.wm.shell.shared.desktopmode.DesktopState
import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.TRANSIT_MINIMIZE
import com.android.wm.shell.transition.Transitions.TRANSIT_START_RECENTS_TRANSITION
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration
import com.android.wm.shell.windowdecor.DragPositioningCallbackUtility
import com.android.wm.shell.windowdecor.DragPositioningCallbackUtility.DragEventListener
@@ -113,7 +113,7 @@ class DesktopTilingWindowDecoration(
    private var isDarkMode = false
    private var isResizing = false
    private var isTilingFocused = false
    private var isTilingVisibleAfterRecents = false
    private var hiddenByOverviewAnimation = false

    fun onAppTiled(
        taskInfo: RunningTaskInfo,
@@ -438,6 +438,10 @@ class DesktopTilingWindowDecoration(
    ) {
        var leftTaskBroughtToFront = false
        var rightTaskBroughtToFront = false
        if (info.type == TRANSIT_START_RECENTS_TRANSITION && isTilingManagerInitialised) {
            hiddenByOverviewAnimation = true
            hideDividerBar()
        }
        for (change in info.changes) {
            change.taskInfo?.let { taskInfo ->
                when {
@@ -477,8 +481,8 @@ class DesktopTilingWindowDecoration(
        }

        if (leftTaskBroughtToFront && rightTaskBroughtToFront) {
            desktopTilingDividerWindowManager?.showDividerBar(isTilingVisibleAfterRecents)
            isTilingVisibleAfterRecents = false
            desktopTilingDividerWindowManager?.showDividerBar(hiddenByOverviewAnimation)
            hiddenByOverviewAnimation = false
        }
    }

@@ -722,17 +726,9 @@ class DesktopTilingWindowDecoration(
        appResizingHelper.dispose()
    }

    fun onOverviewAnimationStateChange(
        @RecentsTransitionStateListener.RecentsTransitionState state: Int
    ) {
        if (!isTilingManagerInitialised) return
        if (RecentsTransitionStateListener.isRunning(state)) {
            isTilingVisibleAfterRecents = true
            desktopTilingDividerWindowManager?.hideDividerBar()
        } else if (allTiledTasksVisible()) {
            desktopTilingDividerWindowManager?.showDividerBar(isTilingVisibleAfterRecents)
            isTilingVisibleAfterRecents = false
        }
    fun onRecentsAnimationEndedToSameDesk() {
        desktopTilingDividerWindowManager?.showDividerBar(hiddenByOverviewAnimation)
        hiddenByOverviewAnimation = false
    }

    override fun onTaskVanished(taskInfo: RunningTaskInfo?) {
Loading