Merge "Use appBounds when computing split screen aspect ratio" into tm-qpr-dev

This commit is contained in:
Vali Calinescu
2023-03-20 14:04:12 +00:00
committed by Android (Google) Code Review
2 changed files with 88 additions and 7 deletions

View File

@@ -849,7 +849,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();
@@ -1504,7 +1504,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) {

View File

@@ -105,7 +105,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;
@@ -1991,7 +1990,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
@@ -2016,7 +2015,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
@@ -2042,7 +2041,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
@@ -2068,7 +2067,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