summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java8
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt9
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt105
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModelTest.kt8
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt20
5 files changed, 99 insertions, 51 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
index c71bf687374d..d9389bf6b3b9 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java
@@ -814,7 +814,9 @@ public abstract class WMShellModule {
ReturnToDragStartAnimator returnToDragStartAnimator,
@DynamicOverride DesktopUserRepositories desktopUserRepositories,
DesktopModeEventLogger desktopModeEventLogger,
- WindowDecorTaskResourceLoader windowDecorTaskResourceLoader) {
+ WindowDecorTaskResourceLoader windowDecorTaskResourceLoader,
+ FocusTransitionObserver focusTransitionObserver,
+ @ShellMainThread ShellExecutor mainExecutor) {
return new DesktopTilingDecorViewModel(
context,
mainDispatcher,
@@ -828,7 +830,9 @@ public abstract class WMShellModule {
returnToDragStartAnimator,
desktopUserRepositories,
desktopModeEventLogger,
- windowDecorTaskResourceLoader
+ windowDecorTaskResourceLoader,
+ focusTransitionObserver,
+ mainExecutor
);
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
index d72da3a08de5..8747f63e789f 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModel.kt
@@ -29,6 +29,7 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayChangeController
import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopTasksController
@@ -37,6 +38,7 @@ import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler
import com.android.wm.shell.shared.annotations.ShellBackgroundThread
import com.android.wm.shell.shared.annotations.ShellMainThread
+import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader
@@ -58,6 +60,8 @@ class DesktopTilingDecorViewModel(
private val desktopUserRepositories: DesktopUserRepositories,
private val desktopModeEventLogger: DesktopModeEventLogger,
private val taskResourceLoader: WindowDecorTaskResourceLoader,
+ private val focusTransitionObserver: FocusTransitionObserver,
+ private val mainExecutor: ShellExecutor,
) : DisplayChangeController.OnDisplayChangingListener {
@VisibleForTesting
var tilingTransitionHandlerByDisplayId = SparseArray<DesktopTilingWindowDecoration>()
@@ -94,6 +98,8 @@ class DesktopTilingDecorViewModel(
returnToDragStartAnimator,
desktopUserRepositories,
desktopModeEventLogger,
+ focusTransitionObserver,
+ mainExecutor,
)
tilingTransitionHandlerByDisplayId.put(displayId, newHandler)
newHandler
@@ -112,9 +118,10 @@ class DesktopTilingDecorViewModel(
}
fun moveTaskToFrontIfTiled(taskInfo: RunningTaskInfo): Boolean {
+ // Always pass focus=true because taskInfo.isFocused is not updated yet.
return tilingTransitionHandlerByDisplayId
.get(taskInfo.displayId)
- ?.moveTiledPairToFront(taskInfo, isTaskFocused = true) ?: false
+ ?.moveTiledPairToFront(taskInfo.taskId, isFocusedOnDisplay = true) ?: false
}
fun onOverviewAnimationStateChange(isRunning: Boolean) {
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
index 6f2323347468..666d4bd046dc 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt
@@ -35,11 +35,14 @@ import android.window.TransitionRequestInfo
import android.window.WindowContainerTransaction
import com.android.internal.annotations.VisibleForTesting
import com.android.launcher3.icons.BaseIconFactory
+import com.android.window.flags.Flags
+import com.android.wm.shell.shared.FocusTransitionListener
import com.android.wm.shell.R
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayLayout
+import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
@@ -49,6 +52,7 @@ import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler
import com.android.wm.shell.shared.annotations.ShellBackgroundThread
import com.android.wm.shell.shared.annotations.ShellMainThread
+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.windowdecor.DesktopModeWindowDecoration
@@ -78,13 +82,16 @@ class DesktopTilingWindowDecoration(
private val returnToDragStartAnimator: ReturnToDragStartAnimator,
private val desktopUserRepositories: DesktopUserRepositories,
private val desktopModeEventLogger: DesktopModeEventLogger,
+ private val focusTransitionObserver: FocusTransitionObserver,
+ @ShellMainThread private val mainExecutor: ShellExecutor,
private val transactionSupplier: Supplier<Transaction> = Supplier { Transaction() },
) :
Transitions.TransitionHandler,
ShellTaskOrganizer.FocusListener,
ShellTaskOrganizer.TaskVanishedListener,
DragEventListener,
- Transitions.TransitionObserver {
+ Transitions.TransitionObserver,
+ FocusTransitionListener {
companion object {
private val TAG: String = DesktopTilingWindowDecoration::class.java.simpleName
private const val TILING_DIVIDER_TAG = "Tiling Divider"
@@ -176,8 +183,13 @@ class DesktopTilingWindowDecoration(
if (!isTilingManagerInitialised) {
desktopTilingDividerWindowManager = initTilingManagerForDisplay(displayId, config)
isTilingManagerInitialised = true
- shellTaskOrganizer.addFocusListener(this)
- isTilingFocused = true
+
+ if (Flags.enableDisplayFocusInShellTransitions()) {
+ focusTransitionObserver.setLocalFocusTransitionListener(this, mainExecutor)
+ } else {
+ shellTaskOrganizer.addFocusListener(this)
+ isTilingFocused = true
+ }
}
leftTaskResizingHelper?.initIfNeeded()
rightTaskResizingHelper?.initIfNeeded()
@@ -474,23 +486,33 @@ class DesktopTilingWindowDecoration(
}
}
- // Only called if [taskInfo] relates to a focused task
- private fun isTilingFocusRemoved(taskInfo: RunningTaskInfo): Boolean {
+ // Only called if [taskId] relates to a focused task
+ private fun isTilingFocusRemoved(taskId: Int): Boolean {
return isTilingFocused &&
- taskInfo.taskId != leftTaskResizingHelper?.taskInfo?.taskId &&
- taskInfo.taskId != rightTaskResizingHelper?.taskInfo?.taskId
+ taskId != leftTaskResizingHelper?.taskInfo?.taskId &&
+ taskId != rightTaskResizingHelper?.taskInfo?.taskId
}
+ // Overriding ShellTaskOrganizer.FocusListener
override fun onFocusTaskChanged(taskInfo: RunningTaskInfo?) {
+ if (Flags.enableDisplayFocusInShellTransitions()) return
if (taskInfo != null) {
- moveTiledPairToFront(taskInfo)
+ moveTiledPairToFront(taskInfo.taskId, taskInfo.isFocused)
}
}
+ // Overriding FocusTransitionListener
+ override fun onFocusedTaskChanged(taskId: Int,
+ isFocusedOnDisplay: Boolean,
+ isFocusedGlobally: Boolean) {
+ if (!Flags.enableDisplayFocusInShellTransitions()) return
+ moveTiledPairToFront(taskId, isFocusedOnDisplay)
+ }
+
// Only called if [taskInfo] relates to a focused task
- private fun isTilingRefocused(taskInfo: RunningTaskInfo): Boolean {
- return taskInfo.taskId == leftTaskResizingHelper?.taskInfo?.taskId ||
- taskInfo.taskId == rightTaskResizingHelper?.taskInfo?.taskId
+ private fun isTilingRefocused(taskId: Int): Boolean {
+ return taskId == leftTaskResizingHelper?.taskInfo?.taskId ||
+ taskId == rightTaskResizingHelper?.taskInfo?.taskId
}
private fun buildTiledTasksMoveToFront(leftOnTop: Boolean): WindowContainerTransaction {
@@ -582,14 +604,13 @@ class DesktopTilingWindowDecoration(
* If specified, [isTaskFocused] will override [RunningTaskInfo.isFocused]. This is to be used
* when called when the task will be focused, but the [taskInfo] hasn't been updated yet.
*/
- fun moveTiledPairToFront(taskInfo: RunningTaskInfo, isTaskFocused: Boolean? = null): Boolean {
+ fun moveTiledPairToFront(taskId: Int, isFocusedOnDisplay: Boolean): Boolean {
if (!isTilingManagerInitialised) return false
- val isFocused = isTaskFocused ?: taskInfo.isFocused
- if (!isFocused) return false
+ if (!isFocusedOnDisplay) return false
// If a task that isn't tiled is being focused, let the generic handler do the work.
- if (isTilingFocusRemoved(taskInfo)) {
+ if (!Flags.enableDisplayFocusInShellTransitions() && isTilingFocusRemoved(taskId)) {
isTilingFocused = false
return false
}
@@ -597,31 +618,29 @@ class DesktopTilingWindowDecoration(
val leftTiledTask = leftTaskResizingHelper ?: return false
val rightTiledTask = rightTaskResizingHelper ?: return false
if (!allTiledTasksVisible()) return false
- val isLeftOnTop = taskInfo.taskId == leftTiledTask.taskInfo.taskId
- if (isTilingRefocused(taskInfo)) {
- val t = transactionSupplier.get()
- isTilingFocused = true
- if (taskInfo.taskId == leftTaskResizingHelper?.taskInfo?.taskId) {
- desktopTilingDividerWindowManager?.onRelativeLeashChanged(
- leftTiledTask.getLeash(),
- t,
- )
- }
- if (taskInfo.taskId == rightTaskResizingHelper?.taskInfo?.taskId) {
- desktopTilingDividerWindowManager?.onRelativeLeashChanged(
- rightTiledTask.getLeash(),
- t,
- )
- }
- transitions.startTransition(
- TRANSIT_TO_FRONT,
- buildTiledTasksMoveToFront(isLeftOnTop),
- null,
- )
- t.apply()
- return true
+ val isLeftOnTop = taskId == leftTiledTask.taskInfo.taskId
+ if (!isTilingRefocused(taskId)) return false
+ val t = transactionSupplier.get()
+ if (!Flags.enableDisplayFocusInShellTransitions()) isTilingFocused = true
+ if (taskId == leftTaskResizingHelper?.taskInfo?.taskId) {
+ desktopTilingDividerWindowManager?.onRelativeLeashChanged(
+ leftTiledTask.getLeash(),
+ t,
+ )
}
- return false
+ if (taskId == rightTaskResizingHelper?.taskInfo?.taskId) {
+ desktopTilingDividerWindowManager?.onRelativeLeashChanged(
+ rightTiledTask.getLeash(),
+ t,
+ )
+ }
+ transitions.startTransition(
+ TRANSIT_TO_FRONT,
+ buildTiledTasksMoveToFront(isLeftOnTop),
+ null,
+ )
+ t.apply()
+ return true
}
private fun allTiledTasksVisible(): Boolean {
@@ -706,7 +725,13 @@ class DesktopTilingWindowDecoration(
}
private fun tearDownTiling() {
- if (isTilingManagerInitialised) shellTaskOrganizer.removeFocusListener(this)
+ if (isTilingManagerInitialised) {
+ if (Flags.enableDisplayFocusInShellTransitions()) {
+ focusTransitionObserver.unsetLocalFocusTransitionListener(this)
+ } else {
+ shellTaskOrganizer.removeFocusListener(this)
+ }
+ }
if (leftTaskResizingHelper == null && rightTaskResizingHelper == null) {
shellTaskOrganizer.removeTaskVanishedListener(this)
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModelTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModelTest.kt
index 997ece6ecadc..2cabb9a33b86 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModelTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDecorViewModelTest.kt
@@ -23,6 +23,7 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.DisplayController
+import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopUserRepositories
@@ -30,6 +31,7 @@ import com.android.wm.shell.desktopmode.DesktopTasksController
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
import com.android.wm.shell.desktopmode.ToggleResizeDesktopTaskTransitionHandler
+import com.android.wm.shell.transition.FocusTransitionObserver
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader
@@ -67,6 +69,8 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
private val desktopModeWindowDecorationMock: DesktopModeWindowDecoration = mock()
private val desktopTilingDecoration: DesktopTilingWindowDecoration = mock()
private val taskResourceLoader: WindowDecorTaskResourceLoader = mock()
+ private val focusTransitionObserver: FocusTransitionObserver = mock()
+ private val mainExecutor: ShellExecutor = mock()
private lateinit var desktopTilingDecorViewModel: DesktopTilingDecorViewModel
@Before
@@ -86,6 +90,8 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
userRepositories,
desktopModeEventLogger,
taskResourceLoader,
+ focusTransitionObserver,
+ mainExecutor
)
whenever(contextMock.createContextAsUser(any(), any())).thenReturn(contextMock)
}
@@ -140,7 +146,7 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
desktopTilingDecorViewModel.moveTaskToFrontIfTiled(task1)
verify(desktopTilingDecoration, times(1))
- .moveTiledPairToFront(any(), isTaskFocused = eq(true))
+ .moveTiledPairToFront(any(), isFocusedOnDisplay = eq(true))
}
@Test
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt
index 2f15c2e38855..399a51e1ed08 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt
@@ -33,6 +33,7 @@ import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayLayout
+import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopModeEventLogger.Companion.ResizeTrigger
@@ -42,6 +43,7 @@ import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
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.transition.FocusTransitionObserver
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.windowdecor.DesktopModeWindowDecoration
import com.android.wm.shell.windowdecor.DragResizeWindowGeometry
@@ -105,6 +107,8 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
private val mainDispatcher: MainCoroutineDispatcher = mock()
private val bgScope: CoroutineScope = mock()
private val taskResourceLoader: WindowDecorTaskResourceLoader = mock()
+ private val focusTransitionObserver: FocusTransitionObserver = mock()
+ private val mainExecutor: ShellExecutor = mock()
private lateinit var tilingDecoration: DesktopTilingWindowDecoration
private val split_divider_width = 10
@@ -129,6 +133,8 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
returnToDragStartAnimator,
userRepositories,
desktopModeEventLogger,
+ focusTransitionObserver,
+ mainExecutor
)
whenever(context.createContextAsUser(any(), any())).thenReturn(context)
whenever(userRepositories.current).thenReturn(desktopRepository)
@@ -242,7 +248,7 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
BOUNDS,
)
- assertThat(tilingDecoration.moveTiledPairToFront(task2)).isFalse()
+ assertThat(tilingDecoration.moveTiledPairToFront(task2.taskId, false)).isFalse()
verify(transitions, never()).startTransition(any(), any(), any())
}
@@ -272,7 +278,7 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
BOUNDS,
)
- assertThat(tilingDecoration.moveTiledPairToFront(task3)).isFalse()
+ assertThat(tilingDecoration.moveTiledPairToFront(task3.taskId, false)).isFalse()
verify(transitions, never()).startTransition(any(), any(), any())
}
@@ -304,7 +310,7 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
)
task1.isFocused = true
- assertThat(tilingDecoration.moveTiledPairToFront(task1, isTaskFocused = true)).isTrue()
+ assertThat(tilingDecoration.moveTiledPairToFront(task1.taskId, isFocusedOnDisplay = true)).isTrue()
verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
}
@@ -336,8 +342,8 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
task1.isFocused = true
task3.isFocused = true
- assertThat(tilingDecoration.moveTiledPairToFront(task3)).isFalse()
- assertThat(tilingDecoration.moveTiledPairToFront(task1)).isTrue()
+ assertThat(tilingDecoration.moveTiledPairToFront(task3.taskId, true)).isFalse()
+ assertThat(tilingDecoration.moveTiledPairToFront(task1.taskId, true)).isTrue()
verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
}
@@ -367,8 +373,8 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
BOUNDS,
)
- assertThat(tilingDecoration.moveTiledPairToFront(task3, isTaskFocused = true)).isFalse()
- assertThat(tilingDecoration.moveTiledPairToFront(task1, isTaskFocused = true)).isTrue()
+ assertThat(tilingDecoration.moveTiledPairToFront(task3.taskId, isFocusedOnDisplay = true)).isFalse()
+ assertThat(tilingDecoration.moveTiledPairToFront(task1.taskId, isFocusedOnDisplay = true)).isTrue()
verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
}