From 1657c81a6c6c6c6873b747060f33e46a71737382 Mon Sep 17 00:00:00 2001 From: mattsziklay Date: Wed, 30 Aug 2023 10:32:30 -0700 Subject: Update desktop gesture exclusion criteria. Expands the gesture exclusion regions generated per task to include caption bounds. This prevents gestures from occurring when attempting to drag position a task from the edge of the screen. This CL also excludes the corners from the gesture exclusion region for non-resizeable tasks. Bug: 296925353 Test: Manual, drag task off the edge of the screen, then drag back from the edge without triggering gesture. Change-Id: If6cbcd24934bf0163d226ab5d158c20610f5dde5 --- .../shell/desktopmode/DesktopModeTaskRepository.kt | 39 +++++++------ .../wm/shell/desktopmode/DesktopTasksController.kt | 20 +++---- .../DesktopModeWindowDecorViewModel.java | 20 +++---- .../windowdecor/DesktopModeWindowDecoration.java | 68 +++++++++++++++------- 4 files changed, 89 insertions(+), 58 deletions(-) (limited to 'libs') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt index c05af73e6765..c0fc02fadd4d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopModeTaskRepository.kt @@ -52,8 +52,8 @@ class DesktopModeTaskRepository { private val activeTasksListeners = ArraySet() // Track visible tasks separately because a task may be part of the desktop but not visible. private val visibleTasksListeners = ArrayMap() - // Track corners of desktop tasks, used to determine gesture exclusion - private val desktopCorners = SparseArray() + // Track corner/caption regions of desktop tasks, used to determine gesture exclusion + private val desktopExclusionRegions = SparseArray() private var desktopGestureExclusionListener: Consumer? = null private var desktopGestureExclusionExecutor: Executor? = null @@ -96,10 +96,11 @@ class DesktopModeTaskRepository { } /** - * Add a Consumer which will inform other classes of changes to corners for all Desktop tasks. + * Add a Consumer which will inform other classes of changes to exclusion regions for all + * Desktop tasks. */ - fun setTaskCornerListener(cornersListener: Consumer, executor: Executor) { - desktopGestureExclusionListener = cornersListener + fun setExclusionRegionListener(regionListener: Consumer, executor: Executor) { + desktopGestureExclusionListener = regionListener desktopGestureExclusionExecutor = executor executor.execute { desktopGestureExclusionListener?.accept(calculateDesktopExclusionRegion()) @@ -107,14 +108,14 @@ class DesktopModeTaskRepository { } /** - * Create a new merged region representative of all corners in all desktop tasks. + * Create a new merged region representative of all exclusion regions in all desktop tasks. */ private fun calculateDesktopExclusionRegion(): Region { - val desktopCornersRegion = Region() - desktopCorners.valueIterator().forEach { taskCorners -> - desktopCornersRegion.op(taskCorners, Region.Op.UNION) + val desktopExclusionRegion = Region() + desktopExclusionRegions.valueIterator().forEach { taskExclusionRegion -> + desktopExclusionRegion.op(taskExclusionRegion, Region.Op.UNION) } - return desktopCornersRegion + return desktopExclusionRegion } /** @@ -294,22 +295,24 @@ class DesktopModeTaskRepository { } /** - * Updates the active desktop corners; if desktopCorners has been accepted by - * desktopCornersListener, it will be updated in the appropriate classes. + * Updates the active desktop gesture exclusion regions; if desktopExclusionRegions has been + * accepted by desktopGestureExclusionListener, it will be updated in the + * appropriate classes. */ - fun updateTaskCorners(taskId: Int, taskCorners: Region) { - desktopCorners.put(taskId, taskCorners) + fun updateTaskExclusionRegions(taskId: Int, taskExclusionRegions: Region) { + desktopExclusionRegions.put(taskId, taskExclusionRegions) desktopGestureExclusionExecutor?.execute { desktopGestureExclusionListener?.accept(calculateDesktopExclusionRegion()) } } /** - * Removes the active desktop corners for the specified task; if desktopCorners has been - * accepted by desktopCornersListener, it will be updated in the appropriate classes. + * Removes the desktop gesture exclusion region for the specified task; if exclusionRegion + * has been accepted by desktopGestureExclusionListener, it will be updated in the + * appropriate classes. */ - fun removeTaskCorners(taskId: Int) { - desktopCorners.delete(taskId) + fun removeExclusionRegion(taskId: Int) { + desktopExclusionRegions.delete(taskId) desktopGestureExclusionExecutor?.execute { desktopGestureExclusionListener?.accept(calculateDesktopExclusionRegion()) } 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 b918c83a5c6b..dd68ac966f5c 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 @@ -972,17 +972,17 @@ class DesktopTasksController( } /** - * Update the corner region for a specified task + * Update the exclusion region for a specified task */ - fun onTaskCornersChanged(taskId: Int, corner: Region) { - desktopModeTaskRepository.updateTaskCorners(taskId, corner) + fun onExclusionRegionChanged(taskId: Int, exclusionRegion: Region) { + desktopModeTaskRepository.updateTaskExclusionRegions(taskId, exclusionRegion) } /** - * Remove a previously tracked corner region for a specified task. + * Remove a previously tracked exclusion region for a specified task. */ - fun removeCornersForTask(taskId: Int) { - desktopModeTaskRepository.removeTaskCorners(taskId) + fun removeExclusionRegionForTask(taskId: Int) { + desktopModeTaskRepository.removeExclusionRegion(taskId) } /** @@ -996,16 +996,16 @@ class DesktopTasksController( } /** - * Adds a listener to track changes to desktop task corners + * Adds a listener to track changes to desktop task gesture exclusion regions * * @param listener the listener to add. * @param callbackExecutor the executor to call the listener on. */ - fun setTaskCornerListener( + fun setTaskRegionListener( listener: Consumer, callbackExecutor: Executor ) { - desktopModeTaskRepository.setTaskCornerListener(listener, callbackExecutor) + desktopModeTaskRepository.setExclusionRegionListener(listener, callbackExecutor) } private fun dump(pw: PrintWriter, prefix: String) { @@ -1031,7 +1031,7 @@ class DesktopTasksController( callbackExecutor: Executor ) { mainExecutor.execute { - this@DesktopTasksController.setTaskCornerListener(listener, callbackExecutor) + this@DesktopTasksController.setTaskRegionListener(listener, callbackExecutor) } } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java index abd2ad49317b..026d0cdd7c52 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java @@ -21,7 +21,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; - import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT; import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_TOP_OR_LEFT; import static com.android.wm.shell.desktopmode.EnterDesktopTaskTransitionHandler.FINAL_FREEFORM_SCALE; @@ -79,7 +78,7 @@ import com.android.wm.shell.sysui.KeyguardChangeListener; import com.android.wm.shell.sysui.ShellController; import com.android.wm.shell.sysui.ShellInit; import com.android.wm.shell.transition.Transitions; -import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration.TaskCornersListener; +import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration.ExclusionRegionListener; import java.util.Optional; import java.util.function.Supplier; @@ -106,7 +105,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { private SparseArray mEventReceiversByDisplay = new SparseArray<>(); - private final TaskCornersListener mCornersListener = new TaskCornersListenerImpl(); + private final ExclusionRegionListener mExclusionRegionListener = + new ExclusionRegionListenerImpl(); private final SparseArray mWindowDecorByTaskId = new SparseArray<>(); @@ -920,7 +920,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { windowDecoration.setCaptionListeners( touchEventListener, touchEventListener, touchEventListener); - windowDecoration.setCornersListener(mCornersListener); + windowDecoration.setExclusionRegionListener(mExclusionRegionListener); windowDecoration.setDragPositioningCallback(dragPositioningCallback); windowDecoration.setDragDetector(touchEventListener.mDragDetector); windowDecoration.relayout(taskInfo, startT, finishT, @@ -958,17 +958,17 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { } } - private class TaskCornersListenerImpl - implements DesktopModeWindowDecoration.TaskCornersListener { + private class ExclusionRegionListenerImpl + implements ExclusionRegionListener { @Override - public void onTaskCornersChanged(int taskId, Region corner) { - mDesktopTasksController.ifPresent(d -> d.onTaskCornersChanged(taskId, corner)); + public void onExclusionRegionChanged(int taskId, Region region) { + mDesktopTasksController.ifPresent(d -> d.onExclusionRegionChanged(taskId, region)); } @Override - public void onTaskCornersRemoved(int taskId) { - mDesktopTasksController.ifPresent(d -> d.removeCornersForTask(taskId)); + public void onExclusionRegionDismissed(int taskId) { + mDesktopTasksController.ifPresent(d -> d.removeExclusionRegionForTask(taskId)); } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index e954f3b4a1d5..dbff20e6026a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -92,7 +92,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration mTransitionsPausingRelayout = new HashSet<>(); private int mRelayoutBlock; @@ -128,8 +128,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration