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

Commit d03a47b1 authored by Evan Rosky's avatar Evan Rosky
Browse files

Separate task-view management out of taskview impl [1/N]

Start of separating taskview control functionality out
of TaskView impl.

There are a number of calls in TaskView where the taskview
is asking a "higher-level" to perform a general management
operation on it (eg. "please resize me" or "please close me"
in a transition). In practice, though, its the "higher-level"
that is asking the taskview to do this, so we end up with a
sorta inside-out logic where the outer controller asks the
taskview to do something which then just goes back to the
controller to ask it to do the thing.

This means that some of the overall taskview control is
implemented within the TaskView, itself. As a result, we
can't substitute the taskview control implementation for
different use-cases (eg. bubbles vs auto) which we need
in order to support transitions tailored to each interaction.

To remedy this, the plan is to "lift" the taskview control
functionality into an interface that can have different
implementations. The refactor is mechanical, but will be
separated into a few CLs to make it easier to see that it
is mechanical.

The mechanical operations in this CL are:
- verbatim move calls like startActivity from TaskViewTaskController
  to TaskViewTransitions
- Have TaskView call the moved calls on TaskViewTransitions instead.
- BubbleController makes its own instance of TaskViewTransitions
  when shared repository is enabled (behind flag).
- Removed some unused functions

Bug: 384976265
Test: refactor only, so existing tests
Flag: EXEMPT mechanical refactor
Change-Id: I31951b20a3c6b618620e0eb110ba94d6bb2bbd18
parent 78fd834f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.wm.shell.shared.bubbles.BubbleBarUpdate
import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.taskview.TaskViewRepository
import com.android.wm.shell.taskview.TaskViewTransitions
import com.android.wm.shell.transition.Transitions
import com.google.common.truth.Truth.assertThat
@@ -282,6 +283,7 @@ class BubbleControllerBubbleBarTest {
            mainExecutor,
            mock<Handler>(),
            bgExecutor,
            mock<TaskViewRepository>(),
            mock<TaskViewTransitions>(),
            mock<Transitions>(),
            SyncTransactionQueue(TransactionPool(), mainExecutor),
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.wm.shell.sysui.ShellCommandHandler
import com.android.wm.shell.sysui.ShellController
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewRepository
import com.android.wm.shell.taskview.TaskViewTransitions
import com.android.wm.shell.transition.Transitions
import com.google.common.truth.Truth.assertThat
@@ -155,6 +156,7 @@ class BubbleViewInfoTaskTest {
                mainExecutor,
                mock<Handler>(),
                bgExecutor,
                mock<TaskViewRepository>(),
                mock<TaskViewTransitions>(),
                mock<Transitions>(),
                SyncTransactionQueue(TransactionPool(), mainExecutor),
+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewTaskController
import com.android.wm.shell.taskview.TaskViewTransitions
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

@@ -32,8 +33,9 @@ class FakeBubbleTaskViewFactory(
    private val mainExecutor: ShellExecutor,
) : BubbleTaskViewFactory {
    override fun create(): BubbleTaskView {
        val taskViewTransitions = mock<TaskViewTransitions>()
        val taskViewTaskController = mock<TaskViewTaskController>()
        val taskView = TaskView(context, taskViewTaskController)
        val taskView = TaskView(context, taskViewTransitions, taskViewTaskController)
        val taskInfo = mock<ActivityManager.RunningTaskInfo>()
        whenever(taskViewTaskController.taskInfo).thenReturn(taskInfo)
        return BubbleTaskView(taskView, mainExecutor)
+14 −8
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.wm.shell.bubbles.FakeBubbleExpandedViewManager
import com.android.wm.shell.bubbles.FakeBubbleFactory
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewTaskController
import com.android.wm.shell.taskview.TaskViewTransitions
import com.google.common.truth.Truth.assertThat
import java.util.concurrent.Semaphore
import java.util.concurrent.TimeUnit
@@ -58,6 +59,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
@@ -165,7 +167,9 @@ class BubbleBarAnimationHelperTest {
    fun animateSwitch_bubbleToBubble_updateTaskBounds() {
        val fromBubble = createBubble("from").initialize(container)
        val toBubbleTaskController = mock<TaskViewTaskController>()
        val toBubble = createBubble("to", toBubbleTaskController).initialize(container)
        val taskTransitions = mock<TaskViewTransitions>()
        val toBubble = createBubble("to", taskTransitions, toBubbleTaskController).initialize(
            container)

        activityScenario.onActivity {
            animationHelper.animateSwitch(fromBubble, toBubble) {}
@@ -174,11 +178,11 @@ class BubbleBarAnimationHelperTest {
        }
        getInstrumentation().waitForIdleSync()
        // Clear invocations to ensure that bounds update happens after animation ends
        clearInvocations(toBubbleTaskController)
        clearInvocations(taskTransitions)
        getInstrumentation().runOnMainSync { animatorTestRule.advanceTimeBy(900) }
        getInstrumentation().waitForIdleSync()

        verify(toBubbleTaskController).setWindowBounds(any())
        verify(taskTransitions).setTaskBounds(eq(toBubbleTaskController), any())
    }

    @Test
@@ -229,8 +233,9 @@ class BubbleBarAnimationHelperTest {

    @Test
    fun animateToRestPosition_updateTaskBounds() {
        val taskController = mock<TaskViewTaskController>()
        val bubble = createBubble("key", taskController).initialize(container)
        val taskView = mock<TaskViewTaskController>()
        val tvTransitions = mock<TaskViewTransitions>()
        val bubble = createBubble("key", tvTransitions, taskView).initialize(container)

        val semaphore = Semaphore(0)
        val after = Runnable { semaphore.release() }
@@ -247,11 +252,11 @@ class BubbleBarAnimationHelperTest {
            animatorTestRule.advanceTimeBy(100)
        }
        // Clear invocations to ensure that bounds update happens after animation ends
        clearInvocations(taskController)
        clearInvocations(tvTransitions)
        getInstrumentation().runOnMainSync { animatorTestRule.advanceTimeBy(900) }
        getInstrumentation().waitForIdleSync()

        verify(taskController).setWindowBounds(any())
        verify(tvTransitions).setTaskBounds(eq(taskView), any())
    }

    @Test
@@ -329,9 +334,10 @@ class BubbleBarAnimationHelperTest {

    private fun createBubble(
        key: String,
        taskViewTransitions: TaskViewTransitions = mock<TaskViewTransitions>(),
        taskViewTaskController: TaskViewTaskController = mock<TaskViewTaskController>(),
    ): Bubble {
        val taskView = TaskView(context, taskViewTaskController)
        val taskView = TaskView(context, taskViewTransitions, taskViewTaskController)
        val taskInfo = mock<ActivityManager.RunningTaskInfo>()
        whenever(taskViewTaskController.taskInfo).thenReturn(taskInfo)
        val bubbleTaskView = BubbleTaskView(taskView, mainExecutor)
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.wm.shell.bubbles.UiEventSubject.Companion.assertThat
import com.android.wm.shell.shared.handles.RegionSamplingHelper
import com.android.wm.shell.taskview.TaskView
import com.android.wm.shell.taskview.TaskViewTaskController
import com.android.wm.shell.taskview.TaskViewTransitions
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import com.google.common.util.concurrent.MoreExecutors.directExecutor
@@ -356,7 +357,7 @@ class BubbleBarExpandedViewTest {
    private inner class FakeBubbleTaskViewFactory : BubbleTaskViewFactory {
        override fun create(): BubbleTaskView {
            val taskViewTaskController = mock<TaskViewTaskController>()
            val taskView = TaskView(context, taskViewTaskController)
            val taskView = TaskView(context, mock<TaskViewTransitions>(), taskViewTaskController)
            val taskInfo = mock<ActivityManager.RunningTaskInfo>()
            whenever(taskViewTaskController.taskInfo).thenReturn(taskInfo)
            return BubbleTaskView(taskView, mainExecutor)
Loading