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

Commit b1311abb authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Make screenLayout calculation consistent

Generally this reverts [1] that uses the smallest layout
in all rotations. Because
1. According to the definition to screenLayout, it is more like
   the current size instead of smallest possible value.
2. Since [2][3], the configuration passed to app already only
   calculates from current size.

This fixes the inconsistent calculation, e.g. for the same size,
the task may calculate landscape configuration with LARGE and
portrait configuration with NORMAL. But the display always gets
NORMAL for portrait and landscape.

[1]: I85f90a16294ef5a7de94d5b9231abbc6f914fe90
[2]: Ie27020616983646b274b073f17accea627399df0
[3]: I0fcec4f035e466fafedc31be5925c0b04a6580f7

Bug: 233855302
Bug: 253386061
Test: atest DisplayContentTests ConfigurationScreenLayoutTest
Change-Id: If806e2a42a6c3c548d93ba43c1aed69889901193
parent 58946d06
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8454,7 +8454,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        getTaskFragment().computeConfigResourceOverrides(resolvedConfig, newParentConfiguration,
                mCompatDisplayInsets);
        // Use current screen layout as source because the size of app is independent to parent.
        resolvedConfig.screenLayout = TaskFragment.computeScreenLayoutOverride(
        resolvedConfig.screenLayout = computeScreenLayout(
                getConfiguration().screenLayout, resolvedConfig.screenWidthDp,
                resolvedConfig.screenHeightDp);

+6 −28
Original line number Diff line number Diff line
@@ -2188,8 +2188,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            mDisplayInfo.flags &= ~Display.FLAG_SCALING_DISABLED;
        }

        computeSizeRangesAndScreenLayout(mDisplayInfo, rotated, dw, dh,
                mDisplayMetrics.density, outConfig);
        computeSizeRanges(mDisplayInfo, rotated, dw, dh, mDisplayMetrics.density, outConfig);

        mWmService.mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(mDisplayId,
                mDisplayInfo);
@@ -2289,8 +2288,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        displayInfo.appHeight = appBounds.height();
        final DisplayCutout displayCutout = calculateDisplayCutoutForRotation(rotation);
        displayInfo.displayCutout = displayCutout.isEmpty() ? null : displayCutout;
        computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh,
                mDisplayMetrics.density, outConfig);
        computeSizeRanges(displayInfo, rotated, dw, dh, mDisplayMetrics.density, outConfig);
        return displayInfo;
    }

@@ -2309,6 +2307,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        outConfig.screenHeightDp = (int) (info.mConfigFrame.height() / density + 0.5f);
        outConfig.compatScreenWidthDp = (int) (outConfig.screenWidthDp / mCompatibleScreenScale);
        outConfig.compatScreenHeightDp = (int) (outConfig.screenHeightDp / mCompatibleScreenScale);
        outConfig.screenLayout = computeScreenLayout(
                Configuration.resetScreenLayout(outConfig.screenLayout),
                outConfig.screenWidthDp, outConfig.screenHeightDp);

        final boolean rotated = (rotation == ROTATION_90 || rotation == ROTATION_270);
        outConfig.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dw, dh);
@@ -2450,7 +2451,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        return curSize;
    }

    private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
    private void computeSizeRanges(DisplayInfo displayInfo, boolean rotated,
            int dw, int dh, float density, Configuration outConfig) {

        // We need to determine the smallest width that will occur under normal
@@ -2477,31 +2478,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (outConfig == null) {
            return;
        }
        int sl = Configuration.resetScreenLayout(outConfig.screenLayout);
        sl = reduceConfigLayout(sl, Surface.ROTATION_0, density, unrotDw, unrotDh);
        sl = reduceConfigLayout(sl, Surface.ROTATION_90, density, unrotDh, unrotDw);
        sl = reduceConfigLayout(sl, Surface.ROTATION_180, density, unrotDw, unrotDh);
        sl = reduceConfigLayout(sl, Surface.ROTATION_270, density, unrotDh, unrotDw);
        outConfig.smallestScreenWidthDp =
                (int) (displayInfo.smallestNominalAppWidth / density + 0.5f);
        outConfig.screenLayout = sl;
    }

    private int reduceConfigLayout(int curLayout, int rotation, float density, int dw, int dh) {
        // Get the app screen size at this rotation.
        final Rect size = mDisplayPolicy.getDecorInsetsInfo(rotation, dw, dh).mNonDecorFrame;

        // Compute the screen layout size class for this rotation.
        int longSize = size.width();
        int shortSize = size.height();
        if (longSize < shortSize) {
            int tmp = longSize;
            longSize = shortSize;
            shortSize = tmp;
        }
        longSize = (int) (longSize / density + 0.5f);
        shortSize = (int) (shortSize / density + 0.5f);
        return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
    }

    private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) {
+1 −11
Original line number Diff line number Diff line
@@ -2189,7 +2189,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
                compatScreenHeightDp = inOutConfig.screenHeightDp;
            }
            // Reducing the screen layout starting from its parent config.
            inOutConfig.screenLayout = computeScreenLayoutOverride(parentConfig.screenLayout,
            inOutConfig.screenLayout = computeScreenLayout(parentConfig.screenLayout,
                    compatScreenWidthDp, compatScreenHeightDp);
        }
    }
@@ -2252,16 +2252,6 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        }
    }

    /** Computes LONG, SIZE and COMPAT parts of {@link Configuration#screenLayout}. */
    static int computeScreenLayoutOverride(int sourceScreenLayout, int screenWidthDp,
            int screenHeightDp) {
        sourceScreenLayout = sourceScreenLayout
                & (Configuration.SCREENLAYOUT_LONG_MASK | Configuration.SCREENLAYOUT_SIZE_MASK);
        final int longSize = Math.max(screenWidthDp, screenHeightDp);
        final int shortSize = Math.min(screenWidthDp, screenHeightDp);
        return Configuration.reduceScreenLayout(sourceScreenLayout, longSize, shortSize);
    }

    @Override
    public int getActivityType() {
        final int applicationType = super.getActivityType();
+10 −0
Original line number Diff line number Diff line
@@ -1607,6 +1607,16 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        return false;
    }

    /** Computes LONG, SIZE and COMPAT parts of {@link Configuration#screenLayout}. */
    static int computeScreenLayout(int sourceScreenLayout, int screenWidthDp,
            int screenHeightDp) {
        sourceScreenLayout = sourceScreenLayout
                & (Configuration.SCREENLAYOUT_LONG_MASK | Configuration.SCREENLAYOUT_SIZE_MASK);
        final int longSize = Math.max(screenWidthDp, screenHeightDp);
        final int shortSize = Math.min(screenWidthDp, screenHeightDp);
        return Configuration.reduceScreenLayout(sourceScreenLayout, longSize, shortSize);
    }

    // TODO: Users would have their own window containers under the display container?
    void switchUser(int userId) {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
+1 −7
Original line number Diff line number Diff line
@@ -448,14 +448,8 @@ class WindowToken extends WindowContainer<WindowState> {
        if (mFixedRotationTransformState != null) {
            mFixedRotationTransformState.disassociate(this);
        }
        // TODO(b/233855302): Remove TaskFragment override if the DisplayContent uses the same
        //  bounds for screenLayout calculation.
        final Configuration overrideConfig = new Configuration(config);
        overrideConfig.screenLayout = TaskFragment.computeScreenLayoutOverride(
                overrideConfig.screenLayout, overrideConfig.screenWidthDp,
                overrideConfig.screenHeightDp);
        mFixedRotationTransformState = new FixedRotationTransformState(info, displayFrames,
                overrideConfig, mDisplayContent.getRotation());
                new Configuration(config), mDisplayContent.getRotation());
        mFixedRotationTransformState.mAssociatedTokens.add(this);
        mDisplayContent.getDisplayPolicy().simulateLayoutDisplay(displayFrames);
        onFixedRotationStatePrepared();
Loading