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

Commit ec9c4cd5 authored by Chris Li's avatar Chris Li
Browse files

Ignore orientation request from resizable apps in multi window

Resizable app should be able to handle multi window by themselves, no
need to letterbox for them.

Fix: 189344515
Test: atest WmTests:ActivityRecordTests
Change-Id: I9787467246ae94c1ec9f68f5e7aa6bedf110ac4d
parent f142b5a3
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -7013,7 +7013,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // TODO(b/181207944): Consider removing the if condition and always run
        // TODO(b/181207944): Consider removing the if condition and always run
        // resolveFixedOrientationConfiguration() since this should be applied for all cases.
        // resolveFixedOrientationConfiguration() since this should be applied for all cases.
        if (isFixedOrientationLetterboxAllowed) {
        if (isFixedOrientationLetterboxAllowed) {
            resolveFixedOrientationConfiguration(newParentConfiguration);
            resolveFixedOrientationConfiguration(newParentConfiguration, parentWindowingMode);
        }
        }


        if (mCompatDisplayInsets != null) {
        if (mCompatDisplayInsets != null) {
@@ -7160,16 +7160,21 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
     * change and the requested orientation is different from the parent.
     * change and the requested orientation is different from the parent.
     *
     *
     * <p>If letterboxed due to fixed orientation then aspect ratio restrictions are also applied
     * <p>If letterboxed due to fixed orientation then aspect ratio restrictions are also applied
     * in this methiod.
     * in this method.
     */
     */
    private void resolveFixedOrientationConfiguration(@NonNull Configuration newParentConfig) {
    private void resolveFixedOrientationConfiguration(@NonNull Configuration newParentConfig,
            int windowingMode) {
        mLetterboxBoundsForFixedOrientationAndAspectRatio = null;
        mLetterboxBoundsForFixedOrientationAndAspectRatio = null;
        if (handlesOrientationChangeFromDescendant()) {
        if (handlesOrientationChangeFromDescendant()) {
            // No need to letterbox because of fixed orientation. Display will handle
            // No need to letterbox because of fixed orientation. Display will handle
            // fixed-orientation requests.
            // fixed-orientation requests.
            return;
            return;
        }
        }
        if (newParentConfig.windowConfiguration.getWindowingMode() == WINDOWING_MODE_PINNED) {
        if (WindowConfiguration.inMultiWindowMode(windowingMode) && isResizeable()) {
            // Ignore orientation request for resizable apps in multi window.
            return;
        }
        if (windowingMode == WINDOWING_MODE_PINNED) {
            // PiP bounds have higher priority than the requested orientation. Otherwise the
            // PiP bounds have higher priority than the requested orientation. Otherwise the
            // activity may be squeezed into a small piece.
            // activity may be squeezed into a small piece.
            return;
            return;
+39 −6
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_ALLOWLISTED;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_ALLOWLISTED;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
@@ -546,7 +547,7 @@ public class ActivityRecordTests extends WindowTestsBase {
    }
    }


    @Test
    @Test
    public void ignoreRequestedOrientationInSplitWindows() {
    public void ignoreRequestedOrientationForResizableInSplitWindows() {
        final ActivityRecord activity = createActivityWith2LevelTask();
        final ActivityRecord activity = createActivityWith2LevelTask();
        final Task task = activity.getTask();
        final Task task = activity.getTask();
        final Task rootTask = activity.getRootTask();
        final Task rootTask = activity.getRootTask();
@@ -578,13 +579,45 @@ public class ActivityRecordTests extends WindowTestsBase {
        }
        }
        task.setBounds(bounds);
        task.setBounds(bounds);


        final int activityCurOrientation = activity.getConfiguration().orientation;

        // Requests orientation that's different from its bounds.
        // Requests orientation that's different from its bounds.
        activity.setRequestedOrientation(
        activity.setRequestedOrientation(activityCurOrientation == ORIENTATION_LANDSCAPE
                isScreenPortrait ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE);
                ? SCREEN_ORIENTATION_PORTRAIT : SCREEN_ORIENTATION_LANDSCAPE);


        // Asserts it has orientation derived requested orientation (fixed orientation letterbox).
        // Asserts fixed orientation request is ignored, and the orientation is not changed
        assertEquals(isScreenPortrait ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE,
        // (fill Task).
                activity.getConfiguration().orientation);
        assertEquals(activityCurOrientation, activity.getConfiguration().orientation);
        assertFalse(activity.isLetterboxedForFixedOrientationAndAspectRatio());
    }

    @Test
    public void respectRequestedOrientationForNonResizableInSplitWindows() {
        final Task task = new TaskBuilder(mSupervisor)
                .setCreateParentTask(true).setCreateActivity(true).build();
        final Task rootTask = task.getRootTask();
        final ActivityRecord activity = new ActivityBuilder(mAtm)
                .setParentTask(task)
                .setOnTop(true)
                .setResizeMode(RESIZE_MODE_UNRESIZEABLE)
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();

        // Task in landscape.
        rootTask.setWindowingMode(WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY);
        task.setBounds(0, 0, 1000, 500);
        assertEquals(ORIENTATION_LANDSCAPE, task.getConfiguration().orientation);

        // Asserts fixed orientation request is respected, and the orientation is not changed.
        assertEquals(ORIENTATION_PORTRAIT, activity.getConfiguration().orientation);

        // Clear size compat.
        activity.clearSizeCompatMode();
        activity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */);
        activity.mDisplayContent.sendNewConfiguration();

        // Relaunching the app should still respect the orientation request.
        assertEquals(ORIENTATION_PORTRAIT, activity.getConfiguration().orientation);
        assertTrue(activity.isLetterboxedForFixedOrientationAndAspectRatio());
        assertTrue(activity.isLetterboxedForFixedOrientationAndAspectRatio());
    }
    }