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

Commit 6c3cc8c9 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Handle null activity in DMLPM calcualtions" into main

parents 4b1272c0 5cf40467
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -141,14 +141,15 @@ public final class DesktopModeBoundsCalculator {
     */
    @NonNull
    private static Rect calculateInitialBounds(@NonNull Task task,
            @NonNull ActivityRecord activity, @NonNull Rect stableBounds,
            @Nullable ActivityRecord activity, @NonNull Rect stableBounds,
            @Nullable ActivityOptions options, @NonNull DisplayContent displayContent,
            boolean shouldRespectOptionPosition, int captionHeight
    ) {
        // Display bounds not taking into account insets.
        final Rect screenBounds = displayContent.getBounds();
        final Size idealSize = calculateIdealSize(screenBounds, DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        if (!DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue()) {
        if (!DesktopModeFlags.ENABLE_WINDOWING_DYNAMIC_INITIAL_BOUNDS.isTrue()
                || activity == null) {
            return centerInScreen(idealSize, screenBounds);
        }
        if (activity.mAppCompatController.getAspectRatioOverrides()
+12 −7
Original line number Diff line number Diff line
@@ -152,17 +152,22 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            return RESULT_SKIP;
        }

        // If activity is null attempt to use task top activity if available.
        final ActivityRecord targetActivity = activity != null ? activity
                : task.getTopMostActivity();

        if (DesktopExperienceFlags.HANDLE_INCOMPATIBLE_TASKS_IN_DESKTOP_LAUNCH_PARAMS.isTrue()
                && activity != null) {
                && targetActivity != null) {
            final boolean isActivityStackTransparent = !task.forAllActivities(r ->
                    (r.occludesParent())) && !activity.occludesParent();
                    (r.occludesParent())) && !targetActivity.occludesParent();
            final AtomicInteger numActivities = new AtomicInteger(1);
            task.forAllActivities((r) -> {
                numActivities.incrementAndGet();
            });
            if (mDesktopModeCompatPolicy.isTopActivityExemptFromDesktopWindowing(
                    activity.mActivityComponent, activity.isNoDisplay(), isActivityStackTransparent,
                    numActivities.get(), task.getUserId(), activity.info)) {
                    targetActivity.mActivityComponent, targetActivity.isNoDisplay(),
                    isActivityStackTransparent, numActivities.get(), task.getUserId(),
                    targetActivity.info)) {
                appendLog("activity exempt from desktop, launching in fullscreen");
                outParams.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
                return RESULT_DONE;
@@ -255,7 +260,7 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
        if (DesktopModeFlags.INHERIT_TASK_BOUNDS_FOR_TRAMPOLINE_TASK_LAUNCHES.isTrue()) {
            ActivityRecord topVisibleFreeformActivity =
                    task.getDisplayContent().getTopMostVisibleFreeformActivity();
            if (shouldInheritExistingTaskBounds(topVisibleFreeformActivity, activity, task)) {
            if (shouldInheritExistingTaskBounds(topVisibleFreeformActivity, targetActivity, task)) {
                appendLog("inheriting bounds from existing closing instance");
                outParams.mBounds.set(topVisibleFreeformActivity.getBounds());
                appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
@@ -264,8 +269,8 @@ class DesktopModeLaunchParamsModifier implements LaunchParamsModifier {
            }
        }

        DesktopModeBoundsCalculator.updateInitialBounds(task, layout, activity, options, display,
                outParams, this::appendLog);
        DesktopModeBoundsCalculator.updateInitialBounds(task, layout, targetActivity, options,
                display, outParams, this::appendLog);
        appendLog("final desktop mode task bounds set to %s", outParams.mBounds);
        if (options != null && options.getFlexibleLaunchSize()) {
            // Return result done to prevent other modifiers from respecting option bounds and
+20 −0
Original line number Diff line number Diff line
@@ -1412,6 +1412,26 @@ public class DesktopModeLaunchParamsModifierTests extends
        assertEquals(desiredHeight, mResult.mBounds.height());
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    public void testNullActivity_defaultBoundsApplied() {
        setupDesktopModeLaunchParamsModifier();

        final TestDisplayContent display = createDisplayContent(ORIENTATION_LANDSCAPE,
                LANDSCAPE_DISPLAY_BOUNDS);
        final Task task = createTask(display, /* isResizeable */ true);

        final int desiredWidth =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.width() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final int desiredHeight =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);

        assertEquals(RESULT_CONTINUE, new CalculateRequestBuilder().setTask(task)
                .setActivity(null).calculate());
        assertEquals(desiredWidth, mResult.mBounds.width());
        assertEquals(desiredHeight, mResult.mBounds.height());
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    public void testNonEmptyActivityOptionsBounds() {