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

Commit a59fd0c1 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

[5/n] Fix top rounded corners in freeform

If activity bounds match parent app bounds height, don't apply rounded
corners. Freeform activities will not have visible letterboxing except
if eligible for camera compat treatment. Pillarboxing for camera compat
will not have rounded corners to ensure consistency between apps.

Round up aspect ratio calculations in desktop mode to match activity
aspect ratio calculations in core.

Flag: com.android.window.flags.exclude_caption_from_app_bounds
Bug: 388014743
Test: atest AppCompatLetterboxPolicyTest
Change-Id: I5fbc8852c00771ffa228a5a635057eee201a4269
parent cc245ac8
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.Size
import com.android.wm.shell.R
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.DisplayLayout
import kotlin.math.ceil

val DESKTOP_MODE_INITIAL_BOUNDS_SCALE: Float =
    SystemProperties.getInt("persist.wm.debug.desktop_mode_initial_bounds_scale", 75) / 100f
@@ -190,22 +191,22 @@ fun maximizeSizeGivenAspectRatio(
    val finalWidth: Int
    // Get orientation either through top activity or task's orientation
    if (taskInfo.hasPortraitTopActivity()) {
        val tempWidth = (targetHeight / aspectRatio).toInt()
        val tempWidth = ceil(targetHeight / aspectRatio).toInt()
        if (tempWidth <= targetWidth) {
            finalHeight = targetHeight
            finalWidth = tempWidth
        } else {
            finalWidth = targetWidth
            finalHeight = (finalWidth * aspectRatio).toInt()
            finalHeight = ceil(finalWidth * aspectRatio).toInt()
        }
    } else {
        val tempWidth = (targetHeight * aspectRatio).toInt()
        val tempWidth = ceil(targetHeight * aspectRatio).toInt()
        if (tempWidth <= targetWidth) {
            finalHeight = targetHeight
            finalWidth = tempWidth
        } else {
            finalWidth = targetWidth
            finalHeight = (finalWidth / aspectRatio).toInt()
            finalHeight = ceil(finalWidth / aspectRatio).toInt()
        }
    }
    return Size(finalWidth, finalHeight + captionInsets)
+1 −1
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
    private val DEFAULT_PORTRAIT_BOUNDS = Rect(200, 165, 1400, 2085)
    private val RESIZABLE_LANDSCAPE_BOUNDS = Rect(25, 435, 1575, 1635)
    private val RESIZABLE_PORTRAIT_BOUNDS = Rect(680, 75, 1880, 1275)
    private val UNRESIZABLE_LANDSCAPE_BOUNDS = Rect(25, 449, 1575, 1611)
    private val UNRESIZABLE_LANDSCAPE_BOUNDS = Rect(25, 448, 1575, 1611)
    private val UNRESIZABLE_PORTRAIT_BOUNDS = Rect(830, 75, 1730, 1275)
    private val wallpaperToken = MockToken().token()

+34 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
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;
@@ -48,6 +49,8 @@ import java.io.PrintWriter;
 */
class AppCompatLetterboxPolicy {

    private static final int DIFF_TOLERANCE_PX = 1;

    @NonNull
    private final ActivityRecord mActivityRecord;
    @NonNull
@@ -56,6 +59,9 @@ class AppCompatLetterboxPolicy {
    private final AppCompatRoundedCorners mAppCompatRoundedCorners;
    @NonNull
    private final AppCompatConfiguration mAppCompatConfiguration;
    // Convenience temporary object to save allocation when calculating Rect.
    @NonNull
    private final Rect mTmpRect = new Rect();

    private boolean mLastShouldShowLetterboxUi;

@@ -71,7 +77,7 @@ class AppCompatLetterboxPolicy {
                : new LegacyLetterboxPolicyState();
        // TODO (b/358334569) Improve cutout logic dependency on app compat.
        mAppCompatRoundedCorners = new AppCompatRoundedCorners(mActivityRecord,
                this::isLetterboxedNotForDisplayCutout);
                this::ieEligibleForRoundedCorners);
        mAppCompatConfiguration = appCompatConfiguration;
    }

@@ -84,7 +90,7 @@ class AppCompatLetterboxPolicy {
        mLetterboxPolicyState.stop();
    }

    /** @return {@value true} if the letterbox policy is running and the activity letterboxed. */
    /** @return {@code true} if the letterbox policy is running and the activity letterboxed. */
    boolean isRunning() {
        return mLetterboxPolicyState.isRunning();
    }
@@ -130,7 +136,7 @@ class AppCompatLetterboxPolicy {
     *     <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}).
     *     once the starting window is removed in {@link ActivityRecord#removeStartingWindow}).
     * </ul>
     */
    boolean isEligibleForLetterboxEducation() {
@@ -294,16 +300,40 @@ class AppCompatLetterboxPolicy {
        }
    }

    private boolean ieEligibleForRoundedCorners(@NonNull WindowState mainWindow) {
        return isLetterboxedNotForDisplayCutout(mainWindow)
                && !isFreeformActivityMatchParentAppBoundsHeight();
    }

    private boolean isLetterboxedNotForDisplayCutout(@NonNull WindowState mainWindow) {
        return shouldShowLetterboxUi(mainWindow)
                && !mainWindow.isLetterboxedForDisplayCutout();
    }

    private boolean isFreeformActivityMatchParentAppBoundsHeight() {
        if (!Flags.excludeCaptionFromAppBounds()) {
            return false;
        }
        final Task task = mActivityRecord.getTask();
        if (task == null) {
            return false;
        }
        final Rect parentAppBounds = task.getWindowConfiguration().getAppBounds();
        if (parentAppBounds == null) {
            return false;
        }

        mLetterboxPolicyState.getLetterboxInnerBounds(mTmpRect);
        final int diff = parentAppBounds.height() - mTmpRect.height();
        // Compare bounds with tolerance of 1 px to account for rounding error calculations.
        return task.getWindowingMode() == WINDOWING_MODE_FREEFORM && diff <= DIFF_TOLERANCE_PX;
    }

    private static boolean shouldNotLayoutLetterbox(@Nullable WindowState w) {
        if (w == null) {
            return true;
        }
        final int type = w.mAttrs.type;
        final int type = w.getAttrs().type;
        // Allow letterbox to be displayed early for base application or application starting
        // windows even if it is not on the top z order to prevent flickering when the
        // letterboxed window is brought to the top
+4 −4
Original line number Diff line number Diff line
@@ -35,12 +35,12 @@ class AppCompatRoundedCorners {
    @NonNull
    private final ActivityRecord mActivityRecord;
    @NonNull
    private final Predicate<WindowState> mIsLetterboxedNotForDisplayCutout;
    private final Predicate<WindowState> mRoundedCornersWindowCondition;

    AppCompatRoundedCorners(@NonNull ActivityRecord  activityRecord,
            @NonNull Predicate<WindowState> isLetterboxedNotForDisplayCutout) {
            @NonNull Predicate<WindowState> roundedCornersWindowCondition) {
        mActivityRecord = activityRecord;
        mIsLetterboxedNotForDisplayCutout = isLetterboxedNotForDisplayCutout;
        mRoundedCornersWindowCondition = roundedCornersWindowCondition;
    }

    void updateRoundedCornersIfNeeded(@NonNull final WindowState mainWindow) {
@@ -136,7 +136,7 @@ class AppCompatRoundedCorners {
    private boolean requiresRoundedCorners(@NonNull final WindowState mainWindow) {
        final AppCompatLetterboxOverrides letterboxOverrides = mActivityRecord
                .mAppCompatController.getLetterboxOverrides();
        return mIsLetterboxedNotForDisplayCutout.test(mainWindow)
        return mRoundedCornersWindowCondition.test(mainWindow)
                && letterboxOverrides.isLetterboxActivityCornersRounded();
    }

+4 −0
Original line number Diff line number Diff line
@@ -151,6 +151,10 @@ class AppCompatActivityRobot {
        doReturn(taskBounds).when(mTaskStack.top()).getBounds();
    }

    void configureTaskAppBounds(@NonNull Rect appBounds) {
        mTaskStack.top().getWindowConfiguration().setAppBounds(appBounds);
    }

    void configureTopActivityBounds(@NonNull Rect activityBounds) {
        doReturn(activityBounds).when(mActivityStack.top()).getBounds();
    }
Loading