diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 87ba859c3d94e..f03c241356918 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -2515,7 +2515,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A } removeStartingWindowAnimation(true /* prepareAnimation */); - // TODO(b/215316431): Add tests final Task task = getTask(); if (prevEligibleForLetterboxEducation != isEligibleForLetterboxEducation() && task != null) { @@ -7695,7 +7694,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A * once the starting window is removed in {@link #removeStartingWindow}). * */ - // TODO(b/215316431): Add tests boolean isEligibleForLetterboxEducation() { return mWmService.mLetterboxConfiguration.getIsEducationEnabled() && mIsEligibleForFixedOrientationLetterbox diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index b815c38b7a8aa..7b38a955f8229 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -31,6 +31,7 @@ import static android.view.Surface.ROTATION_180; import static android.view.Surface.ROTATION_270; import static android.view.Surface.ROTATION_90; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; @@ -2128,6 +2129,136 @@ public class SizeCompatTests extends WindowTestsBase { APP_COMPAT_STATE_CHANGED__STATE__LETTERBOXED_FOR_SIZE_COMPAT_MODE); } + @Test + public void testIsEligibleForLetterboxEducation_educationNotEnabled_returnsFalse() { + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(false); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + } + + @Test + public void testIsEligibleForLetterboxEducation_notEligibleForFixedOrientation_returnsFalse() { + setUpDisplaySizeWithApp(1000, 2500); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + } + + @Test + public void testIsEligibleForLetterboxEducation_windowingModeMultiWindow_returnsFalse() { + // Support non resizable in multi window + mAtm.mDevEnableNonResizableMultiWindow = true; + setUpDisplaySizeWithApp(1000, 1200); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + final TestSplitOrganizer organizer = + new TestSplitOrganizer(mAtm, mActivity.getDisplayContent()); + + // Non-resizable landscape activity + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + final Rect originalBounds = new Rect(mActivity.getBounds()); + + // Move activity to split screen which takes half of the screen. + mTask.reparent(organizer.mPrimary, POSITION_TOP, + false /*moveParents*/, "test"); + organizer.mPrimary.setBounds(0, 0, 1000, 600); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode()); + } + + @Test + public void testIsEligibleForLetterboxEducation_fixedOrientationLandscape_returnsFalse() { + setUpDisplaySizeWithApp(1000, 2500); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_LANDSCAPE); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio()); + } + + @Test + public void testIsEligibleForLetterboxEducation_hasStartingWindow_returnsFalseUntilRemoved() { + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + mActivity.mStartingData = mock(StartingData.class); + mActivity.attachStartingWindow( + createWindowState(new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING), + mActivity)); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + + // Verify that after removing the starting window isEligibleForLetterboxEducation returns + // true and mTask.dispatchTaskInfoChangedIfNeeded is called. + spyOn(mTask); + mActivity.removeStartingWindow(); + + assertTrue(mActivity.isEligibleForLetterboxEducation()); + verify(mTask).dispatchTaskInfoChangedIfNeeded(true); + } + + @Test + public void testIsEligibleForLetterboxEducation_hasStartingWindowAndEducationNotEnabled() { + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(false); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + mActivity.mStartingData = mock(StartingData.class); + mActivity.attachStartingWindow( + createWindowState(new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING), + mActivity)); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + + // Verify that after removing the starting window isEligibleForLetterboxEducation still + // returns false and mTask.dispatchTaskInfoChangedIfNeeded isn't called. + spyOn(mTask); + mActivity.removeStartingWindow(); + + assertFalse(mActivity.isEligibleForLetterboxEducation()); + verify(mTask, never()).dispatchTaskInfoChangedIfNeeded(true); + } + + @Test + public void testIsEligibleForLetterboxEducation_letterboxedForFixedOrientation_returnsTrue() { + setUpDisplaySizeWithApp(2500, 1000); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + + assertTrue(mActivity.isEligibleForLetterboxEducation()); + assertTrue(mActivity.isLetterboxedForFixedOrientationAndAspectRatio()); + } + + @Test + public void testIsEligibleForLetterboxEducation_sizeCompatAndEligibleForFixedOrientation() { + setUpDisplaySizeWithApp(1000, 2500); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mActivity.mWmService.mLetterboxConfiguration.setIsEducationEnabled(true); + + prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT); + + rotateDisplay(mActivity.mDisplayContent, ROTATION_90); + + assertTrue(mActivity.isEligibleForLetterboxEducation()); + assertFalse(mActivity.isLetterboxedForFixedOrientationAndAspectRatio()); + assertTrue(mActivity.inSizeCompatMode()); + } + /** * Tests that all three paths in which aspect ratio logic can be applied yield the same * result, which is that aspect ratio is respected on app bounds. The three paths are