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

Commit 65048ceb authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Fall back to checking window bounds height during drag-to-desktop

During the (spring) drag-to-desktop animation we fetch the current
animation fraction by checking the animated width of the window against
its start- and end bounds. This logic breaks if the start- and
end-widths are the same. In this CL we check the start- and end heights
if the widths are the same.

Bug: 397196997
Flag: com.android.window.flags.enable_desktop_windowing_enter_transition_bugfix
Test: manual
Change-Id: I2144503e3d56e44a55840bc750bc03478b58fe48
parent 2c6f80fe
Loading
Loading
Loading
Loading
+35 −10
Original line number Diff line number Diff line
@@ -1138,8 +1138,11 @@ constructor(
            .spring(FloatProperties.RECT_HEIGHT, endBounds.height().toFloat(), sizeSpringConfig)
            .addUpdateListener { animBounds, _ ->
                val animFraction =
                    (animBounds.width() - startBounds.width()).toFloat() /
                        (endBounds.width() - startBounds.width())
                    getAnimationFraction(
                        startBounds = startBounds,
                        endBounds = endBounds,
                        animBounds = animBounds,
                    )
                val animScale = startScale + animFraction * (1 - startScale)
                // Freeform animation starts with freeform animation offset relative to the commit
                // animation and plays until the commit animation ends. For instance:
@@ -1191,16 +1194,38 @@ constructor(
            .start()
    }

    companion object {
        private const val TAG = "SpringDragToDesktopTransitionHandler"

        @VisibleForTesting
        fun getAnimationFraction(startBounds: Rect, endBounds: Rect, animBounds: Rect): Float {
            if (startBounds.width() != endBounds.width()) {
                return (animBounds.width() - startBounds.width()).toFloat() /
                    (endBounds.width() - startBounds.width())
            }
            if (startBounds.height() != endBounds.height()) {
                return (animBounds.height() - startBounds.height()).toFloat() /
                    (endBounds.height() - startBounds.height())
            }
            logW(
                "same start and end sizes, returning 0: " +
                    "startBounds=$startBounds, endBounds=$endBounds, animBounds=$animBounds"
            )
            return 0f
        }

        private fun logV(msg: String, vararg arguments: Any?) {
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
        }

        private fun logW(msg: String, vararg arguments: Any?) {
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
        }

        private fun logE(msg: String, vararg arguments: Any?) {
            ProtoLog.e(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
        }

    companion object {
        private const val TAG = "SpringDragToDesktopTransitionHandler"
        /** The freeform tasks initial scale when committing the drag-to-desktop gesture. */
        private val FREEFORM_TASKS_INITIAL_SCALE =
            propertyValue("freeform_tasks_initial_scale", scale = 100f, default = 0.9f)
+50 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW
import android.app.WindowConfiguration.WindowingMode
import android.graphics.PointF
import android.graphics.Rect
import android.os.IBinder
import android.os.SystemProperties
import android.testing.AndroidTestingRunner
@@ -36,6 +37,7 @@ import com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_TOP
import com.android.wm.shell.splitscreen.SplitScreenController
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.MoveToDesktopAnimator
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import java.util.function.Supplier
import junit.framework.Assert.assertEquals
@@ -694,6 +696,50 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {
            .cancel(eq(CUJ_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG_HOLD))
    }

    @Test
    fun getAnimationFraction_returnsFraction() {
        val fraction =
            SpringDragToDesktopTransitionHandler.getAnimationFraction(
                startBounds = Rect(0, 0, 0, 0),
                endBounds = Rect(0, 0, 10, 10),
                animBounds = Rect(0, 0, 5, 5),
            )
        assertThat(fraction).isWithin(TOLERANCE).of(0.5f)
    }

    @Test
    fun getAnimationFraction_animBoundsSameAsEnd_returnsOne() {
        val fraction =
            SpringDragToDesktopTransitionHandler.getAnimationFraction(
                startBounds = Rect(0, 0, 0, 0),
                endBounds = Rect(0, 0, 10, 10),
                animBounds = Rect(0, 0, 10, 10),
            )
        assertThat(fraction).isWithin(TOLERANCE).of(1f)
    }

    @Test
    fun getAnimationFraction_startAndEndBoundsSameWidth_usesHeight() {
        val fraction =
            SpringDragToDesktopTransitionHandler.getAnimationFraction(
                startBounds = Rect(0, 0, 10, 10),
                endBounds = Rect(0, 0, 10, 30),
                animBounds = Rect(0, 0, 10, 25),
            )
        assertThat(fraction).isWithin(TOLERANCE).of(0.75f)
    }

    @Test
    fun getAnimationFraction_startAndEndBoundsSame_returnsZero() {
        val fraction =
            SpringDragToDesktopTransitionHandler.getAnimationFraction(
                startBounds = Rect(0, 0, 10, 10),
                endBounds = Rect(0, 0, 10, 10),
                animBounds = Rect(0, 0, 10, 25),
            )
        assertThat(fraction).isWithin(TOLERANCE).of(0f)
    }

    private fun startDrag(
        handler: DragToDesktopTransitionHandler,
        task: RunningTaskInfo = createTask(),
@@ -826,4 +872,8 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {

    private fun systemPropertiesKey(name: String) =
        "${SpringDragToDesktopTransitionHandler.SYSTEM_PROPERTIES_GROUP}.$name"

    private companion object {
        private const val TOLERANCE = 1e-5f
    }
}