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

Commit 515b0a1a authored by Vania Desmonda's avatar Vania Desmonda
Browse files

Add method to start transition on intent launch.

This forces the task to correctly start the TRANSIT_OPEN transiiton in
Desktop mode when launching an intent from the taskbar and prevent it
from opening in full screen.

Fixes: 361366053
Flag: EXEMPT bugfix
Test: manual test
Change-Id: I6ce85cdfdf2b027a57cbca8402baf2ed7421f3bb
parent d4815549
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.graphics.PointF
import android.graphics.Rect
import android.graphics.Region
import android.os.Binder
import android.os.Bundle
import android.os.Handler
import android.os.IBinder
import android.os.SystemProperties
@@ -879,6 +880,36 @@ class DesktopTasksController(
        moveToDisplay(task, newDisplayId)
    }

    /**
     * Start an intent through a launch transition for starting tasks whose transition does not get
     * handled by [handleRequest]
     */
    fun startLaunchIntentTransition(intent: Intent, options: Bundle, displayId: Int) {
        val wct = WindowContainerTransaction()
        val displayLayout = displayController.getDisplayLayout(displayId) ?: return
        val bounds = calculateDefaultDesktopTaskBounds(displayLayout)
        if (DesktopModeFlags.ENABLE_CASCADING_WINDOWS.isTrue) {
            cascadeWindow(bounds, displayLayout, displayId)
        }
        val pendingIntent =
            PendingIntent.getActivity(
                context,
                /* requestCode= */ 0,
                intent,
                PendingIntent.FLAG_IMMUTABLE,
            )
        val ops =
            ActivityOptions.fromBundle(options).apply {
                launchWindowingMode = WINDOWING_MODE_FREEFORM
                pendingIntentBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOW_ALWAYS
                launchBounds = bounds
            }

        wct.sendPendingIntent(pendingIntent, intent, ops.toBundle())
        startLaunchTransition(TRANSIT_OPEN, wct, launchingTaskId = null)
    }

    /**
     * Move [task] to display with [displayId].
     *
@@ -2862,6 +2893,12 @@ class DesktopTasksController(
                c.moveToNextDisplay(taskId)
            }
        }

        override fun startLaunchIntentTransition(intent: Intent, options: Bundle, displayId: Int) {
            executeRemoteCallWithTaskPermission(controller, "startLaunchIntentTransition") { c ->
                c.startLaunchIntentTransition(intent, options, displayId)
            }
        }
    }

    private fun logV(msg: String, vararg arguments: Any?) {
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.wm.shell.desktopmode;

import android.app.ActivityManager.RunningTaskInfo;
import android.content.Intent;
import android.os.Bundle;
import android.window.RemoteTransition;
import com.android.wm.shell.desktopmode.IDesktopTaskListener;
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource;
@@ -61,4 +63,7 @@ interface IDesktopMode {

    /** Move a task with given `taskId` to external display */
    void moveToExternalDisplay(int taskId);

    /** Start a transition when launching an intent in desktop mode */
    void startLaunchIntentTransition(in Intent intent, in Bundle options, in int displayId);
}
 No newline at end of file
+16 −1
Original line number Diff line number Diff line
@@ -1117,6 +1117,21 @@ class DesktopTasksControllerTest : ShellTestCase() {
            .isEqualTo(DesktopTaskPosition.Center)
    }

    @Test
    fun launchIntent_taskInDesktopMode_transitionStarted() {
        setUpLandscapeDisplay()
        val freeformTask = setUpFreeformTask()

        controller.startLaunchIntentTransition(
            freeformTask.baseIntent,
            Bundle.EMPTY,
            DEFAULT_DISPLAY,
        )

        val wct = getLatestDesktopMixedTaskWct(type = TRANSIT_OPEN)
        assertThat(wct.hierarchyOps).hasSize(1)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS)
    fun addMoveToDesktopChanges_landscapeDevice_userFullscreenOverride_defaultPortraitBounds() {
@@ -5110,7 +5125,7 @@ class DesktopTasksControllerTest : ShellTestCase() {
        val arg: ArgumentCaptor<WindowContainerTransaction> =
            ArgumentCaptor.forClass(WindowContainerTransaction::class.java)
        verify(desktopMixedTransitionHandler)
            .startLaunchTransition(eq(type), capture(arg), anyInt(), anyOrNull(), anyOrNull())
            .startLaunchTransition(eq(type), capture(arg), anyOrNull(), anyOrNull(), anyOrNull())
        return arg.value
    }