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

Commit d7191844 authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Prevent WallpaperActivity from being added to repo

In some cases, DesktopWallpaperActivity is being launched in freeform.
To prevent the device from being unusable when that happens, prevent
adding it to the DesktopRepository. This CL should be reverted when the
root cause for the above is found and fixed.

Bug: 420917959
Test: atest DesktopTaskChangeListener
Flag: com.android.window.flags.enable_windowing_transition_handlers_observers
Change-Id: Id81587baefa426b6a05ad849f36d991c7f0669ec
parent d987f495
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -46,6 +46,14 @@ class DesktopTaskChangeListener(
            return
        }
        if (isFreeformTask(taskInfo) && !desktopRepository.isActiveTask(taskInfo.taskId)) {
            // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for
            // [DesktopWallpaperActivity] launch which should always be in fullscreen.
            if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) {
                logE(
                    "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead"
                )
                return
            }
            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
        }
    }
@@ -72,6 +80,14 @@ class DesktopTaskChangeListener(
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.taskId)
        } else if (isFreeformTask(taskInfo)) {
            // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for
            // [DesktopWallpaperActivity] launch which should always be in fullscreen.
            if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) {
                logE(
                    "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead"
                )
                return
            }
            // If the task is already active in the repository, then moves task to the front,
            // else adds the task.
            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
@@ -108,6 +124,14 @@ class DesktopTaskChangeListener(
            desktopRepository.removeTask(taskInfo.taskId)
        }
        if (isFreeformTask(taskInfo)) {
            // TODO: b/420917959 - Remove this once LaunchParams respects activity options set for
            // [DesktopWallpaperActivity] launch which should always be in fullscreen.
            if (DesktopWallpaperActivity.isWallpaperTask(taskInfo)) {
                logE(
                    "Trying to add freeform DesktopWallpaperActivity to DesktopRepository, returning early instead"
                )
                return
            }
            // If the task is already active in the repository, then it only moves the task to the
            // front.
            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
@@ -165,6 +189,10 @@ class DesktopTaskChangeListener(
        ProtoLog.d(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 = "DesktopTaskChangeListener"
    }
+50 −0
Original line number Diff line number Diff line
@@ -16,13 +16,18 @@

package com.android.wm.shell.desktopmode

import android.app.ActivityManager.RunningTaskInfo
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.content.Intent
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION
import com.android.window.flags.Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND
import com.android.wm.shell.MockToken
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestRunningTaskInfoBuilder
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFreeformTask
import com.android.wm.shell.desktopmode.DesktopTestHelpers.createFullscreenTask
import com.android.wm.shell.shared.desktopmode.FakeDesktopState
@@ -119,6 +124,22 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
        verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskOpening_freeformWallpaperActivityTask_noop() {
        val freeformWallpaperActivity = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM)
        whenever(desktopUserRepositories.current.isActiveTask(freeformWallpaperActivity.taskId))
            .thenReturn(false)

        desktopTaskChangeListener.onTaskOpening(freeformWallpaperActivity)

        verify(desktopUserRepositories.current, never())
            .addTask(
                freeformWallpaperActivity.displayId,
                freeformWallpaperActivity.taskId,
                freeformWallpaperActivity.isVisible,
            )
    }

    @Test
    @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onTaskOpening_desktopModeNotSupportedInDisplay_noOp() {
@@ -160,6 +181,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
        verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskChanging_freeformWallpaperActivityTask_noop() {
        val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM)

        desktopTaskChangeListener.onTaskChanging(task)

        verify(desktopUserRepositories.current, never())
            .addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onTaskChanging_desktopModeNotSupportedInDisplay_noOp() {
@@ -200,6 +231,16 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
        verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskMovingToFront_freeformWallpaperActivityTask_noop() {
        val task = createWallpaperTaskInfo(WINDOWING_MODE_FREEFORM)

        desktopTaskChangeListener.onTaskMovingToFront(task)

        verify(desktopUserRepositories.current, never())
            .addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    @EnableFlags(FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onTaskMovingToFront_desktopModeNotSupportedInDisplay_noOp() {
@@ -314,6 +355,15 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
        verify(desktopUserRepositories.current, never()).removeTask(task.taskId)
    }

    private fun createWallpaperTaskInfo(windowingMode: Int): RunningTaskInfo =
        TestRunningTaskInfoBuilder()
            .setBaseIntent(
                Intent().apply { component = DesktopWallpaperActivity.wallpaperActivityComponent }
            )
            .setToken(MockToken().token())
            .setWindowingMode(windowingMode)
            .build()

    companion object {
        private const val UNSUPPORTED_DISPLAY_ID = 3
    }