diff options
author | 2025-03-10 15:43:52 -0700 | |
---|---|---|
committer | 2025-03-10 16:09:18 -0700 | |
commit | 073576142f0499612f39da6cad7606a6e35cf008 (patch) | |
tree | 80069a3267c706fff0705f700641c06a882821dd | |
parent | 89b6ee18c946febeef77f23177224c357471ae82 (diff) |
Fix DesktopPipTransitionObserver dependencies in WMShellModule.
The original commit 148cfd9411eac458707ec7b0846ddcb45c98a70a for PiP in
Desktop Mode caused a crash when the DESKTOP_WINDOWING_PIP flag is not
enabled due to the forced get() calls.
This CL is a fix forward along with the reland of the original CL.
Bug: 401865824
Bug: 401978578
Test: atest DesktopTasksControllerTest
DesktopTasksTransitionObserverTest
Test: Disable DESKTOP_WINDOWING_PIP flag and check that there are no
crashes and tests still pass
Flag: com.android.window.flags.enable_desktop_windowing_pip
Change-Id: I3615a8f1c30525182cea69aac819b192b7a9b499
5 files changed, 12 insertions, 9 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java index 3dbc151a2e92..124043215e3e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellModule.java @@ -825,7 +825,7 @@ public abstract class WMShellModule { overviewToDesktopTransitionObserver, desksOrganizer, desksTransitionObserver.get(), - desktopPipTransitionObserver.get(), + desktopPipTransitionObserver, userProfileContexts, desktopModeCompatPolicy, dragToDisplayTransitionHandler, @@ -1241,7 +1241,7 @@ public abstract class WMShellModule { transitions, shellTaskOrganizer, desktopMixedTransitionHandler.get(), - desktopPipTransitionObserver.get(), + desktopPipTransitionObserver, backAnimationController.get(), desktopWallpaperActivityTokenProvider, shellInit))); @@ -1266,7 +1266,7 @@ public abstract class WMShellModule { static Optional<DesktopPipTransitionObserver> provideDesktopPipTransitionObserver( Context context ) { - if (DesktopModeStatus.canEnterDesktopModeOrShowAppHandle(context) + if (DesktopModeStatus.canEnterDesktopMode(context) && DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PIP.isTrue()) { return Optional.of( new DesktopPipTransitionObserver()); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index dce67b3798a6..664e19d30707 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -213,7 +213,7 @@ class DesktopTasksController( private val overviewToDesktopTransitionObserver: OverviewToDesktopTransitionObserver, private val desksOrganizer: DesksOrganizer, private val desksTransitionObserver: DesksTransitionObserver, - private val desktopPipTransitionObserver: DesktopPipTransitionObserver, + private val desktopPipTransitionObserver: Optional<DesktopPipTransitionObserver>, private val userProfileContexts: UserProfileContexts, private val desktopModeCompatPolicy: DesktopModeCompatPolicy, private val dragToDisplayTransitionHandler: DragToDisplayTransitionHandler, @@ -811,6 +811,7 @@ class DesktopTasksController( } val isMinimizingToPip = DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_PIP.isTrue && + desktopPipTransitionObserver.isPresent && (taskInfo.pictureInPictureParams?.isAutoEnterEnabled ?: false) // If task is going to PiP, start a PiP transition instead of a minimize transition @@ -827,7 +828,7 @@ class DesktopTasksController( val requestRes = transitions.dispatchRequest(Binder(), requestInfo, /* skip= */ null) wct.merge(requestRes.second, true) - desktopPipTransitionObserver.addPendingPipTransition( + desktopPipTransitionObserver.get().addPendingPipTransition( DesktopPipTransitionObserver.PendingPipTransition( token = freeformTaskTransitionStarter.startPipTransition(wct), taskId = taskInfo.taskId, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt index c670ac3c4488..efd2253bc9b0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserver.kt @@ -40,6 +40,7 @@ import com.android.wm.shell.shared.TransitionUtil import com.android.wm.shell.shared.desktopmode.DesktopModeStatus import com.android.wm.shell.sysui.ShellInit import com.android.wm.shell.transition.Transitions +import java.util.Optional /** * A [Transitions.TransitionObserver] that observes shell transitions and updates the @@ -52,7 +53,7 @@ class DesktopTasksTransitionObserver( private val transitions: Transitions, private val shellTaskOrganizer: ShellTaskOrganizer, private val desktopMixedTransitionHandler: DesktopMixedTransitionHandler, - private val desktopPipTransitionObserver: DesktopPipTransitionObserver, + private val desktopPipTransitionObserver: Optional<DesktopPipTransitionObserver>, private val backAnimationController: BackAnimationController, private val desktopWallpaperActivityTokenProvider: DesktopWallpaperActivityTokenProvider, shellInit: ShellInit, @@ -94,7 +95,7 @@ class DesktopTasksTransitionObserver( removeTaskIfNeeded(info) } removeWallpaperOnLastTaskClosingIfNeeded(transition, info) - desktopPipTransitionObserver.onTransitionReady(transition, info) + desktopPipTransitionObserver.ifPresent { it.onTransitionReady(transition, info) } } private fun removeTaskIfNeeded(info: TransitionInfo) { diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt index 9e14d7685d1b..3c631dc81cbb 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksControllerTest.kt @@ -458,7 +458,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase() overviewToDesktopTransitionObserver, desksOrganizer, desksTransitionsObserver, - desktopPipTransitionObserver, + Optional.of(desktopPipTransitionObserver), userProfileContexts, desktopModeCompatPolicy, dragToDisplayTransitionHandler, diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt index ec64c2fa2337..9333a03c1592 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/desktopmode/DesktopTasksTransitionObserverTest.kt @@ -50,6 +50,7 @@ import com.android.wm.shell.sysui.ShellInit import com.android.wm.shell.transition.Transitions import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage +import java.util.Optional import org.junit.Before import org.junit.Rule import org.junit.Test @@ -110,7 +111,7 @@ class DesktopTasksTransitionObserverTest { transitions, shellTaskOrganizer, mixedHandler, - pipTransitionObserver, + Optional.of(pipTransitionObserver), backAnimationController, desktopWallpaperActivityTokenProvider, shellInit, |