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

Commit 73a9e8a3 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas
Browse files

Use stable bounds orientation for initial bounds calculation

Using the existing task orientation is not a reliable way to calculate
the required initial bounds as there is a possibility the destination
orientation might be different to the current task one. This can be
the case with split screen to desk as well as moving tasks to external
displays.

Instead use the stable bounds orientation of the destination display.

Flag: com.android.window.flags.enable_windowing_dynamic_initial_bounds
Test: atest WMShellUnitTests:DesktopTasksControllerTest
Fixes: 404887079
Change-Id: Ic013146710bd2aa1f8afef32077f157312b1ccf6
parent 5d628b1f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -18,9 +18,13 @@ package com.android.internal.policy;

import static android.content.pm.ActivityInfo.INSETS_DECOUPLED_CONFIGURATION_ENFORCED;
import static android.content.pm.ActivityInfo.OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;

import android.annotation.NonNull;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.window.DesktopModeFlags;

/**
@@ -48,6 +52,14 @@ public final class DesktopModeCompatUtils {
                    || info.isChangeEnabled(OVERRIDE_EXCLUDE_CAPTION_INSETS_FROM_APP_BOUNDS));
    }

    /**
     * Returns the orientation of the given {@code rect}.
     */
    public static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) {
        return rect.height() >= rect.width()
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
    }

    private static boolean isConfigurationDecoupled(@NonNull ActivityInfo info,
            boolean optOutEdgeToEdge) {
        return info.isChangeEnabled(INSETS_DECOUPLED_CONFIGURATION_ENFORCED) && !optOutEdgeToEdge;
+3 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.graphics.Rect
import android.os.SystemProperties
import android.util.Size
import android.window.DesktopModeFlags
import com.android.internal.policy.DesktopModeCompatUtils
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayLayout
@@ -86,9 +87,10 @@ fun calculateInitialBounds(
    val topActivityInfo =
        taskInfo.topActivityInfo ?: return positionInScreen(idealSize, stableBounds)
    val screenOrientation = requestedScreenOrientation ?: topActivityInfo.screenOrientation
    val stableBoundsOrientation = DesktopModeCompatUtils.computeConfigOrientation(stableBounds)

    val initialSize: Size =
        when (taskInfo.configuration.orientation) {
        when (stableBoundsOrientation) {
            ORIENTATION_LANDSCAPE -> {
                if (taskInfo.canChangeAspectRatio) {
                    if (isFixedOrientationPortrait(screenOrientation)) {
+0 −10
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.server.wm;

import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;

@@ -84,14 +82,6 @@ final class AppCompatUtils {
        return Math.max(width, height) / (float) Math.min(width, height);
    }

    /**
     * Returns the orientation of the given {@code rect}.
     */
    static @Configuration.Orientation int computeConfigOrientation(@NonNull Rect rect) {
        return rect.height() >= rect.width()
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
    }

    /**
     * @param config The current {@link Configuration}
     * @return {@code true} if using a VR headset.
+5 −2
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.view.Display;
import android.view.Gravity;
import android.window.DesktopModeFlags;

import com.android.internal.policy.DesktopModeCompatUtils;

import java.util.function.Consumer;

/**
@@ -157,7 +159,8 @@ public final class DesktopModeBoundsCalculator {
        }
        final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy =
                activity.mAppCompatController.getDesktopAspectRatioPolicy();
        final int stableBoundsOrientation = AppCompatUtils.computeConfigOrientation(stableBounds);
        final int stableBoundsOrientation =
                DesktopModeCompatUtils.computeConfigOrientation(stableBounds);
        int activityOrientation = getActivityConfigurationOrientation(
                activity, task, stableBoundsOrientation);
        // Use orientation mismatch to resolve aspect ratio to match fixed orientation letterboxing
@@ -250,7 +253,7 @@ public final class DesktopModeBoundsCalculator {
                    task.topRunningActivity().getWindowConfiguration();
            final Rect existingBounds = windowConfiguration.getAppBounds() != null
                    ? windowConfiguration.getAppBounds() : windowConfiguration.getBounds();
            return AppCompatUtils.computeConfigOrientation(existingBounds);
            return DesktopModeCompatUtils.computeConfigOrientation(existingBounds);
        }
        final int activityOrientation = activity.getOverrideOrientation();
        final DesktopAppCompatAspectRatioPolicy desktopAppCompatAspectRatioPolicy =
+2 −1
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import android.view.Gravity;

import androidx.test.filters.SmallTest;

import com.android.internal.policy.DesktopModeCompatUtils;
import com.android.window.flags.Flags;

import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
@@ -325,7 +326,7 @@ public class DesktopModeLaunchParamsModifierTests extends
                .setActivity(activity).setOptions(options).calculate());
        // Original orientation and aspect ratio of activity is maintained.
        assertEquals(ORIENTATION_PORTRAIT,
                AppCompatUtils.computeConfigOrientation(mResult.mBounds));
                DesktopModeCompatUtils.computeConfigOrientation(mResult.mBounds));
        assertEquals(expectedAspectRatio,
                AppCompatUtils.computeAspectRatio(mResult.mAppBounds), /* delta */ 0.05);
    }