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

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

[45/n] Integrate LetterboxLifecycleEventFactory

Integrate LetterboxLifecycleEventFactory in LetterboxTransitionObserver
to detect what LetterboxLifecycleEvent to generate from a Change.

Flag: com.android.window.flags.app_compat_refactoring
Bug: 409043134
Test: atest WMShellUnitTests:MigrationLetterboxTransitionObserverTest
Test: atest WMShellUnitTests:DelegateLetterboxTransitionObserverTest

Change-Id: Ie8c2037ce8c8520c9bbb1a8df0bf0575806e8e68
parent aacb0c90
Loading
Loading
Loading
Loading
+12 −7
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.window.TransitionInfo
import com.android.internal.protolog.ProtoLog
import com.android.window.flags.Flags.appCompatRefactoring
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleController
import com.android.wm.shell.compatui.letterbox.lifecycle.toLetterboxLifecycleEvent
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleEventFactory
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_APP_COMPAT
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
@@ -35,6 +35,7 @@ class DelegateLetterboxTransitionObserver(
    shellInit: ShellInit,
    private val transitions: Transitions,
    private val letterboxLifecycleController: LetterboxLifecycleController,
    private val letterboxLifecycleEventFactory: LetterboxLifecycleEventFactory
) : Transitions.TransitionObserver {

    companion object {
@@ -57,14 +58,18 @@ class DelegateLetterboxTransitionObserver(
        startTransaction: SurfaceControl.Transaction,
        finishTransaction: SurfaceControl.Transaction
    ) {
        info.changes.forEach {
        info.changes.forEach { change ->
            if (letterboxLifecycleEventFactory.canHandle(change)) {
                letterboxLifecycleEventFactory.createLifecycleEvent(change)?.let { event ->
                    letterboxLifecycleController.onLetterboxLifecycleEvent(
                it.toLetterboxLifecycleEvent(),
                        event,
                        startTransaction,
                        finishTransaction
                    )
                }
            }
        }
    }

    private fun logV(msg: String) {
        ProtoLog.v(WM_SHELL_APP_COMPAT, "%s: %s", TAG, msg)
+16 −2
Original line number Diff line number Diff line
@@ -24,12 +24,17 @@ import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy;
import com.android.wm.shell.compatui.letterbox.MixedLetterboxController;
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleController;
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleControllerImpl;
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleEventFactory;
import com.android.wm.shell.compatui.letterbox.lifecycle.MultiLetterboxLifecycleEventFactory;
import com.android.wm.shell.compatui.letterbox.lifecycle.TaskInfoLetterboxLifecycleEventFactory;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

import dagger.Module;
import dagger.Provides;

import java.util.List;

/**
 * Provides Letterbox Shell implementation components to Dagger dependency Graph.
 */
@@ -41,10 +46,19 @@ public abstract class LetterboxModule {
    static DelegateLetterboxTransitionObserver provideDelegateLetterboxTransitionObserver(
            @NonNull ShellInit shellInit,
            @NonNull Transitions transitions,
            @NonNull LetterboxLifecycleController letterboxLifecycleController
            @NonNull LetterboxLifecycleController letterboxLifecycleController,
            @NonNull LetterboxLifecycleEventFactory letterboxLifecycleEventFactory
    ) {
        return new DelegateLetterboxTransitionObserver(shellInit, transitions,
                letterboxLifecycleController);
                letterboxLifecycleController, letterboxLifecycleEventFactory);
    }

    @WMSingleton
    @Provides
    static LetterboxLifecycleEventFactory provideLetterboxLifecycleEventFactory() {
        return new MultiLetterboxLifecycleEventFactory(List.of(
                new TaskInfoLetterboxLifecycleEventFactory()
        ));
    }

    @WMSingleton
+17 −1
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ import androidx.test.filters.SmallTest
import com.android.window.flags.Flags
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.compatui.letterbox.lifecycle.FakeLetterboxLifecycleEventFactory
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleController
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleEvent
import com.android.wm.shell.compatui.letterbox.lifecycle.toLetterboxLifecycleEvent
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.util.executeTransitionObserverTest
@@ -119,6 +121,9 @@ class DelegateLetterboxTransitionObserverTest : ShellTestCase() {

                validateOutput {
                    r.checkLifecycleControllerInvoked(times = 3)
                    r.checkOnLetterboxLifecycleEventFactory { factory ->
                        assert(factory.canHandleInvokeTimes == 3)
                    }
                }
            }
        }
@@ -139,6 +144,7 @@ class DelegateLetterboxTransitionObserverTest : ShellTestCase() {
        private val transitions: Transitions
        private val letterboxObserver: DelegateLetterboxTransitionObserver
        private val letterboxLifecycleController: LetterboxLifecycleController
        private var letterboxLifecycleEventFactory: FakeLetterboxLifecycleEventFactory

        val observerFactory: () -> DelegateLetterboxTransitionObserver

@@ -147,11 +153,15 @@ class DelegateLetterboxTransitionObserverTest : ShellTestCase() {
            shellInit = ShellInit(executor)
            transitions = mock<Transitions>()
            letterboxLifecycleController = mock<LetterboxLifecycleController>()
            letterboxLifecycleEventFactory = FakeLetterboxLifecycleEventFactory(
                eventToReturnFactory = { c -> c.toLetterboxLifecycleEvent() }
            )
            letterboxObserver =
                DelegateLetterboxTransitionObserver(
                    shellInit,
                    transitions,
                    letterboxLifecycleController
                    letterboxLifecycleController,
                    letterboxLifecycleEventFactory
                )
            observerFactory = { letterboxObserver }
        }
@@ -164,6 +174,12 @@ class DelegateLetterboxTransitionObserverTest : ShellTestCase() {
            verify(transitions, expected.asMode()).registerObserver(observer())
        }

        fun checkOnLetterboxLifecycleEventFactory(
            consumer: (FakeLetterboxLifecycleEventFactory) -> Unit
        ) {
            consumer(letterboxLifecycleEventFactory)
        }

        fun checkLifecycleControllerInvoked(
            times: Int = 1,
        ) = verify(
+17 −1
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@ import com.android.window.flags.Flags
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.transition.TransitionStateHolder
import com.android.wm.shell.compatui.letterbox.lifecycle.FakeLetterboxLifecycleEventFactory
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleController
import com.android.wm.shell.compatui.letterbox.lifecycle.LetterboxLifecycleControllerImpl
import com.android.wm.shell.compatui.letterbox.lifecycle.toLetterboxLifecycleEvent
import com.android.wm.shell.recents.RecentsTransitionHandler
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
@@ -97,6 +99,9 @@ class MigrationLetterboxTransitionObserverTest : ShellTestCase() {
                    r.visibilityEventDetected(expected = false)
                    r.destroyEventDetected(expected = false)
                    r.updateSurfaceBoundsEventDetected(expected = false)
                    r.checkOnLetterboxLifecycleEventFactory { factory ->
                        assert(factory.canHandleInvokeTimes == 3)
                    }
                }
            }
        }
@@ -220,6 +225,7 @@ class MigrationLetterboxTransitionObserverTest : ShellTestCase() {
        private val transitionStateHolder: TransitionStateHolder
        private val letterboxStrategy: LetterboxControllerStrategy
        private val letterboxLifecycleContoller: LetterboxLifecycleController
        private var letterboxLifecycleEventFactory: FakeLetterboxLifecycleEventFactory

        val observerFactory: () -> DelegateLetterboxTransitionObserver

@@ -237,11 +243,15 @@ class MigrationLetterboxTransitionObserverTest : ShellTestCase() {
                transitionStateHolder,
                letterboxStrategy
            )
            letterboxLifecycleEventFactory = FakeLetterboxLifecycleEventFactory(
                eventToReturnFactory = { c -> c.toLetterboxLifecycleEvent() }
            )
            letterboxObserver =
                DelegateLetterboxTransitionObserver(
                    shellInit,
                    transitions,
                    letterboxLifecycleContoller
                    letterboxLifecycleContoller,
                    letterboxLifecycleEventFactory
                )
            observerFactory = { letterboxObserver }
        }
@@ -254,6 +264,12 @@ class MigrationLetterboxTransitionObserverTest : ShellTestCase() {
            verify(transitions, expected.asMode()).registerObserver(observer())
        }

        fun checkOnLetterboxLifecycleEventFactory(
            consumer: (FakeLetterboxLifecycleEventFactory) -> Unit
        ) {
            consumer(letterboxLifecycleEventFactory)
        }

        fun configureRecentsState(running: Boolean) {
            doReturn(running).`when`(transitionStateHolder).isRecentsTransitionRunning()
        }
+3 −2
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ import android.window.TransitionInfo.Change
 */
class FakeLetterboxLifecycleEventFactory(
    private val canHandleReturn: Boolean = true,
    private val eventToReturn: LetterboxLifecycleEvent? = null
    private val eventToReturn: LetterboxLifecycleEvent? = null,
    private val eventToReturnFactory: (Change) -> LetterboxLifecycleEvent? = { eventToReturn }
) : LetterboxLifecycleEventFactory {

    companion object {
@@ -46,6 +47,6 @@ class FakeLetterboxLifecycleEventFactory(
    override fun createLifecycleEvent(change: Change): LetterboxLifecycleEvent? {
        createLifecycleEventInvokeTimes++
        lastCreateLifecycleEventChange = change
        return eventToReturn
        return eventToReturnFactory(change)
    }
}