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

Commit ec0f2c3b authored by Vali Calinescu's avatar Vali Calinescu
Browse files

Use appBounds when computing split screen aspect ratio

When computing the split screen aspect ratio we were previously using the bounds of the display which did not take insets into account, so an activity that would be using this value would get letterboxed when in split screen because the aspect ratio restriction is applied for appBounds on the activity.

Fix: 273513446
Test: atest WmTests:SizeCompatTests#testOverrideSplitScreenAspectRatio_splitScreenActivityInPortrait_notLetterboxed
Test: atest WmTests:SizeCompatTests#testOverrideSplitScreenAspectRatio_splitScreenActivityInLandscape_notLetterboxed
Change-Id: I996651124c16e855910efa3b315ea644adffd7c1
parent bce91b77
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -845,7 +845,7 @@ final class LetterboxUiController {
        int dividerInsets =
                getResources().getDimensionPixelSize(R.dimen.docked_stack_divider_insets);
        int dividerSize = dividerWindowWidth - dividerInsets * 2;
        final Rect bounds = new Rect(displayContent.getBounds());
        final Rect bounds = new Rect(displayContent.getWindowConfiguration().getAppBounds());
        if (bounds.width() >= bounds.height()) {
            bounds.inset(/* dx */ dividerSize / 2, /* dy */ 0);
            bounds.right = bounds.centerX();
@@ -1500,7 +1500,7 @@ final class LetterboxUiController {
    }

    private void inheritConfiguration(ActivityRecord firstOpaque) {
        // To avoid wrong behaviour, we're not forcing a specific aspet ratio to activities
        // To avoid wrong behaviour, we're not forcing a specific aspect ratio to activities
        // which are not already providing one (e.g. permission dialogs) and presumably also
        // not resizable.
        if (mActivityRecord.getMinAspectRatio() != UNDEFINED_ASPECT_RATIO) {
+86 −5
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -1988,7 +1987,7 @@ public class SizeCompatTests extends WindowTestsBase {
        float expectedAspectRatio = 1f * displayWidth / getExpectedSplitSize(displayHeight);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.height()) / afterBounds.width();
        Assert.assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
    }

    @Test
@@ -2013,7 +2012,7 @@ public class SizeCompatTests extends WindowTestsBase {
        float expectedAspectRatio = 1f * displayHeight / getExpectedSplitSize(displayWidth);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.height()) / afterBounds.width();
        Assert.assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
    }

    @Test
@@ -2039,7 +2038,7 @@ public class SizeCompatTests extends WindowTestsBase {
        float expectedAspectRatio = 1f * displayWidth / getExpectedSplitSize(displayHeight);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.width()) / afterBounds.height();
        Assert.assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
    }

    @Test
@@ -2065,7 +2064,89 @@ public class SizeCompatTests extends WindowTestsBase {
        float expectedAspectRatio = 1f * displayHeight / getExpectedSplitSize(displayWidth);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.width()) / afterBounds.height();
        Assert.assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
    }

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_TO_ALIGN_WITH_SPLIT_SCREEN})
    public void testOverrideSplitScreenAspectRatio_splitScreenActivityInPortrait_notLetterboxed() {
        mAtm.mDevEnableNonResizableMultiWindow = true;
        final int screenWidth = 1800;
        final int screenHeight = 1000;
        setUpDisplaySizeWithApp(screenWidth, screenHeight);
        final ActivityRecord activity = new ActivityBuilder(mAtm)
                .setTask(mTask)
                .setComponent(ComponentName.createRelative(mContext,
                        SizeCompatTests.class.getName()))
                .setUid(android.os.Process.myUid())
                .build();

        activity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Simulate real display with top insets.
        final int topInset = 30;
        activity.mDisplayContent.getWindowConfiguration()
                .setAppBounds(0, topInset, screenWidth, screenHeight);

        final TestSplitOrganizer organizer =
                new TestSplitOrganizer(mAtm, activity.getDisplayContent());
        // Move activity to split screen which takes half of the screen.
        mTask.reparent(organizer.mPrimary, POSITION_TOP, /* moveParents= */ false , "test");
        organizer.mPrimary.setBounds(0, 0, getExpectedSplitSize(screenWidth), screenHeight);
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, activity.getWindowingMode());

        // Unresizable portrait-only activity.
        prepareUnresizable(activity, 3f, SCREEN_ORIENTATION_PORTRAIT);

        // Activity should have the aspect ratio of a split screen activity and occupy exactly one
        // half of the screen, so there is no letterbox
        float expectedAspectRatio = 1f * screenHeight / getExpectedSplitSize(screenWidth);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.height()) / afterBounds.width();
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertFalse(activity.areBoundsLetterboxed());
    }

    @Test
    @EnableCompatChanges({ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO,
            ActivityInfo.OVERRIDE_MIN_ASPECT_RATIO_TO_ALIGN_WITH_SPLIT_SCREEN})
    public void testOverrideSplitScreenAspectRatio_splitScreenActivityInLandscape_notLetterboxed() {
        mAtm.mDevEnableNonResizableMultiWindow = true;
        final int screenWidth = 1000;
        final int screenHeight = 1800;
        setUpDisplaySizeWithApp(screenWidth, screenHeight);
        final ActivityRecord activity = new ActivityBuilder(mAtm)
                .setTask(mTask)
                .setComponent(ComponentName.createRelative(mContext,
                        SizeCompatTests.class.getName()))
                .setUid(android.os.Process.myUid())
                .build();

        activity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Simulate real display with top insets.
        final int leftInset = 30;
        activity.mDisplayContent.getWindowConfiguration()
                .setAppBounds(leftInset, 0, screenWidth, screenHeight);

        final TestSplitOrganizer organizer =
                new TestSplitOrganizer(mAtm, activity.getDisplayContent());
        // Move activity to split screen which takes half of the screen.
        mTask.reparent(organizer.mPrimary, POSITION_TOP, /* moveParents= */ false , "test");
        organizer.mPrimary.setBounds(0, 0, screenWidth, getExpectedSplitSize(screenHeight));
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, mTask.getWindowingMode());
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, activity.getWindowingMode());

        // Unresizable landscape-only activity.
        prepareUnresizable(activity, 3f, SCREEN_ORIENTATION_LANDSCAPE);

        // Activity should have the aspect ratio of a split screen activity and occupy exactly one
        // half of the screen, so there is no letterbox
        float expectedAspectRatio = 1f * screenWidth / getExpectedSplitSize(screenHeight);
        final Rect afterBounds = activity.getBounds();
        final float afterAspectRatio = (float) (afterBounds.width()) / afterBounds.height();
        assertEquals(expectedAspectRatio, afterAspectRatio, 0.001f);
        assertFalse(activity.areBoundsLetterboxed());
    }

    @Test