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

Commit 4ac53b6a authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[50/n] Move FixedOrientation Letterbox eligibility" into main

parents 4292e37e 6b264b36
Loading
Loading
Loading
Loading
+12 −35
Original line number Diff line number Diff line
@@ -784,11 +784,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    @NonNull
    final AppCompatController mAppCompatController;

    // Whether the activity is eligible to be letterboxed for fixed orientation with respect to its
    // requested orientation, even when it's letterbox for another reason (e.g., size compat mode)
    // and therefore #isLetterboxedForFixedOrientationAndAspectRatio returns false.
    private boolean mIsEligibleForFixedOrientationLetterbox;

    /**
     * Whether the activity is to be displayed. See {@link android.R.attr#windowNoDisplay}.
     */
@@ -2829,7 +2824,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }

    void removeStartingWindow() {
        boolean prevEligibleForLetterboxEducation = isEligibleForLetterboxEducation();
        final AppCompatLetterboxPolicy letterboxPolicy = mAppCompatController
                .getAppCompatLetterboxPolicy();
        boolean prevEligibleForLetterboxEducation =
                letterboxPolicy.isEligibleForLetterboxEducation();

        if (mStartingData != null
                && mStartingData.mRemoveAfterTransaction == AFTER_TRANSITION_FINISH) {
@@ -2842,8 +2840,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        removeStartingWindowAnimation(true /* prepareAnimation */);

        final Task task = getTask();
        if (prevEligibleForLetterboxEducation != isEligibleForLetterboxEducation()
                && task != null) {
        if (task != null && prevEligibleForLetterboxEducation
                != letterboxPolicy.isEligibleForLetterboxEducation()) {
            // Trigger TaskInfoChanged to update the letterbox education.
            task.dispatchTaskInfoChangedIfNeeded(true /* force */);
        }
@@ -8443,7 +8441,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final AppCompatAspectRatioPolicy aspectRatioPolicy =
                mAppCompatController.getAspectRatioPolicy();
        aspectRatioPolicy.reset();
        mIsEligibleForFixedOrientationLetterbox = false;
        mAppCompatController.getAppCompatLetterboxPolicy()
                .resetFixedOrientationLetterboxEligibility();
        mResolveConfigHint.resolveTmpOverrides(mDisplayContent, newParentConfiguration,
                isFixedRotationTransforming());

@@ -8779,28 +8778,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return inTransitionSelfOrParent();
    }

    /**
     * Whether this activity is eligible for letterbox eduction.
     *
     * <p>Conditions that need to be met:
     *
     * <ul>
     *     <li>{@link AppCompatConfiguration#getIsEducationEnabled} is true.
     *     <li>The activity is eligible for fixed orientation letterbox.
     *     <li>The activity is in fullscreen.
     *     <li>The activity is portrait-only.
     *     <li>The activity doesn't have a starting window (education should only be displayed
     *     once the starting window is removed in {@link #removeStartingWindow}).
     * </ul>
     */
    boolean isEligibleForLetterboxEducation() {
        return mWmService.mAppCompatConfiguration.getIsEducationEnabled()
                && mIsEligibleForFixedOrientationLetterbox
                && getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                && getRequestedConfigurationOrientation() == ORIENTATION_PORTRAIT
                && mStartingWindow == null;
    }

    /**
     * In some cases, applying insets to bounds changes the orientation. For example, if a
     * close-to-square display rotates to portrait to respect a portrait orientation activity, after
@@ -8905,11 +8882,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // If the activity requires a different orientation (either by override or activityInfo),
        // make it fit the available bounds by scaling down its bounds.
        final int forcedOrientation = getRequestedConfigurationOrientation();
        final boolean isEligibleForFixedOrientationLetterbox = mAppCompatController
                .getAppCompatLetterboxPolicy()
                .resolveFixedOrientationLetterboxEligibility(forcedOrientation, parentOrientation);

        mIsEligibleForFixedOrientationLetterbox = forcedOrientation != ORIENTATION_UNDEFINED
                && forcedOrientation != parentOrientation;

        if (!mIsEligibleForFixedOrientationLetterbox && (forcedOrientation == ORIENTATION_UNDEFINED
        if (!isEligibleForFixedOrientationLetterbox && (forcedOrientation == ORIENTATION_UNDEFINED
                || orientationRespectedWithInsets)) {
            return;
        }
+50 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.server.wm;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
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;
@@ -28,6 +31,7 @@ import static com.android.server.wm.AppCompatLetterboxUtils.calculateLetterboxPo

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.Configuration.Orientation;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.SurfaceControl;
@@ -55,6 +59,11 @@ class AppCompatLetterboxPolicy {

    private boolean mLastShouldShowLetterboxUi;

    // Whether the activity is eligible to be letterboxed for fixed orientation with respect to its
    // requested orientation, even when it's letterbox for another reason (e.g., size compat mode)
    // and therefore #isLetterboxedForFixedOrientationAndAspectRatio returns false.
    private boolean mIsEligibleForFixedOrientationLetterbox;

    AppCompatLetterboxPolicy(@NonNull ActivityRecord  activityRecord,
            @NonNull AppCompatConfiguration appCompatConfiguration) {
        mActivityRecord = activityRecord;
@@ -66,6 +75,10 @@ class AppCompatLetterboxPolicy {
        mAppCompatConfiguration = appCompatConfiguration;
    }

    void resetFixedOrientationLetterboxEligibility() {
        mIsEligibleForFixedOrientationLetterbox = false;
    }

    /** Cleans up {@link Letterbox} if it exists.*/
    void stop() {
        mLetterboxPolicyState.stop();
@@ -91,6 +104,43 @@ class AppCompatLetterboxPolicy {
        mLetterboxPolicyState.getLetterboxInnerBounds(outBounds);
    }

    /**
     * Checks if the current activity is eligible to be letterboxed because of a fixed orientation.
     *
     * @param forcedOrientation The requeste orientation
     * @param parentOrientation The orientation of the parent container.
     * @return {@code true} if the activity can be letterboxed because of the requested fixed
     * orientation.
     */
    boolean resolveFixedOrientationLetterboxEligibility(@Orientation int forcedOrientation,
            @Orientation int parentOrientation) {
        mIsEligibleForFixedOrientationLetterbox = forcedOrientation != ORIENTATION_UNDEFINED
                && forcedOrientation != parentOrientation;
        return mIsEligibleForFixedOrientationLetterbox;
    }

    /**
     * Whether this activity is eligible for letterbox eduction.
     *
     * <p>Conditions that need to be met:
     *
     * <ul>
     *     <li>{@link AppCompatConfiguration#getIsEducationEnabled} is true.
     *     <li>The activity is eligible for fixed orientation letterbox.
     *     <li>The activity is in fullscreen.
     *     <li>The activity is portrait-only.
     *     <li>The activity doesn't have a starting window (education should only be displayed
     *     once the starting window is removed in {@link #removeStartingWindow}).
     * </ul>
     */
    boolean isEligibleForLetterboxEducation() {
        return mAppCompatConfiguration.getIsEducationEnabled()
                && mIsEligibleForFixedOrientationLetterbox
                && mActivityRecord.getWindowingMode() == WINDOWING_MODE_FULLSCREEN
                && mActivityRecord.getRequestedConfigurationOrientation() == ORIENTATION_PORTRAIT
                && mActivityRecord.mStartingWindow == null;
    }

    @Nullable
    LetterboxDetails getLetterboxDetails() {
        final WindowState w = mActivityRecord.findMainWindow();
+6 −4
Original line number Diff line number Diff line
@@ -150,10 +150,12 @@ final class AppCompatUtils {
            appCompatTaskInfo.setTopActivityInSizeCompat(top.fillsParent());
        }
        // Whether the direct top activity is eligible for letterbox education.
        appCompatTaskInfo.setEligibleForLetterboxEducation(
                isTopActivityResumed && top.isEligibleForLetterboxEducation());
        appCompatTaskInfo.setLetterboxEducationEnabled(top.mAppCompatController
                .getAppCompatLetterboxOverrides().isLetterboxEducationEnabled());
        appCompatTaskInfo.setEligibleForLetterboxEducation(isTopActivityResumed
                && top.mAppCompatController.getAppCompatLetterboxPolicy()
                    .isEligibleForLetterboxEducation());
        appCompatTaskInfo.setLetterboxEducationEnabled(
                top.mAppCompatController.getAppCompatLetterboxOverrides()
                        .isLetterboxEducationEnabled());

        final AppCompatAspectRatioOverrides aspectRatioOverrides =
                top.mAppCompatController.getAspectRatioOverrides();
+20 −10
Original line number Diff line number Diff line
@@ -4683,7 +4683,8 @@ public class SizeCompatTests extends WindowTestsBase {

        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
    }

    @Test
@@ -4694,7 +4695,8 @@ public class SizeCompatTests extends WindowTestsBase {

        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
    }

    @Test
@@ -4716,7 +4718,8 @@ public class SizeCompatTests extends WindowTestsBase {
                false /*moveParents*/, "test");
        organizer.mPrimary.setBounds(0, 0, 1000, 600);

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        assertEquals(WINDOWING_MODE_MULTI_WINDOW, mActivity.getWindowingMode());
    }

@@ -4728,7 +4731,8 @@ public class SizeCompatTests extends WindowTestsBase {

        prepareUnresizable(mActivity, SCREEN_ORIENTATION_LANDSCAPE);

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        assertTrue(mActivity.mAppCompatController.getAspectRatioPolicy()
                .isLetterboxedForFixedOrientationAndAspectRatio());
    }
@@ -4745,14 +4749,16 @@ public class SizeCompatTests extends WindowTestsBase {
                createWindowState(new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING),
                        mActivity));

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());

        // Verify that after removing the starting window isEligibleForLetterboxEducation returns
        // true and mTask.dispatchTaskInfoChangedIfNeeded is called.
        spyOn(mTask);
        mActivity.removeStartingWindow();

        assertTrue(mActivity.isEligibleForLetterboxEducation());
        assertTrue(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        verify(mTask).dispatchTaskInfoChangedIfNeeded(true);
    }

@@ -4768,14 +4774,16 @@ public class SizeCompatTests extends WindowTestsBase {
                createWindowState(new WindowManager.LayoutParams(TYPE_APPLICATION_STARTING),
                        mActivity));

        assertFalse(mActivity.isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .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());
        assertFalse(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        verify(mTask, never()).dispatchTaskInfoChangedIfNeeded(true);
    }

@@ -4787,7 +4795,8 @@ public class SizeCompatTests extends WindowTestsBase {

        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);

        assertTrue(mActivity.isEligibleForLetterboxEducation());
        assertTrue(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        assertTrue(mActivity.mAppCompatController.getAspectRatioPolicy()
                .isLetterboxedForFixedOrientationAndAspectRatio());
    }
@@ -4802,7 +4811,8 @@ public class SizeCompatTests extends WindowTestsBase {

        rotateDisplay(mActivity.mDisplayContent, ROTATION_90);

        assertTrue(mActivity.isEligibleForLetterboxEducation());
        assertTrue(mActivity.mAppCompatController.getAppCompatLetterboxPolicy()
                .isEligibleForLetterboxEducation());
        assertFalse(mActivity.mAppCompatController.getAspectRatioPolicy()
                .isLetterboxedForFixedOrientationAndAspectRatio());
        assertTrue(mActivity.inSizeCompatMode());