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

Commit 05cafef1 authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Find and remove visible task onTaskVanished.

When a task vanishes, its displayId is set to INVALID_DISPLAY. Find the
display that we put the task in as visible and remove it from the
visibleTasks list.

Bug: 323162330
Test: atest DesktopModeTaskRepositoryTest
Change-Id: Ib036ae0eea4754fd5071d92fba74f1d98f5fcbcb
parent 28020faf
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.Region
import android.util.ArrayMap
import android.util.ArraySet
import android.util.SparseArray
import android.view.Display.INVALID_DISPLAY
import androidx.core.util.forEach
import androidx.core.util.keyIterator
import androidx.core.util.valueIterator
@@ -226,6 +227,14 @@ class DesktopModeTaskRepository {
                        displayData[otherDisplayId].visibleTasks.size)
                }
            }
        } else if (displayId == INVALID_DISPLAY) {
            // Task has vanished. Check which display to remove the task from.
            displayData.forEach { displayId, data ->
                if (data.visibleTasks.remove(taskId)) {
                    notifyVisibleTaskListeners(displayId, data.visibleTasks.size)
                }
            }
            return
        }

        val prevCount = getVisibleTaskCount(displayId)
@@ -236,6 +245,7 @@ class DesktopModeTaskRepository {
        }
        val newCount = getVisibleTaskCount(displayId)

        // Check if count changed
        if (prevCount != newCount) {
            KtProtoLog.d(
                WM_SHELL_DESKTOP_MODE,
@@ -244,10 +254,6 @@ class DesktopModeTaskRepository {
                visible,
                displayId
            )
        }

        // Check if count changed
        if (prevCount != newCount) {
            KtProtoLog.d(
                WM_SHELL_DESKTOP_MODE,
                "DesktopTaskRepo: visibleTaskCount has changed from %d to %d",
+22 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.desktopmode

import android.testing.AndroidTestingRunner
import android.view.Display.DEFAULT_DISPLAY
import android.view.Display.INVALID_DISPLAY
import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestShellExecutor
@@ -237,6 +238,27 @@ class DesktopModeTaskRepositoryTest : ShellTestCase() {
        assertThat(listener.visibleChangesOnDefaultDisplay).isEqualTo(4)
    }

    /**
     * When a task vanishes, the displayId of the task is set to INVALID_DISPLAY.
     * This tests that task is removed from the last parent display when it vanishes.
     */
    @Test
    fun updateVisibleFreeformTasks_removeVisibleTasksRemovesTaskWithInvalidDisplay() {
        val listener = TestVisibilityListener()
        val executor = TestShellExecutor()
        repo.addVisibleTasksListener(listener, executor)
        repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 1, visible = true)
        repo.updateVisibleFreeformTasks(DEFAULT_DISPLAY, taskId = 2, visible = true)
        executor.flushAll()

        assertThat(listener.visibleTasksCountOnDefaultDisplay).isEqualTo(2)
        repo.updateVisibleFreeformTasks(INVALID_DISPLAY, taskId = 1, visible = false)
        executor.flushAll()

        assertThat(listener.visibleChangesOnDefaultDisplay).isEqualTo(3)
        assertThat(listener.visibleTasksCountOnDefaultDisplay).isEqualTo(1)
    }

    @Test
    fun getVisibleTaskCount() {
        // No tasks, count is 0