Update listeners of stashed state after add

When a VisibleTasksListener is added to DesktopModeTaskRepository, send
an update with the current stashed value.
This is in addition to the update on visibility.

Launcher will start using the visibility listener for updating its
state. Remove the TODO for it.

Test: atest DesktopModeTaskRepositoryTest
Bug: 280490493
Change-Id: I9d6638a73283f5121599384b80ea84f671bb884b
This commit is contained in:
Ats Jenk
2023-06-01 17:22:59 -07:00
parent 5c8ee219f2
commit 676aaab6c7
3 changed files with 23 additions and 4 deletions

View File

@@ -86,8 +86,10 @@ class DesktopModeTaskRepository {
visibleTasksListeners[visibleTasksListener] = executor
displayData.keyIterator().forEach { displayId ->
val visibleTasks = getVisibleTaskCount(displayId)
val stashed = isStashed(displayId)
executor.execute {
visibleTasksListener.onVisibilityChanged(displayId, visibleTasks > 0)
visibleTasksListener.onStashedChanged(displayId, stashed)
}
}
}

View File

@@ -742,16 +742,21 @@ class DesktopTasksController(
private val listener: VisibleTasksListener = object : VisibleTasksListener {
override fun onVisibilityChanged(displayId: Int, visible: Boolean) {
// TODO(b/261234402): move visibility from sysui state to listener
KtProtoLog.v(
WM_SHELL_DESKTOP_MODE,
"IDesktopModeImpl: onVisibilityChanged display=%d visible=%b",
displayId,
visible
)
remoteListener.call { l -> l.onVisibilityChanged(displayId, visible) }
}
override fun onStashedChanged(displayId: Int, stashed: Boolean) {
KtProtoLog.v(
WM_SHELL_DESKTOP_MODE,
"IDesktopModeImpl: onStashedChanged stashed=%b display=%d",
stashed,
displayId
"IDesktopModeImpl: onStashedChanged display=%d stashed=%b",
displayId,
stashed
)
remoteListener.call { l -> l.onStashedChanged(displayId, stashed) }
}

View File

@@ -128,6 +128,18 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
assertThat(listener.visibleChangesOnDefaultDisplay).isEqualTo(1)
}
@Test
fun addListener_notifiesStashed() {
repo.setStashed(DEFAULT_DISPLAY, true)
val listener = TestVisibilityListener()
val executor = TestShellExecutor()
repo.addVisibleTasksListener(listener, executor)
executor.flushAll()
assertThat(listener.stashedOnDefaultDisplay).isTrue()
assertThat(listener.stashedChangesOnDefaultDisplay).isEqualTo(1)
}
@Test
fun addListener_tasksOnDifferentDisplay_doesNotNotify() {
repo.updateVisibleFreeformTasks(SECOND_DISPLAY, taskId = 1, visible = true)