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

Commit 26a27835 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Make screenLayout calculation consistent"

parents 9f360cb8 b1311abb
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