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

Commit f89994d1 authored by Massimo Carli's avatar Massimo Carli
Browse files

[74/n] Add configuration to LetterboxTaskInfoRepository

The Configuration from the TaskInfo is necessary for the
Rounded Corners View creation. The rounded corners Views
are created when the letterbox surfaces are created and
the TransitionObserver needs the Configuration from the
TaskInfo before the same is available in the
LetterboxTaskListenerAdapter. For this reason the
TaskInfoLetterboxLifecycleEventFactory now depends on the
LetterboxTaskInfoRepository and stores the Configuration.

Flag: EXEMPT Refactoring
Bug: 375124280
Test: atest WMShellUnitTests:LetterboxTaskListenerAdapterTest
Test: atest WMShellUnitTests:TaskInfoLetterboxLifecycleEventFactoryTest
Test: atest WMShellUnitTests:ActivityLetterboxLifecycleEventFactoryTest
Test: atest WMShellUnitTests:LetterboxTaskListenerAdapterTest

Change-Id: I3006d57e963a9cb1f5c112d83b718e354963007c
parent 74322386
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.window.TransitionInfo.Change
import com.android.window.flags.Flags
import com.android.wm.shell.compatui.letterbox.config.LetterboxDependenciesHelper
import com.android.wm.shell.compatui.letterbox.state.LetterboxTaskInfoRepository
import com.android.wm.shell.compatui.letterbox.state.updateConfiguration
import com.android.wm.shell.compatui.letterbox.state.updateTaskLeafState

/**
@@ -49,6 +50,14 @@ class TaskInfoLetterboxLifecycleEventFactory(
                    Rect(absBounds).apply { offset(-taskBoundsAbs.left, -taskBoundsAbs.top) }
                }
            val shouldSupportInput = letterboxDependenciesHelper.shouldSupportInputSurface(change)
            if (Flags.appCompatRefactoringRoundedCorners()) {
                // Sometimes the [TransitionObserver] is notified before than the
                // [TaskAppearedListener] and the related information (e.g. [Configuration])
                // are required soon. This is the case, for instance, of rounded corners
                // implementation which require the [Configuration] when the related surfaces
                // are created.
                letterboxTaskInfoRepository.updateConfiguration(ti, change.leash)
            }
            if (Flags.appCompatRefactoringFixMultiwindowTaskHierarchy()) {
                // Because the [TransitionObserver] is invoked before the [OnTaskAppearedListener]s
                // it's important to store the information about the Task to be reused below for the
+16 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.compatui.letterbox.state

import android.app.ActivityManager.RunningTaskInfo
import android.app.ActivityTaskManager
import android.content.res.Configuration
import android.view.SurfaceControl
import android.window.WindowContainerToken
import com.android.internal.protolog.ProtoLog
@@ -30,10 +31,11 @@ import javax.inject.Inject

/** Encapsulate the [TaskInfo] information useful for letterboxing in shell. */
data class LetterboxTaskInfoState(
    val containerToken: WindowContainerToken,
    val containerToken: WindowContainerToken? = null,
    val containerLeash: SurfaceControl,
    val taskId: Int = ActivityTaskManager.INVALID_TASK_ID,
    val parentTaskId: Int = ActivityTaskManager.INVALID_TASK_ID,
    val configuration: Configuration,
)

/**
@@ -65,6 +67,7 @@ fun LetterboxTaskInfoRepository.updateTaskLeafState(
                    containerLeash = leash,
                    parentTaskId = taskInfo.parentTaskId,
                    taskId = taskInfo.taskId,
                    configuration = taskInfo.configuration,
                ),
            overrideIfPresent = true,
        )
@@ -72,3 +75,15 @@ fun LetterboxTaskInfoRepository.updateTaskLeafState(
        delete(taskInfo.taskId)
    }
}

/** Updates the configuration given the [TaskInfo] and the leash. */
fun LetterboxTaskInfoRepository.updateConfiguration(
    taskInfo: RunningTaskInfo,
    leash: SurfaceControl,
) {
    insert(
        taskInfo.taskId,
        LetterboxTaskInfoState(taskInfo.token, leash, configuration = taskInfo.configuration),
        overrideIfPresent = true,
    )
}
+16 −6
Original line number Diff line number Diff line
@@ -47,9 +47,7 @@ constructor(
                {
                    shellTaskOrganizer.addTaskAppearedListener(this)
                    shellTaskOrganizer.addTaskVanishedListener(this)
                    if (Flags.appCompatRefactoringFixMultiwindowTaskHierarchy()) {
                    shellTaskOrganizer.addTaskInfoChangedListener(this)
                    }
                },
                this,
            )
@@ -63,17 +61,29 @@ constructor(
            letterboxTaskInfoRepository.insert(
                key = taskInfo.taskId,
                item =
                    LetterboxTaskInfoState(containerToken = taskInfo.token, containerLeash = leash),
                    LetterboxTaskInfoState(
                        containerToken = taskInfo.token,
                        containerLeash = leash,
                        configuration = taskInfo.configuration,
                    ),
                overrideIfPresent = true,
            )
        }
    }

    override fun onTaskInfoChanged(taskInfo: RunningTaskInfo) {
        if (Flags.appCompatRefactoringFixMultiwindowTaskHierarchy()) {
            if (!taskInfo.isALeafTask) {
                letterboxTaskInfoRepository.delete(taskInfo.taskId)
            }
        }
        if (Flags.appCompatRefactoringRoundedCorners()) {
            letterboxTaskInfoRepository.update(
                key = taskInfo.taskId,
                updateItem = { item -> item.copy(configuration = taskInfo.configuration) },
            )
        }
    }

    override fun onTaskVanished(taskInfo: RunningTaskInfo) {
        letterboxTaskInfoRepository.delete(taskInfo.taskId)
+17 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.compatui.letterbox.lifecycle

import android.content.res.Configuration
import android.graphics.Rect
import android.testing.AndroidTestingRunner
import android.view.SurfaceControl
@@ -74,7 +75,10 @@ class ActivityLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    }
                    endAbsBounds = Rect(100, 50, 2000, 1500)
                }
                r.addToTaskRepository(10, LetterboxTaskInfoState(testToken, testLeash))
                r.addToTaskRepository(
                    10,
                    LetterboxTaskInfoState(testToken, testLeash, configuration = Configuration())
                )
                validateCanHandle { canHandle ->
                    assertTrue(canHandle)
                }
@@ -100,7 +104,10 @@ class ActivityLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                        }
                    }
                }
                r.addToTaskRepository(10, LetterboxTaskInfoState(testToken, testLeash))
                r.addToTaskRepository(
                    10,
                    LetterboxTaskInfoState(testToken, testLeash, configuration = Configuration())
                )
                validateCanHandle { canHandle ->
                    assertTrue(canHandle)
                }
@@ -118,7 +125,10 @@ class ActivityLetterboxLifecycleEventFactoryTest : ShellTestCase() {
            testLetterboxLifecycleEventFactory(r.getLetterboxLifecycleEventFactory()) {
                val testLeash = mock<SurfaceControl>()
                val testToken = mock<WindowContainerToken>()
                r.addToTaskRepository(10, LetterboxTaskInfoState(testToken, testLeash))
                r.addToTaskRepository(
                    10,
                    LetterboxTaskInfoState(testToken, testLeash, configuration = Configuration())
                )
                inputChange {
                    activityTransitionInfo {
                        taskId = 10
@@ -146,7 +156,10 @@ class ActivityLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                }
                val testLeash = mock<SurfaceControl>()
                val testToken = mock<WindowContainerToken>()
                r.addToTaskRepository(10, LetterboxTaskInfoState(testToken, testLeash))
                r.addToTaskRepository(
                    10,
                    LetterboxTaskInfoState(testToken, testLeash, configuration = Configuration())
                )
                r.shouldSupportInputSurface(shouldSupportInputSurface = true)
                validateCreateLifecycleEvent { event ->
                    assertNotNull(event)
+6 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.compatui.letterbox.lifecycle

import android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW
import android.content.res.Configuration
import android.testing.AndroidTestingRunner
import android.view.SurfaceControl
import android.window.WindowContainerToken
@@ -126,6 +127,9 @@ class TaskIdResolverTest : ShellTestCase() {

            @JvmStatic
            val TEST_LEASH = mock<SurfaceControl>()

            @JvmStatic
            val TEST_CONFIGURATION = Configuration()
        }

        private val letterboxTaskInfoRepository: LetterboxTaskInfoRepository =
@@ -145,7 +149,8 @@ class TaskIdResolverTest : ShellTestCase() {
                containerToken = TEST_TOKEN,
                containerLeash = TEST_LEASH,
                taskId = taskId,
                parentTaskId = parentTaskId
                parentTaskId = parentTaskId,
                configuration = TEST_CONFIGURATION
            )
    }
}
Loading