summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-24 02:13:33 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-02-24 02:13:33 -0800
commit5ac62be2f1cca101ebabbee4f51a0f52f24d5c31 (patch)
tree4d324ec5b7f50193b594f234f8fd8bf53b084fbf
parent3835fafdb4091315f4ea3c0dc6295754e9b14c96 (diff)
parent65048ceb2f8d863f66853f9cb116190f6ee2f8d4 (diff)
Merge "Fall back to checking window bounds height during drag-to-desktop" into main
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt45
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandlerTest.kt50
2 files changed, 85 insertions, 10 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt
index cb231800bd63..d396d8bff2b8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandler.kt
@@ -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()
}
- private fun logV(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"
+
+ @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)
+ }
+
/** 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)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandlerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandlerTest.kt
index 85f6cd36992d..de55db86d1e7 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandlerTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DragToDesktopTransitionHandlerTest.kt
@@ -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
+ }
}